mirror of
https://github.com/PaperMC/Paper.git
synced 2025-01-02 17:32:03 +01:00
Add ItemFactory#getSpawnEgg API
This commit is contained in:
parent
864494345a
commit
b530d53b66
2 changed files with 25 additions and 0 deletions
|
@ -9,6 +9,7 @@ import net.minecraft.core.HolderSet;
|
||||||
import net.minecraft.core.RegistryAccess;
|
import net.minecraft.core.RegistryAccess;
|
||||||
import net.minecraft.core.component.DataComponentPatch;
|
import net.minecraft.core.component.DataComponentPatch;
|
||||||
import net.minecraft.core.registries.Registries;
|
import net.minecraft.core.registries.Registries;
|
||||||
|
import net.minecraft.resources.ResourceLocation;
|
||||||
import net.minecraft.server.MinecraftServer;
|
import net.minecraft.server.MinecraftServer;
|
||||||
import net.minecraft.tags.EnchantmentTags;
|
import net.minecraft.tags.EnchantmentTags;
|
||||||
import net.minecraft.util.RandomSource;
|
import net.minecraft.util.RandomSource;
|
||||||
|
@ -291,4 +292,19 @@ public final class CraftItemFactory implements ItemFactory {
|
||||||
new net.md_5.bungee.api.chat.TextComponent(customName));
|
new net.md_5.bungee.api.chat.TextComponent(customName));
|
||||||
}
|
}
|
||||||
// Paper end - bungee hover events
|
// 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 = ResourceLocation.parse(typeId);
|
||||||
|
net.minecraft.world.entity.EntityType<?> nmsType = net.minecraft.core.registries.BuiltInRegistries.ENTITY_TYPE.getValue(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
|
||||||
}
|
}
|
||||||
|
|
|
@ -465,6 +465,15 @@ public class Commodore {
|
||||||
}
|
}
|
||||||
// Paper end
|
// 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 (modern) {
|
||||||
if (owner.equals("org/bukkit/Material") || (instantiatedMethodType != null && instantiatedMethodType.getDescriptor().startsWith("(Lorg/bukkit/Material;)"))) {
|
if (owner.equals("org/bukkit/Material") || (instantiatedMethodType != null && instantiatedMethodType.getDescriptor().startsWith("(Lorg/bukkit/Material;)"))) {
|
||||||
switch (name) {
|
switch (name) {
|
||||||
|
|
Loading…
Reference in a new issue