Adds AutoEat, AutoGapple, Adds new util class: InventoryUtil

This commit is contained in:
noil 2020-12-15 22:19:33 -05:00
parent 781081bf7a
commit 521c1dbb37
5 changed files with 298 additions and 27 deletions

View File

@ -0,0 +1,47 @@
package me.rigamortis.seppuku.api.util;
import net.minecraft.client.Minecraft;
import net.minecraft.item.Item;
/**
* @author noil
*/
public final class InventoryUtil {
private static final Minecraft mc = Minecraft.getMinecraft();
public static boolean hasItem(Item input) {
for (int i = 0; i < 36; i++) {
Item item = mc.player.inventory.getStackInSlot(i).getItem();
if (item == input) {
return true;
}
}
return false;
}
public static int getItemCount(Item input) {
int items = 0;
for (int i = 0; i < 45; i++) {
Item item = mc.player.inventory.getStackInSlot(i).getItem();
if (item == input) {
items += 1;
}
}
return items;
}
public static int getSlotForItem(Item input) {
for (int i = 0; i < 36; i++) {
Item item = mc.player.inventory.getStackInSlot(i).getItem();
if (item == input) {
return i;
}
}
return -1;
}
}

View File

@ -160,6 +160,8 @@ public final class ModuleManager {
add(new MultitaskModule());
add(new InfEnderChestModule());
add(new SearchModule());
add(new AutoGappleModule());
add(new AutoEatModule());
// p2w experience
if (Seppuku.INSTANCE.getCapeManager().hasCape())

View File

@ -0,0 +1,127 @@
package me.rigamortis.seppuku.impl.module.player;
import me.rigamortis.seppuku.api.event.EventStageable;
import me.rigamortis.seppuku.api.event.player.EventPlayerUpdate;
import me.rigamortis.seppuku.api.module.Module;
import me.rigamortis.seppuku.api.value.Value;
import net.minecraft.client.Minecraft;
import net.minecraft.init.Items;
import net.minecraft.inventory.ClickType;
import net.minecraft.item.Item;
import net.minecraft.item.ItemFood;
import net.minecraft.item.ItemStack;
import team.stiff.pomelo.impl.annotated.handler.annotation.Listener;
/**
* @author noil
*/
public final class AutoEatModule extends Module {
public final Value<Float> hunger = new Value<Float>("Hunger", new String[]{"food", "h"}, "The amount of hunger needed to acquire some food.", 7.0f, 0.0f, 20.0f, 0.5f);
public final Value<Integer> forcedSlot = new Value<Integer>("Slot", new String[]{"s"}, "The hot-bar slot to put the food into. (45 for offhand)", 43, 0, 43, 1);
private int previousHeldItem = -1;
private int foodSlot = -1;
public AutoEatModule() {
super("AutoEat", new String[]{"Eat", "AutoFeed"}, "Automatically swaps & eats food when hunger is below the set threshold.", "NONE", -1, ModuleType.PLAYER);
}
@Override
public String getMetaData() {
return "" + this.getFoodCount();
}
@Listener
public void onPlayerUpdate(EventPlayerUpdate event) {
if (event.getStage() != EventStageable.EventStage.PRE)
return;
final Minecraft mc = Minecraft.getMinecraft();
if (mc.player == null)
return;
if (mc.player.getFoodStats().getFoodLevel() < this.hunger.getValue()) {
this.foodSlot = this.findFood();
}
if (this.foodSlot != -1) {
if (this.forcedSlot.getValue() != 45) { // we aren't trying to put it in the offhand
if (this.previousHeldItem == -1) {
this.previousHeldItem = mc.player.inventory.currentItem;
}
if (this.foodSlot < 36) {
mc.playerController.windowClick(0, this.forcedSlot.getValue(), 0, ClickType.QUICK_MOVE, mc.player); // last hot-bar slot
mc.playerController.windowClick(0, this.foodSlot, 0, ClickType.PICKUP, mc.player);
mc.playerController.windowClick(0, this.forcedSlot.getValue(), 0, ClickType.PICKUP, mc.player);
mc.player.inventory.currentItem = this.forcedSlot.getValue() - 36;
} else {
mc.player.inventory.currentItem = this.foodSlot - 36; // in the hot-bar, so remove the inventory offset
}
} else { // we need this notch apple in the offhand
if (mc.player.getHeldItemOffhand().getItem() != Items.GOLDEN_APPLE) {
mc.playerController.windowClick(0, 45, 0, ClickType.QUICK_MOVE, mc.player); // offhand slot
mc.playerController.windowClick(0, this.foodSlot, 0, ClickType.PICKUP, mc.player);
mc.playerController.windowClick(0, 45, 0, ClickType.PICKUP, mc.player);
}
}
if (mc.player.getFoodStats().getFoodLevel() >= this.hunger.getValue()) {
mc.gameSettings.keyBindUseItem.pressed = false;
if (this.previousHeldItem != -1) {
mc.player.inventory.currentItem = this.previousHeldItem;
}
this.foodSlot = -1;
this.previousHeldItem = -1;
} else {
mc.gameSettings.keyBindUseItem.pressed = true;
}
}
}
private int findFood() {
float bestSaturation = -1;
int bestFoodSlot = -1;
for (int slot = 44; slot > 8; slot--) {
ItemStack itemStack = Minecraft.getMinecraft().player.inventoryContainer.getSlot(slot).getStack();
if (itemStack.isEmpty())
continue;
if (this.isFoodItem(itemStack.getItem())) {
float saturation = ((ItemFood) itemStack.getItem()).getSaturationModifier(itemStack);
if (saturation > bestSaturation) {
bestSaturation = saturation;
bestFoodSlot = slot;
}
}
}
return bestFoodSlot;
}
private int getFoodCount() {
int food = 0;
if (Minecraft.getMinecraft().player == null)
return food;
for (int i = 0; i < 45; i++) {
final ItemStack stack = Minecraft.getMinecraft().player.inventory.getStackInSlot(i);
if (!stack.isEmpty() && this.isFoodItem(stack.getItem())) {
food += stack.getCount();
}
}
return food;
}
private boolean isFoodItem(Item item) {
if (!(item instanceof ItemFood))
return false; // is not of ItemFood class
if (item == Items.GOLDEN_APPLE || item == Items.CHORUS_FRUIT || item == Items.ROTTEN_FLESH || item == Items.POISONOUS_POTATO || item == Items.SPIDER_EYE)
return false;
return true;
}
}

View File

@ -0,0 +1,109 @@
package me.rigamortis.seppuku.impl.module.player;
import me.rigamortis.seppuku.api.event.EventStageable;
import me.rigamortis.seppuku.api.event.player.EventPlayerUpdate;
import me.rigamortis.seppuku.api.module.Module;
import me.rigamortis.seppuku.api.value.Value;
import net.minecraft.client.Minecraft;
import net.minecraft.init.Items;
import net.minecraft.inventory.ClickType;
import net.minecraft.item.ItemStack;
import team.stiff.pomelo.impl.annotated.handler.annotation.Listener;
/**
* @author noil
*/
public final class AutoGappleModule extends Module {
public final Value<Float> health = new Value<Float>("Health", new String[]{"Hp", "h"}, "The amount of health needed to acquire a notch apple.", 8.0f, 0.0f, 20.0f, 0.5f);
public final Value<Integer> forcedSlot = new Value<Integer>("Slot", new String[]{"s"}, "The hot-bar slot to put the notch apple into. (45 for offhand)", 44, 0, 44, 1);
private int previousHeldItem = -1;
private int notchAppleSlot = -1;
public AutoGappleModule() {
super("AutoGapple", new String[]{"Gapple", "AutoApple"}, "Automatically swaps & eats a (notch) apple when health is below the set threshold.", "NONE", -1, ModuleType.PLAYER);
}
@Override
public String getMetaData() {
return "" + this.getNotchAppleCount();
}
@Listener
public void onPlayerUpdate(EventPlayerUpdate event) {
if (event.getStage() != EventStageable.EventStage.PRE)
return;
final Minecraft mc = Minecraft.getMinecraft();
if (mc.player == null)
return;
if (mc.player.getHealth() < this.health.getValue() && mc.player.getAbsorptionAmount() == 0) {
this.notchAppleSlot = this.findNotchApple();
}
if (this.notchAppleSlot != -1) {
if (this.forcedSlot.getValue() != 45) { // we aren't trying to put it in the offhand
if (this.previousHeldItem == -1) {
this.previousHeldItem = mc.player.inventory.currentItem;
}
if (this.notchAppleSlot < 36) {
mc.playerController.windowClick(0, this.forcedSlot.getValue(), 0, ClickType.QUICK_MOVE, mc.player); // last hotbar slot
mc.playerController.windowClick(0, this.notchAppleSlot, 0, ClickType.PICKUP, mc.player);
mc.playerController.windowClick(0, this.forcedSlot.getValue(), 0, ClickType.PICKUP, mc.player);
mc.player.inventory.currentItem = this.forcedSlot.getValue() - 36;
} else {
mc.player.inventory.currentItem = this.notchAppleSlot - 36; // in the hotbar, so remove the inventory offset
}
} else { // we need this notch apple in the offhand
if (mc.player.getHeldItemOffhand().getItem() != Items.GOLDEN_APPLE) {
mc.playerController.windowClick(0, 45, 0, ClickType.QUICK_MOVE, mc.player); // offhand slot
mc.playerController.windowClick(0, this.notchAppleSlot, 0, ClickType.PICKUP, mc.player);
mc.playerController.windowClick(0, 45, 0, ClickType.PICKUP, mc.player);
}
}
if (mc.player.getHealth() >= this.health.getValue() && mc.player.getAbsorptionAmount() > 0) {
mc.gameSettings.keyBindUseItem.pressed = false;
if (this.previousHeldItem != -1) {
mc.player.inventory.currentItem = this.previousHeldItem;
}
this.notchAppleSlot = -1;
this.previousHeldItem = -1;
} else {
mc.gameSettings.keyBindUseItem.pressed = true;
}
}
}
private int findNotchApple() {
for (int slot = 44; slot > 8; slot--) {
ItemStack itemStack = Minecraft.getMinecraft().player.inventoryContainer.getSlot(slot).getStack();
if (itemStack.isEmpty() || itemStack.getItemDamage() == 0)
continue;
if (itemStack.getItem() == Items.GOLDEN_APPLE) {
return slot;
}
}
return -1;
}
private int getNotchAppleCount() {
int gapples = 0;
if (Minecraft.getMinecraft().player == null)
return gapples;
for (int i = 0; i < 45; i++) {
final ItemStack stack = Minecraft.getMinecraft().player.inventory.getStackInSlot(i);
if (stack.getItem() == Items.GOLDEN_APPLE && stack.getItemDamage() != 0) {
gapples += stack.getCount();
}
}
return gapples;
}
}

View File

@ -10,7 +10,6 @@ import net.minecraft.block.state.IBlockState;
import net.minecraft.client.Minecraft;
import net.minecraft.client.entity.EntityPlayerSP;
import net.minecraft.client.renderer.BufferBuilder;
import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.client.renderer.Tessellator;
import net.minecraft.client.renderer.vertex.DefaultVertexFormats;
import net.minecraft.entity.Entity;
@ -78,23 +77,19 @@ public final class ProjectilesModule extends Module {
final boolean bobbing = mc.gameSettings.viewBobbing;
mc.gameSettings.viewBobbing = false;
mc.entityRenderer.setupCameraTransform(event.getPartialTicks(), 0);
GlStateManager.pushMatrix();
GlStateManager.disableTexture2D();
GlStateManager.enableBlend();
GlStateManager.disableAlpha();
GlStateManager.tryBlendFuncSeparate(770, 771, 1, 0);
GlStateManager.shadeModel(GL_SMOOTH);
glLineWidth(width.getValue());
glEnable(GL_LINE_SMOOTH);
glHint(GL_LINE_SMOOTH_HINT, GL_NICEST);
GlStateManager.disableDepth();
glEnable(GL32.GL_DEPTH_CLAMP);
final Tessellator tessellator = Tessellator.getInstance();
final BufferBuilder bufferbuilder = tessellator.getBuffer();
RenderUtil.begin3D();
glLineWidth(width.getValue());
glEnable(GL32.GL_DEPTH_CLAMP);
while (!flightPoint.isEmpty()) {
bufferbuilder.begin(GL11.GL_LINE_STRIP, DefaultVertexFormats.POSITION_COLOR);
Vec3d head = flightPoint.poll();
if (head == null)
continue;
bufferbuilder.pos(head.x, head.y, head.z).color(red.getValue() / 255.0f, green.getValue() / 255.0f, blue.getValue() / 255.0f, alpha.getValue() / 255.0f).endVertex();
if (flightPoint.peek() != null) {
@ -104,15 +99,7 @@ public final class ProjectilesModule extends Module {
tessellator.draw();
}
GlStateManager.shadeModel(GL_FLAT);
glDisable(GL_LINE_SMOOTH);
GlStateManager.enableDepth();
glDisable(GL32.GL_DEPTH_CLAMP);
GlStateManager.disableBlend();
GlStateManager.enableAlpha();
GlStateManager.enableTexture2D();
GlStateManager.popMatrix();
mc.gameSettings.viewBobbing = bobbing;
mc.entityRenderer.setupCameraTransform(event.getPartialTicks(), 0);
@ -131,20 +118,19 @@ public final class ProjectilesModule extends Module {
}
} else if (hit.typeOfHit == RayTraceResult.Type.ENTITY && hit.entityHit != null) {
final AxisAlignedBB entityBB = hit.entityHit.getEntityBoundingBox();
if (entityBB != null) {
bb = new AxisAlignedBB(entityBB.minX - mc.getRenderManager().viewerPosX, entityBB.minY - mc.getRenderManager().viewerPosY, entityBB.minZ - mc.getRenderManager().viewerPosZ, entityBB.maxX - mc.getRenderManager().viewerPosX, entityBB.maxY - mc.getRenderManager().viewerPosY, entityBB.maxZ - mc.getRenderManager().viewerPosZ);
}
bb = new AxisAlignedBB(entityBB.minX - mc.getRenderManager().viewerPosX, entityBB.minY - mc.getRenderManager().viewerPosY, entityBB.minZ - mc.getRenderManager().viewerPosZ, entityBB.maxX - mc.getRenderManager().viewerPosX, entityBB.maxY - mc.getRenderManager().viewerPosY, entityBB.maxZ - mc.getRenderManager().viewerPosZ);
}
if (bb != null) {
RenderUtil.drawBoundingBox(bb, width.getValue(), red.getValue() / 255.0f, green.getValue() / 255.0f, blue.getValue() / 255.0f, alpha.getValue() / 255.0f);
}
}
RenderUtil.end3D();
}
private ThrowableType getTypeFromCurrentItem(EntityPlayerSP player) {
// Check if we're holding an item first
if (player.getHeldItemMainhand() == null) {
if (player.getHeldItemMainhand().isEmpty()) {
return ThrowableType.NONE;
}
@ -238,8 +224,8 @@ public final class ProjectilesModule extends Module {
* implementation resides in multiple classes but the parent of all
* of them is {@link net.minecraft.entity.projectile.EntityThrowable}
*/
final class FlightPath {
private EntityPlayerSP shooter;
private final class FlightPath {
private final EntityPlayerSP shooter;
private Vec3d position;
private Vec3d motion;
private float yaw;
@ -247,7 +233,7 @@ public final class ProjectilesModule extends Module {
private AxisAlignedBB boundingBox;
private boolean collided;
private RayTraceResult target;
private ThrowableType throwableType;
private final ThrowableType throwableType;
FlightPath(EntityPlayerSP player, ThrowableType throwableType) {
this.shooter = player;