fix fluid tank voxel shape gap

This commit is contained in:
LordGrimmauld 2020-06-17 16:14:46 +02:00
parent 7b64f06d79
commit 80e680eb9c
2 changed files with 110 additions and 97 deletions

View file

@ -3,6 +3,7 @@ package com.simibubi.create.content.contraptions.fluids;
import com.simibubi.create.AllBlocks; import com.simibubi.create.AllBlocks;
import com.simibubi.create.AllShapes; import com.simibubi.create.AllShapes;
import com.simibubi.create.AllTileEntities; import com.simibubi.create.AllTileEntities;
import net.minecraft.block.Block; import net.minecraft.block.Block;
import net.minecraft.block.BlockState; import net.minecraft.block.BlockState;
import net.minecraft.item.BlockItemUseContext; import net.minecraft.item.BlockItemUseContext;
@ -14,6 +15,7 @@ import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.shapes.ISelectionContext; import net.minecraft.util.math.shapes.ISelectionContext;
import net.minecraft.util.math.shapes.VoxelShape; import net.minecraft.util.math.shapes.VoxelShape;
import net.minecraft.util.math.shapes.VoxelShapes;
import net.minecraft.world.IBlockReader; import net.minecraft.world.IBlockReader;
import net.minecraft.world.ILightReader; import net.minecraft.world.ILightReader;
import net.minecraft.world.IWorld; import net.minecraft.world.IWorld;
@ -23,114 +25,125 @@ import net.minecraftforge.api.distmarker.OnlyIn;
public class FluidTankBlock extends Block { public class FluidTankBlock extends Block {
public static final BooleanProperty TOP = BooleanProperty.create("top"); public static final BooleanProperty TOP = BooleanProperty.create("top");
public static final BooleanProperty BOTTOM = BooleanProperty.create("bottom"); public static final BooleanProperty BOTTOM = BooleanProperty.create("bottom");
public FluidTankBlock(Properties p_i48440_1_) {
super(p_i48440_1_);
setDefaultState(getDefaultState().with(TOP, true)
.with(BOTTOM, true));
}
public static boolean shouldDrawDiagonalFiller(ILightReader world, BlockPos pos, BlockState state, boolean north, public FluidTankBlock(Properties p_i48440_1_) {
boolean east) { super(p_i48440_1_);
if (!isTank(state)) setDefaultState(getDefaultState().with(TOP, true)
return false; .with(BOTTOM, true));
int northOffset = north ? 1 : -1; }
int eastOffset = east ? 1 : -1;
if (!isTank(world.getBlockState(pos.north(northOffset))))
return false;
if (!isTank(world.getBlockState(pos.east(eastOffset))))
return false;
return !isTank(world.getBlockState(pos.east(eastOffset)
.north(northOffset)));
}
public static boolean shouldDrawCapFiller(ILightReader world, BlockPos pos, BlockState state, Direction direction, public static boolean shouldDrawDiagonalFiller(ILightReader world, BlockPos pos, BlockState state, boolean north,
boolean top) { boolean east) {
if (!isTank(state)) if (!isTank(state))
return false; return false;
if (top && !state.get(TOP)) int northOffset = north ? 1 : -1;
return false; int eastOffset = east ? 1 : -1;
if (!top && !state.get(BOTTOM)) if (!isTank(world.getBlockState(pos.north(northOffset))))
return false; return false;
BlockPos adjacentPos = pos.offset(direction); if (!isTank(world.getBlockState(pos.east(eastOffset))))
BlockState adjacentState = world.getBlockState(adjacentPos); return false;
if (!isTank(adjacentState)) return !isTank(world.getBlockState(pos.east(eastOffset)
return false; .north(northOffset)));
if (top && adjacentState.get(TOP)) }
return false;
return top || !adjacentState.get(BOTTOM);
}
public static boolean isTank(BlockState state) { public static boolean shouldDrawCapFiller(ILightReader world, BlockPos pos, BlockState state, Direction direction,
return state.getBlock() instanceof FluidTankBlock; boolean top) {
} if (!isTank(state))
return false;
if (top && !state.get(TOP))
return false;
if (!top && !state.get(BOTTOM))
return false;
BlockPos adjacentPos = pos.offset(direction);
BlockState adjacentState = world.getBlockState(adjacentPos);
if (!isTank(adjacentState))
return false;
if (top && adjacentState.get(TOP))
return false;
return top || !adjacentState.get(BOTTOM);
}
@Override public static boolean isTank(BlockState state) {
protected void fillStateContainer(Builder<Block, BlockState> p_206840_1_) { return state.getBlock() instanceof FluidTankBlock;
p_206840_1_.add(TOP, BOTTOM); }
}
@Override @Override
public BlockState getStateForPlacement(BlockItemUseContext p_196258_1_) { protected void fillStateContainer(Builder<Block, BlockState> p_206840_1_) {
World world = p_196258_1_.getWorld(); p_206840_1_.add(TOP, BOTTOM);
BlockPos pos = p_196258_1_.getPos(); }
BlockState state = super.getStateForPlacement(p_196258_1_);
state = updateState(state, world, pos, Direction.UP);
state = updateState(state, world, pos, Direction.DOWN);
return state;
}
private boolean isTankToDirection(IBlockReader world, BlockPos pos, Direction direction) { @Override
return world.getBlockState(pos.offset(direction)).getBlock() instanceof FluidTankBlock; public BlockState getStateForPlacement(BlockItemUseContext p_196258_1_) {
} World world = p_196258_1_.getWorld();
BlockPos pos = p_196258_1_.getPos();
BlockState state = super.getStateForPlacement(p_196258_1_);
state = updateState(state, world, pos, Direction.UP);
state = updateState(state, world, pos, Direction.DOWN);
return state;
}
public AxisAlignedBB getTankBodyShape(IBlockReader world, BlockPos pos) { private boolean isTankToDirection(IBlockReader world, BlockPos pos, Direction direction) {
return new AxisAlignedBB((isTankToDirection(world, pos, Direction.WEST) ? 0 : 2) / 16f, return world.getBlockState(pos.offset(direction)).getBlock() instanceof FluidTankBlock;
(isTankToDirection(world, pos, Direction.DOWN) ? 0 : 4) / 16f, }
(isTankToDirection(world, pos, Direction.NORTH) ? 0 : 2) / 16f,
(isTankToDirection(world, pos, Direction.EAST) ? 16 : 14) / 16f,
(isTankToDirection(world, pos, Direction.UP) ? 16 : 12) / 16f,
(isTankToDirection(world, pos, Direction.SOUTH) ? 16 : 14) / 16f);
}
@Override public AxisAlignedBB getTankShape(IBlockReader world, BlockPos pos) {
public VoxelShape getShape(BlockState state, IBlockReader world, BlockPos pos, return new AxisAlignedBB((isTankToDirection(world, pos, Direction.WEST) ? 0 : 2) / 16f,
ISelectionContext p_220053_4_) { (isTankToDirection(world, pos, Direction.DOWN) ? 0 : 4) / 16f,
boolean top = state.get(TOP); (isTankToDirection(world, pos, Direction.NORTH) ? 0 : 2) / 16f,
boolean bottom = state.get(BOTTOM); (isTankToDirection(world, pos, Direction.EAST) ? 16 : 14) / 16f,
return top ? bottom ? AllShapes.TANK_TOP_BOTTOM : AllShapes.TANK_TOP (isTankToDirection(world, pos, Direction.UP) ? 16 : 12) / 16f,
: bottom ? AllShapes.TANK_BOTTOM : AllShapes.TANK; (isTankToDirection(world, pos, Direction.SOUTH) ? 16 : 14) / 16f);
}
@Override }
public BlockState updatePostPlacement(BlockState state, Direction direction, BlockState p_196271_3_, IWorld world,
BlockPos pos, BlockPos p_196271_6_) {
return updateState(state, world, pos, direction);
}
private BlockState updateState(BlockState state, ILightReader reader, BlockPos pos, Direction direction) { public AxisAlignedBB getBodyShape(IBlockReader world, BlockPos pos) {
if (direction.getAxis() return new AxisAlignedBB((isTankToDirection(world, pos, Direction.WEST) ? 0 : 1) / 16f,
.isHorizontal()) 0.25f,
return state; (isTankToDirection(world, pos, Direction.NORTH) ? 0 : 1) / 16f,
return state.with(direction == Direction.UP ? TOP : BOTTOM, (isTankToDirection(world, pos, Direction.EAST) ? 16 : 15) / 16f,
!AllBlocks.FLUID_TANK.has(reader.getBlockState(pos.offset(direction)))); 0.75f,
} (isTankToDirection(world, pos, Direction.SOUTH) ? 16 : 15) / 16f);
}
@Override @Override
@OnlyIn(Dist.CLIENT) public VoxelShape getShape(BlockState state, IBlockReader world, BlockPos pos,
public boolean isSideInvisible(BlockState state, BlockState adjacentBlockState, Direction side) { ISelectionContext p_220053_4_) {
return adjacentBlockState.getBlock() == this; boolean top = state.get(TOP);
} boolean bottom = state.get(BOTTOM);
return VoxelShapes.or(top ? bottom ? AllShapes.TANK_TOP_BOTTOM : AllShapes.TANK_TOP
: bottom ? AllShapes.TANK_BOTTOM : AllShapes.TANK, VoxelShapes.create(getBodyShape(world, pos)));
}
@Override @Override
public boolean hasTileEntity(BlockState state) { public BlockState updatePostPlacement(BlockState state, Direction direction, BlockState p_196271_3_, IWorld world,
return true; BlockPos pos, BlockPos p_196271_6_) {
} return updateState(state, world, pos, direction);
}
@Override private BlockState updateState(BlockState state, ILightReader reader, BlockPos pos, Direction direction) {
public TileEntity createTileEntity(BlockState state, IBlockReader world) { if (direction.getAxis()
return AllTileEntities.FLUID_TANK.create(); .isHorizontal())
} return state;
return state.with(direction == Direction.UP ? TOP : BOTTOM,
!AllBlocks.FLUID_TANK.has(reader.getBlockState(pos.offset(direction))));
}
@Override
@OnlyIn(Dist.CLIENT)
public boolean isSideInvisible(BlockState state, BlockState adjacentBlockState, Direction side) {
return adjacentBlockState.getBlock() == this;
}
@Override
public boolean hasTileEntity(BlockState state) {
return true;
}
@Override
public TileEntity createTileEntity(BlockState state, IBlockReader world) {
return AllTileEntities.FLUID_TANK.create();
}
} }

View file

@ -175,7 +175,7 @@ public class FluidTankRenderer extends SafeTileEntityRenderer<FluidTankTileEntit
} }
private List<FluidTankRenderInfo> getTanksToRender(FluidTankTileEntity te) { private List<FluidTankRenderInfo> getTanksToRender(FluidTankTileEntity te) {
return Collections.singletonList(new FluidTankRenderInfo(te, ((FluidTankBlock) te.getBlockState().getBlock()).getTankBodyShape(te.getWorld(), te.getPos()))); return Collections.singletonList(new FluidTankRenderInfo(te, ((FluidTankBlock) te.getBlockState().getBlock()).getTankShape(te.getWorld(), te.getPos())));
} }
private static class FluidTankRenderInfo { private static class FluidTankRenderInfo {