3
0
Mirror von https://github.com/ViaVersion/ViaBackwards.git synchronisiert 2024-11-20 06:50:10 +01:00

Rewrite metadata changes en add missing entity track

Dieser Commit ist enthalten in:
Matsv 2019-01-19 15:53:31 +01:00
Ursprung 87f217ca37
Commit 842631feef
2 geänderte Dateien mit 307 neuen und 228 gelöschten Zeilen

Datei anzeigen

@ -60,6 +60,10 @@ public abstract class EntityRewriter<T extends BackwardsProtocol> extends Rewrit
getEntityTracker(connection).trackEntityType(entityId, type); getEntityTracker(connection).trackEntityType(entityId, type);
} }
protected boolean hasData(AbstractEntityType type) {
return entityTypes.containsKey(type);
}
protected Optional<EntityData> getEntityData(AbstractEntityType type) { protected Optional<EntityData> getEntityData(AbstractEntityType type) {
if (!entityTypes.containsKey(type)) if (!entityTypes.containsKey(type))
return Optional.empty(); return Optional.empty();
@ -144,8 +148,9 @@ public abstract class EntityRewriter<T extends BackwardsProtocol> extends Rewrit
EntityData entData = opEd.get(); EntityData entData = opEd.get();
if (entData.getMobName() != null && if (entData.getMobName() != null &&
(data.getValue() == null || ((String) data.getValue()).isEmpty()) && (data.getValue() == null || ((String) data.getValue()).isEmpty()) &&
data.getMetaType().getTypeID() == getDisplayNameMetaType().getTypeID()) data.getMetaType().getTypeID() == getDisplayNameMetaType().getTypeID()) {
data.setValue(entData.getMobName()); data.setValue(entData.getMobName());
}
} }
} }

Datei anzeigen

