Skip to content

Commit

Permalink
I believe this is a better fix for Cannot copy null stack in Bukkit.
Browse files Browse the repository at this point in the history
Signed-off-by: 秋雨落 <i@rain.cx>
  • Loading branch information
qyl27 committed Nov 17, 2024
1 parent 4b290e2 commit 0490af1
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package io.izzel.arclight.common.mixin.bukkit.inventory;

import net.minecraft.world.item.ItemStack;
import org.bukkit.craftbukkit.v.inventory.CraftItemStack;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Redirect;

@Mixin(CraftItemStack.class)
public abstract class CraftItemStackMixin {
@Redirect(method = "asCraftMirror", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/item/ItemStack;isEmpty()Z"))
private static boolean arclight$asCraftMirror$ItemStack$isEmpty(ItemStack instance) {
return false;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
"Registry_SimpleRegistryMixin",
"StandardMessengerMixin",
"WatchdogThreadMixin",
"inventory.CraftItemStackMixin",
"util.BlockStateListPopulatorMixin",
"util.DelegatedGeneratorAccessMixin",
"util.DummyGeneratorAccessMixin"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,6 @@ public abstract class ItemStackMixin_NeoForge implements ItemStackBridge, IItemS
@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 {
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 Down

0 comments on commit 0490af1

Please sign in to comment.