2018-12-27 13:57:23 +01:00
|
|
|
package de.ellpeck.naturesaura.blocks;
|
|
|
|
|
|
|
|
import de.ellpeck.naturesaura.blocks.tiles.TileEntityGratedChute;
|
2020-01-29 00:40:28 +01:00
|
|
|
import de.ellpeck.naturesaura.data.BlockStateGenerator;
|
|
|
|
import de.ellpeck.naturesaura.data.ItemModelGenerator;
|
|
|
|
import de.ellpeck.naturesaura.reg.ICustomBlockState;
|
|
|
|
import de.ellpeck.naturesaura.reg.ICustomItemModel;
|
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-28 18:08:56 +01:00
|
|
|
import net.minecraft.util.ActionResultType;
|
2020-01-21 17:46:32 +01:00
|
|
|
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;
|
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;
|
|
|
|
|
2020-01-29 00:40:28 +01:00
|
|
|
public class BlockGratedChute extends BlockContainerImpl implements ICustomBlockState, ICustomItemModel {
|
2018-12-27 13:57:23 +01:00
|
|
|
|
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-10-17 21:13:45 +02:00
|
|
|
super("grated_chute", TileEntityGratedChute::new, Properties.create(Material.IRON).hardnessAndResistance(3.0F, 8.0F).sound(SoundType.METAL));
|
2018-12-27 13:57:23 +01:00
|
|
|
}
|
|
|
|
|
2020-02-05 14:30:17 +01:00
|
|
|
@Override
|
|
|
|
protected boolean hasWaterlogging() {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
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
|
2020-01-28 18:08:56 +01:00
|
|
|
public ActionResultType onBlockActivated(BlockState state, World worldIn, BlockPos pos, PlayerEntity player, Hand handIn, BlockRayTraceResult hit) {
|
2020-09-22 03:17:02 +02:00
|
|
|
if (!player.isSneaking())
|
2020-01-28 18:08:56 +01:00
|
|
|
return ActionResultType.FAIL;
|
2019-02-25 17:15:39 +01:00
|
|
|
TileEntity tile = worldIn.getTileEntity(pos);
|
|
|
|
if (!(tile instanceof TileEntityGratedChute))
|
2020-01-28 18:08:56 +01:00
|
|
|
return ActionResultType.FAIL;
|
2019-02-25 17:15:39 +01:00
|
|
|
if (!worldIn.isRemote) {
|
|
|
|
TileEntityGratedChute chute = (TileEntityGratedChute) tile;
|
|
|
|
chute.isBlacklist = !chute.isBlacklist;
|
|
|
|
chute.sendToClients();
|
|
|
|
}
|
2020-01-28 18:08:56 +01:00
|
|
|
return ActionResultType.SUCCESS;
|
2019-02-25 17:15:39 +01:00
|
|
|
}
|
|
|
|
|
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;
|
2020-02-05 14:30:17 +01:00
|
|
|
return super.getStateForPlacement(context).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) {
|
2020-10-19 21:26:32 +02:00
|
|
|
IItemHandler handler = ((TileEntityGratedChute) tile).getItemHandler();
|
2018-12-27 14:01:38 +01:00
|
|
|
ItemStack stack = handler.getStackInSlot(0);
|
|
|
|
if (stack.isEmpty())
|
|
|
|
return 0;
|
2020-01-28 18:08:56 +01:00
|
|
|
return MathHelper.ceil(stack.getCount() / (float) stack.getMaxStackSize() * 15);
|
2018-12-27 14:01:38 +01:00
|
|
|
} else
|
|
|
|
return 0;
|
2018-12-27 13:57:23 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2020-01-21 21:04:44 +01:00
|
|
|
protected void fillStateContainer(StateContainer.Builder<Block, BlockState> builder) {
|
2020-02-05 14:30:17 +01:00
|
|
|
super.fillStateContainer(builder);
|
2020-01-21 17:46:32 +01:00
|
|
|
builder.add(FACING);
|
2018-12-27 13:57:23 +01:00
|
|
|
}
|
2020-01-29 00:40:28 +01:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public void generateCustomBlockState(BlockStateGenerator generator) {
|
|
|
|
// noop
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void generateCustomItemModel(ItemModelGenerator generator) {
|
|
|
|
generator.withExistingParent(this.getBaseName(), generator.modLoc("block/" + this.getBaseName() + "_down"));
|
|
|
|
}
|
2018-12-27 13:57:23 +01:00
|
|
|
}
|