Advertisement
Guest User

Untitled

a guest
Nov 11th, 2016
143
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.86 KB | None | 0 0
  1. package thecraft.mod.common;
  2.  
  3. import cpw.mods.fml.common.network.internal.FMLNetworkHandler;
  4. import net.minecraft.block.Block;
  5. import net.minecraft.block.material.Material;
  6. import net.minecraft.entity.EntityLivingBase;
  7. import net.minecraft.entity.item.EntityItem;
  8. import net.minecraft.entity.player.EntityPlayer;
  9. import net.minecraft.inventory.IInventory;
  10. import net.minecraft.item.ItemStack;
  11. import net.minecraft.nbt.NBTTagCompound;
  12. import net.minecraft.tileentity.TileEntity;
  13. import net.minecraft.tileentity.TileEntityChest;
  14. import net.minecraft.world.World;
  15.  
  16. public class Ewilitechest extends Block
  17. {
  18. public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int side, float hitx, float hity, float hitz)
  19. {
  20. FMLNetworkHandler.openGui(player, ewifaction.instance, 0, world, x, y, z);
  21. return true;
  22. }
  23. protected Ewilitechest(Material material)
  24. {
  25. super(material);
  26. }
  27. public TileEntity createTileEntity(World world)
  28. {
  29. return new TileEntityEwiliteChest();
  30. }
  31.  
  32. public boolean hasTileEntity(int metadata)
  33. {
  34. return true;
  35. }
  36. public boolean onBlockActivated1(World world, int x, int y, int z, EntityPlayer player, int side, float hitX, float hitY, float hitZ)
  37. {
  38. if(world.isRemote)
  39. {
  40. return true;
  41. }
  42. else
  43. {
  44. player.openGui(ewifaction.instance, 0, world, x, y, z);
  45. return true;
  46. }
  47. }
  48. public void breakBlock(World world, int x, int y, int z, Block block, int metadata)
  49. {
  50. TileEntity tileentity = world.getTileEntity(x, y, z);
  51.  
  52. if(tileentity instanceof IInventory)
  53. {
  54. IInventory inv = (IInventory)tileentity;
  55. for(int i1 = 0; i1 < inv.getSizeInventory(); ++i1)
  56. {
  57. ItemStack itemstack = inv.getStackInSlot(i1);
  58.  
  59. if(itemstack != null)
  60. {
  61. float f = world.rand.nextFloat() * 0.8F + 0.1F;
  62. float f1 = world.rand.nextFloat() * 0.8F + 0.1F;
  63. EntityItem entityitem;
  64.  
  65. for(float f2 = world.rand.nextFloat() * 0.8F + 0.1F; itemstack.stackSize > 0; world.spawnEntityInWorld(entityitem))
  66. {
  67. int j1 = world.rand.nextInt(21) + 10;
  68.  
  69. if(j1 > itemstack.stackSize)
  70. {
  71. j1 = itemstack.stackSize;
  72. }
  73.  
  74. itemstack.stackSize -= j1;
  75. entityitem = new EntityItem(world, (double)((float)x + f), (double)((float)y + f1), (double)((float)z + f2), new ItemStack(itemstack.getItem(), j1, itemstack.getItemDamage()));
  76. float f3 = 0.05F;
  77. entityitem.motionX = (double)((float)world.rand.nextGaussian() * f3);
  78. entityitem.motionY = (double)((float)world.rand.nextGaussian() * f3 + 0.2F);
  79. entityitem.motionZ = (double)((float)world.rand.nextGaussian() * f3);
  80.  
  81. if(itemstack.hasTagCompound())
  82. {
  83. entityitem.getEntityItem().setTagCompound((NBTTagCompound)itemstack.getTagCompound().copy());
  84. }
  85. }
  86. }
  87. }
  88. world.func_147453_f(x, y, z, block);
  89. }
  90. super.breakBlock(world, x, y, z, block, metadata);
  91. }
  92. public void onBlockPlacedBy(World world, int x, int y, int z, EntityLivingBase living, ItemStack stack)
  93. {
  94. TileEntity tile = world.getTileEntity(x, y, z);
  95. if(tile instanceof TileEntityEwiliteChest)
  96. {
  97. if(stack.hasDisplayName())
  98. {
  99. ((TileEntityEwiliteChest)tile).setCustomName(stack.getDisplayName(), textureName);
  100. }
  101. }
  102. }
  103.  
  104. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement