3
0
Mirror von https://github.com/ViaVersion/ViaVersion.git synchronisiert 2024-11-05 07:40:16 +01:00

Fix metadata :)

Dieser Commit ist enthalten in:
Myles 2016-08-10 20:23:13 +01:00
Ursprung 0dd8c33aa9
Commit 85de7c35ea
3 geänderte Dateien mit 84 neuen und 0 gelöschten Zeilen

Datei anzeigen

@ -5,6 +5,7 @@ import us.myles.ViaVersion.api.minecraft.metadata.Metadata;
import us.myles.ViaVersion.api.type.Type; import us.myles.ViaVersion.api.type.Type;
import us.myles.ViaVersion.protocols.protocol1_9to1_8.metadata.NewType; import us.myles.ViaVersion.protocols.protocol1_9to1_8.metadata.NewType;
import java.util.ArrayList;
import java.util.List; import java.util.List;
public class MetadataRewriter { public class MetadataRewriter {
@ -73,6 +74,75 @@ public class MetadataRewriter {
return currentType; return currentType;
} }
public static void handleMetadata(int type, List<Metadata> metadatas) {
for (Metadata metadata : new ArrayList<>(metadatas)) {
if (type == 4 || type == 68) { // Guardians
int oldid = metadata.getId();
if (oldid == 12) {
metadata.setType(Type.BOOLEAN);
metadata.setTypeID(NewType.Boolean.getTypeID());
boolean val = (((byte) metadata.getValue()) & 0x02) == 0x02;
metadata.setValue(val);
}
}
if (type == 51 || type == 5 || type == 6) { // Skeletons
int oldid = metadata.getId();
if (oldid == 12) {
metadatas.remove(metadata);
}
if (oldid == 13) {
metadata.setId(12);
}
}
if (type == 54 || type == 27) { // Zombie | Zombie Villager
if (type == 54 && metadata.getId() == 14) {
metadatas.remove(metadata);
} else {
if (metadata.getId() == 15) {
metadata.setId(14);
} else {
if (metadata.getId() == 14) {
metadata.setId(15);
}
}
}
}
if (type == 100 || type == 31 || type == 32 || type == 29 || type == 28) { // Horses
// Remap metadata id
int oldid = metadata.getId();
if (oldid == 14) { // Type
metadatas.remove(metadata);
}
if (oldid == 16) { // Owner
metadata.setId(14);
}
if (oldid == 17) { // Armor
metadata.setId(16);
}
// Process per type
if (type == 100) {
// Normal Horse
} else {
// Remove 15, 16
if (metadata.getId() == 15 || metadata.getId() == 16) {
metadatas.remove(metadata);
}
}
if (type == 31 || type == 32) {
// Chested Horse
if (metadata.getId() == 13) {
if ((((byte) metadata.getValue()) & 0x08) == 0x08) {
metadatas.add(new Metadata(15, NewType.Boolean.getTypeID(), Type.BOOLEAN, true));
} else {
metadatas.add(new Metadata(15, NewType.Boolean.getTypeID(), Type.BOOLEAN, false));
}
}
}
}
}
}
public static Optional<Metadata> getById(List<Metadata> metadatas, int id) { public static Optional<Metadata> getById(List<Metadata> metadatas, int id) {
for (Metadata metadata : metadatas) { for (Metadata metadata : metadatas) {
if (metadata.getId() == id) return Optional.of(metadata); if (metadata.getId() == id) return Optional.of(metadata);

Datei anzeigen

@ -44,6 +44,7 @@ public class ProtocolSnapshotTo1_10 extends Protocol {
wrapper.set(Type.VAR_INT, 1, type); wrapper.set(Type.VAR_INT, 1, type);
// Register Type ID // Register Type ID
wrapper.user().get(EntityTracker.class).getClientEntityTypes().put(wrapper.get(Type.VAR_INT, 0), type); wrapper.user().get(EntityTracker.class).getClientEntityTypes().put(wrapper.get(Type.VAR_INT, 0), type);
MetadataRewriter.handleMetadata(type, wrapper.get(Types1_9.METADATA_LIST, 0));
} }
}); });
} }
@ -71,6 +72,17 @@ public class ProtocolSnapshotTo1_10 extends Protocol {
public void registerMap() { public void registerMap() {
map(Type.VAR_INT); // 0 - Entity ID map(Type.VAR_INT); // 0 - Entity ID
map(Types1_9.METADATA_LIST); // 1 - Metadata list map(Types1_9.METADATA_LIST); // 1 - Metadata list
handler(new PacketHandler() {
@Override
public void handle(PacketWrapper wrapper) throws Exception {
int entityId = wrapper.get(Type.VAR_INT, 0);
if (!wrapper.user().get(EntityTracker.class).getClientEntityTypes().containsKey(entityId)) {
return;
}
int type = wrapper.user().get(EntityTracker.class).getClientEntityTypes().get(entityId);
MetadataRewriter.handleMetadata(type, wrapper.get(Types1_9.METADATA_LIST, 0));
}
});
} }
}); });

Datei anzeigen

@ -3,7 +3,9 @@ package us.myles.ViaVersion.protocols.protocolsnapshotto1_10.storage;
import lombok.Getter; import lombok.Getter;
import us.myles.ViaVersion.api.data.StoredObject; import us.myles.ViaVersion.api.data.StoredObject;
import us.myles.ViaVersion.api.data.UserConnection; import us.myles.ViaVersion.api.data.UserConnection;
import us.myles.ViaVersion.api.minecraft.metadata.Metadata;
import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;