Mirror von
https://github.com/ViaVersion/ViaVersion.git
synchronisiert 2024-11-19 14:30:16 +01:00
Handle show_entity type field
Dieser Commit ist enthalten in:
Ursprung
57b37457d6
Commit
7825a1e460
@ -160,80 +160,99 @@ public class ComponentRewriter1_20_5 extends ComponentRewriter<ClientboundPacket
|
|||||||
@Override
|
@Override
|
||||||
protected void handleHoverEvent(final CompoundTag hoverEventTag) {
|
protected void handleHoverEvent(final CompoundTag hoverEventTag) {
|
||||||
final StringTag actionTag = hoverEventTag.getStringTag("action");
|
final StringTag actionTag = hoverEventTag.getStringTag("action");
|
||||||
if (actionTag == null || !actionTag.getValue().equals("show_item")) {
|
if (actionTag == null) return;
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
final Tag valueTag = hoverEventTag.remove("value");
|
if (actionTag.getValue().equals("show_item")) {
|
||||||
if (valueTag != null) { // Convert legacy hover event to new format for rewriting
|
final Tag valueTag = hoverEventTag.remove("value");
|
||||||
final CompoundTag tag = ComponentUtil.deserializeShowItem(valueTag, SerializerVersion.V1_20_3);
|
if (valueTag != null) { // Convert legacy hover event to new format for rewriting (Doesn't handle all cases, but good enough)
|
||||||
final CompoundTag contentsTag = new CompoundTag();
|
final CompoundTag tag = ComponentUtil.deserializeShowItem(valueTag, SerializerVersion.V1_20_3);
|
||||||
contentsTag.put("id", tag.getStringTag("id"));
|
final CompoundTag contentsTag = new CompoundTag();
|
||||||
contentsTag.put("count", new IntTag(tag.getByte("Count")));
|
contentsTag.put("id", tag.getStringTag("id"));
|
||||||
if (tag.get("tag") instanceof CompoundTag) {
|
contentsTag.put("count", new IntTag(tag.getByte("Count")));
|
||||||
contentsTag.put("tag", new StringTag(SerializerVersion.V1_20_3.toSNBT(tag.getCompoundTag("tag"))));
|
if (tag.get("tag") instanceof CompoundTag) {
|
||||||
|
contentsTag.put("tag", new StringTag(SerializerVersion.V1_20_3.toSNBT(tag.getCompoundTag("tag"))));
|
||||||
|
}
|
||||||
|
hoverEventTag.put("contents", contentsTag);
|
||||||
}
|
}
|
||||||
hoverEventTag.put("contents", contentsTag);
|
|
||||||
}
|
|
||||||
|
|
||||||
final CompoundTag contentsTag = hoverEventTag.getCompoundTag("contents");
|
final CompoundTag contentsTag = hoverEventTag.getCompoundTag("contents");
|
||||||
if (contentsTag == null) {
|
if (contentsTag == null) {
|
||||||
return;
|
return;
|
||||||
}
|
|
||||||
|
|
||||||
final StringTag idTag = contentsTag.getStringTag("id");
|
|
||||||
if (idTag == null) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
final int itemId = Protocol1_20_5To1_20_3.MAPPINGS.itemId(idTag.getValue());
|
|
||||||
if (itemId == -1) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
final StringTag tag = contentsTag.remove("tag");
|
|
||||||
if (tag == null) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
CompoundTag tagTag;
|
|
||||||
try {
|
|
||||||
tagTag = (CompoundTag) SerializerVersion.V1_20_3.toTag(tag.getValue());
|
|
||||||
} catch (Exception e) {
|
|
||||||
if (!Via.getConfig().isSuppressConversionWarnings() || Via.getManager().isDebug()) {
|
|
||||||
Via.getPlatform().getLogger().log(Level.WARNING, "Error reading 1.20.3 NBT in show_item: " + contentsTag, e);
|
|
||||||
}
|
}
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
final Item oldItem = new DataItem();
|
final StringTag idTag = contentsTag.getStringTag("id");
|
||||||
oldItem.setIdentifier(itemId);
|
if (idTag == null) {
|
||||||
if (tagTag != null) { // We don't need to remap data if there is none
|
return;
|
||||||
oldItem.setTag(tagTag);
|
}
|
||||||
}
|
|
||||||
|
|
||||||
final Item newItem = protocol.getItemRewriter().handleItemToClient(oldItem);
|
final int itemId = Protocol1_20_5To1_20_3.MAPPINGS.itemId(idTag.getValue());
|
||||||
if (newItem == null) {
|
if (itemId == -1) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
final String itemName = Protocol1_20_5To1_20_3.MAPPINGS.itemName(newItem.identifier());
|
final StringTag tag = contentsTag.remove("tag");
|
||||||
if (itemName != null) {
|
if (tag == null) {
|
||||||
contentsTag.putString("id", itemName);
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
final Map<StructuredDataKey<?>, StructuredData<?>> data = newItem.structuredData().data();
|
CompoundTag tagTag;
|
||||||
if (!data.isEmpty()) {
|
|
||||||
CompoundTag components;
|
|
||||||
try {
|
try {
|
||||||
components = toTag(data, false);
|
tagTag = (CompoundTag) SerializerVersion.V1_20_3.toTag(tag.getValue());
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
if (!Via.getConfig().isSuppressConversionWarnings() || Via.getManager().isDebug()) {
|
if (!Via.getConfig().isSuppressConversionWarnings() || Via.getManager().isDebug()) {
|
||||||
Via.getPlatform().getLogger().log(Level.WARNING, "Error writing 1.20.5 components in show_item!", e);
|
Via.getPlatform().getLogger().log(Level.WARNING, "Error reading 1.20.3 NBT in show_item: " + contentsTag, e);
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
contentsTag.put("components", components);
|
|
||||||
|
final Item oldItem = new DataItem();
|
||||||
|
oldItem.setIdentifier(itemId);
|
||||||
|
if (tagTag != null) { // We don't need to remap data if there is none
|
||||||
|
oldItem.setTag(tagTag);
|
||||||
|
}
|
||||||
|
|
||||||
|
final Item newItem = protocol.getItemRewriter().handleItemToClient(oldItem);
|
||||||
|
if (newItem == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
final String itemName = Protocol1_20_5To1_20_3.MAPPINGS.itemName(newItem.identifier());
|
||||||
|
if (itemName != null) {
|
||||||
|
contentsTag.putString("id", itemName);
|
||||||
|
}
|
||||||
|
|
||||||
|
final Map<StructuredDataKey<?>, StructuredData<?>> data = newItem.structuredData().data();
|
||||||
|
if (!data.isEmpty()) {
|
||||||
|
CompoundTag components;
|
||||||
|
try {
|
||||||
|
components = toTag(data, false);
|
||||||
|
} catch (Exception e) {
|
||||||
|
if (!Via.getConfig().isSuppressConversionWarnings() || Via.getManager().isDebug()) {
|
||||||
|
Via.getPlatform().getLogger().log(Level.WARNING, "Error writing 1.20.5 components in show_item!", e);
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
contentsTag.put("components", components);
|
||||||
|
}
|
||||||
|
} else if (actionTag.getValue().equals("show_entity")) {
|
||||||
|
final Tag valueTag = hoverEventTag.remove("value");
|
||||||
|
if (valueTag != null) { // Convert legacy hover event to new format for rewriting (Doesn't handle all cases, but good enough)
|
||||||
|
final CompoundTag tag = ComponentUtil.deserializeShowItem(valueTag, SerializerVersion.V1_20_3);
|
||||||
|
final CompoundTag contentsTag = new CompoundTag();
|
||||||
|
contentsTag.put("type", tag.getStringTag("type"));
|
||||||
|
contentsTag.put("id", tag.getStringTag("id"));
|
||||||
|
contentsTag.put("name", SerializerVersion.V1_20_3.toTag(SerializerVersion.V1_20_3.toComponent(tag.getString("name"))));
|
||||||
|
hoverEventTag.put("contents", contentsTag);
|
||||||
|
}
|
||||||
|
|
||||||
|
final CompoundTag contentsTag = hoverEventTag.getCompoundTag("contents");
|
||||||
|
if (contentsTag == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.protocol.getMappingData().getEntityMappings().mappedId(contentsTag.getString("type")) == -1) {
|
||||||
|
contentsTag.put("type", new StringTag("pig"));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren