2018-12-27 13:57:23 +01:00
|
|
|
package de.ellpeck.naturesaura.blocks;
|
|
|
|
|
|
|
|
import de.ellpeck.naturesaura.blocks.tiles.TileEntityGratedChute;
|
2019-10-20 22:30:49 +02:00
|
|
|
import net.minecraft.block.HopperBlock;
|
2018-12-27 13:57:23 +01:00
|
|
|
import net.minecraft.block.SoundType;
|
|
|
|
import net.minecraft.block.material.Material;
|
|
|
|
import net.minecraft.block.properties.PropertyDirection;
|
|
|
|
import net.minecraft.block.state.BlockFaceShape;
|
|
|
|
import net.minecraft.block.state.BlockStateContainer;
|
2019-10-20 22:30:49 +02:00
|
|
|
import net.minecraft.block.BlockState;
|
2018-12-27 13:57:23 +01:00
|
|
|
import net.minecraft.entity.Entity;
|
2019-10-20 22:30:49 +02:00
|
|
|
import net.minecraft.entity.LivingEntity;
|
|
|
|
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;
|
2018-12-27 14:01:38 +01:00
|
|
|
import net.minecraft.tileentity.TileEntity;
|
2018-12-27 13:57:23 +01:00
|
|
|
import net.minecraft.util.*;
|
|
|
|
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.util.math.shapes.VoxelShapes;
|
2018-12-27 13:57:23 +01:00
|
|
|
import net.minecraft.world.IBlockAccess;
|
|
|
|
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
|
|
|
|
|
|
|
import javax.annotation.Nullable;
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
public class BlockGratedChute extends BlockContainerImpl {
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
private static VoxelShape BASE = VoxelShapes.combine()
|
|
|
|
|
|
|
|
private static final VoxelShape SHAPES[] {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2018-12-27 13:57:23 +01:00
|
|
|
public BlockGratedChute() {
|
2019-11-04 19:08:49 +01:00
|
|
|
super("grated_chute", TileEntityGratedChute.class, "grated_chute", ModBlocks.prop(Material.IRON).hardnessAndResistance(3.0F, 8.0F).sound(SoundType.METAL));
|
2018-12-27 13:57:23 +01:00
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2018-12-27 13:57:23 +01:00
|
|
|
@Override
|
2019-10-20 22:30:49 +02:00
|
|
|
public AxisAlignedBB getBoundingBox(BlockState state, IBlockAccess source, BlockPos pos) {
|
2018-12-27 13:57:23 +01:00
|
|
|
return FULL_BLOCK_AABB;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2019-10-20 22:30:49 +02:00
|
|
|
public void addCollisionBoxToList(BlockState state, World worldIn, BlockPos pos, AxisAlignedBB entityBox, List<AxisAlignedBB> collidingBoxes, @Nullable Entity entityIn, boolean isActualState) {
|
2018-12-27 13:57:23 +01:00
|
|
|
addCollisionBoxToList(pos, entityBox, collidingBoxes, BASE_AABB);
|
|
|
|
addCollisionBoxToList(pos, entityBox, collidingBoxes, EAST_AABB);
|
|
|
|
addCollisionBoxToList(pos, entityBox, collidingBoxes, WEST_AABB);
|
|
|
|
addCollisionBoxToList(pos, entityBox, collidingBoxes, SOUTH_AABB);
|
|
|
|
addCollisionBoxToList(pos, entityBox, collidingBoxes, NORTH_AABB);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2019-10-20 22:30:49 +02:00
|
|
|
public BlockState getStateForPlacement(World worldIn, BlockPos pos, EnumFacing facing, float hitX, float hitY, float hitZ, int meta, LivingEntity placer) {
|
2018-12-27 13:57:23 +01:00
|
|
|
EnumFacing newFacing = facing.getOpposite();
|
|
|
|
if (newFacing == EnumFacing.UP)
|
|
|
|
newFacing = EnumFacing.DOWN;
|
|
|
|
return this.getDefaultState().withProperty(FACING, newFacing);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2019-10-20 22:30:49 +02:00
|
|
|
public boolean isTopSolid(BlockState state) {
|
2018-12-27 13:57:23 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2019-10-20 22:30:49 +02:00
|
|
|
public EnumBlockRenderType getRenderType(BlockState state) {
|
2018-12-27 13:57:23 +01:00
|
|
|
return EnumBlockRenderType.MODEL;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2019-10-20 22:30:49 +02:00
|
|
|
public boolean isFullCube(BlockState state) {
|
2018-12-27 13:57:23 +01:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2019-10-20 22:30:49 +02:00
|
|
|
public boolean isOpaqueCube(BlockState state) {
|
2018-12-27 13:57:23 +01:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2019-10-20 22:30:49 +02:00
|
|
|
@OnlyIn(Dist.CLIENT)
|
|
|
|
public boolean shouldSideBeRendered(BlockState blockState, IBlockAccess blockAccess, BlockPos pos, EnumFacing side) {
|
2018-12-27 13:57:23 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
@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
|
2019-10-20 22:30:49 +02:00
|
|
|
public BlockState getStateFromMeta(int meta) {
|
2018-12-27 13:57:23 +01:00
|
|
|
return this.getDefaultState().withProperty(FACING, EnumFacing.byIndex(meta));
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2019-10-20 22:30:49 +02:00
|
|
|
public int getMetaFromState(BlockState state) {
|
2018-12-27 13:57:23 +01:00
|
|
|
return state.getValue(FACING).getIndex();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2019-10-20 22:30:49 +02:00
|
|
|
public BlockState withRotation(BlockState state, Rotation rot) {
|
2018-12-27 13:57:23 +01:00
|
|
|
return state.withProperty(FACING, rot.rotate(state.getValue(FACING)));
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2019-10-20 22:30:49 +02:00
|
|
|
public BlockState withMirror(BlockState state, Mirror mirrorIn) {
|
2018-12-27 13:57:23 +01:00
|
|
|
return state.withRotation(mirrorIn.toRotation(state.getValue(FACING)));
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected BlockStateContainer createBlockState() {
|
|
|
|
return new BlockStateContainer(this, FACING);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2019-10-20 22:30:49 +02:00
|
|
|
public BlockFaceShape getBlockFaceShape(IBlockAccess worldIn, BlockState state, BlockPos pos, EnumFacing face) {
|
2018-12-27 13:57:23 +01:00
|
|
|
return face == EnumFacing.UP ? BlockFaceShape.BOWL : BlockFaceShape.UNDEFINED;
|
|
|
|
}
|
|
|
|
}
|