mirror of
https://github.com/Xiao-MoMi/craft-engine.git
synced 2025-12-25 01:49:30 +00:00
@@ -39,6 +39,7 @@ import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.io.Reader;
|
||||
import java.lang.reflect.Array;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.nio.file.Path;
|
||||
import java.util.*;
|
||||
@@ -988,8 +989,22 @@ public class BukkitRecipeManager implements RecipeManager<ItemStack> {
|
||||
}
|
||||
}
|
||||
|
||||
// 1.21.5+
|
||||
private static Object toTransmuteResult(ItemStack item) throws InvocationTargetException, IllegalAccessException, InstantiationException {
|
||||
Object itemStack = Reflections.method$CraftItemStack$asNMSCopy.invoke(null, item);
|
||||
Object nmsItem = Reflections.method$ItemStack$getItem.invoke(itemStack);
|
||||
return Reflections.constructor$TransmuteResult.newInstance(nmsItem);
|
||||
}
|
||||
|
||||
private static Object createMinecraftSmithingTransformRecipe(CustomSmithingTransformRecipe<ItemStack> ceRecipe) throws ReflectiveOperationException {
|
||||
if (VersionHelper.isVersionNewerThan1_21_2()) {
|
||||
if (VersionHelper.isVersionNewerThan1_21_5()) {
|
||||
return Reflections.constructor$SmithingTransformRecipe.newInstance(
|
||||
toOptionalMinecraftIngredient(ceRecipe.template()),
|
||||
toMinecraftIngredient(ceRecipe.base()),
|
||||
toOptionalMinecraftIngredient(ceRecipe.addition()),
|
||||
toTransmuteResult(ceRecipe.result(ItemBuildContext.EMPTY))
|
||||
);
|
||||
} else if (VersionHelper.isVersionNewerThan1_21_2()) {
|
||||
return Reflections.constructor$SmithingTransformRecipe.newInstance(
|
||||
toOptionalMinecraftIngredient(ceRecipe.template()),
|
||||
toOptionalMinecraftIngredient(ceRecipe.base()),
|
||||
|
||||
@@ -11,6 +11,7 @@ public class LightUtils {
|
||||
|
||||
private LightUtils() {}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public static void updateChunkLight(World world, Map<Long, BitSet> sectionPosSet) {
|
||||
try {
|
||||
Object serverLevel = Reflections.field$CraftWorld$ServerLevel.get(world);
|
||||
@@ -19,8 +20,13 @@ public class LightUtils {
|
||||
long chunkKey = entry.getKey();
|
||||
Object chunkHolder = Reflections.method$ServerChunkCache$getVisibleChunkIfPresent.invoke(chunkSource, chunkKey);
|
||||
if (chunkHolder == null) continue;
|
||||
@SuppressWarnings("unchecked")
|
||||
List<Object> players = (List<Object>) Reflections.method$ChunkHolder$getPlayers.invoke(chunkHolder, false);
|
||||
List<Object> players;
|
||||
if (Reflections.method$ChunkHolder$getPlayers != null) {
|
||||
players = (List<Object>) Reflections.method$ChunkHolder$getPlayers.invoke(chunkHolder, false);
|
||||
} else {
|
||||
Object chunkHolder$PlayerProvider = Reflections.field$ChunkHolder$playerProvider.get(chunkHolder);
|
||||
players = (List<Object>) Reflections.method$ChunkHolder$PlayerProvider$getPlayers.invoke(chunkHolder$PlayerProvider, false);
|
||||
}
|
||||
if (players.isEmpty()) continue;
|
||||
Object lightEngine = Reflections.field$ChunkHolder$lightEngine.get(chunkHolder);
|
||||
BitSet blockChangedLightSectionFilter = (BitSet) Reflections.field$ChunkHolder$blockChangedLightSectionFilter.get(chunkHolder);
|
||||
|
||||
@@ -1263,9 +1263,18 @@ public class Reflections {
|
||||
)
|
||||
);
|
||||
|
||||
public static final Class<?> clazz$Team$Visibility = requireNonNull(
|
||||
ReflectionUtils.getClazz(
|
||||
BukkitReflectionUtils.assembleMCClass("world.scores.Team$Visibility"),
|
||||
BukkitReflectionUtils.assembleMCClass("world.scores.ScoreboardTeamBase$EnumTeamPush")
|
||||
)
|
||||
);
|
||||
|
||||
public static final Field field$ClientboundSetPlayerTeamPacket$Parameters$nametagVisibility = requireNonNull(
|
||||
ReflectionUtils.getInstanceDeclaredField(
|
||||
clazz$ClientboundSetPlayerTeamPacket$Parameters, String.class, 0
|
||||
clazz$ClientboundSetPlayerTeamPacket$Parameters,
|
||||
VersionHelper.isVersionNewerThan1_21_5() ? clazz$Team$Visibility : String.class,
|
||||
0
|
||||
)
|
||||
);
|
||||
|
||||
@@ -2660,12 +2669,31 @@ public class Reflections {
|
||||
)
|
||||
);
|
||||
|
||||
public static final Method method$ChunkHolder$getPlayers = requireNonNull(
|
||||
ReflectionUtils.getMethod(
|
||||
clazz$ChunkHolder, List.class, boolean.class
|
||||
public static final Class<?> clazz$ChunkHolder$PlayerProvider = requireNonNull(
|
||||
ReflectionUtils.getClazz(
|
||||
BukkitReflectionUtils.assembleMCClass("server.level.ChunkHolder$PlayerProvider"),
|
||||
BukkitReflectionUtils.assembleMCClass("server.level.PlayerChunk$d")
|
||||
)
|
||||
);
|
||||
|
||||
public static final Field field$ChunkHolder$playerProvider = requireNonNull(
|
||||
ReflectionUtils.getDeclaredField(
|
||||
clazz$ChunkHolder, clazz$ChunkHolder$PlayerProvider, 0
|
||||
)
|
||||
);
|
||||
|
||||
public static final Method method$ChunkHolder$PlayerProvider$getPlayers = requireNonNull(
|
||||
ReflectionUtils.getMethod(
|
||||
clazz$ChunkHolder$PlayerProvider, List.class, clazz$ChunkPos, boolean.class
|
||||
)
|
||||
);
|
||||
|
||||
// 1.20 ~ 1.21.4
|
||||
public static final Method method$ChunkHolder$getPlayers =
|
||||
ReflectionUtils.getMethod(
|
||||
clazz$ChunkHolder, List.class, boolean.class
|
||||
);
|
||||
|
||||
public static final Field field$ChunkHolder$lightEngine = requireNonNull(
|
||||
ReflectionUtils.getDeclaredField(
|
||||
clazz$ChunkHolder, clazz$LevelLightEngine, 0
|
||||
@@ -3924,9 +3952,9 @@ public class Reflections {
|
||||
);
|
||||
|
||||
public static final Method method$CraftEventFactory$callBlockPlaceEvent = requireNonNull(
|
||||
ReflectionUtils.getStaticMethod(
|
||||
clazz$CraftEventFactory, BlockPlaceEvent.class, clazz$ServerLevel, clazz$Player, clazz$InteractionHand, BlockState.class, int.class, int.class, int.class
|
||||
)
|
||||
VersionHelper.isVersionNewerThan1_21_5()
|
||||
? ReflectionUtils.getStaticMethod(clazz$CraftEventFactory, BlockPlaceEvent.class, clazz$ServerLevel, clazz$Player, clazz$InteractionHand, BlockState.class, clazz$BlockPos)
|
||||
: ReflectionUtils.getStaticMethod(clazz$CraftEventFactory, BlockPlaceEvent.class, clazz$ServerLevel, clazz$Player, clazz$InteractionHand, BlockState.class, int.class, int.class, int.class)
|
||||
);
|
||||
|
||||
public static final Class<?> clazz$Abilities = requireNonNull(
|
||||
@@ -4817,9 +4845,9 @@ public class Reflections {
|
||||
);
|
||||
|
||||
public static final Method method$ServerLevel$levelEvent = requireNonNull(
|
||||
ReflectionUtils.getMethod(
|
||||
clazz$ServerLevel, void.class, clazz$Player, int.class, clazz$BlockPos, int.class
|
||||
)
|
||||
VersionHelper.isVersionNewerThan1_21_5()
|
||||
? ReflectionUtils.getMethod(clazz$ServerLevel, void.class, clazz$Entity, int.class, clazz$BlockPos, int.class)
|
||||
: ReflectionUtils.getMethod(clazz$ServerLevel, void.class, clazz$Player, int.class, clazz$BlockPos, int.class)
|
||||
);
|
||||
|
||||
public static final Method method$PalettedContainer$getAndSet = Objects.requireNonNull(
|
||||
@@ -5105,12 +5133,24 @@ public class Reflections {
|
||||
)
|
||||
);
|
||||
|
||||
// 1.21.5+
|
||||
public static final Class<?> clazz$TransmuteResult =
|
||||
ReflectionUtils.getClazz(
|
||||
BukkitReflectionUtils.assembleMCClass("world.item.crafting.TransmuteResult")
|
||||
);
|
||||
|
||||
public static final Constructor<?> constructor$TransmuteResult = Optional.ofNullable(clazz$TransmuteResult)
|
||||
.map(it -> ReflectionUtils.getConstructor(it, clazz$Item))
|
||||
.orElse(null);
|
||||
|
||||
public static final Constructor<?> constructor$SmithingTransformRecipe = requireNonNull(
|
||||
VersionHelper.isVersionNewerThan1_21_2() ?
|
||||
ReflectionUtils.getConstructor(clazz$SmithingTransformRecipe, Optional.class, Optional.class, Optional.class, clazz$ItemStack) :
|
||||
VersionHelper.isVersionNewerThan1_20_2() ?
|
||||
ReflectionUtils.getConstructor(clazz$SmithingTransformRecipe, clazz$Ingredient, clazz$Ingredient, clazz$Ingredient, clazz$ItemStack) :
|
||||
ReflectionUtils.getConstructor(clazz$SmithingTransformRecipe, clazz$ResourceLocation, clazz$Ingredient, clazz$Ingredient, clazz$Ingredient, clazz$ItemStack)
|
||||
VersionHelper.isVersionNewerThan1_21_5()
|
||||
? ReflectionUtils.getConstructor(clazz$SmithingTransformRecipe, Optional.class, clazz$Ingredient, Optional.class, clazz$TransmuteResult)
|
||||
: VersionHelper.isVersionNewerThan1_21_2()
|
||||
? ReflectionUtils.getConstructor(clazz$SmithingTransformRecipe, Optional.class, Optional.class, Optional.class, clazz$ItemStack)
|
||||
: VersionHelper.isVersionNewerThan1_20_2()
|
||||
? ReflectionUtils.getConstructor(clazz$SmithingTransformRecipe, clazz$Ingredient, clazz$Ingredient, clazz$Ingredient, clazz$ItemStack)
|
||||
: ReflectionUtils.getConstructor(clazz$SmithingTransformRecipe, clazz$ResourceLocation, clazz$Ingredient, clazz$Ingredient, clazz$Ingredient, clazz$ItemStack)
|
||||
);
|
||||
|
||||
public static final Method method$RecipeManager$addRecipe = requireNonNull(
|
||||
@@ -5416,13 +5456,11 @@ public class Reflections {
|
||||
);
|
||||
|
||||
public static final Method method$SimpleWaterloggedBlock$canPlaceLiquid = requireNonNull(
|
||||
VersionHelper.isVersionNewerThan1_20_2() ?
|
||||
ReflectionUtils.getMethod(
|
||||
clazz$SimpleWaterloggedBlock, boolean.class, clazz$Player, clazz$BlockGetter, clazz$BlockPos, clazz$BlockState, clazz$Fluid
|
||||
) :
|
||||
ReflectionUtils.getMethod(
|
||||
clazz$SimpleWaterloggedBlock, boolean.class, clazz$BlockGetter, clazz$BlockPos, clazz$BlockState, clazz$Fluid
|
||||
)
|
||||
VersionHelper.isVersionNewerThan1_21_5()
|
||||
? ReflectionUtils.getMethod(clazz$SimpleWaterloggedBlock, boolean.class, clazz$LivingEntity, clazz$BlockGetter, clazz$BlockPos, clazz$BlockState, clazz$Fluid)
|
||||
: VersionHelper.isVersionNewerThan1_20_2()
|
||||
? ReflectionUtils.getMethod(clazz$SimpleWaterloggedBlock, boolean.class, clazz$Player, clazz$BlockGetter, clazz$BlockPos, clazz$BlockState, clazz$Fluid)
|
||||
: ReflectionUtils.getMethod(clazz$SimpleWaterloggedBlock, boolean.class, clazz$BlockGetter, clazz$BlockPos, clazz$BlockState, clazz$Fluid)
|
||||
);
|
||||
|
||||
public static final Method method$SimpleWaterloggedBlock$placeLiquid = requireNonNull(
|
||||
@@ -5432,13 +5470,11 @@ public class Reflections {
|
||||
);
|
||||
|
||||
public static final Method method$SimpleWaterloggedBlock$pickupBlock = requireNonNull(
|
||||
VersionHelper.isVersionNewerThan1_20_2() ?
|
||||
ReflectionUtils.getMethod(
|
||||
clazz$SimpleWaterloggedBlock, clazz$ItemStack, clazz$Player, clazz$LevelAccessor, clazz$BlockPos, clazz$BlockState
|
||||
) :
|
||||
ReflectionUtils.getMethod(
|
||||
clazz$SimpleWaterloggedBlock, clazz$ItemStack, clazz$LevelAccessor, clazz$BlockPos, clazz$BlockState
|
||||
)
|
||||
VersionHelper.isVersionNewerThan1_21_5()
|
||||
? ReflectionUtils.getMethod(clazz$SimpleWaterloggedBlock, clazz$ItemStack, clazz$LivingEntity, clazz$LevelAccessor, clazz$BlockPos, clazz$BlockState)
|
||||
: VersionHelper.isVersionNewerThan1_20_2()
|
||||
? ReflectionUtils.getMethod(clazz$SimpleWaterloggedBlock, clazz$ItemStack, clazz$Player, clazz$LevelAccessor, clazz$BlockPos, clazz$BlockState)
|
||||
: ReflectionUtils.getMethod(clazz$SimpleWaterloggedBlock, clazz$ItemStack, clazz$LevelAccessor, clazz$BlockPos, clazz$BlockState)
|
||||
);
|
||||
|
||||
public static final Method method$Fluid$getTickDelay = requireNonNull(
|
||||
|
||||
Reference in New Issue
Block a user