9
0
mirror of https://github.com/Xiao-MoMi/craft-engine.git synced 2026-01-03 22:26:16 +00:00
This commit is contained in:
XiaoMoMi
2025-04-05 13:35:25 +08:00
parent a83879086d
commit 6c7c1a9361
21 changed files with 135 additions and 122 deletions

View File

@@ -659,7 +659,7 @@ public class BukkitBlockManager extends AbstractBlockManager {
private void recordVanillaNoteBlocks() {
try {
Object resourceLocation = Reflections.method$ResourceLocation$fromNamespaceAndPath.invoke(null, BlockKeys.NOTE_BLOCK.namespace(), BlockKeys.NOTE_BLOCK.value());
Object resourceLocation = KeyUtils.toResourceLocation(BlockKeys.NOTE_BLOCK);
Object block = Reflections.method$Registry$get.invoke(Reflections.instance$BuiltInRegistries$BLOCK, resourceLocation);
Object stateDefinition = Reflections.field$Block$StateDefinition.get(block);
@SuppressWarnings("unchecked")

View File

@@ -2,6 +2,7 @@ package net.momirealms.craftengine.bukkit.block;
import net.momirealms.craftengine.bukkit.plugin.BukkitCraftEngine;
import net.momirealms.craftengine.bukkit.util.BlockStateUtils;
import net.momirealms.craftengine.bukkit.util.KeyUtils;
import net.momirealms.craftengine.bukkit.util.Reflections;
import net.momirealms.craftengine.bukkit.util.SoundUtils;
import net.momirealms.craftengine.core.block.*;
@@ -125,7 +126,7 @@ public class BukkitCustomBlock extends CustomBlock {
Object holder = BukkitCraftEngine.instance().blockManager().getMinecraftBlockHolder(state.customBlockState().registryId());
Set<Object> tags = new HashSet<>();
for (Key tag : settings.tags()) {
tags.add(Reflections.method$TagKey$create.invoke(null, Reflections.instance$Registries$BLOCK, Reflections.method$ResourceLocation$fromNamespaceAndPath.invoke(null, tag.namespace(), tag.value())));
tags.add(Reflections.method$TagKey$create.invoke(null, Reflections.instance$Registries$BLOCK, KeyUtils.toResourceLocation(tag)));
}
Reflections.field$Holder$Reference$tags.set(holder, tags);
// set burning properties

View File

@@ -8,6 +8,7 @@ import net.momirealms.craftengine.bukkit.item.behavior.WaterBucketItemBehavior;
import net.momirealms.craftengine.bukkit.item.factory.BukkitItemFactory;
import net.momirealms.craftengine.bukkit.plugin.BukkitCraftEngine;
import net.momirealms.craftengine.bukkit.util.ItemUtils;
import net.momirealms.craftengine.bukkit.util.KeyUtils;
import net.momirealms.craftengine.bukkit.util.MaterialUtils;
import net.momirealms.craftengine.bukkit.util.Reflections;
import net.momirealms.craftengine.core.entity.player.Player;
@@ -588,7 +589,7 @@ public class BukkitItemManager extends AbstractItemManager<ItemStack> {
.orElseGet(() -> ((WritableRegistry<Key>) BuiltInRegistries.OPTIMIZED_ITEM_ID)
.register(new ResourceKey<>(BuiltInRegistries.OPTIMIZED_ITEM_ID.key().location(), id), id));
Object resourceLocation = Reflections.method$ResourceLocation$fromNamespaceAndPath.invoke(null, id.namespace(), id.value());
Object resourceLocation = KeyUtils.toResourceLocation(id.namespace(), id.value());
Object mcHolder = ((Optional<Object>) Reflections.method$Registry$getHolder1.invoke(Reflections.instance$BuiltInRegistries$ITEM, Reflections.method$ResourceKey$create.invoke(null, Reflections.instance$Registries$ITEM, resourceLocation))).get();
Set<Object> tags = (Set<Object>) Reflections.field$Holder$Reference$tags.get(mcHolder);
for (Object tag : tags) {

View File

@@ -6,7 +6,9 @@ import com.saicone.rtag.item.ItemObject;
import com.saicone.rtag.tag.TagCompound;
import net.momirealms.craftengine.bukkit.item.BukkitItemManager;
import net.momirealms.craftengine.bukkit.item.CloneableConstantItem;
import net.momirealms.craftengine.bukkit.nms.FastNMS;
import net.momirealms.craftengine.bukkit.plugin.BukkitCraftEngine;
import net.momirealms.craftengine.bukkit.util.KeyUtils;
import net.momirealms.craftengine.bukkit.util.MaterialUtils;
import net.momirealms.craftengine.bukkit.util.RecipeUtils;
import net.momirealms.craftengine.bukkit.util.Reflections;
@@ -125,8 +127,7 @@ public class BukkitRecipeManager extends AbstractRecipeManager<ItemStack> {
nmsRecipe = Reflections.constructor$RecipeHolder.newInstance(
Reflections.method$CraftRecipe$toMinecraft.invoke(null, new NamespacedKey(id.namespace(), id.value())), nmsRecipe);
} else if (VersionHelper.isVersionNewerThan1_20_2()) {
nmsRecipe = Reflections.constructor$RecipeHolder.newInstance(
Reflections.method$ResourceLocation$fromNamespaceAndPath.invoke(null, id.namespace(), id.value()), nmsRecipe);
nmsRecipe = Reflections.constructor$RecipeHolder.newInstance(KeyUtils.toResourceLocation(id), nmsRecipe);
} else {
return () -> {};
}
@@ -693,7 +694,7 @@ public class BukkitRecipeManager extends AbstractRecipeManager<ItemStack> {
List<Object> itemStacks = new ArrayList<>();
for (Holder<Key> holder : holders) {
ItemStack itemStack = BukkitItemManager.instance().getBuildableItem(holder.value()).get().buildItemStack(ItemBuildContext.EMPTY, 1);
Object nmsStack = Reflections.method$CraftItemStack$asNMSCopy.invoke(null, itemStack);
Object nmsStack = FastNMS.INSTANCE.method$CraftItemStack$asNMSCopy(itemStack);
itemStacks.add(nmsStack);
}
return itemStacks;
@@ -779,7 +780,7 @@ public class BukkitRecipeManager extends AbstractRecipeManager<ItemStack> {
}
return optional.get();
} else {
Object resourceLocation = Reflections.method$ResourceLocation$fromNamespaceAndPath.invoke(null, id.namespace(), id.value());
Object resourceLocation = KeyUtils.toResourceLocation(id);
@SuppressWarnings("unchecked")
Optional<Object> optional = (Optional<Object>) Reflections.method$RecipeManager$byKey.invoke(nmsRecipeManager, resourceLocation);
if (optional.isEmpty()) {
@@ -837,7 +838,7 @@ public class BukkitRecipeManager extends AbstractRecipeManager<ItemStack> {
// 1.21.5+
private static Object toTransmuteResult(ItemStack item) throws InvocationTargetException, IllegalAccessException, InstantiationException {
Object itemStack = Reflections.method$CraftItemStack$asNMSCopy.invoke(null, item);
Object itemStack = FastNMS.INSTANCE.method$CraftItemStack$asNMSCopy(item);
Object nmsItem = Reflections.method$ItemStack$getItem.invoke(itemStack);
return Reflections.constructor$TransmuteResult.newInstance(nmsItem);
}
@@ -856,22 +857,22 @@ public class BukkitRecipeManager extends AbstractRecipeManager<ItemStack> {
toOptionalMinecraftIngredient(recipe.template()),
toOptionalMinecraftIngredient(recipe.base()),
toOptionalMinecraftIngredient(recipe.addition()),
Reflections.method$CraftItemStack$asNMSCopy.invoke(null, recipe.result(ItemBuildContext.EMPTY))
FastNMS.INSTANCE.method$CraftItemStack$asNMSCopy(recipe.result(ItemBuildContext.EMPTY))
);
} else if (VersionHelper.isVersionNewerThan1_20_2()) {
return Reflections.constructor$SmithingTransformRecipe.newInstance(
toMinecraftIngredient(recipe.template()),
toMinecraftIngredient(recipe.base()),
toMinecraftIngredient(recipe.addition()),
Reflections.method$CraftItemStack$asNMSCopy.invoke(null, recipe.result(ItemBuildContext.EMPTY))
FastNMS.INSTANCE.method$CraftItemStack$asNMSCopy(recipe.result(ItemBuildContext.EMPTY))
);
} else {
return Reflections.constructor$SmithingTransformRecipe.newInstance(
Reflections.method$ResourceLocation$fromNamespaceAndPath.invoke(null, recipe.id().namespace(), recipe.id().value()),
KeyUtils.toResourceLocation(recipe.id()),
toMinecraftIngredient(recipe.template()),
toMinecraftIngredient(recipe.base()),
toMinecraftIngredient(recipe.addition()),
Reflections.method$CraftItemStack$asNMSCopy.invoke(null, recipe.result(ItemBuildContext.EMPTY))
FastNMS.INSTANCE.method$CraftItemStack$asNMSCopy(recipe.result(ItemBuildContext.EMPTY))
);
}
}

View File

@@ -347,7 +347,7 @@ public class RecipeEventListener implements Listener {
Optional<Object> optionalMCRecipe = (Optional<Object>) Reflections.method$RecipeManager$getRecipeFor1.invoke(
BukkitRecipeManager.nmsRecipeManager(),
Reflections.instance$RecipeType$CAMPFIRE_COOKING,
Reflections.constructor$SingleRecipeInput.newInstance(Reflections.method$CraftItemStack$asNMSCopy.invoke(null, itemStack)),
Reflections.constructor$SingleRecipeInput.newInstance(FastNMS.INSTANCE.method$CraftItemStack$asNMSCopy(itemStack)),
FastNMS.INSTANCE.field$CraftWorld$ServerLevel(event.getPlayer().getWorld()),
null
);

View File

@@ -537,10 +537,9 @@ public class BukkitNetworkManager implements NetworkManager, Listener, PluginMes
handleNMSPacket(user, event, packet);
}
@SuppressWarnings("unchecked")
private void onNMSPacketSend(NetWorkUser player, NMSPacketEvent event, Object packet) throws ReflectiveOperationException {
private void onNMSPacketSend(NetWorkUser player, NMSPacketEvent event, Object packet) {
if (Reflections.clazz$ClientboundBundlePacket.isInstance(packet)) {
Iterable<Object> packets = (Iterable<Object>) Reflections.field$BundlePacket$packets.get(packet);
Iterable<Object> packets = FastNMS.INSTANCE.method$ClientboundBundlePacket$subPackets(packet);
for (Object p : packets) {
onNMSPacketSend(player, event, p);
}

View File

@@ -251,10 +251,10 @@ public class PacketConsumers {
writeMethod = Reflections.method$Packet$write;
}
Object packet = Reflections.constructor$ClientboundLevelParticlesPacket.newInstance(mcByteBuf);
Object option = Reflections.field$ClientboundLevelParticlesPacket$particle.get(packet);
Object option = FastNMS.INSTANCE.field$ClientboundLevelParticlesPacket$particle(packet);
if (option == null) return;
if (!Reflections.clazz$BlockParticleOption.isInstance(option)) return;
Object blockState = Reflections.field$BlockParticleOption$blockState.get(option);
Object blockState = FastNMS.INSTANCE.field$BlockParticleOption$blockState(option);
int id = BlockStateUtils.blockStateToId(blockState);
int remapped = remap(id);
if (remapped == id) return;
@@ -274,7 +274,7 @@ public class PacketConsumers {
BukkitServerPlayer player = (BukkitServerPlayer) user;
Player platformPlayer = player.platformPlayer();
World world = platformPlayer.getWorld();
Object blockPos = Reflections.field$ServerboundPlayerActionPacket$pos.get(packet);
Object blockPos = FastNMS.INSTANCE.field$ServerboundPlayerActionPacket$pos(packet);
BlockPos pos = LocationUtils.fromBlockPos(blockPos);
if (VersionHelper.isFolia()) {
BukkitCraftEngine.instance().scheduler().sync().run(() -> {
@@ -293,7 +293,7 @@ public class PacketConsumers {
};
private static void handlePlayerActionPacketOnMainThread(BukkitServerPlayer player, World world, BlockPos pos, Object packet) throws Exception {
Object action = Reflections.field$ServerboundPlayerActionPacket$action.get(packet);
Object action = FastNMS.INSTANCE.field$ServerboundPlayerActionPacket$action(packet);
if (action == Reflections.instance$ServerboundPlayerActionPacket$Action$START_DESTROY_BLOCK) {
Object serverLevel = FastNMS.INSTANCE.field$CraftWorld$ServerLevel(world);
Object blockState = FastNMS.INSTANCE.method$BlockGetter$getBlockState(serverLevel, LocationUtils.toBlockPos(pos));
@@ -313,7 +313,7 @@ public class PacketConsumers {
return;
}
if (player.isAdventureMode()) {
Object itemStack = Reflections.method$CraftItemStack$asNMSCopy.invoke(null, player.platformPlayer().getInventory().getItemInMainHand());
Object itemStack = FastNMS.INSTANCE.method$CraftItemStack$asNMSCopy(player.platformPlayer().getInventory().getItemInMainHand());
Object blockPos = LocationUtils.toBlockPos(pos);
Object blockInWorld = Reflections.constructor$BlockInWorld.newInstance(serverLevel, blockPos, false);
if (VersionHelper.isVersionNewerThan1_20_5()) {
@@ -375,6 +375,7 @@ public class PacketConsumers {
public static final TriConsumer<NetWorkUser, NMSPacketEvent, Object> RESPAWN = (user, event, packet) -> {
try {
BukkitServerPlayer player = (BukkitServerPlayer) user;
player.clearView();
Object dimensionKey;
if (!VersionHelper.isVersionNewerThan1_20_2()) {
dimensionKey = Reflections.field$ClientboundRespawnPacket$dimension.get(packet);
@@ -606,22 +607,22 @@ public class PacketConsumers {
}
assert Reflections.method$ServerGamePacketListenerImpl$tryPickItem != null;
Reflections.method$ServerGamePacketListenerImpl$tryPickItem.invoke(
Reflections.field$ServerPlayer$connection.get(FastNMS.INSTANCE.method$CraftPlayer$getHandle(player)), Reflections.method$CraftItemStack$asNMSCopy.invoke(null, itemStack));
Reflections.field$ServerPlayer$connection.get(FastNMS.INSTANCE.method$CraftPlayer$getHandle(player)), FastNMS.INSTANCE.method$CraftItemStack$asNMSCopy(itemStack));
}
public static final TriConsumer<NetWorkUser, NMSPacketEvent, Object> ADD_ENTITY = (user, event, packet) -> {
try {
Object entityType = Reflections.field$ClientboundAddEntityPacket$type.get(packet);
Object entityType = FastNMS.INSTANCE.field$ClientboundAddEntityPacket$type(packet);
// Falling blocks
if (entityType == Reflections.instance$EntityType$FALLING_BLOCK) {
int data = Reflections.field$ClientboundAddEntityPacket$data.getInt(packet);
int data = FastNMS.INSTANCE.field$ClientboundAddEntityPacket$data(packet);
int remapped = remap(data);
if (remapped != data) {
Reflections.field$ClientboundAddEntityPacket$data.set(packet, remapped);
}
} else if (entityType == Reflections.instance$EntityType$ITEM_DISPLAY) {
// Furniture
int entityId = (int) Reflections.field$ClientboundAddEntityPacket$entityId.get(packet);
int entityId = FastNMS.INSTANCE.field$ClientboundAddEntityPacket$entityId(packet);
LoadedFurniture furniture = BukkitFurnitureManager.instance().loadedFurnitureByRealEntityId(entityId);
if (furniture != null) {
user.furnitureView().computeIfAbsent(furniture.baseEntityId(), k -> new ArrayList<>()).addAll(furniture.fakeEntityIds());
@@ -632,13 +633,13 @@ public class PacketConsumers {
}
} else if (entityType == Reflections.instance$EntityType$SHULKER) {
// Cancel collider entity packet
int entityId = (int) Reflections.field$ClientboundAddEntityPacket$entityId.get(packet);
int entityId = FastNMS.INSTANCE.field$ClientboundAddEntityPacket$entityId(packet);
LoadedFurniture furniture = BukkitFurnitureManager.instance().loadedFurnitureByRealEntityId(entityId);
if (furniture != null) {
event.setCancelled(true);
}
} else if (entityType == Reflections.instance$EntityType$BLOCK_DISPLAY) {
int entityId = (int) Reflections.field$ClientboundAddEntityPacket$entityId.get(packet);
int entityId = FastNMS.INSTANCE.field$ClientboundAddEntityPacket$entityId(packet);
user.entityView().put(entityId, entityType);
}
} catch (Exception e) {
@@ -646,6 +647,7 @@ public class PacketConsumers {
}
};
// 1.21.3+
public static final TriConsumer<NetWorkUser, NMSPacketEvent, Object> SYNC_ENTITY_POSITION = (user, event, packet) -> {
try {
int entityId = (int) Reflections.field$ClientboundEntityPositionSyncPacket$id.get(packet);
@@ -670,7 +672,7 @@ public class PacketConsumers {
public static final TriConsumer<NetWorkUser, NMSPacketEvent, Object> REMOVE_ENTITY = (user, event, packet) -> {
try {
IntList intList = (IntList) Reflections.field$ClientboundRemoveEntitiesPacket$entityIds.get(packet);
IntList intList = FastNMS.INSTANCE.field$ClientboundRemoveEntitiesPacket$entityIds(packet);
for (int i = 0, size = intList.size(); i < size; i++) {
List<Integer> entities = user.furnitureView().remove(intList.getInt(i));
if (entities == null) continue;
@@ -689,16 +691,16 @@ public class PacketConsumers {
if (player == null) return;
int entityId;
if (BukkitNetworkManager.hasModelEngine()) {
int fakeId = (int) Reflections.field$ServerboundInteractPacket$entityId.get(packet);
int fakeId = FastNMS.INSTANCE.field$ServerboundInteractPacket$entityId(packet);
entityId = ModelEngineUtils.interactionToBaseEntity(fakeId);
} else {
entityId = Reflections.field$ServerboundInteractPacket$entityId.getInt(packet);
entityId = FastNMS.INSTANCE.field$ServerboundInteractPacket$entityId(packet);
}
LoadedFurniture furniture = BukkitFurnitureManager.instance().loadedFurnitureByEntityId(entityId);
if (furniture == null) return;
Object action = Reflections.field$ServerboundInteractPacket$action.get(packet);
Object actionType = Reflections.method$ServerboundInteractPacket$Action$getType.invoke(action);
if (actionType == null) return;
LoadedFurniture furniture = BukkitFurnitureManager.instance().loadedFurnitureByEntityId(entityId);
if (furniture == null) return;
Location location = furniture.baseEntity().getLocation();
BukkitServerPlayer serverPlayer = (BukkitServerPlayer) user;
if (serverPlayer.isSpectatorMode() || serverPlayer.isAdventureMode()) return;
@@ -721,9 +723,10 @@ public class PacketConsumers {
Object interactionHand = Reflections.field$ServerboundInteractPacket$InteractionAtLocationAction$hand.get(action);
hand = interactionHand == Reflections.instance$InteractionHand$MAIN_HAND ? InteractionHand.MAIN_HAND : InteractionHand.OFF_HAND;
Object vec3 = Reflections.field$ServerboundInteractPacket$InteractionAtLocationAction$location.get(action);
double x = (double) Reflections.field$Vec3$x.get(vec3);
double y = (double) Reflections.field$Vec3$y.get(vec3);
double z = (double) Reflections.field$Vec3$z.get(vec3);
double x = FastNMS.INSTANCE.field$Vec3$x(vec3);
double y = FastNMS.INSTANCE.field$Vec3$y(vec3);
double z = FastNMS.INSTANCE.field$Vec3$z(vec3);
interactionPoint = new Location(location.getWorld(), x, y, z);
} catch (ReflectiveOperationException e) {
throw new RuntimeException("Failed to get interaction hand from interact packet", e);
@@ -748,25 +751,15 @@ public class PacketConsumers {
public static final TriConsumer<NetWorkUser, NMSPacketEvent, Object> SOUND = (user, event, packet) -> {
try {
Object sound = Reflections.field$ClientboundSoundPacket$sound.get(packet);
Object soundEvent = Reflections.method$Holder$value.invoke(sound);
Key mapped = BukkitBlockManager.instance().replaceSoundIfExist(Key.of(Reflections.field$SoundEvent$location.get(soundEvent).toString()));
Object soundEvent = FastNMS.INSTANCE.field$ClientboundSoundPacket$soundEvent(packet);
Key mapped = BukkitBlockManager.instance().replaceSoundIfExist(Key.of(FastNMS.INSTANCE.field$SoundEvent$location(soundEvent).toString()));
if (mapped != null) {
event.setCancelled(true);
Object newId = Reflections.method$ResourceLocation$fromNamespaceAndPath.invoke(null, mapped.namespace(), mapped.value());
Object newId = FastNMS.INSTANCE.method$ResourceLocation$fromNamespaceAndPath(mapped.namespace(), mapped.value());
Object newSoundEvent = VersionHelper.isVersionNewerThan1_21_2() ?
Reflections.constructor$SoundEvent.newInstance(newId, Reflections.field$SoundEvent$fixedRange.get(soundEvent)) :
Reflections.constructor$SoundEvent.newInstance(newId, Reflections.field$SoundEvent$range.get(soundEvent), Reflections.field$SoundEvent$newSystem.get(soundEvent));
Object newSoundPacket = Reflections.constructor$ClientboundSoundPacket.newInstance(
Reflections.method$Holder$direct.invoke(null, newSoundEvent),
Reflections.field$ClientboundSoundPacket$source.get(packet),
(double) Reflections.field$ClientboundSoundPacket$x.getInt(packet) / 8,
(double) Reflections.field$ClientboundSoundPacket$y.getInt(packet) / 8,
(double) Reflections.field$ClientboundSoundPacket$z.getInt(packet) / 8,
Reflections.field$ClientboundSoundPacket$volume.get(packet),
Reflections.field$ClientboundSoundPacket$pitch.get(packet),
Reflections.field$ClientboundSoundPacket$seed.get(packet)
);
Object newSoundPacket = FastNMS.INSTANCE.fastConstructor$ClientboundSoundPacket(newSoundEvent, packet);
user.sendPacket(newSoundPacket, true);
}
} catch (Exception e) {
@@ -965,22 +958,19 @@ public class PacketConsumers {
}
};
@SuppressWarnings("unchecked")
public static final TriConsumer<NetWorkUser, NMSPacketEvent, Object> SET_ENTITY_DATA = (user, event, packet) -> {
try {
int id = (int) Reflections.field$ClientboundSetEntityDataPacket$id.get(packet);
int id = FastNMS.INSTANCE.field$ClientboundSetEntityDataPacket$id(packet);
Object entityType = user.entityView().get(id);
if (entityType == Reflections.instance$EntityType$BLOCK_DISPLAY) {
List<Object> packedItems = (List<Object>) Reflections.field$ClientboundSetEntityDataPacket$packedItems.get(packet);
List<Object> packedItems = FastNMS.INSTANCE.field$ClientboundSetEntityDataPacket$packedItems(packet);
for (int i = 0; i < packedItems.size(); i++) {
Object packedItem = packedItems.get(i);
int entityDataId = (int) Reflections.field$SynchedEntityData$DataValue$id.get(packedItem);
if ((VersionHelper.isVersionNewerThan1_20_2() && entityDataId != 23)
|| (!VersionHelper.isVersionNewerThan1_20_2() && entityDataId != 22)) {
int entityDataId = FastNMS.INSTANCE.field$SynchedEntityData$DataValue$id(packedItem);
if (entityDataId != EntityDataUtils.BLOCK_STATE_DATA_ID) {
continue;
}
Object blockState = Reflections.field$SynchedEntityData$DataValue$value.get(packedItem);
Object serializer = Reflections.field$SynchedEntityData$DataValue$serializer.get(packedItem);
Object blockState = FastNMS.INSTANCE.field$SynchedEntityData$DataValue$value(packedItem);
int stateId = BlockStateUtils.blockStateToId(blockState);
int newStateId;
if (!user.clientModEnabled()) {
@@ -988,7 +978,8 @@ public class PacketConsumers {
} else {
newStateId = remapMOD(stateId);
}
packedItems.set(i, Reflections.constructor$SynchedEntityData$DataValue.newInstance(
Object serializer = FastNMS.INSTANCE.field$SynchedEntityData$DataValue$serializer(packedItem);
packedItems.set(i, FastNMS.INSTANCE.constructor$SynchedEntityData$DataValue(
entityDataId, serializer, BlockStateUtils.idToBlockState(newStateId)
));
break;

View File

@@ -69,8 +69,9 @@ public class BukkitServerPlayer extends Player {
private boolean hasClientMod = false;
// for better fake furniture visual sync
// TODO CLEAR ENTITY VIEW
private final Map<Integer, List<Integer>> furnitureView = new ConcurrentHashMap<>();
private final Map<Integer, Object> entityView = new ConcurrentHashMap<>();
private final Map<Integer, Object> entityTypeView = new ConcurrentHashMap<>();
public BukkitServerPlayer(BukkitCraftEngine plugin, Channel channel) {
this.channel = channel;
@@ -344,7 +345,7 @@ public class BukkitServerPlayer extends Player {
} else {
if (VersionHelper.isVersionNewerThan1_20_5()) {
Object attributeModifier = VersionHelper.isVersionNewerThan1_21() ?
Reflections.constructor$AttributeModifier.newInstance(Reflections.method$ResourceLocation$fromNamespaceAndPath.invoke(null, "craftengine", "custom_hardness"), -9999d, Reflections.instance$AttributeModifier$Operation$ADD_VALUE) :
Reflections.constructor$AttributeModifier.newInstance(KeyUtils.toResourceLocation("craftengine", "custom_hardness"), -9999d, Reflections.instance$AttributeModifier$Operation$ADD_VALUE) :
Reflections.constructor$AttributeModifier.newInstance(UUID.randomUUID(), "craftengine:custom_hardness", -9999d, Reflections.instance$AttributeModifier$Operation$ADD_VALUE);
Object attributeSnapshot = Reflections.constructor$ClientboundUpdateAttributesPacket$AttributeSnapshot.newInstance(Reflections.instance$Holder$Attribute$block_break_speed, 1d, Lists.newArrayList(attributeModifier));
Object newPacket = Reflections.constructor$ClientboundUpdateAttributesPacket1.newInstance(entityID(), Lists.newArrayList(attributeSnapshot));
@@ -621,7 +622,7 @@ public class BukkitServerPlayer extends Player {
@Override
public Map<Integer, Object> entityView() {
return this.entityView;
return this.entityTypeView;
}
public void setResendSound() {
@@ -655,4 +656,10 @@ public class BukkitServerPlayer extends Player {
public void setClientModState(boolean enable) {
this.hasClientMod = enable;
}
@Override
public void clearView() {
this.entityTypeView.clear();
this.furnitureView.clear();
}
}

View File

@@ -1,6 +1,7 @@
package net.momirealms.craftengine.bukkit.sound;
import net.momirealms.craftengine.bukkit.util.ComponentUtils;
import net.momirealms.craftengine.bukkit.util.KeyUtils;
import net.momirealms.craftengine.bukkit.util.Reflections;
import net.momirealms.craftengine.core.plugin.CraftEngine;
import net.momirealms.craftengine.core.sound.AbstractSoundManager;
@@ -26,8 +27,8 @@ public class BukkitSoundManager extends AbstractSoundManager {
for (Map.Entry<Key, JukeboxSong> entry : songs.entrySet()) {
Key id = entry.getKey();
JukeboxSong jukeboxSong = entry.getValue();
Object resourceLocation = Reflections.method$ResourceLocation$fromNamespaceAndPath.invoke(null, id.namespace(), id.value());
Object soundId = Reflections.method$ResourceLocation$fromNamespaceAndPath.invoke(null, jukeboxSong.sound().namespace(), jukeboxSong.sound().value());
Object resourceLocation = KeyUtils.toResourceLocation(id);
Object soundId = KeyUtils.toResourceLocation(jukeboxSong.sound());
Object song = Reflections.method$Registry$get.invoke(Reflections.instance$InternalRegistries$JUKEBOX_SONG, resourceLocation);
Object soundEvent = VersionHelper.isVersionNewerThan1_21_2() ?

View File

@@ -63,7 +63,7 @@ public class BlockStateUtils {
@SuppressWarnings("unchecked")
public static List<Object> getAllVanillaBlockStates(Key block) {
try {
Object blockIns = Reflections.method$Registry$get.invoke(Reflections.instance$BuiltInRegistries$BLOCK, Reflections.method$ResourceLocation$fromNamespaceAndPath.invoke(null, block.namespace(), block.value()));
Object blockIns = Reflections.method$Registry$get.invoke(Reflections.instance$BuiltInRegistries$BLOCK, KeyUtils.toResourceLocation(block));
Object definition = Reflections.field$Block$StateDefinition.get(blockIns);
return (List<Object>) Reflections.field$StateDefinition$states.get(definition);
} catch (Exception e) {

View File

@@ -14,7 +14,7 @@ public class BlockTags {
Object value = CACHE.get(key);
if (value == null) {
try {
value = Reflections.method$TagKey$create.invoke(null, Reflections.instance$Registries$BLOCK, Reflections.method$ResourceLocation$fromNamespaceAndPath.invoke(null, key.namespace(), key.value()));
value = Reflections.method$TagKey$create.invoke(null, Reflections.instance$Registries$BLOCK, KeyUtils.toResourceLocation(key));
CACHE.put(key, value);
return value;
} catch (Exception e) {

View File

@@ -1,5 +1,7 @@
package net.momirealms.craftengine.bukkit.util;
import net.momirealms.craftengine.core.util.VersionHelper;
public class EntityDataUtils {
private EntityDataUtils() {}
@@ -9,6 +11,7 @@ public class EntityDataUtils {
private static final int USE_DEFAULT_BACKGROUND = 0x04; // 4
private static final int LEFT_ALIGNMENT = 0x08; // 8
private static final int RIGHT_ALIGNMENT = 0x10; // 16
public static final int BLOCK_STATE_DATA_ID = VersionHelper.isVersionNewerThan1_20_2() ? 23 : 22;
public static byte encodeTextDisplayMask(boolean hasShadow, boolean isSeeThrough, boolean useDefaultBackground, int alignment) {
int bitMask = 0;

View File

@@ -8,7 +8,7 @@ public class FeatureUtils {
public static Object createFeatureKey(Key id) {
try {
return Reflections.method$ResourceKey$create.invoke(null, Reflections.instance$Registries$CONFIGURED_FEATURE, Reflections.method$ResourceLocation$fromNamespaceAndPath.invoke(null, id.namespace(), id.value()));
return Reflections.method$ResourceKey$create.invoke(null, Reflections.instance$Registries$CONFIGURED_FEATURE, KeyUtils.toResourceLocation(id));
} catch (ReflectiveOperationException e) {
throw new RuntimeException(e);
}

View File

@@ -17,7 +17,7 @@ public class ItemTags {
Object value = CACHE.get(key);
if (value == null) {
try {
value = Reflections.method$TagKey$create.invoke(null, Reflections.instance$Registries$ITEM, Reflections.method$ResourceLocation$fromNamespaceAndPath.invoke(null, key.namespace(), key.value()));
value = Reflections.method$TagKey$create.invoke(null, Reflections.instance$Registries$ITEM, KeyUtils.toResourceLocation(key));
CACHE.put(key, value);
return value;
} catch (Exception e) {

View File

@@ -1,5 +1,6 @@
package net.momirealms.craftengine.bukkit.util;
import net.momirealms.craftengine.bukkit.nms.FastNMS;
import net.momirealms.craftengine.core.util.Key;
import org.bukkit.NamespacedKey;
@@ -14,4 +15,12 @@ public class KeyUtils {
public static Key adventureKey2Key(net.kyori.adventure.key.Key key) {
return Key.of(key.namespace(), key.value());
}
public static Object toResourceLocation(String namespace, String path) {
return FastNMS.INSTANCE.method$ResourceLocation$fromNamespaceAndPath(namespace, path);
}
public static Object toResourceLocation(Key key) {
return toResourceLocation(key.namespace(), key.value());
}
}

View File

@@ -152,8 +152,8 @@ public class PlayerUtils {
ItemStack offhandItem = player.getInventory().getItemInOffHand();
List<Object> packets = new ArrayList<>();
try {
Object previousItem = Reflections.method$CraftItemStack$asNMSCopy.invoke(null, offhandItem);
Object totemItem = Reflections.method$CraftItemStack$asNMSCopy.invoke(null, totem);
Object previousItem = FastNMS.INSTANCE.method$CraftItemStack$asNMSCopy(offhandItem);
Object totemItem = FastNMS.INSTANCE.method$CraftItemStack$asNMSCopy(totem);
Object packet1 = Reflections.constructor$ClientboundSetEquipmentPacket
.newInstance(player.getEntityId(), List.of(Pair.of(Reflections.instance$EquipmentSlot$OFFHAND, totemItem)));

View File

@@ -564,11 +564,11 @@ public class Reflections {
)
);
public static final Field field$ClientboundRemoveEntitiesPacket$entityIds = requireNonNull(
ReflectionUtils.getInstanceDeclaredField(
clazz$ClientboundRemoveEntitiesPacket, 0
)
);
// public static final Field field$ClientboundRemoveEntitiesPacket$entityIds = requireNonNull(
// ReflectionUtils.getInstanceDeclaredField(
// clazz$ClientboundRemoveEntitiesPacket, 0
// )
// );
public static final Field field$ClientboundAddEntityPacket$entityId = requireNonNull(
ReflectionUtils.getDeclaredField(
@@ -792,35 +792,35 @@ public class Reflections {
}
}
public static final Field field$ClientboundSetEntityDataPacket$id = requireNonNull(
ReflectionUtils.getDeclaredField(
clazz$ClientboundSetEntityDataPacket, int.class, 0
)
);
// public static final Field field$ClientboundSetEntityDataPacket$id = requireNonNull(
// ReflectionUtils.getDeclaredField(
// clazz$ClientboundSetEntityDataPacket, int.class, 0
// )
// );
public static final Field field$ClientboundSetEntityDataPacket$packedItems = requireNonNull(
ReflectionUtils.getDeclaredField(
clazz$ClientboundSetEntityDataPacket, List.class, 0
)
);
// public static final Field field$ClientboundSetEntityDataPacket$packedItems = requireNonNull(
// ReflectionUtils.getDeclaredField(
// clazz$ClientboundSetEntityDataPacket, List.class, 0
// )
// );
public static final Field field$SynchedEntityData$DataValue$id = requireNonNull(
ReflectionUtils.getDeclaredField(
clazz$SynchedEntityData$DataValue, int.class, 0
)
);
// public static final Field field$SynchedEntityData$DataValue$id = requireNonNull(
// ReflectionUtils.getDeclaredField(
// clazz$SynchedEntityData$DataValue, int.class, 0
// )
// );
public static final Field field$SynchedEntityData$DataValue$serializer = requireNonNull(
ReflectionUtils.getDeclaredField(
clazz$SynchedEntityData$DataValue, 1
)
);
public static final Field field$SynchedEntityData$DataValue$value = requireNonNull(
ReflectionUtils.getDeclaredField(
clazz$SynchedEntityData$DataValue, 2
)
);
// public static final Field field$SynchedEntityData$DataValue$serializer = requireNonNull(
// ReflectionUtils.getDeclaredField(
// clazz$SynchedEntityData$DataValue, 1
// )
// );
//
// public static final Field field$SynchedEntityData$DataValue$value = requireNonNull(
// ReflectionUtils.getDeclaredField(
// clazz$SynchedEntityData$DataValue, 2
// )
// );
public static final Class<?> clazz$ClientboundUpdateAttributesPacket = requireNonNull(
ReflectionUtils.getClazz(
@@ -3140,11 +3140,11 @@ public class Reflections {
}
}
public static final Field field$ServerboundInteractPacket$entityId = requireNonNull(
ReflectionUtils.getInstanceDeclaredField(
clazz$ServerboundInteractPacket, int.class, 0
)
);
// public static final Field field$ServerboundInteractPacket$entityId = requireNonNull(
// ReflectionUtils.getInstanceDeclaredField(
// clazz$ServerboundInteractPacket, int.class, 0
// )
// );
public static final Field field$ServerboundInteractPacket$usingSecondaryAction = requireNonNull(
ReflectionUtils.getInstanceDeclaredField(
@@ -3354,11 +3354,11 @@ public class Reflections {
)
);
public static final Method method$CraftItemStack$asNMSCopy = requireNonNull(
ReflectionUtils.getStaticMethod(
clazz$CraftItemStack, clazz$ItemStack, new String[]{"asNMSCopy"}, ItemStack.class
)
);
// public static final Method method$CraftItemStack$asNMSCopy = requireNonNull(
// ReflectionUtils.getStaticMethod(
// clazz$CraftItemStack, clazz$ItemStack, new String[]{"asNMSCopy"}, ItemStack.class
// )
// );
public static final Field field$Holder$Reference$tags = requireNonNull(
ReflectionUtils.getDeclaredField(
@@ -6099,11 +6099,11 @@ public class Reflections {
)
);
public static final Constructor<?> constructor$SynchedEntityData$DataValue = requireNonNull(
ReflectionUtils.getConstructor(
clazz$SynchedEntityData$DataValue, int.class, clazz$EntityDataSerializer, Object.class
)
);
// public static final Constructor<?> constructor$SynchedEntityData$DataValue = requireNonNull(
// ReflectionUtils.getConstructor(
// clazz$SynchedEntityData$DataValue, int.class, clazz$EntityDataSerializer, Object.class
// )
// );
public static final Class<?> clazz$EntityLookup = requireNonNull(
ReflectionUtils.getClazz(

View File

@@ -19,8 +19,6 @@ public class SoundUtils {
}
public static Object getOrRegisterSoundEvent(Key key) throws ReflectiveOperationException {
return Reflections.method$SoundEvent$createVariableRangeEvent.invoke(null,
Reflections.method$ResourceLocation$fromNamespaceAndPath.invoke(null, key.namespace(), key.value())
);
return Reflections.method$SoundEvent$createVariableRangeEvent.invoke(null, KeyUtils.toResourceLocation(key));
}
}

View File

@@ -74,4 +74,6 @@ public abstract class Player extends Entity implements NetWorkUser {
public abstract void closeInventory();
public abstract BlockHitResult rayTrace(double distance, FluidCollisionRule collisionRule);
public abstract void clearView();
}

View File

@@ -37,9 +37,9 @@ public interface NetWorkUser {
Map<Integer, List<Integer>> furnitureView();
Map<Integer, Object> entityView();
boolean clientModEnabled();
void setClientModState(boolean enable);
Map<Integer, Object> entityView();
}

View File

@@ -41,7 +41,7 @@ geantyref_version=1.3.16
zstd_version=1.5.7-2
commons_io_version=2.18.0
sparrow_nbt_version=0.3
sparrow_util_version=0.36
sparrow_util_version=0.37
fastutil_version=8.5.15
netty_version=4.1.119.Final
joml_version=1.10.8
@@ -51,7 +51,7 @@ byte_buddy_version=1.17.5
ahocorasick_version=0.6.3
snake_yaml_version=2.4
anti_grief_version=0.13
nms_helper_version=0.34
nms_helper_version=0.37
# Ignite Dependencies
mixinextras_version=0.4.1
mixin_version=0.15.2+mixin.0.8.7