Appearance fixes and improvements.

This commit is contained in:
modmuss50 2022-11-14 08:56:42 +00:00
parent c30db3317c
commit 12a729234c
8 changed files with 57 additions and 46 deletions

View file

@ -45,16 +45,14 @@ public class CableCoverRenderer implements BlockEntityRenderer<CableBlockEntity>
@Override @Override
public void render(CableBlockEntity blockEntity, float tickDelta, MatrixStack matrices, VertexConsumerProvider vertexConsumers, int light, int overlay) { public void render(CableBlockEntity blockEntity, float tickDelta, MatrixStack matrices, VertexConsumerProvider vertexConsumers, int light, int overlay) {
if (blockEntity.getWorld() == null) { if (!blockEntity.getCachedState().get(CableBlock.COVERED) || blockEntity.getWorld() == null) {
return;
}
BlockState blockState = blockEntity.getWorld().getBlockState(blockEntity.getPos());
if (!(blockState.getBlock() instanceof CableBlock) || !blockState.get(CableBlock.COVERED)) {
return; return;
} }
final BlockRenderManager blockRenderManager = MinecraftClient.getInstance().getBlockRenderManager(); final BlockRenderManager blockRenderManager = MinecraftClient.getInstance().getBlockRenderManager();
BlockState coverState = blockEntity.getCover() != null ? blockEntity.getCover() : Blocks.OAK_PLANKS.getDefaultState(); final BlockState renderData = blockEntity.getRenderAttachmentData();
VertexConsumer consumer = vertexConsumers.getBuffer(RenderLayers.getBlockLayer(coverState)); 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()); blockRenderManager.renderBlock(coverState, blockEntity.getPos(), blockEntity.getWorld(), matrices, consumer, true, Random.create());
} }

View file

