Advertisement
Guest User

Untitled

a guest
Dec 7th, 2016
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.54 KB | None | 0 0
  1. package me.aristhena.utils;
  2.  
  3. import java.util.Objects;
  4. import net.minecraft.block.Block;
  5. import net.minecraft.block.BlockAir;
  6. import net.minecraft.block.BlockHopper;
  7. import net.minecraft.block.BlockIce;
  8. import net.minecraft.block.BlockLadder;
  9. import net.minecraft.block.BlockLiquid;
  10. import net.minecraft.block.BlockPackedIce;
  11. import net.minecraft.block.BlockVine;
  12. import net.minecraft.block.state.IBlockState;
  13. import net.minecraft.client.Minecraft;
  14. import net.minecraft.client.entity.EntityPlayerSP;
  15. import net.minecraft.client.multiplayer.WorldClient;
  16. import net.minecraft.entity.Entity;
  17. import net.minecraft.entity.player.InventoryPlayer;
  18. import net.minecraft.inventory.Container;
  19. import net.minecraft.inventory.Slot;
  20. import net.minecraft.item.Item;
  21. import net.minecraft.item.ItemStack;
  22. import net.minecraft.util.AxisAlignedBB;
  23. import net.minecraft.util.BlockPos;
  24. import net.minecraft.util.MathHelper;
  25.  
  26. public class BlockUtils
  27. {
  28. public static int getBestTool(BlockPos pos)
  29. {
  30. Block block = Minecraft.getMinecraft().theWorld.getBlockState(pos).getBlock();
  31. int slot = 0;
  32. float dmg = 0.1F;
  33. for (int index = 36; index < 45; index++)
  34. {
  35. ItemStack itemStack = Minecraft.getMinecraft().thePlayer.inventoryContainer.getSlot(index).getStack();
  36. if ((itemStack != null) && (block != null) && (itemStack.getItem().getStrVsBlock(itemStack, block) > dmg))
  37. {
  38. slot = index - 36;
  39. dmg = itemStack.getItem().getStrVsBlock(itemStack, block);
  40. }
  41. }
  42. if (dmg > 0.1F) {
  43. return slot;
  44. }
  45. return Minecraft.getMinecraft().thePlayer.inventory.currentItem;
  46. }
  47.  
  48. public static boolean isInLiquid(Entity entity)
  49. {
  50. if (entity == null) {
  51. return false;
  52. }
  53. boolean inLiquid = false;
  54. int y = (int)entity.getEntityBoundingBox().minY;
  55. for (int x = MathHelper.floor_double(entity.getEntityBoundingBox().minX); x < MathHelper.floor_double(Minecraft.getMinecraft().thePlayer.getEntityBoundingBox().maxX) + 1; x++) {
  56. for (int z = MathHelper.floor_double(entity.getEntityBoundingBox().minZ); z < MathHelper.floor_double(entity.getEntityBoundingBox().maxZ) + 1; z++)
  57. {
  58. Block block = Minecraft.getMinecraft().theWorld.getBlockState(new BlockPos(x, y, z)).getBlock();
  59. if ((block != null) && (!(block instanceof BlockAir)))
  60. {
  61. if (!(block instanceof BlockLiquid)) {
  62. return false;
  63. }
  64. inLiquid = true;
  65. }
  66. }
  67. }
  68. return (inLiquid) || (Minecraft.getMinecraft().thePlayer.isInWater());
  69. }
  70.  
  71. public static boolean isOnLiquid(Entity entity)
  72. {
  73. if (entity == null) {
  74. return false;
  75. }
  76. boolean onLiquid = false;
  77. int y = (int)entity.getEntityBoundingBox().offset(0.0D, -0.01D, 0.0D).minY;
  78. for (int x = MathHelper.floor_double(entity.getEntityBoundingBox().minX); x < MathHelper.floor_double(entity.getEntityBoundingBox().maxX) + 1; x++) {
  79. for (int z = MathHelper.floor_double(entity.getEntityBoundingBox().minZ); z < MathHelper.floor_double(entity.getEntityBoundingBox().maxZ) + 1; z++)
  80. {
  81. Block block = Minecraft.getMinecraft().theWorld.getBlockState(new BlockPos(x, y, z)).getBlock();
  82. if ((block != null) && (!(block instanceof BlockAir)))
  83. {
  84. if (!(block instanceof BlockLiquid)) {
  85. return false;
  86. }
  87. onLiquid = true;
  88. }
  89. }
  90. }
  91. return onLiquid;
  92. }
  93.  
  94. public static boolean isOnIce(Entity entity)
  95. {
  96. if (entity == null) {
  97. return false;
  98. }
  99. boolean onIce = false;
  100. int y = (int)entity.getEntityBoundingBox().offset(0.0D, -0.01D, 0.0D).minY;
  101. for (int x = MathHelper.floor_double(entity.getEntityBoundingBox().minX); x < MathHelper.floor_double(entity.getEntityBoundingBox().maxX) + 1; x++) {
  102. for (int z = MathHelper.floor_double(entity.getEntityBoundingBox().minZ); z < MathHelper.floor_double(entity.getEntityBoundingBox().maxZ) + 1; z++)
  103. {
  104. Block block = Minecraft.getMinecraft().theWorld.getBlockState(new BlockPos(x, y, z)).getBlock();
  105. if ((block != null) && (!(block instanceof BlockAir)))
  106. {
  107. if ((!(block instanceof BlockIce)) && (!(block instanceof BlockPackedIce))) {
  108. return false;
  109. }
  110. onIce = true;
  111. }
  112. }
  113. }
  114. return onIce;
  115. }
  116.  
  117. public static boolean isOnLadder(Entity entity)
  118. {
  119. if (entity == null) {
  120. return false;
  121. }
  122. boolean onLadder = false;
  123. int y = (int)entity.getEntityBoundingBox().offset(0.0D, 1.0D, 0.0D).minY;
  124. for (int x = MathHelper.floor_double(entity.getEntityBoundingBox().minX); x < MathHelper.floor_double(entity.getEntityBoundingBox().maxX) + 1; x++) {
  125. for (int z = MathHelper.floor_double(entity.getEntityBoundingBox().minZ); z < MathHelper.floor_double(entity.getEntityBoundingBox().maxZ) + 1; z++)
  126. {
  127. Block block = Minecraft.getMinecraft().theWorld.getBlockState(new BlockPos(x, y, z)).getBlock();
  128. if ((Objects.nonNull(block)) && (!(block instanceof BlockAir)))
  129. {
  130. if ((!(block instanceof BlockLadder)) && (!(block instanceof BlockVine))) {
  131. return false;
  132. }
  133. onLadder = true;
  134. }
  135. }
  136. }
  137. return (onLadder) || (Minecraft.getMinecraft().thePlayer.isOnLadder());
  138. }
  139.  
  140. public static boolean isInsideBlock(Entity entity)
  141. {
  142. for (int x = MathHelper.floor_double(entity.getEntityBoundingBox().minX); x < MathHelper.floor_double(entity.getEntityBoundingBox().maxX) + 1; x++) {
  143. for (int y = MathHelper.floor_double(entity.getEntityBoundingBox().minY); y < MathHelper.floor_double(entity.getEntityBoundingBox().maxY) + 1; y++) {
  144. for (int z = MathHelper.floor_double(entity.getEntityBoundingBox().minZ); z < MathHelper.floor_double(entity.getEntityBoundingBox().maxZ) + 1; z++)
  145. {
  146. Block block = Minecraft.getMinecraft().theWorld.getBlockState(new BlockPos(x, y, z)).getBlock();
  147. if (block != null)
  148. {
  149. AxisAlignedBB boundingBox = block.getCollisionBoundingBox(Minecraft.getMinecraft().theWorld, new BlockPos(x, y, z), Minecraft.getMinecraft().theWorld.getBlockState(new BlockPos(x, y, z)));
  150. if ((block instanceof BlockHopper)) {
  151. boundingBox = new AxisAlignedBB(x, y, z, x + 1, y + 1, z + 1);
  152. }
  153. if ((boundingBox != null) && (entity.getEntityBoundingBox().intersectsWith(boundingBox))) {
  154. return true;
  155. }
  156. }
  157. }
  158. }
  159. }
  160. return false;
  161. }
  162. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement