feat: allow AutoTool to be invoked from other mods

This commit is contained in:
əlemi 2023-03-04 01:24:39 +01:00
parent 4dddbe5fba
commit c13aa88bbd
Signed by: alemi
GPG key ID: A4895B84D311642C

View file

@ -37,19 +37,36 @@ public class AutoTool extends AbstractModule implements ICommons {
&& item.getMaxDamage() - item.getDamageValue() <= this.limit.get(); && item.getMaxDamage() - item.getDamageValue() <= this.limit.get();
} }
@SubscribeEvent public boolean selectBestWeapon() {
public void onClick(InputEvent.ClickInputEvent event) { List<Slot> hotbar = Inventory.hotbar(MC.player);
if (MC.player == null) return; int current_slot = MC.player.inventory.selected;
// TODO this is fired many times consecutively, can we filter out double current_damage = Inventory.itemDPS(hotbar.get(current_slot).getItem());
// some without putting a dumb time cooldown?; for (int i = 0; i < Inventory.HOTBAR_SIZE; i++) {
if (event.isAttack()) { ItemStack item = hotbar.get(i).getItem();
if (this.itemIsTooDamaged(item)) {
continue;
}
double damage = Inventory.itemDPS(item);
if (damage > current_damage) {
current_slot = i;
current_damage = damage;
}
}
if (current_slot != MC.player.inventory.selected) {
MC.player.inventory.selected = current_slot;
MC.gameMode.ensureHasSentCarriedItem(); // ACCESSTRANSFORMER
return true;
}
return false;
}
public boolean selectBestTool() {
List<Slot> hotbar = Inventory.hotbar(MC.player); List<Slot> hotbar = Inventory.hotbar(MC.player);
int current_slot = MC.player.inventory.selected; int current_slot = MC.player.inventory.selected;
switch (MC.hitResult.getType()) {
case BLOCK:
BlockRayTraceResult result = (BlockRayTraceResult) MC.hitResult; BlockRayTraceResult result = (BlockRayTraceResult) MC.hitResult;
BlockState state = MC.level.getBlockState(result.getBlockPos()); BlockState state = MC.level.getBlockState(result.getBlockPos());
float current_speed = 0.f; float current_speed = hotbar.get(current_slot).getItem().getDestroySpeed(state);
for (int i = 0; i < Inventory.HOTBAR_SIZE; i++) { for (int i = 0; i < Inventory.HOTBAR_SIZE; i++) {
ItemStack item = hotbar.get(i).getItem(); ItemStack item = hotbar.get(i).getItem();
if (this.itemIsTooDamaged(item)) { if (this.itemIsTooDamaged(item)) {
@ -61,25 +78,26 @@ public class AutoTool extends AbstractModule implements ICommons {
current_speed = speed; current_speed = speed;
} }
} }
if (current_slot != MC.player.inventory.selected) {
MC.player.inventory.selected = current_slot; MC.player.inventory.selected = current_slot;
MC.gameMode.ensureHasSentCarriedItem(); // ACCESSTRANSFORMER MC.gameMode.ensureHasSentCarriedItem(); // ACCESSTRANSFORMER
break; return true;
case ENTITY: }
double current_damage = 0.f; return false;
for (int i = 0; i < Inventory.HOTBAR_SIZE; i++) {
ItemStack item = hotbar.get(i).getItem();
if (this.itemIsTooDamaged(item)) {
continue;
} }
double damage = Inventory.itemDamage(item); @SubscribeEvent
if (damage > current_damage) { public void onClick(InputEvent.ClickInputEvent event) {
current_slot = i; if (MC.player == null) return;
current_damage = damage; // TODO this is fired many times consecutively, can we filter out
} // some without putting a dumb time cooldown?;
} if (event.isAttack()) {
MC.player.inventory.selected = current_slot; switch (MC.hitResult.getType()) {
MC.gameMode.ensureHasSentCarriedItem(); // ACCESSTRANSFORMER case BLOCK:
selectBestTool();
break;
case ENTITY:
selectBestWeapon();
break; break;
case MISS: case MISS:
break; break;