mirror of
https://github.com/Xiao-MoMi/craft-engine.git
synced 2025-12-25 09:59:20 +00:00
基础改进
This commit is contained in:
@@ -500,13 +500,9 @@ public final class BukkitBlockManager extends AbstractBlockManager {
|
||||
Object clientBoundTags = settings.get("client-bound-tags");
|
||||
if (clientBoundTags instanceof List<?> list) {
|
||||
List<String> clientSideTags = MiscUtils.getAsStringList(list).stream().filter(ResourceLocation::isValid).toList();
|
||||
try {
|
||||
Object nmsBlock = CoreReflections.method$Registry$get.invoke(MBuiltInRegistries.BLOCK, KeyUtils.toResourceLocation(id));
|
||||
FastNMS.INSTANCE.method$IdMap$getId(MBuiltInRegistries.BLOCK, nmsBlock).ifPresent(i ->
|
||||
BukkitBlockManager.this.clientBoundTags.put(i, clientSideTags));
|
||||
} catch (ReflectiveOperationException e) {
|
||||
BukkitBlockManager.this.plugin.logger().warn("Unable to get block " + id, e);
|
||||
}
|
||||
Object nmsBlock = FastNMS.INSTANCE.method$Registry$getValue(MBuiltInRegistries.BLOCK, KeyUtils.toResourceLocation(id));
|
||||
FastNMS.INSTANCE.method$IdMap$getId(MBuiltInRegistries.BLOCK, nmsBlock).ifPresent(i ->
|
||||
BukkitBlockManager.this.clientBoundTags.put(i, clientSideTags));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -657,7 +653,7 @@ public final class BukkitBlockManager extends AbstractBlockManager {
|
||||
private void recordVanillaNoteBlocks() {
|
||||
try {
|
||||
Object resourceLocation = KeyUtils.toResourceLocation(BlockKeys.NOTE_BLOCK);
|
||||
Object block = CoreReflections.method$Registry$get.invoke(MBuiltInRegistries.BLOCK, resourceLocation);
|
||||
Object block = FastNMS.INSTANCE.method$Registry$getValue(MBuiltInRegistries.BLOCK, resourceLocation);
|
||||
Object stateDefinition = CoreReflections.field$Block$StateDefinition.get(block);
|
||||
@SuppressWarnings("unchecked")
|
||||
ImmutableList<Object> states = (ImmutableList<Object>) CoreReflections.field$StateDefinition$states.get(stateDefinition);
|
||||
@@ -841,8 +837,8 @@ public final class BukkitBlockManager extends AbstractBlockManager {
|
||||
return FastNMS.INSTANCE.method$ResourceLocation$fromNamespaceAndPath(key.namespace(), key.value());
|
||||
}
|
||||
|
||||
private Object getBlockFromRegistry(Object resourceLocation) throws Exception {
|
||||
return CoreReflections.method$Registry$get.invoke(MBuiltInRegistries.BLOCK, resourceLocation);
|
||||
private Object getBlockFromRegistry(Object resourceLocation) {
|
||||
return FastNMS.INSTANCE.method$Registry$getValue(MBuiltInRegistries.BLOCK, resourceLocation);
|
||||
}
|
||||
|
||||
private Key createRealBlockKey(Key replacedBlock, int index) {
|
||||
|
||||
@@ -107,12 +107,11 @@ public class GrassBlockBehavior extends BukkitBlockBehavior {
|
||||
return InteractionResult.SUCCESS;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public void performBoneMeal(Object thisBlock, Object[] args) throws Exception {
|
||||
Object registry = CoreReflections.method$RegistryAccess$registryOrThrow.invoke(FastNMS.INSTANCE.registryAccess(), MRegistries.PLACED_FEATURE);
|
||||
Object registry = FastNMS.INSTANCE.method$RegistryAccess$lookupOrThrow(FastNMS.INSTANCE.registryAccess(), MRegistries.PLACED_FEATURE);
|
||||
if (registry == null) return;
|
||||
Optional<Object> holder = (Optional<Object>) CoreReflections.method$Registry$getHolder1.invoke(registry, FeatureUtils.createPlacedFeatureKey(boneMealFeature()));
|
||||
Optional<Object> holder = FastNMS.INSTANCE.method$Registry$getHolderByResourceKey(registry, FeatureUtils.createPlacedFeatureKey(boneMealFeature()));
|
||||
if (holder.isEmpty()) {
|
||||
CraftEngine.instance().logger().warn("Placed feature not found: " + boneMealFeature());
|
||||
return;
|
||||
|
||||
@@ -79,10 +79,9 @@ public class SaplingBlockBehavior extends BukkitBlockBehavior {
|
||||
}
|
||||
|
||||
private void generateTree(Object world, Object blockPos, Object blockState, Object randomSource) throws Exception {
|
||||
Object registry = CoreReflections.method$RegistryAccess$registryOrThrow.invoke(FastNMS.INSTANCE.registryAccess(), MRegistries.CONFIGURED_FEATURE);
|
||||
Object registry = FastNMS.INSTANCE.method$RegistryAccess$lookupOrThrow(FastNMS.INSTANCE.registryAccess(), MRegistries.CONFIGURED_FEATURE);
|
||||
if (registry == null) return;
|
||||
@SuppressWarnings("unchecked")
|
||||
Optional<Object> holder = (Optional<Object>) CoreReflections.method$Registry$getHolder1.invoke(registry, FeatureUtils.createConfiguredFeatureKey(treeFeature()));
|
||||
Optional<Object> holder = FastNMS.INSTANCE.method$Registry$getHolderByResourceKey(registry, FeatureUtils.createConfiguredFeatureKey(treeFeature()));
|
||||
if (holder.isEmpty()) {
|
||||
CraftEngine.instance().logger().warn("Configured feature not found: " + treeFeature());
|
||||
return;
|
||||
|
||||
@@ -223,7 +223,7 @@ public class BukkitItemManager extends AbstractItemManager<ItemStack> {
|
||||
Holder.Reference<Key> holder = BuiltInRegistries.OPTIMIZED_ITEM_ID.get(itemKey)
|
||||
.orElseGet(() -> ((WritableRegistry<Key>) BuiltInRegistries.OPTIMIZED_ITEM_ID)
|
||||
.register(new ResourceKey<>(BuiltInRegistries.OPTIMIZED_ITEM_ID.key().location(), itemKey), itemKey));
|
||||
Object mcHolder = ((Optional<Object>) CoreReflections.method$Registry$getHolder1.invoke(MBuiltInRegistries.ITEM, CoreReflections.method$ResourceKey$create.invoke(null, MRegistries.ITEM, resourceLocation))).get();
|
||||
Object mcHolder = FastNMS.INSTANCE.method$Registry$getHolderByResourceKey(MBuiltInRegistries.ITEM, FastNMS.INSTANCE.method$ResourceKey$create(MRegistries.ITEM, resourceLocation)).get();
|
||||
Set<Object> tags = (Set<Object>) CoreReflections.field$Holder$Reference$tags.get(mcHolder);
|
||||
for (Object tag : tags) {
|
||||
Key tagId = Key.of(CoreReflections.field$TagKey$location.get(tag).toString());
|
||||
|
||||
@@ -305,13 +305,21 @@ public class BukkitRecipeManager extends AbstractRecipeManager<ItemStack> {
|
||||
if (!Config.enableRecipeSystem()) return;
|
||||
super.unload();
|
||||
if (VersionHelper.isOrAbove1_21_2()) {
|
||||
this.plugin.scheduler().executeSync(() -> {
|
||||
if (Bukkit.getServer().isStopping()) {
|
||||
try {
|
||||
CoreReflections.method$RecipeManager$finalizeRecipeLoading.invoke(nmsRecipeManager);
|
||||
} catch (ReflectiveOperationException e) {
|
||||
this.plugin.logger().warn("Failed to unregister recipes", e);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
this.plugin.scheduler().executeSync(() -> {
|
||||
try {
|
||||
CoreReflections.method$RecipeManager$finalizeRecipeLoading.invoke(nmsRecipeManager);
|
||||
} catch (ReflectiveOperationException e) {
|
||||
this.plugin.logger().warn("Failed to unregister recipes", e);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -90,7 +90,7 @@ public class BukkitVanillaLootManager extends AbstractVanillaLootManager impleme
|
||||
}
|
||||
|
||||
public class VanillaLootParser implements ConfigParser {
|
||||
public static final String[] CONFIG_SECTION_NAME = new String[] {"vanilla-loots", "vanilla-loot", "loots", "loot"};
|
||||
public static final String[] CONFIG_SECTION_NAME = new String[] {"vanilla-loots", "vanilla-loot", "vanilla_loots", "vanilla_loot"};
|
||||
|
||||
@Override
|
||||
public int loadingSequence() {
|
||||
|
||||
@@ -64,10 +64,8 @@ import net.momirealms.craftengine.core.world.collision.AABB;
|
||||
import net.momirealms.sparrow.nbt.Tag;
|
||||
import org.bukkit.*;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.data.BlockData;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.ItemType;
|
||||
import org.bukkit.inventory.PlayerInventory;
|
||||
import org.bukkit.util.RayTraceResult;
|
||||
import org.bukkit.util.Vector;
|
||||
|
||||
@@ -289,11 +289,11 @@ public final class CoreReflections {
|
||||
)).getInterfaces()[0]
|
||||
);
|
||||
|
||||
public static final Method method$RegistryAccess$registryOrThrow = requireNonNull(
|
||||
ReflectionUtils.getMethod(
|
||||
clazz$RegistryAccess, clazz$Registry, clazz$ResourceKey
|
||||
)
|
||||
);
|
||||
// public static final Method method$RegistryAccess$registryOrThrow = requireNonNull(
|
||||
// ReflectionUtils.getMethod(
|
||||
// clazz$RegistryAccess, clazz$Registry, clazz$ResourceKey
|
||||
// )
|
||||
// );
|
||||
|
||||
public static final Method method$Registry$register = requireNonNull(
|
||||
ReflectionUtils.getStaticMethod(
|
||||
@@ -328,58 +328,52 @@ public final class CoreReflections {
|
||||
)
|
||||
);
|
||||
|
||||
public static final Method method$Registry$getKey = requireNonNull(
|
||||
ReflectionUtils.getMethod(clazz$Registry, clazz$ResourceLocation, Object.class)
|
||||
);
|
||||
// public static final Method method$Registry$getKey = requireNonNull(
|
||||
// ReflectionUtils.getMethod(clazz$Registry, clazz$ResourceLocation, Object.class)
|
||||
// );
|
||||
|
||||
public static final Method method$Registry$get = requireNonNull(
|
||||
ReflectionUtils.getMethods(
|
||||
clazz$Registry, Object.class, clazz$ResourceLocation
|
||||
).stream().filter(m -> m.getReturnType() != Optional.class).findAny().orElse(null)
|
||||
);
|
||||
|
||||
// use ResourceLocation
|
||||
public static final Method method$Registry$getHolder0;
|
||||
// use ResourceKey
|
||||
public static final Method method$Registry$getHolder1;
|
||||
|
||||
static {
|
||||
List<Method> methods = ReflectionUtils.getMethods(clazz$Registry, Optional.class, clazz$ResourceLocation);
|
||||
Method theMethod1 = null;
|
||||
for (Method method : methods) {
|
||||
Type returnType = method.getGenericReturnType();
|
||||
if (method.getParameterCount() == 1 && method.getParameterTypes()[0] == clazz$ResourceLocation) {
|
||||
if (returnType instanceof ParameterizedType parameterizedType) {
|
||||
Type[] actualTypeArguments = parameterizedType.getActualTypeArguments();
|
||||
if (actualTypeArguments.length == 1) {
|
||||
if (actualTypeArguments[0] instanceof ParameterizedType) {
|
||||
theMethod1 = method;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
method$Registry$getHolder0 = theMethod1;
|
||||
}
|
||||
|
||||
static {
|
||||
List<Method> methods = ReflectionUtils.getMethods(clazz$Registry, Optional.class, clazz$ResourceKey);
|
||||
Method theMethod1 = null;
|
||||
for (Method method : methods) {
|
||||
Type returnType = method.getGenericReturnType();
|
||||
if (method.getParameterCount() == 1 && method.getParameterTypes()[0] == clazz$ResourceKey) {
|
||||
if (returnType instanceof ParameterizedType parameterizedType) {
|
||||
Type[] actualTypeArguments = parameterizedType.getActualTypeArguments();
|
||||
if (actualTypeArguments.length == 1) {
|
||||
if (actualTypeArguments[0] instanceof ParameterizedType) {
|
||||
theMethod1 = method;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
method$Registry$getHolder1 = theMethod1;
|
||||
}
|
||||
// // use ResourceLocation
|
||||
// public static final Method method$Registry$getHolder0;
|
||||
// // use ResourceKey
|
||||
// public static final Method method$Registry$getHolder1;
|
||||
//
|
||||
// static {
|
||||
// List<Method> methods = ReflectionUtils.getMethods(clazz$Registry, Optional.class, clazz$ResourceLocation);
|
||||
// Method theMethod1 = null;
|
||||
// for (Method method : methods) {
|
||||
// Type returnType = method.getGenericReturnType();
|
||||
// if (method.getParameterCount() == 1 && method.getParameterTypes()[0] == clazz$ResourceLocation) {
|
||||
// if (returnType instanceof ParameterizedType parameterizedType) {
|
||||
// Type[] actualTypeArguments = parameterizedType.getActualTypeArguments();
|
||||
// if (actualTypeArguments.length == 1) {
|
||||
// if (actualTypeArguments[0] instanceof ParameterizedType) {
|
||||
// theMethod1 = method;
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// method$Registry$getHolder0 = theMethod1;
|
||||
// }
|
||||
//
|
||||
// static {
|
||||
// List<Method> methods = ReflectionUtils.getMethods(clazz$Registry, Optional.class, clazz$ResourceKey);
|
||||
// Method theMethod1 = null;
|
||||
// for (Method method : methods) {
|
||||
// Type returnType = method.getGenericReturnType();
|
||||
// if (method.getParameterCount() == 1 && method.getParameterTypes()[0] == clazz$ResourceKey) {
|
||||
// if (returnType instanceof ParameterizedType parameterizedType) {
|
||||
// Type[] actualTypeArguments = parameterizedType.getActualTypeArguments();
|
||||
// if (actualTypeArguments.length == 1) {
|
||||
// if (actualTypeArguments[0] instanceof ParameterizedType) {
|
||||
// theMethod1 = method;
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// method$Registry$getHolder1 = theMethod1;
|
||||
// }
|
||||
|
||||
public static final Class<?> clazz$BlockPos = requireNonNull(
|
||||
BukkitReflectionUtils.findReobfOrMojmapClass(
|
||||
@@ -3592,4 +3586,15 @@ public final class CoreReflections {
|
||||
"nbt.CompoundTag"
|
||||
)
|
||||
);
|
||||
|
||||
public static final Class<?> clazz$TrimPattern = requireNonNull(
|
||||
BukkitReflectionUtils.findReobfOrMojmapClass(
|
||||
"world.item.equipment.trim.TrimPattern",
|
||||
"world.item.equipment.trim.TrimPattern"
|
||||
)
|
||||
);
|
||||
|
||||
public static final Constructor<?> constructor$TrimPattern = requireNonNull(
|
||||
ReflectionUtils.getConstructor(clazz$TrimPattern, clazz$ResourceLocation, clazz$Holder, clazz$Component)
|
||||
);
|
||||
}
|
||||
|
||||
@@ -3,8 +3,6 @@ package net.momirealms.craftengine.bukkit.plugin.reflection.minecraft;
|
||||
import net.momirealms.craftengine.bukkit.nms.FastNMS;
|
||||
import net.momirealms.craftengine.core.util.VersionHelper;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
public final class MAttributeHolders {
|
||||
private MAttributeHolders() {}
|
||||
|
||||
@@ -12,26 +10,20 @@ public final class MAttributeHolders {
|
||||
public static final Object BLOCK_INTERACTION_RANGE;
|
||||
public static final Object SCALE;
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private static Object getById(String id) throws ReflectiveOperationException {
|
||||
private static Object getById(String id) {
|
||||
Object rl = FastNMS.INSTANCE.method$ResourceLocation$fromNamespaceAndPath("minecraft", id);
|
||||
Optional<Object> optionalHolder = (Optional<Object>) CoreReflections.method$Registry$getHolder0.invoke(MBuiltInRegistries.ATTRIBUTE, rl);
|
||||
return optionalHolder.orElse(null);
|
||||
return FastNMS.INSTANCE.method$Registry$getValue(MBuiltInRegistries.ATTRIBUTE, rl);
|
||||
}
|
||||
|
||||
static {
|
||||
try {
|
||||
if (VersionHelper.isOrAbove1_20_5()) {
|
||||
BLOCK_BREAK_SPEED = getById(VersionHelper.isOrAbove1_21_2() ? "block_break_speed" : "player.block_break_speed");
|
||||
BLOCK_INTERACTION_RANGE = getById(VersionHelper.isOrAbove1_21_2() ? "block_interaction_range" : "player.block_interaction_range");
|
||||
SCALE = getById(VersionHelper.isOrAbove1_21_2() ? "scale" : "generic.scale");
|
||||
} else {
|
||||
BLOCK_BREAK_SPEED = null;
|
||||
BLOCK_INTERACTION_RANGE = null;
|
||||
SCALE = null;
|
||||
}
|
||||
} catch (ReflectiveOperationException e) {
|
||||
throw new RuntimeException(e);
|
||||
if (VersionHelper.isOrAbove1_20_5()) {
|
||||
BLOCK_BREAK_SPEED = getById(VersionHelper.isOrAbove1_21_2() ? "block_break_speed" : "player.block_break_speed");
|
||||
BLOCK_INTERACTION_RANGE = getById(VersionHelper.isOrAbove1_21_2() ? "block_interaction_range" : "player.block_interaction_range");
|
||||
SCALE = getById(VersionHelper.isOrAbove1_21_2() ? "scale" : "generic.scale");
|
||||
} else {
|
||||
BLOCK_BREAK_SPEED = null;
|
||||
BLOCK_INTERACTION_RANGE = null;
|
||||
SCALE = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package net.momirealms.craftengine.bukkit.plugin.reflection.minecraft;
|
||||
|
||||
import net.momirealms.craftengine.bukkit.nms.FastNMS;
|
||||
import net.momirealms.craftengine.bukkit.plugin.reflection.ReflectionInitException;
|
||||
import net.momirealms.craftengine.core.util.VersionHelper;
|
||||
|
||||
public final class MBlocks {
|
||||
@@ -19,26 +18,22 @@ public final class MBlocks {
|
||||
public static final Object SHULKER_BOX;
|
||||
public static final Object COMPOSTER;
|
||||
|
||||
private static Object getById(String id) throws ReflectiveOperationException {
|
||||
private static Object getById(String id) {
|
||||
Object rl = FastNMS.INSTANCE.method$ResourceLocation$fromNamespaceAndPath("minecraft", id);
|
||||
return CoreReflections.method$Registry$get.invoke(MBuiltInRegistries.BLOCK, rl);
|
||||
return FastNMS.INSTANCE.method$Registry$getValue(MBuiltInRegistries.BLOCK, rl);
|
||||
}
|
||||
|
||||
static {
|
||||
try {
|
||||
AIR = getById("air");
|
||||
AIR$defaultState = FastNMS.INSTANCE.method$Block$defaultState(AIR);
|
||||
FIRE = getById("fire");
|
||||
SOUL_FIRE = getById("soul_fire");
|
||||
STONE = getById("stone");
|
||||
STONE$defaultState = FastNMS.INSTANCE.method$Block$defaultState(STONE);
|
||||
ICE = getById("ice");
|
||||
SHORT_GRASS = getById(VersionHelper.isOrAbove1_20_3() ? "short_grass" : "grass");
|
||||
SHORT_GRASS$defaultState = FastNMS.INSTANCE.method$Block$defaultState(SHORT_GRASS);
|
||||
SHULKER_BOX = getById("shulker_box");
|
||||
COMPOSTER = getById("composter");
|
||||
} catch (ReflectiveOperationException e) {
|
||||
throw new ReflectionInitException("Failed to init Blocks", e);
|
||||
}
|
||||
AIR = getById("air");
|
||||
AIR$defaultState = FastNMS.INSTANCE.method$Block$defaultState(AIR);
|
||||
FIRE = getById("fire");
|
||||
SOUL_FIRE = getById("soul_fire");
|
||||
STONE = getById("stone");
|
||||
STONE$defaultState = FastNMS.INSTANCE.method$Block$defaultState(STONE);
|
||||
ICE = getById("ice");
|
||||
SHORT_GRASS = getById(VersionHelper.isOrAbove1_20_3() ? "short_grass" : "grass");
|
||||
SHORT_GRASS$defaultState = FastNMS.INSTANCE.method$Block$defaultState(SHORT_GRASS);
|
||||
SHULKER_BOX = getById("shulker_box");
|
||||
COMPOSTER = getById("composter");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package net.momirealms.craftengine.bukkit.plugin.reflection.minecraft;
|
||||
|
||||
import net.momirealms.craftengine.bukkit.nms.FastNMS;
|
||||
import net.momirealms.craftengine.bukkit.plugin.reflection.ReflectionInitException;
|
||||
import net.momirealms.craftengine.core.util.VersionHelper;
|
||||
|
||||
public final class MEntityTypes {
|
||||
@@ -60,72 +59,68 @@ public final class MEntityTypes {
|
||||
public static final Object PLAYER;
|
||||
public static final int PLAYER$registryId;
|
||||
|
||||
private static Object getById(String id) throws ReflectiveOperationException {
|
||||
private static Object getById(String id) {
|
||||
Object rl = FastNMS.INSTANCE.method$ResourceLocation$fromNamespaceAndPath("minecraft", id);
|
||||
return CoreReflections.method$Registry$get.invoke(MBuiltInRegistries.ENTITY_TYPE, rl);
|
||||
return FastNMS.INSTANCE.method$Registry$getValue(MBuiltInRegistries.ENTITY_TYPE, rl);
|
||||
}
|
||||
|
||||
private static int getRegistryId(Object type) throws ReflectiveOperationException {
|
||||
private static int getRegistryId(Object type) {
|
||||
if (type == null) return -1;
|
||||
return (int) CoreReflections.method$Registry$getId.invoke(MBuiltInRegistries.ENTITY_TYPE, type);
|
||||
return FastNMS.INSTANCE.method$Registry$getId(MBuiltInRegistries.ENTITY_TYPE, type);
|
||||
}
|
||||
|
||||
static {
|
||||
try {
|
||||
TEXT_DISPLAY = getById("text_display");
|
||||
TEXT_DISPLAY$registryId = getRegistryId(TEXT_DISPLAY);
|
||||
ITEM_DISPLAY = getById("item_display");
|
||||
ITEM_DISPLAY$registryId = getRegistryId(ITEM_DISPLAY);
|
||||
BLOCK_DISPLAY = getById("block_display");
|
||||
BLOCK_DISPLAY$registryId = getRegistryId(BLOCK_DISPLAY);
|
||||
FALLING_BLOCK = getById("falling_block");
|
||||
FALLING_BLOCK$registryId = getRegistryId(FALLING_BLOCK);
|
||||
INTERACTION = getById("interaction");
|
||||
INTERACTION$registryId = getRegistryId(INTERACTION);
|
||||
SHULKER = getById("shulker");
|
||||
SHULKER$registryId = getRegistryId(SHULKER);
|
||||
ARMOR_STAND = getById("armor_stand");
|
||||
ARMOR_STAND$registryId = getRegistryId(ARMOR_STAND);
|
||||
OAK_BOAT = getById(VersionHelper.isOrAbove1_21_2() ? "oak_boat" : "boat");
|
||||
OAK_BOAT$registryId = getRegistryId(OAK_BOAT);
|
||||
TRIDENT = getById("trident");
|
||||
TRIDENT$registryId = getRegistryId(TRIDENT);
|
||||
SNOWBALL = getById("snowball");
|
||||
SNOWBALL$registryId = getRegistryId(SNOWBALL);
|
||||
FIREBALL = getById("fireball");
|
||||
FIREBALL$registryId = getRegistryId(FIREBALL);
|
||||
EYE_OF_ENDER = getById("eye_of_ender");
|
||||
EYE_OF_ENDER$registryId = getRegistryId(EYE_OF_ENDER);
|
||||
FIREWORK_ROCKET = getById("firework_rocket");
|
||||
FIREWORK_ROCKET$registryId = getRegistryId(FIREWORK_ROCKET);
|
||||
ITEM = getById("item");
|
||||
ITEM$registryId = getRegistryId(ITEM);
|
||||
ITEM_FRAME = getById("item_frame");
|
||||
ITEM_FRAME$registryId = getRegistryId(ITEM_FRAME);
|
||||
GLOW_ITEM_FRAME = getById("glow_item_frame");
|
||||
GLOW_ITEM_FRAME$registryId = getRegistryId(GLOW_ITEM_FRAME);
|
||||
SMALL_FIREBALL = getById("small_fireball");
|
||||
SMALL_FIREBALL$registryId = getRegistryId(SMALL_FIREBALL);
|
||||
EGG = getById("egg");
|
||||
EGG$registryId = getRegistryId(EGG);
|
||||
ENDER_PEARL = getById("ender_pearl");
|
||||
ENDER_PEARL$registryId = getRegistryId(ENDER_PEARL);
|
||||
EXPERIENCE_BOTTLE = getById("experience_bottle");
|
||||
EXPERIENCE_BOTTLE$registryId = getRegistryId(EXPERIENCE_BOTTLE);
|
||||
POTION = getById("potion");
|
||||
POTION$registryId = getRegistryId(POTION);
|
||||
OMINOUS_ITEM_SPAWNER = VersionHelper.isOrAbove1_20_5() ? getById("ominous_item_spawner") : null;
|
||||
OMINOUS_ITEM_SPAWNER$registryId = getRegistryId(OMINOUS_ITEM_SPAWNER);
|
||||
HAPPY_GHAST = VersionHelper.isOrAbove1_21_6() ? getById("happy_ghast") : null;
|
||||
HAPPY_GHAST$registryId = getRegistryId(HAPPY_GHAST);
|
||||
PLAYER = getById("player");
|
||||
PLAYER$registryId = getRegistryId(PLAYER);
|
||||
ARROW = getById("arrow");
|
||||
ARROW$registryId = getRegistryId(ARROW);
|
||||
SPECTRAL_ARROW = getById("spectral_arrow");
|
||||
SPECTRAL_ARROW$registryId = getRegistryId(SPECTRAL_ARROW);
|
||||
} catch (ReflectiveOperationException e) {
|
||||
throw new ReflectionInitException("Failed to init EntityTypes", e);
|
||||
}
|
||||
TEXT_DISPLAY = getById("text_display");
|
||||
TEXT_DISPLAY$registryId = getRegistryId(TEXT_DISPLAY);
|
||||
ITEM_DISPLAY = getById("item_display");
|
||||
ITEM_DISPLAY$registryId = getRegistryId(ITEM_DISPLAY);
|
||||
BLOCK_DISPLAY = getById("block_display");
|
||||
BLOCK_DISPLAY$registryId = getRegistryId(BLOCK_DISPLAY);
|
||||
FALLING_BLOCK = getById("falling_block");
|
||||
FALLING_BLOCK$registryId = getRegistryId(FALLING_BLOCK);
|
||||
INTERACTION = getById("interaction");
|
||||
INTERACTION$registryId = getRegistryId(INTERACTION);
|
||||
SHULKER = getById("shulker");
|
||||
SHULKER$registryId = getRegistryId(SHULKER);
|
||||
ARMOR_STAND = getById("armor_stand");
|
||||
ARMOR_STAND$registryId = getRegistryId(ARMOR_STAND);
|
||||
OAK_BOAT = getById(VersionHelper.isOrAbove1_21_2() ? "oak_boat" : "boat");
|
||||
OAK_BOAT$registryId = getRegistryId(OAK_BOAT);
|
||||
TRIDENT = getById("trident");
|
||||
TRIDENT$registryId = getRegistryId(TRIDENT);
|
||||
SNOWBALL = getById("snowball");
|
||||
SNOWBALL$registryId = getRegistryId(SNOWBALL);
|
||||
FIREBALL = getById("fireball");
|
||||
FIREBALL$registryId = getRegistryId(FIREBALL);
|
||||
EYE_OF_ENDER = getById("eye_of_ender");
|
||||
EYE_OF_ENDER$registryId = getRegistryId(EYE_OF_ENDER);
|
||||
FIREWORK_ROCKET = getById("firework_rocket");
|
||||
FIREWORK_ROCKET$registryId = getRegistryId(FIREWORK_ROCKET);
|
||||
ITEM = getById("item");
|
||||
ITEM$registryId = getRegistryId(ITEM);
|
||||
ITEM_FRAME = getById("item_frame");
|
||||
ITEM_FRAME$registryId = getRegistryId(ITEM_FRAME);
|
||||
GLOW_ITEM_FRAME = getById("glow_item_frame");
|
||||
GLOW_ITEM_FRAME$registryId = getRegistryId(GLOW_ITEM_FRAME);
|
||||
SMALL_FIREBALL = getById("small_fireball");
|
||||
SMALL_FIREBALL$registryId = getRegistryId(SMALL_FIREBALL);
|
||||
EGG = getById("egg");
|
||||
EGG$registryId = getRegistryId(EGG);
|
||||
ENDER_PEARL = getById("ender_pearl");
|
||||
ENDER_PEARL$registryId = getRegistryId(ENDER_PEARL);
|
||||
EXPERIENCE_BOTTLE = getById("experience_bottle");
|
||||
EXPERIENCE_BOTTLE$registryId = getRegistryId(EXPERIENCE_BOTTLE);
|
||||
POTION = getById("potion");
|
||||
POTION$registryId = getRegistryId(POTION);
|
||||
OMINOUS_ITEM_SPAWNER = VersionHelper.isOrAbove1_20_5() ? getById("ominous_item_spawner") : null;
|
||||
OMINOUS_ITEM_SPAWNER$registryId = getRegistryId(OMINOUS_ITEM_SPAWNER);
|
||||
HAPPY_GHAST = VersionHelper.isOrAbove1_21_6() ? getById("happy_ghast") : null;
|
||||
HAPPY_GHAST$registryId = getRegistryId(HAPPY_GHAST);
|
||||
PLAYER = getById("player");
|
||||
PLAYER$registryId = getRegistryId(PLAYER);
|
||||
ARROW = getById("arrow");
|
||||
ARROW$registryId = getRegistryId(ARROW);
|
||||
SPECTRAL_ARROW = getById("spectral_arrow");
|
||||
SPECTRAL_ARROW$registryId = getRegistryId(SPECTRAL_ARROW);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,7 +15,7 @@ public final class MFluids {
|
||||
|
||||
private static Object getById(String id) throws ReflectiveOperationException {
|
||||
Object rl = FastNMS.INSTANCE.method$ResourceLocation$fromNamespaceAndPath("minecraft", id);
|
||||
return CoreReflections.method$Registry$get.invoke(MBuiltInRegistries.FLUID, rl);
|
||||
return FastNMS.INSTANCE.method$Registry$getValue(MBuiltInRegistries.FLUID, rl);
|
||||
}
|
||||
|
||||
static {
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package net.momirealms.craftengine.bukkit.plugin.reflection.minecraft;
|
||||
|
||||
import net.momirealms.craftengine.bukkit.nms.FastNMS;
|
||||
import net.momirealms.craftengine.bukkit.plugin.reflection.ReflectionInitException;
|
||||
|
||||
public final class MItems {
|
||||
private MItems() {}
|
||||
@@ -9,17 +8,13 @@ public final class MItems {
|
||||
public static final Object AIR;
|
||||
public static final Object WATER_BUCKET;
|
||||
|
||||
private static Object getById(String id) throws ReflectiveOperationException {
|
||||
private static Object getById(String id) {
|
||||
Object rl = FastNMS.INSTANCE.method$ResourceLocation$fromNamespaceAndPath("minecraft", id);
|
||||
return CoreReflections.method$Registry$get.invoke(MBuiltInRegistries.ITEM, rl);
|
||||
return FastNMS.INSTANCE.method$Registry$getValue(MBuiltInRegistries.ITEM, rl);
|
||||
}
|
||||
|
||||
static {
|
||||
try {
|
||||
AIR = getById("air");
|
||||
WATER_BUCKET = getById("water_bucket");
|
||||
} catch (ReflectiveOperationException e) {
|
||||
throw new ReflectionInitException("Failed to init Items", e);
|
||||
}
|
||||
AIR = getById("air");
|
||||
WATER_BUCKET = getById("water_bucket");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package net.momirealms.craftengine.bukkit.plugin.reflection.minecraft;
|
||||
|
||||
import net.momirealms.craftengine.bukkit.nms.FastNMS;
|
||||
import net.momirealms.craftengine.bukkit.plugin.reflection.ReflectionInitException;
|
||||
|
||||
public final class MMobEffects {
|
||||
private MMobEffects() {}
|
||||
@@ -10,19 +9,15 @@ public final class MMobEffects {
|
||||
public static final Object HASTE;
|
||||
public static final Object INVISIBILITY;
|
||||
|
||||
private static Object getById(String id) throws ReflectiveOperationException {
|
||||
private static Object getById(String id) {
|
||||
Object rl = FastNMS.INSTANCE.method$ResourceLocation$fromNamespaceAndPath("minecraft", id);
|
||||
return CoreReflections.method$Registry$get.invoke(MBuiltInRegistries.MOB_EFFECT, rl);
|
||||
return FastNMS.INSTANCE.method$Registry$getValue(MBuiltInRegistries.MOB_EFFECT, rl);
|
||||
}
|
||||
|
||||
// for 1.20.1-1.20.4
|
||||
static {
|
||||
try {
|
||||
MINING_FATIGUE = getById("mining_fatigue");
|
||||
HASTE = getById("haste");
|
||||
INVISIBILITY = getById("invisibility");
|
||||
} catch (ReflectiveOperationException e) {
|
||||
throw new ReflectionInitException("Failed to init MobEffects", e);
|
||||
}
|
||||
MINING_FATIGUE = getById("mining_fatigue");
|
||||
HASTE = getById("haste");
|
||||
INVISIBILITY = getById("invisibility");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package net.momirealms.craftengine.bukkit.plugin.reflection.minecraft;
|
||||
|
||||
import net.momirealms.craftengine.bukkit.nms.FastNMS;
|
||||
import net.momirealms.craftengine.bukkit.plugin.reflection.ReflectionInitException;
|
||||
|
||||
public final class MRecipeTypes {
|
||||
private MRecipeTypes() {}
|
||||
@@ -14,22 +13,18 @@ public final class MRecipeTypes {
|
||||
public static final Object STONECUTTING;
|
||||
public static final Object SMITHING;
|
||||
|
||||
private static Object getById(String id) throws ReflectiveOperationException {
|
||||
private static Object getById(String id) {
|
||||
Object rl = FastNMS.INSTANCE.method$ResourceLocation$fromNamespaceAndPath("minecraft", id);
|
||||
return CoreReflections.method$Registry$get.invoke(MBuiltInRegistries.RECIPE_TYPE, rl);
|
||||
return FastNMS.INSTANCE.method$Registry$getValue(MBuiltInRegistries.RECIPE_TYPE, rl);
|
||||
}
|
||||
|
||||
static {
|
||||
try {
|
||||
CRAFTING = getById("crafting");
|
||||
SMELTING = getById("smelting");
|
||||
BLASTING = getById("blasting");
|
||||
SMOKING = getById("smoking");
|
||||
CAMPFIRE_COOKING = getById("campfire_cooking");
|
||||
STONECUTTING = getById("stonecutting");
|
||||
SMITHING = getById("smithing");
|
||||
} catch (ReflectiveOperationException e) {
|
||||
throw new ReflectionInitException("Failed to init RecipeTypes", e);
|
||||
}
|
||||
CRAFTING = getById("crafting");
|
||||
SMELTING = getById("smelting");
|
||||
BLASTING = getById("blasting");
|
||||
SMOKING = getById("smoking");
|
||||
CAMPFIRE_COOKING = getById("campfire_cooking");
|
||||
STONECUTTING = getById("stonecutting");
|
||||
SMITHING = getById("smithing");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,6 +23,7 @@ public final class MRegistries {
|
||||
public static final Object DIMENSION_TYPE;
|
||||
public static final Object CONFIGURED_FEATURE;
|
||||
public static final Object PLACED_FEATURE;
|
||||
public static final Object TRIM_PATTERN;
|
||||
@Nullable // 1.21+
|
||||
public static final Object JUKEBOX_SONG;
|
||||
@Nullable // 1.21+
|
||||
@@ -46,6 +47,7 @@ public final class MRegistries {
|
||||
Object registries$PlacedFeature = null;
|
||||
Object registries$JukeboxSong = null;
|
||||
Object registries$Recipe = null;
|
||||
Object registries$TrimPattern = null;
|
||||
for (Field field : fields) {
|
||||
Type fieldType = field.getGenericType();
|
||||
if (fieldType instanceof ParameterizedType paramType) {
|
||||
@@ -87,6 +89,8 @@ public final class MRegistries {
|
||||
registries$JukeboxSong = field.get(null);
|
||||
} else if (type == CoreReflections.clazz$PlacedFeature) {
|
||||
registries$PlacedFeature = field.get(null);
|
||||
} else if (type == CoreReflections.clazz$TrimPattern) {
|
||||
registries$TrimPattern = field.get(null);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -106,6 +110,7 @@ public final class MRegistries {
|
||||
RECIPE_TYPE = requireNonNull(registries$RecipeType);
|
||||
CONFIGURED_FEATURE = requireNonNull(registries$ConfiguredFeature);
|
||||
PLACED_FEATURE = requireNonNull(registries$PlacedFeature);
|
||||
TRIM_PATTERN = requireNonNull(registries$TrimPattern);
|
||||
JUKEBOX_SONG = registries$JukeboxSong;
|
||||
RECIPE = registries$Recipe;
|
||||
} catch (ReflectiveOperationException e) {
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package net.momirealms.craftengine.bukkit.plugin.reflection.minecraft;
|
||||
|
||||
import net.momirealms.craftengine.bukkit.nms.FastNMS;
|
||||
import net.momirealms.craftengine.bukkit.plugin.reflection.ReflectionInitException;
|
||||
|
||||
public final class MSoundEvents {
|
||||
private MSoundEvents() {}
|
||||
@@ -12,20 +11,16 @@ public final class MSoundEvents {
|
||||
public static final Object TRIDENT_RIPTIDE_3;
|
||||
public static final Object TRIDENT_THROW;
|
||||
|
||||
private static Object getById(String id) throws ReflectiveOperationException {
|
||||
private static Object getById(String id) {
|
||||
Object rl = FastNMS.INSTANCE.method$ResourceLocation$fromNamespaceAndPath("minecraft", id);
|
||||
return CoreReflections.method$Registry$get.invoke(MBuiltInRegistries.SOUND_EVENT, rl);
|
||||
return FastNMS.INSTANCE.method$Registry$getValue(MBuiltInRegistries.SOUND_EVENT, rl);
|
||||
}
|
||||
|
||||
static {
|
||||
try {
|
||||
EMPTY = getById("intentionally_empty");
|
||||
TRIDENT_RIPTIDE_1 = getById("item.trident_riptide_1");
|
||||
TRIDENT_RIPTIDE_2 = getById("item.trident_riptide_2");
|
||||
TRIDENT_RIPTIDE_3 = getById("item.trident.riptide_3");
|
||||
TRIDENT_THROW = getById("item.trident.throw");
|
||||
} catch (ReflectiveOperationException e) {
|
||||
throw new ReflectionInitException("Failed to init SoundEvents", e);
|
||||
}
|
||||
EMPTY = getById("intentionally_empty");
|
||||
TRIDENT_RIPTIDE_1 = getById("item.trident_riptide_1");
|
||||
TRIDENT_RIPTIDE_2 = getById("item.trident_riptide_2");
|
||||
TRIDENT_RIPTIDE_3 = getById("item.trident.riptide_3");
|
||||
TRIDENT_THROW = getById("item.trident.throw");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,6 +12,7 @@ import net.momirealms.craftengine.core.sound.JukeboxSong;
|
||||
import net.momirealms.craftengine.core.util.Key;
|
||||
import net.momirealms.craftengine.core.util.VersionHelper;
|
||||
|
||||
import java.util.IdentityHashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
@@ -30,20 +31,22 @@ public class BukkitSoundManager extends AbstractSoundManager {
|
||||
protected void registerSongs(Map<Key, JukeboxSong> songs) {
|
||||
if (songs.isEmpty()) return;
|
||||
try {
|
||||
Object registry = CoreReflections.method$RegistryAccess$registryOrThrow.invoke(FastNMS.INSTANCE.registryAccess(), MRegistries.JUKEBOX_SONG);;
|
||||
// 获取 JUKEBOX_SONG 注册表
|
||||
Object registry = FastNMS.INSTANCE.method$RegistryAccess$lookupOrThrow(FastNMS.INSTANCE.registryAccess(), MRegistries.JUKEBOX_SONG);
|
||||
unfreezeRegistry(registry);
|
||||
for (Map.Entry<Key, JukeboxSong> entry : songs.entrySet()) {
|
||||
Key id = entry.getKey();
|
||||
JukeboxSong jukeboxSong = entry.getValue();
|
||||
Object resourceLocation = KeyUtils.toResourceLocation(id);
|
||||
Object soundId = KeyUtils.toResourceLocation(jukeboxSong.sound());
|
||||
Object song = CoreReflections.method$Registry$get.invoke(registry, resourceLocation);
|
||||
// 检查之前有没有注册过了
|
||||
Object song = FastNMS.INSTANCE.method$Registry$getValue(registry, resourceLocation);
|
||||
|
||||
Object soundEvent = VersionHelper.isOrAbove1_21_2() ?
|
||||
CoreReflections.constructor$SoundEvent.newInstance(soundId, Optional.of(jukeboxSong.range())) :
|
||||
CoreReflections.constructor$SoundEvent.newInstance(soundId, jukeboxSong.range(), false);
|
||||
Object soundHolder = CoreReflections.method$Holder$direct.invoke(null, soundEvent);
|
||||
|
||||
// 只有没注册才注册,否则会报错
|
||||
if (song == null) {
|
||||
song = CoreReflections.constructor$JukeboxSong.newInstance(soundHolder, ComponentUtils.adventureToMinecraft(jukeboxSong.description()), jukeboxSong.lengthInSeconds(), jukeboxSong.comparatorOutput());
|
||||
Object holder = CoreReflections.method$Registry$registerForHolder.invoke(null, registry, resourceLocation, song);
|
||||
|
||||
@@ -62,7 +62,7 @@ public class BlockStateUtils {
|
||||
@SuppressWarnings("unchecked")
|
||||
public static List<Object> getAllVanillaBlockStates(Key block) {
|
||||
try {
|
||||
Object blockIns = CoreReflections.method$Registry$get.invoke(MBuiltInRegistries.BLOCK, KeyUtils.toResourceLocation(block));
|
||||
Object blockIns = FastNMS.INSTANCE.method$Registry$getValue(MBuiltInRegistries.BLOCK, KeyUtils.toResourceLocation(block));
|
||||
Object definition = CoreReflections.field$Block$StateDefinition.get(blockIns);
|
||||
return (List<Object>) CoreReflections.field$StateDefinition$states.get(definition);
|
||||
} catch (Exception e) {
|
||||
|
||||
@@ -19,7 +19,7 @@ public class RegistryUtils {
|
||||
|
||||
public static int currentBiomeRegistrySize() {
|
||||
try {
|
||||
Object idMap = CoreReflections.method$Registry$asHolderIdMap.invoke(CoreReflections.method$RegistryAccess$registryOrThrow.invoke(FastNMS.INSTANCE.registryAccess(), MRegistries.BIOME));
|
||||
Object idMap = CoreReflections.method$Registry$asHolderIdMap.invoke(FastNMS.INSTANCE.method$RegistryAccess$lookupOrThrow(FastNMS.INSTANCE.registryAccess(), MRegistries.BIOME));
|
||||
return (int) CoreReflections.method$IdMap$size.invoke(idMap);
|
||||
} catch (ReflectiveOperationException e) {
|
||||
throw new RuntimeException(e);
|
||||
|
||||
@@ -11,8 +11,6 @@ import net.momirealms.craftengine.core.world.BlockPos;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
public abstract class Player extends AbstractEntity implements NetWorkUser {
|
||||
private static final Key TYPE = Key.of("minecraft:player");
|
||||
|
||||
@@ -25,7 +25,7 @@ public class TrimModifier<I> implements ItemDataModifier<I> {
|
||||
|
||||
@Override
|
||||
public Item<I> apply(Item<I> item, ItemBuildContext context) {
|
||||
item.trim(new Trim(this.material, this.pattern));
|
||||
item.trim(new Trim(this.pattern, this.material));
|
||||
return item;
|
||||
}
|
||||
|
||||
|
||||
@@ -40,6 +40,7 @@ public abstract class AbstractSoundManager implements SoundManager {
|
||||
public void unload() {
|
||||
this.byId.clear();
|
||||
this.byNamespace.clear();
|
||||
this.songs.clear();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -60,7 +61,7 @@ public abstract class AbstractSoundManager implements SoundManager {
|
||||
protected abstract void registerSongs(Map<Key, JukeboxSong> songs);
|
||||
|
||||
public class SongParser implements ConfigParser {
|
||||
public static final String[] CONFIG_SECTION_NAME = new String[] {"jukebox_songs", "song", "songs", "jukebox", "jukebox_song"};
|
||||
public static final String[] CONFIG_SECTION_NAME = new String[] {"jukebox_songs", "jukebox_song", "jukebox-songs", "jukebox-song"};
|
||||
|
||||
@Override
|
||||
public int loadingSequence() {
|
||||
|
||||
@@ -50,7 +50,7 @@ byte_buddy_version=1.17.5
|
||||
ahocorasick_version=0.6.3
|
||||
snake_yaml_version=2.4
|
||||
anti_grief_version=0.18
|
||||
nms_helper_version=1.0.20
|
||||
nms_helper_version=1.0.25
|
||||
evalex_version=3.5.0
|
||||
reactive_streams_version=1.0.4
|
||||
amazon_awssdk_version=2.31.23
|
||||
|
||||
Reference in New Issue
Block a user