mirror of
https://github.com/Ellpeck/NaturesAura.git
synced 2024-11-14 16:49:09 +01:00
145 lines
5.4 KiB
Java
145 lines
5.4 KiB
Java
package de.ellpeck.naturesaura.blocks;
|
|
|
|
import de.ellpeck.naturesaura.blocks.tiles.TileEntityGratedChute;
|
|
import net.minecraft.block.BlockHopper;
|
|
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;
|
|
import net.minecraft.block.state.IBlockState;
|
|
import net.minecraft.entity.Entity;
|
|
import net.minecraft.entity.EntityLivingBase;
|
|
import net.minecraft.item.ItemStack;
|
|
import net.minecraft.tileentity.TileEntity;
|
|
import net.minecraft.util.*;
|
|
import net.minecraft.util.math.AxisAlignedBB;
|
|
import net.minecraft.util.math.BlockPos;
|
|
import net.minecraft.util.math.MathHelper;
|
|
import net.minecraft.world.IBlockAccess;
|
|
import net.minecraft.world.World;
|
|
import net.minecraftforge.fml.relauncher.Side;
|
|
import net.minecraftforge.fml.relauncher.SideOnly;
|
|
import net.minecraftforge.items.IItemHandler;
|
|
|
|
import javax.annotation.Nullable;
|
|
import java.util.List;
|
|
|
|
public class BlockGratedChute extends BlockContainerImpl {
|
|
|
|
public static final PropertyDirection FACING = BlockHopper.FACING;
|
|
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);
|
|
|
|
public BlockGratedChute() {
|
|
super(Material.IRON, "grated_chute", TileEntityGratedChute.class, "grated_chute");
|
|
this.setHardness(3.0F);
|
|
this.setResistance(8.0F);
|
|
this.setSoundType(SoundType.METAL);
|
|
}
|
|
|
|
@Override
|
|
public AxisAlignedBB getBoundingBox(IBlockState state, IBlockAccess source, BlockPos pos) {
|
|
return FULL_BLOCK_AABB;
|
|
}
|
|
|
|
@Override
|
|
public void addCollisionBoxToList(IBlockState state, World worldIn, BlockPos pos, AxisAlignedBB entityBox, List<AxisAlignedBB> collidingBoxes, @Nullable Entity entityIn, boolean isActualState) {
|
|
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
|
|
public IBlockState getStateForPlacement(World worldIn, BlockPos pos, EnumFacing facing, float hitX, float hitY, float hitZ, int meta, EntityLivingBase placer) {
|
|
EnumFacing newFacing = facing.getOpposite();
|
|
if (newFacing == EnumFacing.UP)
|
|
newFacing = EnumFacing.DOWN;
|
|
return this.getDefaultState().withProperty(FACING, newFacing);
|
|
}
|
|
|
|
@Override
|
|
public boolean isTopSolid(IBlockState state) {
|
|
return true;
|
|
}
|
|
|
|
@Override
|
|
public EnumBlockRenderType getRenderType(IBlockState state) {
|
|
return EnumBlockRenderType.MODEL;
|
|
}
|
|
|
|
@Override
|
|
public boolean isFullCube(IBlockState state) {
|
|
return false;
|
|
}
|
|
|
|
@Override
|
|
public boolean isOpaqueCube(IBlockState state) {
|
|
return false;
|
|
}
|
|
|
|
@Override
|
|
@SideOnly(Side.CLIENT)
|
|
public boolean shouldSideBeRendered(IBlockState blockState, IBlockAccess blockAccess, BlockPos pos, EnumFacing side) {
|
|
return true;
|
|
}
|
|
|
|
@Override
|
|
public boolean hasComparatorInputOverride(IBlockState state) {
|
|
return true;
|
|
}
|
|
|
|
@Override
|
|
public int getComparatorInputOverride(IBlockState blockState, World worldIn, BlockPos pos) {
|
|
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;
|
|
}
|
|
|
|
@Override
|
|
@SideOnly(Side.CLIENT)
|
|
public BlockRenderLayer getRenderLayer() {
|
|
return BlockRenderLayer.CUTOUT_MIPPED;
|
|
}
|
|
|
|
@Override
|
|
public IBlockState getStateFromMeta(int meta) {
|
|
return this.getDefaultState().withProperty(FACING, EnumFacing.byIndex(meta));
|
|
}
|
|
|
|
@Override
|
|
public int getMetaFromState(IBlockState state) {
|
|
return state.getValue(FACING).getIndex();
|
|
}
|
|
|
|
@Override
|
|
public IBlockState withRotation(IBlockState state, Rotation rot) {
|
|
return state.withProperty(FACING, rot.rotate(state.getValue(FACING)));
|
|
}
|
|
|
|
@Override
|
|
public IBlockState withMirror(IBlockState state, Mirror mirrorIn) {
|
|
return state.withRotation(mirrorIn.toRotation(state.getValue(FACING)));
|
|
}
|
|
|
|
@Override
|
|
protected BlockStateContainer createBlockState() {
|
|
return new BlockStateContainer(this, FACING);
|
|
}
|
|
|
|
@Override
|
|
public BlockFaceShape getBlockFaceShape(IBlockAccess worldIn, IBlockState state, BlockPos pos, EnumFacing face) {
|
|
return face == EnumFacing.UP ? BlockFaceShape.BOWL : BlockFaceShape.UNDEFINED;
|
|
}
|
|
}
|