From 48a8e28b88da4ea0302f5ac40f04b8ef2077af2f Mon Sep 17 00:00:00 2001 From: lothrazar Date: Fri, 4 Oct 2024 14:05:05 -0700 Subject: [PATCH] facade rendering now uses tesselateBlock, configs updated --- gradle.properties | 2 +- .../block/cable/BlockCable.java | 10 ++--- .../block/cable/CableFacadeRenderer.java | 43 +++++++++++++++++++ .../storagenetwork/block/cable/TileCable.java | 4 +- .../block/facade/TesrCable.java | 31 ------------- .../block/facade/TesrExportCable.java | 31 ------------- .../block/facade/TesrImportCable.java | 31 ------------- .../block/facade/TesrImportFilterCable.java | 31 ------------- .../block/facade/TesrStorageCable.java | 31 ------------- .../registry/ClientEventRegistry.java | 16 +++---- .../registry/ConfigRegistry.java | 28 ++++++++---- .../storagenetwork/registry/SsnEvents.java | 19 ++++---- .../storagenetwork/registry/SsnRegistry.java | 3 -- update.json | 1 + 14 files changed, 88 insertions(+), 193 deletions(-) create mode 100644 src/main/java/com/lothrazar/storagenetwork/block/cable/CableFacadeRenderer.java delete mode 100644 src/main/java/com/lothrazar/storagenetwork/block/facade/TesrCable.java delete mode 100644 src/main/java/com/lothrazar/storagenetwork/block/facade/TesrExportCable.java delete mode 100644 src/main/java/com/lothrazar/storagenetwork/block/facade/TesrImportCable.java delete mode 100644 src/main/java/com/lothrazar/storagenetwork/block/facade/TesrImportFilterCable.java delete mode 100644 src/main/java/com/lothrazar/storagenetwork/block/facade/TesrStorageCable.java diff --git a/gradle.properties b/gradle.properties index 51cc9c6c..2ed1bc6d 100644 --- a/gradle.properties +++ b/gradle.properties @@ -13,7 +13,7 @@ org.gradle.daemon=false mod_id=storagenetwork curse_id=268495 -mod_version=1.11.1 +mod_version=1.11.2-SNAPSHOT diff --git a/src/main/java/com/lothrazar/storagenetwork/block/cable/BlockCable.java b/src/main/java/com/lothrazar/storagenetwork/block/cable/BlockCable.java index 7a4af675..32d1129f 100644 --- a/src/main/java/com/lothrazar/storagenetwork/block/cable/BlockCable.java +++ b/src/main/java/com/lothrazar/storagenetwork/block/cable/BlockCable.java @@ -125,11 +125,11 @@ public static BlockState cleanBlockState(BlockState state) { @Override public VoxelShape getShape(BlockState state, BlockGetter worldIn, BlockPos pos, CollisionContext context) { - TileCable tile = TileCable.getTileCable(worldIn, pos); - if (tile != null - && ConfigRegistry.facadesUseCollisionBoundingBox.get() - && tile.getFacadeState() != null) { - return tile.getFacadeState().getShape(worldIn, pos, context); + if (ConfigRegistry.enableFacades.get()) { + TileCable tile = TileCable.getTileCable(worldIn, pos); + if (tile != null && tile.getFacadeState() != null) { + return tile.getFacadeState().getShape(worldIn, pos, context); + } } return ShapeCache.getOrCreate(state, ShapeBuilder::createShape); } diff --git a/src/main/java/com/lothrazar/storagenetwork/block/cable/CableFacadeRenderer.java b/src/main/java/com/lothrazar/storagenetwork/block/cable/CableFacadeRenderer.java new file mode 100644 index 00000000..3d9ce8b6 --- /dev/null +++ b/src/main/java/com/lothrazar/storagenetwork/block/cable/CableFacadeRenderer.java @@ -0,0 +1,43 @@ +package com.lothrazar.storagenetwork.block.cable; + +import com.lothrazar.storagenetwork.registry.ConfigRegistry; +import com.mojang.blaze3d.vertex.PoseStack; +import com.mojang.blaze3d.vertex.VertexConsumer; +import com.mojang.blaze3d.vertex.VertexMultiConsumer; +import net.minecraft.client.renderer.MultiBufferSource; +import net.minecraft.client.renderer.RenderType; +import net.minecraft.client.renderer.block.BlockRenderDispatcher; +import net.minecraft.client.renderer.block.ModelBlockRenderer; +import net.minecraft.client.renderer.blockentity.BlockEntityRenderer; +import net.minecraft.client.renderer.blockentity.BlockEntityRendererProvider; +import net.minecraft.client.resources.model.BakedModel; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraftforge.client.model.data.ModelData; + +public class CableFacadeRenderer implements BlockEntityRenderer { + + private BlockRenderDispatcher brd; + private ModelBlockRenderer renderer; + + public CableFacadeRenderer(BlockEntityRendererProvider.Context d) { + this.brd = d.getBlockRenderDispatcher(); + this.renderer = brd.getModelRenderer(); + } + + @Override + public boolean shouldRenderOffScreen(TileCable te) { + return true; + } + + @Override + public void render(TileCable te, float v, PoseStack matrixStack, MultiBufferSource ibuffer, int packedLight, int packedOverlay) { + if (ConfigRegistry.enableFacades.get() && te.getFacadeState() != null) { + BlockState facadeState = te.getFacadeState(); + BakedModel model = this.brd.getBlockModel(facadeState); + VertexConsumer vertexConsumer = VertexMultiConsumer.create(ibuffer.getBuffer(RenderType.solid())); + renderer.tesselateBlock(te.getLevel(), model, facadeState, te.getBlockPos(), + matrixStack, vertexConsumer, false, te.getLevel().random, packedLight, packedOverlay, + ModelData.EMPTY, RenderType.solid()); + } + } +} diff --git a/src/main/java/com/lothrazar/storagenetwork/block/cable/TileCable.java b/src/main/java/com/lothrazar/storagenetwork/block/cable/TileCable.java index b8c35e4c..01903f84 100644 --- a/src/main/java/com/lothrazar/storagenetwork/block/cable/TileCable.java +++ b/src/main/java/com/lothrazar/storagenetwork/block/cable/TileCable.java @@ -37,14 +37,13 @@ public void load(CompoundTag compound) { else { setFacadeState(null); } - } @Override public void saveAdditional(CompoundTag compound) { super.saveAdditional(compound); if (facadeState != null) { - compound.put(NBT_FACADE, facadeState); + compound.put(NBT_FACADE, facadeState); } } @@ -67,5 +66,4 @@ public BlockState getFacadeState() { public void setFacadeState(CompoundTag facadeState) { this.facadeState = facadeState; } - } diff --git a/src/main/java/com/lothrazar/storagenetwork/block/facade/TesrCable.java b/src/main/java/com/lothrazar/storagenetwork/block/facade/TesrCable.java deleted file mode 100644 index 8e2ab3d3..00000000 --- a/src/main/java/com/lothrazar/storagenetwork/block/facade/TesrCable.java +++ /dev/null @@ -1,31 +0,0 @@ -package com.lothrazar.storagenetwork.block.facade; - -import com.lothrazar.storagenetwork.block.cable.TileCable; -import com.mojang.blaze3d.vertex.PoseStack; -import net.minecraft.client.renderer.MultiBufferSource; -import net.minecraft.client.renderer.RenderType; -import net.minecraft.client.renderer.block.BlockRenderDispatcher; -import net.minecraft.client.renderer.blockentity.BlockEntityRenderer; -import net.minecraft.client.renderer.blockentity.BlockEntityRendererProvider; -import net.minecraftforge.client.model.data.ModelData; - -public class TesrCable implements BlockEntityRenderer { - - private BlockRenderDispatcher brd; - - public TesrCable(BlockEntityRendererProvider.Context d) { - this.brd = d.getBlockRenderDispatcher(); - } - - @Override - public boolean shouldRenderOffScreen(TileCable te) { - return true; - } - - @Override - public void render(TileCable te, float v, PoseStack matrixStack, MultiBufferSource ibuffer, int partialTicks, int destroyStage) { - if (te.getFacadeState() != null) { - brd.renderSingleBlock(te.getFacadeState(), matrixStack, ibuffer, partialTicks, destroyStage, ModelData.EMPTY, RenderType.solid()); - } - } -} diff --git a/src/main/java/com/lothrazar/storagenetwork/block/facade/TesrExportCable.java b/src/main/java/com/lothrazar/storagenetwork/block/facade/TesrExportCable.java deleted file mode 100644 index a64363c9..00000000 --- a/src/main/java/com/lothrazar/storagenetwork/block/facade/TesrExportCable.java +++ /dev/null @@ -1,31 +0,0 @@ -package com.lothrazar.storagenetwork.block.facade; - -import com.lothrazar.storagenetwork.block.cable.export.TileCableExport; -import com.mojang.blaze3d.vertex.PoseStack; -import net.minecraft.client.renderer.MultiBufferSource; -import net.minecraft.client.renderer.RenderType; -import net.minecraft.client.renderer.block.BlockRenderDispatcher; -import net.minecraft.client.renderer.blockentity.BlockEntityRenderer; -import net.minecraft.client.renderer.blockentity.BlockEntityRendererProvider; -import net.minecraftforge.client.model.data.ModelData; - -public class TesrExportCable implements BlockEntityRenderer { - - private BlockRenderDispatcher brd; - - public TesrExportCable(BlockEntityRendererProvider.Context d) { - this.brd = d.getBlockRenderDispatcher(); - } - - @Override - public boolean shouldRenderOffScreen(TileCableExport te) { - return true; - } - - @Override - public void render(TileCableExport te, float v, PoseStack matrixStack, MultiBufferSource ibuffer, int partialTicks, int destroyStage) { - if (te.getFacadeState() != null) { - brd.renderSingleBlock(te.getFacadeState(), matrixStack, ibuffer, partialTicks, destroyStage, ModelData.EMPTY, RenderType.solid()); - } - } -} diff --git a/src/main/java/com/lothrazar/storagenetwork/block/facade/TesrImportCable.java b/src/main/java/com/lothrazar/storagenetwork/block/facade/TesrImportCable.java deleted file mode 100644 index 908857a5..00000000 --- a/src/main/java/com/lothrazar/storagenetwork/block/facade/TesrImportCable.java +++ /dev/null @@ -1,31 +0,0 @@ -package com.lothrazar.storagenetwork.block.facade; - -import com.lothrazar.storagenetwork.block.cable.input.TileCableIO; -import com.mojang.blaze3d.vertex.PoseStack; -import net.minecraft.client.renderer.MultiBufferSource; -import net.minecraft.client.renderer.RenderType; -import net.minecraft.client.renderer.block.BlockRenderDispatcher; -import net.minecraft.client.renderer.blockentity.BlockEntityRenderer; -import net.minecraft.client.renderer.blockentity.BlockEntityRendererProvider; -import net.minecraftforge.client.model.data.ModelData; - -public class TesrImportCable implements BlockEntityRenderer { - - private BlockRenderDispatcher brd; - - public TesrImportCable(BlockEntityRendererProvider.Context d) { - this.brd = d.getBlockRenderDispatcher(); - } - - @Override - public boolean shouldRenderOffScreen(TileCableIO te) { - return true; - } - - @Override - public void render(TileCableIO te, float v, PoseStack matrixStack, MultiBufferSource ibuffer, int partialTicks, int destroyStage) { - if (te.getFacadeState() != null) { - brd.renderSingleBlock(te.getFacadeState(), matrixStack, ibuffer, partialTicks, destroyStage, ModelData.EMPTY, RenderType.solid()); - } - } -} diff --git a/src/main/java/com/lothrazar/storagenetwork/block/facade/TesrImportFilterCable.java b/src/main/java/com/lothrazar/storagenetwork/block/facade/TesrImportFilterCable.java deleted file mode 100644 index 18501353..00000000 --- a/src/main/java/com/lothrazar/storagenetwork/block/facade/TesrImportFilterCable.java +++ /dev/null @@ -1,31 +0,0 @@ -package com.lothrazar.storagenetwork.block.facade; - -import com.lothrazar.storagenetwork.block.cable.inputfilter.TileCableImportFilter; -import com.mojang.blaze3d.vertex.PoseStack; -import net.minecraft.client.renderer.MultiBufferSource; -import net.minecraft.client.renderer.RenderType; -import net.minecraft.client.renderer.block.BlockRenderDispatcher; -import net.minecraft.client.renderer.blockentity.BlockEntityRenderer; -import net.minecraft.client.renderer.blockentity.BlockEntityRendererProvider; -import net.minecraftforge.client.model.data.ModelData; - -public class TesrImportFilterCable implements BlockEntityRenderer { - - private BlockRenderDispatcher brd; - - public TesrImportFilterCable(BlockEntityRendererProvider.Context d) { - this.brd = d.getBlockRenderDispatcher(); - } - - @Override - public boolean shouldRenderOffScreen(TileCableImportFilter te) { - return true; - } - - @Override - public void render(TileCableImportFilter te, float v, PoseStack matrixStack, MultiBufferSource ibuffer, int partialTicks, int destroyStage) { - if (te.getFacadeState() != null) { - brd.renderSingleBlock(te.getFacadeState(), matrixStack, ibuffer, partialTicks, destroyStage, ModelData.EMPTY, RenderType.solid()); - } - } -} diff --git a/src/main/java/com/lothrazar/storagenetwork/block/facade/TesrStorageCable.java b/src/main/java/com/lothrazar/storagenetwork/block/facade/TesrStorageCable.java deleted file mode 100644 index 6d9df564..00000000 --- a/src/main/java/com/lothrazar/storagenetwork/block/facade/TesrStorageCable.java +++ /dev/null @@ -1,31 +0,0 @@ -package com.lothrazar.storagenetwork.block.facade; - -import com.lothrazar.storagenetwork.block.cable.link.TileCableLink; -import com.mojang.blaze3d.vertex.PoseStack; -import net.minecraft.client.renderer.MultiBufferSource; -import net.minecraft.client.renderer.RenderType; -import net.minecraft.client.renderer.block.BlockRenderDispatcher; -import net.minecraft.client.renderer.blockentity.BlockEntityRenderer; -import net.minecraft.client.renderer.blockentity.BlockEntityRendererProvider; -import net.minecraftforge.client.model.data.ModelData; - -public class TesrStorageCable implements BlockEntityRenderer { - - private BlockRenderDispatcher brd; - - public TesrStorageCable(BlockEntityRendererProvider.Context d) { - this.brd = d.getBlockRenderDispatcher(); - } - - @Override - public boolean shouldRenderOffScreen(TileCableLink te) { - return true; - } - - @Override - public void render(TileCableLink te, float v, PoseStack matrixStack, MultiBufferSource ibuffer, int partialTicks, int destroyStage) { - if (te.getFacadeState() != null) { - brd.renderSingleBlock(te.getFacadeState(), matrixStack, ibuffer, partialTicks, destroyStage, ModelData.EMPTY, RenderType.solid()); - } - } -} diff --git a/src/main/java/com/lothrazar/storagenetwork/registry/ClientEventRegistry.java b/src/main/java/com/lothrazar/storagenetwork/registry/ClientEventRegistry.java index 55729dff..d9c565a5 100644 --- a/src/main/java/com/lothrazar/storagenetwork/registry/ClientEventRegistry.java +++ b/src/main/java/com/lothrazar/storagenetwork/registry/ClientEventRegistry.java @@ -2,11 +2,7 @@ import org.lwjgl.glfw.GLFW; import com.lothrazar.storagenetwork.StorageNetworkMod; -import com.lothrazar.storagenetwork.block.facade.TesrCable; -import com.lothrazar.storagenetwork.block.facade.TesrExportCable; -import com.lothrazar.storagenetwork.block.facade.TesrImportCable; -import com.lothrazar.storagenetwork.block.facade.TesrImportFilterCable; -import com.lothrazar.storagenetwork.block.facade.TesrStorageCable; +import com.lothrazar.storagenetwork.block.cable.CableFacadeRenderer; import com.lothrazar.storagenetwork.registry.SsnRegistry.Tiles; import com.mojang.blaze3d.platform.InputConstants; import net.minecraft.client.KeyMapping; @@ -25,10 +21,10 @@ public class ClientEventRegistry { @SubscribeEvent public static void onRegisterRenderers(EntityRenderersEvent.RegisterRenderers event) { - event.registerBlockEntityRenderer(Tiles.KABEL.get(), TesrCable::new); - event.registerBlockEntityRenderer(Tiles.EXPORT_KABEL.get(), TesrExportCable::new); - event.registerBlockEntityRenderer(Tiles.STORAGE_KABEL.get(), TesrStorageCable::new); - event.registerBlockEntityRenderer(Tiles.IMPORT_FILTER_KABEL.get(), TesrImportFilterCable::new); - event.registerBlockEntityRenderer(Tiles.IMPORT_KABEL.get(), TesrImportCable::new); + event.registerBlockEntityRenderer(Tiles.KABEL.get(), CableFacadeRenderer::new); + event.registerBlockEntityRenderer(Tiles.EXPORT_KABEL.get(), CableFacadeRenderer::new); + event.registerBlockEntityRenderer(Tiles.STORAGE_KABEL.get(), CableFacadeRenderer::new); + event.registerBlockEntityRenderer(Tiles.IMPORT_FILTER_KABEL.get(), CableFacadeRenderer::new); + event.registerBlockEntityRenderer(Tiles.IMPORT_KABEL.get(), CableFacadeRenderer::new); } } diff --git a/src/main/java/com/lothrazar/storagenetwork/registry/ConfigRegistry.java b/src/main/java/com/lothrazar/storagenetwork/registry/ConfigRegistry.java index 50b19ec3..47c9b148 100644 --- a/src/main/java/com/lothrazar/storagenetwork/registry/ConfigRegistry.java +++ b/src/main/java/com/lothrazar/storagenetwork/registry/ConfigRegistry.java @@ -28,7 +28,7 @@ public class ConfigRegistry { public static IntValue ITEMRANGE; public static IntValue RECIPEMAXTAGS; private static ConfigValue> CABLEIGNORELIST; - public static BooleanValue facadesUseCollisionBoundingBox; + public static BooleanValue enableFacades; static { initConfig(); } @@ -62,13 +62,25 @@ private static void initConfig() { RECIPEMAXTAGS = COMMON_BUILDER.comment("\r\n When matching items to recipes in the JEI + button, this is the maximum number of tags to serialize over the network when on a server. Reduce if you get errors relating to Packet Sizes being too large (Minecraft 1.12.2 had this hardcoded at 5).") .defineInRange("jeiMaximumRecipeTags", 64, 5, 128); // - list = Arrays.asList("minecraft:golden_rail", "minecraft:ladder", "minecraft:rail", "minecraft:detector_rail", "minecraft:activator_rail", - "minecraft:double_plant", - "minecraft:waterlily"); - CABLEIGNORELIST = COMMON_BUILDER.comment("\r\n Disable these blocks from ever being able to connect to the network, they will be treated as a non-inventory.") - .define("BlacklistFacadeCableItems", list); - facadesUseCollisionBoundingBox = COMMON_BUILDER.comment("If this is true, cables with facades will also use the collision block from the block facade (ie stairs, carpet, etc). ") - .define("facadesUseCollisionBoundingBox", true); + COMMON_BUILDER.push("facades"); + list = Arrays.asList("minecraft:ladder", "minecraft:double_plant", "minecraft:waterlily", + "minecraft:torch", "minecraft:*_torch", "minecraft:redstone", "minecraft:iron_bars", + "minecraft:chest", "minecraft:ender_chest", "minecraft:sculk_vein", "minecraft:string", "minecraft:vine", + "minecraft:rail", + "minecraft:*_rail", + "minecraft:brewing_stand", + "minecraft:*_dripleaf", + "minecraft:*_pane", + "minecraft:*_sapling", "minecraft:*_sign", + "minecraft:*_door", + "minecraft:*_banner", "minecraft:*_shulker_box", + "cyclic:*_pipe", "cyclic:*_bars", + "storagenetwork:*"); + CABLEIGNORELIST = COMMON_BUILDER.comment("\r\n These items are not able to be used as Facade blocks for cables (shift-left-click to add or remove block facades while in not-creative)") + .define("itemsNotAllowed", list); + enableFacades = COMMON_BUILDER.comment("Change this to 'false' to disable facades. The facade feature lets you hide cables with blocks (does not consume the item, use shift-left-click when not creative)") + .define("enabled", true); + COMMON_BUILDER.pop(); COMMON_BUILDER.pop(); COMMON_CONFIG = COMMON_BUILDER.build(); } diff --git a/src/main/java/com/lothrazar/storagenetwork/registry/SsnEvents.java b/src/main/java/com/lothrazar/storagenetwork/registry/SsnEvents.java index 1c1e5fe1..302445bd 100644 --- a/src/main/java/com/lothrazar/storagenetwork/registry/SsnEvents.java +++ b/src/main/java/com/lothrazar/storagenetwork/registry/SsnEvents.java @@ -30,7 +30,12 @@ public void onEntityItemPickupEvent(EntityItemPickupEvent event) { @SubscribeEvent public void onHit(PlayerInteractEvent.LeftClickBlock event) { ItemBuilder.onLeftClickBlock(event); + if (ConfigRegistry.enableFacades.get()) { + onHitFacadeHandler(event); + } + } + private void onHitFacadeHandler(PlayerInteractEvent.LeftClickBlock event) { Level level = event.getLevel(); if (!level.isClientSide) { return; @@ -45,19 +50,18 @@ public void onHit(PlayerInteractEvent.LeftClickBlock event) { else { Block block = Block.byItem(held.getItem()); if (block == null || block == Blocks.AIR) { - StorageNetworkMod.log("no block"); return; } if (!ConfigRegistry.isFacadeAllowed(held)) { - StorageNetworkMod.log("not allowed as a facade from config file"); + StorageNetworkMod.log("not allowed as a facade from config file: " + held.getItem()); return; } - BlockHitResult bhr = (BlockHitResult) player.pick(5, 1, false); + //pick the block, write to tags, and send to server + boolean pickFluids = false; + BlockHitResult bhr = (BlockHitResult) player.pick(player.getBlockReach(), 1, pickFluids); BlockPlaceContext context = new BlockPlaceContext(player, event.getHand(), held, bhr); - - BlockState facadeState = null; - facadeState = block.getStateForPlacement(context); - CompoundTag tags = NbtUtils.writeBlockState(facadeState); + BlockState facadeState = block.getStateForPlacement(context); + CompoundTag tags = (facadeState == null) ? null : NbtUtils.writeBlockState(facadeState); PacketRegistry.INSTANCE.sendToServer(new CableFacadeMessage(event.getPos(), tags)); } } @@ -70,5 +74,4 @@ public void onKeyInput(InputEvent.Key event) { PacketRegistry.INSTANCE.sendToServer(new KeybindCurioMessage()); } } - } diff --git a/src/main/java/com/lothrazar/storagenetwork/registry/SsnRegistry.java b/src/main/java/com/lothrazar/storagenetwork/registry/SsnRegistry.java index 659f32fc..075e9d55 100644 --- a/src/main/java/com/lothrazar/storagenetwork/registry/SsnRegistry.java +++ b/src/main/java/com/lothrazar/storagenetwork/registry/SsnRegistry.java @@ -111,11 +111,8 @@ public static class Tiles { public static final RegistryObject> EXPORT_KABEL = TILES.register("export_kabel", () -> BlockEntityType.Builder.of(TileCableExport::new, Blocks.EXPORT_KABEL.get()).build(null)); public static final RegistryObject> EXCHANGE = TILES.register("exchange", () -> BlockEntityType.Builder.of(TileExchange::new, Blocks.EXCHANGE.get()).build(null)); public static final RegistryObject> COLLECTOR = TILES.register("collector", () -> BlockEntityType.Builder.of(TileCollection::new, Blocks.COLLECTOR.get()).build(null)); - - } - @Mod.EventBusSubscriber(bus = Mod.EventBusSubscriber.Bus.MOD) public static class Menus { diff --git a/update.json b/update.json index 9b42f817..889019ee 100644 --- a/update.json +++ b/update.json @@ -10,5 +10,6 @@ ,"1.11.1":"The Storage Request Table 'storagenetwork:request' block no longer saves the contents of its crafting-grid; instead items are returned to the player on close, exactly matching vanilla crafting table behavior (this was changed to prevent potential exploits. If any items are left behind in the grid during world upgrade they will be returned and not lost. No changes were made to the remotes or to other blocks). Fixed a null pointer exception " + ,"1.11.2":"Ported the Cable Facades feature (from Minecraft 1.12.2), so that you can shift-left-click with a block on a cable to hide it with a facade. Disable this feature or ignore cretain blocks with the config file" } }