Advertisement
Guest User

Untitled

a guest
Sep 19th, 2019
159
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.30 KB | None | 0 0
  1. public final class AutoSoupMod
  2. extends Mod
  3. implements UpdateListener
  4. {
  5. private final SliderSetting health = new SliderSetting("Health", 6.5D, 0.5D, 9.5D, 0.5D, SliderSetting.ValueDisplay.DECIMAL);
  6.  
  7. private final CheckboxSetting ignoreScreen = new CheckboxSetting("Ignore screen", true);
  8.  
  9. private int oldSlot = -1;
  10.  
  11.  
  12.  
  13. public AutoSoupMod() {
  14. super("AutoSoup", "Automatically eats soup if your health is lower than or equal to the set value.\n\n�lNote:�r This mod ignores hunger and assumes that eating soup directly refills your health.\nIf the server you are playing on is not configured to do that, use AutoEat instead.");
  15.  
  16.  
  17. setCategory(Category.OTHER);
  18. }
  19.  
  20.  
  21.  
  22. public void initSettings() {
  23. addSetting(this.health);
  24. addSetting(this.ignoreScreen);
  25. }
  26.  
  27.  
  28.  
  29. public Feature[] getSeeAlso() {
  30. return new Feature[] { wurst.mods.autoSplashPotMod,
  31. wurst.mods.autoEatMod };
  32. }
  33.  
  34.  
  35.  
  36.  
  37. public void onEnable() { wurst.events.add(UpdateListener.class, this); }
  38.  
  39.  
  40.  
  41.  
  42. public void onDisable() {
  43. wurst.events.remove(UpdateListener.class, this);
  44. stopIfEating();
  45. }
  46.  
  47.  
  48.  
  49.  
  50. public void onUpdate() {
  51. for (int i = 0; i < 36; i++) {
  52.  
  53.  
  54. ItemStack stack =
  55. (WMinecraft.getPlayer()).inventory.getStackInSlot(i);
  56. if (stack != null && stack.getItem() == Items.BOWL && i != 9) {
  57.  
  58.  
  59.  
  60. ItemStack emptyBowlStack =
  61. (WMinecraft.getPlayer()).inventory.getStackInSlot(9);
  62. boolean swap = (!WItem.isNullOrEmpty(emptyBowlStack) &&
  63. emptyBowlStack.getItem() != Items.BOWL);
  64.  
  65.  
  66. WPlayerController.windowClick_PICKUP((i < 9) ? (36 + i) : i);
  67. WPlayerController.windowClick_PICKUP(9);
  68.  
  69.  
  70. if (swap) {
  71. WPlayerController.windowClick_PICKUP((i < 9) ? (36 + i) : i);
  72. }
  73. }
  74. }
  75. int soupInHotbar = findSoup(0, 9);
  76.  
  77.  
  78. if (soupInHotbar != -1) {
  79.  
  80.  
  81. if (!shouldEatSoup()) {
  82.  
  83. stopIfEating();
  84.  
  85. return;
  86. }
  87.  
  88. if (this.oldSlot == -1) {
  89. this.oldSlot = (WMinecraft.getPlayer()).inventory.currentItem;
  90. }
  91.  
  92. (WMinecraft.getPlayer()).inventory.currentItem = soupInHotbar;
  93.  
  94.  
  95. mc.gameSettings.keyBindUseItem.pressed = true;
  96. WPlayerController.processRightClick();
  97.  
  98. return;
  99. }
  100.  
  101. stopIfEating();
  102.  
  103.  
  104. int soupInInventory = findSoup(9, 36);
  105.  
  106.  
  107. if (soupInInventory != -1) {
  108. WPlayerController.windowClick_QUICK_MOVE(soupInInventory);
  109. }
  110. }
  111.  
  112.  
  113. public void onYesCheatUpdate(YesCheatSpf.Profile profile) {
  114. switch ($SWITCH_TABLE$net$wurstclient$features$special_features$YesCheatSpf$Profile()[profile.ordinal()]) {
  115.  
  116. case 6:
  117. this.ignoreScreen.lock(() -> false);
  118. return;
  119. }
  120.  
  121. this.ignoreScreen.unlock();
  122. }
  123.  
  124.  
  125.  
  126.  
  127. private int findSoup(int startSlot, int endSlot) {
  128. for (int i = startSlot; i < endSlot; i++) {
  129.  
  130. ItemStack stack =
  131. (WMinecraft.getPlayer()).inventory.getStackInSlot(i);
  132.  
  133. if (stack != null && stack.getItem() instanceof net.minecraft.item.ItemSoup) {
  134. return i;
  135. }
  136. }
  137. return -1;
  138. }
  139.  
  140.  
  141.  
  142. private boolean shouldEatSoup() {
  143. if (WMinecraft.getPlayer().getHealth() > this.health.getValueF() * 2.0F) {
  144. return false;
  145. }
  146.  
  147. if (!this.ignoreScreen.isChecked() && mc.currentScreen != null) {
  148. return false;
  149. }
  150.  
  151. if (mc.currentScreen == null && mc.objectMouseOver != null) {
  152.  
  153.  
  154. Entity entity = mc.objectMouseOver.entityHit;
  155. if (entity instanceof net.minecraft.entity.passive.EntityVillager ||
  156. entity instanceof net.minecraft.entity.passive.EntityTameable) {
  157. return false;
  158. }
  159.  
  160. if (mc.objectMouseOver.getBlockPos() != null && WBlock.getBlock(
  161. mc.objectMouseOver.getBlockPos()) instanceof net.minecraft.block.BlockContainer) {
  162. return false;
  163. }
  164. }
  165. return true;
  166. }
  167.  
  168.  
  169.  
  170. private void stopIfEating() {
  171. if (this.oldSlot == -1) {
  172. return;
  173. }
  174.  
  175. mc.gameSettings.keyBindUseItem.pressed = false;
  176.  
  177.  
  178. (WMinecraft.getPlayer()).inventory.currentItem = this.oldSlot;
  179. this.oldSlot = -1;
  180. }
  181. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement