From 99be93e8a635cc3607e98739ef1f9fe04f9d3129 Mon Sep 17 00:00:00 2001 From: PepperBell <44146161+PepperCode1@users.noreply.github.com> Date: Sat, 31 Jul 2021 17:28:41 -0700 Subject: [PATCH 01/13] Synchronization - Make PonderRegistry use a ThreadLocal current namespace - Add synchronized blocks to some methods that modify maps or lists - Move some non-thread safe method calls to the event.enqueueWork lambdas --- src/main/java/com/simibubi/create/Create.java | 11 ++++---- .../com/simibubi/create/CreateClient.java | 10 ++++---- .../weapons/PotatoCannonProjectileTypes.java | 8 ++++-- .../foundation/ponder/PonderRegistry.java | 25 +++++++++++++------ .../ponder/content/PonderChapterRegistry.java | 9 +++++-- .../ponder/content/PonderIndex.java | 22 ++++++++-------- .../ponder/content/PonderTagRegistry.java | 8 ++++-- .../render/SuperByteBufferCache.java | 16 +++++++----- 8 files changed, 68 insertions(+), 41 deletions(-) diff --git a/src/main/java/com/simibubi/create/Create.java b/src/main/java/com/simibubi/create/Create.java index 5935dfb7e..a5bc411e7 100644 --- a/src/main/java/com/simibubi/create/Create.java +++ b/src/main/java/com/simibubi/create/Create.java @@ -109,6 +109,7 @@ public class Create { modEventBus.addListener(AllConfigs::onReload); modEventBus.addListener(EventPriority.LOWEST, this::gatherData); forgeEventBus.addListener(EventPriority.HIGH, Create::onBiomeLoad); + forgeEventBus.register(CHUNK_UTIL); DistExecutor.unsafeRunWhenOn(Dist.CLIENT, () -> () -> CreateClient.addClientListeners(forgeEventBus, modEventBus)); @@ -116,16 +117,14 @@ public class Create { public static void init(final FMLCommonSetupEvent event) { CapabilityMinecartController.register(); - SchematicInstances.register(); - - CHUNK_UTIL.init(); - MinecraftForge.EVENT_BUS.register(CHUNK_UTIL); - AllPackets.registerPackets(); - AllTriggers.register(); + SchematicInstances.register(); PotatoCannonProjectileTypes.register(); + CHUNK_UTIL.init(); + event.enqueueWork(() -> { + AllTriggers.register(); SchematicProcessor.register(); AllWorldFeatures.registerFeatures(); }); diff --git a/src/main/java/com/simibubi/create/CreateClient.java b/src/main/java/com/simibubi/create/CreateClient.java index 29500e2c7..52bfb4fe8 100644 --- a/src/main/java/com/simibubi/create/CreateClient.java +++ b/src/main/java/com/simibubi/create/CreateClient.java @@ -107,12 +107,12 @@ public class CreateClient { UIRenderHelper.init(); - IResourceManager resourceManager = Minecraft.getInstance() - .getResourceManager(); - if (resourceManager instanceof IReloadableResourceManager) - ((IReloadableResourceManager) resourceManager).registerReloadListener(new ResourceReloadHandler()); - event.enqueueWork(() -> { + IResourceManager resourceManager = Minecraft.getInstance() + .getResourceManager(); + if (resourceManager instanceof IReloadableResourceManager) + ((IReloadableResourceManager) resourceManager).registerReloadListener(new ResourceReloadHandler()); + registerLayerRenderers(Minecraft.getInstance() .getEntityRenderDispatcher()); }); diff --git a/src/main/java/com/simibubi/create/content/curiosities/weapons/PotatoCannonProjectileTypes.java b/src/main/java/com/simibubi/create/content/curiosities/weapons/PotatoCannonProjectileTypes.java index 52c847bd7..0d19ad0a9 100644 --- a/src/main/java/com/simibubi/create/content/curiosities/weapons/PotatoCannonProjectileTypes.java +++ b/src/main/java/com/simibubi/create/content/curiosities/weapons/PotatoCannonProjectileTypes.java @@ -253,11 +253,15 @@ public class PotatoCannonProjectileTypes { ; public static void registerType(ResourceLocation resLoc, PotatoCannonProjectileTypes type) { - ALL.put(resLoc, type); + synchronized (ALL) { + ALL.put(resLoc, type); + } } public static void assignType(IRegistryDelegate item, PotatoCannonProjectileTypes type) { - ITEM_MAP.put(item, type); + synchronized (ITEM_MAP) { + ITEM_MAP.put(item, type); + } } public static Optional getProjectileTypeOf(ItemStack item) { diff --git a/src/main/java/com/simibubi/create/foundation/ponder/PonderRegistry.java b/src/main/java/com/simibubi/create/foundation/ponder/PonderRegistry.java index ee420a6f4..ee876bd31 100644 --- a/src/main/java/com/simibubi/create/foundation/ponder/PonderRegistry.java +++ b/src/main/java/com/simibubi/create/foundation/ponder/PonderRegistry.java @@ -41,23 +41,32 @@ public class PonderRegistry { // Map from item ids to all storyboards public static final Map> ALL = new HashMap<>(); - private static String currentNamespace; + private static final ThreadLocal CURRENT_NAMESPACE = new ThreadLocal<>(); + + private static String getCurrentNamespace() { + return CURRENT_NAMESPACE.get(); + } + + private static void setCurrentNamespace(String namespace) { + CURRENT_NAMESPACE.set(namespace); + } public static void startRegistration(String namespace) { - if (currentNamespace != null) { + if (getCurrentNamespace() != null) { throw new IllegalStateException("Cannot start registration when already started!"); } - currentNamespace = namespace; + setCurrentNamespace(namespace); } public static void endRegistration() { - if (currentNamespace == null) { + if (getCurrentNamespace() == null) { throw new IllegalStateException("Cannot end registration when not started!"); } - currentNamespace = null; + setCurrentNamespace(null); } private static String getNamespaceOrThrow() { + String currentNamespace = getCurrentNamespace(); if (currentNamespace == null) { throw new IllegalStateException("Cannot register storyboard without starting registration!"); } @@ -71,8 +80,10 @@ public class PonderRegistry { PonderSceneBuilder builder = new PonderSceneBuilder(entry); if (tags.length > 0) builder.highlightTags(tags); - ALL.computeIfAbsent(id, _$ -> new ArrayList<>()) - .add(entry); + synchronized (ALL) { + ALL.computeIfAbsent(id, _$ -> new ArrayList<>()) + .add(entry); + } return builder; } diff --git a/src/main/java/com/simibubi/create/foundation/ponder/content/PonderChapterRegistry.java b/src/main/java/com/simibubi/create/foundation/ponder/content/PonderChapterRegistry.java index ec861ed1a..85d986fac 100644 --- a/src/main/java/com/simibubi/create/foundation/ponder/content/PonderChapterRegistry.java +++ b/src/main/java/com/simibubi/create/foundation/ponder/content/PonderChapterRegistry.java @@ -22,11 +22,16 @@ public class PonderChapterRegistry { } public void addStoriesToChapter(@Nonnull PonderChapter chapter, PonderStoryBoardEntry... entries) { - chapters.get(chapter.getId()).getSecond().addAll(Arrays.asList(entries)); + List entryList = chapters.get(chapter.getId()).getSecond(); + synchronized (entryList) { + entryList.addAll(Arrays.asList(entries)); + } } PonderChapter addChapter(@Nonnull PonderChapter chapter) { - chapters.put(chapter.getId(), Pair.of(chapter, new ArrayList<>())); + synchronized (chapters) { + chapters.put(chapter.getId(), Pair.of(chapter, new ArrayList<>())); + } return chapter; } diff --git a/src/main/java/com/simibubi/create/foundation/ponder/content/PonderIndex.java b/src/main/java/com/simibubi/create/foundation/ponder/content/PonderIndex.java index 62241e7fc..9dc494031 100644 --- a/src/main/java/com/simibubi/create/foundation/ponder/content/PonderIndex.java +++ b/src/main/java/com/simibubi/create/foundation/ponder/content/PonderIndex.java @@ -445,17 +445,17 @@ public class PonderIndex { .add(Blocks.HONEY_BLOCK); PonderRegistry.TAGS.forTag(PonderTag.CONTRAPTION_ACTOR) - .add(AllBlocks.MECHANICAL_HARVESTER) - .add(AllBlocks.MECHANICAL_PLOUGH) - .add(AllBlocks.MECHANICAL_DRILL) - .add(AllBlocks.MECHANICAL_SAW) - .add(AllBlocks.DEPLOYER) - .add(AllBlocks.PORTABLE_STORAGE_INTERFACE) - .add(AllBlocks.PORTABLE_FLUID_INTERFACE) - .add(AllBlocks.MECHANICAL_BEARING) - .add(AllBlocks.ANDESITE_FUNNEL) - .add(AllBlocks.BRASS_FUNNEL) - .add(AllBlocks.SEATS.get(DyeColor.WHITE)) + .add(AllBlocks.MECHANICAL_HARVESTER) + .add(AllBlocks.MECHANICAL_PLOUGH) + .add(AllBlocks.MECHANICAL_DRILL) + .add(AllBlocks.MECHANICAL_SAW) + .add(AllBlocks.DEPLOYER) + .add(AllBlocks.PORTABLE_STORAGE_INTERFACE) + .add(AllBlocks.PORTABLE_FLUID_INTERFACE) + .add(AllBlocks.MECHANICAL_BEARING) + .add(AllBlocks.ANDESITE_FUNNEL) + .add(AllBlocks.BRASS_FUNNEL) + .add(AllBlocks.SEATS.get(DyeColor.WHITE)) .add(AllBlocks.REDSTONE_CONTACT) .add(Blocks.BELL) .add(Blocks.DISPENSER) diff --git a/src/main/java/com/simibubi/create/foundation/ponder/content/PonderTagRegistry.java b/src/main/java/com/simibubi/create/foundation/ponder/content/PonderTagRegistry.java index f13fc6cdc..cdd5be6e6 100644 --- a/src/main/java/com/simibubi/create/foundation/ponder/content/PonderTagRegistry.java +++ b/src/main/java/com/simibubi/create/foundation/ponder/content/PonderTagRegistry.java @@ -49,11 +49,15 @@ public class PonderTagRegistry { } public void add(PonderTag tag, ResourceLocation item) { - tags.put(item, tag); + synchronized (tags) { + tags.put(item, tag); + } } public void add(PonderTag tag, PonderChapter chapter) { - chapterTags.put(chapter, tag); + synchronized (chapterTags) { + chapterTags.put(chapter, tag); + } } public ItemBuilder forItems(ResourceLocation... items) { diff --git a/src/main/java/com/simibubi/create/foundation/render/SuperByteBufferCache.java b/src/main/java/com/simibubi/create/foundation/render/SuperByteBufferCache.java index 6b7131c3f..5027a0313 100644 --- a/src/main/java/com/simibubi/create/foundation/render/SuperByteBufferCache.java +++ b/src/main/java/com/simibubi/create/foundation/render/SuperByteBufferCache.java @@ -28,7 +28,7 @@ import net.minecraft.util.math.BlockPos; public class SuperByteBufferCache { - Map, Cache> cache; + private Map, Cache> cache; public SuperByteBufferCache() { cache = new HashMap<>(); @@ -87,14 +87,18 @@ public class SuperByteBufferCache { } public void registerCompartment(Compartment instance) { - cache.put(instance, CacheBuilder.newBuilder() - .build()); + synchronized (cache) { + cache.put(instance, CacheBuilder.newBuilder() + .build()); + } } public void registerCompartment(Compartment instance, long ticksUntilExpired) { - cache.put(instance, CacheBuilder.newBuilder() - .expireAfterAccess(ticksUntilExpired * 50, TimeUnit.MILLISECONDS) - .build()); + synchronized (cache) { + cache.put(instance, CacheBuilder.newBuilder() + .expireAfterAccess(ticksUntilExpired * 50, TimeUnit.MILLISECONDS) + .build()); + } } private SuperByteBuffer standardBlockRender(BlockState renderedState) { From c674b5df8d51d64467fe91b838310d578651230a Mon Sep 17 00:00:00 2001 From: PepperBell <44146161+PepperCode1@users.noreply.github.com> Date: Sat, 31 Jul 2021 19:10:17 -0700 Subject: [PATCH 02/13] Fix linked controller rendering - Fix unequip animation - Fix button progress not resetting on unequip - Optimize code --- .../item/LecternControllerRenderer.java | 8 +- .../item/LinkedControllerClientHandler.java | 11 ++- .../item/LinkedControllerItemRenderer.java | 95 ++++++++++++------- 3 files changed, 72 insertions(+), 42 deletions(-) diff --git a/src/main/java/com/simibubi/create/content/logistics/item/LecternControllerRenderer.java b/src/main/java/com/simibubi/create/content/logistics/item/LecternControllerRenderer.java index 3f725dff0..33e7d36d5 100644 --- a/src/main/java/com/simibubi/create/content/logistics/item/LecternControllerRenderer.java +++ b/src/main/java/com/simibubi/create/content/logistics/item/LecternControllerRenderer.java @@ -26,12 +26,12 @@ public class LecternControllerRenderer extends SafeTileEntityRenderer currentlyPressed = new HashSet<>(); @@ -112,6 +108,8 @@ public class LinkedControllerClientHandler { if (!currentlyPressed.isEmpty()) AllPackets.channel.sendToServer(new LinkedControllerInputPacket(currentlyPressed, false)); currentlyPressed.clear(); + + LinkedControllerItemRenderer.resetButtons(); } protected static boolean isActuallyPressed(KeyBinding kb) { @@ -124,6 +122,7 @@ public class LinkedControllerClientHandler { public static void tick() { LinkedControllerItemRenderer.tick(); + if (MODE == Mode.IDLE) return; if (packetCooldown > 0) @@ -269,4 +268,8 @@ public class LinkedControllerClientHandler { } + public enum Mode { + IDLE, ACTIVE, BIND + } + } diff --git a/src/main/java/com/simibubi/create/content/logistics/item/LinkedControllerItemRenderer.java b/src/main/java/com/simibubi/create/content/logistics/item/LinkedControllerItemRenderer.java index e82a57735..b67e280e5 100644 --- a/src/main/java/com/simibubi/create/content/logistics/item/LinkedControllerItemRenderer.java +++ b/src/main/java/com/simibubi/create/content/logistics/item/LinkedControllerItemRenderer.java @@ -50,35 +50,56 @@ public class LinkedControllerItemRenderer extends CustomRenderedItemModelRendere } } + static void resetButtons() { + for (int i = 0; i < buttons.size(); i++) { + buttons.get(i).startWithValue(0); + } + } + @Override protected void render(ItemStack stack, LinkedControllerModel model, PartialItemModelRenderer renderer, ItemCameraTransforms.TransformType transformType, MatrixStack ms, IRenderTypeBuffer buffer, int light, int overlay) { - - renderLinkedController(stack, model, renderer, transformType, ms, light, null, null); + renderNormal(stack, model, renderer, transformType, ms, light); } - public static void renderLinkedController(ItemStack stack, LinkedControllerModel model, + protected static void renderNormal(ItemStack stack, LinkedControllerModel model, PartialItemModelRenderer renderer, ItemCameraTransforms.TransformType transformType, MatrixStack ms, - int light, Boolean active, Boolean usedByMe) { + int light) { + render(stack, model, renderer, transformType, ms, light, RenderType.NORMAL, false, false); + } + public static void renderInLectern(ItemStack stack, LinkedControllerModel model, + PartialItemModelRenderer renderer, ItemCameraTransforms.TransformType transformType, MatrixStack ms, + int light, boolean active, boolean renderDepression) { + render(stack, model, renderer, transformType, ms, light, RenderType.LECTERN, active, renderDepression); + } + + protected static void render(ItemStack stack, LinkedControllerModel model, + PartialItemModelRenderer renderer, ItemCameraTransforms.TransformType transformType, MatrixStack ms, + int light, RenderType renderType, boolean active, boolean renderDepression) { float pt = AnimationTickHolder.getPartialTicks(); MatrixTransformStack msr = MatrixTransformStack.of(ms); ms.pushPose(); - Minecraft mc = Minecraft.getInstance(); - boolean rightHanded = mc.options.mainHand == HandSide.RIGHT; - TransformType mainHand = - rightHanded ? TransformType.FIRST_PERSON_RIGHT_HAND : TransformType.FIRST_PERSON_LEFT_HAND; - TransformType offHand = - rightHanded ? TransformType.FIRST_PERSON_LEFT_HAND : TransformType.FIRST_PERSON_RIGHT_HAND; + if (renderType == RenderType.NORMAL) { + Minecraft mc = Minecraft.getInstance(); + boolean rightHanded = mc.options.mainHand == HandSide.RIGHT; + TransformType mainHand = + rightHanded ? TransformType.FIRST_PERSON_RIGHT_HAND : TransformType.FIRST_PERSON_LEFT_HAND; + TransformType offHand = + rightHanded ? TransformType.FIRST_PERSON_LEFT_HAND : TransformType.FIRST_PERSON_RIGHT_HAND; - if (active == null) { active = false; - boolean noControllerInMain = !AllItems.LINKED_CONTROLLER.isIn(mc.player.getMainHandItem()); + if (transformType == mainHand || (transformType == offHand && noControllerInMain)) { + float equip = equipProgress.getValue(pt); + int handModifier = transformType == TransformType.FIRST_PERSON_LEFT_HAND ? -1 : 1; + msr.translate(0, equip / 4, equip / 4 * handModifier); + msr.rotateY(equip * -30 * handModifier); + msr.rotateZ(equip * -30); active = true; } @@ -89,56 +110,62 @@ public class LinkedControllerItemRenderer extends CustomRenderedItemModelRendere active = true; } - active &= LinkedControllerClientHandler.MODE != Mode.IDLE && !LinkedControllerClientHandler.inLectern(); - usedByMe = active; + active &= LinkedControllerClientHandler.MODE != Mode.IDLE; - if (active && (transformType == mainHand || transformType == offHand)) { - float equip = equipProgress.getValue(pt); - int handModifier = transformType == TransformType.FIRST_PERSON_LEFT_HAND ? -1 : 1; - msr.translate(0, equip / 4, equip / 4 * handModifier); - msr.rotateY(equip * -30 * handModifier); - msr.rotateZ(equip * -30); - } + renderDepression = true; } renderer.render(active ? model.getPartial("powered") : model.getOriginalModel(), light); + if (!active) { + ms.popPose(); + return; + } + IBakedModel button = model.getPartial("button"); float s = 1 / 16f; float b = s * -.75f; int index = 0; - if (LinkedControllerClientHandler.MODE == Mode.BIND) { - int i = (int) MathHelper.lerp((MathHelper.sin(AnimationTickHolder.getRenderTime() / 4f) + 1) / 2, 5, 15); - light = i << 20; + if (renderType == RenderType.NORMAL) { + if (LinkedControllerClientHandler.MODE == Mode.BIND) { + int i = (int) MathHelper.lerp((MathHelper.sin(AnimationTickHolder.getRenderTime() / 4f) + 1) / 2, 5, 15); + light = i << 20; + } } ms.pushPose(); msr.translate(2 * s, 0, 8 * s); - button(renderer, ms, light, pt, button, b, index++, usedByMe); + renderButton(renderer, ms, light, pt, button, b, index++, renderDepression); msr.translate(4 * s, 0, 0); - button(renderer, ms, light, pt, button, b, index++, usedByMe); + renderButton(renderer, ms, light, pt, button, b, index++, renderDepression); msr.translate(-2 * s, 0, 2 * s); - button(renderer, ms, light, pt, button, b, index++, usedByMe); + renderButton(renderer, ms, light, pt, button, b, index++, renderDepression); msr.translate(0, 0, -4 * s); - button(renderer, ms, light, pt, button, b, index++, usedByMe); + renderButton(renderer, ms, light, pt, button, b, index++, renderDepression); ms.popPose(); msr.translate(3 * s, 0, 3 * s); - button(renderer, ms, light, pt, button, b, index++, usedByMe); + renderButton(renderer, ms, light, pt, button, b, index++, renderDepression); msr.translate(2 * s, 0, 0); - button(renderer, ms, light, pt, button, b, index++, usedByMe); + renderButton(renderer, ms, light, pt, button, b, index++, renderDepression); ms.popPose(); } - protected static void button(PartialItemModelRenderer renderer, MatrixStack ms, int light, float pt, IBakedModel button, - float b, int index, boolean usedByMe) { + protected static void renderButton(PartialItemModelRenderer renderer, MatrixStack ms, int light, float pt, IBakedModel button, + float b, int index, boolean renderDepression) { ms.pushPose(); - float depression = usedByMe ? b * buttons.get(index).getValue(pt) : 0; - ms.translate(0, depression, 0); + if (renderDepression) { + float depression = b * buttons.get(index).getValue(pt); + ms.translate(0, depression, 0); + } renderer.renderSolid(button, light); ms.popPose(); } + protected enum RenderType { + NORMAL, LECTERN; + } + } From 468435e1a02b9dc6979598261e1a4d161b21bdf2 Mon Sep 17 00:00:00 2001 From: Jozufozu Date: Mon, 2 Aug 2021 00:08:26 -0700 Subject: [PATCH 03/13] Fix nullpointer when contraptions stop --- .../render/ContraptionRenderManager.java | 9 ++++++++- .../render/FlwContraptionManager.java | 18 +++++++++++------- 2 files changed, 19 insertions(+), 8 deletions(-) diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/render/ContraptionRenderManager.java b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/render/ContraptionRenderManager.java index 57d9fa089..8d94a681a 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/render/ContraptionRenderManager.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/render/ContraptionRenderManager.java @@ -50,13 +50,17 @@ public abstract class ContraptionRenderManager } public void beginFrame(BeginFrameEvent event) { - visible.clear(); renderInfos.int2ObjectEntrySet() .stream() .map(Map.Entry::getValue) .forEach(renderInfo -> renderInfo.beginFrame(event)); + collectVisible(); + } + + protected void collectVisible() { + visible.clear(); renderInfos.int2ObjectEntrySet() .stream() .map(Map.Entry::getValue) @@ -80,6 +84,9 @@ public abstract class ContraptionRenderManager renderInfos.clear(); } + /** + * Remove all render infos associated with dead/removed contraptions. + */ public void removeDeadRenderers() { renderInfos.values().removeIf(ContraptionRenderInfo::isDead); } diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/render/FlwContraptionManager.java b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/render/FlwContraptionManager.java index 8bdb46d9f..3aff78682 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/render/FlwContraptionManager.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/render/FlwContraptionManager.java @@ -80,13 +80,17 @@ public class FlwContraptionManager extends ContraptionRenderManager { - if (renderer.isDead()) { - renderer.invalidate(); - return true; - } - return false; - }); + boolean removed = renderInfos.values() + .removeIf(renderer -> { + if (renderer.isDead()) { + renderer.invalidate(); + return true; + } + return false; + }); + + // we use visible in #tick() so we have to re-evaluate it if any were removed + if (removed) collectVisible(); } @Override From e8a650043422f8d854a71298ece0cd693c48c8db Mon Sep 17 00:00:00 2001 From: MRH0 Date: Wed, 4 Aug 2021 02:20:40 +0200 Subject: [PATCH 04/13] Added tag for improved integration in DeployerApplicationRecipe + Added create:sandpaper to AllRecipeTypes and datagen. ~ Changed hardcoded list of sandpaper items to Tag. This would enable me to include the Diamond Grit Sandpaper from CC&A in the deployer recipe. Node: There might be more applications for this tag. --- .../resources/data/create/tags/items/sandpaper.json | 7 +++++++ src/main/java/com/simibubi/create/AllItems.java | 2 ++ src/main/java/com/simibubi/create/AllTags.java | 3 ++- .../components/deployer/DeployerApplicationRecipe.java | 3 ++- 4 files changed, 13 insertions(+), 2 deletions(-) create mode 100644 src/generated/resources/data/create/tags/items/sandpaper.json diff --git a/src/generated/resources/data/create/tags/items/sandpaper.json b/src/generated/resources/data/create/tags/items/sandpaper.json new file mode 100644 index 000000000..acab7913a --- /dev/null +++ b/src/generated/resources/data/create/tags/items/sandpaper.json @@ -0,0 +1,7 @@ +{ + "replace": false, + "values": [ + "create:sand_paper", + "create:red_sand_paper" + ] +} \ No newline at end of file diff --git a/src/main/java/com/simibubi/create/AllItems.java b/src/main/java/com/simibubi/create/AllItems.java index 5103e0aa6..728ac0894 100644 --- a/src/main/java/com/simibubi/create/AllItems.java +++ b/src/main/java/com/simibubi/create/AllItems.java @@ -228,11 +228,13 @@ public class AllItems { public static final ItemEntry SAND_PAPER = REGISTRATE.item("sand_paper", SandPaperItem::new) .transform(CreateRegistrate.customRenderedItem(() -> SandPaperModel::new)) + .tag(AllTags.AllItemTags.SANDPAPER.tag) .register(); public static final ItemEntry RED_SAND_PAPER = REGISTRATE.item("red_sand_paper", SandPaperItem::new) .transform(CreateRegistrate.customRenderedItem(() -> SandPaperModel::new)) .onRegister(s -> TooltipHelper.referTo(s, SAND_PAPER)) + .tag(AllTags.AllItemTags.SANDPAPER.tag) .register(); public static final ItemEntry WRENCH = REGISTRATE.item("wrench", WrenchItem::new) diff --git a/src/main/java/com/simibubi/create/AllTags.java b/src/main/java/com/simibubi/create/AllTags.java index a3542f906..51269fc2c 100644 --- a/src/main/java/com/simibubi/create/AllTags.java +++ b/src/main/java/com/simibubi/create/AllTags.java @@ -84,7 +84,8 @@ public class AllTags { INGOTS(FORGE), NUGGETS(FORGE), PLATES(FORGE), - COBBLESTONE(FORGE) + COBBLESTONE(FORGE), + SANDPAPER(MOD) ; diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/deployer/DeployerApplicationRecipe.java b/src/main/java/com/simibubi/create/content/contraptions/components/deployer/DeployerApplicationRecipe.java index c315bea50..a698ebda3 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/deployer/DeployerApplicationRecipe.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/deployer/DeployerApplicationRecipe.java @@ -19,6 +19,7 @@ import com.simibubi.create.foundation.utility.Lang; import net.minecraft.item.ItemStack; import net.minecraft.item.crafting.IRecipe; import net.minecraft.item.crafting.Ingredient; +import net.minecraft.tags.ItemTags; import net.minecraft.util.IItemProvider; import net.minecraft.util.text.ITextComponent; import net.minecraft.util.text.StringTextComponent; @@ -69,7 +70,7 @@ public class DeployerApplicationRecipe extends ProcessingRecipe i .map(r -> new ProcessingRecipeBuilder<>(DeployerApplicationRecipe::new, Create.asResource(r.getId() .getPath() + "_using_deployer")).require(r.getIngredients() .get(0)) - .require(Ingredient.of(AllItems.SAND_PAPER.get(), AllItems.RED_SAND_PAPER.get())) + .require(ItemTags.createOptional(Create.asResource("sandpaper"))) .output(r.getResultItem()) .build()) .collect(Collectors.toList()); From 8dd2f1dbf658f1e29bb67616c2d710717ec10dea Mon Sep 17 00:00:00 2001 From: simibubi <31564874+simibubi@users.noreply.github.com> Date: Thu, 5 Aug 2021 17:05:13 +0200 Subject: [PATCH 05/13] Schematic Problematic - Fixed ammo-specific fire damage not dropping cooked drops from killed entities - Fixed Schematicannons not visually aiming toward current block trajectory - Fixed placed Schematics using smaller boundaries than the original - Added the option to enable/disable placing air blocks with instant creative schematic printing - Added safety check for Missing/Migrated filter attributes #2065 - Added safety check for Crushing wheels near unloaded blocks - Added safety check for instant printing an invalid Schematic --- gradle.properties | 2 +- src/main/java/com/simibubi/create/Create.java | 2 +- .../crusher/CrushingWheelControllerBlock.java | 6 +++-- .../weapons/PotatoCannonProjectileTypes.java | 16 ++++++++++--- .../weapons/PotatoProjectileEntity.java | 2 ++ .../logistics/item/filter/FilterItem.java | 2 ++ .../content/schematics/SchematicPrinter.java | 23 +++++++++++++++---- .../packet/SchematicPlacePacket.java | 9 ++++++++ .../create/foundation/config/CSchematics.java | 3 +++ src/main/resources/META-INF/mods.toml | 2 +- 10 files changed, 54 insertions(+), 13 deletions(-) diff --git a/gradle.properties b/gradle.properties index 190398720..4da5ad71c 100644 --- a/gradle.properties +++ b/gradle.properties @@ -4,7 +4,7 @@ org.gradle.jvmargs = -Xmx3G org.gradle.daemon = false # mod version info -mod_version = 0.3.2c +mod_version = 0.3.2d minecraft_version = 1.16.5 forge_version = 36.2.0 diff --git a/src/main/java/com/simibubi/create/Create.java b/src/main/java/com/simibubi/create/Create.java index a5bc411e7..6ab5657a9 100644 --- a/src/main/java/com/simibubi/create/Create.java +++ b/src/main/java/com/simibubi/create/Create.java @@ -58,7 +58,7 @@ public class Create { public static final String ID = "create"; public static final String NAME = "Create"; - public static final String VERSION = "0.3.2c"; + public static final String VERSION = "0.3.2d"; public static final Logger LOGGER = LogManager.getLogger(); diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/crusher/CrushingWheelControllerBlock.java b/src/main/java/com/simibubi/create/content/contraptions/components/crusher/CrushingWheelControllerBlock.java index 3184f7f3b..b136458b1 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/crusher/CrushingWheelControllerBlock.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/crusher/CrushingWheelControllerBlock.java @@ -156,8 +156,10 @@ public class CrushingWheelControllerBlock extends DirectionalBlock continue; if (neighbour.getValue(BlockStateProperties.AXIS) == d.getAxis()) continue; - KineticTileEntity wheelTe = (KineticTileEntity) world.getBlockEntity(pos.relative(d)); - te.crushingspeed = Math.abs(wheelTe.getSpeed() / 50f); + TileEntity adjTe = world.getBlockEntity(pos.relative(d)); + if (!(adjTe instanceof KineticTileEntity)) + continue; + te.crushingspeed = Math.abs(((KineticTileEntity) adjTe).getSpeed() / 50f); te.sendData(); break; } diff --git a/src/main/java/com/simibubi/create/content/curiosities/weapons/PotatoCannonProjectileTypes.java b/src/main/java/com/simibubi/create/content/curiosities/weapons/PotatoCannonProjectileTypes.java index 0d19ad0a9..cb1159fbe 100644 --- a/src/main/java/com/simibubi/create/content/curiosities/weapons/PotatoCannonProjectileTypes.java +++ b/src/main/java/com/simibubi/create/content/curiosities/weapons/PotatoCannonProjectileTypes.java @@ -77,7 +77,7 @@ public class PotatoCannonProjectileTypes { .velocity(1.25f) .knockback(0.5f) .renderTumbling() - .onEntityHit(setFire(3)) + .preEntityHit(setFire(3)) .registerAndAssign(Items.BAKED_POTATO), CARROT = create("carrot").damage(4) @@ -247,7 +247,7 @@ public class PotatoCannonProjectileTypes { .velocity(1.1f) .renderTumbling() .sticky() - .onEntityHit(setFire(12)) + .preEntityHit(setFire(12)) .soundPitch(1.0f) .registerAndAssign(AllItems.BLAZE_CAKE.get()) ; @@ -286,7 +286,8 @@ public class PotatoCannonProjectileTypes { private float fwoompPitch = 1; private boolean sticky = false; private PotatoProjectileRenderMode renderMode = new PotatoProjectileRenderMode.Billboard(); - private Predicate onEntityHit = e -> false; + private Predicate preEntityHit = e -> false; // True if hit should be canceled + private Predicate onEntityHit = e -> false; // True if shouldn't recover projectile private BiPredicate onBlockHit = (w, ray) -> false; public float getGravityMultiplier() { @@ -327,6 +328,10 @@ public class PotatoCannonProjectileTypes { public boolean isSticky() { return sticky; } + public boolean preEntityHit(EntityRayTraceResult ray) { + return preEntityHit.test(ray); + } + public boolean onEntityHit(EntityRayTraceResult ray) { return onEntityHit.test(ray); } @@ -542,6 +547,11 @@ public class PotatoCannonProjectileTypes { return this; } + public Builder preEntityHit(Predicate callback) { + result.preEntityHit = callback; + return this; + } + public Builder onEntityHit(Predicate callback) { result.onEntityHit = callback; return this; diff --git a/src/main/java/com/simibubi/create/content/curiosities/weapons/PotatoProjectileEntity.java b/src/main/java/com/simibubi/create/content/curiosities/weapons/PotatoProjectileEntity.java index 6d7fd45db..0cd481f15 100644 --- a/src/main/java/com/simibubi/create/content/curiosities/weapons/PotatoProjectileEntity.java +++ b/src/main/java/com/simibubi/create/content/curiosities/weapons/PotatoProjectileEntity.java @@ -190,6 +190,8 @@ public class PotatoProjectileEntity extends DamagingProjectileEntity implements if (target instanceof WitherEntity && ((WitherEntity) target).isPowered()) return; + if (projectileType.preEntityHit(ray)) + return; boolean targetIsEnderman = target.getType() == EntityType.ENDERMAN; int k = target.getRemainingFireTicks(); diff --git a/src/main/java/com/simibubi/create/content/logistics/item/filter/FilterItem.java b/src/main/java/com/simibubi/create/content/logistics/item/filter/FilterItem.java index b6685de89..b971d7cda 100644 --- a/src/main/java/com/simibubi/create/content/logistics/item/filter/FilterItem.java +++ b/src/main/java/com/simibubi/create/content/logistics/item/filter/FilterItem.java @@ -220,6 +220,8 @@ public class FilterItem extends Item implements INamedContainerProvider { for (INBT inbt : attributes) { CompoundNBT compound = (CompoundNBT) inbt; ItemAttribute attribute = ItemAttribute.fromNBT(compound); + if (attribute == null) + continue; boolean matches = attribute.appliesTo(stack, world) != compound.getBoolean("Inverted"); if (matches) { diff --git a/src/main/java/com/simibubi/create/content/schematics/SchematicPrinter.java b/src/main/java/com/simibubi/create/content/schematics/SchematicPrinter.java index 99dd33f7a..906a907fe 100644 --- a/src/main/java/com/simibubi/create/content/schematics/SchematicPrinter.java +++ b/src/main/java/com/simibubi/create/content/schematics/SchematicPrinter.java @@ -51,7 +51,14 @@ public class SchematicPrinter { public void fromTag(CompoundNBT compound, boolean clientPacket) { if (compound.contains("CurrentPos")) currentPos = NBTUtil.readBlockPos(compound.getCompound("CurrentPos")); - + if (clientPacket) { + schematicLoaded = false; + if (compound.contains("Anchor")) { + schematicAnchor = NBTUtil.readBlockPos(compound.getCompound("Anchor")); + schematicLoaded = true; + } + } + printingEntityIndex = compound.getInt("EntityProgress"); printStage = PrintStage.valueOf(compound.getString("PrintStage")); compound.getList("DeferredBlocks", 10).stream() @@ -62,7 +69,9 @@ public class SchematicPrinter { public void write(CompoundNBT compound) { if (currentPos != null) compound.put("CurrentPos", NBTUtil.writeBlockPos(currentPos)); - + if (schematicAnchor != null) + compound.put("Anchor", NBTUtil.writeBlockPos(schematicAnchor)); + compound.putInt("EntityProgress", printingEntityIndex); compound.putString("PrintStage", printStage.name()); ListNBT tagDeferredBlocks = new ListNBT(); @@ -78,15 +87,19 @@ public class SchematicPrinter { Template activeTemplate = SchematicItem.loadSchematic(blueprint); PlacementSettings settings = SchematicItem.getSettings(blueprint, processNBT); - schematicAnchor = NBTUtil.readBlockPos(blueprint.getTag().getCompound("Anchor")); + schematicAnchor = NBTUtil.readBlockPos(blueprint.getTag() + .getCompound("Anchor")); blockReader = new SchematicWorld(schematicAnchor, originalWorld); activeTemplate.placeInWorldChunk(blockReader, schematicAnchor, settings, blockReader.getRandom()); + BlockPos extraBounds = Template.calculateRelativePosition(settings, activeTemplate.getSize() + .offset(-1, -1, -1)); + blockReader.bounds.expand(new MutableBoundingBox(extraBounds, extraBounds)); + StructureTransform transform = new StructureTransform(settings.getRotationPivot(), Direction.Axis.Y, settings.getRotation(), settings.getMirror()); - for (TileEntity te : blockReader.tileEntities.values()) { + for (TileEntity te : blockReader.tileEntities.values()) transform.apply(te); - } printingEntityIndex = -1; printStage = PrintStage.BLOCKS; diff --git a/src/main/java/com/simibubi/create/content/schematics/packet/SchematicPlacePacket.java b/src/main/java/com/simibubi/create/content/schematics/packet/SchematicPlacePacket.java index 3f6eccd0f..3331040c2 100644 --- a/src/main/java/com/simibubi/create/content/schematics/packet/SchematicPlacePacket.java +++ b/src/main/java/com/simibubi/create/content/schematics/packet/SchematicPlacePacket.java @@ -3,6 +3,7 @@ package com.simibubi.create.content.schematics.packet; import java.util.function.Supplier; import com.simibubi.create.content.schematics.SchematicPrinter; +import com.simibubi.create.foundation.config.AllConfigs; import com.simibubi.create.foundation.networking.SimplePacketBase; import com.simibubi.create.foundation.utility.BlockHelper; @@ -38,12 +39,20 @@ public class SchematicPlacePacket extends SimplePacketBase { World world = player.getLevel(); SchematicPrinter printer = new SchematicPrinter(); printer.loadSchematic(stack, world, !player.canUseGameMasterBlocks()); + if (!printer.isLoaded()) + return; + + boolean includeAir = AllConfigs.SERVER.schematics.creativePrintIncludesAir.get(); while (printer.advanceCurrentPos()) { if (!printer.shouldPlaceCurrent(world)) continue; printer.handleCurrentTarget((pos, state, tile) -> { + boolean placingAir = state.getBlock().isAir(state, world, pos); + if (placingAir && !includeAir) + return; + CompoundNBT tileData = tile != null ? tile.save(new CompoundNBT()) : null; BlockHelper.placeSchematicBlock(world, state, pos, null, tileData); }, (pos, entity) -> { diff --git a/src/main/java/com/simibubi/create/foundation/config/CSchematics.java b/src/main/java/com/simibubi/create/foundation/config/CSchematics.java index 21a38ef34..9745a8b84 100644 --- a/src/main/java/com/simibubi/create/foundation/config/CSchematics.java +++ b/src/main/java/com/simibubi/create/foundation/config/CSchematics.java @@ -2,6 +2,7 @@ package com.simibubi.create.foundation.config; public class CSchematics extends ConfigBase { + public ConfigBool creativePrintIncludesAir = b(false, "creativePrintIncludesAir", Comments.creativePrintIncludesAir); public ConfigInt maxSchematics = i(10, 1, "maxSchematics", Comments.maxSchematics); public ConfigInt maxTotalSchematicSize = i(256, 16, "maxSchematics", Comments.kb, Comments.maxSize); public ConfigInt maxSchematicPacketSize = @@ -33,6 +34,8 @@ public class CSchematics extends ConfigBase { static String skips = "Amount of block positions per tick scanned by a running cannon. Higher => Faster"; static String gunpowderWorth = "% of Schematicannon's Fuel filled by 1 Gunpowder."; static String fuelUsage = "% of Schematicannon's Fuel used for each fired block."; + static String creativePrintIncludesAir = + "Whether placing a Schematic directly in Creative Mode should replace world blocks with Air"; } } diff --git a/src/main/resources/META-INF/mods.toml b/src/main/resources/META-INF/mods.toml index b3457e6a6..c932c8408 100644 --- a/src/main/resources/META-INF/mods.toml +++ b/src/main/resources/META-INF/mods.toml @@ -5,7 +5,7 @@ license="MIT" [[mods]] modId="create" -version="v0.3.2c for 1.16.5" +version="v0.3.2d" displayName="Create" #updateJSONURL="" displayURL="https://www.curseforge.com/minecraft/mc-mods/create" From 9f558cf419a4d8a272f3acd53b08f100f5448f1b Mon Sep 17 00:00:00 2001 From: simibubi <31564874+simibubi@users.noreply.github.com> Date: Thu, 5 Aug 2021 19:11:13 +0200 Subject: [PATCH 06/13] Not a magic mod - Fixed Auto-Compacting picking up special gated recipes from the mod Occultism #2070 --- .../simibubi/create/compat/jei/CreateJEI.java | 4 ++-- .../press/MechanicalPressTileEntity.java | 19 +++++++++++++++++-- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/simibubi/create/compat/jei/CreateJEI.java b/src/main/java/com/simibubi/create/compat/jei/CreateJEI.java index da8730eaa..2cf7dcf90 100644 --- a/src/main/java/com/simibubi/create/compat/jei/CreateJEI.java +++ b/src/main/java/com/simibubi/create/compat/jei/CreateJEI.java @@ -123,7 +123,7 @@ public class CreateJEI implements IModPlugin { autoShapeless = register("automatic_shapeless", MixingCategory::autoShapeless) .recipes(r -> r.getSerializer() == IRecipeSerializer.SHAPELESS_RECIPE && r.getIngredients() - .size() > 1 && !MechanicalPressTileEntity.canCompress(r.getIngredients()), + .size() > 1 && !MechanicalPressTileEntity.canCompress(r), BasinRecipe::convertShapeless) .catalyst(AllBlocks.MECHANICAL_MIXER::get) .catalyst(AllBlocks.BASIN::get) @@ -160,7 +160,7 @@ public class CreateJEI implements IModPlugin { .build(), autoSquare = register("automatic_packing", PackingCategory::autoSquare) - .recipes(r -> (r instanceof ICraftingRecipe) && MechanicalPressTileEntity.canCompress(r.getIngredients()), + .recipes(r -> (r instanceof ICraftingRecipe) && MechanicalPressTileEntity.canCompress(r), BasinRecipe::convertShapeless) .catalyst(AllBlocks.MECHANICAL_PRESS::get) .catalyst(AllBlocks.BASIN::get) diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/press/MechanicalPressTileEntity.java b/src/main/java/com/simibubi/create/content/contraptions/components/press/MechanicalPressTileEntity.java index 27ac4f416..059067cfd 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/press/MechanicalPressTileEntity.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/press/MechanicalPressTileEntity.java @@ -4,6 +4,7 @@ import java.util.ArrayList; import java.util.List; import java.util.Optional; +import com.google.common.collect.ImmutableList; import com.simibubi.create.AllBlocks; import com.simibubi.create.AllRecipeTypes; import com.simibubi.create.AllSoundEvents; @@ -31,12 +32,14 @@ import net.minecraft.inventory.IInventory; import net.minecraft.item.ItemStack; import net.minecraft.item.crafting.ICraftingRecipe; import net.minecraft.item.crafting.IRecipe; +import net.minecraft.item.crafting.IRecipeSerializer; import net.minecraft.item.crafting.Ingredient; import net.minecraft.nbt.CompoundNBT; import net.minecraft.particles.ItemParticleData; import net.minecraft.particles.ParticleTypes; import net.minecraft.tileentity.TileEntityType; import net.minecraft.util.NonNullList; +import net.minecraft.util.ResourceLocation; import net.minecraft.util.math.AxisAlignedBB; import net.minecraft.util.math.MathHelper; import net.minecraft.util.math.vector.Vector3d; @@ -339,7 +342,19 @@ public class MechanicalPressTileEntity extends BasinOperatingTileEntity { return AllRecipeTypes.PRESSING.find(pressingInv, level); } - public static boolean canCompress(NonNullList ingredients) { + private static final List RECIPE_DENY_LIST = + ImmutableList.of(new ResourceLocation("occultism", "spirit_trade")); + + public static boolean canCompress(IRecipe recipe) { + NonNullList ingredients = recipe.getIngredients(); + if (!(recipe instanceof ICraftingRecipe)) + return false; + + IRecipeSerializer serializer = recipe.getSerializer(); + for (ResourceLocation denied : RECIPE_DENY_LIST) + if (serializer != null && denied.equals(serializer.getRegistryName())) + return false; + return AllConfigs.SERVER.recipes.allowShapedSquareInPress.get() && (ingredients.size() == 4 || ingredients.size() == 9) && ItemHelper.condenseIngredients(ingredients) .size() == 1; @@ -347,7 +362,7 @@ public class MechanicalPressTileEntity extends BasinOperatingTileEntity { @Override protected boolean matchStaticFilters(IRecipe recipe) { - return (recipe instanceof ICraftingRecipe && canCompress(recipe.getIngredients())) + return (recipe instanceof ICraftingRecipe && canCompress(recipe)) || recipe.getType() == AllRecipeTypes.COMPACTING.getType(); } From b81fc66145f031d4b6f3c1f60e663b2c26f7c249 Mon Sep 17 00:00:00 2001 From: PepperBell <44146161+PepperCode1@users.noreply.github.com> Date: Thu, 5 Aug 2021 10:23:59 -0700 Subject: [PATCH 07/13] Sandpaper tag improvements - Use already created sandpaper tag - Use previous recipe's namespace instead of Create's when converting sandpaper recipes to deployer recipes --- src/main/java/com/simibubi/create/AllItems.java | 2 +- src/main/java/com/simibubi/create/AllTags.java | 4 ++-- .../deployer/DeployerApplicationRecipe.java | 13 ++++++------- 3 files changed, 9 insertions(+), 10 deletions(-) diff --git a/src/main/java/com/simibubi/create/AllItems.java b/src/main/java/com/simibubi/create/AllItems.java index 728ac0894..36885956c 100644 --- a/src/main/java/com/simibubi/create/AllItems.java +++ b/src/main/java/com/simibubi/create/AllItems.java @@ -233,8 +233,8 @@ public class AllItems { public static final ItemEntry RED_SAND_PAPER = REGISTRATE.item("red_sand_paper", SandPaperItem::new) .transform(CreateRegistrate.customRenderedItem(() -> SandPaperModel::new)) - .onRegister(s -> TooltipHelper.referTo(s, SAND_PAPER)) .tag(AllTags.AllItemTags.SANDPAPER.tag) + .onRegister(s -> TooltipHelper.referTo(s, SAND_PAPER)) .register(); public static final ItemEntry WRENCH = REGISTRATE.item("wrench", WrenchItem::new) diff --git a/src/main/java/com/simibubi/create/AllTags.java b/src/main/java/com/simibubi/create/AllTags.java index 51269fc2c..f0328a5e6 100644 --- a/src/main/java/com/simibubi/create/AllTags.java +++ b/src/main/java/com/simibubi/create/AllTags.java @@ -79,13 +79,13 @@ public class AllTags { SEATS(MOD), VALVE_HANDLES(MOD), UPRIGHT_ON_BELT(MOD), + SANDPAPER(MOD), CREATE_INGOTS(MOD), BEACON_PAYMENT(FORGE), INGOTS(FORGE), NUGGETS(FORGE), PLATES(FORGE), - COBBLESTONE(FORGE), - SANDPAPER(MOD) + COBBLESTONE(FORGE) ; diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/deployer/DeployerApplicationRecipe.java b/src/main/java/com/simibubi/create/content/contraptions/components/deployer/DeployerApplicationRecipe.java index a698ebda3..3fb54e05f 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/deployer/DeployerApplicationRecipe.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/deployer/DeployerApplicationRecipe.java @@ -6,9 +6,8 @@ import java.util.function.Supplier; import java.util.stream.Collectors; import com.simibubi.create.AllBlocks; -import com.simibubi.create.AllItems; import com.simibubi.create.AllRecipeTypes; -import com.simibubi.create.Create; +import com.simibubi.create.AllTags.AllItemTags; import com.simibubi.create.compat.jei.category.sequencedAssembly.SequencedAssemblySubCategory; import com.simibubi.create.content.contraptions.itemAssembly.IAssemblyRecipe; import com.simibubi.create.content.contraptions.processing.ProcessingRecipe; @@ -19,8 +18,8 @@ import com.simibubi.create.foundation.utility.Lang; import net.minecraft.item.ItemStack; import net.minecraft.item.crafting.IRecipe; import net.minecraft.item.crafting.Ingredient; -import net.minecraft.tags.ItemTags; import net.minecraft.util.IItemProvider; +import net.minecraft.util.ResourceLocation; import net.minecraft.util.text.ITextComponent; import net.minecraft.util.text.StringTextComponent; import net.minecraft.util.text.TranslationTextComponent; @@ -67,10 +66,10 @@ public class DeployerApplicationRecipe extends ProcessingRecipe i public static List convert(List> sandpaperRecipes) { return sandpaperRecipes.stream() - .map(r -> new ProcessingRecipeBuilder<>(DeployerApplicationRecipe::new, Create.asResource(r.getId() + .map(r -> new ProcessingRecipeBuilder<>(DeployerApplicationRecipe::new, new ResourceLocation(r.getId().getNamespace(), r.getId() .getPath() + "_using_deployer")).require(r.getIngredients() .get(0)) - .require(ItemTags.createOptional(Create.asResource("sandpaper"))) + .require(AllItemTags.SANDPAPER.tag) .output(r.getResultItem()) .build()) .collect(Collectors.toList()); @@ -80,7 +79,7 @@ public class DeployerApplicationRecipe extends ProcessingRecipe i public void addAssemblyIngredients(List list) { list.add(ingredients.get(1)); } - + @Override @OnlyIn(Dist.CLIENT) public ITextComponent getDescriptionForAssembly() { @@ -96,7 +95,7 @@ public class DeployerApplicationRecipe extends ProcessingRecipe i public void addRequiredMachines(Set list) { list.add(AllBlocks.DEPLOYER.get()); } - + @Override public Supplier> getJEISubCategory() { return () -> SequencedAssemblySubCategory.AssemblyDeploying::new; From 3e6e8c406b1af27824bd08926b513c16f0ad7250 Mon Sep 17 00:00:00 2001 From: Jozufozu Date: Wed, 4 Aug 2021 17:20:08 -0700 Subject: [PATCH 08/13] Bump Flywheel version - Small tweak to contraption layer creation --- gradle.properties | 2 +- .../structureMovement/render/RenderedContraption.java | 7 +++++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/gradle.properties b/gradle.properties index 4da5ad71c..984e19f84 100644 --- a/gradle.properties +++ b/gradle.properties @@ -16,7 +16,7 @@ cursegradle_version = 1.4.0 # dependency versions registrate_version = 1.0.10 -flywheel_version = 1.16-0.2.0.34 +flywheel_version = 1.16-0.2.0.41 jei_version = 7.7.1.116 # curseforge information diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/render/RenderedContraption.java b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/render/RenderedContraption.java index 6dc366b95..0d20a6435 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/render/RenderedContraption.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/render/RenderedContraption.java @@ -125,10 +125,13 @@ public class RenderedContraption extends ContraptionRenderInfo { for (RenderType layer : blockLayers) { Supplier layerModel = () -> new WorldModel(renderWorld, layer, contraption.getBlocks().values()); + ModelRenderer renderer; if (Backend.getInstance().compat.vertexArrayObjectsSupported()) - renderLayers.put(layer, new ArrayModelRenderer(layerModel)); + renderer = new ArrayModelRenderer(layerModel); else - renderLayers.put(layer, new ModelRenderer(layerModel)); + renderer = new ModelRenderer(layerModel); + + renderLayers.put(layer, renderer); } } From e7c7669d7f1195da8c3db2e718ae512921f84822 Mon Sep 17 00:00:00 2001 From: Jozufozu Date: Thu, 5 Aug 2021 14:57:55 -0700 Subject: [PATCH 09/13] Setup build script for maven --- build.gradle | 34 ++++++++++++++++++++++++++++++++++ settings.gradle | 1 + 2 files changed, 35 insertions(+) create mode 100644 settings.gradle diff --git a/build.gradle b/build.gradle index 56d6fb380..676d87dba 100644 --- a/build.gradle +++ b/build.gradle @@ -187,6 +187,40 @@ reobf { shadowJar {} } + +task sourcesJar(type: Jar) { + from sourceSets.main.allSource + archiveBaseName.set(project.archivesBaseName) + archiveVersion.set("${project.version}") + archiveClassifier.set('sources') +} + +task javadocJar(type: Jar, dependsOn: javadoc) { + from javadoc.destinationDir + archiveClassifier.set('javadoc') +} + +artifacts { + archives shadowJar, sourcesJar, javadocJar +} + +publishing { + tasks.publish.dependsOn 'build' + publications { + mavenJava(MavenPublication) { + artifact shadowJar + artifact sourcesJar + artifact javadocJar + } + } + + repositories { + if (project.hasProperty('mavendir')) { + maven { url mavendir } + } + } +} + String getChangelogText() { def changelogFile = file('changelog.txt') String str = '' diff --git a/settings.gradle b/settings.gradle new file mode 100644 index 000000000..ecc4e7182 --- /dev/null +++ b/settings.gradle @@ -0,0 +1 @@ +rootProject.name = 'Create' From 26fbe97ae62ed269cd5f6833f6bed2b932a8a144 Mon Sep 17 00:00:00 2001 From: Jozufozu Date: Thu, 5 Aug 2021 15:05:32 -0700 Subject: [PATCH 10/13] Fix contraption shadow rendering with optifine - More conventional naming for fields of ContraptionMatrices - Encapsulate fields in ContraptionMatrices - Move creation to RenderLayerEvent - De-clutter RenderedContraption#beginFrame - Bump flywheel version --- gradle.properties | 2 +- .../components/actors/DrillRenderer.java | 6 +- .../components/actors/HarvesterRenderer.java | 6 +- .../PortableStorageInterfaceRenderer.java | 4 +- .../components/deployer/DeployerRenderer.java | 10 +-- .../components/saw/SawRenderer.java | 6 +- .../ContraptionEntityRenderer.java | 3 +- .../StabilizedBearingMovementBehaviour.java | 6 +- .../render/ContraptionMatrices.java | 85 ++++++++++++------- .../render/ContraptionRenderDispatcher.java | 27 +++--- .../render/ContraptionRenderInfo.java | 44 +++++++--- .../render/ContraptionRenderManager.java | 6 +- .../render/FlwContraptionManager.java | 2 + .../render/RenderedContraption.java | 24 ++---- .../render/SBBContraptionManager.java | 9 +- src/main/resources/META-INF/mods.toml | 2 +- 16 files changed, 140 insertions(+), 102 deletions(-) diff --git a/gradle.properties b/gradle.properties index 984e19f84..dff493265 100644 --- a/gradle.properties +++ b/gradle.properties @@ -16,7 +16,7 @@ cursegradle_version = 1.4.0 # dependency versions registrate_version = 1.0.10 -flywheel_version = 1.16-0.2.0.41 +flywheel_version = 1.16-0.2.3.44 jei_version = 7.7.1.116 # curseforge information diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/actors/DrillRenderer.java b/src/main/java/com/simibubi/create/content/contraptions/components/actors/DrillRenderer.java index 3a81d4509..7270d25ec 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/actors/DrillRenderer.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/actors/DrillRenderer.java @@ -44,7 +44,7 @@ public class DrillRenderer extends KineticTileEntityRenderer { float time = AnimationTickHolder.getRenderTime() / 20; float angle = (float) (((time * speed) % 360)); - MatrixStack m = matrices.contraptionStack; + MatrixStack m = matrices.getModel(); m.pushPose(); MatrixTransformStack.of(m) .centre() @@ -55,9 +55,9 @@ public class DrillRenderer extends KineticTileEntityRenderer { superBuffer .transform(m) - .light(matrices.entityMatrix, + .light(matrices.getWorld(), ContraptionRenderDispatcher.getContraptionWorldLight(context, renderWorld)) - .renderInto(matrices.entityStack, buffer.getBuffer(RenderType.solid())); + .renderInto(matrices.getViewProjection(), buffer.getBuffer(RenderType.solid())); m.popPose(); } diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/actors/HarvesterRenderer.java b/src/main/java/com/simibubi/create/content/contraptions/components/actors/HarvesterRenderer.java index 79eee6a0a..0aac5f333 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/actors/HarvesterRenderer.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/actors/HarvesterRenderer.java @@ -52,13 +52,13 @@ public class HarvesterRenderer extends SafeTileEntityRenderer sbb.light(matrices.entityMatrix, + render(blockState, lit, progress, matrices.getModel(), sbb -> sbb.light(matrices.getWorld(), ContraptionRenderDispatcher.getContraptionWorldLight(context, renderWorld)) - .renderInto(matrices.entityStack, vb)); + .renderInto(matrices.getViewProjection(), vb)); } private static void render(BlockState blockState, boolean lit, float progress, diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/deployer/DeployerRenderer.java b/src/main/java/com/simibubi/create/content/contraptions/components/deployer/DeployerRenderer.java index 72b799cb3..c639e1bf4 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/deployer/DeployerRenderer.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/deployer/DeployerRenderer.java @@ -181,7 +181,7 @@ public class DeployerRenderer extends SafeTileEntityRenderer Vector3d offset = Vector3d.atLowerCornerOf(blockState.getValue(FACING) .getNormal()).scale(factor); - MatrixStack m = matrices.contraptionStack; + MatrixStack m = matrices.getModel(); m.pushPose(); m.translate(offset.x, offset.y, offset.z); @@ -190,10 +190,10 @@ public class DeployerRenderer extends SafeTileEntityRenderer pole = transform(world, pole, blockState, pos, true); hand = transform(world, hand, blockState, pos, false); - pole.light(matrices.entityMatrix, ContraptionRenderDispatcher.getContraptionWorldLight(context, renderWorld)) - .renderInto(matrices.entityStack, builder); - hand.light(matrices.entityMatrix, ContraptionRenderDispatcher.getContraptionWorldLight(context, renderWorld)) - .renderInto(matrices.entityStack, builder); + pole.light(matrices.getWorld(), ContraptionRenderDispatcher.getContraptionWorldLight(context, renderWorld)) + .renderInto(matrices.getViewProjection(), builder); + hand.light(matrices.getWorld(), ContraptionRenderDispatcher.getContraptionWorldLight(context, renderWorld)) + .renderInto(matrices.getViewProjection(), builder); m.popPose(); } diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/saw/SawRenderer.java b/src/main/java/com/simibubi/create/content/contraptions/components/saw/SawRenderer.java index 91e468f99..4f52cd5d8 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/saw/SawRenderer.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/saw/SawRenderer.java @@ -192,7 +192,7 @@ public class SawRenderer extends SafeTileEntityRenderer { superBuffer = PartialBufferer.get(AllBlockPartials.SAW_BLADE_VERTICAL_INACTIVE, state); } - MatrixStack m = matrices.contraptionStack; + MatrixStack m = matrices.getModel(); m.pushPose(); MatrixTransformStack.of(m) .centre() @@ -205,8 +205,8 @@ public class SawRenderer extends SafeTileEntityRenderer { .unCentre(); superBuffer.transform(m) - .light(matrices.entityMatrix, ContraptionRenderDispatcher.getContraptionWorldLight(context, renderWorld)) - .renderInto(matrices.entityStack, buffer.getBuffer(RenderType.cutoutMipped())); + .light(matrices.getWorld(), ContraptionRenderDispatcher.getContraptionWorldLight(context, renderWorld)) + .renderInto(matrices.getViewProjection(), buffer.getBuffer(RenderType.cutoutMipped())); m.popPose(); } diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/ContraptionEntityRenderer.java b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/ContraptionEntityRenderer.java index 57e249dcf..8be7f7b41 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/ContraptionEntityRenderer.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/ContraptionEntityRenderer.java @@ -1,7 +1,6 @@ package com.simibubi.create.content.contraptions.components.structureMovement; import com.mojang.blaze3d.matrix.MatrixStack; -import com.simibubi.create.content.contraptions.components.structureMovement.render.ContraptionMatrices; import com.simibubi.create.content.contraptions.components.structureMovement.render.ContraptionRenderDispatcher; import net.minecraft.client.renderer.IRenderTypeBuffer; @@ -39,7 +38,7 @@ public class ContraptionEntityRenderer exte Contraption contraption = entity.getContraption(); if (contraption != null) { - ContraptionRenderDispatcher.render(entity, contraption, buffers); + ContraptionRenderDispatcher.renderFromEntity(entity, contraption, buffers); } } diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/bearing/StabilizedBearingMovementBehaviour.java b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/bearing/StabilizedBearingMovementBehaviour.java index 82ae9b925..2e03a363e 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/bearing/StabilizedBearingMovementBehaviour.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/bearing/StabilizedBearingMovementBehaviour.java @@ -53,14 +53,14 @@ public class StabilizedBearingMovementBehaviour extends MovementBehaviour { orientation = rotation; - superBuffer.transform(matrices.contraptionStack); + superBuffer.transform(matrices.getModel()); superBuffer.rotateCentered(orientation); // render superBuffer - .light(matrices.entityMatrix, + .light(matrices.getWorld(), ContraptionRenderDispatcher.getContraptionWorldLight(context, renderWorld)) - .renderInto(matrices.entityStack, buffer.getBuffer(RenderType.solid())); + .renderInto(matrices.getViewProjection(), buffer.getBuffer(RenderType.solid())); } @Override diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/render/ContraptionMatrices.java b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/render/ContraptionMatrices.java index 202d5dddf..f2c43dfeb 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/render/ContraptionMatrices.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/render/ContraptionMatrices.java @@ -6,9 +6,16 @@ import com.simibubi.create.foundation.utility.AnimationTickHolder; import net.minecraft.entity.Entity; import net.minecraft.util.math.MathHelper; -import net.minecraft.util.math.vector.Matrix3f; import net.minecraft.util.math.vector.Matrix4f; +import net.minecraft.util.math.vector.Vector3d; +/** + * LIFETIME: one frame + * + *

+ * ContraptionMatrices must be re-created per-contraption per-frame + *

+ */ public class ContraptionMatrices { /** @@ -16,47 +23,68 @@ public class ContraptionMatrices { */ public static final ContraptionMatrices EMPTY = new ContraptionMatrices(); - public final MatrixStack entityStack; - public final MatrixStack contraptionStack; - public final MatrixStack finalStack; - public final Matrix4f entityMatrix; - public final Matrix4f lightMatrix; + private final MatrixStack modelViewProjection; + private final MatrixStack viewProjection; + private final MatrixStack model; + private final Matrix4f world; + private final Matrix4f light; private ContraptionMatrices() { - this.entityStack = this.contraptionStack = this.finalStack = new MatrixStack(); - this.entityMatrix = new Matrix4f(); - this.lightMatrix = new Matrix4f(); + this.viewProjection = this.model = this.modelViewProjection = new MatrixStack(); + this.world = new Matrix4f(); + this.light = new Matrix4f(); } - public ContraptionMatrices(MatrixStack entityStack, AbstractContraptionEntity entity) { - this.entityStack = copyStack(entityStack); - this.contraptionStack = new MatrixStack(); + public ContraptionMatrices(MatrixStack viewProjection, AbstractContraptionEntity entity) { + this.viewProjection = copyStack(viewProjection); float partialTicks = AnimationTickHolder.getPartialTicks(); - entity.doLocalTransforms(partialTicks, new MatrixStack[] { this.contraptionStack }); + this.model = creatModelMatrix(entity, partialTicks); - entityMatrix = translateTo(entity, partialTicks); + world = translateTo(entity, partialTicks); - lightMatrix = entityMatrix.copy(); - lightMatrix.multiply(contraptionStack.last().pose()); + light = getWorld().copy(); + getLight().multiply(this.getModel() + .last().pose()); - finalStack = copyStack(entityStack); - transform(finalStack, contraptionStack); + modelViewProjection = copyStack(viewProjection); + transform(getModelViewProjection(), this.getModel()); } - public MatrixStack getFinalStack() { - return finalStack; + public MatrixStack getModelViewProjection() { + return modelViewProjection; } - public Matrix4f getFinalModel() { - return finalStack.last().pose(); + public MatrixStack getViewProjection() { + return viewProjection; } - public Matrix3f getFinalNormal() { - return finalStack.last().normal(); + public MatrixStack getModel() { + return model; } - public Matrix4f getFinalLight() { - return lightMatrix; + public Matrix4f getWorld() { + return world; + } + + public Matrix4f getLight() { + return light; + } + + public static Matrix4f createModelViewPartial(AbstractContraptionEntity entity, float pt, Vector3d cameraPos) { + float x = (float) (MathHelper.lerp(pt, entity.xOld, entity.getX()) - cameraPos.x); + float y = (float) (MathHelper.lerp(pt, entity.yOld, entity.getY()) - cameraPos.y); + float z = (float) (MathHelper.lerp(pt, entity.zOld, entity.getZ()) - cameraPos.z); + Matrix4f mat = Matrix4f.createTranslateMatrix(x, y, z); + Matrix4f modelMatrix = creatModelMatrix(entity, pt).last().pose(); + + mat.multiply(modelMatrix); + return mat; + } + + public static MatrixStack creatModelMatrix(AbstractContraptionEntity entity, float partialTicks) { + MatrixStack model = new MatrixStack(); + entity.doLocalTransforms(partialTicks, new MatrixStack[] { model}); + return model; } public static Matrix4f translateTo(Entity entity, float partialTicks) { @@ -82,9 +110,4 @@ public class ContraptionMatrices { return cms; } - - public Matrix4f contraptionPose() { - return contraptionStack.last() - .pose(); - } } diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/render/ContraptionRenderDispatcher.java b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/render/ContraptionRenderDispatcher.java index 2d98ca770..ddcadab07 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/render/ContraptionRenderDispatcher.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/render/ContraptionRenderDispatcher.java @@ -71,13 +71,24 @@ public class ContraptionRenderDispatcher { reset(); } - public static void render(AbstractContraptionEntity entity, Contraption contraption, IRenderTypeBuffer buffers) { + public static void renderFromEntity(AbstractContraptionEntity entity, Contraption contraption, IRenderTypeBuffer buffers) { World world = entity.level; ContraptionRenderInfo renderInfo = WORLDS.get(world) .getRenderInfo(contraption); + ContraptionMatrices matrices = renderInfo.getMatrices(); - renderDynamic(world, renderInfo.renderWorld, contraption, renderInfo.getMatrices(), buffers); + // something went wrong with the other rendering + if (matrices == null) return; + + PlacementSimulationWorld renderWorld = renderInfo.renderWorld; + + renderTileEntities(world, renderWorld, contraption, matrices, buffers); + + if (buffers instanceof IRenderTypeBuffer.Impl) + ((IRenderTypeBuffer.Impl) buffers).endBatch(); + + renderActors(world, renderWorld, contraption, matrices, buffers); } public static PlacementSimulationWorld setupRenderWorld(World world, Contraption c) { @@ -96,18 +107,10 @@ public class ContraptionRenderDispatcher { return renderWorld; } - public static void renderDynamic(World world, PlacementSimulationWorld renderWorld, Contraption c, - ContraptionMatrices matrices, IRenderTypeBuffer buffer) { - renderTileEntities(world, renderWorld, c, matrices, buffer); - if (buffer instanceof IRenderTypeBuffer.Impl) - ((IRenderTypeBuffer.Impl) buffer).endBatch(); - renderActors(world, renderWorld, c, matrices, buffer); - } - public static void renderTileEntities(World world, PlacementSimulationWorld renderWorld, Contraption c, ContraptionMatrices matrices, IRenderTypeBuffer buffer) { TileEntityRenderHelper.renderTileEntities(world, renderWorld, c.specialRenderedTileEntities, - matrices.getFinalStack(), matrices.getFinalLight(), buffer); + matrices.getModelViewProjection(), matrices.getLight(), buffer); } protected static void renderActors(World world, PlacementSimulationWorld renderWorld, Contraption c, @@ -120,7 +123,7 @@ public class ContraptionRenderDispatcher { context.world = world; Template.BlockInfo blockInfo = actor.getLeft(); - MatrixStack m = matrices.contraptionStack; + MatrixStack m = matrices.getModel(); m.pushPose(); MatrixTransformStack.of(m) .translate(blockInfo.pos); diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/render/ContraptionRenderInfo.java b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/render/ContraptionRenderInfo.java index db8c3e764..1000aeed2 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/render/ContraptionRenderInfo.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/render/ContraptionRenderInfo.java @@ -1,6 +1,10 @@ package com.simibubi.create.content.contraptions.components.structureMovement.render; +import javax.annotation.Nullable; + import com.jozufozu.flywheel.event.BeginFrameEvent; +import com.jozufozu.flywheel.event.RenderLayerEvent; +import com.mojang.blaze3d.matrix.MatrixStack; import com.simibubi.create.content.contraptions.components.structureMovement.AbstractContraptionEntity; import com.simibubi.create.content.contraptions.components.structureMovement.Contraption; import com.simibubi.create.foundation.utility.AnimationTickHolder; @@ -30,29 +34,41 @@ public class ContraptionRenderInfo { } public void beginFrame(BeginFrameEvent event) { + matrices = null; + AbstractContraptionEntity entity = contraption.entity; visible = event.getClippingHelper().isVisible(entity.getBoundingBoxForCulling().inflate(2)); - - event.getStack().pushPose(); - - Vector3d cameraPos = event.getInfo() - .getPosition(); - double x = MathHelper.lerp(AnimationTickHolder.getPartialTicks(), entity.xOld, entity.getX()) - cameraPos.x; - double y = MathHelper.lerp(AnimationTickHolder.getPartialTicks(), entity.yOld, entity.getY()) - cameraPos.y; - double z = MathHelper.lerp(AnimationTickHolder.getPartialTicks(), entity.zOld, entity.getZ()) - cameraPos.z; - - event.getStack().translate(x, y, z); - - matrices = new ContraptionMatrices(event.getStack(), entity); - - event.getStack().popPose(); } public boolean isVisible() { return visible && contraption.entity.isAlive(); } + /** + * Need to call this during RenderLayerEvent. + */ + public void setupMatrices(MatrixStack viewProjection, double camX, double camY, double camZ) { + if (matrices == null) { + AbstractContraptionEntity entity = contraption.entity; + + viewProjection.pushPose(); + + double x = MathHelper.lerp(AnimationTickHolder.getPartialTicks(), entity.xOld, entity.getX()) - camX; + double y = MathHelper.lerp(AnimationTickHolder.getPartialTicks(), entity.yOld, entity.getY()) - camY; + double z = MathHelper.lerp(AnimationTickHolder.getPartialTicks(), entity.zOld, entity.getZ()) - camZ; + + viewProjection.translate(x, y, z); + + matrices = new ContraptionMatrices(viewProjection, entity); + + viewProjection.popPose(); + } + } + + /** + * If #setupMatrices is called correctly, this will not return null + */ public ContraptionMatrices getMatrices() { return matrices; } diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/render/ContraptionRenderManager.java b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/render/ContraptionRenderManager.java index 8d94a681a..735d569f1 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/render/ContraptionRenderManager.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/render/ContraptionRenderManager.java @@ -29,7 +29,11 @@ public abstract class ContraptionRenderManager this.world = (World) world; } - public abstract void renderLayer(RenderLayerEvent event); + public void renderLayer(RenderLayerEvent event) { + for (C c : visible) { + c.setupMatrices(event.stack, event.camX, event.camY, event.camZ); + } + } protected abstract C create(Contraption c); diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/render/FlwContraptionManager.java b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/render/FlwContraptionManager.java index 3aff78682..efd42ad70 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/render/FlwContraptionManager.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/render/FlwContraptionManager.java @@ -38,6 +38,8 @@ public class FlwContraptionManager extends ContraptionRenderManager renderLayers = new HashMap<>(); - private Matrix4f model; + private Matrix4f modelViewPartial; private AxisAlignedBB lightBox; public RenderedContraption(Contraption contraption, PlacementSimulationWorld renderWorld) { @@ -78,26 +77,17 @@ public class RenderedContraption extends ContraptionRenderInfo { kinetics.beginFrame(event.getInfo()); - AbstractContraptionEntity entity = contraption.entity; - float pt = AnimationTickHolder.getPartialTicks(); - AxisAlignedBB lightBox = GridAlignedBB.toAABB(lighter.lightVolume.getTextureVolume()); + Vector3d cameraPos = event.getCameraPos(); - Vector3d cameraPos = event.getInfo() - .getPosition(); + modelViewPartial = ContraptionMatrices.createModelViewPartial(contraption.entity, AnimationTickHolder.getPartialTicks(), cameraPos); - float x = (float) (MathHelper.lerp(pt, entity.xOld, entity.getX()) - cameraPos.x); - float y = (float) (MathHelper.lerp(pt, entity.yOld, entity.getY()) - cameraPos.y); - float z = (float) (MathHelper.lerp(pt, entity.zOld, entity.getZ()) - cameraPos.z); - model = Matrix4f.createTranslateMatrix(x, y, z); - - model.multiply(getMatrices().contraptionPose()); - - this.lightBox = lightBox.move(-cameraPos.x, -cameraPos.y, -cameraPos.z); + lightBox = GridAlignedBB.toAABB(lighter.lightVolume.getTextureVolume()) + .move(-cameraPos.x, -cameraPos.y, -cameraPos.z); } void setup(ContraptionProgram shader) { - if (model == null || lightBox == null) return; - shader.bind(model, lightBox); + if (modelViewPartial == null || lightBox == null) return; + shader.bind(modelViewPartial, lightBox); lighter.lightVolume.bind(); } diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/render/SBBContraptionManager.java b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/render/SBBContraptionManager.java index 94f0fec6d..4c68ea22c 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/render/SBBContraptionManager.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/render/SBBContraptionManager.java @@ -21,6 +21,7 @@ public class SBBContraptionManager extends ContraptionRenderManager renderContraptionLayerSBB(event, info)); } @@ -38,12 +39,12 @@ public class SBBContraptionManager extends ContraptionRenderManager buildStructureBuffer(renderInfo.renderWorld, renderInfo.contraption, layer)); if (!contraptionBuffer.isEmpty()) { - ContraptionMatrices matrices = renderInfo.getMatrices(); - contraptionBuffer.transform(matrices.contraptionStack) - .light(matrices.entityMatrix) + + contraptionBuffer.transform(matrices.getModel()) + .light(matrices.getWorld()) .hybridLight() - .renderInto(matrices.entityStack, event.buffers.bufferSource() + .renderInto(matrices.getViewProjection(), event.buffers.bufferSource() .getBuffer(layer)); } diff --git a/src/main/resources/META-INF/mods.toml b/src/main/resources/META-INF/mods.toml index c932c8408..4f944f0a4 100644 --- a/src/main/resources/META-INF/mods.toml +++ b/src/main/resources/META-INF/mods.toml @@ -32,6 +32,6 @@ Technology that empowers the player.''' [[dependencies.create]] modId="flywheel" mandatory=true - versionRange="[1.16-0.2,1.16-0.3)" + versionRange="[1.16-0.2.3,1.16-0.3)" ordering="AFTER" side="CLIENT" From 333ef9ecbb93bb6efba45dda91f4cfbaa0ce30c5 Mon Sep 17 00:00:00 2001 From: PepperBell <44146161+PepperCode1@users.noreply.github.com> Date: Thu, 5 Aug 2021 17:48:35 -0700 Subject: [PATCH 11/13] Reuse contraption matrices - Optimize memory usage by reusing ContraptionMatrices instances --- .../render/ContraptionMatrices.java | 100 ++++++++---------- .../render/ContraptionRenderDispatcher.java | 2 +- .../render/ContraptionRenderInfo.java | 14 +-- .../render/RenderedContraption.java | 31 +++++- 4 files changed, 80 insertions(+), 67 deletions(-) diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/render/ContraptionMatrices.java b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/render/ContraptionMatrices.java index f2c43dfeb..733ff004d 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/render/ContraptionMatrices.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/render/ContraptionMatrices.java @@ -7,47 +7,55 @@ import com.simibubi.create.foundation.utility.AnimationTickHolder; import net.minecraft.entity.Entity; import net.minecraft.util.math.MathHelper; import net.minecraft.util.math.vector.Matrix4f; -import net.minecraft.util.math.vector.Vector3d; /** - * LIFETIME: one frame - * *

- * ContraptionMatrices must be re-created per-contraption per-frame + * ContraptionMatrices must be cleared and setup per-contraption per-frame *

*/ public class ContraptionMatrices { - /** - * The results from using this are undefined. - */ - public static final ContraptionMatrices EMPTY = new ContraptionMatrices(); + private final MatrixStack modelViewProjection = new MatrixStack(); + private final MatrixStack viewProjection = new MatrixStack(); + private final MatrixStack model = new MatrixStack(); + private final Matrix4f world = new Matrix4f(); + private final Matrix4f light = new Matrix4f(); - private final MatrixStack modelViewProjection; - private final MatrixStack viewProjection; - private final MatrixStack model; - private final Matrix4f world; - private final Matrix4f light; + private boolean ready; - private ContraptionMatrices() { - this.viewProjection = this.model = this.modelViewProjection = new MatrixStack(); - this.world = new Matrix4f(); - this.light = new Matrix4f(); + public ContraptionMatrices() { + world.setIdentity(); + light.setIdentity(); } - public ContraptionMatrices(MatrixStack viewProjection, AbstractContraptionEntity entity) { - this.viewProjection = copyStack(viewProjection); + public void setup(MatrixStack viewProjection, AbstractContraptionEntity entity) { float partialTicks = AnimationTickHolder.getPartialTicks(); - this.model = creatModelMatrix(entity, partialTicks); - world = translateTo(entity, partialTicks); + this.viewProjection.pushPose(); + transform(this.viewProjection, viewProjection); + model.pushPose(); + entity.doLocalTransforms(partialTicks, new MatrixStack[] { model }); - light = getWorld().copy(); - getLight().multiply(this.getModel() + modelViewProjection.pushPose(); + transform(modelViewProjection, viewProjection); + transform(modelViewProjection, model); + + translateToEntity(world, entity, partialTicks); + + light.set(world); + light.multiply(model .last().pose()); - modelViewProjection = copyStack(viewProjection); - transform(getModelViewProjection(), this.getModel()); + ready = true; + } + + public void clear() { + clearStack(modelViewProjection); + clearStack(viewProjection); + clearStack(model); + world.setIdentity(); + light.setIdentity(); + ready = false; } public MatrixStack getModelViewProjection() { @@ -70,28 +78,8 @@ public class ContraptionMatrices { return light; } - public static Matrix4f createModelViewPartial(AbstractContraptionEntity entity, float pt, Vector3d cameraPos) { - float x = (float) (MathHelper.lerp(pt, entity.xOld, entity.getX()) - cameraPos.x); - float y = (float) (MathHelper.lerp(pt, entity.yOld, entity.getY()) - cameraPos.y); - float z = (float) (MathHelper.lerp(pt, entity.zOld, entity.getZ()) - cameraPos.z); - Matrix4f mat = Matrix4f.createTranslateMatrix(x, y, z); - Matrix4f modelMatrix = creatModelMatrix(entity, pt).last().pose(); - - mat.multiply(modelMatrix); - return mat; - } - - public static MatrixStack creatModelMatrix(AbstractContraptionEntity entity, float partialTicks) { - MatrixStack model = new MatrixStack(); - entity.doLocalTransforms(partialTicks, new MatrixStack[] { model}); - return model; - } - - public static Matrix4f translateTo(Entity entity, float partialTicks) { - double x = MathHelper.lerp(partialTicks, entity.xOld, entity.getX()); - double y = MathHelper.lerp(partialTicks, entity.yOld, entity.getY()); - double z = MathHelper.lerp(partialTicks, entity.zOld, entity.getZ()); - return Matrix4f.createTranslateMatrix((float) x, (float) y, (float) z); + public boolean isReady() { + return ready; } public static void transform(MatrixStack ms, MatrixStack transform) { @@ -103,11 +91,17 @@ public class ContraptionMatrices { .normal()); } - public static MatrixStack copyStack(MatrixStack ms) { - MatrixStack cms = new MatrixStack(); - - transform(cms, ms); - - return cms; + public static void translateToEntity(Matrix4f matrix, Entity entity, float partialTicks) { + double x = MathHelper.lerp(partialTicks, entity.xOld, entity.getX()); + double y = MathHelper.lerp(partialTicks, entity.yOld, entity.getY()); + double z = MathHelper.lerp(partialTicks, entity.zOld, entity.getZ()); + matrix.setTranslation((float) x, (float) y, (float) z); } + + public static void clearStack(MatrixStack ms) { + while (!ms.clear()) { + ms.popPose(); + } + } + } diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/render/ContraptionRenderDispatcher.java b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/render/ContraptionRenderDispatcher.java index ddcadab07..f74968039 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/render/ContraptionRenderDispatcher.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/render/ContraptionRenderDispatcher.java @@ -79,7 +79,7 @@ public class ContraptionRenderDispatcher { ContraptionMatrices matrices = renderInfo.getMatrices(); // something went wrong with the other rendering - if (matrices == null) return; + if (!matrices.isReady()) return; PlacementSimulationWorld renderWorld = renderInfo.renderWorld; diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/render/ContraptionRenderInfo.java b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/render/ContraptionRenderInfo.java index 1000aeed2..6bc36792d 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/render/ContraptionRenderInfo.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/render/ContraptionRenderInfo.java @@ -1,9 +1,6 @@ package com.simibubi.create.content.contraptions.components.structureMovement.render; -import javax.annotation.Nullable; - import com.jozufozu.flywheel.event.BeginFrameEvent; -import com.jozufozu.flywheel.event.RenderLayerEvent; import com.mojang.blaze3d.matrix.MatrixStack; import com.simibubi.create.content.contraptions.components.structureMovement.AbstractContraptionEntity; import com.simibubi.create.content.contraptions.components.structureMovement.Contraption; @@ -11,13 +8,12 @@ import com.simibubi.create.foundation.utility.AnimationTickHolder; import com.simibubi.create.foundation.utility.worldWrappers.PlacementSimulationWorld; import net.minecraft.util.math.MathHelper; -import net.minecraft.util.math.vector.Vector3d; public class ContraptionRenderInfo { public final Contraption contraption; public final PlacementSimulationWorld renderWorld; - private ContraptionMatrices matrices = ContraptionMatrices.EMPTY; + private ContraptionMatrices matrices = new ContraptionMatrices(); private boolean visible; public ContraptionRenderInfo(Contraption contraption, PlacementSimulationWorld renderWorld) { @@ -34,7 +30,7 @@ public class ContraptionRenderInfo { } public void beginFrame(BeginFrameEvent event) { - matrices = null; + matrices.clear(); AbstractContraptionEntity entity = contraption.entity; @@ -49,7 +45,7 @@ public class ContraptionRenderInfo { * Need to call this during RenderLayerEvent. */ public void setupMatrices(MatrixStack viewProjection, double camX, double camY, double camZ) { - if (matrices == null) { + if (!matrices.isReady()) { AbstractContraptionEntity entity = contraption.entity; viewProjection.pushPose(); @@ -60,14 +56,14 @@ public class ContraptionRenderInfo { viewProjection.translate(x, y, z); - matrices = new ContraptionMatrices(viewProjection, entity); + matrices.setup(viewProjection, entity); viewProjection.popPose(); } } /** - * If #setupMatrices is called correctly, this will not return null + * If #setupMatrices is called correctly, the returned matrices will be ready */ public ContraptionMatrices getMatrices() { return matrices; diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/render/RenderedContraption.java b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/render/RenderedContraption.java index e33ab3422..56467c7dc 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/render/RenderedContraption.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/render/RenderedContraption.java @@ -15,6 +15,7 @@ import com.jozufozu.flywheel.core.model.IModel; import com.jozufozu.flywheel.core.model.WorldModel; import com.jozufozu.flywheel.event.BeginFrameEvent; import com.jozufozu.flywheel.light.GridAlignedBB; +import com.mojang.blaze3d.matrix.MatrixStack; import com.simibubi.create.content.contraptions.components.structureMovement.AbstractContraptionEntity; import com.simibubi.create.content.contraptions.components.structureMovement.Contraption; import com.simibubi.create.content.contraptions.components.structureMovement.ContraptionLighter; @@ -26,6 +27,7 @@ import net.minecraft.client.renderer.RenderType; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.math.AxisAlignedBB; import net.minecraft.util.math.BlockPos; +import net.minecraft.util.math.MathHelper; import net.minecraft.util.math.vector.Matrix4f; import net.minecraft.util.math.vector.Vector3d; import net.minecraft.world.World; @@ -39,7 +41,8 @@ public class RenderedContraption extends ContraptionRenderInfo { private final Map renderLayers = new HashMap<>(); - private Matrix4f modelViewPartial; + private final Matrix4f modelViewPartial = new Matrix4f(); + private boolean modelViewPartialReady; private AxisAlignedBB lightBox; public RenderedContraption(Contraption contraption, PlacementSimulationWorld renderWorld) { @@ -73,20 +76,31 @@ public class RenderedContraption extends ContraptionRenderInfo { public void beginFrame(BeginFrameEvent event) { super.beginFrame(event); + modelViewPartial.setIdentity(); + modelViewPartialReady = false; + if (!isVisible()) return; kinetics.beginFrame(event.getInfo()); Vector3d cameraPos = event.getCameraPos(); - modelViewPartial = ContraptionMatrices.createModelViewPartial(contraption.entity, AnimationTickHolder.getPartialTicks(), cameraPos); - lightBox = GridAlignedBB.toAABB(lighter.lightVolume.getTextureVolume()) .move(-cameraPos.x, -cameraPos.y, -cameraPos.z); } + @Override + public void setupMatrices(MatrixStack viewProjection, double camX, double camY, double camZ) { + super.setupMatrices(viewProjection, camX, camY, camZ); + + if (!modelViewPartialReady) { + setupModelViewPartial(modelViewPartial, getMatrices().getModel().last().pose(), contraption.entity, camX, camY, camZ, AnimationTickHolder.getPartialTicks()); + modelViewPartialReady = true; + } + } + void setup(ContraptionProgram shader) { - if (modelViewPartial == null || lightBox == null) return; + if (!modelViewPartialReady || lightBox == null) return; shader.bind(modelViewPartial, lightBox); lighter.lightVolume.bind(); } @@ -144,4 +158,13 @@ public class RenderedContraption extends ContraptionRenderInfo { private void buildActors() { contraption.getActors().forEach(kinetics::createActor); } + + public static void setupModelViewPartial(Matrix4f matrix, Matrix4f modelMatrix, AbstractContraptionEntity entity, double camX, double camY, double camZ, float pt) { + float x = (float) (MathHelper.lerp(pt, entity.xOld, entity.getX()) - camX); + float y = (float) (MathHelper.lerp(pt, entity.yOld, entity.getY()) - camY); + float z = (float) (MathHelper.lerp(pt, entity.zOld, entity.getZ()) - camZ); + matrix.setTranslation(x, y, z); + matrix.multiply(modelMatrix); + } + } From b19d92f6c27c79b9455d160cab0652305047dc4d Mon Sep 17 00:00:00 2001 From: PepperBell <44146161+PepperCode1@users.noreply.github.com> Date: Thu, 5 Aug 2021 22:35:24 -0700 Subject: [PATCH 12/13] Remove legacy TER light code - TERs now pass in the light, so no need to recalculate it - Make ContraptionRenderInfo.matrices final --- .../components/clock/CuckooClockRenderer.java | 12 ++++------ .../crafter/MechanicalCrafterRenderer.java | 21 ++++++++--------- .../components/deployer/DeployerRenderer.java | 23 ++++++++----------- .../flywheel/engine/EngineRenderer.java | 3 +-- .../mixer/MechanicalMixerRenderer.java | 8 ++----- .../press/MechanicalPressRenderer.java | 6 +---- .../render/ContraptionRenderInfo.java | 2 +- .../relays/gauge/GaugeRenderer.java | 8 +++---- .../curiosities/bell/BellRenderer.java | 7 ++---- .../block/redstone/AnalogLeverRenderer.java | 6 ++--- 10 files changed, 35 insertions(+), 61 deletions(-) diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/clock/CuckooClockRenderer.java b/src/main/java/com/simibubi/create/content/contraptions/components/clock/CuckooClockRenderer.java index 443c00b11..935baf026 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/clock/CuckooClockRenderer.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/clock/CuckooClockRenderer.java @@ -14,7 +14,6 @@ import com.simibubi.create.foundation.utility.AngleHelper; import net.minecraft.block.BlockState; import net.minecraft.client.renderer.IRenderTypeBuffer; import net.minecraft.client.renderer.RenderType; -import net.minecraft.client.renderer.WorldRenderer; import net.minecraft.client.renderer.tileentity.TileEntityRendererDispatcher; import net.minecraft.util.Direction; import net.minecraft.util.math.MathHelper; @@ -34,7 +33,6 @@ public class CuckooClockRenderer extends KineticTileEntityRenderer { CuckooClockTileEntity clock = (CuckooClockTileEntity) te; BlockState blockState = te.getBlockState(); - int packedLightmapCoords = WorldRenderer.getLightColor(te.getLevel(), blockState, te.getBlockPos()); Direction direction = blockState.getValue(CuckooClockBlock.HORIZONTAL_FACING); IVertexBuilder vb = buffer.getBuffer(RenderType.solid()); @@ -44,9 +42,9 @@ public class CuckooClockRenderer extends KineticTileEntityRenderer { SuperByteBuffer minuteHand = PartialBufferer.get(AllBlockPartials.CUCKOO_MINUTE_HAND, blockState); float hourAngle = clock.hourHand.get(partialTicks); float minuteAngle = clock.minuteHand.get(partialTicks); - rotateHand(hourHand, hourAngle, direction).light(packedLightmapCoords) + rotateHand(hourHand, hourAngle, direction).light(light) .renderInto(ms, vb); - rotateHand(minuteHand, minuteAngle, direction).light(packedLightmapCoords) + rotateHand(minuteHand, minuteAngle, direction).light(light) .renderInto(ms, vb); // Doors @@ -72,9 +70,9 @@ public class CuckooClockRenderer extends KineticTileEntityRenderer { } } - rotateDoor(leftDoor, angle, true, direction).light(packedLightmapCoords) + rotateDoor(leftDoor, angle, true, direction).light(light) .renderInto(ms, vb); - rotateDoor(rightDoor, angle, false, direction).light(packedLightmapCoords) + rotateDoor(rightDoor, angle, false, direction).light(light) .renderInto(ms, vb); // Figure @@ -85,7 +83,7 @@ public class CuckooClockRenderer extends KineticTileEntityRenderer { PartialBufferer.get(partialModel, blockState); figure.rotateCentered(Direction.UP, AngleHelper.rad(AngleHelper.horizontalAngle(direction.getCounterClockWise()))); figure.translate(offset, 0, 0); - figure.light(packedLightmapCoords) + figure.light(light) .renderInto(ms, vb); } diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/crafter/MechanicalCrafterRenderer.java b/src/main/java/com/simibubi/create/content/contraptions/components/crafter/MechanicalCrafterRenderer.java index 82858218e..d589cd999 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/crafter/MechanicalCrafterRenderer.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/crafter/MechanicalCrafterRenderer.java @@ -22,7 +22,6 @@ import net.minecraft.block.BlockState; import net.minecraft.client.Minecraft; import net.minecraft.client.renderer.IRenderTypeBuffer; import net.minecraft.client.renderer.RenderType; -import net.minecraft.client.renderer.WorldRenderer; import net.minecraft.client.renderer.model.ItemCameraTransforms.TransformType; import net.minecraft.client.renderer.tileentity.TileEntityRendererDispatcher; import net.minecraft.item.ItemStack; @@ -169,41 +168,39 @@ public class MechanicalCrafterRenderer extends SafeTileEntityRenderer { @@ -117,16 +115,17 @@ public class DeployerRenderer extends SafeTileEntityRenderer } BlockState blockState = te.getBlockState(); - BlockPos pos = te.getBlockPos(); Vector3d offset = getHandOffset(te, partialTicks, blockState); SuperByteBuffer pole = PartialBufferer.get(AllBlockPartials.DEPLOYER_POLE, blockState); SuperByteBuffer hand = PartialBufferer.get(te.getHandPose(), blockState); - transform(te.getLevel(), pole.translate(offset.x, offset.y, offset.z), blockState, pos, true).renderInto(ms, - vb); - transform(te.getLevel(), hand.translate(offset.x, offset.y, offset.z), blockState, pos, false).renderInto(ms, - vb); + transform(pole.translate(offset.x, offset.y, offset.z), blockState, true) + .light(light) + .renderInto(ms, vb); + transform(hand.translate(offset.x, offset.y, offset.z), blockState, false) + .light(light) + .renderInto(ms, vb); } protected Vector3d getHandOffset(DeployerTileEntity te, float partialTicks, BlockState blockState) { @@ -138,8 +137,7 @@ public class DeployerRenderer extends SafeTileEntityRenderer return KineticTileEntityRenderer.shaft(KineticTileEntityRenderer.getRotationAxisOf(te)); } - private static SuperByteBuffer transform(World world, SuperByteBuffer buffer, BlockState deployerState, - BlockPos pos, boolean axisDirectionMatters) { + private static SuperByteBuffer transform(SuperByteBuffer buffer, BlockState deployerState, boolean axisDirectionMatters) { Direction facing = deployerState.getValue(FACING); float zRotLast = @@ -151,7 +149,6 @@ public class DeployerRenderer extends SafeTileEntityRenderer buffer.rotateCentered(Direction.SOUTH, (float) ((zRot) / 180 * Math.PI)); buffer.rotateCentered(Direction.UP, (float) ((yRot) / 180 * Math.PI)); buffer.rotateCentered(Direction.SOUTH, (float) ((zRotLast) / 180 * Math.PI)); - buffer.light(WorldRenderer.getLightColor(world, deployerState, pos)); return buffer; } @@ -159,9 +156,7 @@ public class DeployerRenderer extends SafeTileEntityRenderer ContraptionMatrices matrices, IRenderTypeBuffer buffer) { IVertexBuilder builder = buffer.getBuffer(RenderType.solid()); BlockState blockState = context.state; - BlockPos pos = BlockPos.ZERO; Mode mode = NBTHelper.readEnum(context.tileData, "Mode", Mode.class); - World world = context.world; PartialModel handPose = getHandPose(mode); SuperByteBuffer pole = PartialBufferer.get(AllBlockPartials.DEPLOYER_POLE, blockState); @@ -187,8 +182,8 @@ public class DeployerRenderer extends SafeTileEntityRenderer pole.transform(m); hand.transform(m); - pole = transform(world, pole, blockState, pos, true); - hand = transform(world, hand, blockState, pos, false); + pole = transform(pole, blockState, true); + hand = transform(hand, blockState, false); pole.light(matrices.getWorld(), ContraptionRenderDispatcher.getContraptionWorldLight(context, renderWorld)) .renderInto(matrices.getViewProjection(), builder); diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/flywheel/engine/EngineRenderer.java b/src/main/java/com/simibubi/create/content/contraptions/components/flywheel/engine/EngineRenderer.java index 0d09715ae..a91ba53d3 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/flywheel/engine/EngineRenderer.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/flywheel/engine/EngineRenderer.java @@ -10,7 +10,6 @@ import com.simibubi.create.foundation.utility.AngleHelper; import net.minecraft.block.Block; import net.minecraft.client.renderer.IRenderTypeBuffer; import net.minecraft.client.renderer.RenderType; -import net.minecraft.client.renderer.WorldRenderer; import net.minecraft.client.renderer.tileentity.TileEntityRendererDispatcher; import net.minecraft.util.Direction; @@ -38,7 +37,7 @@ public class EngineRenderer extends SafeTileEntityRe PartialBufferer.get(frame, te.getBlockState()) .rotateCentered(Direction.UP, angle) .translate(0, 0, -1) - .light(WorldRenderer.getLightColor(te.getLevel(), te.getBlockState(), te.getBlockPos())) + .light(light) .renderInto(ms, buffer.getBuffer(RenderType.solid())); } } diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/mixer/MechanicalMixerRenderer.java b/src/main/java/com/simibubi/create/content/contraptions/components/mixer/MechanicalMixerRenderer.java index 6da31b2e5..61873ce38 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/mixer/MechanicalMixerRenderer.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/mixer/MechanicalMixerRenderer.java @@ -13,10 +13,8 @@ import com.simibubi.create.foundation.utility.AnimationTickHolder; import net.minecraft.block.BlockState; import net.minecraft.client.renderer.IRenderTypeBuffer; import net.minecraft.client.renderer.RenderType; -import net.minecraft.client.renderer.WorldRenderer; import net.minecraft.client.renderer.tileentity.TileEntityRendererDispatcher; import net.minecraft.util.Direction; -import net.minecraft.util.math.BlockPos; public class MechanicalMixerRenderer extends KineticTileEntityRenderer { @@ -37,14 +35,12 @@ public class MechanicalMixerRenderer extends KineticTileEntityRenderer { BlockState blockState = te.getBlockState(); MechanicalMixerTileEntity mixer = (MechanicalMixerTileEntity) te; - BlockPos pos = te.getBlockPos(); IVertexBuilder vb = buffer.getBuffer(RenderType.solid()); SuperByteBuffer superBuffer = PartialBufferer.get(AllBlockPartials.SHAFTLESS_COGWHEEL, blockState); standardKineticRotationTransform(superBuffer, te, light).renderInto(ms, vb); - int packedLightmapCoords = WorldRenderer.getLightColor(te.getLevel(), blockState, pos); float renderedHeadOffset = mixer.getRenderedHeadOffset(partialTicks); float speed = mixer.getRenderedHeadRotationSpeed(partialTicks); float time = AnimationTickHolder.getRenderTime(te.getLevel()); @@ -52,13 +48,13 @@ public class MechanicalMixerRenderer extends KineticTileEntityRenderer { SuperByteBuffer poleRender = PartialBufferer.get(AllBlockPartials.MECHANICAL_MIXER_POLE, blockState); poleRender.translate(0, -renderedHeadOffset, 0) - .light(packedLightmapCoords) + .light(light) .renderInto(ms, vb); SuperByteBuffer headRender = PartialBufferer.get(AllBlockPartials.MECHANICAL_MIXER_HEAD, blockState); headRender.rotateCentered(Direction.UP, angle) .translate(0, -renderedHeadOffset, 0) - .light(packedLightmapCoords) + .light(light) .renderInto(ms, vb); } diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/press/MechanicalPressRenderer.java b/src/main/java/com/simibubi/create/content/contraptions/components/press/MechanicalPressRenderer.java index 731294f2c..a310c7c1d 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/press/MechanicalPressRenderer.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/press/MechanicalPressRenderer.java @@ -13,9 +13,7 @@ import com.simibubi.create.foundation.render.SuperByteBuffer; import net.minecraft.block.BlockState; import net.minecraft.client.renderer.IRenderTypeBuffer; import net.minecraft.client.renderer.RenderType; -import net.minecraft.client.renderer.WorldRenderer; import net.minecraft.client.renderer.tileentity.TileEntityRendererDispatcher; -import net.minecraft.util.math.BlockPos; public class MechanicalPressRenderer extends KineticTileEntityRenderer { @@ -35,14 +33,12 @@ public class MechanicalPressRenderer extends KineticTileEntityRenderer { if (Backend.getInstance().canUseInstancing(te.getLevel())) return; - BlockPos pos = te.getBlockPos(); BlockState blockState = te.getBlockState(); - int packedLightmapCoords = WorldRenderer.getLightColor(te.getLevel(), blockState, pos); float renderedHeadOffset = ((MechanicalPressTileEntity) te).getRenderedHeadOffset(partialTicks); SuperByteBuffer headRender = PartialBufferer.getFacing(AllBlockPartials.MECHANICAL_PRESS_HEAD, blockState, blockState.getValue(HORIZONTAL_FACING)); headRender.translate(0, -renderedHeadOffset, 0) - .light(packedLightmapCoords) + .light(light) .renderInto(ms, buffer.getBuffer(RenderType.solid())); } diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/render/ContraptionRenderInfo.java b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/render/ContraptionRenderInfo.java index 6bc36792d..2b628393e 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/render/ContraptionRenderInfo.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/render/ContraptionRenderInfo.java @@ -13,7 +13,7 @@ public class ContraptionRenderInfo { public final Contraption contraption; public final PlacementSimulationWorld renderWorld; - private ContraptionMatrices matrices = new ContraptionMatrices(); + private final ContraptionMatrices matrices = new ContraptionMatrices(); private boolean visible; public ContraptionRenderInfo(Contraption contraption, PlacementSimulationWorld renderWorld) { diff --git a/src/main/java/com/simibubi/create/content/contraptions/relays/gauge/GaugeRenderer.java b/src/main/java/com/simibubi/create/content/contraptions/relays/gauge/GaugeRenderer.java index 182c75728..ebd9bfad8 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/relays/gauge/GaugeRenderer.java +++ b/src/main/java/com/simibubi/create/content/contraptions/relays/gauge/GaugeRenderer.java @@ -15,7 +15,6 @@ import com.simibubi.create.foundation.utility.Iterate; import net.minecraft.block.BlockState; import net.minecraft.client.renderer.IRenderTypeBuffer; import net.minecraft.client.renderer.RenderType; -import net.minecraft.client.renderer.WorldRenderer; import net.minecraft.client.renderer.tileentity.TileEntityRendererDispatcher; import net.minecraft.util.Direction; import net.minecraft.util.math.MathHelper; @@ -43,9 +42,9 @@ public class GaugeRenderer extends KineticTileEntityRenderer { if (Backend.getInstance().canUseInstancing(te.getLevel())) return; super.renderSafe(te, partialTicks, ms, buffer, light, overlay); + BlockState gaugeState = te.getBlockState(); GaugeTileEntity gaugeTE = (GaugeTileEntity) te; - int lightCoords = WorldRenderer.getLightColor(te.getLevel(), gaugeState, te.getBlockPos()); PartialModel partialModel = (type == Type.SPEED ? AllBlockPartials.GAUGE_HEAD_SPEED : AllBlockPartials.GAUGE_HEAD_STRESS); SuperByteBuffer headBuffer = @@ -64,12 +63,11 @@ public class GaugeRenderer extends KineticTileEntityRenderer { rotateBufferTowards(dialBuffer, facing).translate(0, dialPivot, dialPivot) .rotate(Direction.EAST, (float) (Math.PI / 2 * -progress)) .translate(0, -dialPivot, -dialPivot) - .light(lightCoords) + .light(light) .renderInto(ms, vb); - rotateBufferTowards(headBuffer, facing).light(lightCoords) + rotateBufferTowards(headBuffer, facing).light(light) .renderInto(ms, vb); } - } @Override diff --git a/src/main/java/com/simibubi/create/content/curiosities/bell/BellRenderer.java b/src/main/java/com/simibubi/create/content/curiosities/bell/BellRenderer.java index 37d12a927..c32fce701 100644 --- a/src/main/java/com/simibubi/create/content/curiosities/bell/BellRenderer.java +++ b/src/main/java/com/simibubi/create/content/curiosities/bell/BellRenderer.java @@ -1,7 +1,6 @@ package com.simibubi.create.content.curiosities.bell; import com.mojang.blaze3d.matrix.MatrixStack; -import com.mojang.blaze3d.vertex.IVertexBuilder; import com.simibubi.create.foundation.render.PartialBufferer; import com.simibubi.create.foundation.render.SuperByteBuffer; import com.simibubi.create.foundation.tileEntity.renderer.SafeTileEntityRenderer; @@ -11,7 +10,6 @@ import net.minecraft.block.BellBlock; import net.minecraft.block.BlockState; import net.minecraft.client.renderer.IRenderTypeBuffer; import net.minecraft.client.renderer.RenderType; -import net.minecraft.client.renderer.WorldRenderer; import net.minecraft.client.renderer.tileentity.TileEntityRendererDispatcher; import net.minecraft.state.properties.BellAttachment; import net.minecraft.util.Direction; @@ -39,9 +37,8 @@ public class BellRenderer extends SafeTileEnt rY += 90; bell.rotateCentered(Direction.UP, AngleHelper.rad(rY)); - IVertexBuilder vb = buffer.getBuffer(RenderType.cutout()); - int lightCoords = WorldRenderer.getLightColor(te.getLevel(), state, te.getBlockPos()); - bell.light(lightCoords).renderInto(ms, vb); + bell.light(light) + .renderInto(ms, buffer.getBuffer(RenderType.cutout())); } public static float getSwingAngle(float time) { diff --git a/src/main/java/com/simibubi/create/content/logistics/block/redstone/AnalogLeverRenderer.java b/src/main/java/com/simibubi/create/content/logistics/block/redstone/AnalogLeverRenderer.java index 01e3d5d05..24e387780 100644 --- a/src/main/java/com/simibubi/create/content/logistics/block/redstone/AnalogLeverRenderer.java +++ b/src/main/java/com/simibubi/create/content/logistics/block/redstone/AnalogLeverRenderer.java @@ -13,7 +13,6 @@ import com.simibubi.create.foundation.utility.ColorHelper; import net.minecraft.block.BlockState; import net.minecraft.client.renderer.IRenderTypeBuffer; import net.minecraft.client.renderer.RenderType; -import net.minecraft.client.renderer.WorldRenderer; import net.minecraft.client.renderer.tileentity.TileEntityRendererDispatcher; import net.minecraft.state.properties.AttachFace; import net.minecraft.util.Direction; @@ -31,7 +30,6 @@ public class AnalogLeverRenderer extends SafeTileEntityRenderer Date: Fri, 6 Aug 2021 12:13:51 -0700 Subject: [PATCH 13/13] Fix CI - Javadoc doesn't like angle brackets - Add jar to artifacts --- build.gradle | 2 +- .../contraptions/fluids/PipeConnection.java | 8 ++++---- .../foundation/ponder/SceneBuilder.java | 20 +++++++++---------- 3 files changed, 15 insertions(+), 15 deletions(-) diff --git a/build.gradle b/build.gradle index 676d87dba..94ae11c67 100644 --- a/build.gradle +++ b/build.gradle @@ -201,7 +201,7 @@ task javadocJar(type: Jar, dependsOn: javadoc) { } artifacts { - archives shadowJar, sourcesJar, javadocJar + archives jar, shadowJar, sourcesJar, javadocJar } publishing { diff --git a/src/main/java/com/simibubi/create/content/contraptions/fluids/PipeConnection.java b/src/main/java/com/simibubi/create/content/contraptions/fluids/PipeConnection.java index f766f18f4..240883516 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/fluids/PipeConnection.java +++ b/src/main/java/com/simibubi/create/content/contraptions/fluids/PipeConnection.java @@ -87,7 +87,7 @@ public class PipeConnection { FlowSource flowSource = source.get(); flowSource.manageSource(world); } - + public boolean manageFlows(World world, BlockPos pos, FluidStack internalFluid, Predicate extractionPredicate) { @@ -193,7 +193,7 @@ public class PipeConnection { if (world.isClientSide) { if (!source.isPresent()) determineSource(world, pos); - + spawnParticles(world, pos, flow.fluid); if (particleSplashNextTick) spawnSplashOnRim(world, pos, flow.fluid); @@ -282,8 +282,8 @@ public class PipeConnection { /** * @return zero if outward == inbound
- * positive if outward > inbound
- * negative if outward < inbound + * positive if outward {@literal >} inbound
+ * negative if outward {@literal <} inbound */ public float comparePressure() { return getOutwardPressure() - getInboundPressure(); diff --git a/src/main/java/com/simibubi/create/foundation/ponder/SceneBuilder.java b/src/main/java/com/simibubi/create/foundation/ponder/SceneBuilder.java index 108351609..da969d2fb 100644 --- a/src/main/java/com/simibubi/create/foundation/ponder/SceneBuilder.java +++ b/src/main/java/com/simibubi/create/foundation/ponder/SceneBuilder.java @@ -132,7 +132,7 @@ public class SceneBuilder { * Assign a unique translation key, as well as the standard english translation * for this scene's title using this method, anywhere inside the program * function. - * + * * @param sceneId * @param title */ @@ -147,7 +147,7 @@ public class SceneBuilder { * the the base plate.
* As a result, showBasePlate() will only show the configured size, and the * scene's scaling inside the UI will be consistent with its base size. - * + * * @param xOffset Block spaces between the base plate and the schematic * boundary on the Western side. * @param zOffset Block spaces between the base plate and the schematic @@ -164,8 +164,8 @@ public class SceneBuilder { /** * Use this in case you are not happy with the scale of the scene relative to * the overlay - * - * @param factor >1 will make the scene appear larger, smaller otherwise + * + * @param factor {@literal >}1 will make the scene appear larger, smaller otherwise */ public void scaleSceneView(float factor) { scene.scaleFactor = factor; @@ -174,8 +174,8 @@ public class SceneBuilder { /** * Use this in case you are not happy with the vertical alignment of the scene * relative to the overlay - * - * @param yOffset >0 moves the scene up, down otherwise + * + * @param yOffset {@literal >}0 moves the scene up, down otherwise */ public void setSceneOffsetY(float yOffset) { scene.yOffset = yOffset; @@ -197,7 +197,7 @@ public class SceneBuilder { * actions play out.
* Idle does not stall any animations, only schedules a time gap between * instructions. - * + * * @param ticks Duration to wait for */ public void idle(int ticks) { @@ -209,7 +209,7 @@ public class SceneBuilder { * actions play out.
* Idle does not stall any animations, only schedules a time gap between * instructions. - * + * * @param seconds Duration to wait for */ public void idleSeconds(int seconds) { @@ -229,7 +229,7 @@ public class SceneBuilder { /** * Pans the scene's camera view around the vertical axis by the given amount - * + * * @param degrees */ public void rotateCameraY(float degrees) { @@ -824,4 +824,4 @@ public class SceneBuilder { scene.schedule.add(PonderInstruction.simple(callback)); } -} \ No newline at end of file +}