Advertisement
Guest User

Untitled

a guest
Apr 19th, 2014
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.03 KB | None | 0 0
  1. package projecte.items;
  2.  
  3. import java.util.List;
  4.  
  5. import net.minecraft.block.Block;
  6. import net.minecraft.client.renderer.texture.IIconRegister;
  7. import net.minecraft.entity.item.EntityItem;
  8. import net.minecraft.entity.player.EntityPlayer;
  9. import net.minecraft.init.Items;
  10. import net.minecraft.inventory.IInventory;
  11. import net.minecraft.item.Item;
  12. import net.minecraft.item.ItemStack;
  13. import net.minecraft.world.World;
  14. import net.minecraftforge.common.util.ForgeDirection;
  15. import projecte.ModInfo;
  16. import projecte.ProjectE;
  17.  
  18. public class ItemDestructionCatalyst extends Item {
  19. public ItemDestructionCatalyst() {
  20.  
  21. super();
  22. this.setUnlocalizedName(ModInfo.MOD_ID + ":destructionCatalyst");
  23. this.setCreativeTab(ProjectE.tab);
  24. this.setMaxDamage(15);
  25. maxStackSize = 1;
  26.  
  27. }
  28.  
  29. @Override
  30. public void registerIcons(IIconRegister iconRegister) {
  31. itemIcon = iconRegister.registerIcon(ModInfo.MOD_ID + ":destructionCatalyst");
  32. }
  33.  
  34. @Override
  35. public void addInformation(ItemStack ist, EntityPlayer par2EntityPlayer, List par3List, boolean par4) {
  36. par3List.add("Mines Out A 3x3x3");
  37. par3List.add("[WIP]");
  38. }
  39.  
  40. @Override
  41. public boolean onItemUse(ItemStack ist, EntityPlayer player, World world, int x, int y, int z, int side, float xOff, float yOff, float zOff) {
  42.  
  43. if (hasFuel(player)) {
  44. doExplosion(world, x, y, z, side, player);
  45. }
  46. return true;
  47. }
  48.  
  49. public void doExplosion(World world, int cx, int cy, int cz, int side, EntityPlayer player) {
  50.  
  51. int depth = 50;
  52. int width = 0;
  53. //int depth = player.getCurrentEquippedItem().getItemDamage();
  54. //int width = player.getCurrentEquippedItem().getItemDamage();
  55.  
  56.  
  57. boolean destroyedSomething = false;
  58. boolean playOnce = true;
  59. if (!world.isRemote) {
  60. ForgeDirection dir = ForgeDirection.getOrientation(side);
  61. int x = cx + dir.offsetX;
  62. int y = cy + dir.offsetY;
  63. int z = cz + dir.offsetZ;
  64. for (int xD = (dir.offsetX > 0 ? -dir.offsetX * depth : -width); xD <= (dir.offsetX < 0 ? -dir.offsetX * depth : width); xD++) {
  65. for (int yD = (dir.offsetY > 0 ? -dir.offsetY * depth : -width); yD <= (dir.offsetY < 0 ? -dir.offsetY * depth : width); yD++) {
  66. for (int zD = (dir.offsetZ > 0 ? -dir.offsetZ * depth : -width); zD <= (dir.offsetZ < 0 ? -dir.offsetZ * depth : width); zD++) {
  67. if (isBreakable(world.getBlock(x + xD, y + yD, z + zD))) {
  68.  
  69. Block block = world.getBlock(x + xD, y + yD, z + zD);
  70. List<ItemStack> drops = block.getDrops(world, x + xD, y + yD, z + zD, world.getBlockMetadata(x + xD, y + yD, z + zD), 0);
  71.  
  72. for (ItemStack item : drops) {
  73.  
  74. if(item != null){
  75. world.setBlockToAir(x + xD, y + yD, z + zD);
  76.  
  77. EntityItem entity = new EntityItem(world, cx, cy, cz, item);
  78. world.spawnEntityInWorld(entity);
  79. }
  80.  
  81. }
  82. destroyedSomething = true;
  83.  
  84. }
  85.  
  86. }
  87. }
  88. }
  89. if (destroyedSomething) {
  90. consumeFuel(player);
  91. }
  92. }
  93. }
  94.  
  95. public boolean isBreakable(Block block) {
  96.  
  97. return ":" != null;
  98. }
  99.  
  100. public boolean consumeFuel(EntityPlayer player) {
  101. int FuelCost = 1;
  102. IInventory inventory = player.inventory;
  103. for (int slot = 0; slot < inventory.getSizeInventory(); slot++) {
  104. if (inventory.getStackInSlot(slot) == null) {
  105. continue;
  106. }
  107. if (inventory.getStackInSlot(slot).getItem() == Items.glowstone_dust) {
  108. while (FuelCost > 0 && player.inventory.getStackInSlot(slot) != null) {
  109. player.inventory.decrStackSize(slot, 1);
  110. FuelCost--;
  111. }
  112. if (FuelCost == 0)
  113. return true;
  114. }
  115. }
  116. return false;
  117. }
  118.  
  119. public boolean hasFuel(EntityPlayer player) {
  120. int FuelCount = 0;
  121. IInventory inventory = player.inventory;
  122. for (int slot = 0; slot < inventory.getSizeInventory(); slot++) {
  123. if (inventory.getStackInSlot(slot) == null) {
  124. continue;
  125. }
  126. if (inventory.getStackInSlot(slot).getItem() == Items.glowstone_dust) {
  127. FuelCount += inventory.getStackInSlot(slot).stackSize;
  128. if (FuelCount >= 1)
  129. return true;
  130. }
  131. }
  132. return false;
  133. }
  134. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement