equivalent-exchange-3/ee3_common/com/pahimar/ee3/block/BlockGlassDome.java

122 lines
3.6 KiB
Java
Raw Normal View History

2013-02-18 03:30:11 +01:00
package com.pahimar.ee3.block;
import java.util.Random;
import net.minecraft.block.material.Material;
import net.minecraft.entity.item.EntityItem;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.World;
2013-02-26 22:08:43 +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;
2013-04-16 22:06:30 +02:00
import com.pahimar.ee3.tileentity.TileGlassDome;
public class BlockGlassDome extends BlockEE {
2013-02-18 03:30:11 +01:00
/**
2013-04-16 22:06:30 +02:00
* Is the random generator used by glass dome to drop the inventory contents in
2013-02-26 22:08:43 +01:00
* random directions.
2013-02-18 03:30:11 +01:00
*/
private Random rand = new Random();
2013-04-16 22:06:30 +02:00
public BlockGlassDome(int id) {
2013-02-26 22:08:43 +01:00
2013-04-16 22:06:30 +02:00
super(id, Material.glass);
this.setUnlocalizedName(Strings.GLASS_DOME_NAME);
2013-02-18 03:30:11 +01:00
this.setCreativeTab(EquivalentExchange3.tabsEE3);
2013-04-16 22:06:30 +02:00
this.setBlockBounds(0.125F, 0.0F, 0.125F, 0.875F, 0.66F, 0.875F);
this.setHardness(1.0F);
2013-02-18 03:30:11 +01:00
}
2013-04-16 22:06:30 +02:00
2013-02-18 03:30:11 +01:00
@Override
public TileEntity createNewTileEntity(World world) {
2013-04-16 22:06:30 +02:00
return new TileGlassDome();
2013-02-18 03:30:11 +01:00
}
2013-02-26 22:08:43 +01:00
2013-02-18 03:30:11 +01:00
@Override
public boolean renderAsNormalBlock() {
return false;
}
@Override
public boolean isOpaqueCube() {
return false;
}
@Override
public int getRenderType() {
2013-04-16 22:06:30 +02:00
return RenderIds.glassDomeId;
2013-02-18 03:30:11 +01:00
}
@Override
public void breakBlock(World world, int x, int y, int z, int id, int meta) {
2013-02-26 22:08:43 +01:00
2013-02-18 03:30:11 +01:00
dropInventory(world, x, y, z);
super.breakBlock(world, x, y, z, id, meta);
}
@Override
2013-02-26 22:08:43 +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-18 03:30:11 +01:00
if (player.isSneaking())
2013-02-26 22:08:43 +01:00
return false;
else {
if (!world.isRemote) {
2013-04-16 22:06:30 +02:00
TileGlassDome tileGlassDome = (TileGlassDome) world.getBlockTileEntity(x, y, z);
2013-04-16 22:06:30 +02:00
if (tileGlassDome != null) {
player.openGui(EquivalentExchange3.instance, GuiIds.GLASS_DOME, world, x, y, z);
2013-02-26 22:08:43 +01:00
}
2013-02-18 03:30:11 +01:00
}
2013-02-26 22:08:43 +01:00
return true;
2013-02-18 03:30:11 +01:00
}
}
2013-02-26 22:08:43 +01:00
2013-02-18 03:30:11 +01:00
private void dropInventory(World world, int x, int y, int z) {
2013-02-26 22:08:43 +01:00
2013-02-18 03:30:11 +01:00
TileEntity tileEntity = world.getBlockTileEntity(x, y, z);
2013-02-26 22:08:43 +01:00
if (!(tileEntity instanceof IInventory))
2013-02-18 03:30:11 +01:00
return;
2013-02-26 22:08:43 +01:00
2013-02-18 03:30:11 +01:00
IInventory inventory = (IInventory) tileEntity;
for (int i = 0; i < inventory.getSizeInventory(); i++) {
2013-02-26 22:08:43 +01:00
2013-02-18 03:30:11 +01:00
ItemStack itemStack = inventory.getStackInSlot(i);
2013-02-26 22:08:43 +01:00
if (itemStack != null && itemStack.stackSize > 0) {
float dX = rand.nextFloat() * 0.8F + 0.1F;
float dY = rand.nextFloat() * 0.8F + 0.1F;
float dZ = rand.nextFloat() * 0.8F + 0.1F;
2013-02-26 22:08:43 +01:00
2013-02-18 03:30:11 +01:00
EntityItem entityItem = new EntityItem(world, x + dX, y + dY, z + dZ, new ItemStack(itemStack.itemID, itemStack.stackSize, itemStack.getItemDamage()));
2013-02-26 22:08:43 +01:00
2013-02-18 03:30:11 +01:00
if (itemStack.hasTagCompound()) {
2013-02-26 22:08:43 +01:00
entityItem.getEntityItem().setTagCompound((NBTTagCompound) itemStack.getTagCompound().copy());
2013-02-18 03:30:11 +01:00
}
float factor = 0.05F;
entityItem.motionX = rand.nextGaussian() * factor;
entityItem.motionY = rand.nextGaussian() * factor + 0.2F;
entityItem.motionZ = rand.nextGaussian() * factor;
2013-02-18 03:30:11 +01:00
world.spawnEntityInWorld(entityItem);
itemStack.stackSize = 0;
}
}
}
2013-04-16 22:06:30 +02:00
2013-02-18 03:30:11 +01:00
}