public class BlockMultiBlock extends Block implements ITileEntityProvider {
public BlockMultiBlock() {
super(Material.iron);
setStepSound(soundTypeAnvil);
setHardness(5F);
setResistance(2000F);
setBlockTextureName(MultiBlockMod.MODID + ":multi_block");
setBlockName(MultiBlockMod.MODID + ".multi_block");
setCreativeTab(CreativeTabs.tabBlock);
}
@Override
public TileEntity createNewTileEntity(World world, int metadata) {
return metadata == 15 ? new TileEntityMultiBlock() : null;
}
/*
@Override
public boolean isOpaqueCube() {
return false;
}
@Override
public boolean renderAsNormalBlock() {
return false;
}
@Override
public int getRenderType() {
return -1;
}
*/
/*
@Override
public void addCollisionBoxesToList(World world, int x, int y, int z, AxisAlignedBB aabb, List list, Entity entity) {
setBlockBounds(0.4375F, 0.0F, 0.4375F, 0.5625F, 0.875F, 0.5625F);
super.addCollisionBoxesToList(world, x, y, z, aabb, list, entity);
setBlockBoundsForItemRender();
super.addCollisionBoxesToList(world, x, y, z, aabb, list, entity);
}
*/
/*
@Override
public void setBlockBoundsForItemRender() {
setBlockBounds(0.0F, 0.0F, 0.0F, 1.0F, 0.125F, 1.0F);
}
*/
@Override
public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int side, float hitX, float hitY, float hitZ) {
if (world.isRemote) return true;
else {
System.out.println(world.getBlockMetadata(x, y, z));
if (world.getBlockMetadata(x, y, z) == 15) {
player.openGui(MultiBlockMod.instance, 0, world, x, y, z);
} else {
for (int osX = -1; osX < 2; ++osX) {
for (int osZ = -1; osZ < 2; ++osZ) {
for (int osY = -4; osY < 1; ++osY) {
if (world.getBlock(x + osX, y + osY, z + osZ) == this && world.getBlockMetadata(x + osX, y + osY, z + osZ) == 15) {
player.openGui(MultiBlockMod.instance, 0, world, x + osX, y + osY, z + osZ);
return true;
}
}
}
}
}
return true;
}
}
@Override
public void onBlockPlacedBy(World world, int x, int y, int z, EntityLivingBase entity, ItemStack itemStack) {
if (world.getBlockMetadata(x, y, z) == 15) {
if (itemStack.hasDisplayName())
((TileEntityMultiBlock)world.getTileEntity(x, y, z)).setInventoryName(itemStack.getDisplayName());
} else {
for (int osX = -1; osX < 2; ++osX) {
for (int osZ = -1; osZ < 2; ++osZ) {
for (int osY = 0; osY < 5; ++osY) {
if (osX == 0 && osY == 0 && osZ == 0) continue;
else
if (!world.isAirBlock(x + osX, y + osY, z + osZ)) {
world.func_147480_a(x, y, z, true);
return;
}
}
}
}
for (int osX = -1; osX < 2; ++osX) {
for (int osZ = -1; osZ < 2; ++osZ) {
for (int osY = 0; osY < 5; ++osY) {
if (osX == 0 && osY == 0 && osZ == 0)
world.setBlockMetadataWithNotify(x + osX, y + osY, z + osZ, 15, 3);
else
world.setBlock(x + osX, y + osY, z + osZ, this);
}
}
}
}
}
@Override
public void breakBlock(World world, int x, int y, int z, Block block, int metadata) {
boolean breakAll = false;
if (metadata == 15) breakAll = true;
else {
for (int osX = -1; osX < 2; ++osX) {
for (int osZ = -1; osZ < 2; ++osZ) {
for (int osY = -4; osY < 1; ++osY) {
if (world.getBlock(x + osX, y + osY, z + osZ) == this && world.getBlockMetadata(x + osX, y + osY, z + osZ) == 15) {
x += osX;
y += osY;
z += osZ;
breakAll = true;
break;
}
if (breakAll) break;
}
if (breakAll) break;
}
if (breakAll) break;
}
}
TileEntity tileentity = world.getTileEntity(x, y, z);
if (tileentity instanceof TileEntityMultiBlock) {
TileEntityMultiBlock te = (TileEntityMultiBlock)tileentity;
for (int i1 = 0; i1 < te.getSizeInventory(); ++i1) {
ItemStack itemstack = te.getStackInSlot(i1);
if (itemstack != null) {
float f = world.rand.nextFloat() * 0.8F + 0.1F;
float f1 = world.rand.nextFloat() * 0.8F + 0.1F;
float f2 = world.rand.nextFloat() * 0.8F + 0.1F;
while (itemstack.stackSize > 0) {
int j1 = world.rand.nextInt(21) + 10;
if (j1 > itemstack.stackSize) {
j1 = itemstack.stackSize;
}
itemstack.stackSize -= j1;
EntityItem entityitem = new EntityItem(world, (double)((float)x + f), (double)((float)y + f1), (double)((float)z + f2), new ItemStack(itemstack.getItem(), j1, itemstack.getItemDamage()));
float f3 = 0.05F;
entityitem.motionX = (double)((float)world.rand.nextGaussian() * f3);
entityitem.motionY = (double)((float)world.rand.nextGaussian() * f3 + 0.2F);
entityitem.motionZ = (double)((float)world.rand.nextGaussian() * f3);
world.spawnEntityInWorld(entityitem);
}
}
}
}
if (breakAll) {
for (int osX = x - 1; osX < x + 2; ++osX) {
for (int osZ = z - 1; osZ < z + 2; ++osZ) {
for (int osY = y; osY < y + 5; ++osY) {
if (world.getBlock(osX, osY, osZ) == this) {
if (osX == x && osY == y && osZ == z) {
world.setBlockMetadataWithNotify(osX, osY, osZ, 0, 3);
world.func_147480_a(osX, osY, osZ, true);
world.removeTileEntity(osX, osY, osZ);
} else
world.setBlockToAir(osX, osY, osZ);
}
}
}
}
}
//super.breakBlock(world, x, y, z, block, metadata);
}
@Override
public boolean hasComparatorInputOverride() {
return true;
}
@Override
public int getComparatorInputOverride(World world, int x, int y, int z, int p_149736_5_) {
return Container.calcRedstoneFromInventory((IInventory)world.getTileEntity(x, y, z));
}
@SideOnly(Side.CLIENT)
@Override
public void randomDisplayTick(World world, int x, int y, int z, Random random) {
TileEntity tileentity = world.getTileEntity(x, y, z);
if (tileentity instanceof TileEntityMultiBlock) {
TileEntityMultiBlock te = (TileEntityMultiBlock)tileentity;
if (te.getMakingTime() > 0) {
double d0 = (double)((float)x + 0.4F + random.nextFloat() * 0.2F);
double d1 = (double)((float)y + 0.7F + random.nextFloat() * 0.3F);
double d2 = (double)((float)z + 0.4F + random.nextFloat() * 0.2F);
world.spawnParticle("smoke", d0, d1, d2, 0.0D, 0.0D, 0.0D);
}
}
}
}