feat: allow AutoTool to be invoked from other mods
This commit is contained in:
parent
4dddbe5fba
commit
c13aa88bbd
1 changed files with 51 additions and 33 deletions
|
@ -37,19 +37,36 @@ public class AutoTool extends AbstractModule implements ICommons {
|
|||
&& item.getMaxDamage() - item.getDamageValue() <= this.limit.get();
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public void onClick(InputEvent.ClickInputEvent event) {
|
||||
if (MC.player == null) return;
|
||||
// TODO this is fired many times consecutively, can we filter out
|
||||
// some without putting a dumb time cooldown?;
|
||||
if (event.isAttack()) {
|
||||
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;
|
||||
switch (MC.hitResult.getType()) {
|
||||
case BLOCK:
|
||||
BlockRayTraceResult result = (BlockRayTraceResult) MC.hitResult;
|
||||
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++) {
|
||||
ItemStack item = hotbar.get(i).getItem();
|
||||
if (this.itemIsTooDamaged(item)) {
|
||||
|
@ -61,25 +78,26 @@ public class AutoTool extends AbstractModule implements ICommons {
|
|||
current_speed = speed;
|
||||
}
|
||||
}
|
||||
if (current_slot != MC.player.inventory.selected) {
|
||||
MC.player.inventory.selected = current_slot;
|
||||
MC.gameMode.ensureHasSentCarriedItem(); // ACCESSTRANSFORMER
|
||||
break;
|
||||
case ENTITY:
|
||||
double current_damage = 0.f;
|
||||
for (int i = 0; i < Inventory.HOTBAR_SIZE; i++) {
|
||||
ItemStack item = hotbar.get(i).getItem();
|
||||
if (this.itemIsTooDamaged(item)) {
|
||||
continue;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
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
|
||||
@SubscribeEvent
|
||||
public void onClick(InputEvent.ClickInputEvent event) {
|
||||
if (MC.player == null) return;
|
||||
// TODO this is fired many times consecutively, can we filter out
|
||||
// some without putting a dumb time cooldown?;
|
||||
if (event.isAttack()) {
|
||||
switch (MC.hitResult.getType()) {
|
||||
case BLOCK:
|
||||
selectBestTool();
|
||||
break;
|
||||
case ENTITY:
|
||||
selectBestWeapon();
|
||||
break;
|
||||
case MISS:
|
||||
break;
|
||||
|
|
Loading…
Reference in a new issue