Migrate reflections to mojang mapped by default

This commit is contained in:
Lixfel
2025-01-06 16:44:10 +01:00
parent 94a1ed3569
commit 9888700273
44 changed files with 216 additions and 110 deletions
@@ -226,13 +226,13 @@ public class FlatteningWrapper14 implements FlatteningWrapper.IFlatteningWrapper
renamedLegacy.put("RECORD_12", Material.MUSIC_DISC_WAIT);
}
private static final Reflection.Field<?> scoreboardName = Reflection.getField(FlatteningWrapper.scoreboardObjective, Reflection.getClass("net.minecraft.network.chat.IChatBaseComponent"), 0);
private static final Reflection.Field<?> scoreboardName = Reflection.getField(FlatteningWrapper.scoreboardObjective, Reflection.getClass("net.minecraft.network.chat.Component"), 0);
@Override
public void setScoreboardTitle(Object packet, String title) {
scoreboardName.set(packet, ChatWrapper.impl.stringToChatComponent(title));
}
private static final Class<?> scoreActionEnum = Core.getVersion() < 21 ? Reflection.getClass("net.minecraft.server.ScoreboardServer$Action") : null;
private static final Class<?> scoreActionEnum = Core.getVersion() < 21 ? Reflection.getClass("net.minecraft.server.ServerScoreboard$Method") : null;
private static final Reflection.Field<?> scoreAction = Core.getVersion() < 21 ? Reflection.getField(FlatteningWrapper.scoreboardScore, scoreActionEnum, 0) : null;
private static final Object scoreActionChange = Core.getVersion() < 21 ? scoreActionEnum.getEnumConstants()[0] : null;
@@ -300,7 +300,7 @@ public class FlatteningWrapper14 implements FlatteningWrapper.IFlatteningWrapper
return head;
}
private static final Class<?> entityPose = Reflection.getClass("net.minecraft.world.entity.EntityPose");
private static final Class<?> entityPose = Reflection.getClass("net.minecraft.world.entity.Pose");
private static final Object standing = entityPose.getEnumConstants()[0];
private static final Object swimming = entityPose.getEnumConstants()[3];
private static final Object sneaking = entityPose.getEnumConstants()[5];
@@ -327,10 +327,10 @@ public class FlatteningWrapper14 implements FlatteningWrapper.IFlatteningWrapper
return displayName != null ? Optional.of(ChatWrapper.impl.stringToChatComponent(displayName)) : Optional.empty();
}
private static final Class<?> registryBlocks = Reflection.getClass("net.minecraft.core.RegistryBlocks");
private static final Class<?> entityTypes = Reflection.getClass("net.minecraft.world.entity.EntityTypes");
private static final Class<?> registryBlocks = Reflection.getClass("net.minecraft.core.DefaultedRegistry");
private static final Class<?> entityTypes = Reflection.getClass("net.minecraft.world.entity.EntityType");
private static final Object entityTypesRegistry = Reflection.getField(Reflection.getClass(Core.getVersion() > 18 ? "net.minecraft.core.registries.BuiltInRegistries" : "net.minecraft.core.IRegistry"), registryBlocks, 0, entityTypes).get(null);
private static final Reflection.Method get = Reflection.getMethod(registryBlocks, null, Reflection.getClass("net.minecraft.resources.MinecraftKey"));
private static final Reflection.Method get = Reflection.getMethod(registryBlocks, null, Reflection.getClass("net.minecraft.resources.ResourceLocation"));
private static final Reflection.Field<?> spawnType = Reflection.getField(ProtocolWrapper.spawnPacket, entityTypes, 0);
private static final Reflection.Field<?> spawnLivingType = Core.getVersion() > 18 ? spawnType : Reflection.getField(ProtocolWrapper.spawnLivingPacket, int.class, 1);
private static final Reflection.Method toMinecraft = Reflection.getMethod("org.bukkit.craftbukkit.util.CraftNamespacedKey", "toMinecraft", NamespacedKey.class);
@@ -353,7 +353,7 @@ public class FlatteningWrapper14 implements FlatteningWrapper.IFlatteningWrapper
}
private static final Reflection.Method getHandle = Reflection.getMethod("org.bukkit.craftbukkit.CraftWorld", "getHandle");
private static final Reflection.Method save = Reflection.getMethod("net.minecraft.server.level.WorldServer", null, Reflection.getClass("net.minecraft.util.IProgressUpdate"), boolean.class, boolean.class);
private static final Reflection.Method save = Reflection.getMethod("net.minecraft.server.level.ServerLevel", null, Reflection.getClass("net.minecraft.util.ProgressListener"), boolean.class, boolean.class);
@Override
public void syncSave(World world) {
save.invoke(getHandle.invoke(world), null, true, false);
@@ -28,9 +28,9 @@ import java.util.Set;
public class BlockIds14 implements BlockIds {
private static final Class<?> blockStateList = Reflection.getClass("net.minecraft.world.level.block.state.BlockStateList");
private static final Class<?> fluidTypeFlowing = Reflection.getClass("net.minecraft.world.level.material.FluidTypeFlowing");
private static final Class<?> fluid = Reflection.getClass("net.minecraft.world.level.material.Fluid");
private static final Class<?> blockStateList = Reflection.getClass("net.minecraft.world.level.block.state.StateDefinition");
private static final Class<?> fluidTypeFlowing = Reflection.getClass("net.minecraft.world.level.material.FlowingFluid");
private static final Class<?> fluid = Reflection.getClass("net.minecraft.world.level.material.FluidState");
private static final Reflection.Method getBlockData = Reflection.getTypedMethod(TechHider.block, null, TechHider.iBlockData);
@Override
@@ -40,8 +40,8 @@ public class BlockIds14 implements BlockIds {
private static final Reflection.Method getStates = Reflection.getTypedMethod(TechHider.block, null, blockStateList);
private static final Reflection.Method getStateList = Reflection.getTypedMethod(blockStateList, null, ImmutableList.class);
private static final Object water = Reflection.getTypedMethod(fluidTypeFlowing, null, fluid, boolean.class).invoke(Reflection.getField(Reflection.getClass("net.minecraft.world.level.material.FluidTypes"), fluidTypeFlowing, 1).get(null), false);
private static final Iterable<?> registryBlockId = (Iterable<?>) Reflection.getField(TechHider.block, Reflection.getClass("net.minecraft.core.RegistryBlockID"), 0).get(null);
private static final Object water = Reflection.getTypedMethod(fluidTypeFlowing, null, fluid, boolean.class).invoke(Reflection.getField(Reflection.getClass("net.minecraft.world.level.material.Fluids"), fluidTypeFlowing, 1).get(null), false);
private static final Iterable<?> registryBlockId = (Iterable<?>) Reflection.getField(TechHider.block, Reflection.getClass("net.minecraft.core.IdMapper"), 0).get(null);
private static final Reflection.Method getFluid = Reflection.getTypedMethod(TechHider.iBlockData, null, fluid);
@Override
public Set<Integer> materialToAllIds(Material material) {