2016-02-18 17:25:11 +01:00
|
|
|
package WayofTime.bloodmagic.block;
|
|
|
|
|
2016-12-11 20:28:47 -05:00
|
|
|
import WayofTime.bloodmagic.BloodMagic;
|
|
|
|
import WayofTime.bloodmagic.api.Constants;
|
|
|
|
import WayofTime.bloodmagic.client.IVariantProvider;
|
|
|
|
import WayofTime.bloodmagic.tile.TileBloodTank;
|
2016-02-18 17:25:11 +01:00
|
|
|
import net.minecraft.block.BlockContainer;
|
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;
|
2016-12-11 20:28:47 -05:00
|
|
|
import net.minecraft.block.properties.IProperty;
|
|
|
|
import net.minecraft.block.properties.PropertyInteger;
|
|
|
|
import net.minecraft.block.state.BlockStateContainer;
|
2016-02-18 17:25:11 +01:00
|
|
|
import net.minecraft.block.state.IBlockState;
|
|
|
|
import net.minecraft.entity.EntityLivingBase;
|
|
|
|
import net.minecraft.entity.player.EntityPlayer;
|
|
|
|
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;
|
|
|
|
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.ImmutablePair;
|
|
|
|
import org.apache.commons.lang3.tuple.Pair;
|
2016-02-18 17:25:11 +01:00
|
|
|
|
2016-12-11 20:28:47 -05:00
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
public class BlockBloodTank extends BlockContainer implements IVariantProvider
|
2016-02-18 17:25:11 +01:00
|
|
|
{
|
2016-12-11 20:28:47 -05:00
|
|
|
public static final PropertyInteger TIER = PropertyInteger.create("tier", 0, TileBloodTank.capacities.length - 1);
|
|
|
|
|
2016-02-18 17:25:11 +01:00
|
|
|
public BlockBloodTank()
|
|
|
|
{
|
2016-04-24 10:06:28 -07:00
|
|
|
super(Material.IRON);
|
2016-02-18 17:25:11 +01:00
|
|
|
|
|
|
|
setUnlocalizedName(Constants.Mod.MODID + ".bloodTank");
|
|
|
|
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);
|
|
|
|
setCreativeTab(BloodMagic.tabBloodMagic);
|
2016-12-11 20:28:47 -05:00
|
|
|
setLightOpacity(0);
|
|
|
|
|
|
|
|
setDefaultState(blockState.getBaseState().withProperty(TIER, 0));
|
|
|
|
}
|
|
|
|
|
|
|
|
// This is important!!! - DON'T DELETE - idk why
|
|
|
|
@Override
|
|
|
|
public TileEntity createTileEntity(World worldIn, IBlockState blockState)
|
|
|
|
{
|
|
|
|
return new TileBloodTank(getMetaFromState(blockState));
|
2016-02-18 17:25:11 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public TileEntity createNewTileEntity(World worldIn, int meta)
|
|
|
|
{
|
2016-12-11 20:28:47 -05:00
|
|
|
return new TileBloodTank(meta);
|
2016-02-18 17:25:11 +01:00
|
|
|
}
|
|
|
|
|
2016-02-23 22:47:28 -08:00
|
|
|
@Override
|
2016-03-18 13:16:38 -04:00
|
|
|
public EnumBlockRenderType getRenderType(IBlockState state)
|
2016-03-16 18:41:06 -04:00
|
|
|
{
|
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)
|
|
|
|
public BlockRenderLayer getBlockLayer()
|
|
|
|
{
|
|
|
|
return BlockRenderLayer.TRANSLUCENT;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean isFullCube(IBlockState state)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean isOpaqueCube(IBlockState state)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public IBlockState getStateFromMeta(int meta)
|
|
|
|
{
|
|
|
|
return this.getDefaultState().withProperty(TIER, meta);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int getMetaFromState(IBlockState state)
|
|
|
|
{
|
|
|
|
return state.getValue(TIER);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public IBlockState getActualState(IBlockState state, IBlockAccess world, BlockPos pos)
|
|
|
|
{
|
|
|
|
if (world.getTileEntity(pos) == null)
|
|
|
|
return state;
|
|
|
|
return state.withProperty(TIER, world.getTileEntity(pos).getBlockMetadata());
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected BlockStateContainer createBlockState()
|
|
|
|
{
|
|
|
|
return new BlockStateContainer(this, new IProperty[] { TIER });
|
|
|
|
}
|
|
|
|
|
2016-02-18 17:25:11 +01:00
|
|
|
@Override
|
2016-03-18 13:16:38 -04:00
|
|
|
public boolean onBlockActivated(World world, BlockPos blockPos, IBlockState state, EntityPlayer player, EnumHand hand, ItemStack heldItem, EnumFacing side, float hitX, float hitY, float hitZ)
|
2016-02-18 17:25:11 +01:00
|
|
|
{
|
|
|
|
TileBloodTank fluidHandler = (TileBloodTank) world.getTileEntity(blockPos);
|
2016-12-11 20:28:47 -05:00
|
|
|
if (FluidUtil.interactWithFluidHandler(heldItem, fluidHandler.getTank(), player))
|
2016-02-18 17:25:11 +01:00
|
|
|
{
|
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 20:28:47 -05:00
|
|
|
return false;
|
2016-02-18 17:25:11 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
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
|
|
|
|
public List<ItemStack> getDrops(IBlockAccess world, BlockPos blockPos, IBlockState blockState, int fortune)
|
|
|
|
{
|
|
|
|
ArrayList<ItemStack> list = new ArrayList<ItemStack>();
|
|
|
|
|
|
|
|
if (world.getTileEntity(blockPos) instanceof TileBloodTank)
|
|
|
|
{
|
|
|
|
TileBloodTank bloodTank = (TileBloodTank) world.getTileEntity(blockPos);
|
|
|
|
ItemStack drop = new ItemStack(this);
|
|
|
|
NBTTagCompound tag = new NBTTagCompound();
|
2016-12-11 20:28:47 -05:00
|
|
|
bloodTank.serialize(tag);
|
2016-02-18 17:25:11 +01:00
|
|
|
drop.setTagCompound(tag);
|
2016-12-11 20:28:47 -05:00
|
|
|
drop.setItemDamage(getMetaFromState(blockState));
|
2016-02-18 17:25:11 +01:00
|
|
|
list.add(drop);
|
|
|
|
}
|
|
|
|
|
|
|
|
return list;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onBlockPlacedBy(World world, BlockPos blockPos, IBlockState blockState, EntityLivingBase placer, ItemStack stack)
|
|
|
|
{
|
|
|
|
if (world.getTileEntity(blockPos) != null && world.getTileEntity(blockPos) instanceof TileBloodTank)
|
|
|
|
{
|
|
|
|
NBTTagCompound tag = stack.getTagCompound();
|
|
|
|
if (tag != null)
|
|
|
|
{
|
2016-12-11 20:28:47 -05:00
|
|
|
((TileBloodTank) world.getTileEntity(blockPos)).deserialize(tag);
|
|
|
|
blockState.withProperty(TIER, stack.getMetadata());
|
2016-02-18 17:25:11 +01:00
|
|
|
}
|
|
|
|
}
|
2016-12-11 20:28:47 -05:00
|
|
|
|
|
|
|
world.checkLight(blockPos);
|
|
|
|
world.updateComparatorOutputLevel(blockPos, this);
|
|
|
|
world.markAndNotifyBlock(blockPos, world.getChunkFromBlockCoords(blockPos), blockState, blockState, 3);
|
2016-02-18 17:25:11 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2016-03-18 13:16:38 -04:00
|
|
|
public int getLightValue(IBlockState state, IBlockAccess world, BlockPos pos)
|
2016-02-18 17:25:11 +01:00
|
|
|
{
|
|
|
|
TileEntity tile = world.getTileEntity(pos);
|
|
|
|
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
|
2016-03-18 13:16:38 -04:00
|
|
|
public ItemStack getPickBlock(IBlockState state, RayTraceResult target, World world, BlockPos pos, EntityPlayer player)
|
2016-02-18 17:25:11 +01:00
|
|
|
{
|
|
|
|
return getDrops(world, pos, world.getBlockState(pos), 0).get(0);
|
|
|
|
}
|
2016-12-11 20:28:47 -05:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean hasComparatorInputOverride(IBlockState state)
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int getComparatorInputOverride(IBlockState state, World w, BlockPos pos)
|
|
|
|
{
|
|
|
|
TileEntity tile = w.getTileEntity(pos);
|
|
|
|
if (tile instanceof TileBloodTank)
|
|
|
|
return ((TileBloodTank) tile).getComparatorOutput();
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public List<Pair<Integer, String>> getVariants()
|
|
|
|
{
|
|
|
|
List<Pair<Integer, String>> ret = new ArrayList<Pair<Integer, String>>();
|
|
|
|
for (int i = 0; i < TileBloodTank.capacities.length; i++)
|
|
|
|
ret.add(new ImmutablePair<Integer, String>(i, "inventory"));
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
2016-02-18 17:25:11 +01:00
|
|
|
}
|