9
0
mirror of https://github.com/Xiao-MoMi/craft-engine.git synced 2025-12-23 17:09:19 +00:00

为盔甲架单开配置

This commit is contained in:
XiaoMoMi
2025-04-09 21:23:28 +08:00
parent 62d857351c
commit aee2faa8b0
4 changed files with 59 additions and 6 deletions

View File

@@ -163,6 +163,7 @@ image:
team: true
scoreboard: true
entity-name: false
armor-stand: true
text-display: true
emoji: {}

View File

@@ -1883,10 +1883,10 @@ public class PacketConsumers {
buf.writeVarInt(id);
FastNMS.INSTANCE.method$ClientboundSetEntityDataPacket$pack(packedItems, buf);
}
} else if (Config.interceptEntityName()) {
boolean isChanged = false;
List<Object> packedItems = FastNMS.INSTANCE.method$ClientboundSetEntityDataPacket$unpack(buf);
if (entityType == Reflections.instance$EntityType$TEXT_DISPLAY) {
} else if (entityType == Reflections.instance$EntityType$TEXT_DISPLAY) {
if (Config.interceptTextDisplay()) {
boolean isChanged = false;
List<Object> packedItems = FastNMS.INSTANCE.method$ClientboundSetEntityDataPacket$unpack(buf);
for (int i = 0; i < packedItems.size(); i++) {
Object packedItem = packedItems.get(i);
int entityDataId = FastNMS.INSTANCE.field$SynchedEntityData$DataValue$id(packedItem);
@@ -1907,7 +1907,18 @@ public class PacketConsumers {
}
}
}
} else {
if (isChanged) {
event.setChanged(true);
buf.clear();
buf.writeVarInt(event.packetID());
buf.writeVarInt(id);
FastNMS.INSTANCE.method$ClientboundSetEntityDataPacket$pack(packedItems, buf);
}
}
} else if (entityType == Reflections.instance$EntityType$ARMOR_STAND) {
if (Config.interceptArmorStand()) {
boolean isChanged = false;
List<Object> packedItems = FastNMS.INSTANCE.method$ClientboundSetEntityDataPacket$unpack(buf);
for (int i = 0; i < packedItems.size(); i++) {
Object packedItem = packedItems.get(i);
int entityDataId = FastNMS.INSTANCE.field$SynchedEntityData$DataValue$id(packedItem);
@@ -1930,6 +1941,38 @@ public class PacketConsumers {
}
}
}
if (isChanged) {
event.setChanged(true);
buf.clear();
buf.writeVarInt(event.packetID());
buf.writeVarInt(id);
FastNMS.INSTANCE.method$ClientboundSetEntityDataPacket$pack(packedItems, buf);
}
}
} else if (Config.interceptEntityName()) {
boolean isChanged = false;
List<Object> packedItems = FastNMS.INSTANCE.method$ClientboundSetEntityDataPacket$unpack(buf);
for (int i = 0; i < packedItems.size(); i++) {
Object packedItem = packedItems.get(i);
int entityDataId = FastNMS.INSTANCE.field$SynchedEntityData$DataValue$id(packedItem);
if (entityDataId == EntityDataUtils.CUSTOM_NAME_DATA_ID) {
Optional<Object> optionalTextComponent = (Optional<Object>) FastNMS.INSTANCE.field$SynchedEntityData$DataValue$value(packedItem);
if (optionalTextComponent.isPresent()) {
Object textComponent = optionalTextComponent.get();
String json = ComponentUtils.minecraftToJson(textComponent);
Map<String, Component> tokens = CraftEngine.instance().imageManager().matchTags(json);
if (!tokens.isEmpty()) {
Component component = AdventureHelper.jsonToComponent(json);
for (Map.Entry<String, Component> token : tokens.entrySet()) {
component = component.replaceText(b -> b.matchLiteral(token.getKey()).replacement(token.getValue()));
}
Object serializer = FastNMS.INSTANCE.field$SynchedEntityData$DataValue$serializer(packedItem);
packedItems.set(i, FastNMS.INSTANCE.constructor$SynchedEntityData$DataValue(entityDataId, serializer, Optional.of(ComponentUtils.adventureToMinecraft(component))));
isChanged = true;
break;
}
}
}
}
if (isChanged) {
event.setChanged(true);

View File

@@ -3706,6 +3706,7 @@ public class Reflections {
public static final Object instance$EntityType$TEXT_DISPLAY;
public static final Object instance$EntityType$ITEM_DISPLAY;
public static final Object instance$EntityType$BLOCK_DISPLAY;
public static final Object instance$EntityType$ARMOR_STAND;
public static final Object instance$EntityType$FALLING_BLOCK;
public static final Object instance$EntityType$INTERACTION;
public static final Object instance$EntityType$SHULKER;
@@ -3724,6 +3725,8 @@ public class Reflections {
instance$EntityType$INTERACTION = Reflections.method$Registry$get.invoke(Reflections.instance$BuiltInRegistries$ENTITY_TYPE, interaction);
Object shulker = method$ResourceLocation$fromNamespaceAndPath.invoke(null, "minecraft", "shulker");
instance$EntityType$SHULKER = Reflections.method$Registry$get.invoke(Reflections.instance$BuiltInRegistries$ENTITY_TYPE, shulker);
Object armorStand = method$ResourceLocation$fromNamespaceAndPath.invoke(null, "minecraft", "armor_stand");
instance$EntityType$ARMOR_STAND = Reflections.method$Registry$get.invoke(Reflections.instance$BuiltInRegistries$ENTITY_TYPE, armorStand);
} catch (ReflectiveOperationException e) {
throw new RuntimeException(e);
}

View File

@@ -132,6 +132,7 @@ public class Config {
protected boolean image$intercept_packets$scoreboard;
protected boolean image$intercept_packets$entity_name;
protected boolean image$intercept_packets$text_display;
protected boolean image$intercept_packets$armor_stand;
public Config(CraftEngine plugin) {
this.plugin = plugin;
@@ -296,8 +297,9 @@ public class Config {
image$intercept_packets$container = config.getBoolean("image.intercept-packets.container", true);
image$intercept_packets$team = config.getBoolean("image.intercept-packets.team", true);
image$intercept_packets$scoreboard = config.getBoolean("image.intercept-packets.scoreboard", true);
image$intercept_packets$entity_name = config.getBoolean("image.intercept-packets.entity-name", true);
image$intercept_packets$entity_name = config.getBoolean("image.intercept-packets.entity-name", false);
image$intercept_packets$text_display = config.getBoolean("image.intercept-packets.text-display", true);
image$intercept_packets$armor_stand = config.getBoolean("image.intercept-packets.armor-stand", true);
Class<?> modClazz = ReflectionUtils.getClazz(CraftEngine.MOD_CLASS);
if (modClazz != null) {
@@ -638,6 +640,10 @@ public class Config {
return instance.image$intercept_packets$text_display;
}
public static boolean interceptArmorStand() {
return instance.image$intercept_packets$armor_stand;
}
public YamlDocument loadOrCreateYamlData(String fileName) {
File file = new File(this.plugin.dataFolderFile(), fileName);
if (!file.exists()) {