From f20dbd5caee0d1c4c514f71637a129439344bb35 Mon Sep 17 00:00:00 2001 From: VoidLeech Date: Fri, 5 Jul 2024 00:16:28 +0200 Subject: [PATCH 1/9] fix backtank nbt not saving ForgeCaps don't save yet either though --- src/generated/resources/.cache/cache | 6 +++--- .../loot_tables/blocks/copper_backtank.json | 11 +++++++++++ .../loot_tables/blocks/netherite_backtank.json | 11 +++++++++++ .../emptying/compat/alexsmobs/lava_bottle.json | 2 +- .../content/equipment/armor/BacktankBlock.java | 9 ++++++--- .../equipment/armor/BacktankBlockEntity.java | 15 +++++++++++++++ .../foundation/data/BuilderTransformers.java | 4 ++++ 7 files changed, 51 insertions(+), 7 deletions(-) diff --git a/src/generated/resources/.cache/cache b/src/generated/resources/.cache/cache index 1f49b621b..e8b04142f 100644 --- a/src/generated/resources/.cache/cache +++ b/src/generated/resources/.cache/cache @@ -3329,7 +3329,7 @@ c2b075008849e152f20e8da946e89c9722325df6 data/create/loot_tables/blocks/content_ 69b4b25d7d271458177fbbaeba2c797daccc38a2 data/create/loot_tables/blocks/contraption_controls.json 28856dc862efc6bcc421d035d26386740458f868 data/create/loot_tables/blocks/controller_rail.json 2c2785e39e1891dff2c50cba93e814b56d935154 data/create/loot_tables/blocks/controls.json -3abf04f6132955275ad490668cd28f481afb4ec2 data/create/loot_tables/blocks/copper_backtank.json +830949a5dc64982392db2c1f651d2a9d0ff659a8 data/create/loot_tables/blocks/copper_backtank.json 6697e619d5c6dcb81aad4f5c88ba319d13665b35 data/create/loot_tables/blocks/copper_bars.json 8010db6b2427536c74312c85425b3ba83abc363c data/create/loot_tables/blocks/copper_casing.json ea5fb942c8dfb792daac538e09d286ac120aa199 data/create/loot_tables/blocks/copper_door.json @@ -3590,7 +3590,7 @@ afdff197c9d1a6940e988c00435135f9705fd0e5 data/create/loot_tables/blocks/metal_gi b83a90fbe83906b171fc0de6bdc2d9aa3a8c542e data/create/loot_tables/blocks/millstone.json 5c1df8443043b3fe3b665dba348e2ff188bcbe31 data/create/loot_tables/blocks/minecart_anchor.json 1e73d28fdd2e54910074aeadbe5617425a8ae656 data/create/loot_tables/blocks/mysterious_cuckoo_clock.json -a5fa8fdc10efe534e5c7d8bdb687f226b39f63ef data/create/loot_tables/blocks/netherite_backtank.json +9be92bab82bc1e83533f1d4679b09bd0513b07eb data/create/loot_tables/blocks/netherite_backtank.json 2e21a06c0d671e543bffecb0b67d97b51fa83ddc data/create/loot_tables/blocks/nixie_tube.json f6b4095a518a01081f3663d7268d67063bdb44ee data/create/loot_tables/blocks/nozzle.json d378be8f13fc7ed625813eae3a50b68e8706a297 data/create/loot_tables/blocks/oak_window.json @@ -5012,7 +5012,7 @@ e6aa8895186358e9d069f5a99909132be49f3bf1 data/create/recipes/diorite_from_stone_ a90268d38f976327ff5e1b87ff1d72ca2d1ebad6 data/create/recipes/dripstone_block_from_stone_types_dripstone_stonecutting.json 27d9bf05a610447e90314e658dbbcd191f378fc9 data/create/recipes/dripstone_pillar_from_stone_types_dripstone_stonecutting.json d81ceba2946286d374801e698a4ca2116395cbad data/create/recipes/emptying/builders_tea.json -318ab703224ff1d6f7200675e1e0a4c138b28456 data/create/recipes/emptying/compat/alexsmobs/lava_bottle.json +d62f4682fe6cc61df5a1c0231a2004a4ee78a329 data/create/recipes/emptying/compat/alexsmobs/lava_bottle.json c26d003e921720308c05ad7b9f3cb57de94a10a8 data/create/recipes/emptying/compat/farmersdelight/milk_bottle.json 60c0edfb5b759e4f13427b631861f503f8552923 data/create/recipes/emptying/compat/neapolitan/milk_bottle.json 20b7c7c62fa2e33199e08188dd8836844a6d9cfd data/create/recipes/emptying/honey_bottle.json diff --git a/src/generated/resources/data/create/loot_tables/blocks/copper_backtank.json b/src/generated/resources/data/create/loot_tables/blocks/copper_backtank.json index 9083fd8b2..2ae4e172a 100644 --- a/src/generated/resources/data/create/loot_tables/blocks/copper_backtank.json +++ b/src/generated/resources/data/create/loot_tables/blocks/copper_backtank.json @@ -8,6 +8,17 @@ { "type": "minecraft:item", "functions": [ + { + "function": "minecraft:copy_nbt", + "source": "block_entity", + "ops": [ + { + "source": "FullNBT", + "target": "{}", + "op": "merge" + } + ] + }, { "function": "minecraft:copy_name", "source": "block_entity" diff --git a/src/generated/resources/data/create/loot_tables/blocks/netherite_backtank.json b/src/generated/resources/data/create/loot_tables/blocks/netherite_backtank.json index 4418da818..dde8be2fa 100644 --- a/src/generated/resources/data/create/loot_tables/blocks/netherite_backtank.json +++ b/src/generated/resources/data/create/loot_tables/blocks/netherite_backtank.json @@ -8,6 +8,17 @@ { "type": "minecraft:item", "functions": [ + { + "function": "minecraft:copy_nbt", + "source": "block_entity", + "ops": [ + { + "source": "FullNBT", + "target": "{}", + "op": "merge" + } + ] + }, { "function": "minecraft:copy_name", "source": "block_entity" diff --git a/src/generated/resources/data/create/recipes/emptying/compat/alexsmobs/lava_bottle.json b/src/generated/resources/data/create/recipes/emptying/compat/alexsmobs/lava_bottle.json index b9a1453cc..5840cfd98 100644 --- a/src/generated/resources/data/create/recipes/emptying/compat/alexsmobs/lava_bottle.json +++ b/src/generated/resources/data/create/recipes/emptying/compat/alexsmobs/lava_bottle.json @@ -16,7 +16,7 @@ ], "conditions": [ { - "modid": "atmospheric", + "modid": "alexsmobs", "type": "forge:mod_loaded" } ] diff --git a/src/main/java/com/simibubi/create/content/equipment/armor/BacktankBlock.java b/src/main/java/com/simibubi/create/content/equipment/armor/BacktankBlock.java index 8848aa392..aa07e001f 100644 --- a/src/main/java/com/simibubi/create/content/equipment/armor/BacktankBlock.java +++ b/src/main/java/com/simibubi/create/content/equipment/armor/BacktankBlock.java @@ -83,7 +83,7 @@ public class BacktankBlock extends HorizontalKineticBlock @Override public BlockState updateShape(BlockState state, Direction direction, BlockState neighbourState, LevelAccessor world, BlockPos pos, BlockPos neighbourPos) { - if (state.getValue(BlockStateProperties.WATERLOGGED)) + if (state.getValue(BlockStateProperties.WATERLOGGED)) world.scheduleTick(pos, Fluids.WATER, Fluids.WATER.getTickDelay(world)); return state; } @@ -121,6 +121,7 @@ public class BacktankBlock extends HorizontalKineticBlock be.setEnchantmentTag(stack.getEnchantmentTags()); if (stack.hasCustomHoverName()) be.setCustomName(stack.getHoverName()); + be.setFullNbt(stack.getOrCreateTag()); }); } @@ -157,9 +158,10 @@ public class BacktankBlock extends HorizontalKineticBlock ItemStack stack = new ItemStack(item); Optional blockEntityOptional = getBlockEntityOptional(blockGetter, pos); + CompoundTag tag = blockEntityOptional.map(BacktankBlockEntity::getFullNbt).orElse(stack.getOrCreateTag()); + int air = blockEntityOptional.map(BacktankBlockEntity::getAirLevel) .orElse(0); - CompoundTag tag = stack.getOrCreateTag(); tag.putInt("Air", air); ListTag enchants = blockEntityOptional.map(BacktankBlockEntity::getEnchantmentTag) @@ -174,6 +176,7 @@ public class BacktankBlock extends HorizontalKineticBlock .orElse(null); if (customName != null) stack.setHoverName(customName); + stack.setTag(tag); return stack; } @@ -187,7 +190,7 @@ public class BacktankBlock extends HorizontalKineticBlock public Class getBlockEntityClass() { return BacktankBlockEntity.class; } - + @Override public BlockEntityType getBlockEntityType() { return AllBlockEntityTypes.BACKTANK.get(); diff --git a/src/main/java/com/simibubi/create/content/equipment/armor/BacktankBlockEntity.java b/src/main/java/com/simibubi/create/content/equipment/armor/BacktankBlockEntity.java index 20f3c4518..cca4eda3f 100644 --- a/src/main/java/com/simibubi/create/content/equipment/armor/BacktankBlockEntity.java +++ b/src/main/java/com/simibubi/create/content/equipment/armor/BacktankBlockEntity.java @@ -37,10 +37,13 @@ public class BacktankBlockEntity extends KineticBlockEntity implements Nameable private int capacityEnchantLevel; private ListTag enchantmentTag; + private CompoundTag fullNbt; + public BacktankBlockEntity(BlockEntityType type, BlockPos pos, BlockState state) { super(type, pos, state); defaultName = getDefaultName(state); enchantmentTag = new ListTag(); + fullNbt = new CompoundTag(); } public static Component getDefaultName(BlockState state) { @@ -118,6 +121,7 @@ public class BacktankBlockEntity extends KineticBlockEntity implements Nameable if (this.customName != null) compound.putString("CustomName", Component.Serializer.toJson(this.customName)); compound.put("Enchantments", enchantmentTag); + compound.put("FullNBT", fullNbt); } @Override @@ -128,6 +132,7 @@ public class BacktankBlockEntity extends KineticBlockEntity implements Nameable airLevel = compound.getInt("Air"); airLevelTimer = compound.getInt("Timer"); enchantmentTag = compound.getList("Enchantments", Tag.TAG_COMPOUND); + this.fullNbt = compound.getCompound("FullNBT"); if (compound.contains("CustomName", 8)) this.customName = Component.Serializer.fromJson(compound.getString("CustomName")); if (prev != 0 && prev != airLevel && airLevel == BacktankUtil.maxAir(capacityEnchantLevel) && clientPacket) @@ -182,4 +187,14 @@ public class BacktankBlockEntity extends KineticBlockEntity implements Nameable this.capacityEnchantLevel = capacityEnchantLevel; } + public CompoundTag getFullNbt() + { + return fullNbt; + } + + public void setFullNbt(CompoundTag fullNbt) + { + this.fullNbt = fullNbt; + } + } diff --git a/src/main/java/com/simibubi/create/foundation/data/BuilderTransformers.java b/src/main/java/com/simibubi/create/foundation/data/BuilderTransformers.java index b39035f11..3e839be0f 100644 --- a/src/main/java/com/simibubi/create/foundation/data/BuilderTransformers.java +++ b/src/main/java/com/simibubi/create/foundation/data/BuilderTransformers.java @@ -73,6 +73,8 @@ import net.minecraft.world.level.storage.loot.LootTable.Builder; import net.minecraft.world.level.storage.loot.entries.LootItem; import net.minecraft.world.level.storage.loot.functions.CopyNameFunction; import net.minecraft.world.level.storage.loot.functions.CopyNbtFunction; +import net.minecraft.world.level.storage.loot.functions.LootItemFunction; +import net.minecraft.world.level.storage.loot.functions.SetNbtFunction; import net.minecraft.world.level.storage.loot.predicates.ExplosionCondition; import net.minecraft.world.level.storage.loot.predicates.LootItemCondition; import net.minecraft.world.level.storage.loot.providers.nbt.ContextNbtProvider; @@ -435,6 +437,8 @@ public class BuilderTransformers { .when(survivesExplosion) .setRolls(ConstantValue.exactly(1)) .add(LootItem.lootTableItem(drop.get()) + .apply(CopyNbtFunction.copyData(ContextNbtProvider.BLOCK_ENTITY) + .copy("FullNBT", "{}", CopyNbtFunction.MergeStrategy.MERGE)) .apply(CopyNameFunction.copyName(CopyNameFunction.NameSource.BLOCK_ENTITY)) .apply(CopyNbtFunction.copyData(ContextNbtProvider.BLOCK_ENTITY) .copy("Air", "Air")) From d67f345146433a8f958ec2d3a81bb1f82a1cb4fb Mon Sep 17 00:00:00 2001 From: VoidLeech Date: Fri, 5 Jul 2024 00:57:11 +0200 Subject: [PATCH 2/9] remove unused imports --- .../simibubi/create/foundation/data/BuilderTransformers.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/main/java/com/simibubi/create/foundation/data/BuilderTransformers.java b/src/main/java/com/simibubi/create/foundation/data/BuilderTransformers.java index 3e839be0f..0a7148cf2 100644 --- a/src/main/java/com/simibubi/create/foundation/data/BuilderTransformers.java +++ b/src/main/java/com/simibubi/create/foundation/data/BuilderTransformers.java @@ -73,8 +73,6 @@ import net.minecraft.world.level.storage.loot.LootTable.Builder; import net.minecraft.world.level.storage.loot.entries.LootItem; import net.minecraft.world.level.storage.loot.functions.CopyNameFunction; import net.minecraft.world.level.storage.loot.functions.CopyNbtFunction; -import net.minecraft.world.level.storage.loot.functions.LootItemFunction; -import net.minecraft.world.level.storage.loot.functions.SetNbtFunction; import net.minecraft.world.level.storage.loot.predicates.ExplosionCondition; import net.minecraft.world.level.storage.loot.predicates.LootItemCondition; import net.minecraft.world.level.storage.loot.providers.nbt.ContextNbtProvider; From a6f5c51d6a3a2c971d6a4f40cfdc3ee4499b63d9 Mon Sep 17 00:00:00 2001 From: VoidLeech Date: Fri, 5 Jul 2024 01:08:44 +0200 Subject: [PATCH 3/9] Preserve getOrCreateStack --- .../simibubi/create/content/equipment/armor/BacktankBlock.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/simibubi/create/content/equipment/armor/BacktankBlock.java b/src/main/java/com/simibubi/create/content/equipment/armor/BacktankBlock.java index aa07e001f..59ca29710 100644 --- a/src/main/java/com/simibubi/create/content/equipment/armor/BacktankBlock.java +++ b/src/main/java/com/simibubi/create/content/equipment/armor/BacktankBlock.java @@ -158,7 +158,7 @@ public class BacktankBlock extends HorizontalKineticBlock ItemStack stack = new ItemStack(item); Optional blockEntityOptional = getBlockEntityOptional(blockGetter, pos); - CompoundTag tag = blockEntityOptional.map(BacktankBlockEntity::getFullNbt).orElse(stack.getOrCreateTag()); + CompoundTag tag = stack.getOrCreateTag().merge(blockEntityOptional.map(BacktankBlockEntity::getFullNbt).orElse(new CompoundTag())); int air = blockEntityOptional.map(BacktankBlockEntity::getAirLevel) .orElse(0); From caf79d40ae2977fe5a56946a8de9c0b1e3907914 Mon Sep 17 00:00:00 2001 From: VoidLeech Date: Fri, 5 Jul 2024 02:29:33 +0200 Subject: [PATCH 4/9] Revert "Preserve getOrCreateStack" This reverts commit a6f5c51d6a3a2c971d6a4f40cfdc3ee4499b63d9. Would duplicate the enchants on the backtank --- .../simibubi/create/content/equipment/armor/BacktankBlock.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/simibubi/create/content/equipment/armor/BacktankBlock.java b/src/main/java/com/simibubi/create/content/equipment/armor/BacktankBlock.java index 59ca29710..aa07e001f 100644 --- a/src/main/java/com/simibubi/create/content/equipment/armor/BacktankBlock.java +++ b/src/main/java/com/simibubi/create/content/equipment/armor/BacktankBlock.java @@ -158,7 +158,7 @@ public class BacktankBlock extends HorizontalKineticBlock ItemStack stack = new ItemStack(item); Optional blockEntityOptional = getBlockEntityOptional(blockGetter, pos); - CompoundTag tag = stack.getOrCreateTag().merge(blockEntityOptional.map(BacktankBlockEntity::getFullNbt).orElse(new CompoundTag())); + CompoundTag tag = blockEntityOptional.map(BacktankBlockEntity::getFullNbt).orElse(stack.getOrCreateTag()); int air = blockEntityOptional.map(BacktankBlockEntity::getAirLevel) .orElse(0); From ee41e0f04e365678c786eb82454761a714f5a88c Mon Sep 17 00:00:00 2001 From: NotSoEpic Date: Sat, 6 Jul 2024 08:41:41 +0800 Subject: [PATCH 5/9] Encasing blocks plays a placing sound --- .../content/decoration/encasing/EncasableBlock.java | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/main/java/com/simibubi/create/content/decoration/encasing/EncasableBlock.java b/src/main/java/com/simibubi/create/content/decoration/encasing/EncasableBlock.java index 6c31ae78c..d53cf9617 100644 --- a/src/main/java/com/simibubi/create/content/decoration/encasing/EncasableBlock.java +++ b/src/main/java/com/simibubi/create/content/decoration/encasing/EncasableBlock.java @@ -3,12 +3,14 @@ package com.simibubi.create.content.decoration.encasing; import java.util.List; import net.minecraft.core.BlockPos; +import net.minecraft.sounds.SoundSource; import net.minecraft.world.InteractionHand; import net.minecraft.world.InteractionResult; import net.minecraft.world.entity.player.Player; import net.minecraft.world.item.ItemStack; import net.minecraft.world.level.Level; import net.minecraft.world.level.block.Block; +import net.minecraft.world.level.block.SoundType; import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.phys.BlockHitResult; @@ -31,9 +33,16 @@ public interface EncasableBlock { return InteractionResult.SUCCESS; encased.handleEncasing(state, level, pos, heldItem, player, hand, ray); + playEncaseSound(level, pos); return InteractionResult.SUCCESS; } } return InteractionResult.PASS; } + + default void playEncaseSound(Level level, BlockPos pos) { + BlockState newState = level.getBlockState(pos); + SoundType soundType = newState.getSoundType(); + level.playSound(null, pos, soundType.getPlaceSound(), SoundSource.BLOCKS, (soundType.getVolume() + 1.0F) / 2.0F, soundType.getPitch() * 0.8F); + } } From 9dfbe061def61b99b03b5bbf66a349323709fd91 Mon Sep 17 00:00:00 2001 From: drouarb Date: Mon, 8 Jul 2024 20:53:49 +0200 Subject: [PATCH 6/9] Preserving BakedModel and switching to ItemRenderer.render instead of ItemRenderer.renderStatic for performance --- .../decoration/placard/PlacardRenderer.java | 7 ++++--- .../content/fluids/drain/ItemDrainRenderer.java | 7 ++++--- .../create/content/kinetics/belt/BeltRenderer.java | 11 ++++++----- .../kinetics/deployer/DeployerRenderer.java | 8 ++++---- .../kinetics/mechanicalArm/ArmRenderer.java | 14 +++++++------- .../create/content/kinetics/saw/SawRenderer.java | 2 +- .../content/logistics/depot/DepotRenderer.java | 7 ++++--- 7 files changed, 30 insertions(+), 26 deletions(-) diff --git a/src/main/java/com/simibubi/create/content/decoration/placard/PlacardRenderer.java b/src/main/java/com/simibubi/create/content/decoration/placard/PlacardRenderer.java index 7081b98ae..fe98850ea 100644 --- a/src/main/java/com/simibubi/create/content/decoration/placard/PlacardRenderer.java +++ b/src/main/java/com/simibubi/create/content/decoration/placard/PlacardRenderer.java @@ -10,6 +10,7 @@ import net.minecraft.client.renderer.MultiBufferSource; import net.minecraft.client.renderer.block.model.ItemTransforms.TransformType; import net.minecraft.client.renderer.blockentity.BlockEntityRendererProvider; import net.minecraft.client.renderer.entity.ItemRenderer; +import net.minecraft.client.resources.model.BakedModel; import net.minecraft.core.Direction; import net.minecraft.util.Mth; import net.minecraft.world.item.ItemStack; @@ -33,8 +34,8 @@ public class PlacardRenderer extends SafeBlockEntityRenderer ItemRenderer itemRenderer = Minecraft.getInstance() .getItemRenderer(); - boolean blockItem = itemRenderer.getModel(heldItem, null, null, 0) - .isGui3d(); + BakedModel bakedModel = itemRenderer.getModel(heldItem, null, null, 0); + boolean blockItem = bakedModel.isGui3d(); ms.pushPose(); TransformStack.cast(ms) @@ -46,7 +47,7 @@ public class PlacardRenderer extends SafeBlockEntityRenderer .translate(0, 0, 4.5 / 16f) .scale(blockItem ? .5f : .375f); - itemRenderer.renderStatic(heldItem, TransformType.FIXED, light, overlay, ms, buffer, 0); + itemRenderer.render(heldItem, TransformType.FIXED, false, ms, buffer, light, overlay, bakedModel); ms.popPose(); } diff --git a/src/main/java/com/simibubi/create/content/fluids/drain/ItemDrainRenderer.java b/src/main/java/com/simibubi/create/content/fluids/drain/ItemDrainRenderer.java index d803e31dc..e3a9c4957 100644 --- a/src/main/java/com/simibubi/create/content/fluids/drain/ItemDrainRenderer.java +++ b/src/main/java/com/simibubi/create/content/fluids/drain/ItemDrainRenderer.java @@ -19,6 +19,7 @@ import net.minecraft.client.renderer.MultiBufferSource; import net.minecraft.client.renderer.block.model.ItemTransforms.TransformType; import net.minecraft.client.renderer.blockentity.BlockEntityRendererProvider; import net.minecraft.client.renderer.entity.ItemRenderer; +import net.minecraft.client.resources.model.BakedModel; import net.minecraft.core.Direction; import net.minecraft.core.Direction.Axis; import net.minecraft.util.Mth; @@ -78,8 +79,8 @@ public class ItemDrainRenderer extends SmartBlockEntityRenderer { boolean slopeAlongX = beltFacing .getAxis() == Axis.X; + ItemRenderer itemRenderer = Minecraft.getInstance().getItemRenderer(); boolean onContraption = be.getLevel() instanceof WrappedWorld; for (TransportedItemStack transported : be.getInventory() @@ -238,11 +240,10 @@ public class BeltRenderer extends SafeBlockEntityRenderer { ms.translate(alongX ? sideOffset : 0, 0, alongX ? 0 : sideOffset); int stackLight = onContraption ? light : getPackedLight(be, offset); - ItemRenderer itemRenderer = Minecraft.getInstance() - .getItemRenderer(); + boolean renderUpright = BeltHelper.isItemUpright(transported.stack); - boolean blockItem = itemRenderer.getModel(transported.stack, be.getLevel(), null, 0) - .isGui3d(); + BakedModel bakedModel = itemRenderer.getModel(transported.stack, be.getLevel(), null, 0); + boolean blockItem = bakedModel.isGui3d(); int count = (int) (Mth.log2((int) (transported.stack.getCount()))) / 2; Random r = new Random(transported.angle); @@ -289,7 +290,7 @@ public class BeltRenderer extends SafeBlockEntityRenderer { } ms.scale(.5f, .5f, .5f); - itemRenderer.renderStatic(null, transported.stack, TransformType.FIXED, false, ms, buffer, be.getLevel(), stackLight, overlay, 0); + itemRenderer.render(transported.stack, TransformType.FIXED, false, ms, buffer, stackLight, overlay, bakedModel); ms.popPose(); if (!renderUpright) { diff --git a/src/main/java/com/simibubi/create/content/kinetics/deployer/DeployerRenderer.java b/src/main/java/com/simibubi/create/content/kinetics/deployer/DeployerRenderer.java index 3ce20684f..031f162ce 100644 --- a/src/main/java/com/simibubi/create/content/kinetics/deployer/DeployerRenderer.java +++ b/src/main/java/com/simibubi/create/content/kinetics/deployer/DeployerRenderer.java @@ -34,6 +34,7 @@ import net.minecraft.client.renderer.RenderType; import net.minecraft.client.renderer.block.model.ItemTransforms.TransformType; import net.minecraft.client.renderer.blockentity.BlockEntityRendererProvider; import net.minecraft.client.renderer.entity.ItemRenderer; +import net.minecraft.client.resources.model.BakedModel; import net.minecraft.core.BlockPos; import net.minecraft.core.Direction; import net.minecraft.core.Direction.Axis; @@ -89,9 +90,8 @@ public class DeployerRenderer extends SafeBlockEntityRenderer { ItemRenderer itemRenderer = Minecraft.getInstance() .getItemRenderer(); - boolean isBlockItem = - hasItem && (item.getItem() instanceof BlockItem) && itemRenderer.getModel(item, be.getLevel(), null, 0) - .isGui3d(); + BakedModel bakedModel = itemRenderer.getModel(item, be.getLevel(), null, 0); + boolean isBlockItem = hasItem && (item.getItem() instanceof BlockItem) && bakedModel.isGui3d(); VertexConsumer builder = buffer.getBuffer(be.goggles ? RenderType.cutout() : RenderType.solid()); BlockState blockState = be.getBlockState(); @@ -102,7 +102,7 @@ public class ArmRenderer extends KineticBlockEntityRenderer { .multiply(msLocal.last() .pose()); - itemRenderer.renderStatic(item, TransformType.FIXED, light, overlay, ms, buffer, 0); + itemRenderer.render(item, TransformType.FIXED, false, ms, buffer, light, overlay, bakedModel); ms.popPose(); } @@ -141,13 +141,13 @@ public class ArmRenderer extends KineticBlockEntityRenderer { .renderInto(ms, builder); transformHead(msr, headAngle); - + if (inverted) msr.rotateZ(180); - + claw.transform(msLocal) .renderInto(ms, builder); - + if (inverted) msr.rotateZ(180); diff --git a/src/main/java/com/simibubi/create/content/kinetics/saw/SawRenderer.java b/src/main/java/com/simibubi/create/content/kinetics/saw/SawRenderer.java index 926b7332a..750ca9371 100644 --- a/src/main/java/com/simibubi/create/content/kinetics/saw/SawRenderer.java +++ b/src/main/java/com/simibubi/create/content/kinetics/saw/SawRenderer.java @@ -134,7 +134,7 @@ public class SawRenderer extends SafeBlockEntityRenderer { if (alongZ) ms.mulPose(Vector3f.YP.rotationDegrees(90)); ms.mulPose(Vector3f.XP.rotationDegrees(90)); - itemRenderer.renderStatic(stack, ItemTransforms.TransformType.FIXED, light, overlay, ms, buffer, 0); + itemRenderer.render(stack, ItemTransforms.TransformType.FIXED, false, ms, buffer, light, overlay, modelWithOverrides); break; } diff --git a/src/main/java/com/simibubi/create/content/logistics/depot/DepotRenderer.java b/src/main/java/com/simibubi/create/content/logistics/depot/DepotRenderer.java index 5f830e91d..3d53879fa 100644 --- a/src/main/java/com/simibubi/create/content/logistics/depot/DepotRenderer.java +++ b/src/main/java/com/simibubi/create/content/logistics/depot/DepotRenderer.java @@ -16,6 +16,7 @@ import net.minecraft.client.renderer.MultiBufferSource; import net.minecraft.client.renderer.block.model.ItemTransforms.TransformType; import net.minecraft.client.renderer.blockentity.BlockEntityRendererProvider; import net.minecraft.client.renderer.entity.ItemRenderer; +import net.minecraft.client.resources.model.BakedModel; import net.minecraft.core.Direction.Axis; import net.minecraft.util.Mth; import net.minecraft.world.entity.Entity; @@ -104,8 +105,8 @@ public class DepotRenderer extends SafeBlockEntityRenderer { TransformStack msr = TransformStack.cast(ms); int count = (int) (Mth.log2((int) (itemStack.getCount()))) / 2; boolean renderUpright = BeltHelper.isItemUpright(itemStack); - boolean blockItem = itemRenderer.getModel(itemStack, null, null, 0) - .isGui3d(); + BakedModel bakedModel = itemRenderer.getModel(itemStack, null, null, 0); + boolean blockItem = bakedModel.isGui3d(); ms.pushPose(); msr.rotateY(angle); @@ -131,7 +132,7 @@ public class DepotRenderer extends SafeBlockEntityRenderer { ms.translate(0, -3 / 16f, 0); msr.rotateX(90); } - itemRenderer.renderStatic(itemStack, TransformType.FIXED, light, overlay, ms, buffer, 0); + itemRenderer.render(itemStack, TransformType.FIXED, false, ms, buffer, light, overlay, bakedModel); ms.popPose(); if (!renderUpright) { From 03973c4dc5927a9f67afdb412c0a920c20977878 Mon Sep 17 00:00:00 2001 From: drouarb Date: Thu, 11 Jul 2024 00:00:27 +0200 Subject: [PATCH 7/9] Culling item on belts --- .../content/kinetics/belt/BeltRenderer.java | 24 +++++++++++++++---- .../renderer/SafeBlockEntityRenderer.java | 21 ++++++++++++++++ .../resources/META-INF/accesstransformer.cfg | 3 +++ 3 files changed, 43 insertions(+), 5 deletions(-) diff --git a/src/main/java/com/simibubi/create/content/kinetics/belt/BeltRenderer.java b/src/main/java/com/simibubi/create/content/kinetics/belt/BeltRenderer.java index c7241ed53..04f366232 100644 --- a/src/main/java/com/simibubi/create/content/kinetics/belt/BeltRenderer.java +++ b/src/main/java/com/simibubi/create/content/kinetics/belt/BeltRenderer.java @@ -198,10 +198,6 @@ public class BeltRenderer extends SafeBlockEntityRenderer { for (TransportedItemStack transported : be.getInventory() .getTransportedItems()) { - ms.pushPose(); - TransformStack.cast(ms) - .nudge(transported.angle); - float offset; float sideOffset; float verticalMovement; @@ -228,6 +224,18 @@ public class BeltRenderer extends SafeBlockEntityRenderer { .getAxis() == Axis.Z); float slopeAngle = onSlope ? tiltForward ? -45 : 45 : 0; + Vec3 itemPos = beltStartOffset.add( + be.getBlockPos().getX(), + be.getBlockPos().getY(), + be.getBlockPos().getZ()) + .add(offsetVec); + + if (this.shouldCullItem(itemPos)) { + continue; + } + + ms.pushPose(); + TransformStack.cast(ms).nudge(transported.angle); ms.translate(offsetVec.x, offsetVec.y, offsetVec.z); boolean alongX = beltFacing @@ -243,7 +251,13 @@ public class BeltRenderer extends SafeBlockEntityRenderer { boolean renderUpright = BeltHelper.isItemUpright(transported.stack); boolean blockItem = itemRenderer.getModel(transported.stack, be.getLevel(), null, 0) .isGui3d(); - int count = (int) (Mth.log2((int) (transported.stack.getCount()))) / 2; + + + int count = 0; + if (Minecraft.getInstance().player.getEyePosition(1.0F).distanceTo(itemPos) < 16) { + count = (int) (Mth.log2((int) (transported.stack.getCount()))) / 2; + } + Random r = new Random(transported.angle); boolean slopeShadowOnly = renderUpright && onSlope; diff --git a/src/main/java/com/simibubi/create/foundation/blockEntity/renderer/SafeBlockEntityRenderer.java b/src/main/java/com/simibubi/create/foundation/blockEntity/renderer/SafeBlockEntityRenderer.java index 1ecb77e29..f26940d4c 100644 --- a/src/main/java/com/simibubi/create/foundation/blockEntity/renderer/SafeBlockEntityRenderer.java +++ b/src/main/java/com/simibubi/create/foundation/blockEntity/renderer/SafeBlockEntityRenderer.java @@ -2,10 +2,14 @@ package com.simibubi.create.foundation.blockEntity.renderer; import com.mojang.blaze3d.vertex.PoseStack; +import net.minecraft.client.Minecraft; import net.minecraft.client.renderer.MultiBufferSource; import net.minecraft.client.renderer.blockentity.BlockEntityRenderer; +import net.minecraft.client.renderer.culling.Frustum; import net.minecraft.world.level.block.Blocks; import net.minecraft.world.level.block.entity.BlockEntity; +import net.minecraft.world.phys.AABB; +import net.minecraft.world.phys.Vec3; public abstract class SafeBlockEntityRenderer implements BlockEntityRenderer { @Override @@ -23,4 +27,21 @@ public abstract class SafeBlockEntityRenderer implements return !be.hasLevel() || be.getBlockState() .getBlock() == Blocks.AIR; } + + public boolean shouldCullItem(Vec3 itemPos) { + Frustum frustum = Minecraft.getInstance().levelRenderer.capturedFrustum != null ? + Minecraft.getInstance().levelRenderer.capturedFrustum : + Minecraft.getInstance().levelRenderer.cullingFrustum; + + AABB itemBB = new AABB( + itemPos.x - 0.25, + itemPos.y - 0.25, + itemPos.z - 0.25, + itemPos.x + 0.25, + itemPos.y + 0.25, + itemPos.z + 0.25 + ); + + return !frustum.isVisible(itemBB); + } } diff --git a/src/main/resources/META-INF/accesstransformer.cfg b/src/main/resources/META-INF/accesstransformer.cfg index a911f646d..1bc660abe 100644 --- a/src/main/resources/META-INF/accesstransformer.cfg +++ b/src/main/resources/META-INF/accesstransformer.cfg @@ -42,3 +42,6 @@ public net.minecraft.client.model.AgeableListModel f_102012_ # bodyYOffset public net.minecraft.client.gui.components.CommandSuggestions f_93866_ # suggestions public net.minecraft.client.gui.components.CommandSuggestions$SuggestionsList (Lnet/minecraft/client/gui/components/CommandSuggestions;IIILjava/util/List;Z)V # + +public net.minecraft.client.renderer.LevelRenderer f_172938_ # cullingFrustum +public net.minecraft.client.renderer.LevelRenderer f_109442_ # capturedFrustum From 7bd602a33f838bd8904c4ac8edf9cc21220862e4 Mon Sep 17 00:00:00 2001 From: simibubi <31564874+simibubi@users.noreply.github.com> Date: Mon, 15 Jul 2024 11:44:30 +0200 Subject: [PATCH 8/9] The Dupe Chute - Fixed a duplication bug involving belts and chutes #6210 #5781 #6686 --- .../content/kinetics/belt/transport/BeltInventory.java | 2 ++ .../belt/transport/ItemHandlerBeltSegment.java | 10 ++++++---- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/simibubi/create/content/kinetics/belt/transport/BeltInventory.java b/src/main/java/com/simibubi/create/content/kinetics/belt/transport/BeltInventory.java index 42b0939f6..1d1b80b05 100644 --- a/src/main/java/com/simibubi/create/content/kinetics/belt/transport/BeltInventory.java +++ b/src/main/java/com/simibubi/create/content/kinetics/belt/transport/BeltInventory.java @@ -378,6 +378,8 @@ public class BeltInventory { float min = offset; float max = offset + 1; for (TransportedItemStack stack : items) { + if (toRemove.contains(stack)) + continue; if (stack.beltPosition > max) continue; if (stack.beltPosition > min) diff --git a/src/main/java/com/simibubi/create/content/kinetics/belt/transport/ItemHandlerBeltSegment.java b/src/main/java/com/simibubi/create/content/kinetics/belt/transport/ItemHandlerBeltSegment.java index 3395f9393..0a5248c5f 100644 --- a/src/main/java/com/simibubi/create/content/kinetics/belt/transport/ItemHandlerBeltSegment.java +++ b/src/main/java/com/simibubi/create/content/kinetics/belt/transport/ItemHandlerBeltSegment.java @@ -50,13 +50,15 @@ public class ItemHandlerBeltSegment implements IItemHandler { return ItemStack.EMPTY; amount = Math.min(amount, transported.stack.getCount()); - ItemStack extracted = simulate ? transported.stack.copy().split(amount) : transported.stack.split(amount); + ItemStack extracted = simulate ? transported.stack.copy() + .split(amount) : transported.stack.split(amount); if (!simulate) { if (transported.stack.isEmpty()) - this.beltInventory.toRemove.add(transported); - this.beltInventory.belt.setChanged(); - this.beltInventory.belt.sendData(); + beltInventory.toRemove.add(transported); + else + beltInventory.belt.notifyUpdate(); } + return extracted; } From 4b3dcc32abb34a32fd420b44e2812ef8e17ce87e Mon Sep 17 00:00:00 2001 From: simibubi <31564874+simibubi@users.noreply.github.com> Date: Mon, 15 Jul 2024 12:58:38 +0200 Subject: [PATCH 9/9] Equals does not equal not equals - Fix inverted fluid comparison from a recent PR --- .../create/foundation/fluid/FluidHelper.java | 8 ++++++++ .../create/foundation/fluid/FluidIngredient.java | 16 +++++++--------- 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/src/main/java/com/simibubi/create/foundation/fluid/FluidHelper.java b/src/main/java/com/simibubi/create/foundation/fluid/FluidHelper.java index befb004b2..5d54e13cf 100644 --- a/src/main/java/com/simibubi/create/foundation/fluid/FluidHelper.java +++ b/src/main/java/com/simibubi/create/foundation/fluid/FluidHelper.java @@ -49,6 +49,14 @@ public class FluidHelper { public static boolean isLava(Fluid fluid) { return convertToStill(fluid) == Fluids.LAVA; } + + public static boolean isSame(FluidStack fluidStack, FluidStack fluidStack2) { + return fluidStack.getFluid() == fluidStack2.getFluid(); + } + + public static boolean isSame(FluidStack fluidStack, Fluid fluid) { + return fluidStack.getFluid() == fluid; + } @SuppressWarnings("deprecation") public static boolean isTag(Fluid fluid, TagKey tag) { diff --git a/src/main/java/com/simibubi/create/foundation/fluid/FluidIngredient.java b/src/main/java/com/simibubi/create/foundation/fluid/FluidIngredient.java index 0a6fcca97..9f1eccaf0 100644 --- a/src/main/java/com/simibubi/create/foundation/fluid/FluidIngredient.java +++ b/src/main/java/com/simibubi/create/foundation/fluid/FluidIngredient.java @@ -152,7 +152,7 @@ public abstract class FluidIngredient implements Predicate { @Override protected boolean testInternal(FluidStack t) { - if (t.getFluid() != fluid) + if (!FluidHelper.isSame(t, fluid)) return false; if (tagToMatch.isEmpty()) return true; @@ -200,16 +200,14 @@ public abstract class FluidIngredient implements Predicate { protected TagKey tag; - @SuppressWarnings("deprecation") @Override protected boolean testInternal(FluidStack t) { - if (tag == null) { - for (FluidStack accepted : getMatchingFluidStacks()) - if (accepted.getFluid() != t.getFluid()) - return true; - return false; - } - return t.getFluid().is(tag); + if (tag != null) + return FluidHelper.isTag(t, tag); + for (FluidStack accepted : getMatchingFluidStacks()) + if (FluidHelper.isSame(accepted, t)) + return true; + return false; } @Override