Rewrite metadata changes en add missing entity track

This commit is contained in:
Matsv 2019-01-19 15:53:31 +01:00
parent 87f217ca37
commit 842631feef
2 changed files with 307 additions and 228 deletions

View File

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

View File

@ -4,6 +4,7 @@ import nl.matsv.viabackwards.ViaBackwards;
import nl.matsv.viabackwards.api.entities.storage.EntityData;
import nl.matsv.viabackwards.api.entities.storage.MetaStorage;
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.EntityType;
import nl.matsv.viabackwards.api.rewriters.EntityRewriter;
@ -19,6 +20,7 @@ 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_13;
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 java.util.Optional;
@ -153,8 +155,8 @@ public class EntityPackets1_13 extends EntityRewriter<Protocol1_12_2To1_13> {
);
Optional<Integer> oldId = EntityTypeMapping.getOldId(type);
if (!oldId.isPresent()) {
if (!hasData(entityType))
ViaBackwards.getPlatform().getLogger().warning("Could not find 1.12 entity type for 1.13 entity type " + type + "/" + entityType);
return;
} else {
wrapper.set(Type.VAR_INT, 1, oldId.get());
}
@ -176,12 +178,16 @@ public class EntityPackets1_13 extends EntityRewriter<Protocol1_12_2To1_13> {
);
Optional<EntityData> optEntDat = getEntityData(type);
System.out.println(optEntDat + " OPTENT");
if (optEntDat.isPresent()) {
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())
data.getDefaultMeta().handle(storage);
}
System.out.println(storage.getMetaDataList());
// Rewrite Metadata
wrapper.set(
@ -272,6 +278,19 @@ public class EntityPackets1_13 extends EntityRewriter<Protocol1_12_2To1_13> {
map(Type.UNSIGNED_BYTE); // 1 - Gamemode
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() {
@Override
public void handle(PacketWrapper wrapper) throws Exception {
@ -321,12 +340,21 @@ public class EntityPackets1_13 extends EntityRewriter<Protocol1_12_2To1_13> {
protocol.registerOutgoing(State.PLAY, 0x3F, 0x3C, new PacketRemapper() {
@Override
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() {
@Override
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()
);
}
});
}
@ -345,7 +373,10 @@ public class EntityPackets1_13 extends EntityRewriter<Protocol1_12_2To1_13> {
regEntType(EntityType.TROPICAL_FISH, EntityType.SQUID).mobName("Tropical Fish");
// 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
regEntType(EntityType.DOLPHIN, EntityType.SQUID).mobName("Dolphin");
@ -355,13 +386,13 @@ public class EntityPackets1_13 extends EntityRewriter<Protocol1_12_2To1_13> {
// Rewrite Meta types
this.registerMetaHandler().handle(e -> {
registerMetaHandler().handle(e -> {
Metadata meta = e.getData();
int typeId = meta.getMetaType().getTypeID();
// Rewrite optional chat to chat
if (typeId == 5) {
meta.setMetaType(MetaType1_12.Chat);
meta.setMetaType(MetaType1_12.String);
if (meta.getValue() == null) {
meta.setValue("");
@ -380,11 +411,54 @@ public class EntityPackets1_13 extends EntityRewriter<Protocol1_12_2To1_13> {
));
}
return e.getData();
return meta;
});
// TODO Remove everything for now
this.registerMetaHandler().removed();
// Rewrite Custom Name from Chat to String
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();
}
}