3
0
Mirror von https://github.com/ViaVersion/ViaVersion.git synchronisiert 2024-12-26 16:12:42 +01:00

Handle entity type changes in show_entity hover events

Fixes #4199
Dieser Commit ist enthalten in:
Nassim Jahnke 2024-10-25 20:45:23 +02:00
Ursprung 9bc943ea67
Commit 7be7139241
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: EF6771C01F6EF02F
4 geänderte Dateien mit 27 neuen und 2 gelöschten Zeilen

Datei anzeigen

@ -58,6 +58,14 @@ public interface EntityRewriter<T extends Protocol<?, ?, ?, ?>> extends Rewriter
*/ */
int newEntityId(int id); int newEntityId(int id);
/**
* Returns the mapped entity (or the same if it has not changed).
*
* @param identifier unmapped entity identifier
* @return mapped entity identifier
*/
String mappedEntityIdentifier(String identifier);
/** /**
* Handles and transforms entity data of an entity. * Handles and transforms entity data of an entity.
* *

Datei anzeigen

@ -51,7 +51,8 @@ public interface ItemRewriter<T extends Protocol<?, ?, ?, ?>> extends Rewriter<T
@Nullable @Nullable
Item handleItemToServer(UserConnection connection, @Nullable Item item); Item handleItemToServer(UserConnection connection, @Nullable Item item);
void rewriteParticle(UserConnection connection, Particle particle); default void rewriteParticle(UserConnection connection, Particle particle) {
}
/** /**
* Returns the item type of the current protocol. * Returns the item type of the current protocol.

Datei anzeigen

@ -390,6 +390,11 @@ public class ComponentRewriter<C extends ClientboundPacketType> implements com.v
final CompoundTag contents = hoverEventTag.getCompoundTag("contents"); final CompoundTag contents = hoverEventTag.getCompoundTag("contents");
if (contents != null) { if (contents != null) {
processTag(connection, contents.get("name")); processTag(connection, contents.get("name"));
final StringTag typeTag = contents.getStringTag("type");
if (typeTag != null && protocol.getEntityRewriter() != null) {
typeTag.setValue(protocol.getEntityRewriter().mappedEntityIdentifier(typeTag.getValue()));
}
} }
} else if (action.equals("show_item")) { } else if (action.equals("show_item")) {
convertLegacyContents(hoverEventTag); convertLegacyContents(hoverEventTag);

Datei anzeigen

@ -24,6 +24,7 @@ import com.viaversion.nbt.tag.NumberTag;
import com.viaversion.nbt.tag.Tag; import com.viaversion.nbt.tag.Tag;
import com.viaversion.viaversion.api.Via; import com.viaversion.viaversion.api.Via;
import com.viaversion.viaversion.api.connection.UserConnection; import com.viaversion.viaversion.api.connection.UserConnection;
import com.viaversion.viaversion.api.data.FullMappings;
import com.viaversion.viaversion.api.data.Int2IntMapMappings; import com.viaversion.viaversion.api.data.Int2IntMapMappings;
import com.viaversion.viaversion.api.data.Mappings; import com.viaversion.viaversion.api.data.Mappings;
import com.viaversion.viaversion.api.data.ParticleMappings; import com.viaversion.viaversion.api.data.ParticleMappings;
@ -60,7 +61,6 @@ import org.checkerframework.checker.nullness.qual.Nullable;
public abstract class EntityRewriter<C extends ClientboundPacketType, T extends Protocol<C, ?, ?, ?>> public abstract class EntityRewriter<C extends ClientboundPacketType, T extends Protocol<C, ?, ?, ?>>
extends RewriterBase<T> implements com.viaversion.viaversion.api.rewriter.EntityRewriter<T> { extends RewriterBase<T> implements com.viaversion.viaversion.api.rewriter.EntityRewriter<T> {
private static final EntityData[] EMPTY_ARRAY = new EntityData[0];
protected final List<EntityDataFilter> entityDataFilters = new ArrayList<>(); protected final List<EntityDataFilter> entityDataFilters = new ArrayList<>();
protected final boolean trackMappedType; protected final boolean trackMappedType;
protected Mappings typeMappings; protected Mappings typeMappings;
@ -156,6 +156,17 @@ public abstract class EntityRewriter<C extends ClientboundPacketType, T extends
return typeMappings != null ? typeMappings.getNewIdOrDefault(id, id) : id; return typeMappings != null ? typeMappings.getNewIdOrDefault(id, id) : id;
} }
@Override
public String mappedEntityIdentifier(final String identifier) {
if (typeMappings instanceof final FullMappings fullMappings) {
final String mappedIdentifier = fullMappings.mappedIdentifier(identifier);
if (mappedIdentifier != null) {
return mappedIdentifier;
}
}
return identifier;
}
/** /**
* Maps an entity type. * Maps an entity type.
* *