@ -4,6 +4,7 @@ import nl.matsv.viabackwards.ViaBackwards;
import nl.matsv.viabackwards.api.entities.storage.EntityData; import nl.matsv.viabackwards.api.entities.storage.EntityData;
import nl.matsv.viabackwards.api.entities.storage.MetaStorage; import nl.matsv.viabackwards.api.entities.storage.MetaStorage;
import nl.matsv.viabackwards.api.entities.types.AbstractEntityType; import nl.matsv.viabackwards.api.entities.types.AbstractEntityType;
import nl.matsv.viabackwards.api.entities.types.EntityType1_12;
import nl.matsv.viabackwards.api.entities.types.EntityType1_13; import nl.matsv.viabackwards.api.entities.types.EntityType1_13;
import nl.matsv.viabackwards.api.entities.types.EntityType1_13.EntityType; import nl.matsv.viabackwards.api.entities.types.EntityType1_13.EntityType;
import nl.matsv.viabackwards.api.rewriters.EntityRewriter; import nl.matsv.viabackwards.api.rewriters.EntityRewriter;
@ -19,152 +20,153 @@ import us.myles.ViaVersion.api.type.Type;
import us.myles.ViaVersion.api.type.types.version.Types1_12; import us.myles.ViaVersion.api.type.types.version.Types1_12;
import us.myles.ViaVersion.api.type.types.version.Types1_13; import us.myles.ViaVersion.api.type.types.version.Types1_13;
import us.myles.ViaVersion.packets.State; import us.myles.ViaVersion.packets.State;
import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.ChatRewriter;
import us.myles.ViaVersion.protocols.protocol1_9_3to1_9_1_2.storage.ClientWorld; import us.myles.ViaVersion.protocols.protocol1_9_3to1_9_1_2.storage.ClientWorld;
import java.util.Optional; import java.util.Optional;
public class EntityPackets1_13 extends EntityRewriter<Protocol1_12_2To1_13> { public class EntityPackets1_13 extends EntityRewriter<Protocol1_12_2To1_13> {
@Override @Override
protected void registerPackets(Protocol1_12_2To1_13 protocol) { protected void registerPackets(Protocol1_12_2To1_13 protocol) {
//Spawn Object //Spawn Object
protocol.out(State.PLAY, 0x00, 0x00, new PacketRemapper() { protocol.out(State.PLAY, 0x00, 0x00, new PacketRemapper() {
@Override @Override
public void registerMap() { public void registerMap() {
map(Type.VAR_INT); map(Type.VAR_INT);
map(Type.UUID); map(Type.UUID);
map(Type.BYTE); map(Type.BYTE);
map(Type.DOUBLE); map(Type.DOUBLE);
map(Type.DOUBLE); map(Type.DOUBLE);
map(Type.DOUBLE); map(Type.DOUBLE);
map(Type.BYTE); map(Type.BYTE);
map(Type.BYTE); map(Type.BYTE);
map(Type.INT); map(Type.INT);
handler(new PacketHandler() { handler(new PacketHandler() {
@Override @Override
public void handle(PacketWrapper wrapper) throws Exception { public void handle(PacketWrapper wrapper) throws Exception {
byte type = wrapper.get(Type.BYTE, 0); byte type = wrapper.get(Type.BYTE, 0);
EntityType entityType = EntityType1_13.getTypeFromId(type, true); EntityType entityType = EntityType1_13.getTypeFromId(type, true);
if (entityType == null) { if (entityType == null) {
ViaBackwards.getPlatform().getLogger().warning("Could not find 1.13 entity type " + type); ViaBackwards.getPlatform().getLogger().warning("Could not find 1.13 entity type " + type);
return; return;
} }
addTrackedEntity( addTrackedEntity(
wrapper.user(), wrapper.user(),
wrapper.get(Type.VAR_INT, 0), wrapper.get(Type.VAR_INT, 0),
entityType entityType
); );
} }
}); });
handler(new PacketHandler() { handler(new PacketHandler() {
@Override @Override
public void handle(PacketWrapper wrapper) throws Exception { public void handle(PacketWrapper wrapper) throws Exception {
Optional<EntityType1_13.ObjectType> type = EntityType1_13.ObjectType.findById(wrapper.get(Type.BYTE, 0)); Optional<EntityType1_13.ObjectType> type = EntityType1_13.ObjectType.findById(wrapper.get(Type.BYTE, 0));
if (type.isPresent() && type.get() == EntityType1_13.ObjectType.FALLING_BLOCK) { if (type.isPresent() && type.get() == EntityType1_13.ObjectType.FALLING_BLOCK) {
int blockState = wrapper.get(Type.INT, 0); int blockState = wrapper.get(Type.INT, 0);
int combined = BlockItemPackets1_13.toOldId(blockState); int combined = BlockItemPackets1_13.toOldId(blockState);
combined = ((combined >> 4) & 0xFFF) | ((combined & 0xF) << 12); combined = ((combined >> 4) & 0xFFF) | ((combined & 0xF) << 12);
wrapper.set(Type.INT, 0, combined); wrapper.set(Type.INT, 0, combined);
} else if (type.isPresent() && type.get() == EntityType1_13.ObjectType.ITEM_FRAME) { } else if (type.isPresent() && type.get() == EntityType1_13.ObjectType.ITEM_FRAME) {
int data = wrapper.get(Type.INT, 0); int data = wrapper.get(Type.INT, 0);
switch (data) { switch (data) {
case 3: case 3:
data = 0; data = 0;
break; break;
case 4: case 4:
data = 1; data = 1;
break; break;
case 5: case 5:
data = 3; data = 3;
break; break;
} }
wrapper.set(Type.INT, 0, data); wrapper.set(Type.INT, 0, data);
} }
} }
}); });
} }
}); });
//Spawn Experience Orb //Spawn Experience Orb
protocol.out(State.PLAY, 0x01, 0x01, new PacketRemapper() { protocol.out(State.PLAY, 0x01, 0x01, new PacketRemapper() {
@Override @Override
public void registerMap() { public void registerMap() {
map(Type.VAR_INT); map(Type.VAR_INT);
handler(new PacketHandler() { handler(new PacketHandler() {
@Override @Override
public void handle(PacketWrapper wrapper) throws Exception { public void handle(PacketWrapper wrapper) throws Exception {
addTrackedEntity( addTrackedEntity(
wrapper.user(), wrapper.user(),
wrapper.get(Type.VAR_INT, 0), wrapper.get(Type.VAR_INT, 0),
EntityType.XP_ORB EntityType.XP_ORB
); );
} }
}); });
} }
}); });
//Spawn Global Entity //Spawn Global Entity
protocol.out(State.PLAY, 0x02, 0x02, new PacketRemapper() { protocol.out(State.PLAY, 0x02, 0x02, new PacketRemapper() {
@Override @Override
public void registerMap() { public void registerMap() {
map(Type.VAR_INT); map(Type.VAR_INT);
map(Type.BYTE); map(Type.BYTE);
handler(new PacketHandler() { handler(new PacketHandler() {
@Override @Override
public void handle(PacketWrapper wrapper) throws Exception { public void handle(PacketWrapper wrapper) throws Exception {
addTrackedEntity( addTrackedEntity(
wrapper.user(), wrapper.user(),
wrapper.get(Type.VAR_INT, 0), wrapper.get(Type.VAR_INT, 0),
EntityType.LIGHTNING_BOLT EntityType.LIGHTNING_BOLT
); );
} }
}); });
} }
}); });
//Spawn Mob //Spawn Mob
protocol.out(State.PLAY, 0x03, 0x03, new PacketRemapper() { protocol.out(State.PLAY, 0x03, 0x03, new PacketRemapper() {
@Override @Override
public void registerMap() { public void registerMap() {
map(Type.VAR_INT); map(Type.VAR_INT);
map(Type.UUID); map(Type.UUID);
map(Type.VAR_INT); map(Type.VAR_INT);
map(Type.DOUBLE); map(Type.DOUBLE);
map(Type.DOUBLE); map(Type.DOUBLE);
map(Type.DOUBLE); map(Type.DOUBLE);
map(Type.BYTE); map(Type.BYTE);
map(Type.BYTE); map(Type.BYTE);
map(Type.BYTE); map(Type.BYTE);
map(Type.SHORT); map(Type.SHORT);
map(Type.SHORT); map(Type.SHORT);
map(Type.SHORT); map(Type.SHORT);
map(Types1_13.METADATA_LIST, Types1_12.METADATA_LIST); map(Types1_13.METADATA_LIST, Types1_12.METADATA_LIST);
handler(new PacketHandler() { handler(new PacketHandler() {
@Override @Override
public void handle(PacketWrapper wrapper) throws Exception { public void handle(PacketWrapper wrapper) throws Exception {
int type = wrapper.get(Type.VAR_INT, 1); int type = wrapper.get(Type.VAR_INT, 1);
EntityType entityType = EntityType1_13.getTypeFromId(type, false); EntityType entityType = EntityType1_13.getTypeFromId(type, false);
addTrackedEntity( addTrackedEntity(
wrapper.user(), wrapper.user(),
wrapper.get(Type.VAR_INT, 0), wrapper.get(Type.VAR_INT, 0),
entityType entityType
); );
Optional<Integer> oldId = EntityTypeMapping.getOldId(type); Optional<Integer> oldId = EntityTypeMapping.getOldId(type);
if (!oldId.isPresent()) { if (!oldId.isPresent()) {
ViaBackwards.getPlatform().getLogger().warning("Could not find 1.12 entity type for 1.13 entity type " + type + "/" + entityType); if (!hasData(entityType))
return; ViaBackwards.getPlatform().getLogger().warning("Could not find 1.12 entity type for 1.13 entity type " + type + "/" + entityType);
} else { } else {
wrapper.set(Type.VAR_INT, 1, oldId.get()); wrapper.set(Type.VAR_INT, 1, oldId.get());
} }
} }
}); });
// Handle entity type & metadata // Handle entity type & metadata
handler(new PacketHandler() { handler(new PacketHandler() {
@Override @Override
public void handle(PacketWrapper wrapper) throws Exception { public void handle(PacketWrapper wrapper) throws Exception {
int entityId = wrapper.get(Type.VAR_INT, 0); int entityId = wrapper.get(Type.VAR_INT, 0);
AbstractEntityType type = getEntityType(wrapper.user(), entityId); AbstractEntityType type = getEntityType(wrapper.user(), entityId);
@ -176,12 +178,16 @@ public class EntityPackets1_13 extends EntityRewriter<Protocol1_12_2To1_13> {
); );
Optional<EntityData> optEntDat = getEntityData(type); Optional<EntityData> optEntDat = getEntityData(type);
System.out.println(optEntDat + " OPTENT");
if (optEntDat.isPresent()) { if (optEntDat.isPresent()) {
EntityData data = optEntDat.get(); EntityData data = optEntDat.get();
wrapper.set(Type.VAR_INT, 1, data.getReplacementId());
Optional<Integer> replacementId = EntityTypeMapping.getOldId(data.getReplacementId());
wrapper.set(Type.VAR_INT, 1, replacementId.orElse(EntityType1_12.EntityType.ZOMBIE.getId()));
if (data.hasBaseMeta()) if (data.hasBaseMeta())
data.getDefaultMeta().handle(storage); data.getDefaultMeta().handle(storage);
} }
System.out.println(storage.getMetaDataList());
// Rewrite Metadata // Rewrite Metadata
wrapper.set( wrapper.set(
@ -190,34 +196,34 @@ public class EntityPackets1_13 extends EntityRewriter<Protocol1_12_2To1_13> {
storage.getMetaDataList() storage.getMetaDataList()
); );
} }
}); });
} }
}); });
// Spawn Player // Spawn Player
protocol.out(State.PLAY, 0x05, 0x05, new PacketRemapper() { protocol.out(State.PLAY, 0x05, 0x05, new PacketRemapper() {
@Override @Override
public void registerMap() { public void registerMap() {
map(Type.VAR_INT); map(Type.VAR_INT);
map(Type.UUID); map(Type.UUID);
map(Type.DOUBLE); map(Type.DOUBLE);
map(Type.DOUBLE); map(Type.DOUBLE);
map(Type.DOUBLE); map(Type.DOUBLE);
map(Type.BYTE); map(Type.BYTE);
map(Type.BYTE); map(Type.BYTE);
map(Types1_13.METADATA_LIST, Types1_12.METADATA_LIST); map(Types1_13.METADATA_LIST, Types1_12.METADATA_LIST);
// Track Entity // Track Entity
handler(new PacketHandler() { handler(new PacketHandler() {
@Override @Override
public void handle(PacketWrapper wrapper) throws Exception { public void handle(PacketWrapper wrapper) throws Exception {
addTrackedEntity( addTrackedEntity(
wrapper.user(), wrapper.user(),
wrapper.get(Type.VAR_INT, 0), wrapper.get(Type.VAR_INT, 0),
EntityType.PLAYER EntityType.PLAYER
); );
} }
}); });
// Rewrite Metadata // Rewrite Metadata
handler(new PacketHandler() { handler(new PacketHandler() {
@ -235,34 +241,34 @@ public class EntityPackets1_13 extends EntityRewriter<Protocol1_12_2To1_13> {
} }
}); });
} }
}); });
//Spawn Painting //Spawn Painting
protocol.out(State.PLAY, 0x04, 0x04, new PacketRemapper() { protocol.out(State.PLAY, 0x04, 0x04, new PacketRemapper() {
@Override @Override
public void registerMap() { public void registerMap() {
map(Type.VAR_INT); map(Type.VAR_INT);
map(Type.UUID); map(Type.UUID);
handler(new PacketHandler() { handler(new PacketHandler() {
@Override @Override
public void handle(PacketWrapper wrapper) throws Exception { public void handle(PacketWrapper wrapper) throws Exception {
addTrackedEntity( addTrackedEntity(
wrapper.user(), wrapper.user(),
wrapper.get(Type.VAR_INT, 0), wrapper.get(Type.VAR_INT, 0),
EntityType.PAINTING EntityType.PAINTING
); );
} }
}); });
handler(new PacketHandler() { handler(new PacketHandler() {
@Override @Override
public void handle(PacketWrapper wrapper) throws Exception { public void handle(PacketWrapper wrapper) throws Exception {
int motive = wrapper.read(Type.VAR_INT); int motive = wrapper.read(Type.VAR_INT);
String title = PaintingMapping.getStringId(motive); String title = PaintingMapping.getStringId(motive);
wrapper.write(Type.STRING, title); wrapper.write(Type.STRING, title);
} }
}); });
} }
}); });
// Join game // Join game
protocol.out(State.PLAY, 0x25, 0x23, new PacketRemapper() { protocol.out(State.PLAY, 0x25, 0x23, new PacketRemapper() {
@ -272,6 +278,19 @@ public class EntityPackets1_13 extends EntityRewriter<Protocol1_12_2To1_13> {
map(Type.UNSIGNED_BYTE); // 1 - Gamemode map(Type.UNSIGNED_BYTE); // 1 - Gamemode
map(Type.INT); // 2 - Dimension map(Type.INT); // 2 - Dimension
// Track Entity
handler(new PacketHandler() {
@Override
public void handle(PacketWrapper wrapper) throws Exception {
addTrackedEntity(
wrapper.user(),
wrapper.get(Type.INT, 0),
EntityType1_12.EntityType.PLAYER
);
}
});
// Save dimension
handler(new PacketHandler() { handler(new PacketHandler() {
@Override @Override
public void handle(PacketWrapper wrapper) throws Exception { public void handle(PacketWrapper wrapper) throws Exception {
@ -321,70 +340,125 @@ public class EntityPackets1_13 extends EntityRewriter<Protocol1_12_2To1_13> {
protocol.registerOutgoing(State.PLAY, 0x3F, 0x3C, new PacketRemapper() { protocol.registerOutgoing(State.PLAY, 0x3F, 0x3C, new PacketRemapper() {
@Override @Override
public void registerMap() { public void registerMap() {
// TODO HANDLE map(Type.VAR_INT); // 0 - Entity ID
map(Types1_13.METADATA_LIST, Types1_12.METADATA_LIST); // 1 - Metadata list
handler(new PacketHandler() { handler(new PacketHandler() {
@Override @Override
public void handle(PacketWrapper wrapper) throws Exception { public void handle(PacketWrapper wrapper) throws Exception {
wrapper.cancel(); wrapper.set(
Types1_12.METADATA_LIST,
0,
handleMeta(
wrapper.user(),
wrapper.get(Type.VAR_INT, 0),
new MetaStorage(wrapper.get(Types1_12.METADATA_LIST, 0))
).getMetaDataList()
);
} }
}); });
} }
}); });
} }
@Override @Override
protected void registerRewrites() { protected void registerRewrites() {
// Rewrite new Entity 'drowned' // Rewrite new Entity 'drowned'
regEntType(EntityType.DROWNED, EntityType.ZOMBIE_VILLAGER).mobName("Drowned"); regEntType(EntityType.DROWNED, EntityType.ZOMBIE_VILLAGER).mobName("Drowned");
// Fishy // Fishy
regEntType(EntityType.COD_MOB, EntityType.SQUID).mobName("Cod"); regEntType(EntityType.COD_MOB, EntityType.SQUID).mobName("Cod");
regEntType(EntityType.SALMON_MOB, EntityType.SQUID).mobName("Salmon"); regEntType(EntityType.SALMON_MOB, EntityType.SQUID).mobName("Salmon");
regEntType(EntityType.PUFFER_FISH, EntityType.SQUID).mobName("Puffer Fish"); regEntType(EntityType.PUFFER_FISH, EntityType.SQUID).mobName("Puffer Fish");
regEntType(EntityType.TROPICAL_FISH, EntityType.SQUID).mobName("Tropical Fish"); regEntType(EntityType.TROPICAL_FISH, EntityType.SQUID).mobName("Tropical Fish");
// Phantom // Phantom
regEntType(EntityType.PHANTOM, EntityType.PARROT).mobName("Phantom"); regEntType(EntityType.PHANTOM, EntityType.PARROT).mobName("Phantom").spawnMetadata(storage -> {
// The phantom is grey/blue so let's do yellow/blue
storage.add(new Metadata(15, MetaType1_12.VarInt, 3));
});
// Dolphin // Dolphin
regEntType(EntityType.DOLPHIN, EntityType.SQUID).mobName("Dolphin"); regEntType(EntityType.DOLPHIN, EntityType.SQUID).mobName("Dolphin");
// Turtle // Turtle
regEntType(EntityType.TURTLE, EntityType.OCELOT).mobName("Turtle"); regEntType(EntityType.TURTLE, EntityType.OCELOT).mobName("Turtle");
// Rewrite Meta types // Rewrite Meta types
this.registerMetaHandler().handle(e -> { registerMetaHandler().handle(e -> {
Metadata meta = e.getData(); Metadata meta = e.getData();
int typeId = meta.getMetaType().getTypeID(); int typeId = meta.getMetaType().getTypeID();
// Rewrite optional chat to chat // Rewrite optional chat to chat
if (typeId == 5) { if (typeId == 5) {
meta.setMetaType(MetaType1_12.Chat); meta.setMetaType(MetaType1_12.String);
if (meta.getValue() == null) { if (meta.getValue() == null) {
meta.setValue(""); meta.setValue("");
} }
} }
// Discontinue particles // Discontinue particles
else if (typeId == 15) { else if (typeId == 15) {
meta.setMetaType(MetaType1_12.Discontinued); meta.setMetaType(MetaType1_12.Discontinued);
} }
// Rewrite to 1.12 ids // Rewrite to 1.12 ids
else if (typeId > 5) { else if (typeId > 5) {
meta.setMetaType(MetaType1_12.byId( meta.setMetaType(MetaType1_12.byId(
typeId - 1 typeId - 1
)); ));
} }
return e.getData(); return meta;
}); });
// TODO Remove everything for now // Rewrite Custom Name from Chat to String
this.registerMetaHandler().removed(); registerMetaHandler().filter(EntityType.ENTITY, true, 2).handle(e -> {
Metadata meta = e.getData();
} meta.setValue(
ChatRewriter.jsonTextToLegacy(
(String) meta.getValue()
)
);
return meta;
});
// Handle zombie metadata
registerMetaHandler().filter(EntityType.ZOMBIE, true, 15).removed();
registerMetaHandler().filter(EntityType.ZOMBIE, true).handle(e -> {
Metadata meta = e.getData();
if (meta.getId() > 15) {
meta.setId(meta.getId() - 1);
}
return meta;
});
// Handle turtle metadata (Remove them all for now)
registerMetaHandler().filter(EntityType.TURTLE, 13).removed(); // Home pos
registerMetaHandler().filter(EntityType.TURTLE, 14).removed(); // Has egg
registerMetaHandler().filter(EntityType.TURTLE, 15).removed(); // Laying egg
registerMetaHandler().filter(EntityType.TURTLE, 16).removed(); // Travel pos
registerMetaHandler().filter(EntityType.TURTLE, 17).removed(); // Going home
registerMetaHandler().filter(EntityType.TURTLE, 18).removed(); // Traveling
// Remove additional fish meta
registerMetaHandler().filter(EntityType.ABSTRACT_FISHES, true, 12).removed();
registerMetaHandler().filter(EntityType.ABSTRACT_FISHES, true, 13).removed();
// Remove phantom size
registerMetaHandler().filter(EntityType.PHANTOM, 12).removed();
// Remove boat splash timer
registerMetaHandler().filter(EntityType.BOAT, 12).removed();
// Remove Trident special loyalty level
registerMetaHandler().filter(EntityType.TRIDENT, 7).removed();
}
} }