@ -25,6 +25,7 @@
package techreborn.blockentity.cable; package techreborn.blockentity.cable;
import net.fabricmc.fabric.api.lookup.v1.block.BlockApiCache; 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.Block;
import net.minecraft.block.BlockState; import net.minecraft.block.BlockState;
import net.minecraft.block.entity.BlockEntity; import net.minecraft.block.entity.BlockEntity;
@ -57,7 +58,7 @@ import java.util.ArrayList;
import java.util.List; import java.util.List;
public class CableBlockEntity extends BlockEntity public class CableBlockEntity extends BlockEntity
implements BlockEntityTicker<CableBlockEntity>, IListInfoProvider, IToolDrop { implements BlockEntityTicker<CableBlockEntity>, IListInfoProvider, IToolDrop, RenderAttachmentBlockEntity {
// Can't use SimpleEnergyStorage because the cable type is not available when the BE is constructed. // Can't use SimpleEnergyStorage because the cable type is not available when the BE is constructed.
final SimpleSidedEnergyContainer energyContainer = new SimpleSidedEnergyContainer() { final SimpleSidedEnergyContainer energyContainer = new SimpleSidedEnergyContainer() {
@Override @Override
@ -78,6 +79,7 @@ public class CableBlockEntity extends BlockEntity
} }
}; };
private TRContent.Cables cableType = null; private TRContent.Cables cableType = null;
@Nullable
private BlockState cover = null; private BlockState cover = null;
long lastTick = 0; long lastTick = 0;
// null means that it needs to be re-queried // null means that it needs to be re-queried
@ -292,6 +294,11 @@ public class CableBlockEntity extends BlockEntity
return new ItemStack(getCableType().block); return new ItemStack(getCableType().block);
} }
@Override
public @Nullable BlockState getRenderAttachmentData() {
return cover;
}
private record CableTarget(Direction directionTo, BlockApiCache<EnergyStorage, Direction> cache) { private record CableTarget(Direction directionTo, BlockApiCache<EnergyStorage, Direction> cache) {
@Nullable @Nullable

View file

@ -24,6 +24,7 @@
package techreborn.blocks.cable; package techreborn.blocks.cable;
import net.fabricmc.fabric.api.rendering.data.v1.RenderAttachedBlockView;
import net.minecraft.block.*; import net.minecraft.block.*;
import net.minecraft.block.entity.BlockEntity; import net.minecraft.block.entity.BlockEntity;
import net.minecraft.block.entity.BlockEntityTicker; import net.minecraft.block.entity.BlockEntityTicker;
@ -203,6 +204,11 @@ public class CableBlock extends BlockWithEntity implements Waterloggable {
return CableShapeUtil.getShape(state); return CableShapeUtil.getShape(state);
} }
@Override
public VoxelShape getCullingShape(BlockState state, BlockView world, BlockPos pos) {
return CableShapeUtil.getShape(state);
}
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")
@Override @Override
public void onEntityCollision(BlockState state, World world, BlockPos pos, Entity entity) { public void onEntityCollision(BlockState state, World world, BlockPos pos, Entity entity) {
@ -265,10 +271,15 @@ public class CableBlock extends BlockWithEntity implements Waterloggable {
@Override @Override
public BlockState getAppearance(BlockState state, BlockRenderView renderView, BlockPos pos, Direction side, @Nullable BlockState sourceState, @Nullable BlockPos sourcePos) { public BlockState getAppearance(BlockState state, BlockRenderView renderView, BlockPos pos, Direction side, @Nullable BlockState sourceState, @Nullable BlockPos sourcePos) {
if (state.get(COVERED)) { if (state.get(COVERED)) {
if (renderView.getBlockEntity(pos) instanceof CableBlockEntity cableBlockEntity) { final BlockState cover;
final BlockState cover = cableBlockEntity.getCover();
return cover != null ? cover : Blocks.OAK_PLANKS.getDefaultState(); 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); return super.getAppearance(state, renderView, pos, side, sourceState, sourcePos);

View file

@ -1,31 +1,30 @@
{ {
"multipart": [ "multipart": [
{ {
"when": { "covered": false },
"apply": { "model": "techreborn:block/cable/glassfiber_cable_core" } "apply": { "model": "techreborn:block/cable/glassfiber_cable_core" }
}, },
{ {
"when": { "north": true, "covered": false }, "when": { "north": true },
"apply": { "model": "techreborn:block/cable/glassfiber_cable_side" } "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 } "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 } "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 } "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} "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 } "apply": { "model": "techreborn:block/cable/glassfiber_cable_side", "x": 90 }
} }
] ]

View file

@ -1,31 +1,30 @@
{ {
"multipart": [ "multipart": [
{ {
"when": { "covered": false },
"apply": { "model": "techreborn:block/cable/insulated_copper_cable_core" } "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" } "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 } "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 } "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 } "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} "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 } "apply": { "model": "techreborn:block/cable/insulated_copper_cable_side", "x": 90 }
} }
] ]

View file

@ -1,31 +1,30 @@
{ {
"multipart": [ "multipart": [
{ {
"when": { "covered": false },
"apply": { "model": "techreborn:block/cable/insulated_gold_cable_core" } "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" } "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 } "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 } "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 } "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} "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 } "apply": { "model": "techreborn:block/cable/insulated_gold_cable_side", "x": 90 }
} }
] ]

View file

@ -1,31 +1,30 @@
{ {
"multipart": [ "multipart": [
{ {
"when": { "covered": false },
"apply": { "model": "techreborn:block/cable/insulated_hv_cable_core" } "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" } "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 } "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 } "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 } "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} "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 } "apply": { "model": "techreborn:block/cable/insulated_hv_cable_side", "x": 90 }
} }
] ]

View file

@ -1,31 +1,30 @@
{ {
"multipart": [ "multipart": [
{ {
"when": { "covered": false },
"apply": { "model": "techreborn:block/cable/superconductor_cable_core" } "apply": { "model": "techreborn:block/cable/superconductor_cable_core" }
}, },
{ {
"when": { "north": true, "covered": false }, "when": { "north": true },
"apply": { "model": "techreborn:block/cable/superconductor_cable_side" } "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 } "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 } "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 } "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} "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 } "apply": { "model": "techreborn:block/cable/superconductor_cable_side", "x": 90 }
} }
] ]