2014-10-27 16:26:14 -04:00
|
|
|
package info.jbcs.minecraft.chisel.block;
|
|
|
|
|
|
2014-12-03 20:59:03 -05:00
|
|
|
import cpw.mods.fml.relauncher.Side;
|
|
|
|
|
import cpw.mods.fml.relauncher.SideOnly;
|
2014-10-27 16:26:14 -04:00
|
|
|
import info.jbcs.minecraft.chisel.Chisel;
|
|
|
|
|
import info.jbcs.minecraft.chisel.block.tileentity.TileEntityAutoChisel;
|
|
|
|
|
import net.minecraft.block.Block;
|
|
|
|
|
import net.minecraft.block.BlockContainer;
|
|
|
|
|
import net.minecraft.block.material.Material;
|
2014-12-03 20:59:03 -05:00
|
|
|
import net.minecraft.creativetab.CreativeTabs;
|
2014-10-27 16:26:14 -04:00
|
|
|
import net.minecraft.entity.item.EntityItem;
|
|
|
|
|
import net.minecraft.entity.player.EntityPlayer;
|
|
|
|
|
import net.minecraft.item.ItemStack;
|
|
|
|
|
import net.minecraft.nbt.NBTTagCompound;
|
|
|
|
|
import net.minecraft.tileentity.TileEntity;
|
|
|
|
|
import net.minecraft.world.World;
|
|
|
|
|
|
2014-12-03 20:59:03 -05:00
|
|
|
import java.util.List;
|
2014-12-01 19:54:35 -05:00
|
|
|
import java.util.Random;
|
|
|
|
|
|
|
|
|
|
public class BlockAutoChisel extends BlockContainer {
|
|
|
|
|
public BlockAutoChisel() {
|
2014-10-27 16:26:14 -04:00
|
|
|
super(Material.rock);
|
|
|
|
|
setHardness(1F);
|
|
|
|
|
}
|
|
|
|
|
|
2014-11-09 12:01:44 -05:00
|
|
|
@Override
|
2014-12-01 19:54:35 -05:00
|
|
|
public int getRenderType() {
|
2014-11-09 12:01:44 -05:00
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
2014-12-01 19:54:35 -05:00
|
|
|
public boolean isOpaqueCube() {
|
2014-11-09 12:01:44 -05:00
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
2014-12-01 19:54:35 -05:00
|
|
|
public boolean renderAsNormalBlock() {
|
2014-11-09 12:01:44 -05:00
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2014-10-27 16:26:14 -04:00
|
|
|
@Override
|
2014-12-01 19:54:35 -05:00
|
|
|
public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int metadata, float x1, float y1, float z1) {
|
2014-10-27 16:26:14 -04:00
|
|
|
TileEntity tile = world.getTileEntity(x, y, z);
|
2014-12-01 19:54:35 -05:00
|
|
|
if (world.isRemote)
|
2014-10-27 16:26:14 -04:00
|
|
|
return true;
|
2014-12-01 19:54:35 -05:00
|
|
|
if (tile != null && tile instanceof TileEntityAutoChisel)
|
|
|
|
|
player.openGui(Chisel.instance, 1, world, x, y, z);
|
2014-10-27 16:26:14 -04:00
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
2014-12-01 19:54:35 -05:00
|
|
|
public void breakBlock(World world, int x, int y, int z, Block block, int par6) {
|
2014-10-27 16:26:14 -04:00
|
|
|
dropItems(world, x, y, z);
|
|
|
|
|
super.breakBlock(world, x, y, z, block, par6);
|
|
|
|
|
}
|
|
|
|
|
|
2014-12-03 20:59:03 -05:00
|
|
|
@Override
|
|
|
|
|
public int damageDropped(int metadata){
|
|
|
|
|
return metadata;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@SideOnly(Side.CLIENT)
|
|
|
|
|
public void getSubBlocks(int metadata, CreativeTabs creativeTabs, List subItems){
|
|
|
|
|
for(int x = 0; x < 4; x++){
|
|
|
|
|
subItems.add(new ItemStack(this, 1, x));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-12-01 19:54:35 -05:00
|
|
|
private void dropItems(World world, int x, int y, int z) {
|
2014-10-27 16:26:14 -04:00
|
|
|
Random random = new Random();
|
|
|
|
|
TileEntity tileEntity = world.getTileEntity(x, y, z);
|
|
|
|
|
|
2014-12-01 19:54:35 -05:00
|
|
|
if (!(tileEntity instanceof TileEntityAutoChisel)) {
|
2014-10-27 16:26:14 -04:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2014-12-01 19:54:35 -05:00
|
|
|
TileEntityAutoChisel inventory = (TileEntityAutoChisel) world.getTileEntity(x, y, z);
|
2014-10-27 16:26:14 -04:00
|
|
|
|
2014-12-01 19:54:35 -05:00
|
|
|
for (int c = 0; c < inventory.getSizeInventory(); c++) {
|
2014-10-27 16:26:14 -04:00
|
|
|
ItemStack stack = inventory.getStackInSlot(c);
|
|
|
|
|
|
2014-12-01 19:54:35 -05:00
|
|
|
if (stack != null && stack.stackSize > 0) {
|
2014-10-27 16:26:14 -04:00
|
|
|
float rx = random.nextFloat() * 0.8F + 0.1F;
|
|
|
|
|
float ry = random.nextFloat() * 0.8F + 0.1F;
|
|
|
|
|
float rz = random.nextFloat() * 0.8F + 0.1F;
|
|
|
|
|
EntityItem entityItem = new EntityItem(world, x + rx, y + ry, z + rz, stack);
|
|
|
|
|
|
2014-12-01 19:54:35 -05:00
|
|
|
if (stack.hasTagCompound()) {
|
2014-10-27 16:26:14 -04:00
|
|
|
entityItem.getEntityItem().setTagCompound((NBTTagCompound) stack.getTagCompound().copy());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
float factor = 0.05F;
|
|
|
|
|
entityItem.motionX = random.nextGaussian() * factor;
|
|
|
|
|
entityItem.motionY = random.nextGaussian() * factor + 0.2F;
|
|
|
|
|
entityItem.motionZ = random.nextGaussian() * factor;
|
|
|
|
|
world.spawnEntityInWorld(entityItem);
|
|
|
|
|
stack.stackSize = 0;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
2014-12-01 19:54:35 -05:00
|
|
|
public TileEntity createNewTileEntity(World var1, int var2) {
|
2014-10-27 16:26:14 -04:00
|
|
|
return new TileEntityAutoChisel();
|
|
|
|
|
}
|
|
|
|
|
}
|