2012-12-17 21:21:53 +01:00
|
|
|
package com.pahimar.ee3.block;
|
|
|
|
|
2013-02-13 03:47:17 +01:00
|
|
|
import java.util.Random;
|
|
|
|
|
2013-02-12 22:02:40 +01:00
|
|
|
import net.minecraft.block.BlockContainer;
|
2012-12-19 19:09:56 +01:00
|
|
|
import net.minecraft.block.material.Material;
|
2013-02-13 03:47:17 +01:00
|
|
|
import net.minecraft.entity.item.EntityItem;
|
2012-12-19 19:09:56 +01:00
|
|
|
import net.minecraft.entity.player.EntityPlayer;
|
2013-02-12 22:02:40 +01:00
|
|
|
import net.minecraft.inventory.IInventory;
|
|
|
|
import net.minecraft.item.ItemStack;
|
2013-02-13 03:47:17 +01:00
|
|
|
import net.minecraft.nbt.NBTTagCompound;
|
2012-12-19 19:09:56 +01:00
|
|
|
import net.minecraft.tileentity.TileEntity;
|
|
|
|
import net.minecraft.world.World;
|
|
|
|
|
2012-12-17 21:21:53 +01:00
|
|
|
import com.pahimar.ee3.EquivalentExchange3;
|
|
|
|
import com.pahimar.ee3.lib.GuiIds;
|
|
|
|
import com.pahimar.ee3.lib.RenderIds;
|
|
|
|
import com.pahimar.ee3.lib.Strings;
|
|
|
|
import com.pahimar.ee3.tileentity.TileCalcinator;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* BlockCalcinator
|
|
|
|
*
|
|
|
|
* Block class for the Calcinator
|
|
|
|
*
|
|
|
|
* @author pahimar
|
|
|
|
* @license Lesser GNU Public License v3 (http://www.gnu.org/licenses/lgpl.html)
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
public class BlockCalcinator extends BlockEE {
|
|
|
|
|
2013-02-13 03:47:17 +01:00
|
|
|
/**
|
|
|
|
* Is the random generator used by calcinator to drop the inventory contents in random directions.
|
|
|
|
*/
|
|
|
|
private Random rand = new Random();
|
|
|
|
|
2012-12-19 19:09:56 +01:00
|
|
|
public BlockCalcinator(int id) {
|
|
|
|
|
|
|
|
super(id, Material.rock);
|
|
|
|
this.setBlockName(Strings.CALCINATOR_NAME);
|
|
|
|
this.setCreativeTab(EquivalentExchange3.tabsEE3);
|
|
|
|
this.setHardness(5F);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2013-02-12 22:02:40 +01:00
|
|
|
public TileEntity createNewTileEntity(World world) {
|
2012-12-19 19:09:56 +01:00
|
|
|
|
|
|
|
return new TileCalcinator();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean renderAsNormalBlock() {
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean isOpaqueCube() {
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int getRenderType() {
|
|
|
|
|
|
|
|
return RenderIds.calcinatorRenderId;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int getBlockTextureFromSide(int par1) {
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2013-02-12 22:02:40 +01:00
|
|
|
@Override
|
|
|
|
public void breakBlock(World world, int x, int y, int z, int id, int meta) {
|
|
|
|
|
2013-02-13 03:47:17 +01:00
|
|
|
dropInventory(world, x, y, z);
|
2013-02-12 22:02:40 +01:00
|
|
|
super.breakBlock(world, x, y, z, id, meta);
|
|
|
|
}
|
|
|
|
|
2012-12-19 19:09:56 +01:00
|
|
|
public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int par6, float par7, float par8, float par9) {
|
|
|
|
|
2013-02-26 22:08:43 +01:00
|
|
|
if (player.isSneaking()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
if (!world.isRemote) {
|
|
|
|
TileCalcinator tileCalcinator = (TileCalcinator) world.getBlockTileEntity(x, y, z);
|
|
|
|
|
|
|
|
if (tileCalcinator != null) {
|
|
|
|
player.openGui(EquivalentExchange3.instance, GuiIds.CALCINATOR, world, x, y, z);
|
|
|
|
}
|
2012-12-17 21:21:53 +01:00
|
|
|
}
|
2013-02-26 22:08:43 +01:00
|
|
|
|
|
|
|
return true;
|
2012-12-19 19:09:56 +01:00
|
|
|
}
|
2012-12-17 21:21:53 +01:00
|
|
|
}
|
2013-02-12 22:02:40 +01:00
|
|
|
|
|
|
|
private void dropInventory(World world, int x, int y, int z) {
|
|
|
|
TileEntity tileEntity = world.getBlockTileEntity(x, y, z);
|
|
|
|
|
|
|
|
if (!(tileEntity instanceof IInventory)) {
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
IInventory inventory = (IInventory) tileEntity;
|
|
|
|
|
|
|
|
for (int i = 0; i < inventory.getSizeInventory(); i++) {
|
|
|
|
|
|
|
|
ItemStack itemStack = inventory.getStackInSlot(i);
|
|
|
|
|
|
|
|
if ((itemStack != null) && (itemStack.stackSize > 0)) {
|
2013-02-13 03:47:17 +01:00
|
|
|
float dX = this.rand.nextFloat() * 0.8F + 0.1F;
|
|
|
|
float dY = this.rand.nextFloat() * 0.8F + 0.1F;
|
|
|
|
float dZ = this.rand.nextFloat() * 0.8F + 0.1F;
|
|
|
|
|
|
|
|
EntityItem entityItem = new EntityItem(world, x + dX, y + dY, z + dZ, new ItemStack(itemStack.itemID, itemStack.stackSize, itemStack.getItemDamage()));
|
2013-02-12 22:02:40 +01:00
|
|
|
|
2013-02-13 03:47:17 +01:00
|
|
|
if (itemStack.hasTagCompound()) {
|
|
|
|
entityItem.getEntityItem().setTagCompound((NBTTagCompound)itemStack.getTagCompound().copy());
|
|
|
|
}
|
|
|
|
|
|
|
|
float factor = 0.05F;
|
|
|
|
entityItem.motionX = (this.rand.nextGaussian() * factor);
|
|
|
|
entityItem.motionY = (this.rand.nextGaussian() * factor + 0.2F);
|
|
|
|
entityItem.motionZ = (this.rand.nextGaussian() * factor);
|
|
|
|
world.spawnEntityInWorld(entityItem);
|
|
|
|
itemStack.stackSize = 0;
|
2013-02-12 22:02:40 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-12-17 21:21:53 +01:00
|
|
|
}
|