Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix IllegalArgumentException: Cannot copy null stack in ItemStackMixin_NeoForge #1550

Merged
merged 7 commits into from
Nov 16, 2024
Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
import net.minecraft.world.item.context.UseOnContext;
import net.minecraft.world.level.LevelReader;
import net.neoforged.neoforge.common.extensions.IItemStackExtension;
import org.bukkit.craftbukkit.v.event.CraftEventFactory;
import org.bukkit.craftbukkit.v.inventory.CraftItemStack;
import org.bukkit.craftbukkit.v1_21_R1.event.CraftEventFactory;
import org.bukkit.craftbukkit.v1_21_R1.inventory.CraftItemStack;
import org.bukkit.event.player.PlayerItemDamageEvent;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Mutable;
Expand All @@ -32,14 +32,20 @@
@Mixin(ItemStack.class)
public abstract class ItemStackMixin_NeoForge implements ItemStackBridge, IItemStackExtension {

// @formatter:off
// @formatter:off
@Mutable @Shadow @Deprecated @Nullable private Item item;
@Shadow private int count;
// @formatter:on

@Decorate(method = "hurtAndBreak(ILnet/minecraft/server/level/ServerLevel;Lnet/minecraft/world/entity/LivingEntity;Ljava/util/function/Consumer;)V",
at = @At(value = "INVOKE", target = "Lnet/minecraft/world/item/enchantment/EnchantmentHelper;processDurabilityChange(Lnet/minecraft/server/level/ServerLevel;Lnet/minecraft/world/item/ItemStack;I)I"))

@Decorate(method = "hurtAndBreak(ILnet/minecraft/server/level/ServerLevel;Lnet/minecraft/world/entity.LivingEntity;Ljava/util.function.Consumer;)V",
at = @At(value = "INVOKE", target = "Lnet/minecraft/world/item/enchantment/EnchantmentHelper.processDurabilityChange(Lnet/minecraft/server/level/ServerLevel;Lnet/minecraft/world/item.ItemStack;I)I"))
private int arclight$itemDamage(ServerLevel serverLevel, ItemStack itemStack, int i, @Local(ordinal = 0) LivingEntity damager) throws Throwable {
// Ensure the itemStack is not null
if (itemStack == null) {
itemStack = ItemStack.EMPTY;
}

int result = (int) DecorationOps.callsite().invoke(serverLevel, itemStack, i);
if (damager instanceof ServerPlayer) {
PlayerItemDamageEvent event = new PlayerItemDamageEvent(((ServerPlayerEntityBridge) damager).bridge$getBukkitEntity(), CraftItemStack.asCraftMirror((ItemStack) (Object) this), result);
Expand All @@ -56,10 +62,11 @@ public abstract class ItemStackMixin_NeoForge implements ItemStackBridge, IItemS
return result;
}

@Inject(method = "hurtAndBreak(ILnet/minecraft/server/level/ServerLevel;Lnet/minecraft/world/entity/LivingEntity;Ljava/util/function/Consumer;)V", at = @At(value = "INVOKE", target = "Ljava/util/function/Consumer;accept(Ljava/lang/Object;)V"))
private void arclight$itemBreak(int amount, ServerLevel level, @org.jetbrains.annotations.Nullable LivingEntity livingEntity, Consumer<Item> onBroken, CallbackInfo ci) {
@Inject(method = "hurtAndBreak(ILnet/minecraft/server/level/ServerLevel;Lnet/minecraft/world/entity.LivingEntity;Ljava/util.function/Consumer;)V",
at = @At(value = "INVOKE", target = "Ljava/util.function.Consumer.accept(Ljava.lang.Object;)V"))
private void arclight$itemBreak(int amount, ServerLevel level, @Nullable LivingEntity livingEntity, Consumer<Item> onBroken, CallbackInfo ci) {
if (this.count == 1 && livingEntity instanceof ServerPlayer serverPlayer) {
CraftEventFactory.callPlayerItemBreakEvent(serverPlayer, (ItemStack) (Object) this);
CraftEventFactory.callPlayerItemBreakEvent(serverPlayer, CraftItemStack.asCraftMirror((ItemStack) (Object) this));
}
}

Expand Down
Loading