3
0
Mirror von https://github.com/ViaVersion/ViaVersion.git synchronisiert 2024-11-03 14:50:30 +01:00

1.14.1 abstraction

Dieser Commit ist enthalten in:
Gerrygames 2019-05-14 10:21:50 +02:00
Ursprung f25442337d
Commit 2e37175dc2
6 geänderte Dateien mit 48 neuen und 88 gelöschten Zeilen

Datei anzeigen

@ -1,33 +0,0 @@
package us.myles.ViaVersion.protocols.protocol1_14_1to1_14;
import us.myles.ViaVersion.api.Via;
import us.myles.ViaVersion.api.data.UserConnection;
import us.myles.ViaVersion.api.entities.Entity1_14Types;
import us.myles.ViaVersion.api.minecraft.metadata.Metadata;
import java.util.ArrayList;
import java.util.List;
public class MetadataRewriter {
public static void handleMetadata(int entityId, Entity1_14Types.EntityType type, List<Metadata> metadatas, UserConnection connection) {
if (type == null) return;
for (Metadata metadata : new ArrayList<>(metadatas)) {
try {
if (type.is(Entity1_14Types.EntityType.VILLAGER) || type.is(Entity1_14Types.EntityType.WANDERING_TRADER)) {
if (metadata.getId() >= 15) {
metadata.setId(metadata.getId() + 1);
}
}
} catch (Exception e) {
metadatas.remove(metadata);
if (!Via.getConfig().isSuppressMetadataErrors() || Via.getManager().isDebug()) {
Via.getPlatform().getLogger().warning("An error occurred with entity metadata handler");
Via.getPlatform().getLogger().warning("Metadata: " + metadata);
e.printStackTrace();
}
}
}
}
}

Datei anzeigen

@ -2,18 +2,21 @@ package us.myles.ViaVersion.protocols.protocol1_14_1to1_14;
import us.myles.ViaVersion.api.data.UserConnection;
import us.myles.ViaVersion.api.protocol.Protocol;
import us.myles.ViaVersion.protocols.protocol1_14_1to1_14.metadata.MetadataRewriter1_14_1To1_14;
import us.myles.ViaVersion.protocols.protocol1_14_1to1_14.packets.EntityPackets;
import us.myles.ViaVersion.protocols.protocol1_14_1to1_14.storage.EntityTracker;
import us.myles.ViaVersion.protocols.protocol1_14_1to1_14.storage.EntityTracker1_14_1;
public class Protocol1_14_1To1_14 extends Protocol {
@Override
protected void registerPackets() {
put(new MetadataRewriter1_14_1To1_14());
EntityPackets.register(this);
}
@Override
public void init(UserConnection userConnection) {
userConnection.put(new EntityTracker(userConnection));
userConnection.put(new EntityTracker1_14_1(userConnection));
}
}

Datei anzeigen

@ -0,0 +1,22 @@
package us.myles.ViaVersion.protocols.protocol1_14_1to1_14.metadata;
import us.myles.ViaVersion.api.data.UserConnection;
import us.myles.ViaVersion.api.entities.Entity1_14Types;
import us.myles.ViaVersion.api.entities.Entity1_14Types.EntityType;
import us.myles.ViaVersion.api.minecraft.metadata.Metadata;
import us.myles.ViaVersion.api.rewriters.MetadataRewriter;
import java.util.List;
public class MetadataRewriter1_14_1To1_14 extends MetadataRewriter<Entity1_14Types.EntityType> {
public void handleMetadata(int entityId, EntityType type, Metadata metadata, List<Metadata> metadatas, UserConnection connection) {
if (type == null) return;
if (type.is(EntityType.VILLAGER) || type.is(EntityType.WANDERING_TRADER)) {
if (metadata.getId() >= 15) {
metadata.setId(metadata.getId() + 1);
}
}
}
}

Datei anzeigen

