2016-02-18 17:25:11 +01:00
|
|
|
package WayofTime.bloodmagic.block;
|
|
|
|
|
2016-12-11 20:28:47 -05:00
|
|
|
import WayofTime.bloodmagic.BloodMagic;
|
2016-12-11 23:54:03 -08:00
|
|
|
import WayofTime.bloodmagic.block.base.BlockInteger;
|
2016-12-11 20:28:47 -05:00
|
|
|
import WayofTime.bloodmagic.client.IVariantProvider;
|
2017-08-14 20:53:42 -07:00
|
|
|
import WayofTime.bloodmagic.item.block.ItemBlockBloodTank;
|
2016-12-11 20:28:47 -05:00
|
|
|
import WayofTime.bloodmagic.tile.TileBloodTank;
|
2017-02-20 13:47:36 -08:00
|
|
|
import com.google.common.collect.Lists;
|
2016-03-18 13:16:38 -04:00
|
|
|
import net.minecraft.block.SoundType;
|
2016-02-18 17:25:11 +01:00
|
|
|
import net.minecraft.block.material.Material;
|
|
|
|
import net.minecraft.block.state.IBlockState;
|
|
|
|
import net.minecraft.entity.EntityLivingBase;
|
|
|
|
import net.minecraft.entity.player.EntityPlayer;
|
2017-08-14 20:53:42 -07:00
|
|
|
import net.minecraft.item.ItemBlock;
|
2016-02-18 17:25:11 +01:00
|
|
|
import net.minecraft.item.ItemStack;
|
|
|
|
import net.minecraft.nbt.NBTTagCompound;
|
|
|
|
import net.minecraft.tileentity.TileEntity;
|
2016-12-11 20:28:47 -05:00
|
|
|
import net.minecraft.util.BlockRenderLayer;
|
2016-03-18 13:16:38 -04:00
|
|
|
import net.minecraft.util.EnumBlockRenderType;
|
2016-02-18 17:25:11 +01:00
|
|
|
import net.minecraft.util.EnumFacing;
|
2016-03-18 13:16:38 -04:00
|
|
|
import net.minecraft.util.EnumHand;
|
2016-12-11 23:54:03 -08:00
|
|
|
import net.minecraft.util.math.AxisAlignedBB;
|
2016-03-18 13:16:38 -04:00
|
|
|
import net.minecraft.util.math.BlockPos;
|
|
|
|
import net.minecraft.util.math.RayTraceResult;
|
2016-02-18 17:25:11 +01:00
|
|
|
import net.minecraft.world.IBlockAccess;
|
|
|
|
import net.minecraft.world.World;
|
|
|
|
import net.minecraftforge.fluids.FluidStack;
|
2016-12-11 20:28:47 -05:00
|
|
|
import net.minecraftforge.fluids.FluidUtil;
|
|
|
|
import net.minecraftforge.fml.relauncher.Side;
|
|
|
|
import net.minecraftforge.fml.relauncher.SideOnly;
|
|
|
|
import org.apache.commons.lang3.tuple.Pair;
|
2016-02-18 17:25:11 +01:00
|
|
|
|
2016-12-11 23:54:03 -08:00
|
|
|
import javax.annotation.Nullable;
|
2016-12-11 20:28:47 -05:00
|
|
|
import java.util.List;
|
|
|
|
|
2017-08-15 21:30:48 -07:00
|
|
|
public class BlockBloodTank extends BlockInteger implements IVariantProvider, IBMBlock {
|
2016-12-11 23:54:03 -08:00
|
|
|
public static final AxisAlignedBB BOX = new AxisAlignedBB(0.25, 0, 0.25, 0.75, 0.8, 0.75);
|
2016-12-11 20:28:47 -05:00
|
|
|
|
2017-08-15 21:30:48 -07:00
|
|
|
public BlockBloodTank() {
|
2016-12-11 23:54:03 -08:00
|
|
|
super(Material.IRON, TileBloodTank.CAPACITIES.length - 1, "tier");
|
2016-02-18 17:25:11 +01:00
|
|
|
|
2017-08-14 20:53:42 -07:00
|
|
|
setUnlocalizedName(BloodMagic.MODID + ".bloodTank");
|
2016-02-18 17:25:11 +01:00
|
|
|
setHardness(2.0F);
|
|
|
|
setResistance(5.0F);
|
2016-03-21 12:55:36 -07:00
|
|
|
setSoundType(SoundType.GLASS);
|
2016-02-18 17:25:11 +01:00
|
|
|
setHarvestLevel("pickaxe", 1);
|
2017-08-14 20:53:42 -07:00
|
|
|
setCreativeTab(BloodMagic.TAB_BM);
|
2016-12-11 20:28:47 -05:00
|
|
|
setLightOpacity(0);
|
|
|
|
}
|
|
|
|
|
2016-12-11 23:54:03 -08:00
|
|
|
@Nullable
|
2016-12-11 20:28:47 -05:00
|
|
|
@Override
|
2017-08-15 21:30:48 -07:00
|
|
|
public AxisAlignedBB getCollisionBoundingBox(IBlockState blockState, IBlockAccess worldIn, BlockPos pos) {
|
2016-12-11 23:54:03 -08:00
|
|
|
return BOX;
|
2016-02-18 17:25:11 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2017-08-15 21:30:48 -07:00
|
|
|
public AxisAlignedBB getSelectedBoundingBox(IBlockState state, World worldIn, BlockPos pos) {
|
2016-12-11 23:54:03 -08:00
|
|
|
return BOX;
|
2016-02-18 17:25:11 +01:00
|
|
|
}
|
|
|
|
|
2016-02-23 22:47:28 -08:00
|
|
|
@Override
|
2017-08-15 21:30:48 -07:00
|
|
|
public EnumBlockRenderType getRenderType(IBlockState state) {
|
2016-03-18 13:16:38 -04:00
|
|
|
return EnumBlockRenderType.MODEL;
|
2016-02-23 22:47:28 -08:00
|
|
|
}
|
|
|
|
|
2016-12-11 20:28:47 -05:00
|
|
|
@Override
|
|
|
|
@SideOnly(Side.CLIENT)
|
2017-08-15 21:30:48 -07:00
|
|
|
public BlockRenderLayer getBlockLayer() {
|
2016-12-11 23:54:03 -08:00
|
|
|
return BlockRenderLayer.CUTOUT_MIPPED;
|
2016-12-11 20:28:47 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2017-08-15 21:30:48 -07:00
|
|
|
public boolean isFullCube(IBlockState state) {
|
2016-12-11 20:28:47 -05:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2017-08-15 21:30:48 -07:00
|
|
|
public boolean isOpaqueCube(IBlockState state) {
|
2016-12-11 20:28:47 -05:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-02-20 13:47:36 -08:00
|
|
|
@Override
|
|
|
|
public void harvestBlock(World world, EntityPlayer player, BlockPos pos, IBlockState state, @Nullable TileEntity tile, ItemStack stack) {
|
|
|
|
super.harvestBlock(world, player, pos, state, tile, stack);
|
|
|
|
world.setBlockToAir(pos);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean removedByPlayer(IBlockState state, World world, BlockPos pos, EntityPlayer player, boolean willHarvest) {
|
|
|
|
return willHarvest || super.removedByPlayer(state, world, pos, player, willHarvest);
|
|
|
|
}
|
|
|
|
|
2016-02-18 17:25:11 +01:00
|
|
|
@Override
|
2017-08-15 21:30:48 -07:00
|
|
|
public boolean onBlockActivated(World world, BlockPos blockPos, IBlockState state, EntityPlayer player, EnumHand hand, EnumFacing side, float hitX, float hitY, float hitZ) {
|
2017-08-14 20:53:42 -07:00
|
|
|
boolean success = FluidUtil.interactWithFluidHandler(player, hand, world, blockPos, side);
|
2017-08-15 21:30:48 -07:00
|
|
|
if (success) {
|
2016-12-11 20:28:47 -05:00
|
|
|
world.checkLight(blockPos);
|
|
|
|
world.updateComparatorOutputLevel(blockPos, this);
|
|
|
|
world.markAndNotifyBlock(blockPos, world.getChunkFromBlockCoords(blockPos), state, state, 3);
|
2016-02-18 17:25:11 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-12-11 23:54:03 -08:00
|
|
|
return true;
|
2016-02-18 17:25:11 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2017-08-15 21:30:48 -07:00
|
|
|
public void onBlockHarvested(World worldIn, BlockPos pos, IBlockState state, EntityPlayer player) {
|
2016-12-11 20:28:47 -05:00
|
|
|
if (!player.capabilities.isCreativeMode)
|
|
|
|
this.dropBlockAsItem(worldIn, pos, state, 0);
|
2016-02-18 17:25:11 +01:00
|
|
|
super.onBlockHarvested(worldIn, pos, state, player);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2017-08-15 21:30:48 -07:00
|
|
|
public List<ItemStack> getDrops(IBlockAccess world, BlockPos pos, IBlockState blockState, int fortune) {
|
2017-02-20 13:47:36 -08:00
|
|
|
List<ItemStack> list = Lists.newArrayList();
|
2016-02-18 17:25:11 +01:00
|
|
|
|
2016-12-11 23:54:03 -08:00
|
|
|
TileEntity tile = world.getTileEntity(pos);
|
2017-08-15 21:30:48 -07:00
|
|
|
if (tile instanceof TileBloodTank) {
|
2016-12-11 23:54:03 -08:00
|
|
|
TileBloodTank bloodTank = (TileBloodTank) tile;
|
2017-02-20 13:47:36 -08:00
|
|
|
ItemStack drop = new ItemStack(this, 1, bloodTank.getBlockMetadata());
|
2016-02-18 17:25:11 +01:00
|
|
|
NBTTagCompound tag = new NBTTagCompound();
|
2017-02-20 13:47:36 -08:00
|
|
|
|
|
|
|
if (bloodTank.getTank().getFluid() != null)
|
|
|
|
bloodTank.getTank().getFluid().writeToNBT(tag);
|
|
|
|
|
2016-02-18 17:25:11 +01:00
|
|
|
drop.setTagCompound(tag);
|
|
|
|
list.add(drop);
|
|
|
|
}
|
|
|
|
|
|
|
|
return list;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2017-08-15 21:30:48 -07:00
|
|
|
public void onBlockPlacedBy(World world, BlockPos pos, IBlockState blockState, EntityLivingBase placer, ItemStack stack) {
|
2016-12-11 23:54:03 -08:00
|
|
|
TileEntity tile = world.getTileEntity(pos);
|
2017-08-15 21:30:48 -07:00
|
|
|
if (tile instanceof TileBloodTank) {
|
2017-02-20 13:47:36 -08:00
|
|
|
TileBloodTank bloodTank = (TileBloodTank) tile;
|
2016-02-18 17:25:11 +01:00
|
|
|
NBTTagCompound tag = stack.getTagCompound();
|
2017-08-15 21:30:48 -07:00
|
|
|
if (tag != null) {
|
2017-02-20 13:47:36 -08:00
|
|
|
FluidStack fluidStack = FluidStack.loadFluidStackFromNBT(tag);
|
|
|
|
bloodTank.getTank().setFluid(fluidStack);
|
2016-02-18 17:25:11 +01:00
|
|
|
}
|
|
|
|
}
|
2016-12-11 20:28:47 -05:00
|
|
|
|
2016-12-11 23:54:03 -08:00
|
|
|
world.checkLight(pos);
|
|
|
|
world.updateComparatorOutputLevel(pos, this);
|
|
|
|
world.markAndNotifyBlock(pos, world.getChunkFromBlockCoords(pos), blockState, blockState, 3);
|
2016-02-18 17:25:11 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2017-08-15 21:30:48 -07:00
|
|
|
public int getLightValue(IBlockState state, IBlockAccess world, BlockPos pos) {
|
2016-02-18 17:25:11 +01:00
|
|
|
TileEntity tile = world.getTileEntity(pos);
|
2017-08-15 21:30:48 -07:00
|
|
|
if (tile instanceof TileBloodTank) {
|
2016-12-11 20:28:47 -05:00
|
|
|
FluidStack fluidStack = ((TileBloodTank) tile).getTank().getFluid();
|
|
|
|
return fluidStack == null || fluidStack.amount <= 0 ? 0 : fluidStack.getFluid().getLuminosity(fluidStack);
|
2016-02-18 17:25:11 +01:00
|
|
|
}
|
2016-12-11 20:28:47 -05:00
|
|
|
|
|
|
|
return super.getLightValue(state, world, pos);
|
2016-02-18 17:25:11 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2017-08-15 21:30:48 -07:00
|
|
|
public ItemStack getPickBlock(IBlockState state, RayTraceResult target, World world, BlockPos pos, EntityPlayer player) {
|
2016-12-11 23:54:03 -08:00
|
|
|
return new ItemStack(this, 1, getMetaFromState(state));
|
2016-02-18 17:25:11 +01:00
|
|
|
}
|
2016-12-11 20:28:47 -05:00
|
|
|
|
|
|
|
@Override
|
2017-08-15 21:30:48 -07:00
|
|
|
public boolean hasComparatorInputOverride(IBlockState state) {
|
2016-12-11 20:28:47 -05:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2017-08-15 21:30:48 -07:00
|
|
|
public int getComparatorInputOverride(IBlockState state, World world, BlockPos pos) {
|
2016-12-11 23:54:03 -08:00
|
|
|
TileEntity tile = world.getTileEntity(pos);
|
2016-12-11 20:28:47 -05:00
|
|
|
if (tile instanceof TileBloodTank)
|
|
|
|
return ((TileBloodTank) tile).getComparatorOutput();
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2016-12-11 23:54:03 -08:00
|
|
|
@Override
|
2017-08-15 21:30:48 -07:00
|
|
|
public TileEntity createTileEntity(World worldIn, IBlockState blockState) {
|
2016-12-11 23:54:03 -08:00
|
|
|
return new TileBloodTank(getMetaFromState(blockState));
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2017-08-15 21:30:48 -07:00
|
|
|
public boolean hasTileEntity(IBlockState state) {
|
2016-12-11 23:54:03 -08:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2017-08-14 20:53:42 -07:00
|
|
|
@Override
|
|
|
|
public ItemBlock getItem() {
|
|
|
|
return new ItemBlockBloodTank(this);
|
|
|
|
}
|
|
|
|
|
2016-12-11 23:54:03 -08:00
|
|
|
// IVariantProvider
|
|
|
|
|
2016-12-11 20:28:47 -05:00
|
|
|
@Override
|
2017-08-15 21:30:48 -07:00
|
|
|
public List<Pair<Integer, String>> getVariants() {
|
2017-08-14 20:53:42 -07:00
|
|
|
List<Pair<Integer, String>> ret = Lists.newArrayList();
|
2016-12-11 23:54:03 -08:00
|
|
|
for (int i = 0; i < TileBloodTank.CAPACITIES.length; i++)
|
2017-08-14 20:53:42 -07:00
|
|
|
ret.add(Pair.of(i, "inventory"));
|
2016-12-11 20:28:47 -05:00
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
2016-02-18 17:25:11 +01:00
|
|
|
}
|