package micdoodle8.mods.galacticraft.core.blocks; import micdoodle8.mods.galacticraft.core.GalacticraftCore; import micdoodle8.mods.galacticraft.core.items.IShiftDescription; import micdoodle8.mods.galacticraft.core.tile.TileEntityFluidTank; import micdoodle8.mods.galacticraft.core.util.EnumSortCategoryBlock; import micdoodle8.mods.galacticraft.core.util.FluidUtil; import micdoodle8.mods.galacticraft.core.util.GCCoreUtil; import net.minecraft.block.Block; import net.minecraft.block.ITileEntityProvider; import net.minecraft.block.material.Material; import net.minecraft.block.properties.PropertyBool; import net.minecraft.block.state.BlockState; import net.minecraft.block.state.IBlockState; import net.minecraft.creativetab.CreativeTabs; import net.minecraft.entity.Entity; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.ItemStack; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.AxisAlignedBB; import net.minecraft.util.BlockPos; import net.minecraft.util.EnumFacing; import net.minecraft.util.EnumWorldBlockLayer; import net.minecraft.world.IBlockAccess; import net.minecraft.world.World; import net.minecraftforge.fml.relauncher.Side; import net.minecraftforge.fml.relauncher.SideOnly; import java.util.List; public class BlockFluidTank extends Block implements IShiftDescription, ISortableBlock, ITileEntityProvider { public static final PropertyBool UP = PropertyBool.create("up"); public static final PropertyBool DOWN = PropertyBool.create("down"); private static final AxisAlignedBB BOUNDS = new AxisAlignedBB(0.05F, 0.0F, 0.05F, 0.95F, 1.0F, 0.95F); public BlockFluidTank(String assetName) { super(Material.glass); this.setHardness(3.0F); this.setResistance(8.0F); this.setStepSound(soundTypeGlass); this.setUnlocalizedName(assetName); } @Override public void breakBlock(World worldIn, BlockPos pos, IBlockState state) { TileEntity tile = worldIn.getTileEntity(pos); if (tile instanceof TileEntityFluidTank) { TileEntityFluidTank tank = (TileEntityFluidTank) tile; tank.onBreak(); } super.breakBlock(worldIn, pos, state); } @Override public CreativeTabs getCreativeTabToDisplayOn() { return GalacticraftCore.galacticraftBlocksTab; } @SideOnly(Side.CLIENT) @Override public EnumWorldBlockLayer getBlockLayer() { return EnumWorldBlockLayer.CUTOUT; } @Override public boolean isFullCube() { return false; } @Override public boolean isOpaqueCube() { return false; } @Override public EnumSortCategoryBlock getCategory(int meta) { return EnumSortCategoryBlock.GENERAL; } @Override public String getShiftDescription(int meta) { return GCCoreUtil.translate(this.getUnlocalizedName() + ".description"); } @Override public boolean showDescription(int meta) { return true; } @Override protected BlockState createBlockState() { return new BlockState(this, UP, DOWN); } @Override public IBlockState getActualState(IBlockState state, IBlockAccess worldIn, BlockPos pos) { IBlockState stateAbove = worldIn.getBlockState(pos.up()); IBlockState stateBelow = worldIn.getBlockState(pos.down()); return state.withProperty(UP, stateAbove.getBlock() == this).withProperty(DOWN, stateBelow.getBlock() == this); } @Override public IBlockState getStateFromMeta(int meta) { return this.getDefaultState(); } @Override public int getMetaFromState(IBlockState state) { return 0; } @Override public TileEntity createNewTileEntity(World worldIn, int meta) { return new TileEntityFluidTank(); } @Override public void setBlockBoundsBasedOnState(IBlockAccess worldIn, BlockPos pos) { this.setBlockBounds((float) BOUNDS.minX, (float) BOUNDS.minY, (float) BOUNDS.minZ, (float) BOUNDS.maxX, (float) BOUNDS.maxY, (float) BOUNDS.maxZ); } @Override public void addCollisionBoxesToList(World worldIn, BlockPos pos, IBlockState state, AxisAlignedBB mask, List<AxisAlignedBB> list, Entity collidingEntity) { this.setBlockBoundsBasedOnState(worldIn, pos); super.addCollisionBoxesToList(worldIn, pos, state, mask, list, collidingEntity); } @Override public AxisAlignedBB getCollisionBoundingBox(World worldIn, BlockPos pos, IBlockState state) { this.setBlockBoundsBasedOnState(worldIn, pos); return super.getCollisionBoundingBox(worldIn, pos, state); } @Override public AxisAlignedBB getSelectedBoundingBox(World worldIn, BlockPos pos) { this.setBlockBoundsBasedOnState(worldIn, pos); return super.getSelectedBoundingBox(worldIn, pos); } @Override public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn, EnumFacing side, float hitX, float hitY, float hitZ) { if (super.onBlockActivated(worldIn, pos, state, playerIn, side, hitX, hitY, hitZ)) { return true; } ItemStack current = playerIn.inventory.getCurrentItem(); if (current != null) { TileEntity tile = worldIn.getTileEntity(pos); if (tile instanceof TileEntityFluidTank) { TileEntityFluidTank tank = (TileEntityFluidTank) tile; if (FluidUtil.interactWithTank(current, playerIn, tank, side)) { return true; } return false; } } return false; } @Override public int getLightValue(IBlockAccess world, BlockPos pos) { TileEntity tile = world.getTileEntity(pos); if (tile instanceof TileEntityFluidTank) { TileEntityFluidTank tank = (TileEntityFluidTank) tile; return tank.fluidTank.getFluid() == null || tank.fluidTank.getFluid().amount == 0 ? 0 : tank.fluidTank.getFluid().getFluid().getLuminosity(tank.fluidTank.getFluid()); } return 0; } }