2021-10-20 23:35:52 +02:00
|
|
|
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
|
2022-11-20 00:53:20 +01:00
|
|
|
Subject: [PATCH] Add ItemFactory#getSpawnEgg API
|
2021-10-20 23:35:52 +02:00
|
|
|
|
|
|
|
|
|
|
|
diff --git a/src/main/java/org/bukkit/craftbukkit/inventory/CraftItemFactory.java b/src/main/java/org/bukkit/craftbukkit/inventory/CraftItemFactory.java
|
2024-10-25 13:52:04 +02:00
|
|
|
index cab7a3d21699605cb7fc480830d7529f70e69e88..ad86ee4372e55c82968fd4fc6a65debab0092028 100644
|
2021-10-20 23:35:52 +02:00
|
|
|
--- a/src/main/java/org/bukkit/craftbukkit/inventory/CraftItemFactory.java
|
|
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/inventory/CraftItemFactory.java
|
2024-06-14 14:11:52 +02:00
|
|
|
@@ -9,6 +9,7 @@ import net.minecraft.core.HolderSet;
|
|
|
|
import net.minecraft.core.RegistryAccess;
|
|
|
|
import net.minecraft.core.component.DataComponentPatch;
|
|
|
|
import net.minecraft.core.registries.Registries;
|
|
|
|
+import net.minecraft.resources.ResourceLocation;
|
|
|
|
import net.minecraft.server.MinecraftServer;
|
|
|
|
import net.minecraft.tags.EnchantmentTags;
|
|
|
|
import net.minecraft.util.RandomSource;
|
2024-10-23 21:43:06 +02:00
|
|
|
@@ -289,4 +290,19 @@ public final class CraftItemFactory implements ItemFactory {
|
2021-10-20 23:35:52 +02:00
|
|
|
new net.md_5.bungee.api.chat.TextComponent(customName));
|
|
|
|
}
|
2023-08-06 02:21:59 +02:00
|
|
|
// Paper end - bungee hover events
|
2021-10-20 23:35:52 +02:00
|
|
|
+
|
2023-08-06 02:21:59 +02:00
|
|
|
+ // 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) {
|
2021-10-20 23:35:52 +02:00
|
|
|
+ if (type == null) {
|
|
|
|
+ return null;
|
|
|
|
+ }
|
|
|
|
+ String typeId = type.getKey().toString();
|
2024-06-14 14:11:52 +02:00
|
|
|
+ net.minecraft.resources.ResourceLocation typeKey = ResourceLocation.parse(typeId);
|
2024-10-25 13:52:04 +02:00
|
|
|
+ net.minecraft.world.entity.EntityType<?> nmsType = net.minecraft.core.registries.BuiltInRegistries.ENTITY_TYPE.getValue(typeKey);
|
2022-11-20 00:53:20 +01:00
|
|
|
+ net.minecraft.world.item.SpawnEggItem eggItem = net.minecraft.world.item.SpawnEggItem.byId(nmsType);
|
2021-10-20 23:35:52 +02:00
|
|
|
+ return eggItem == null ? null : new net.minecraft.world.item.ItemStack(eggItem).asBukkitMirror();
|
|
|
|
+ }
|
2024-01-19 12:30:04 +01:00
|
|
|
+ // Paper end - old getSpawnEgg API
|
2021-10-20 23:35:52 +02:00
|
|
|
}
|
2023-08-06 02:21:59 +02:00
|
|
|
diff --git a/src/main/java/org/bukkit/craftbukkit/util/Commodore.java b/src/main/java/org/bukkit/craftbukkit/util/Commodore.java
|
2024-10-31 23:44:34 +01:00
|
|
|
index 1f25fa2b2ce8fae5bce29232cbb51966b86dae85..f10e7a847e9f57d2a987b118215c0ceab251a5b0 100644
|
2023-08-06 02:21:59 +02:00
|
|
|
--- a/src/main/java/org/bukkit/craftbukkit/util/Commodore.java
|
|
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/util/Commodore.java
|
2024-10-31 23:44:34 +01:00
|
|
|
@@ -463,6 +463,15 @@ public class Commodore {
|
2023-08-06 02:21:59 +02:00
|
|
|
}
|
|
|
|
// Paper end
|
2024-01-14 10:46:04 +01:00
|
|
|
|
2023-08-06 02:21:59 +02:00
|
|
|
+ // 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
|
2024-04-25 20:16:53 +02:00
|
|
|
+ super.visitTypeInsn(Opcodes.CHECKCAST, runtimeCbPkgPrefix() + "inventory/CraftItemFactory");
|
2023-08-06 02:21:59 +02:00
|
|
|
+ super.visitInsn(Opcodes.SWAP); // moves param back to the the top of stack
|
2024-04-25 20:16:53 +02:00
|
|
|
+ super.visitMethodInsn(Opcodes.INVOKEVIRTUAL, runtimeCbPkgPrefix() + "inventory/CraftItemFactory", "getSpawnEgg0", desc, false);
|
2023-08-06 02:21:59 +02:00
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+ // Paper end - ItemFactory#getSpawnEgg
|
2024-01-14 10:46:04 +01:00
|
|
|
if (modern) {
|
|
|
|
if (owner.equals("org/bukkit/Material") || (instantiatedMethodType != null && instantiatedMethodType.getDescriptor().startsWith("(Lorg/bukkit/Material;)"))) {
|
|
|
|
switch (name) {
|