Skip to content

Commit

Permalink
feat: Simplify target slot logic as well as changing it to support th…
Browse files Browse the repository at this point in the history
…e off-hand slot.

Fixes #738 #773
  • Loading branch information
Kamefrede committed Nov 7, 2023
1 parent 7681ac0 commit 4440374
Showing 1 changed file with 18 additions and 15 deletions.
33 changes: 18 additions & 15 deletions src/main/java/vazkii/psi/api/spell/SpellContext.java
Original file line number Diff line number Diff line change
Expand Up @@ -191,29 +191,32 @@ public void verifyEntity(Entity e) throws SpellRuntimeException {
}

public int getTargetSlot() throws SpellRuntimeException {
int slot;
int slot = targetSlot;
int cadSlot = PsiAPI.getPlayerCADSlot(caster);

if(cadSlot == -1) {
throw new SpellRuntimeException(SpellRuntimeException.NO_CAD);
}

if(customTargetSlot) {
return targetSlot % 36;
return targetSlot == 36 ? Inventory.SLOT_OFFHAND : targetSlot % 36;
}

if(shiftTargetSlot) {
int cadSlot = PsiAPI.getPlayerCADSlot(caster);
if(cadSlot == -1) {
throw new SpellRuntimeException(SpellRuntimeException.NO_CAD);
}

if(Inventory.isHotbarSlot(cadSlot)) {
slot = (cadSlot + targetSlot) % 9;
} else {
slot = (caster.getInventory().selected + targetSlot) % 9;
}
} else {
slot = (targetSlot - 1) % 9;
int originSlot = Inventory.isHotbarSlot(cadSlot) ? cadSlot : caster.getInventory().selected;

slot = originSlot + targetSlot;
}

if(slot == -1) {
return Inventory.SLOT_OFFHAND;
}

if(slot < 0) {
slot = 10 + slot;
}
return slot;

return slot % 9;
}

/**
Expand Down

0 comments on commit 4440374

Please sign in to comment.