Appearance fixes and improvements.
This commit is contained in:
parent
c30db3317c
commit
12a729234c
8 changed files with 57 additions and 46 deletions
|
@ -45,16 +45,14 @@ public class CableCoverRenderer implements BlockEntityRenderer<CableBlockEntity>
|
|||
|
||||
@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());
|
||||
}
|
||||
|
||||
|
|
|
@ -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<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.
|
||||
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<EnergyStorage, Direction> cache) {
|
||||
|
||||
@Nullable
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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 }
|
||||
}
|
||||
]
|
||||
|
|
|
@ -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 }
|
||||
}
|
||||
]
|
||||
|
|
|
@ -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 }
|
||||
}
|
||||
]
|
||||
|
|
|
@ -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 }
|
||||
}
|
||||
]
|
||||
|
|
|
@ -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 }
|
||||
}
|
||||
]
|
||||
|
|
Loading…
Add table
Reference in a new issue