BloodMagic/src/main/java/WayofTime/alchemicalWizardry/common/block/BlockBelljar.java

164 lines
4.4 KiB
Java
Raw Normal View History

2014-08-25 07:58:39 -04:00
package WayofTime.alchemicalWizardry.common.block;
import java.util.ArrayList;
import java.util.List;
2014-08-25 07:58:39 -04:00
import net.minecraft.block.BlockContainer;
import net.minecraft.block.material.Material;
import net.minecraft.creativetab.CreativeTabs;
2014-09-14 18:21:45 -04:00
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.Item;
2014-09-14 18:21:45 -04:00
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
2014-08-25 07:58:39 -04:00
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.World;
import WayofTime.alchemicalWizardry.AlchemicalWizardry;
import WayofTime.alchemicalWizardry.ModBlocks;
import WayofTime.alchemicalWizardry.api.alchemy.energy.Reagent;
import WayofTime.alchemicalWizardry.api.alchemy.energy.ReagentContainer;
import WayofTime.alchemicalWizardry.api.alchemy.energy.ReagentRegistry;
import WayofTime.alchemicalWizardry.common.tileEntity.TEBellJar;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
2014-08-25 07:58:39 -04:00
public class BlockBelljar extends BlockContainer
{
2014-10-13 22:33:20 +02:00
public BlockBelljar()
{
super(Material.glass);
setHardness(2.0F);
2014-08-25 07:58:39 -04:00
setResistance(5.0F);
2014-10-13 22:33:20 +02:00
this.setCreativeTab(AlchemicalWizardry.tabBloodMagic);
this.setBlockName("crystalBelljar");
}
@SideOnly(Side.CLIENT)
public void getSubBlocks(Item par1, CreativeTabs par2CreativeTabs, List par3List)
{
if (this.equals(ModBlocks.blockCrystalBelljar))
{
par3List.add(new ItemStack(par1, 1, 0));
for(Reagent reagent : ReagentRegistry.reagentList.values())
{
ItemStack stack = new ItemStack(par1, 1, 0);
NBTTagCompound tag = new NBTTagCompound();
ReagentContainer[] tanks = new ReagentContainer[1];
tanks[0] = new ReagentContainer(reagent, 16000, 16000);
NBTTagList tagList = new NBTTagList();
NBTTagCompound savedTag = new NBTTagCompound();
if (tanks[0] != null)
{
tanks[0].writeToNBT(savedTag);
}
tagList.appendTag(savedTag);
tag.setTag("reagentTanks", tagList);
stack.setTagCompound(tag);
par3List.add(stack);
}
} else
{
super.getSubBlocks(par1, par2CreativeTabs, par3List);
}
}
2014-10-13 22:33:20 +02:00
@Override
public void onBlockPlacedBy(World world, int x, int y, int z, EntityLivingBase entityLiving, ItemStack stack)
{
TileEntity tile = world.getTileEntity(x, y, z);
if (tile instanceof TEBellJar)
{
NBTTagCompound tag = stack.getTagCompound();
if (tag != null)
{
((TEBellJar) tile).readTankNBTOnPlace(tag);
}
}
}
@Override
public TileEntity createNewTileEntity(World world, int meta)
{
return new TEBellJar();
}
@Override
2014-08-25 07:58:39 -04:00
public boolean renderAsNormalBlock()
{
return false;
}
@Override
public int getRenderType()
{
return -1;
}
@Override
public boolean isOpaqueCube()
{
return false;
}
@Override
public boolean hasTileEntity()
{
return true;
2014-10-13 22:33:20 +02:00
}
2014-08-25 07:58:39 -04:00
@Override
2014-10-13 10:33:43 -04:00
public boolean hasComparatorInputOverride()
2014-08-25 07:58:39 -04:00
{
2014-10-13 22:33:20 +02:00
return true;
2014-08-25 07:58:39 -04:00
}
@Override
2014-10-13 10:33:43 -04:00
public int getComparatorInputOverride(World world, int x, int y, int z, int meta)
2014-08-25 07:58:39 -04:00
{
2014-10-13 22:33:20 +02:00
TileEntity tile = world.getTileEntity(x, y, z);
if (tile instanceof TEBellJar)
{
return ((TEBellJar) tile).getRSPowerOutput();
}
2014-08-25 07:58:39 -04:00
return 15;
}
2014-10-13 22:33:20 +02:00
2014-09-14 18:21:45 -04:00
@Override
public void onBlockHarvested(World world, int x, int y, int z, int meta, EntityPlayer player)
{
2014-10-13 22:33:20 +02:00
this.dropBlockAsItem(world, x, y, z, meta, 0);
super.onBlockHarvested(world, x, y, z, meta, player);
2014-09-14 18:21:45 -04:00
}
2014-10-13 22:33:20 +02:00
2014-09-14 18:21:45 -04:00
@Override
public ArrayList<ItemStack> getDrops(World world, int x, int y, int z, int metadata, int fortune)
{
2014-10-13 22:33:20 +02:00
ArrayList<ItemStack> list = new ArrayList();
TileEntity tile = world.getTileEntity(x, y, z);
if (tile instanceof TEBellJar)
{
ItemStack drop = new ItemStack(this);
NBTTagCompound tag = new NBTTagCompound();
((TEBellJar) tile).writeTankNBT(tag);
drop.stackTagCompound = tag;
list.add(drop);
}
return list;
2014-09-14 18:21:45 -04:00
}
2014-08-25 07:58:39 -04:00
}