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

@ -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

View file

@ -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);