parent
8982e79ba6
commit
d22c78f007
@ -2,15 +2,11 @@ package io.izzel.arclight.common.mixin.bukkit;
|
|||||||
|
|
||||||
import io.izzel.arclight.common.bridge.bukkit.CraftItemStackBridge;
|
import io.izzel.arclight.common.bridge.bukkit.CraftItemStackBridge;
|
||||||
import io.izzel.arclight.common.bridge.bukkit.ItemMetaBridge;
|
import io.izzel.arclight.common.bridge.bukkit.ItemMetaBridge;
|
||||||
import io.izzel.arclight.common.bridge.bukkit.MaterialBridge;
|
|
||||||
import io.izzel.arclight.common.bridge.item.ItemStackBridge;
|
import io.izzel.arclight.common.bridge.item.ItemStackBridge;
|
||||||
import io.izzel.arclight.i18n.conf.MaterialPropertySpec;
|
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
import net.minecraft.nbt.CompoundNBT;
|
import net.minecraft.nbt.CompoundNBT;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.craftbukkit.v.inventory.CraftItemFactory;
|
|
||||||
import org.bukkit.craftbukkit.v.inventory.CraftItemStack;
|
import org.bukkit.craftbukkit.v.inventory.CraftItemStack;
|
||||||
import org.bukkit.craftbukkit.v.inventory.CraftMetaItem;
|
|
||||||
import org.bukkit.craftbukkit.v.legacy.CraftLegacy;
|
import org.bukkit.craftbukkit.v.legacy.CraftLegacy;
|
||||||
import org.bukkit.inventory.meta.ItemMeta;
|
import org.bukkit.inventory.meta.ItemMeta;
|
||||||
import org.spongepowered.asm.mixin.Mixin;
|
import org.spongepowered.asm.mixin.Mixin;
|
||||||
@ -26,34 +22,20 @@ import java.util.Objects;
|
|||||||
public abstract class CraftItemStackMixin implements CraftItemStackBridge {
|
public abstract class CraftItemStackMixin implements CraftItemStackBridge {
|
||||||
|
|
||||||
// @formatter:off
|
// @formatter:off
|
||||||
@Shadow static Material getType(ItemStack item) { return null; }
|
|
||||||
@Shadow static boolean hasItemMeta(ItemStack item) { return false; }
|
|
||||||
@Shadow ItemStack handle;
|
@Shadow ItemStack handle;
|
||||||
@Shadow public abstract Material getType();
|
@Shadow public abstract Material getType();
|
||||||
@Shadow public abstract short getDurability();
|
@Shadow public abstract short getDurability();
|
||||||
@Shadow public abstract boolean hasItemMeta();
|
@Shadow public abstract boolean hasItemMeta();
|
||||||
// @formatter:on
|
// @formatter:on
|
||||||
|
|
||||||
@Inject(method = "getItemMeta(Lnet/minecraft/item/ItemStack;)Lorg/bukkit/inventory/meta/ItemMeta;",
|
@Inject(method = "getItemMeta(Lnet/minecraft/item/ItemStack;)Lorg/bukkit/inventory/meta/ItemMeta;", at = @At("RETURN"))
|
||||||
cancellable = true, at = @At("HEAD"))
|
|
||||||
private static void arclight$offerCaps(ItemStack item, CallbackInfoReturnable<ItemMeta> cir) {
|
private static void arclight$offerCaps(ItemStack item, CallbackInfoReturnable<ItemMeta> cir) {
|
||||||
Material type = getType(item);
|
ItemMeta meta = cir.getReturnValue();
|
||||||
if (((MaterialBridge) (Object) type).bridge$getType() != MaterialPropertySpec.MaterialType.VANILLA) {
|
|
||||||
if (hasItemMeta(item)) {
|
|
||||||
CompoundNBT tag = item.getTag();
|
CompoundNBT tag = item.getTag();
|
||||||
CraftMetaItem metaItem;
|
|
||||||
if (tag != null) {
|
if (tag != null) {
|
||||||
metaItem = new CraftMetaItem(tag);
|
((ItemMetaBridge) meta).bridge$offerUnhandledTags(tag);
|
||||||
((ItemMetaBridge) metaItem).bridge$offerUnhandledTags(tag);
|
|
||||||
} else {
|
|
||||||
metaItem = new CraftMetaItem(new CompoundNBT());
|
|
||||||
}
|
|
||||||
((ItemMetaBridge) metaItem).bridge$setForgeCaps(((ItemStackBridge) (Object) item).bridge$getForgeCaps());
|
|
||||||
cir.setReturnValue(metaItem);
|
|
||||||
} else {
|
|
||||||
cir.setReturnValue(CraftItemFactory.instance().getItemMeta(getType(item)));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
((ItemMetaBridge) meta).bridge$setForgeCaps(((ItemStackBridge) (Object) item).bridge$getForgeCaps());
|
||||||
}
|
}
|
||||||
|
|
||||||
// check when update
|
// check when update
|
||||||
|
|||||||
@ -59,6 +59,12 @@ public class CraftMetaItemMixin implements ItemMetaBridge {
|
|||||||
"LodestonePos",
|
"LodestonePos",
|
||||||
"LodestoneTracked"
|
"LodestoneTracked"
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ModifyVariable(method = "<init>(Lnet/minecraft/nbt/CompoundNBT;)V", at = @At(value = "INVOKE", target = "Lorg/bukkit/UnsafeValues;getDataVersion()I"))
|
||||||
|
private CompoundNBT arclight$provideTag(CompoundNBT tag) {
|
||||||
|
return tag == null ? new CompoundNBT() : tag;
|
||||||
|
}
|
||||||
|
|
||||||
private CompoundNBT forgeCaps;
|
private CompoundNBT forgeCaps;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user