NaturesAura/src/main/java/de/ellpeck/naturesaura/blocks/BlockGratedChute.java

103 lines
4.3 KiB
Java
Raw Normal View History

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;
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;
import net.minecraft.state.StateContainer;
2018-12-27 14:01:38 +01:00
import net.minecraft.tileentity.TileEntity;
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.AxisAlignedBB;
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;
2019-11-04 19:08:49 +01:00
import net.minecraft.util.math.shapes.VoxelShape;
import net.minecraft.world.IWorld;
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
public class BlockGratedChute extends BlockContainerImpl {
// TODO voxel shape stuff
2019-11-04 19:08:49 +01:00
public static final DirectionProperty FACING = HopperBlock.FACING;
2018-12-27 13:57:23 +01:00
private static final AxisAlignedBB BASE_AABB = new AxisAlignedBB(0.0D, 0.0D, 0.0D, 1.0D, 0.625D, 1.0D);
private static final AxisAlignedBB SOUTH_AABB = new AxisAlignedBB(0.0D, 0.0D, 0.0D, 1.0D, 1.0D, 0.125D);
private static final AxisAlignedBB NORTH_AABB = new AxisAlignedBB(0.0D, 0.0D, 0.875D, 1.0D, 1.0D, 1.0D);
private static final AxisAlignedBB WEST_AABB = new AxisAlignedBB(0.875D, 0.0D, 0.0D, 1.0D, 1.0D, 1.0D);
private static final AxisAlignedBB EAST_AABB = new AxisAlignedBB(0.0D, 0.0D, 0.0D, 0.125D, 1.0D, 1.0D);
2019-11-04 19:08:49 +01:00
private static final VoxelShape BASE_TOP = makeCuboidShape(0, 9, 0, 16, 10, 16);
private static final VoxelShape BASE_SOUTH = makeCuboidShape(0, 9, 0, 16, 16, 1);
private static final VoxelShape BASE_NORTH = makeCuboidShape(0, 9, 15, 16, 16, 16);
private static final VoxelShape BASE_WEST = makeCuboidShape(15, 9, 0, 16, 26, 16);
private static final VoxelShape BASE_EAST = makeCuboidShape(0, 9, 0, 1, 16, 16);
private static final VoxelShape BASE_BOTTOM = makeCuboidShape(4, 4, 4, 12, 9, 12);
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
}
@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())
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;
}
2018-12-27 13:57:23 +01:00
@Override
public BlockState getStateForPlacement(BlockState state, Direction facing, BlockState state2, IWorld world, BlockPos pos1, BlockPos pos2, Hand hand) {
Direction newFacing = facing.getOpposite();
if (newFacing == Direction.UP)
newFacing = Direction.DOWN;
return this.getDefaultState().with(FACING, newFacing);
2018-12-27 13:57:23 +01:00
}
@Override
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) {
builder.add(FACING);
2018-12-27 13:57:23 +01:00
}
}