mirror of
https://github.com/PaperMC/Paper.git
synced 2024-11-25 20:16:19 +01:00
51 lines
3.3 KiB
Diff
51 lines
3.3 KiB
Diff
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
From: William Blake Galbreath <blake.galbreath@gmail.com>
|
|
Date: Thu, 14 Oct 2021 12:09:39 -0500
|
|
Subject: [PATCH] Add ItemFactory#getSpawnEgg API
|
|
|
|
|
|
diff --git a/src/main/java/org/bukkit/craftbukkit/inventory/CraftItemFactory.java b/src/main/java/org/bukkit/craftbukkit/inventory/CraftItemFactory.java
|
|
index a96a09bb39fc35f3c4dfcd0da0ce1fe283b8377e..31a33e329ee06860f8845d201d32ee86a274a657 100644
|
|
--- a/src/main/java/org/bukkit/craftbukkit/inventory/CraftItemFactory.java
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/inventory/CraftItemFactory.java
|
|
@@ -590,4 +590,19 @@ public final class CraftItemFactory implements ItemFactory {
|
|
new net.md_5.bungee.api.chat.TextComponent(customName));
|
|
}
|
|
// Paper end - bungee hover events
|
|
+
|
|
+ // Paper start - old getSpawnEgg API
|
|
+ // @Override // used to override, upstream added conflicting method, is called via Commodore now
|
|
+ @Deprecated
|
|
+ public ItemStack getSpawnEgg0(org.bukkit.entity.EntityType type) {
|
|
+ if (type == null) {
|
|
+ return null;
|
|
+ }
|
|
+ String typeId = type.getKey().toString();
|
|
+ net.minecraft.resources.ResourceLocation typeKey = new net.minecraft.resources.ResourceLocation(typeId);
|
|
+ net.minecraft.world.entity.EntityType<?> nmsType = net.minecraft.core.registries.BuiltInRegistries.ENTITY_TYPE.get(typeKey);
|
|
+ net.minecraft.world.item.SpawnEggItem eggItem = net.minecraft.world.item.SpawnEggItem.byId(nmsType);
|
|
+ return eggItem == null ? null : new net.minecraft.world.item.ItemStack(eggItem).asBukkitMirror();
|
|
+ }
|
|
+ // Paper end - old getSpawnEgg API
|
|
}
|
|
diff --git a/src/main/java/org/bukkit/craftbukkit/util/Commodore.java b/src/main/java/org/bukkit/craftbukkit/util/Commodore.java
|
|
index 9d8adc5e281decd61fb3a8cfd78531b0b374e29c..0d5ce79dc8fb3b1677e09d663608a5cb5224de2f 100644
|
|
--- a/src/main/java/org/bukkit/craftbukkit/util/Commodore.java
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/util/Commodore.java
|
|
@@ -391,6 +391,15 @@ public class Commodore {
|
|
}
|
|
// Paper end
|
|
|
|
+ // Paper start - ItemFactory#getSpawnEgg (paper had original method that returned ItemStack, upstream added identical but returned Material)
|
|
+ if (owner.equals("org/bukkit/inventory/ItemFactory") && name.equals("getSpawnEgg") && desc.equals("(Lorg/bukkit/entity/EntityType;)Lorg/bukkit/inventory/ItemStack;")) {
|
|
+ super.visitInsn(Opcodes.SWAP); // has 1 param, this moves the owner instance to the top for the checkcast
|
|
+ super.visitTypeInsn(Opcodes.CHECKCAST, runtimeCbPkgPrefix() + "inventory/CraftItemFactory");
|
|
+ super.visitInsn(Opcodes.SWAP); // moves param back to the the top of stack
|
|
+ super.visitMethodInsn(Opcodes.INVOKEVIRTUAL, runtimeCbPkgPrefix() + "inventory/CraftItemFactory", "getSpawnEgg0", desc, false);
|
|
+ return;
|
|
+ }
|
|
+ // Paper end - ItemFactory#getSpawnEgg
|
|
if (modern) {
|
|
if (owner.equals("org/bukkit/Material") || (instantiatedMethodType != null && instantiatedMethodType.getDescriptor().startsWith("(Lorg/bukkit/Material;)"))) {
|
|
switch (name) {
|