Skip to content

Commit

Permalink
Made a few more blocks WaterLoggable
Browse files Browse the repository at this point in the history
Fixed some issues with Sand Layers
Added a few new tags
  • Loading branch information
GirafiStudios committed Nov 2, 2020
1 parent 0544385 commit 219c948
Show file tree
Hide file tree
Showing 9 changed files with 188 additions and 40 deletions.
53 changes: 41 additions & 12 deletions src/main/java/com/teammetallurgy/atum/blocks/SandLayersBlock.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,29 +23,41 @@
import javax.annotation.Nullable;

public class SandLayersBlock extends FallingBlock {
private static final Material SAND_LAYER = new Material.Builder(MaterialColor.SAND).notSolid().pushDestroys().replaceable().build();
private static final Material SAND_LAYER = new Material.Builder(MaterialColor.SAND).doesNotBlockMovement().notOpaque().notSolid().pushDestroys().replaceable().build();
public static final IntegerProperty LAYERS = BlockStateProperties.LAYERS_1_8;
private static final VoxelShape[] SAND_SHAPE = new VoxelShape[]{VoxelShapes.empty(), Block.makeCuboidShape(0.0D, 0.0D, 0.0D, 16.0D, 2.0D, 16.0D), Block.makeCuboidShape(0.0D, 0.0D, 0.0D, 16.0D, 4.0D, 16.0D), Block.makeCuboidShape(0.0D, 0.0D, 0.0D, 16.0D, 6.0D, 16.0D), Block.makeCuboidShape(0.0D, 0.0D, 0.0D, 16.0D, 8.0D, 16.0D), Block.makeCuboidShape(0.0D, 0.0D, 0.0D, 16.0D, 10.0D, 16.0D), Block.makeCuboidShape(0.0D, 0.0D, 0.0D, 16.0D, 12.0D, 16.0D), Block.makeCuboidShape(0.0D, 0.0D, 0.0D, 16.0D, 14.0D, 16.0D), Block.makeCuboidShape(0.0D, 0.0D, 0.0D, 16.0D, 16.0D, 16.0D)};

public SandLayersBlock() {
super(Block.Properties.create(SAND_LAYER).tickRandomly().hardnessAndResistance(0.1F).sound(SoundType.SAND).harvestTool(ToolType.SHOVEL).harvestLevel(0));
super(Block.Properties.create(SAND_LAYER).hardnessAndResistance(0.1F).sound(SoundType.SAND).harvestTool(ToolType.SHOVEL).harvestLevel(0));
this.setDefaultState(this.stateContainer.getBaseState().with(LAYERS, 1));
}

@Override
@Nonnull
public VoxelShape getShape(BlockState state, IBlockReader world, BlockPos pos, ISelectionContext context) {
public VoxelShape getShape(BlockState state, @Nonnull IBlockReader world, @Nonnull BlockPos pos, @Nonnull ISelectionContext context) {
return SAND_SHAPE[state.get(LAYERS)];
}

@Override
@Nonnull
public VoxelShape getCollisionShape(@Nonnull BlockState state, @Nonnull IBlockReader reader, @Nonnull BlockPos pos, ISelectionContext context) {
public VoxelShape getCollisionShape(BlockState state, @Nonnull IBlockReader world, @Nonnull BlockPos pos, @Nonnull ISelectionContext context) {
return SAND_SHAPE[state.get(LAYERS) - 1];
}

@Override
public boolean allowsMovement(@Nonnull BlockState state, @Nonnull IBlockReader reader, @Nonnull BlockPos pos, PathType pathType) {
@Nonnull
public VoxelShape getCollisionShape(BlockState state, @Nonnull IBlockReader reader, @Nonnull BlockPos pos) {
return SAND_SHAPE[state.get(LAYERS)];
}

@Override
@Nonnull
public VoxelShape getRayTraceShape(BlockState state, @Nonnull IBlockReader reader, @Nonnull BlockPos pos, @Nonnull ISelectionContext context) {
return SAND_SHAPE[state.get(LAYERS)];
}

@Override
public boolean allowsMovement(@Nonnull BlockState state, @Nonnull IBlockReader reader, @Nonnull BlockPos pos, @Nonnull PathType pathType) {
if (pathType == PathType.LAND) {
return state.get(LAYERS) < 5;
} else {
Expand All @@ -54,27 +66,44 @@ public boolean allowsMovement(@Nonnull BlockState state, @Nonnull IBlockReader r
}

@Override
public boolean isTransparent(BlockState state) {
public boolean isTransparent(@Nonnull BlockState state) {
return true;
}

@Override
public boolean isValidPosition(BlockState state, IWorldReader reader, BlockPos pos) {
BlockState stateDown = reader.getBlockState(pos.down());
Block blockDown = stateDown.getBlock();
if (blockDown != Blocks.ICE && blockDown != Blocks.PACKED_ICE && blockDown != Blocks.BARRIER) {
return Block.doesSideFillSquare(stateDown.getCollisionShape(reader, pos.down()), Direction.UP) || blockDown == this && stateDown.get(LAYERS) == 8;
public boolean isValidPosition(@Nonnull BlockState state, @Nonnull IWorldReader world, BlockPos pos) {
BlockState stateDown = world.getBlockState(pos.down());
if (!stateDown.isIn(Blocks.ICE) && !stateDown.isIn(Blocks.PACKED_ICE) && !stateDown.isIn(Blocks.BARRIER)) {
if (!stateDown.isIn(Blocks.HONEY_BLOCK) && !stateDown.isIn(Blocks.SOUL_SAND)) {
return Block.doesSideFillSquare(stateDown.getCollisionShape(world, pos.down()), Direction.UP) || stateDown.getBlock() == this && stateDown.get(LAYERS) == 8;
} else {
return true;
}
} else {
return false;
}
}

@Override
@Nonnull
public BlockState updatePostPlacement(BlockState state, Direction direction, BlockState facingState, IWorld world, @Nonnull BlockPos currentPos, BlockPos facingPos) {
public BlockState updatePostPlacement(BlockState state, @Nonnull Direction direction, @Nonnull BlockState facingState, @Nonnull IWorld world, @Nonnull BlockPos currentPos, @Nonnull BlockPos facingPos) {
return !state.isValidPosition(world, currentPos) ? Blocks.AIR.getDefaultState() : super.updatePostPlacement(state, direction, facingState, world, currentPos, facingPos);
}

@Override
public boolean isReplaceable(BlockState state, BlockItemUseContext useContext) {
int layers = state.get(LAYERS);
if (useContext.getItem().getItem() == this.asItem() && layers < 8) {
if (useContext.replacingClickedOnBlock()) {
return useContext.getFace() == Direction.UP;
} else {
return true;
}
} else {
return layers == 1;
}
}

@Override
@Nullable
public BlockState getStateForPlacement(BlockItemUseContext context) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,16 @@
import net.minecraft.block.material.Material;
import net.minecraft.block.material.MaterialColor;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.fluid.FluidState;
import net.minecraft.fluid.Fluids;
import net.minecraft.inventory.IInventory;
import net.minecraft.inventory.InventoryHelper;
import net.minecraft.item.BlockItemUseContext;
import net.minecraft.item.ItemStack;
import net.minecraft.state.BooleanProperty;
import net.minecraft.state.DirectionProperty;
import net.minecraft.state.StateContainer;
import net.minecraft.state.properties.BlockStateProperties;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.*;
import net.minecraft.util.math.BlockPos;
Expand All @@ -26,13 +30,14 @@
import javax.annotation.Nonnull;
import javax.annotation.Nullable;

public class QuernBlock extends ContainerBlock {
public class QuernBlock extends ContainerBlock implements IWaterLoggable {
public static final DirectionProperty FACING = HorizontalBlock.HORIZONTAL_FACING;
public static final BooleanProperty WATERLOGGED = BlockStateProperties.WATERLOGGED;
private static final VoxelShape SHAPE = makeCuboidShape(0.12D * 16, 0.0D, 0.12D * 16, 0.88D * 16, 0.38D * 16, 0.88D * 16);

public QuernBlock() {
super(Properties.create(Material.ROCK, MaterialColor.SAND).hardnessAndResistance(1.5F));
this.setDefaultState(this.stateContainer.getBaseState().with(FACING, Direction.NORTH));
this.setDefaultState(this.stateContainer.getBaseState().with(FACING, Direction.NORTH).with(WATERLOGGED, false));
}

@Override
Expand Down Expand Up @@ -101,18 +106,37 @@ public ActionResultType onBlockActivated(@Nonnull BlockState state, @Nonnull Wor

@Override
public void onReplaced(@Nonnull BlockState state, @Nonnull World world, @Nonnull BlockPos pos, @Nonnull BlockState newState, boolean isMoving) {
if (newState.getBlock() != state.getBlock()) {
TileEntity tileEntity = world.getTileEntity(pos);
if (tileEntity instanceof QuernTileEntity) {
InventoryHelper.dropInventoryItems(world, pos, (IInventory) tileEntity);
if (!state.isIn(newState.getBlock())) {
if (newState.getBlock() != state.getBlock()) {
TileEntity tileEntity = world.getTileEntity(pos);
if (tileEntity instanceof QuernTileEntity) {
InventoryHelper.dropInventoryItems(world, pos, (IInventory) tileEntity);
}
world.removeTileEntity(pos);
}
world.removeTileEntity(pos);
super.onReplaced(state, world, pos, newState, isMoving);
}
}

@Override
public BlockState getStateForPlacement(BlockItemUseContext context) {
return this.getDefaultState().with(FACING, context.getPlacementHorizontalFacing());
FluidState fluidstate = context.getWorld().getFluidState(context.getPos());
return this.getDefaultState().with(FACING, context.getPlacementHorizontalFacing()).with(WATERLOGGED, fluidstate.getFluid() == Fluids.WATER);
}

@Override
@Nonnull
public BlockState updatePostPlacement(@Nonnull BlockState state, @Nonnull Direction facing, @Nonnull BlockState facingState, @Nonnull IWorld world, @Nonnull BlockPos currentPos, @Nonnull BlockPos facingPos) {
if (state.get(WATERLOGGED)) {
world.getPendingFluidTicks().scheduleTick(currentPos, Fluids.WATER, Fluids.WATER.getTickRate(world));
}
return super.updatePostPlacement(state, facing, facingState, world, currentPos, facingPos);
}

@Override
@Nonnull
public FluidState getFluidState(BlockState state) {
return state.get(WATERLOGGED) ? Fluids.WATER.getStillFluidState(false) : super.getFluidState(state);
}

@Override
Expand All @@ -128,7 +152,7 @@ public BlockState mirror(@Nonnull BlockState state, Mirror mirror) {

@Override
protected void fillStateContainer(StateContainer.Builder<Block, BlockState> container) {
container.add(FACING);
container.add(FACING, WATERLOGGED);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,13 @@
import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.block.Blocks;
import net.minecraft.block.IWaterLoggable;
import net.minecraft.fluid.FluidState;
import net.minecraft.fluid.Fluids;
import net.minecraft.item.BlockItemUseContext;
import net.minecraft.state.BooleanProperty;
import net.minecraft.state.StateContainer;
import net.minecraft.state.properties.BlockStateProperties;
import net.minecraft.util.Direction;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.shapes.ISelectionContext;
Expand All @@ -13,11 +20,13 @@

import javax.annotation.Nonnull;

public class CeramicTileBlock extends CeramicBlock {
public class CeramicTileBlock extends CeramicBlock implements IWaterLoggable {
private static final VoxelShape TILE_SHAPE = Block.makeCuboidShape(0.0D, 0.0D, 0.0D, 16.0D, 1.0D, 16.0D);
public static final BooleanProperty WATERLOGGED = BlockStateProperties.WATERLOGGED;

public CeramicTileBlock(Properties properties) {
super(properties.hardnessAndResistance(0.5F));
this.setDefaultState(this.getDefaultState().with(WATERLOGGED, false));
}

@Override
Expand All @@ -26,14 +35,34 @@ public VoxelShape getShape(@Nonnull BlockState state, @Nonnull IBlockReader read
return TILE_SHAPE;
}

@Override
public BlockState getStateForPlacement(BlockItemUseContext context) {
FluidState fluidstate = context.getWorld().getFluidState(context.getPos());
return this.getDefaultState().with(WATERLOGGED, fluidstate.getFluid() == Fluids.WATER);
}

@Override
@Nonnull
public BlockState updatePostPlacement(BlockState state, @Nonnull Direction direction, @Nonnull BlockState facingState, @Nonnull IWorld world, @Nonnull BlockPos currentPos, @Nonnull BlockPos facingPos) {
if (state.get(WATERLOGGED)) {
world.getPendingFluidTicks().scheduleTick(currentPos, Fluids.WATER, Fluids.WATER.getTickRate(world));
}
return !state.isValidPosition(world, currentPos) ? Blocks.AIR.getDefaultState() : super.updatePostPlacement(state, direction, facingState, world, currentPos, facingPos);
}

@Override
public boolean isValidPosition(@Nonnull BlockState state, IWorldReader reader, BlockPos pos) {
return !reader.isAirBlock(pos.down());
}

@Override
@Nonnull
public FluidState getFluidState(BlockState state) {
return state.get(WATERLOGGED) ? Fluids.WATER.getStillFluidState(false) : super.getFluidState(state);
}

@Override
protected void fillStateContainer(StateContainer.Builder<Block, BlockState> builder) {
builder.add(WATERLOGGED);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,16 @@

import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.block.IWaterLoggable;
import net.minecraft.block.SoundType;
import net.minecraft.block.material.Material;
import net.minecraft.fluid.FluidState;
import net.minecraft.fluid.Fluids;
import net.minecraft.item.BlockItemUseContext;
import net.minecraft.state.BooleanProperty;
import net.minecraft.state.EnumProperty;
import net.minecraft.state.StateContainer;
import net.minecraft.state.properties.BlockStateProperties;
import net.minecraft.util.Direction;
import net.minecraft.util.Mirror;
import net.minecraft.util.Rotation;
Expand All @@ -29,17 +33,18 @@
import java.util.Map;
import java.util.Random;

public class DeadwoodBranchBlock extends Block {
public class DeadwoodBranchBlock extends Block implements IWaterLoggable {
public static final EnumProperty<Direction> FACING = EnumProperty.create("facing", Direction.class);
public static final BooleanProperty WATERLOGGED = BlockStateProperties.WATERLOGGED;
public static final BooleanProperty NORTH = BooleanProperty.create("north");
public static final BooleanProperty EAST = BooleanProperty.create("east");
public static final BooleanProperty SOUTH = BooleanProperty.create("south");
public static final BooleanProperty WEST = BooleanProperty.create("west");
public static final BooleanProperty UP = BooleanProperty.create("up");
public static final BooleanProperty DOWN = BooleanProperty.create("down");

private static final Map<Direction, VoxelShape> bounds;
private static final Map<Direction, VoxelShape> connectedBounds;
private static final Map<Direction, VoxelShape> BOUNDS;
private static final Map<Direction, VoxelShape> CONNECTED_BOUNDS;

private static final VoxelShape EAST_AABB = VoxelShapes.create(5 / 16D, 5 / 16D, 5 / 16D, 1.0D, 11 / 16D, 11 / 16D);
private static final VoxelShape WEST_AABB = VoxelShapes.create(0.0D, 5 / 16D, 5 / 16D, 11 / 16D, 11 / 16D, 11 / 16D);
Expand All @@ -49,26 +54,26 @@ public class DeadwoodBranchBlock extends Block {
private static final VoxelShape DOWN_AABB = VoxelShapes.create(5 / 16D, 0.0D, 5 / 16D, 11 / 16D, 11 / 16D, 11 / 16D);

static {
bounds = new HashMap<>();
connectedBounds = new HashMap<>();
bounds.put(Direction.EAST, EAST_AABB);
bounds.put(Direction.WEST, WEST_AABB);
bounds.put(Direction.NORTH, NORTH_AABB);
bounds.put(Direction.SOUTH, SOUTH_AABB);
bounds.put(Direction.UP, UP_AABB);
bounds.put(Direction.DOWN, DOWN_AABB);
BOUNDS = new HashMap<>();
CONNECTED_BOUNDS = new HashMap<>();
BOUNDS.put(Direction.EAST, EAST_AABB);
BOUNDS.put(Direction.WEST, WEST_AABB);
BOUNDS.put(Direction.NORTH, NORTH_AABB);
BOUNDS.put(Direction.SOUTH, SOUTH_AABB);
BOUNDS.put(Direction.UP, UP_AABB);
BOUNDS.put(Direction.DOWN, DOWN_AABB);

for (Direction facing : Direction.values()) {
AxisAlignedBB box = bounds.get(facing).getBoundingBox();
AxisAlignedBB box = BOUNDS.get(facing).getBoundingBox();
AxisAlignedBB expandedBox = new AxisAlignedBB(box.minX, box.minY, box.minZ, box.maxX, box.maxY, box.maxZ);
expandedBox.expand(5 * facing.getXOffset(), 5 * facing.getYOffset(), 5 * facing.getZOffset());
connectedBounds.put(facing, VoxelShapes.create(expandedBox));
CONNECTED_BOUNDS.put(facing, VoxelShapes.create(expandedBox));
}
}

public DeadwoodBranchBlock() {
super(Properties.create(Material.WOOD).hardnessAndResistance(0.8F, 5.0F).sound(SoundType.WOOD).tickRandomly().harvestTool(ToolType.AXE).harvestLevel(0).notSolid());
this.setDefaultState(this.getStateContainer().getBaseState().with(FACING, Direction.NORTH).with(NORTH, false).with(EAST, false).with(SOUTH, false).with(WEST, false).with(UP, false).with(DOWN, false));
this.setDefaultState(this.getStateContainer().getBaseState().with(FACING, Direction.NORTH).with(NORTH, false).with(EAST, false).with(SOUTH, false).with(WEST, false).with(UP, false).with(DOWN, false).with(WATERLOGGED, false));
}

@Override
Expand Down Expand Up @@ -104,23 +109,39 @@ public VoxelShape getShape(BlockState state, IBlockReader reader, BlockPos pos,

BlockState neighbor = reader.getBlockState(pos.add(facing.getDirectionVec()));
if (neighbor.getBlock() == this) {
AxisAlignedBB box = connectedBounds.get(facing).getBoundingBox();
AxisAlignedBB box = CONNECTED_BOUNDS.get(facing).getBoundingBox();
AxisAlignedBB expandedBox = new AxisAlignedBB(box.minX, box.minY, box.minZ, box.maxX, box.maxY, box.maxZ);
return VoxelShapes.create(expandedBox.expand(5 / 16D * facing.getXOffset(), 5 / 16D * facing.getYOffset(), 5 / 16D * facing.getZOffset()));
} else {
return bounds.get(facing);
return BOUNDS.get(facing);
}
}

@Nullable
@Override
public BlockState getStateForPlacement(@Nonnull BlockItemUseContext context) {
return this.makeConnections(context.getWorld(), context.getPos(), context.getFace());
FluidState fluidstate = context.getWorld().getFluidState(context.getPos());
return this.makeConnections(context.getWorld(), context.getPos(), context.getFace()).with(WATERLOGGED, fluidstate.getFluid() == Fluids.WATER);
}

@Override
@Nonnull
public BlockState updatePostPlacement(BlockState state, @Nonnull Direction direction, @Nonnull BlockState facingState, @Nonnull IWorld world, @Nonnull BlockPos currentPos, @Nonnull BlockPos facingPos) {
if (state.get(WATERLOGGED)) {
world.getPendingFluidTicks().scheduleTick(currentPos, Fluids.WATER, Fluids.WATER.getTickRate(world));
}
return super.updatePostPlacement(state, direction, facingState, world, currentPos, facingPos);
}

@Override
@Nonnull
public FluidState getFluidState(BlockState state) {
return state.get(WATERLOGGED) ? Fluids.WATER.getStillFluidState(false) : super.getFluidState(state);
}

@Override
protected void fillStateContainer(StateContainer.Builder<Block, BlockState> container) {
container.add(FACING, NORTH, SOUTH, EAST, WEST, UP, DOWN);
container.add(FACING, NORTH, SOUTH, EAST, WEST, UP, DOWN, WATERLOGGED);
}

public BlockState makeConnections(IWorldReader world, BlockPos pos) {
Expand Down
12 changes: 12 additions & 0 deletions src/main/resources/data/minecraft/tags/blocks/doors.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"replace": false,
"values": [
"atum:limestone_door",
"atum:limestone_cracked_door",
"atum:limestone_brick_small_door",
"atum:limestone_brick_large_door",
"atum:limestone_brick_cracked_brick_door",
"atum:limestone_brick_chiseled_door",
"atum:limestone_brick_carved_door"
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"replace": false,
"values": [
"atum:palm_door",
"atum:deadwood_door"
]
}

0 comments on commit 219c948

Please sign in to comment.