@ -9,8 +9,8 @@ import us.myles.ViaVersion.api.remapper.PacketRemapper;
import us.myles.ViaVersion.api.type.Type;
import us.myles.ViaVersion.api.type.types.version.Types1_14;
import us.myles.ViaVersion.packets.State;
import us.myles.ViaVersion.protocols.protocol1_14_1to1_14.MetadataRewriter;
import us.myles.ViaVersion.protocols.protocol1_14_1to1_14.storage.EntityTracker;
import us.myles.ViaVersion.protocols.protocol1_14_1to1_14.metadata.MetadataRewriter1_14_1To1_14;
import us.myles.ViaVersion.protocols.protocol1_14_1to1_14.storage.EntityTracker1_14_1;
public class EntityPackets {
@ -43,9 +43,9 @@ public class EntityPackets {
Entity1_14Types.EntityType entType = Entity1_14Types.getTypeFromId(type);
// Register Type ID
wrapper.user().get(EntityTracker.class).addEntity(entityId, entType);
wrapper.user().get(EntityTracker1_14_1.class).addEntity(entityId, entType);
MetadataRewriter.handleMetadata(entityId, entType, wrapper.get(Types1_14.METADATA_LIST, 0), wrapper.user());
protocol.get(MetadataRewriter1_14_1To1_14.class).handleMetadata(entityId, entType, wrapper.get(Types1_14.METADATA_LIST, 0), wrapper.user());
}
});
}
@ -72,8 +72,8 @@ public class EntityPackets {
Entity1_14Types.EntityType entType = Entity1_14Types.EntityType.PLAYER;
// Register Type ID
wrapper.user().get(EntityTracker.class).addEntity(entityId, entType);
MetadataRewriter.handleMetadata(entityId, entType, wrapper.get(Types1_14.METADATA_LIST, 0), wrapper.user());
wrapper.user().get(EntityTracker1_14_1.class).addEntity(entityId, entType);
protocol.get(MetadataRewriter1_14_1To1_14.class).handleMetadata(entityId, entType, wrapper.get(Types1_14.METADATA_LIST, 0), wrapper.user());
}
});
}
@ -91,8 +91,8 @@ public class EntityPackets {
public void handle(PacketWrapper wrapper) throws Exception {
int entityId = wrapper.get(Type.VAR_INT, 0);
Optional<Entity1_14Types.EntityType> type = wrapper.user().get(EntityTracker.class).get(entityId);
MetadataRewriter.handleMetadata(entityId, type.orNull(), wrapper.get(Types1_14.METADATA_LIST, 0), wrapper.user());
Optional<Entity1_14Types.EntityType> type = wrapper.user().get(EntityTracker1_14_1.class).getEntity(entityId);
protocol.get(MetadataRewriter1_14_1To1_14.class).handleMetadata(entityId, type.orNull(), wrapper.get(Types1_14.METADATA_LIST, 0), wrapper.user());
}
});
}

Datei anzeigen

@ -1,45 +0,0 @@
package us.myles.ViaVersion.protocols.protocol1_14_1to1_14.storage;
import com.google.common.base.Optional;
import lombok.Getter;
import lombok.Setter;
import us.myles.ViaVersion.api.data.ExternalJoinGameListener;
import us.myles.ViaVersion.api.data.StoredObject;
import us.myles.ViaVersion.api.data.UserConnection;
import us.myles.ViaVersion.api.entities.Entity1_14Types;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
public class EntityTracker extends StoredObject implements ExternalJoinGameListener {
private final Map<Integer, Entity1_14Types.EntityType> clientEntityTypes = new ConcurrentHashMap<>();
@Getter
@Setter
private int clientEntityId;
public EntityTracker(UserConnection user) {
super(user);
}
public void removeEntity(int entityId) {
clientEntityTypes.remove(entityId);
}
public void addEntity(int entityId, Entity1_14Types.EntityType type) {
clientEntityTypes.put(entityId, type);
}
public boolean has(int entityId) {
return clientEntityTypes.containsKey(entityId);
}
public Optional<Entity1_14Types.EntityType> get(int id) {
return Optional.fromNullable(clientEntityTypes.get(id));
}
@Override
public void onExternalJoinGame(int playerEntityId) {
clientEntityId = playerEntityId;
clientEntityTypes.put(playerEntityId, Entity1_14Types.EntityType.PLAYER);
}
}

Datei anzeigen

@ -0,0 +1,13 @@
package us.myles.ViaVersion.protocols.protocol1_14_1to1_14.storage;
import us.myles.ViaVersion.api.data.UserConnection;
import us.myles.ViaVersion.api.entities.Entity1_14Types;
import us.myles.ViaVersion.api.entities.Entity1_14Types.EntityType;
import us.myles.ViaVersion.api.storage.EntityTracker;
public class EntityTracker1_14_1 extends EntityTracker<Entity1_14Types.EntityType> {
public EntityTracker1_14_1(UserConnection user) {
super(user, EntityType.PLAYER);
}
}