fixed environmental eye working in the whole inventory

closes #311
This commit is contained in:
Ell 2023-09-19 22:54:09 +02:00
parent 01813ed372
commit f831d48bba
4 changed files with 11 additions and 7 deletions

View file

@ -309,13 +309,14 @@ public final class Helper {
}
}
public static ItemStack getEquippedItem(Predicate<ItemStack> predicate, Player player) {
public static ItemStack getEquippedItem(Predicate<ItemStack> predicate, Player player, boolean hotbarOnly) {
if (Compat.hasCompat("curios")) {
var stack = CuriosApi.getCuriosHelper().findFirstCurio(player, predicate).map(SlotResult::stack);
if (stack.isPresent())
return stack.get();
}
for (var i = 0; i < player.getInventory().getContainerSize(); i++) {
var invSize = hotbarOnly ? 9 : player.getInventory().getContainerSize();
for (var i = 0; i < invSize; i++) {
var slot = player.getInventory().getItem(i);
if (!slot.isEmpty() && predicate.test(slot))
return slot;

View file

@ -37,7 +37,7 @@ public class InternalHooks implements NaturesAuraAPI.IInternalHooks {
private boolean auraPlayerInteraction(Player player, int amount, boolean extract, boolean simulate) {
if (extract && player.isCreative())
return true;
var stack = Helper.getEquippedItem(s -> s.getCapability(NaturesAuraAPI.CAP_AURA_CONTAINER).isPresent(), player);
var stack = Helper.getEquippedItem(s -> s.getCapability(NaturesAuraAPI.CAP_AURA_CONTAINER).isPresent(), player, false);
if (!stack.isEmpty()) {
var container = stack.getCapability(NaturesAuraAPI.CAP_AURA_CONTAINER).orElse(null);
if (extract) {
@ -181,4 +181,5 @@ public class InternalHooks implements NaturesAuraAPI.IInternalHooks {
highest = defaultSpot;
return highest;
}
}

View file

@ -153,9 +153,9 @@ public class ClientEvents {
inst.setParticleSpawnRange(32);
}
ClientEvents.heldCache = Helper.getEquippedItem(s -> s.getItem() instanceof ItemAuraCache, mc.player);
ClientEvents.heldEye = Helper.getEquippedItem(s -> s.getItem() == ModItems.EYE, mc.player);
ClientEvents.heldOcular = Helper.getEquippedItem(s -> s.getItem() == ModItems.EYE_IMPROVED, mc.player);
ClientEvents.heldCache = Helper.getEquippedItem(s -> s.getItem() instanceof ItemAuraCache, mc.player, false);
ClientEvents.heldEye = Helper.getEquippedItem(s -> s.getItem() == ModItems.EYE, mc.player, true);
ClientEvents.heldOcular = Helper.getEquippedItem(s -> s.getItem() == ModItems.EYE_IMPROVED, mc.player, false);
if (!ClientEvents.heldOcular.isEmpty() && mc.level.getGameTime() % 20 == 0) {
ClientEvents.SHOWING_EFFECTS.clear();

View file

@ -24,7 +24,7 @@ public class ItemDeathRing extends ItemImpl {
public void onDeath(LivingDeathEvent event) {
var entity = event.getEntity();
if (!entity.level().isClientSide && entity instanceof Player) {
var equipped = Helper.getEquippedItem(s -> s.getItem() == ModItems.DEATH_RING, (Player) entity);
var equipped = Helper.getEquippedItem(s -> s.getItem() == ModItems.DEATH_RING, (Player) entity, false);
if (!equipped.isEmpty()) {
entity.setHealth(entity.getMaxHealth() / 2);
entity.removeAllEffects();
@ -39,5 +39,7 @@ public class ItemDeathRing extends ItemImpl {
}
}
}
}
}