Support new fabric block appearance API

This commit is contained in:
modmuss50 2022-11-08 08:57:21 +00:00
parent 3d5300e908
commit 878aa0a74d
4 changed files with 16 additions and 3 deletions

View file

@ -51,6 +51,7 @@ import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Direction;
import net.minecraft.util.shape.VoxelShape;
import net.minecraft.util.shape.VoxelShapes;
import net.minecraft.world.BlockRenderView;
import net.minecraft.world.BlockView;
import net.minecraft.world.World;
import net.minecraft.world.WorldAccess;
@ -260,4 +261,16 @@ public class CableBlock extends BlockWithEntity implements Waterloggable {
public FluidState getFluidState(BlockState state) {
return state.get(WATERLOGGED) ? Fluids.WATER.getStill(false) : super.getFluidState(state);
}
@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();
}
}
return super.getAppearance(state, renderView, pos, side, sourceState, sourcePos);
}
}