From 12a729234c53271fadb9d7efae165eb2dece7d01 Mon Sep 17 00:00:00 2001 From: modmuss50 Date: Mon, 14 Nov 2022 08:56:42 +0000 Subject: [PATCH] Appearance fixes and improvements. --- .../render/entitys/CableCoverRenderer.java | 12 +++++------- .../blockentity/cable/CableBlockEntity.java | 9 ++++++++- .../techreborn/blocks/cable/CableBlock.java | 17 ++++++++++++++--- .../blockstates/glassfiber_cable.json | 13 ++++++------- .../blockstates/insulated_copper_cable.json | 13 ++++++------- .../blockstates/insulated_gold_cable.json | 13 ++++++------- .../blockstates/insulated_hv_cable.json | 13 ++++++------- .../blockstates/superconductor_cable.json | 13 ++++++------- 8 files changed, 57 insertions(+), 46 deletions(-) diff --git a/src/client/java/techreborn/client/render/entitys/CableCoverRenderer.java b/src/client/java/techreborn/client/render/entitys/CableCoverRenderer.java index 1cbd2677d..1ebf469a7 100644 --- a/src/client/java/techreborn/client/render/entitys/CableCoverRenderer.java +++ b/src/client/java/techreborn/client/render/entitys/CableCoverRenderer.java @@ -45,16 +45,14 @@ public class CableCoverRenderer implements BlockEntityRenderer @Override public void render(CableBlockEntity blockEntity, float tickDelta, MatrixStack matrices, VertexConsumerProvider vertexConsumers, int light, int overlay) { - if (blockEntity.getWorld() == null) { - return; - } - BlockState blockState = blockEntity.getWorld().getBlockState(blockEntity.getPos()); - if (!(blockState.getBlock() instanceof CableBlock) || !blockState.get(CableBlock.COVERED)) { + if (!blockEntity.getCachedState().get(CableBlock.COVERED) || blockEntity.getWorld() == null) { return; } + final BlockRenderManager blockRenderManager = MinecraftClient.getInstance().getBlockRenderManager(); - BlockState coverState = blockEntity.getCover() != null ? blockEntity.getCover() : Blocks.OAK_PLANKS.getDefaultState(); - VertexConsumer consumer = vertexConsumers.getBuffer(RenderLayers.getBlockLayer(coverState)); + final BlockState renderData = blockEntity.getRenderAttachmentData(); + final BlockState coverState = renderData != null ? renderData : Blocks.OAK_PLANKS.getDefaultState(); + final VertexConsumer consumer = vertexConsumers.getBuffer(RenderLayers.getBlockLayer(coverState)); blockRenderManager.renderBlock(coverState, blockEntity.getPos(), blockEntity.getWorld(), matrices, consumer, true, Random.create()); } diff --git a/src/main/java/techreborn/blockentity/cable/CableBlockEntity.java b/src/main/java/techreborn/blockentity/cable/CableBlockEntity.java index ed903f219..92c2b7485 100644 --- a/src/main/java/techreborn/blockentity/cable/CableBlockEntity.java +++ b/src/main/java/techreborn/blockentity/cable/CableBlockEntity.java @@ -25,6 +25,7 @@ package techreborn.blockentity.cable; import net.fabricmc.fabric.api.lookup.v1.block.BlockApiCache; +import net.fabricmc.fabric.api.rendering.data.v1.RenderAttachmentBlockEntity; import net.minecraft.block.Block; import net.minecraft.block.BlockState; import net.minecraft.block.entity.BlockEntity; @@ -57,7 +58,7 @@ import java.util.ArrayList; import java.util.List; public class CableBlockEntity extends BlockEntity - implements BlockEntityTicker, IListInfoProvider, IToolDrop { + implements BlockEntityTicker, IListInfoProvider, IToolDrop, RenderAttachmentBlockEntity { // Can't use SimpleEnergyStorage because the cable type is not available when the BE is constructed. final SimpleSidedEnergyContainer energyContainer = new SimpleSidedEnergyContainer() { @Override @@ -78,6 +79,7 @@ public class CableBlockEntity extends BlockEntity } }; private TRContent.Cables cableType = null; + @Nullable private BlockState cover = null; long lastTick = 0; // null means that it needs to be re-queried @@ -292,6 +294,11 @@ public class CableBlockEntity extends BlockEntity return new ItemStack(getCableType().block); } + @Override + public @Nullable BlockState getRenderAttachmentData() { + return cover; + } + private record CableTarget(Direction directionTo, BlockApiCache cache) { @Nullable diff --git a/src/main/java/techreborn/blocks/cable/CableBlock.java b/src/main/java/techreborn/blocks/cable/CableBlock.java index dd1e15eb5..3bfa2fb2e 100644 --- a/src/main/java/techreborn/blocks/cable/CableBlock.java +++ b/src/main/java/techreborn/blocks/cable/CableBlock.java @@ -24,6 +24,7 @@ package techreborn.blocks.cable; +import net.fabricmc.fabric.api.rendering.data.v1.RenderAttachedBlockView; import net.minecraft.block.*; import net.minecraft.block.entity.BlockEntity; import net.minecraft.block.entity.BlockEntityTicker; @@ -203,6 +204,11 @@ public class CableBlock extends BlockWithEntity implements Waterloggable { return CableShapeUtil.getShape(state); } + @Override + public VoxelShape getCullingShape(BlockState state, BlockView world, BlockPos pos) { + return CableShapeUtil.getShape(state); + } + @SuppressWarnings("deprecation") @Override public void onEntityCollision(BlockState state, World world, BlockPos pos, Entity entity) { @@ -265,10 +271,15 @@ public class CableBlock extends BlockWithEntity implements Waterloggable { @Override public BlockState getAppearance(BlockState state, BlockRenderView renderView, BlockPos pos, Direction side, @Nullable BlockState sourceState, @Nullable BlockPos sourcePos) { if (state.get(COVERED)) { - if (renderView.getBlockEntity(pos) instanceof CableBlockEntity cableBlockEntity) { - final BlockState cover = cableBlockEntity.getCover(); - return cover != null ? cover : Blocks.OAK_PLANKS.getDefaultState(); + final BlockState cover; + + if (((RenderAttachedBlockView) renderView).getBlockEntityRenderAttachment(pos) instanceof BlockState blockState) { + cover = blockState; + } else { + cover = Blocks.OAK_PLANKS.getDefaultState(); } + + return cover; } return super.getAppearance(state, renderView, pos, side, sourceState, sourcePos); diff --git a/src/main/resources/assets/techreborn/blockstates/glassfiber_cable.json b/src/main/resources/assets/techreborn/blockstates/glassfiber_cable.json index 0b0141775..da657d559 100644 --- a/src/main/resources/assets/techreborn/blockstates/glassfiber_cable.json +++ b/src/main/resources/assets/techreborn/blockstates/glassfiber_cable.json @@ -1,31 +1,30 @@ { "multipart": [ { - "when": { "covered": false }, "apply": { "model": "techreborn:block/cable/glassfiber_cable_core" } }, { - "when": { "north": true, "covered": false }, + "when": { "north": true }, "apply": { "model": "techreborn:block/cable/glassfiber_cable_side" } }, { - "when": { "east": true, "covered": false }, + "when": { "east": true }, "apply": { "model": "techreborn:block/cable/glassfiber_cable_side", "y": 90 } }, { - "when": { "south": true, "covered": false }, + "when": { "south": true }, "apply": { "model": "techreborn:block/cable/glassfiber_cable_side", "y": 180 } }, { - "when": { "west": true, "covered": false }, + "when": { "west": true }, "apply": { "model": "techreborn:block/cable/glassfiber_cable_side", "y": 270 } }, { - "when": { "up": true, "covered": false }, + "when": { "up": true }, "apply": { "model": "techreborn:block/cable/glassfiber_cable_side", "x": 270} }, { - "when": { "down": true, "covered": false }, + "when": { "down": true }, "apply": { "model": "techreborn:block/cable/glassfiber_cable_side", "x": 90 } } ] diff --git a/src/main/resources/assets/techreborn/blockstates/insulated_copper_cable.json b/src/main/resources/assets/techreborn/blockstates/insulated_copper_cable.json index a010216be..c0faa365b 100644 --- a/src/main/resources/assets/techreborn/blockstates/insulated_copper_cable.json +++ b/src/main/resources/assets/techreborn/blockstates/insulated_copper_cable.json @@ -1,31 +1,30 @@ { "multipart": [ { - "when": { "covered": false }, "apply": { "model": "techreborn:block/cable/insulated_copper_cable_core" } }, { - "when": { "north": true, "covered": false }, + "when": { "north": true }, "apply": { "model": "techreborn:block/cable/insulated_copper_cable_side" } }, { - "when": { "east": true, "covered": false }, + "when": { "east": true }, "apply": { "model": "techreborn:block/cable/insulated_copper_cable_side", "y": 90 } }, { - "when": { "south": true, "covered": false }, + "when": { "south": true }, "apply": { "model": "techreborn:block/cable/insulated_copper_cable_side", "y": 180 } }, { - "when": { "west": true, "covered": false }, + "when": { "west": true }, "apply": { "model": "techreborn:block/cable/insulated_copper_cable_side", "y": 270 } }, { - "when": { "up": true, "covered": false }, + "when": { "up": true }, "apply": { "model": "techreborn:block/cable/insulated_copper_cable_side", "x": 270} }, { - "when": { "down": true, "covered": false }, + "when": { "down": true }, "apply": { "model": "techreborn:block/cable/insulated_copper_cable_side", "x": 90 } } ] diff --git a/src/main/resources/assets/techreborn/blockstates/insulated_gold_cable.json b/src/main/resources/assets/techreborn/blockstates/insulated_gold_cable.json index 7ef40ff30..a368481a2 100644 --- a/src/main/resources/assets/techreborn/blockstates/insulated_gold_cable.json +++ b/src/main/resources/assets/techreborn/blockstates/insulated_gold_cable.json @@ -1,31 +1,30 @@ { "multipart": [ { - "when": { "covered": false }, "apply": { "model": "techreborn:block/cable/insulated_gold_cable_core" } }, { - "when": { "north": true, "covered": false }, + "when": { "north": true }, "apply": { "model": "techreborn:block/cable/insulated_gold_cable_side" } }, { - "when": { "east": true, "covered": false }, + "when": { "east": true }, "apply": { "model": "techreborn:block/cable/insulated_gold_cable_side", "y": 90 } }, { - "when": { "south": true, "covered": false }, + "when": { "south": true }, "apply": { "model": "techreborn:block/cable/insulated_gold_cable_side", "y": 180 } }, { - "when": { "west": true, "covered": false }, + "when": { "west": true }, "apply": { "model": "techreborn:block/cable/insulated_gold_cable_side", "y": 270 } }, { - "when": { "up": true, "covered": false }, + "when": { "up": true }, "apply": { "model": "techreborn:block/cable/insulated_gold_cable_side", "x": 270} }, { - "when": { "down": true, "covered": false }, + "when": { "down": true }, "apply": { "model": "techreborn:block/cable/insulated_gold_cable_side", "x": 90 } } ] diff --git a/src/main/resources/assets/techreborn/blockstates/insulated_hv_cable.json b/src/main/resources/assets/techreborn/blockstates/insulated_hv_cable.json index 093d95630..d6d6de2fa 100644 --- a/src/main/resources/assets/techreborn/blockstates/insulated_hv_cable.json +++ b/src/main/resources/assets/techreborn/blockstates/insulated_hv_cable.json @@ -1,31 +1,30 @@ { "multipart": [ { - "when": { "covered": false }, "apply": { "model": "techreborn:block/cable/insulated_hv_cable_core" } }, { - "when": { "north": true, "covered": false }, + "when": { "north": true }, "apply": { "model": "techreborn:block/cable/insulated_hv_cable_side" } }, { - "when": { "east": true, "covered": false }, + "when": { "east": true }, "apply": { "model": "techreborn:block/cable/insulated_hv_cable_side", "y": 90 } }, { - "when": { "south": true, "covered": false }, + "when": { "south": true }, "apply": { "model": "techreborn:block/cable/insulated_hv_cable_side", "y": 180 } }, { - "when": { "west": true, "covered": false }, + "when": { "west": true }, "apply": { "model": "techreborn:block/cable/insulated_hv_cable_side", "y": 270 } }, { - "when": { "up": true, "covered": false }, + "when": { "up": true }, "apply": { "model": "techreborn:block/cable/insulated_hv_cable_side", "x": 270} }, { - "when": { "down": true, "covered": false }, + "when": { "down": true }, "apply": { "model": "techreborn:block/cable/insulated_hv_cable_side", "x": 90 } } ] diff --git a/src/main/resources/assets/techreborn/blockstates/superconductor_cable.json b/src/main/resources/assets/techreborn/blockstates/superconductor_cable.json index 3750351b7..58931ff6d 100644 --- a/src/main/resources/assets/techreborn/blockstates/superconductor_cable.json +++ b/src/main/resources/assets/techreborn/blockstates/superconductor_cable.json @@ -1,31 +1,30 @@ { "multipart": [ { - "when": { "covered": false }, "apply": { "model": "techreborn:block/cable/superconductor_cable_core" } }, { - "when": { "north": true, "covered": false }, + "when": { "north": true }, "apply": { "model": "techreborn:block/cable/superconductor_cable_side" } }, { - "when": { "east": true, "covered": false }, + "when": { "east": true }, "apply": { "model": "techreborn:block/cable/superconductor_cable_side", "y": 90 } }, { - "when": { "south": true, "covered": false }, + "when": { "south": true }, "apply": { "model": "techreborn:block/cable/superconductor_cable_side", "y": 180 } }, { - "when": { "west": true, "covered": false }, + "when": { "west": true }, "apply": { "model": "techreborn:block/cable/superconductor_cable_side", "y": 270 } }, { - "when": { "up": true, "covered": false }, + "when": { "up": true }, "apply": { "model": "techreborn:block/cable/superconductor_cable_side", "x": 270} }, { - "when": { "down": true, "covered": false }, + "when": { "down": true }, "apply": { "model": "techreborn:block/cable/superconductor_cable_side", "x": 90 } } ]