Skip to content

Commit

Permalink
Fix a VM error when the getting a slot and the player is dead or if t…
Browse files Browse the repository at this point in the history
…he slot access is null/invalid
  • Loading branch information
UnlikePaladin committed Jan 24, 2024
1 parent 8af3544 commit 0a9da0a
Showing 1 changed file with 5 additions and 1 deletion.
Expand Up @@ -15,6 +15,7 @@
import net.minecraft.world.InteractionHand;
import net.minecraft.world.effect.MobEffectInstance;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.SlotAccess;
import net.minecraft.world.entity.player.Inventory;
import net.minecraft.world.inventory.Slot;
import net.minecraft.world.item.ItemStack;
Expand Down Expand Up @@ -334,7 +335,10 @@ public HostAPI swingArm(boolean offhand) {
public ItemStackAPI getSlot(@LuaNotNil Object slot) {
if (!isHost()) return null;
Entity e = this.owner.luaRuntime.getUser();
return ItemStackAPI.verify(e.getSlot(LuaUtils.parseSlot(slot, null)).get());
if (e == null || !e.isAlive())
return ItemStackAPI.verify(ItemStack.EMPTY);
SlotAccess slotAccess = e.getSlot(LuaUtils.parseSlot(slot, null));
return ItemStackAPI.verify(slotAccess.get());
}

@LuaWhitelist
Expand Down

0 comments on commit 0a9da0a

Please sign in to comment.