Update upstream
This commit is contained in:
76
patches/removed/server/0007-Expose-EntityType-Ordinals.patch
Normal file
76
patches/removed/server/0007-Expose-EntityType-Ordinals.patch
Normal file
@@ -0,0 +1,76 @@
|
||||
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
||||
From: lexikiq <noellekiq@gmail.com>
|
||||
Date: Sun, 20 Jun 2021 23:15:44 -0400
|
||||
Subject: [PATCH] Expose EntityType Ordinals
|
||||
|
||||
|
||||
diff --git a/src/main/java/net/minecraft/world/entity/EntityType.java b/src/main/java/net/minecraft/world/entity/EntityType.java
|
||||
index ceacc0d383e2ee674783d3c0a7df0a951595faca..72b5ce4c93c021ca2f3f1d65b45fdd8cd50d71f4 100644
|
||||
--- a/src/main/java/net/minecraft/world/entity/EntityType.java
|
||||
+++ b/src/main/java/net/minecraft/world/entity/EntityType.java
|
||||
@@ -162,6 +162,8 @@ import org.slf4j.Logger;
|
||||
|
||||
public class EntityType<T extends Entity> implements FeatureElement, EntityTypeTest<Entity, T> {
|
||||
|
||||
+ private static int ordinal = 0; // Parchment
|
||||
+ private static final java.util.Map<EntityType, Integer> ordinals = new java.util.HashMap<>(); // Parchment
|
||||
private static final Logger LOGGER = LogUtils.getLogger();
|
||||
public static final String ENTITY_TAG = "EntityTag";
|
||||
private final Holder.Reference<EntityType<?>> builtInRegistryHolder;
|
||||
@@ -310,9 +312,32 @@ public class EntityType<T extends Entity> implements FeatureElement, EntityTypeT
|
||||
private final FeatureFlagSet requiredFeatures;
|
||||
|
||||
private static <T extends Entity> EntityType<T> register(String id, EntityType.Builder type) { // CraftBukkit - decompile error
|
||||
- return (EntityType) Registry.register(BuiltInRegistries.ENTITY_TYPE, id, (EntityType<T>) type.build(id)); // CraftBukkit - decompile error
|
||||
+ // return (EntityType) Registry.register(BuiltInRegistries.ENTITY_TYPE, id, (EntityType<T>) type.build(id)); // CraftBukkit - decompile error
|
||||
+ // Parchment start
|
||||
+ EntityType build = type.build(id);
|
||||
+ ordinals.put(build, ordinal);
|
||||
+ ordinal += 1;
|
||||
+ return (EntityType) Registry.register(BuiltInRegistries.ENTITY_TYPE, id, (EntityType<T>) build);
|
||||
}
|
||||
|
||||
+ public int ordinal() {
|
||||
+ return ordinals.get(this); // CraftBukkit - decompile error
|
||||
+ }
|
||||
+
|
||||
+ @Override
|
||||
+ public boolean equals(Object o) {
|
||||
+ if (this == o) return true;
|
||||
+ if (o == null || getClass() != o.getClass()) return false;
|
||||
+ EntityType<?> that = (EntityType<?>) o;
|
||||
+ return this.builtInRegistryHolder.key().toString().equals(that.builtInRegistryHolder.key().toString());
|
||||
+ }
|
||||
+
|
||||
+ @Override
|
||||
+ public int hashCode() {
|
||||
+ return java.util.Objects.hash(this.builtInRegistryHolder.key().toString());
|
||||
+ }
|
||||
+ // Parchment end
|
||||
+
|
||||
public static ResourceLocation getKey(EntityType<?> type) {
|
||||
return BuiltInRegistries.ENTITY_TYPE.getKey(type);
|
||||
}
|
||||
diff --git a/src/main/java/org/bukkit/craftbukkit/util/CraftMagicNumbers.java b/src/main/java/org/bukkit/craftbukkit/util/CraftMagicNumbers.java
|
||||
index be2739875ba1ba1a973c4a45c7e6a6996f0daf31..a6eab579c0f4cc6039bdd9914dd770c796b75d3c 100644
|
||||
--- a/src/main/java/org/bukkit/craftbukkit/util/CraftMagicNumbers.java
|
||||
+++ b/src/main/java/org/bukkit/craftbukkit/util/CraftMagicNumbers.java
|
||||
@@ -665,6 +665,18 @@ public final class CraftMagicNumbers implements UnsafeValues {
|
||||
final net.minecraft.world.item.context.BlockPlaceContext ctx = context;
|
||||
return future.completeAsync(() -> blockItem.canPlace(ctx, blockState), io.papermc.paper.util.MCUtil.MAIN_EXECUTOR);
|
||||
}
|
||||
+
|
||||
+ @Override
|
||||
+ public int entityID(org.bukkit.entity.EntityType type) {
|
||||
+ String name = type.getName();
|
||||
+ if (name == null) {
|
||||
+ throw new IllegalArgumentException("Entity name is undefined");
|
||||
+ }
|
||||
+ return net.minecraft.world.entity.EntityType.byString(name)
|
||||
+ .orElseThrow(() -> new IllegalArgumentException("Could not find corresponding NMS entity"))
|
||||
+ .ordinal();
|
||||
+ }
|
||||
+
|
||||
// Parchment end
|
||||
|
||||
/**
|
||||
Reference in New Issue
Block a user