AutoWither: Metadata now shows how many buildable withers

This commit is contained in:
noil 2021-01-09 00:34:14 -05:00
parent 284bfb3722
commit 1457c83cfa
2 changed files with 65 additions and 3 deletions

View File

@ -1,7 +1,10 @@
package me.rigamortis.seppuku.api.util;
import net.minecraft.block.Block;
import net.minecraft.client.Minecraft;
import net.minecraft.item.Item;
import net.minecraft.item.ItemBlock;
import net.minecraft.item.ItemStack;
/**
* @author noil
@ -13,7 +16,7 @@ public final class InventoryUtil {
public static boolean hasItem(Item input) {
for (int i = 0; i < 36; i++) {
Item item = mc.player.inventory.getStackInSlot(i).getItem();
final Item item = mc.player.inventory.getStackInSlot(i).getItem();
if (item == input) {
return true;
}
@ -25,7 +28,7 @@ public final class InventoryUtil {
public static int getItemCount(Item input) {
int items = 0;
for (int i = 0; i < 45; i++) {
Item item = mc.player.inventory.getStackInSlot(i).getItem();
final Item item = mc.player.inventory.getStackInSlot(i).getItem();
if (item == input) {
items += 1;
}
@ -34,9 +37,24 @@ public final class InventoryUtil {
return items;
}
public static int getBlockCount(Block input) {
int blocks = 0;
for (int i = 0; i < 45; i++) {
final ItemStack itemStack = mc.player.inventory.getStackInSlot(i);
if (itemStack.getItem() instanceof ItemBlock) {
final ItemBlock itemBlock = (ItemBlock) itemStack.getItem();
if (itemBlock.getBlock() == input) {
blocks += itemStack.getCount();
}
}
}
return blocks;
}
public static int getSlotForItem(Item input) {
for (int i = 0; i < 36; i++) {
Item item = mc.player.inventory.getStackInSlot(i).getItem();
final Item item = mc.player.inventory.getStackInSlot(i).getItem();
if (item == input) {
return i;
}

View File

@ -9,6 +9,7 @@ import me.rigamortis.seppuku.api.event.world.EventLoadWorld;
import me.rigamortis.seppuku.api.module.Module;
import me.rigamortis.seppuku.api.task.hand.HandSwapContext;
import me.rigamortis.seppuku.api.task.rotation.RotationTask;
import me.rigamortis.seppuku.api.util.InventoryUtil;
import me.rigamortis.seppuku.api.util.MathUtil;
import me.rigamortis.seppuku.api.util.Timer;
import me.rigamortis.seppuku.api.value.Value;
@ -63,6 +64,11 @@ public final class AutoWitherModule extends Module {
Seppuku.INSTANCE.getRotationManager().finishTask(this.rotationTask);
}
@Override
public String getMetaData() {
return "" + this.buildableWithers();
}
@Listener
public void onRightClickBlock(EventRightClickBlock event) {
if (mc.world != null && event.getPos() != null) {
@ -226,6 +232,44 @@ public final class AutoWitherModule extends Module {
return -1;
}
private int getWitherSkullCount() {
int skulls = 0;
for (int i = 0; i < 45; i++) {
final ItemStack itemStack = mc.player.inventory.getStackInSlot(i);
if (itemStack.getItem() instanceof ItemSkull) {
if (itemStack.getMetadata() == 1) {
skulls += itemStack.getCount();
}
}
}
return skulls;
}
private int buildableWithers() {
int buildable = 0;
if (mc.player == null || mc.world == null)
return buildable;
final int soulSand = InventoryUtil.getBlockCount(Blocks.SOUL_SAND);
final int skulls = this.getWitherSkullCount();
if (soulSand >= 4 && skulls >= 3) {
final int soulSandDivided = soulSand / 4;
final int skullsDivided = skulls / 3;
if (skullsDivided < soulSandDivided)
return skullsDivided;
else if (soulSandDivided < skullsDivided)
return soulSandDivided;
else
return 1;
}
return buildable;
}
private boolean valid(BlockPos pos, boolean isSkull) {
// There are no entities colliding with block placement
if (!mc.world.checkNoEntityCollision(new AxisAlignedBB(pos)))