2013-07-26 21:18:53 -07:00
|
|
|
package tconstruct.blocks;
|
|
|
|
|
|
|
|
|
|
import java.util.List;
|
|
|
|
|
|
2014-02-05 10:28:54 -05:00
|
|
|
import mantle.blocks.iface.IServantLogic;
|
2013-07-26 21:18:53 -07:00
|
|
|
import net.minecraft.block.Block;
|
|
|
|
|
import net.minecraft.block.BlockContainer;
|
|
|
|
|
import net.minecraft.block.material.Material;
|
2013-12-31 20:24:06 -05:00
|
|
|
import net.minecraft.client.renderer.texture.IIconRegister;
|
2013-07-26 21:18:53 -07:00
|
|
|
import net.minecraft.creativetab.CreativeTabs;
|
2013-08-07 19:06:26 -07:00
|
|
|
import net.minecraft.entity.EntityLivingBase;
|
|
|
|
|
import net.minecraft.entity.item.EntityItem;
|
2013-07-26 21:18:53 -07:00
|
|
|
import net.minecraft.entity.player.EntityPlayer;
|
2014-02-01 14:18:17 -05:00
|
|
|
import net.minecraft.item.Item;
|
2013-07-26 21:18:53 -07:00
|
|
|
import net.minecraft.item.ItemStack;
|
2013-08-07 19:06:26 -07:00
|
|
|
import net.minecraft.nbt.NBTTagCompound;
|
2013-07-26 21:18:53 -07:00
|
|
|
import net.minecraft.tileentity.TileEntity;
|
2013-12-31 20:24:06 -05:00
|
|
|
import net.minecraft.util.IIcon;
|
2013-07-26 21:18:53 -07:00
|
|
|
import net.minecraft.world.IBlockAccess;
|
|
|
|
|
import net.minecraft.world.World;
|
2013-12-31 20:24:06 -05:00
|
|
|
import net.minecraftforge.common.util.ForgeDirection;
|
2013-07-26 21:18:53 -07:00
|
|
|
import net.minecraftforge.fluids.FluidContainerRegistry;
|
|
|
|
|
import net.minecraftforge.fluids.FluidStack;
|
2013-08-07 19:06:26 -07:00
|
|
|
import tconstruct.blocks.logic.LavaTankLogic;
|
|
|
|
|
import tconstruct.client.block.TankRender;
|
|
|
|
|
import tconstruct.library.TConstructRegistry;
|
2013-07-26 21:18:53 -07:00
|
|
|
|
|
|
|
|
public class LavaTankBlock extends BlockContainer
|
|
|
|
|
{
|
2013-12-31 20:24:06 -05:00
|
|
|
public IIcon[] icons;
|
2013-12-11 23:47:07 -05:00
|
|
|
String texturePrefix = "";
|
2013-07-26 21:18:53 -07:00
|
|
|
|
2013-12-31 20:24:06 -05:00
|
|
|
public LavaTankBlock()
|
2013-07-26 21:18:53 -07:00
|
|
|
{
|
2014-02-05 08:28:53 -05:00
|
|
|
super(Material.rock);
|
|
|
|
|
setHardness(3F);
|
|
|
|
|
setResistance(20F);
|
|
|
|
|
setCreativeTab(TConstructRegistry.blockTab);
|
2014-02-14 23:05:41 -05:00
|
|
|
this.setBlockName("TConstruct.LavaTank");
|
|
|
|
|
setStepSound(Block.soundTypeGrass);
|
2013-07-26 21:18:53 -07:00
|
|
|
}
|
|
|
|
|
|
2013-12-31 20:24:06 -05:00
|
|
|
public LavaTankBlock(String prefix)
|
2013-12-11 23:47:07 -05:00
|
|
|
{
|
2013-12-31 20:24:06 -05:00
|
|
|
this();
|
2013-12-11 23:47:07 -05:00
|
|
|
texturePrefix = prefix;
|
|
|
|
|
}
|
|
|
|
|
|
2013-07-26 21:18:53 -07:00
|
|
|
public String[] getTextureNames ()
|
|
|
|
|
{
|
|
|
|
|
String[] textureNames = { "lavatank_side", "lavatank_top", "searedgague_top", "searedgague_side", "searedgague_bottom", "searedwindow_top", "searedwindow_side", "searedwindow_bottom" };
|
|
|
|
|
|
2013-12-11 23:47:07 -05:00
|
|
|
if (!texturePrefix.equals(""))
|
|
|
|
|
for (int i = 0; i < textureNames.length; i++)
|
|
|
|
|
textureNames[i] = texturePrefix + "_" + textureNames[i];
|
|
|
|
|
|
2013-07-26 21:18:53 -07:00
|
|
|
return textureNames;
|
|
|
|
|
}
|
|
|
|
|
|
2014-02-14 23:05:41 -05:00
|
|
|
public void registerBlockIcons (IIconRegister IIconRegister)
|
2013-07-26 21:18:53 -07:00
|
|
|
{
|
|
|
|
|
String[] textureNames = getTextureNames();
|
2013-12-31 20:24:06 -05:00
|
|
|
this.icons = new IIcon[textureNames.length];
|
2013-07-26 21:18:53 -07:00
|
|
|
|
|
|
|
|
for (int i = 0; i < this.icons.length; ++i)
|
|
|
|
|
{
|
2014-02-14 23:05:41 -05:00
|
|
|
this.icons[i] = IIconRegister.registerIcon("tinker:" + textureNames[i]);
|
2013-07-26 21:18:53 -07:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
2014-02-05 08:28:53 -05:00
|
|
|
public int getRenderBlockPass ()
|
2013-07-26 21:18:53 -07:00
|
|
|
{
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
2014-02-05 08:28:53 -05:00
|
|
|
public boolean isOpaqueCube ()
|
2013-07-26 21:18:53 -07:00
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
2014-02-05 08:28:53 -05:00
|
|
|
public boolean renderAsNormalBlock ()
|
2013-07-26 21:18:53 -07:00
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
2014-02-05 08:28:53 -05:00
|
|
|
public boolean shouldSideBeRendered (IBlockAccess world, int x, int y, int z, int side)
|
2013-07-26 21:18:53 -07:00
|
|
|
{
|
|
|
|
|
//if (side == 0 && world.getBlockMetadata(x, y, z) == 0)
|
2014-02-14 23:05:41 -05:00
|
|
|
//return super.shouldSideBeRendered(world, x, y, z, side);
|
|
|
|
|
Block bID = world.getBlock(x, y, z);
|
|
|
|
|
return bID == this ? false : super.shouldSideBeRendered(world, x, y, z, side);
|
2013-07-26 21:18:53 -07:00
|
|
|
//return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public int getLightValue (IBlockAccess world, int x, int y, int z)
|
|
|
|
|
{
|
2014-02-05 08:28:53 -05:00
|
|
|
TileEntity logic = world.getTileEntity(x, y, z);
|
2013-07-26 21:18:53 -07:00
|
|
|
if (logic != null && logic instanceof LavaTankLogic)
|
|
|
|
|
return ((LavaTankLogic) logic).getBrightness();
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*@Override
|
|
|
|
|
public int getRenderBlockPass()
|
|
|
|
|
{
|
|
|
|
|
return 1;
|
|
|
|
|
}*/
|
|
|
|
|
|
|
|
|
|
@Override
|
2014-02-05 08:28:53 -05:00
|
|
|
public int getRenderType ()
|
2013-07-26 21:18:53 -07:00
|
|
|
{
|
|
|
|
|
return TankRender.tankModelID;
|
|
|
|
|
}
|
|
|
|
|
|
2014-02-05 08:28:53 -05:00
|
|
|
public IIcon getIcon (int side, int meta)
|
2013-07-26 21:18:53 -07:00
|
|
|
{
|
2013-08-22 17:17:38 -07:00
|
|
|
if (meta >= 3)
|
|
|
|
|
meta = 0;
|
2013-07-26 21:18:53 -07:00
|
|
|
if (meta == 0)
|
|
|
|
|
{
|
|
|
|
|
if (side == 0 || side == 1)
|
|
|
|
|
{
|
|
|
|
|
return icons[1];
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
return icons[0];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
return icons[meta * 3 + getTextureIndex(side) - 1];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public int getTextureIndex (int side)
|
|
|
|
|
{
|
|
|
|
|
if (side == 0)
|
|
|
|
|
return 2;
|
|
|
|
|
if (side == 1)
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
2014-02-14 23:05:41 -05:00
|
|
|
public TileEntity createTileEntity (World world, int metadata)
|
2013-07-26 21:18:53 -07:00
|
|
|
{
|
|
|
|
|
return new LavaTankLogic();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
2014-02-14 23:05:41 -05:00
|
|
|
public boolean onBlockActivated (World world, int i, int j, int k, EntityPlayer entityplayer, int par6, float par7, float par8, float par9)
|
2013-07-26 21:18:53 -07:00
|
|
|
{
|
2014-02-14 23:05:41 -05:00
|
|
|
ItemStack current = entityplayer.inventory.getCurrentItem();
|
|
|
|
|
|
|
|
|
|
if (current != null)
|
2013-07-26 21:18:53 -07:00
|
|
|
{
|
2014-02-14 23:05:41 -05:00
|
|
|
FluidStack liquid = FluidContainerRegistry.getFluidForFilledItem(current);
|
|
|
|
|
|
|
|
|
|
LavaTankLogic tank = (LavaTankLogic) world.getTileEntity(i, j, k);
|
|
|
|
|
|
|
|
|
|
if (liquid != null)
|
|
|
|
|
{
|
|
|
|
|
int qty = tank.fill(ForgeDirection.UNKNOWN, liquid, true);
|
|
|
|
|
|
|
|
|
|
if (qty != 0 && !entityplayer.capabilities.isCreativeMode)
|
|
|
|
|
{
|
|
|
|
|
entityplayer.inventory.setInventorySlotContents(entityplayer.inventory.currentItem, consumeItem(current));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**ItemStack current = entityplayer.inventory.getCurrentItem();
|
|
|
|
|
if (current != null)
|
|
|
|
|
{
|
|
|
|
|
FluidStack liquid = FluidContainerRegistry.getFluidForFilledItem(current);
|
|
|
|
|
//FluidStack liquid = FluidContainerRegistry.getFluidForFilledItem(current);
|
2014-02-05 08:28:53 -05:00
|
|
|
LavaTankLogic logic = (LavaTankLogic) world.getTileEntity(x, y, z);
|
2013-07-26 21:18:53 -07:00
|
|
|
if (liquid != null)
|
|
|
|
|
{
|
|
|
|
|
int amount = logic.fill(ForgeDirection.UNKNOWN, liquid, false);
|
|
|
|
|
if (amount == liquid.amount)
|
|
|
|
|
{
|
|
|
|
|
logic.fill(ForgeDirection.UNKNOWN, liquid, true);
|
2014-02-14 23:05:41 -05:00
|
|
|
if (!entityplayer.capabilities.isCreativeMode)
|
|
|
|
|
entityplayer.inventory.setInventorySlotContents(entityplayer.inventory.currentItem, consumeItem(current));
|
2013-07-26 21:18:53 -07:00
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2014-02-14 23:05:41 -05:00
|
|
|
else if (FluidContainerRegistry.isFilledContainer(current))
|
2013-07-26 21:18:53 -07:00
|
|
|
{
|
|
|
|
|
FluidTankInfo[] tanks = logic.getTankInfo(ForgeDirection.UNKNOWN);
|
|
|
|
|
FluidStack fillFluid = tanks[0].fluid;//getFluid();
|
2014-02-14 23:05:41 -05:00
|
|
|
ItemStack fillStack = FluidContainerRegistry.fillFluidContainer(fillFluid, current);
|
2013-07-26 21:18:53 -07:00
|
|
|
if (fillStack != null)
|
|
|
|
|
{
|
|
|
|
|
logic.drain(ForgeDirection.UNKNOWN, FluidContainerRegistry.getFluidForFilledItem(fillStack).amount, true);
|
2014-02-14 23:05:41 -05:00
|
|
|
if (!entityplayer.capabilities.isCreativeMode)
|
2013-07-26 21:18:53 -07:00
|
|
|
{
|
2014-02-14 23:05:41 -05:00
|
|
|
if (current.stackSize == 1)
|
2013-07-26 21:18:53 -07:00
|
|
|
{
|
2014-02-14 23:05:41 -05:00
|
|
|
entityplayer.inventory.setInventorySlotContents(entityplayer.inventory.currentItem, fillStack);
|
2013-07-26 21:18:53 -07:00
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2014-02-14 23:05:41 -05:00
|
|
|
entityplayer.inventory.setInventorySlotContents(entityplayer.inventory.currentItem, consumeItem(current));
|
2013-07-26 21:18:53 -07:00
|
|
|
|
2014-02-14 23:05:41 -05:00
|
|
|
if (!entityplayer.inventory.addItemStackToInventory(fillStack))
|
2013-07-26 21:18:53 -07:00
|
|
|
{
|
2014-02-14 23:05:41 -05:00
|
|
|
entityplayer.dropPlayerItemWithRandomChoice(fillStack, false);
|
2013-07-26 21:18:53 -07:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
2014-02-14 23:05:41 -05:00
|
|
|
}*/
|
2013-07-26 21:18:53 -07:00
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static ItemStack consumeItem (ItemStack stack)
|
|
|
|
|
{
|
|
|
|
|
if (stack.stackSize == 1)
|
|
|
|
|
{
|
|
|
|
|
if (stack.getItem().hasContainerItem())
|
2014-02-01 15:43:24 -05:00
|
|
|
return stack.getItem().getContainerItem(stack);
|
2013-07-26 21:18:53 -07:00
|
|
|
else
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
stack.splitStack(1);
|
|
|
|
|
|
|
|
|
|
return stack;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
2014-02-14 23:05:41 -05:00
|
|
|
public TileEntity createNewTileEntity (World world, int test)
|
|
|
|
|
{
|
|
|
|
|
return createTileEntity(world, 0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void getSubBlocks (Item id, CreativeTabs tab, List list)
|
2013-07-26 21:18:53 -07:00
|
|
|
{
|
|
|
|
|
for (int iter = 0; iter < 3; iter++)
|
|
|
|
|
{
|
2014-02-14 23:05:41 -05:00
|
|
|
list.add(new ItemStack(id, 1, iter));
|
2013-07-26 21:18:53 -07:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Data */
|
|
|
|
|
public int damageDropped (int meta)
|
|
|
|
|
{
|
|
|
|
|
return meta;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Updates */
|
|
|
|
|
public void onNeighborBlockChange (World world, int x, int y, int z, int nBlockID)
|
|
|
|
|
{
|
2014-02-05 08:28:53 -05:00
|
|
|
TileEntity logic = world.getTileEntity(x, y, z);
|
2013-07-26 21:18:53 -07:00
|
|
|
if (logic instanceof IServantLogic)
|
|
|
|
|
{
|
|
|
|
|
((IServantLogic) logic).notifyMasterOfChange();
|
|
|
|
|
}
|
|
|
|
|
}
|
2013-08-07 19:06:26 -07:00
|
|
|
|
2013-09-19 04:37:20 -07:00
|
|
|
@Override
|
2014-02-02 11:35:00 -05:00
|
|
|
public boolean removedByPlayer (World world, EntityPlayer player, int x, int y, int z)
|
2013-08-07 19:06:26 -07:00
|
|
|
{
|
|
|
|
|
player.addExhaustion(0.025F);
|
|
|
|
|
int meta = world.getBlockMetadata(x, y, z);
|
2014-01-07 13:50:35 -05:00
|
|
|
ItemStack stack = new ItemStack(this, 1, meta);
|
2014-02-05 08:28:53 -05:00
|
|
|
LavaTankLogic logic = (LavaTankLogic) world.getTileEntity(x, y, z);
|
2013-08-07 19:06:26 -07:00
|
|
|
FluidStack liquid = logic.tank.getFluid();
|
|
|
|
|
if (liquid != null)
|
|
|
|
|
{
|
|
|
|
|
NBTTagCompound tag = new NBTTagCompound();
|
|
|
|
|
NBTTagCompound liquidTag = new NBTTagCompound();
|
|
|
|
|
liquid.writeToNBT(liquidTag);
|
2014-01-16 01:36:18 -05:00
|
|
|
tag.setTag("Fluid", liquidTag);
|
2013-08-07 19:06:26 -07:00
|
|
|
stack.setTagCompound(tag);
|
|
|
|
|
}
|
2013-08-24 22:36:19 -07:00
|
|
|
if (!player.capabilities.isCreativeMode || player.isSneaking())
|
|
|
|
|
dropTankBlock(world, x, y, z, stack);
|
|
|
|
|
|
2014-02-14 23:05:41 -05:00
|
|
|
return world.setBlockToAir(x, y, z);
|
2013-08-07 19:06:26 -07:00
|
|
|
}
|
2013-08-24 22:36:19 -07:00
|
|
|
|
|
|
|
|
protected void dropTankBlock (World world, int x, int y, int z, ItemStack stack)
|
2013-08-07 19:06:26 -07:00
|
|
|
{
|
|
|
|
|
if (!world.isRemote && world.getGameRules().getGameRuleBooleanValue("doTileDrops"))
|
|
|
|
|
{
|
|
|
|
|
float f = 0.7F;
|
2013-08-24 22:36:19 -07:00
|
|
|
double d0 = (double) (world.rand.nextFloat() * f) + (double) (1.0F - f) * 0.5D;
|
|
|
|
|
double d1 = (double) (world.rand.nextFloat() * f) + (double) (1.0F - f) * 0.5D;
|
|
|
|
|
double d2 = (double) (world.rand.nextFloat() * f) + (double) (1.0F - f) * 0.5D;
|
|
|
|
|
EntityItem entityitem = new EntityItem(world, (double) x + d0, (double) y + d1, (double) z + d2, stack);
|
2014-02-05 08:28:53 -05:00
|
|
|
entityitem.delayBeforeCanPickup = 10;
|
2013-08-07 19:06:26 -07:00
|
|
|
world.spawnEntityInWorld(entityitem);
|
|
|
|
|
}
|
|
|
|
|
}
|
2013-08-24 22:36:19 -07:00
|
|
|
|
|
|
|
|
public void harvestBlock (World par1World, EntityPlayer par2EntityPlayer, int par3, int par4, int par5, int par6)
|
2013-08-07 19:06:26 -07:00
|
|
|
{
|
2013-08-24 22:36:19 -07:00
|
|
|
|
2013-08-07 19:06:26 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
2014-02-05 08:28:53 -05:00
|
|
|
public void onBlockPlacedBy (World world, int x, int y, int z, EntityLivingBase living, ItemStack stack)
|
2013-08-07 19:06:26 -07:00
|
|
|
{
|
|
|
|
|
if (stack.hasTagCompound())
|
|
|
|
|
{
|
|
|
|
|
NBTTagCompound liquidTag = stack.getTagCompound().getCompoundTag("Fluid");
|
|
|
|
|
if (liquidTag != null)
|
|
|
|
|
{
|
|
|
|
|
FluidStack liquid = FluidStack.loadFluidStackFromNBT(liquidTag);
|
2014-02-05 08:28:53 -05:00
|
|
|
LavaTankLogic logic = (LavaTankLogic) world.getTileEntity(x, y, z);
|
2013-08-07 19:06:26 -07:00
|
|
|
logic.tank.setFluid(liquid);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2014-02-14 23:05:41 -05:00
|
|
|
}
|