Mirror von
https://github.com/ViaVersion/ViaVersion.git
synchronisiert 2024-12-28 00:50:13 +01:00
Some MetadataRewriter cleanup
Dieser Commit ist enthalten in:
Ursprung
da77c32a0d
Commit
31f7bde35f
@ -16,10 +16,7 @@ import us.myles.ViaVersion.api.type.Type;
|
||||
import us.myles.ViaVersion.protocols.protocol1_9_3to1_9_1_2.storage.ClientWorld;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
public abstract class MetadataRewriter {
|
||||
@ -35,16 +32,9 @@ public abstract class MetadataRewriter {
|
||||
|
||||
public final void handleMetadata(int entityId, List<Metadata> metadatas, UserConnection connection) {
|
||||
EntityType type = connection.get(entityTrackerClass).getEntity(entityId);
|
||||
Map<Integer, Metadata> metadataMap = new HashMap<>(metadatas.size());
|
||||
for (Metadata metadata : metadatas) {
|
||||
metadataMap.put(metadata.getId(), metadata);
|
||||
}
|
||||
|
||||
metadataMap = Collections.unmodifiableMap(metadataMap);
|
||||
|
||||
for (Metadata metadata : new ArrayList<>(metadatas)) {
|
||||
try {
|
||||
handleMetadata(entityId, type, metadata, metadatas, metadataMap, connection);
|
||||
handleMetadata(entityId, type, metadata, metadatas, connection);
|
||||
} catch (Exception e) {
|
||||
metadatas.remove(metadata);
|
||||
if (!Via.getConfig().isSuppressMetadataErrors() || Via.getManager().isDebug()) {
|
||||
@ -270,20 +260,49 @@ public abstract class MetadataRewriter {
|
||||
};
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
protected abstract EntityType getTypeFromId(int type);
|
||||
|
||||
/**
|
||||
* Returns the entity type from the given id.
|
||||
* From 1.14 and onwards, this is the same exact value as {@link #getTypeFromId(int)}.
|
||||
*
|
||||
* @param type entity type id
|
||||
* @return EntityType from id
|
||||
*/
|
||||
protected EntityType getObjectTypeFromId(int type) {
|
||||
return getTypeFromId(type);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the mapped entitiy (or the same if it has not changed).
|
||||
*
|
||||
* @param oldId old entity id
|
||||
* @return mapped entity id
|
||||
*/
|
||||
public int getNewEntityId(int oldId) {
|
||||
return typeMapping != null ? typeMapping.getOrDefault(oldId, oldId) : oldId;
|
||||
}
|
||||
|
||||
protected void handleMetadata(int entityId, EntityType type, Metadata metadata, List<Metadata> metadatas, UserConnection connection) throws Exception {
|
||||
}
|
||||
/**
|
||||
* To be overridden to handle metadata.
|
||||
*
|
||||
* @param entityId entity id
|
||||
* @param type entity type, or null if not tracked
|
||||
* @param metadata current metadata
|
||||
* @param metadatas full, mutable list of metadata
|
||||
* @param connection user connection
|
||||
*/
|
||||
protected abstract void handleMetadata(int entityId, @Nullable EntityType type, Metadata metadata, List<Metadata> metadatas, UserConnection connection) throws Exception;
|
||||
|
||||
protected void handleMetadata(int entityId, EntityType type, Metadata metadata, List<Metadata> metadatas, Map<Integer, Metadata> metadataMap, UserConnection connection) throws Exception {
|
||||
handleMetadata(entityId, type, metadata, metadatas, connection);
|
||||
@Nullable
|
||||
protected Metadata getMetaByIndex(int index, List<Metadata> metadataList) {
|
||||
for (Metadata metadata : metadataList) {
|
||||
if (metadata.getId() == index) {
|
||||
return metadata;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
@ -6,7 +6,8 @@ import us.myles.ViaVersion.api.type.Type;
|
||||
import java.util.List;
|
||||
|
||||
public abstract class MetaListTypeTemplate extends Type<List<Metadata>> {
|
||||
public MetaListTypeTemplate() {
|
||||
|
||||
protected MetaListTypeTemplate() {
|
||||
super("MetaData List", List.class);
|
||||
}
|
||||
|
||||
|
@ -5,6 +5,7 @@ import us.myles.ViaVersion.api.minecraft.metadata.Metadata;
|
||||
import us.myles.ViaVersion.api.type.Type;
|
||||
|
||||
public abstract class ModernMetaListType extends AbstractMetaListType {
|
||||
|
||||
@Override
|
||||
protected void writeEnd(final Type<Metadata> type, final ByteBuf buffer) throws Exception {
|
||||
type.write(buffer, null);
|
||||
|
@ -15,7 +15,6 @@ import us.myles.ViaVersion.protocols.protocol1_11to1_10.Protocol1_11To1_10;
|
||||
import us.myles.ViaVersion.protocols.protocol1_11to1_10.storage.EntityTracker1_11;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
|
||||
public class MetadataRewriter1_11To1_10 extends MetadataRewriter {
|
||||
@ -25,7 +24,7 @@ public class MetadataRewriter1_11To1_10 extends MetadataRewriter {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void handleMetadata(int entityId, us.myles.ViaVersion.api.entities.EntityType type, Metadata metadata, List<Metadata> metadatas, Map<Integer, Metadata> metadataMap, UserConnection connection) {
|
||||
protected void handleMetadata(int entityId, us.myles.ViaVersion.api.entities.EntityType type, Metadata metadata, List<Metadata> metadatas, UserConnection connection) {
|
||||
if (metadata.getValue() instanceof Item) {
|
||||
// Apply rewrite
|
||||
EntityIdRewriter.toClientItem((Item) metadata.getValue());
|
||||
@ -100,15 +99,14 @@ public class MetadataRewriter1_11To1_10 extends MetadataRewriter {
|
||||
}
|
||||
|
||||
if (type.is(EntityType.ARMOR_STAND) && Via.getConfig().isHologramPatch()) {
|
||||
Optional<Metadata> flags = Optional.ofNullable(metadataMap.get(11));
|
||||
Optional<Metadata> customName = Optional.ofNullable(metadataMap.get(2));
|
||||
Optional<Metadata> customNameVisible = Optional.ofNullable(metadataMap.get(3));
|
||||
if (metadata.getId() == 0 && flags.isPresent() && customName.isPresent() && customNameVisible.isPresent()) {
|
||||
Metadata meta = flags.get();
|
||||
Metadata flags = getMetaByIndex(11, metadatas);
|
||||
Metadata customName = getMetaByIndex(2, metadatas);
|
||||
Metadata customNameVisible = getMetaByIndex(3, metadatas);
|
||||
if (metadata.getId() == 0 && flags != null && customName != null && customNameVisible != null) {
|
||||
byte data = (byte) metadata.getValue();
|
||||
// Check invisible | Check small | Check if custom name is empty | Check if custom name visible is true
|
||||
if ((data & 0x20) == 0x20 && ((byte) meta.getValue() & 0x01) == 0x01
|
||||
&& !((String) customName.get().getValue()).isEmpty() && (boolean) customNameVisible.get().getValue()) {
|
||||
if ((data & 0x20) == 0x20 && ((byte) flags.getValue() & 0x01) == 0x01
|
||||
&& !((String) customName.getValue()).isEmpty() && (boolean) customNameVisible.getValue()) {
|
||||
EntityTracker1_11 tracker = connection.get(EntityTracker1_11.class);
|
||||
if (!tracker.isHologram(entityId)) {
|
||||
tracker.addHologram(entityId);
|
||||
|
@ -17,7 +17,6 @@ import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.packets.WorldPackets;
|
||||
import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.storage.EntityTracker1_13;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class MetadataRewriter1_13To1_12_2 extends MetadataRewriter {
|
||||
|
||||
@ -26,7 +25,7 @@ public class MetadataRewriter1_13To1_12_2 extends MetadataRewriter {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void handleMetadata(int entityId, EntityType type, Metadata metadata, List<Metadata> metadatas, Map<Integer, Metadata> metadataMap, UserConnection connection) throws Exception {
|
||||
protected void handleMetadata(int entityId, EntityType type, Metadata metadata, List<Metadata> metadatas, UserConnection connection) throws Exception {
|
||||
// Handle new MetaTypes
|
||||
if (metadata.getMetaType().getTypeID() > 4) {
|
||||
metadata.setMetaType(MetaType1_13.byId(metadata.getMetaType().getTypeID() + 1));
|
||||
@ -80,8 +79,10 @@ public class MetadataRewriter1_13To1_12_2 extends MetadataRewriter {
|
||||
if (type == Entity1_13Types.EntityType.AREA_EFFECT_CLOUD) {
|
||||
if (metadata.getId() == 9) {
|
||||
int particleId = (int) metadata.getValue();
|
||||
int parameter1 = metadataMap.containsKey(10) ? (int) metadataMap.get(10).getValue() : 0;
|
||||
int parameter2 = metadataMap.containsKey(11) ? (int) metadataMap.get(11).getValue() : 0;
|
||||
Metadata parameter1Meta = getMetaByIndex(10, metadatas);
|
||||
Metadata parameter2Meta = getMetaByIndex(11, metadatas);
|
||||
int parameter1 = parameter1Meta != null ? (int) parameter1Meta.getValue() : 0;
|
||||
int parameter2 = parameter2Meta != null ? (int) parameter2Meta.getValue() : 0;
|
||||
|
||||
Particle particle = ParticleRewriter.rewriteParticle(particleId, new Integer[]{parameter1, parameter2});
|
||||
if (particle != null && particle.getId() != -1) {
|
||||
|
@ -16,7 +16,6 @@ import us.myles.ViaVersion.protocols.protocol1_9to1_8.Protocol1_9To1_8;
|
||||
import us.myles.ViaVersion.protocols.protocol1_9to1_8.storage.EntityTracker1_9;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
public class MetadataRewriter1_9To1_8 extends MetadataRewriter {
|
||||
@ -26,7 +25,7 @@ public class MetadataRewriter1_9To1_8 extends MetadataRewriter {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void handleMetadata(int entityId, EntityType type, Metadata metadata, List<Metadata> metadatas, Map<Integer, Metadata> metadataMap, UserConnection connection) throws Exception {
|
||||
protected void handleMetadata(int entityId, EntityType type, Metadata metadata, List<Metadata> metadatas, UserConnection connection) throws Exception {
|
||||
MetaIndex metaIndex = MetaIndex.searchIndex(type, metadata.getId());
|
||||
if (metaIndex == null) {
|
||||
throw new Exception("Could not find valid metadata");
|
||||
@ -43,7 +42,8 @@ public class MetadataRewriter1_9To1_8 extends MetadataRewriter {
|
||||
if (type == Entity1_10Types.EntityType.ENDERMAN && metaIndex.getNewType() == MetaType1_9.BlockID) {
|
||||
if (metaIndex.getOldType() == MetaType1_8.Short) {
|
||||
int id = (Short) metadata.getValue();
|
||||
int data = metadataMap.containsKey(17) ? (Byte) metadataMap.get(17).getValue() : 0;
|
||||
Metadata meta = getMetaByIndex(17, metadatas);
|
||||
int data = meta != null ? (Byte) meta.getValue() : 0;
|
||||
int combined = (id << 4) | (data & 0xF);
|
||||
metadata.setValue(combined);
|
||||
} else {
|
||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren