9
0
mirror of https://github.com/Xiao-MoMi/craft-engine.git synced 2025-12-25 18:09:27 +00:00

fix(network): 修复 1.21.6 debug_item_data 错误

This commit is contained in:
jhqwqmc
2025-06-16 22:11:12 +08:00
parent 253e64857e
commit 5a86f65379
5 changed files with 51 additions and 29 deletions

View File

@@ -1,10 +1,10 @@
package net.momirealms.craftengine.bukkit.plugin.command.feature;
import com.saicone.rtag.RtagMirror;
import com.saicone.rtag.item.ItemObject;
import com.saicone.rtag.tag.TagCompound;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.format.NamedTextColor;
import net.momirealms.craftengine.bukkit.nms.FastNMS;
import net.momirealms.craftengine.bukkit.plugin.command.BukkitCommandFeature;
import net.momirealms.craftengine.bukkit.util.ItemUtils;
import net.momirealms.craftengine.core.plugin.CraftEngine;
@@ -55,20 +55,7 @@ public class DebugItemDataCommand extends BukkitCommandFeature<CommandSender> {
}
private static Map<String, Object> toMap(ItemStack object) {
return TagCompound.getValue(RtagMirror.INSTANCE, toCompound(object));
}
private static Object toCompound(ItemStack object) {
if (object == null) {
return null;
} else {
Object compound = extract(object);
return TagCompound.isTagCompound(compound) ? compound : null;
}
}
private static Object extract(ItemStack object) {
return ItemObject.save(ItemObject.asNMSCopy(object));
return TagCompound.getValue(RtagMirror.INSTANCE, FastNMS.INSTANCE.itemStackToCompoundTag(object));
}
private List<String> mapToList(Map<String, Object> readableDataMap) {

View File

@@ -1,16 +1,22 @@
package net.momirealms.craftengine.bukkit.plugin.command.feature;
import net.momirealms.craftengine.bukkit.nms.FastNMS;
import net.momirealms.craftengine.bukkit.plugin.command.BukkitCommandFeature;
import net.momirealms.craftengine.bukkit.plugin.reflection.minecraft.CoreReflections;
import net.momirealms.craftengine.bukkit.plugin.reflection.minecraft.MEntityTypes;
import net.momirealms.craftengine.bukkit.plugin.reflection.minecraft.NetworkReflections;
import net.momirealms.craftengine.core.plugin.CraftEngine;
import net.momirealms.craftengine.core.plugin.command.CraftEngineCommandManager;
import org.bukkit.Location;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.incendo.cloud.Command;
import org.incendo.cloud.parser.standard.BooleanParser;
import org.incendo.cloud.parser.standard.FloatParser;
import org.incendo.cloud.bukkit.parser.location.LocationParser;
import org.incendo.cloud.parser.standard.StringArrayParser;
import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
public class TestCommand extends BukkitCommandFeature<CommandSender> {
@@ -22,17 +28,38 @@ public class TestCommand extends BukkitCommandFeature<CommandSender> {
public Command.Builder<? extends CommandSender> assembleCommand(org.incendo.cloud.CommandManager<CommandSender> manager, Command.Builder<CommandSender> builder) {
return builder
.senderType(Player.class)
.required("tickRate", FloatParser.floatParser())
.required("isFrozen", BooleanParser.booleanParser())
.required("location", LocationParser.locationParser())
// .required("remove", StringArrayParser.stringArrayParser())
.handler(context -> {
Player player = context.sender();
float tickRate = context.get("tickRate");
boolean isFrozen = context.get("isFrozen");
try {
plugin().adapt(player).sendPacket(NetworkReflections.constructor$ClientboundTickingStatePacket.newInstance(tickRate, isFrozen), true);
} catch (InstantiationException | InvocationTargetException | IllegalAccessException e) {
player.sendMessage("发送失败");
}
// String[] removeEntityIds = context.get("remove");
// int removeHitboxId = Integer.parseInt(removeEntityIds[0]);
// int removePlayerId = Integer.parseInt(removeEntityIds[1]);
// if (removeHitboxId >= 0 && removePlayerId >= 0) {
// try {
// Object packet = NetworkReflections.constructor$ClientboundRemoveEntitiesPacket.newInstance((Object) new int[]{removeHitboxId, removePlayerId});
// plugin().adapt(player).sendPacket(packet, true);
// player.sendMessage("发送成功");
// } catch (ReflectiveOperationException e) {
// player.sendMessage("发送失败");
// }
// return;
// }
Location location = context.get("location");
// int hitboxId = CoreReflections.instance$Entity$ENTITY_COUNTER.incrementAndGet();
int playerId = CoreReflections.instance$Entity$ENTITY_COUNTER.incrementAndGet();
List<Object> packets = new ArrayList<>();
// packets.add(FastNMS.INSTANCE.constructor$ClientboundAddEntityPacket(
// hitboxId, UUID.randomUUID(), location.x(), location.y(), location.z(), 0, location.getYaw(),
// MEntityTypes.HAPPY_GHAST, 0, CoreReflections.instance$Vec3$Zero, 0
// ));
packets.add(FastNMS.INSTANCE.constructor$ClientboundAddEntityPacket(
playerId, UUID.randomUUID(), location.x(), location.y()/* + 4*/, location.z(), 0, location.getYaw(),
MEntityTypes.PLAYER, 0, CoreReflections.instance$Vec3$Zero, 0
));
player.sendMessage("player: " + MEntityTypes.PLAYER);
plugin().adapt(player).sendPackets(packets, true);
player.sendMessage("发送成功 id: [" + /*hitboxId + ", " +*/ playerId + "]");
});
}

View File

@@ -51,6 +51,10 @@ public final class MEntityTypes {
public static final int EXPERIENCE_BOTTLE$registryId;
public static final Object POTION;
public static final int POTION$registryId;
public static final Object HAPPY_GHAST;
public static final int HAPPY_GHAST$registryId;
public static final Object PLAYER;
public static final int PLAYER$registryId;
private static Object getById(String id) throws ReflectiveOperationException {
Object rl = FastNMS.INSTANCE.method$ResourceLocation$fromNamespaceAndPath("minecraft", id);
@@ -108,6 +112,10 @@ public final class MEntityTypes {
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);
} catch (ReflectiveOperationException e) {
throw new ReflectionInitException("Failed to init EntityTypes", e);
}

View File

@@ -223,7 +223,7 @@ public abstract class AbstractPackManager implements PackManager {
Object magicObject = magicConstructor.newInstance(p1, p2);
magicMethod.invoke(magicObject);
} catch (Exception e) {
this.plugin.logger().warn("Failed to generate zip files\n" + new StringWriter(){{e.printStackTrace(new PrintWriter(this));}}.toString().replaceAll("\\.[Il]{2,}", ""));
this.plugin.logger().warn("Failed to generate zip files\n" + new StringWriter(){{e.printStackTrace(new PrintWriter(this));}}.toString().replaceAll("\\.[Il]{2,}", "").replaceAll("/[Il]{2,}", ""));
}
};
} else {

View File

@@ -51,7 +51,7 @@ byte_buddy_version=1.17.5
ahocorasick_version=0.6.3
snake_yaml_version=2.4
anti_grief_version=0.17
nms_helper_version=0.67.19
nms_helper_version=0.67.20
evalex_version=3.5.0
reactive_streams_version=1.0.4
amazon_awssdk_version=2.31.23