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

158 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;
2015-07-29 14:35:00 -04:00
import WayofTime.alchemicalWizardry.api.alchemy.energy.ReagentRegistry;
2014-08-25 07:58:39 -04:00
import net.minecraft.block.BlockContainer;
import net.minecraft.block.material.Material;
2015-07-29 14:35:00 -04:00
import net.minecraft.block.state.IBlockState;
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;
2015-07-29 14:35:00 -04:00
import net.minecraft.util.BlockPos;
import net.minecraft.world.IBlockAccess;
2014-08-25 07:58:39 -04:00
import net.minecraft.world.World;
import WayofTime.alchemicalWizardry.ModBlocks;
import WayofTime.alchemicalWizardry.api.alchemy.energy.Reagent;
import WayofTime.alchemicalWizardry.api.alchemy.energy.ReagentContainer;
import WayofTime.alchemicalWizardry.common.tileEntity.TEBellJar;
2015-07-29 14:35:00 -04:00
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.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
}
@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
2015-07-29 14:35:00 -04:00
public void onBlockPlacedBy(World world, BlockPos blockPos, IBlockState blockState, EntityLivingBase entityLiving, ItemStack stack)
2014-10-13 22:33:20 +02:00
{
2015-07-29 14:35:00 -04:00
TileEntity tile = world.getTileEntity(blockPos);
2014-10-13 22:33:20 +02:00
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();
}
2014-08-25 07:58:39 -04:00
@Override
public int getRenderType()
{
return -1;
}
@Override
public boolean isOpaqueCube()
{
return false;
}
@Override
2015-07-29 14:35:00 -04:00
public boolean hasTileEntity(IBlockState blockState)
2014-08-25 07:58:39 -04:00
{
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
2015-07-29 14:35:00 -04:00
public int getComparatorInputOverride(World world, BlockPos blockPos)
2014-08-25 07:58:39 -04:00
{
2015-07-29 14:35:00 -04:00
TileEntity tile = world.getTileEntity(blockPos);
2014-10-13 22:33:20 +02:00
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
2015-07-29 14:35:00 -04:00
public void onBlockHarvested(World world, BlockPos blockPos, IBlockState blockState, EntityPlayer player)
2014-09-14 18:21:45 -04:00
{
2015-07-29 14:35:00 -04:00
this.dropBlockAsItem(world, blockPos, blockState, 0);
super.onBlockHarvested(world, blockPos, blockState, 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
2015-07-29 14:35:00 -04:00
public ArrayList<ItemStack> getDrops(IBlockAccess world, BlockPos blockPos, IBlockState blockState, int fortune)
2014-09-14 18:21:45 -04:00
{
2015-07-29 14:35:00 -04:00
ArrayList<ItemStack> list = new ArrayList<ItemStack>();
2014-10-13 22:33:20 +02:00
2015-07-29 14:35:00 -04:00
TileEntity tile = world.getTileEntity(blockPos);
2014-10-13 22:33:20 +02:00
if (tile instanceof TEBellJar)
{
ItemStack drop = new ItemStack(this);
NBTTagCompound tag = new NBTTagCompound();
((TEBellJar) tile).writeTankNBT(tag);
2015-01-16 10:00:50 -05:00
drop.setTagCompound(tag);
2014-10-13 22:33:20 +02:00
list.add(drop);
}
return list;
2014-09-14 18:21:45 -04:00
}
2014-08-25 07:58:39 -04:00
}