You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

73 lines
2.7 KiB
Java

package net.brokenmoon.afloydironchest.blocks;
import net.brokenmoon.afloydironchest.MixinInterfaces.IEntityPlayerMP;
import net.brokenmoon.afloydironchest.MixinInterfaces.IEntityPlayerSP;
import net.brokenmoon.afloydironchest.tileEntities.TileEntityIronChest;
import net.minecraft.src.*;
import java.util.Random;
public class IronChest extends BlockContainerRotatable {
Random random = new Random();
public IronChest(int id, Material blockMaterial){
super(id, blockMaterial);
}
@Override
public void onBlockAdded(World world, int i, int j, int k) {
super.onBlockAdded(world, i, j, k);
this.setDefaultDirection(world, i, j, k);
}
@Override
public void onBlockRemoval(World world, int i, int j, int k) {
TileEntityIronChest te = (TileEntityIronChest)world.getBlockTileEntity(i, j, k);
for (int l = 0; l < te.getSizeInventory(); ++l) {
ItemStack itemstack = te.getStackInSlot(l);
if (itemstack == null) continue;
float f = this.random.nextFloat() * 0.8f + 0.1f;
float f1 = this.random.nextFloat() * 0.8f + 0.1f;
float f2 = this.random.nextFloat() * 0.8f + 0.1f;
while (itemstack.stackSize > 0) {
int i1 = this.random.nextInt(21) + 10;
if (i1 > itemstack.stackSize) {
i1 = itemstack.stackSize;
}
itemstack.stackSize -= i1;
EntityItem entityitem = new EntityItem(world, (float)i + f, (float)j + f1, (float)k + f2, new ItemStack(itemstack.itemID, i1, itemstack.getMetadata()));
float f3 = 0.05f;
entityitem.motionX = (float)this.random.nextGaussian() * f3;
entityitem.motionY = (float)this.random.nextGaussian() * f3 + 0.2f;
entityitem.motionZ = (float)this.random.nextGaussian() * f3;
world.entityJoinedWorld(entityitem);
}
}
super.onBlockRemoval(world, i, j, k);
}
@Override
public boolean blockActivated(World world, int x, int y, int z, EntityPlayer entityplayer) {
IInventory chest = (TileEntityIronChest)world.getBlockTileEntity(x, y, z);
if (!world.isMultiplayerAndNotHost) {
this.displayGui(entityplayer, chest);
}
return true;
}
@Override
protected TileEntity getBlockEntity() {
return new TileEntityIronChest();
}
public static void displayGui(EntityPlayer player, IInventory inventory){
if(player instanceof EntityPlayerMP) {
//Multiplayer
((IEntityPlayerMP)player).displayGUIIronChest(inventory);
return;
}
//Singleplayer
((IEntityPlayerSP)player).displayGUIIronChest(inventory);
}
}