2018-12-27 13:57:23 +01:00
|
|
|
package de.ellpeck.naturesaura.blocks;
|
|
|
|
|
|
|
|
import de.ellpeck.naturesaura.blocks.tiles.TileEntityGratedChute;
|
2020-01-21 23:02:39 +01:00
|
|
|
import net.minecraft.block.*;
|
2018-12-27 13:57:23 +01:00
|
|
|
import net.minecraft.block.material.Material;
|
2019-10-20 22:30:49 +02:00
|
|
|
import net.minecraft.entity.player.PlayerEntity;
|
2020-01-22 21:21:23 +01:00
|
|
|
import net.minecraft.item.BlockItemUseContext;
|
2018-12-27 14:01:38 +01:00
|
|
|
import net.minecraft.item.ItemStack;
|
2019-11-04 19:08:49 +01:00
|
|
|
import net.minecraft.state.DirectionProperty;
|
2020-01-21 17:46:32 +01:00
|
|
|
import net.minecraft.state.StateContainer;
|
2020-01-23 16:05:52 +01:00
|
|
|
import net.minecraft.tileentity.IHopper;
|
2018-12-27 14:01:38 +01:00
|
|
|
import net.minecraft.tileentity.TileEntity;
|
2020-01-21 17:46:32 +01:00
|
|
|
import net.minecraft.util.BlockRenderLayer;
|
|
|
|
import net.minecraft.util.Direction;
|
|
|
|
import net.minecraft.util.Hand;
|
2018-12-27 13:57:23 +01:00
|
|
|
import net.minecraft.util.math.BlockPos;
|
2019-11-04 19:08:49 +01:00
|
|
|
import net.minecraft.util.math.BlockRayTraceResult;
|
2018-12-27 14:01:38 +01:00
|
|
|
import net.minecraft.util.math.MathHelper;
|
2020-01-23 16:05:52 +01:00
|
|
|
import net.minecraft.util.math.shapes.IBooleanFunction;
|
|
|
|
import net.minecraft.util.math.shapes.ISelectionContext;
|
2019-11-04 19:08:49 +01:00
|
|
|
import net.minecraft.util.math.shapes.VoxelShape;
|
2020-01-23 16:05:52 +01:00
|
|
|
import net.minecraft.util.math.shapes.VoxelShapes;
|
|
|
|
import net.minecraft.world.IBlockReader;
|
2018-12-27 13:57:23 +01:00
|
|
|
import net.minecraft.world.World;
|
2019-10-20 22:30:49 +02:00
|
|
|
import net.minecraftforge.api.distmarker.Dist;
|
|
|
|
import net.minecraftforge.api.distmarker.OnlyIn;
|
2018-12-27 14:01:38 +01:00
|
|
|
import net.minecraftforge.items.IItemHandler;
|
2018-12-27 13:57:23 +01:00
|
|
|
|
2020-01-22 21:21:23 +01:00
|
|
|
import javax.annotation.Nullable;
|
|
|
|
|
2018-12-27 13:57:23 +01:00
|
|
|
public class BlockGratedChute extends BlockContainerImpl {
|
|
|
|
|
2019-11-04 19:08:49 +01:00
|
|
|
public static final DirectionProperty FACING = HopperBlock.FACING;
|
2020-01-23 16:05:52 +01:00
|
|
|
private static final VoxelShape INPUT_SHAPE = Block.makeCuboidShape(0.0D, 10.0D, 0.0D, 16.0D, 16.0D, 16.0D);
|
|
|
|
private static final VoxelShape MIDDLE_SHAPE = Block.makeCuboidShape(4.0D, 4.0D, 4.0D, 12.0D, 10.0D, 12.0D);
|
|
|
|
private static final VoxelShape INPUT_MIDDLE_SHAPE = VoxelShapes.or(MIDDLE_SHAPE, INPUT_SHAPE);
|
|
|
|
private static final VoxelShape COMBINED_SHAPE = VoxelShapes.combineAndSimplify(INPUT_MIDDLE_SHAPE, IHopper.INSIDE_BOWL_SHAPE, IBooleanFunction.ONLY_FIRST);
|
|
|
|
private static final VoxelShape DOWN_SHAPE = VoxelShapes.or(COMBINED_SHAPE, Block.makeCuboidShape(6.0D, 0.0D, 6.0D, 10.0D, 4.0D, 10.0D));
|
|
|
|
private static final VoxelShape EAST_SHAPE = VoxelShapes.or(COMBINED_SHAPE, Block.makeCuboidShape(12.0D, 4.0D, 6.0D, 16.0D, 8.0D, 10.0D));
|
|
|
|
private static final VoxelShape NORTH_SHAPE = VoxelShapes.or(COMBINED_SHAPE, Block.makeCuboidShape(6.0D, 4.0D, 0.0D, 10.0D, 8.0D, 4.0D));
|
|
|
|
private static final VoxelShape SOUTH_SHAPE = VoxelShapes.or(COMBINED_SHAPE, Block.makeCuboidShape(6.0D, 4.0D, 12.0D, 10.0D, 8.0D, 16.0D));
|
|
|
|
private static final VoxelShape WEST_SHAPE = VoxelShapes.or(COMBINED_SHAPE, Block.makeCuboidShape(0.0D, 4.0D, 6.0D, 4.0D, 8.0D, 10.0D));
|
|
|
|
private static final VoxelShape DOWN_RAYTRACE_SHAPE = IHopper.INSIDE_BOWL_SHAPE;
|
|
|
|
private static final VoxelShape EAST_RAYTRACE_SHAPE = VoxelShapes.or(IHopper.INSIDE_BOWL_SHAPE, Block.makeCuboidShape(12.0D, 8.0D, 6.0D, 16.0D, 10.0D, 10.0D));
|
|
|
|
private static final VoxelShape NORTH_RAYTRACE_SHAPE = VoxelShapes.or(IHopper.INSIDE_BOWL_SHAPE, Block.makeCuboidShape(6.0D, 8.0D, 0.0D, 10.0D, 10.0D, 4.0D));
|
|
|
|
private static final VoxelShape SOUTH_RAYTRACE_SHAPE = VoxelShapes.or(IHopper.INSIDE_BOWL_SHAPE, Block.makeCuboidShape(6.0D, 8.0D, 12.0D, 10.0D, 10.0D, 16.0D));
|
|
|
|
private static final VoxelShape WEST_RAYTRACE_SHAPE = VoxelShapes.or(IHopper.INSIDE_BOWL_SHAPE, Block.makeCuboidShape(0.0D, 8.0D, 6.0D, 4.0D, 10.0D, 10.0D));
|
2019-11-04 19:08:49 +01:00
|
|
|
|
2018-12-27 13:57:23 +01:00
|
|
|
public BlockGratedChute() {
|
2020-01-22 01:32:26 +01:00
|
|
|
super("grated_chute", TileEntityGratedChute::new, ModBlocks.prop(Material.IRON).hardnessAndResistance(3.0F, 8.0F).sound(SoundType.METAL));
|
2018-12-27 13:57:23 +01:00
|
|
|
}
|
|
|
|
|
2020-01-23 16:05:52 +01:00
|
|
|
@Override
|
|
|
|
public VoxelShape getShape(BlockState state, IBlockReader worldIn, BlockPos pos, ISelectionContext context) {
|
|
|
|
switch (state.get(FACING)) {
|
|
|
|
case DOWN:
|
|
|
|
return DOWN_SHAPE;
|
|
|
|
case NORTH:
|
|
|
|
return NORTH_SHAPE;
|
|
|
|
case SOUTH:
|
|
|
|
return SOUTH_SHAPE;
|
|
|
|
case WEST:
|
|
|
|
return WEST_SHAPE;
|
|
|
|
case EAST:
|
|
|
|
return EAST_SHAPE;
|
|
|
|
default:
|
|
|
|
return COMBINED_SHAPE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public VoxelShape getRaytraceShape(BlockState state, IBlockReader worldIn, BlockPos pos) {
|
|
|
|
switch (state.get(FACING)) {
|
|
|
|
case DOWN:
|
|
|
|
return DOWN_RAYTRACE_SHAPE;
|
|
|
|
case NORTH:
|
|
|
|
return NORTH_RAYTRACE_SHAPE;
|
|
|
|
case SOUTH:
|
|
|
|
return SOUTH_RAYTRACE_SHAPE;
|
|
|
|
case WEST:
|
|
|
|
return WEST_RAYTRACE_SHAPE;
|
|
|
|
case EAST:
|
|
|
|
return EAST_RAYTRACE_SHAPE;
|
|
|
|
default:
|
|
|
|
return IHopper.INSIDE_BOWL_SHAPE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-02-25 17:15:39 +01:00
|
|
|
@Override
|
2019-11-04 19:08:49 +01:00
|
|
|
public boolean onBlockActivated(BlockState state, World worldIn, BlockPos pos, PlayerEntity player, Hand handIn, BlockRayTraceResult hit) {
|
|
|
|
if (!player.isSneaking())
|
2019-02-25 17:15:39 +01:00
|
|
|
return false;
|
|
|
|
TileEntity tile = worldIn.getTileEntity(pos);
|
|
|
|
if (!(tile instanceof TileEntityGratedChute))
|
|
|
|
return false;
|
|
|
|
if (!worldIn.isRemote) {
|
|
|
|
TileEntityGratedChute chute = (TileEntityGratedChute) tile;
|
|
|
|
chute.isBlacklist = !chute.isBlacklist;
|
|
|
|
chute.sendToClients();
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2020-01-22 21:21:23 +01:00
|
|
|
@Nullable
|
2018-12-27 13:57:23 +01:00
|
|
|
@Override
|
2020-01-22 21:21:23 +01:00
|
|
|
public BlockState getStateForPlacement(BlockItemUseContext context) {
|
|
|
|
Direction newFacing = context.getFace().getOpposite();
|
2020-01-21 17:46:32 +01:00
|
|
|
if (newFacing == Direction.UP)
|
|
|
|
newFacing = Direction.DOWN;
|
|
|
|
return this.getDefaultState().with(FACING, newFacing);
|
2018-12-27 13:57:23 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2020-01-21 17:46:32 +01:00
|
|
|
public BlockRenderType getRenderType(BlockState state) {
|
|
|
|
return BlockRenderType.MODEL;
|
2018-12-27 13:57:23 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2019-10-20 22:30:49 +02:00
|
|
|
public boolean hasComparatorInputOverride(BlockState state) {
|
2018-12-27 13:57:23 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2019-10-20 22:30:49 +02:00
|
|
|
public int getComparatorInputOverride(BlockState blockState, World worldIn, BlockPos pos) {
|
2018-12-27 14:01:38 +01:00
|
|
|
TileEntity tile = worldIn.getTileEntity(pos);
|
|
|
|
if (tile instanceof TileEntityGratedChute) {
|
|
|
|
IItemHandler handler = ((TileEntityGratedChute) tile).getItemHandler(null);
|
|
|
|
ItemStack stack = handler.getStackInSlot(0);
|
|
|
|
if (stack.isEmpty())
|
|
|
|
return 0;
|
|
|
|
return MathHelper.ceil((stack.getCount() / (float) stack.getMaxStackSize()) * 15);
|
|
|
|
} else
|
|
|
|
return 0;
|
2018-12-27 13:57:23 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2019-10-20 22:30:49 +02:00
|
|
|
@OnlyIn(Dist.CLIENT)
|
2018-12-27 13:57:23 +01:00
|
|
|
public BlockRenderLayer getRenderLayer() {
|
|
|
|
return BlockRenderLayer.CUTOUT_MIPPED;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2020-01-21 21:04:44 +01:00
|
|
|
protected void fillStateContainer(StateContainer.Builder<Block, BlockState> builder) {
|
2020-01-21 17:46:32 +01:00
|
|
|
builder.add(FACING);
|
2018-12-27 13:57:23 +01:00
|
|
|
}
|
|
|
|
}
|