3
0
Mirror von https://github.com/ViaVersion/ViaVersion.git synchronisiert 2024-12-27 08:30:09 +01:00

Fix shields not being for the right entity >.> and also print out value for metadata

Dieser Commit ist enthalten in:
Myles 2016-03-26 13:07:06 +00:00
Ursprung f32d3211ed
Commit f371419396
2 geänderte Dateien mit 120 neuen und 111 gelöschten Zeilen

Datei anzeigen

@ -21,119 +21,123 @@ public class MetadataRewriter {
for (Metadata entry : new ArrayList<>(list)) { for (Metadata entry : new ArrayList<>(list)) {
MetaIndex metaIndex = MetaIndex.getIndex(type, entry.getId()); MetaIndex metaIndex = MetaIndex.getIndex(type, entry.getId());
try { try {
if (metaIndex.getNewType() != NewType.Discontinued) { if (metaIndex != null) {
if (metaIndex.getNewType() != NewType.BlockID || id != -1 && data == -1 || id == -1 && data != -1) { // block ID is only written if we have both parts if (metaIndex.getNewType() != NewType.Discontinued) {
entry.setId(metaIndex.getNewIndex()); if (metaIndex.getNewType() != NewType.BlockID || id != -1 && data == -1 || id == -1 && data != -1) { // block ID is only written if we have both parts
entry.setTypeID(metaIndex.getNewType().getTypeID()); entry.setId(metaIndex.getNewIndex());
} entry.setTypeID(metaIndex.getNewType().getTypeID());
Object value = entry.getValue(); }
switch (metaIndex.getNewType()) { Object value = entry.getValue();
case Byte: switch (metaIndex.getNewType()) {
entry.setType(us.myles.ViaVersion.api.type.Type.BYTE); case Byte:
// convert from int, byte entry.setType(us.myles.ViaVersion.api.type.Type.BYTE);
if (metaIndex.getOldType() == Type.Byte) { // convert from int, byte
if (metaIndex.getOldType() == Type.Byte) {
entry.setValue(value);
}
if (metaIndex.getOldType() == Type.Int) {
entry.setValue(((Integer) value).byteValue());
}
// After writing the last one
if (metaIndex == MetaIndex.ENTITY_STATUS && type == EntityType.PLAYER) {
Byte val = 0;
if ((((Byte) value) & 0x10) == 0x10) { // Player eating/aiming/drinking
val = 1;
}
int newIndex = MetaIndex.PLAYER_HAND.getNewIndex();
int typeID = MetaIndex.PLAYER_HAND.getNewType().getTypeID();
Metadata metadata = new Metadata(newIndex, typeID, us.myles.ViaVersion.api.type.Type.BYTE, val);
list.add(metadata);
}
break;
case OptUUID:
entry.setType(us.myles.ViaVersion.api.type.Type.OPTIONAL_UUID);
String owner = (String) value;
UUID toWrite = null;
if (owner.length() != 0) {
try {
toWrite = UUID.fromString(owner);
} catch (Exception ignored) {
}
}
entry.setValue(toWrite);
break;
case BlockID:
entry.setType(us.myles.ViaVersion.api.type.Type.VAR_INT);
// if we have both sources :))
if (metaIndex.getOldType() == Type.Byte) {
data = (Byte) value;
}
if (metaIndex.getOldType() == Type.Short) {
id = (Short) value;
}
if (id != -1 && data != -1) {
int combined = id << 4 | data;
data = -1;
id = -1;
entry.setValue(combined);
} else {
list.remove(entry);
}
break;
case VarInt:
entry.setType(us.myles.ViaVersion.api.type.Type.VAR_INT);
// convert from int, short, byte
if (metaIndex.getOldType() == Type.Byte) {
entry.setValue(((Byte) value).intValue());
}
if (metaIndex.getOldType() == Type.Short) {
entry.setValue(((Short) value).intValue());
}
if (metaIndex.getOldType() == Type.Int) {
entry.setValue(value);
}
break;
case Float:
entry.setType(us.myles.ViaVersion.api.type.Type.FLOAT);
entry.setValue(value); entry.setValue(value);
} break;
if (metaIndex.getOldType() == Type.Int) { case String:
entry.setValue(((Integer) value).byteValue()); entry.setType(us.myles.ViaVersion.api.type.Type.STRING);
} entry.setValue(value);
// After writing the last one break;
if (metaIndex == MetaIndex.ENTITY_STATUS && type == EntityType.PLAYER) { case Boolean:
Byte val = 0; entry.setType(us.myles.ViaVersion.api.type.Type.BOOLEAN);
if ((((Byte) value) & 0x10) == 0x10) { // Player eating/aiming/drinking if (metaIndex == MetaIndex.AGEABLE_AGE)
val = 1; entry.setValue((Byte) value < 0);
} else
int newIndex = MetaIndex.PLAYER_HAND.getNewIndex(); entry.setValue((Byte) value != 0);
int typeID = MetaIndex.PLAYER_HAND.getNewType().getTypeID(); break;
Metadata metadata = new Metadata(newIndex, typeID, us.myles.ViaVersion.api.type.Type.BYTE, val); case Slot:
list.add(metadata); entry.setType(us.myles.ViaVersion.api.type.Type.ITEM);
} entry.setValue(value);
break; ItemRewriter.toClient((Item) entry.getValue());
case OptUUID: break;
entry.setType(us.myles.ViaVersion.api.type.Type.OPTIONAL_UUID); case Position:
String owner = (String) value; entry.setType(us.myles.ViaVersion.api.type.Type.VECTOR);
UUID toWrite = null; Vector vector = (Vector) value;
if (owner.length() != 0) { entry.setValue(vector);
try { break;
toWrite = UUID.fromString(owner); case Vector3F:
} catch (Exception ignored) { entry.setType(us.myles.ViaVersion.api.type.Type.ROTATION);
} EulerAngle angle = (EulerAngle) value;
} entry.setValue(angle);
entry.setValue(toWrite); break;
break; case Chat:
case BlockID: entry.setType(us.myles.ViaVersion.api.type.Type.STRING);
entry.setType(us.myles.ViaVersion.api.type.Type.VAR_INT); value = Protocol1_9TO1_8.fixJson((String) value);
// if we have both sources :)) entry.setValue(value);
if (metaIndex.getOldType() == Type.Byte) { break;
data = (Byte) value; default:
} System.out.println("[Out] Unhandled MetaDataType: " + metaIndex.getNewType());
if (metaIndex.getOldType() == Type.Short) {
id = (Short) value;
}
if (id != -1 && data != -1) {
int combined = id << 4 | data;
data = -1;
id = -1;
entry.setValue(combined);
} else {
list.remove(entry); list.remove(entry);
} break;
break; }
case VarInt: } else {
entry.setType(us.myles.ViaVersion.api.type.Type.VAR_INT); list.remove(entry);
// convert from int, short, byte
if (metaIndex.getOldType() == Type.Byte) {
entry.setValue(((Byte) value).intValue());
}
if (metaIndex.getOldType() == Type.Short) {
entry.setValue(((Short) value).intValue());
}
if (metaIndex.getOldType() == Type.Int) {
entry.setValue(value);
}
break;
case Float:
entry.setType(us.myles.ViaVersion.api.type.Type.FLOAT);
entry.setValue(value);
break;
case String:
entry.setType(us.myles.ViaVersion.api.type.Type.STRING);
entry.setValue(value);
break;
case Boolean:
entry.setType(us.myles.ViaVersion.api.type.Type.BOOLEAN);
if (metaIndex == MetaIndex.AGEABLE_AGE)
entry.setValue((Byte) value < 0);
else
entry.setValue((Byte) value != 0);
break;
case Slot:
entry.setType(us.myles.ViaVersion.api.type.Type.ITEM);
entry.setValue(value);
ItemRewriter.toClient((Item) entry.getValue());
break;
case Position:
entry.setType(us.myles.ViaVersion.api.type.Type.VECTOR);
Vector vector = (Vector) value;
entry.setValue(vector);
break;
case Vector3F:
entry.setType(us.myles.ViaVersion.api.type.Type.ROTATION);
EulerAngle angle = (EulerAngle) value;
entry.setValue(angle);
break;
case Chat:
entry.setType(us.myles.ViaVersion.api.type.Type.STRING);
value = Protocol1_9TO1_8.fixJson((String) value);
entry.setValue(value);
break;
default:
System.out.println("[Out] Unhandled MetaDataType: " + metaIndex.getNewType());
list.remove(entry);
break;
} }
} else { } else {
list.remove(entry); throw new Exception("Could not find valid metadata");
} }
} catch (Exception e) { } catch (Exception e) {
list.remove(entry); list.remove(entry);
@ -144,6 +148,7 @@ public class MetadataRewriter {
else else
System.out.println("An error occurred with entity meta data for UNKNOWN_ENTITY OldID: " + entry.getId()); System.out.println("An error occurred with entity meta data for UNKNOWN_ENTITY OldID: " + entry.getId());
if (metaIndex != null) { if (metaIndex != null) {
System.out.println("Value: " + entry.getValue());
System.out.println("Old ID: " + metaIndex.getIndex() + " New ID: " + metaIndex.getNewIndex()); System.out.println("Old ID: " + metaIndex.getIndex() + " New ID: " + metaIndex.getNewIndex());
System.out.println("Old Type: " + metaIndex.getOldType() + " New Type: " + metaIndex.getNewType()); System.out.println("Old Type: " + metaIndex.getOldType() + " New Type: " + metaIndex.getNewType());
} }

Datei anzeigen

@ -54,6 +54,10 @@ public class EntityTracker extends StoredObject {
} }
public void setSecondHand(Item item) { public void setSecondHand(Item item) {
setSecondHand(entityID, item);
}
public void setSecondHand(int entityID, Item item) {
PacketWrapper wrapper = new PacketWrapper(0x3C, null, getUser()); PacketWrapper wrapper = new PacketWrapper(0x3C, null, getUser());
wrapper.write(Type.VAR_INT, entityID); wrapper.write(Type.VAR_INT, entityID);
wrapper.write(Type.VAR_INT, 1); // slot wrapper.write(Type.VAR_INT, 1); // slot
@ -106,10 +110,10 @@ public class EntityTracker extends StoredObject {
if ((data & 0x10) == 0x10) { if ((data & 0x10) == 0x10) {
if (validBlocking.contains(entityID)) { if (validBlocking.contains(entityID)) {
Item shield = new Item((short) 442, (byte) 1, (short) 0, null); Item shield = new Item((short) 442, (byte) 1, (short) 0, null);
setSecondHand(shield); setSecondHand(entityID, shield);
} }
} else { } else {
setSecondHand(null); setSecondHand(entityID, null);
} }
} }
} }