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