Mirror von
https://github.com/ViaVersion/ViaVersion.git
synchronisiert 2024-12-27 08:30:09 +01:00
Entity tracker and rewriter cleanup (#1464)
Dieser Commit ist enthalten in:
Ursprung
44a4ffb26a
Commit
4e7c520abe
@ -1,20 +1,31 @@
|
|||||||
package us.myles.ViaVersion.api.rewriters;
|
package us.myles.ViaVersion.api.rewriters;
|
||||||
|
|
||||||
|
import us.myles.ViaVersion.api.PacketWrapper;
|
||||||
import us.myles.ViaVersion.api.Via;
|
import us.myles.ViaVersion.api.Via;
|
||||||
import us.myles.ViaVersion.api.data.UserConnection;
|
import us.myles.ViaVersion.api.data.UserConnection;
|
||||||
import us.myles.ViaVersion.api.entities.EntityType;
|
import us.myles.ViaVersion.api.entities.EntityType;
|
||||||
import us.myles.ViaVersion.api.minecraft.metadata.Metadata;
|
import us.myles.ViaVersion.api.minecraft.metadata.Metadata;
|
||||||
|
import us.myles.ViaVersion.api.protocol.Protocol;
|
||||||
|
import us.myles.ViaVersion.api.remapper.PacketHandler;
|
||||||
|
import us.myles.ViaVersion.api.remapper.PacketRemapper;
|
||||||
|
import us.myles.ViaVersion.api.storage.EntityTracker;
|
||||||
|
import us.myles.ViaVersion.api.type.Type;
|
||||||
|
import us.myles.ViaVersion.packets.State;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.*;
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
public abstract class MetadataRewriter<T extends EntityType> {
|
public abstract class MetadataRewriter<T extends Protocol> extends Rewriter<T> {
|
||||||
|
private final Class<? extends EntityTracker> entityTrackerClass;
|
||||||
|
|
||||||
public final void handleMetadata(int entityId, T type, List<Metadata> metadatas, UserConnection connection) {
|
protected MetadataRewriter(T protocol, Class<? extends EntityTracker> entityTrackerClass) {
|
||||||
|
super(protocol);
|
||||||
|
this.entityTrackerClass = entityTrackerClass;
|
||||||
|
protocol.put(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
public final void handleMetadata(int entityId, List<Metadata> metadatas, UserConnection connection) {
|
||||||
|
EntityType type = connection.get(entityTrackerClass).getEntity(entityId);
|
||||||
Map<Integer, Metadata> metadataMap = new HashMap<>(metadatas.size());
|
Map<Integer, Metadata> metadataMap = new HashMap<>(metadatas.size());
|
||||||
for (Metadata metadata : metadatas) {
|
for (Metadata metadata : metadatas) {
|
||||||
metadataMap.put(metadata.getId(), metadata);
|
metadataMap.put(metadata.getId(), metadata);
|
||||||
@ -41,9 +52,77 @@ public abstract class MetadataRewriter<T extends EntityType> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void handleMetadata(int entityId, T type, Metadata metadata, List<Metadata> metadatas, UserConnection connection) throws Exception {}
|
public void registerMetadataRewriter(int oldPacketId, int newPacketId, Type<List<Metadata>> oldMetaType, Type<List<Metadata>> newMetaType) {
|
||||||
|
getProtocol().registerOutgoing(State.PLAY, oldPacketId, newPacketId, new PacketRemapper() {
|
||||||
|
@Override
|
||||||
|
public void registerMap() {
|
||||||
|
map(Type.VAR_INT); // 0 - Entity ID
|
||||||
|
if (oldMetaType != null) {
|
||||||
|
map(oldMetaType, newMetaType);
|
||||||
|
} else {
|
||||||
|
map(newMetaType);
|
||||||
|
}
|
||||||
|
handler(new PacketHandler() {
|
||||||
|
@Override
|
||||||
|
public void handle(PacketWrapper wrapper) throws Exception {
|
||||||
|
int entityId = wrapper.get(Type.VAR_INT, 0);
|
||||||
|
List<Metadata> metadata = wrapper.get(newMetaType, 0);
|
||||||
|
handleMetadata(entityId, metadata, wrapper.user());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
protected void handleMetadata(int entityId, T type, Metadata metadata, List<Metadata> metadatas, Map<Integer, Metadata> metadataMap, UserConnection connection) throws Exception {
|
public void registerMetadataRewriter(int oldPacketId, int newPacketId, Type<List<Metadata>> metaType) {
|
||||||
|
registerMetadataRewriter(oldPacketId, newPacketId, null, metaType);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void registerExtraTracker(int packetId, EntityType entityType, Type intType) {
|
||||||
|
getProtocol().registerOutgoing(State.PLAY, packetId, packetId, new PacketRemapper() {
|
||||||
|
@Override
|
||||||
|
public void registerMap() {
|
||||||
|
map(intType); // 0 - Entity id
|
||||||
|
handler(new PacketHandler() {
|
||||||
|
@Override
|
||||||
|
public void handle(PacketWrapper wrapper) throws Exception {
|
||||||
|
wrapper.user().get(entityTrackerClass).addEntity((int) wrapper.get(intType, 0), entityType);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public void registerExtraTracker(int packetId, EntityType entityType) {
|
||||||
|
registerExtraTracker(packetId, entityType, Type.VAR_INT);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void registerEntityDestroy(int oldPacketId, int newPacketId) {
|
||||||
|
getProtocol().registerOutgoing(State.PLAY, oldPacketId, newPacketId, new PacketRemapper() {
|
||||||
|
@Override
|
||||||
|
public void registerMap() {
|
||||||
|
map(Type.VAR_INT_ARRAY); // 0 - Entity ids
|
||||||
|
handler(new PacketHandler() {
|
||||||
|
@Override
|
||||||
|
public void handle(PacketWrapper wrapper) throws Exception {
|
||||||
|
EntityTracker entityTracker = wrapper.user().get(entityTrackerClass);
|
||||||
|
for (int entity : wrapper.get(Type.VAR_INT_ARRAY, 0)) {
|
||||||
|
entityTracker.removeEntity(entity);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public void registerEntityDestroy(int packetId) {
|
||||||
|
registerEntityDestroy(packetId, packetId);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void handleMetadata(int entityId, EntityType type, Metadata metadata, List<Metadata> metadatas, UserConnection connection) throws Exception {
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void handleMetadata(int entityId, EntityType type, Metadata metadata, List<Metadata> metadatas, Map<Integer, Metadata> metadataMap, UserConnection connection) throws Exception {
|
||||||
handleMetadata(entityId, type, metadata, metadatas, connection);
|
handleMetadata(entityId, type, metadata, metadatas, connection);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
15
common/src/main/java/us/myles/ViaVersion/api/rewriters/Rewriter.java
Normale Datei
15
common/src/main/java/us/myles/ViaVersion/api/rewriters/Rewriter.java
Normale Datei
@ -0,0 +1,15 @@
|
|||||||
|
package us.myles.ViaVersion.api.rewriters;
|
||||||
|
|
||||||
|
import us.myles.ViaVersion.api.protocol.Protocol;
|
||||||
|
|
||||||
|
public abstract class Rewriter<T extends Protocol> {
|
||||||
|
protected final T protocol;
|
||||||
|
|
||||||
|
protected Rewriter(T protocol) {
|
||||||
|
this.protocol = protocol;
|
||||||
|
}
|
||||||
|
|
||||||
|
public T getProtocol() {
|
||||||
|
return protocol;
|
||||||
|
}
|
||||||
|
}
|
@ -6,15 +6,14 @@ import us.myles.ViaVersion.api.data.UserConnection;
|
|||||||
import us.myles.ViaVersion.api.entities.EntityType;
|
import us.myles.ViaVersion.api.entities.EntityType;
|
||||||
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Optional;
|
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
|
||||||
public abstract class EntityTracker<T extends EntityType> extends StoredObject implements ExternalJoinGameListener {
|
public abstract class EntityTracker extends StoredObject implements ExternalJoinGameListener {
|
||||||
private final Map<Integer, T> clientEntityTypes = new ConcurrentHashMap<>();
|
private final Map<Integer, EntityType> clientEntityTypes = new ConcurrentHashMap<>();
|
||||||
|
private final EntityType playerType;
|
||||||
private int clientEntityId;
|
private int clientEntityId;
|
||||||
private final T playerType;
|
|
||||||
|
|
||||||
protected EntityTracker(UserConnection user, T playerType) {
|
protected EntityTracker(UserConnection user, EntityType playerType) {
|
||||||
super(user);
|
super(user);
|
||||||
this.playerType = playerType;
|
this.playerType = playerType;
|
||||||
}
|
}
|
||||||
@ -23,7 +22,7 @@ public abstract class EntityTracker<T extends EntityType> extends StoredObject i
|
|||||||
clientEntityTypes.remove(entityId);
|
clientEntityTypes.remove(entityId);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addEntity(int entityId, T type) {
|
public void addEntity(int entityId, EntityType type) {
|
||||||
clientEntityTypes.put(entityId, type);
|
clientEntityTypes.put(entityId, type);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -31,8 +30,8 @@ public abstract class EntityTracker<T extends EntityType> extends StoredObject i
|
|||||||
return clientEntityTypes.containsKey(entityId);
|
return clientEntityTypes.containsKey(entityId);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Optional<T> getEntity(int entityId) {
|
public EntityType getEntity(int entityId) {
|
||||||
return Optional.ofNullable(clientEntityTypes.get(entityId));
|
return clientEntityTypes.get(entityId);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -21,8 +21,6 @@ import us.myles.ViaVersion.protocols.protocol1_11to1_10.storage.EntityTracker1_1
|
|||||||
import us.myles.ViaVersion.protocols.protocol1_9_1_2to1_9_3_4.types.Chunk1_9_3_4Type;
|
import us.myles.ViaVersion.protocols.protocol1_9_1_2to1_9_3_4.types.Chunk1_9_3_4Type;
|
||||||
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;
|
|
||||||
|
|
||||||
public class Protocol1_11To1_10 extends Protocol {
|
public class Protocol1_11To1_10 extends Protocol {
|
||||||
private static final ValueTransformer<Float, Short> toOldByte = new ValueTransformer<Float, Short>(Type.UNSIGNED_BYTE) {
|
private static final ValueTransformer<Float, Short> toOldByte = new ValueTransformer<Float, Short>(Type.UNSIGNED_BYTE) {
|
||||||
@Override
|
@Override
|
||||||
@ -33,7 +31,7 @@ public class Protocol1_11To1_10 extends Protocol {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void registerPackets() {
|
protected void registerPackets() {
|
||||||
put(new MetadataRewriter1_11To1_10());
|
MetadataRewriter1_11To1_10 metadataRewriter = new MetadataRewriter1_11To1_10(this);
|
||||||
|
|
||||||
InventoryPackets.register(this);
|
InventoryPackets.register(this);
|
||||||
|
|
||||||
@ -93,7 +91,7 @@ public class Protocol1_11To1_10 extends Protocol {
|
|||||||
|
|
||||||
// Register Type ID
|
// Register Type ID
|
||||||
wrapper.user().get(EntityTracker1_11.class).addEntity(entityId, entType);
|
wrapper.user().get(EntityTracker1_11.class).addEntity(entityId, entType);
|
||||||
get(MetadataRewriter1_11To1_10.class).handleMetadata(entityId, entType, wrapper.get(Types1_9.METADATA_LIST, 0), wrapper.user());
|
metadataRewriter.handleMetadata(entityId, wrapper.get(Types1_9.METADATA_LIST, 0), wrapper.user());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -143,25 +141,7 @@ public class Protocol1_11To1_10 extends Protocol {
|
|||||||
});
|
});
|
||||||
|
|
||||||
// Metadata packet
|
// Metadata packet
|
||||||
registerOutgoing(State.PLAY, 0x39, 0x39, new PacketRemapper() {
|
metadataRewriter.registerMetadataRewriter(0x39, 0x39, Types1_9.METADATA_LIST);
|
||||||
@Override
|
|
||||||
public void registerMap() {
|
|
||||||
map(Type.VAR_INT); // 0 - Entity ID
|
|
||||||
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);
|
|
||||||
|
|
||||||
Optional<Entity1_11Types.EntityType> type = wrapper.user().get(EntityTracker1_11.class).getEntity(entityId);
|
|
||||||
if (!type.isPresent())
|
|
||||||
return;
|
|
||||||
|
|
||||||
get(MetadataRewriter1_11To1_10.class).handleMetadata(entityId, type.get(), wrapper.get(Types1_9.METADATA_LIST, 0), wrapper.user());
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
// Entity teleport
|
// Entity teleport
|
||||||
registerOutgoing(State.PLAY, 0x49, 0x49, new PacketRemapper() {
|
registerOutgoing(State.PLAY, 0x49, 0x49, new PacketRemapper() {
|
||||||
@ -193,20 +173,7 @@ public class Protocol1_11To1_10 extends Protocol {
|
|||||||
});
|
});
|
||||||
|
|
||||||
// Destroy entities
|
// Destroy entities
|
||||||
registerOutgoing(State.PLAY, 0x30, 0x30, new PacketRemapper() {
|
metadataRewriter.registerEntityDestroy(0x30);
|
||||||
@Override
|
|
||||||
public void registerMap() {
|
|
||||||
map(Type.VAR_INT_ARRAY); // 0 - Entity IDS
|
|
||||||
|
|
||||||
handler(new PacketHandler() {
|
|
||||||
@Override
|
|
||||||
public void handle(PacketWrapper wrapper) throws Exception {
|
|
||||||
for (int entity : wrapper.get(Type.VAR_INT_ARRAY, 0))
|
|
||||||
wrapper.user().get(EntityTracker1_11.class).removeEntity(entity);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
// Title packet
|
// Title packet
|
||||||
registerOutgoing(State.PLAY, 0x45, 0x45, new PacketRemapper() {
|
registerOutgoing(State.PLAY, 0x45, 0x45, new PacketRemapper() {
|
||||||
@ -416,7 +383,9 @@ public class Protocol1_11To1_10 extends Protocol {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void init(UserConnection userConnection) {
|
public void init(UserConnection userConnection) {
|
||||||
|
// Entity tracker
|
||||||
userConnection.put(new EntityTracker1_11(userConnection));
|
userConnection.put(new EntityTracker1_11(userConnection));
|
||||||
|
|
||||||
if (!userConnection.has(ClientWorld.class))
|
if (!userConnection.has(ClientWorld.class))
|
||||||
userConnection.put(new ClientWorld(userConnection));
|
userConnection.put(new ClientWorld(userConnection));
|
||||||
}
|
}
|
||||||
|
@ -17,15 +17,20 @@ import java.util.List;
|
|||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
|
||||||
public class MetadataRewriter1_11To1_10 extends MetadataRewriter<EntityType> {
|
public class MetadataRewriter1_11To1_10 extends MetadataRewriter<Protocol1_11To1_10> {
|
||||||
|
|
||||||
|
public MetadataRewriter1_11To1_10(Protocol1_11To1_10 protocol) {
|
||||||
|
super(protocol, EntityTracker1_11.class);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void handleMetadata(int entityId, EntityType type, Metadata metadata, List<Metadata> metadatas, Map<Integer, Metadata> metadataMap, UserConnection connection) {
|
protected void handleMetadata(int entityId, us.myles.ViaVersion.api.entities.EntityType type, Metadata metadata, List<Metadata> metadatas, Map<Integer, Metadata> metadataMap, UserConnection connection) {
|
||||||
if (metadata.getValue() instanceof Item) {
|
if (metadata.getValue() instanceof Item) {
|
||||||
// Apply rewrite
|
// Apply rewrite
|
||||||
EntityIdRewriter.toClientItem((Item) metadata.getValue());
|
EntityIdRewriter.toClientItem((Item) metadata.getValue());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (type == null) return;
|
||||||
if (type.is(EntityType.ELDER_GUARDIAN) || type.is(EntityType.GUARDIAN)) { // Guardians
|
if (type.is(EntityType.ELDER_GUARDIAN) || type.is(EntityType.GUARDIAN)) { // Guardians
|
||||||
int oldid = metadata.getId();
|
int oldid = metadata.getId();
|
||||||
if (oldid == 12) {
|
if (oldid == 12) {
|
||||||
|
@ -2,13 +2,12 @@ package us.myles.ViaVersion.protocols.protocol1_11to1_10.storage;
|
|||||||
|
|
||||||
import com.google.common.collect.Sets;
|
import com.google.common.collect.Sets;
|
||||||
import us.myles.ViaVersion.api.data.UserConnection;
|
import us.myles.ViaVersion.api.data.UserConnection;
|
||||||
import us.myles.ViaVersion.api.entities.Entity1_11Types;
|
|
||||||
import us.myles.ViaVersion.api.entities.Entity1_11Types.EntityType;
|
import us.myles.ViaVersion.api.entities.Entity1_11Types.EntityType;
|
||||||
import us.myles.ViaVersion.api.storage.EntityTracker;
|
import us.myles.ViaVersion.api.storage.EntityTracker;
|
||||||
|
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
public class EntityTracker1_11 extends EntityTracker<Entity1_11Types.EntityType> {
|
public class EntityTracker1_11 extends EntityTracker {
|
||||||
private final Set<Integer> holograms = Sets.newConcurrentHashSet();
|
private final Set<Integer> holograms = Sets.newConcurrentHashSet();
|
||||||
|
|
||||||
public EntityTracker1_11(UserConnection user) {
|
public EntityTracker1_11(UserConnection user) {
|
||||||
|
@ -26,13 +26,11 @@ import us.myles.ViaVersion.protocols.protocol1_9_1_2to1_9_3_4.types.Chunk1_9_3_4
|
|||||||
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 us.myles.ViaVersion.protocols.protocol1_9to1_8.Protocol1_9To1_8;
|
import us.myles.ViaVersion.protocols.protocol1_9to1_8.Protocol1_9To1_8;
|
||||||
|
|
||||||
import java.util.Optional;
|
|
||||||
|
|
||||||
public class Protocol1_12To1_11_1 extends Protocol {
|
public class Protocol1_12To1_11_1 extends Protocol {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void registerPackets() {
|
protected void registerPackets() {
|
||||||
put(new MetadataRewriter1_12To1_11_1());
|
MetadataRewriter1_12To1_11_1 metadataRewriter = new MetadataRewriter1_12To1_11_1(this);
|
||||||
|
|
||||||
InventoryPackets.register(this);
|
InventoryPackets.register(this);
|
||||||
// Outgoing
|
// Outgoing
|
||||||
@ -89,7 +87,7 @@ public class Protocol1_12To1_11_1 extends Protocol {
|
|||||||
Entity1_12Types.EntityType entType = Entity1_12Types.getTypeFromId(type, false);
|
Entity1_12Types.EntityType entType = Entity1_12Types.getTypeFromId(type, false);
|
||||||
// Register Type ID
|
// Register Type ID
|
||||||
wrapper.user().get(EntityTracker1_12.class).addEntity(entityId, entType);
|
wrapper.user().get(EntityTracker1_12.class).addEntity(entityId, entType);
|
||||||
get(MetadataRewriter1_12To1_11_1.class).handleMetadata(entityId, entType, wrapper.get(Types1_12.METADATA_LIST, 0), wrapper.user());
|
metadataRewriter.handleMetadata(entityId, wrapper.get(Types1_12.METADATA_LIST, 0), wrapper.user());
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -191,22 +189,11 @@ public class Protocol1_12To1_11_1 extends Protocol {
|
|||||||
registerOutgoing(State.PLAY, 0x25, 0x26);
|
registerOutgoing(State.PLAY, 0x25, 0x26);
|
||||||
registerOutgoing(State.PLAY, 0x26, 0x27);
|
registerOutgoing(State.PLAY, 0x26, 0x27);
|
||||||
registerOutgoing(State.PLAY, 0x27, 0x28);
|
registerOutgoing(State.PLAY, 0x27, 0x28);
|
||||||
|
|
||||||
// New packet at 0x30
|
// New packet at 0x30
|
||||||
// Destroy entities
|
// Destroy entities
|
||||||
registerOutgoing(State.PLAY, 0x30, 0x31, new PacketRemapper() {
|
metadataRewriter.registerEntityDestroy(0x30, 0x31);
|
||||||
@Override
|
|
||||||
public void registerMap() {
|
|
||||||
map(Type.VAR_INT_ARRAY); // 0 - Entity IDS
|
|
||||||
|
|
||||||
handler(new PacketHandler() {
|
|
||||||
@Override
|
|
||||||
public void handle(PacketWrapper wrapper) throws Exception {
|
|
||||||
for (int entity : wrapper.get(Type.VAR_INT_ARRAY, 0))
|
|
||||||
wrapper.user().get(EntityTracker1_12.class).removeEntity(entity);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
registerOutgoing(State.PLAY, 0x31, 0x32);
|
registerOutgoing(State.PLAY, 0x31, 0x32);
|
||||||
registerOutgoing(State.PLAY, 0x32, 0x33);
|
registerOutgoing(State.PLAY, 0x32, 0x33);
|
||||||
// Respawn Packet
|
// Respawn Packet
|
||||||
@ -233,26 +220,10 @@ public class Protocol1_12To1_11_1 extends Protocol {
|
|||||||
registerOutgoing(State.PLAY, 0x36, 0x38);
|
registerOutgoing(State.PLAY, 0x36, 0x38);
|
||||||
registerOutgoing(State.PLAY, 0x37, 0x39);
|
registerOutgoing(State.PLAY, 0x37, 0x39);
|
||||||
registerOutgoing(State.PLAY, 0x38, 0x3a);
|
registerOutgoing(State.PLAY, 0x38, 0x3a);
|
||||||
|
|
||||||
// Metadata packet
|
// Metadata packet
|
||||||
registerOutgoing(State.PLAY, 0x39, 0x3b, new PacketRemapper() {
|
metadataRewriter.registerMetadataRewriter(0x39, 0x3b, Types1_12.METADATA_LIST);
|
||||||
@Override
|
|
||||||
public void registerMap() {
|
|
||||||
map(Type.VAR_INT); // 0 - Entity ID
|
|
||||||
map(Types1_12.METADATA_LIST); // 1 - Metadata list
|
|
||||||
handler(new PacketHandler() {
|
|
||||||
@Override
|
|
||||||
public void handle(PacketWrapper wrapper) throws Exception {
|
|
||||||
int entityId = wrapper.get(Type.VAR_INT, 0);
|
|
||||||
|
|
||||||
Optional<Entity1_12Types.EntityType> type = wrapper.user().get(EntityTracker1_12.class).getEntity(entityId);
|
|
||||||
if (!type.isPresent())
|
|
||||||
return;
|
|
||||||
|
|
||||||
get(MetadataRewriter1_12To1_11_1.class).handleMetadata(entityId, type.get(), wrapper.get(Types1_12.METADATA_LIST, 0), wrapper.user());
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
registerOutgoing(State.PLAY, 0x3a, 0x3c);
|
registerOutgoing(State.PLAY, 0x3a, 0x3c);
|
||||||
registerOutgoing(State.PLAY, 0x3b, 0x3d);
|
registerOutgoing(State.PLAY, 0x3b, 0x3d);
|
||||||
// registerOutgoing(State.PLAY, 0x3c, 0x3e); - Handled in InventoryPackets
|
// registerOutgoing(State.PLAY, 0x3c, 0x3e); - Handled in InventoryPackets
|
||||||
|
@ -2,15 +2,21 @@ package us.myles.ViaVersion.protocols.protocol1_12to1_11_1.metadata;
|
|||||||
|
|
||||||
import us.myles.ViaVersion.api.data.UserConnection;
|
import us.myles.ViaVersion.api.data.UserConnection;
|
||||||
import us.myles.ViaVersion.api.entities.Entity1_12Types;
|
import us.myles.ViaVersion.api.entities.Entity1_12Types;
|
||||||
import us.myles.ViaVersion.api.entities.Entity1_12Types.EntityType;
|
import us.myles.ViaVersion.api.entities.EntityType;
|
||||||
import us.myles.ViaVersion.api.minecraft.item.Item;
|
import us.myles.ViaVersion.api.minecraft.item.Item;
|
||||||
import us.myles.ViaVersion.api.minecraft.metadata.Metadata;
|
import us.myles.ViaVersion.api.minecraft.metadata.Metadata;
|
||||||
import us.myles.ViaVersion.api.rewriters.MetadataRewriter;
|
import us.myles.ViaVersion.api.rewriters.MetadataRewriter;
|
||||||
import us.myles.ViaVersion.protocols.protocol1_12to1_11_1.BedRewriter;
|
import us.myles.ViaVersion.protocols.protocol1_12to1_11_1.BedRewriter;
|
||||||
|
import us.myles.ViaVersion.protocols.protocol1_12to1_11_1.Protocol1_12To1_11_1;
|
||||||
|
import us.myles.ViaVersion.protocols.protocol1_12to1_11_1.storage.EntityTracker1_12;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class MetadataRewriter1_12To1_11_1 extends MetadataRewriter<Entity1_12Types.EntityType> {
|
public class MetadataRewriter1_12To1_11_1 extends MetadataRewriter<Protocol1_12To1_11_1> {
|
||||||
|
|
||||||
|
public MetadataRewriter1_12To1_11_1(Protocol1_12To1_11_1 protocol) {
|
||||||
|
super(protocol, EntityTracker1_12.class);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void handleMetadata(int entityId, EntityType type, Metadata metadata, List<Metadata> metadatas, UserConnection connection) {
|
protected void handleMetadata(int entityId, EntityType type, Metadata metadata, List<Metadata> metadatas, UserConnection connection) {
|
||||||
@ -18,8 +24,10 @@ public class MetadataRewriter1_12To1_11_1 extends MetadataRewriter<Entity1_12Typ
|
|||||||
// Apply rewrite
|
// Apply rewrite
|
||||||
BedRewriter.toClientItem((Item) metadata.getValue());
|
BedRewriter.toClientItem((Item) metadata.getValue());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (type == null) return;
|
||||||
// Evocation Illager aggressive property became 13
|
// Evocation Illager aggressive property became 13
|
||||||
if (type.is(EntityType.EVOCATION_ILLAGER)) {
|
if (type == Entity1_12Types.EntityType.EVOCATION_ILLAGER) {
|
||||||
if (metadata.getId() == 12) {
|
if (metadata.getId() == 12) {
|
||||||
metadata.setId(13);
|
metadata.setId(13);
|
||||||
}
|
}
|
||||||
|
@ -1,11 +1,10 @@
|
|||||||
package us.myles.ViaVersion.protocols.protocol1_12to1_11_1.storage;
|
package us.myles.ViaVersion.protocols.protocol1_12to1_11_1.storage;
|
||||||
|
|
||||||
import us.myles.ViaVersion.api.data.UserConnection;
|
import us.myles.ViaVersion.api.data.UserConnection;
|
||||||
import us.myles.ViaVersion.api.entities.Entity1_12Types;
|
|
||||||
import us.myles.ViaVersion.api.entities.Entity1_12Types.EntityType;
|
import us.myles.ViaVersion.api.entities.Entity1_12Types.EntityType;
|
||||||
import us.myles.ViaVersion.api.storage.EntityTracker;
|
import us.myles.ViaVersion.api.storage.EntityTracker;
|
||||||
|
|
||||||
public class EntityTracker1_12 extends EntityTracker<Entity1_12Types.EntityType> {
|
public class EntityTracker1_12 extends EntityTracker {
|
||||||
|
|
||||||
public EntityTracker1_12(UserConnection user) {
|
public EntityTracker1_12(UserConnection user) {
|
||||||
super(user, EntityType.PLAYER);
|
super(user, EntityType.PLAYER);
|
||||||
|
@ -20,7 +20,7 @@ public class Protocol1_13_1To1_13 extends Protocol {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void registerPackets() {
|
protected void registerPackets() {
|
||||||
put(new MetadataRewriter1_13_1To1_13());
|
new MetadataRewriter1_13_1To1_13(this);
|
||||||
|
|
||||||
EntityPackets.register(this);
|
EntityPackets.register(this);
|
||||||
InventoryPackets.register(this);
|
InventoryPackets.register(this);
|
||||||
|
@ -2,17 +2,22 @@ package us.myles.ViaVersion.protocols.protocol1_13_1to1_13.metadata;
|
|||||||
|
|
||||||
import us.myles.ViaVersion.api.data.UserConnection;
|
import us.myles.ViaVersion.api.data.UserConnection;
|
||||||
import us.myles.ViaVersion.api.entities.Entity1_13Types;
|
import us.myles.ViaVersion.api.entities.Entity1_13Types;
|
||||||
import us.myles.ViaVersion.api.entities.Entity1_13Types.EntityType;
|
import us.myles.ViaVersion.api.entities.EntityType;
|
||||||
import us.myles.ViaVersion.api.minecraft.item.Item;
|
import us.myles.ViaVersion.api.minecraft.item.Item;
|
||||||
import us.myles.ViaVersion.api.minecraft.metadata.Metadata;
|
import us.myles.ViaVersion.api.minecraft.metadata.Metadata;
|
||||||
import us.myles.ViaVersion.api.minecraft.metadata.types.MetaType1_13;
|
import us.myles.ViaVersion.api.minecraft.metadata.types.MetaType1_13;
|
||||||
import us.myles.ViaVersion.api.rewriters.MetadataRewriter;
|
import us.myles.ViaVersion.api.rewriters.MetadataRewriter;
|
||||||
import us.myles.ViaVersion.protocols.protocol1_13_1to1_13.Protocol1_13_1To1_13;
|
import us.myles.ViaVersion.protocols.protocol1_13_1to1_13.Protocol1_13_1To1_13;
|
||||||
import us.myles.ViaVersion.protocols.protocol1_13_1to1_13.packets.InventoryPackets;
|
import us.myles.ViaVersion.protocols.protocol1_13_1to1_13.packets.InventoryPackets;
|
||||||
|
import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.storage.EntityTracker1_13;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class MetadataRewriter1_13_1To1_13 extends MetadataRewriter<Entity1_13Types.EntityType> {
|
public class MetadataRewriter1_13_1To1_13 extends MetadataRewriter<Protocol1_13_1To1_13> {
|
||||||
|
|
||||||
|
public MetadataRewriter1_13_1To1_13(Protocol1_13_1To1_13 protocol) {
|
||||||
|
super(protocol, EntityTracker1_13.class);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void handleMetadata(int entityId, EntityType type, Metadata metadata, List<Metadata> metadatas, UserConnection connection) {
|
protected void handleMetadata(int entityId, EntityType type, Metadata metadata, List<Metadata> metadatas, UserConnection connection) {
|
||||||
@ -27,13 +32,13 @@ public class MetadataRewriter1_13_1To1_13 extends MetadataRewriter<Entity1_13Typ
|
|||||||
|
|
||||||
if (type == null) return;
|
if (type == null) return;
|
||||||
|
|
||||||
if (type.isOrHasParent(EntityType.MINECART_ABSTRACT) && metadata.getId() == 9) {
|
if (type.isOrHasParent(Entity1_13Types.EntityType.MINECART_ABSTRACT) && metadata.getId() == 9) {
|
||||||
// New block format
|
// New block format
|
||||||
int data = (int) metadata.getValue();
|
int data = (int) metadata.getValue();
|
||||||
metadata.setValue(Protocol1_13_1To1_13.getNewBlockStateId(data));
|
metadata.setValue(Protocol1_13_1To1_13.getNewBlockStateId(data));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (type.isOrHasParent(EntityType.ABSTRACT_ARROW) && metadata.getId() >= 7) {
|
if (type.isOrHasParent(Entity1_13Types.EntityType.ABSTRACT_ARROW) && metadata.getId() >= 7) {
|
||||||
metadata.setId(metadata.getId() + 1); // New shooter UUID
|
metadata.setId(metadata.getId() + 1); // New shooter UUID
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -12,11 +12,10 @@ import us.myles.ViaVersion.protocols.protocol1_13_1to1_13.Protocol1_13_1To1_13;
|
|||||||
import us.myles.ViaVersion.protocols.protocol1_13_1to1_13.metadata.MetadataRewriter1_13_1To1_13;
|
import us.myles.ViaVersion.protocols.protocol1_13_1to1_13.metadata.MetadataRewriter1_13_1To1_13;
|
||||||
import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.storage.EntityTracker1_13;
|
import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.storage.EntityTracker1_13;
|
||||||
|
|
||||||
import java.util.Optional;
|
|
||||||
|
|
||||||
public class EntityPackets {
|
public class EntityPackets {
|
||||||
|
|
||||||
public static void register(final Protocol protocol) {
|
public static void register(final Protocol protocol) {
|
||||||
|
MetadataRewriter1_13_1To1_13 metadataRewriter = protocol.get(MetadataRewriter1_13_1To1_13.class);
|
||||||
|
|
||||||
//spawn entity
|
//spawn entity
|
||||||
protocol.registerOutgoing(State.PLAY, 0x0, 0x0, new PacketRemapper() {
|
protocol.registerOutgoing(State.PLAY, 0x0, 0x0, new PacketRemapper() {
|
||||||
@ -81,7 +80,7 @@ public class EntityPackets {
|
|||||||
// Register Type ID
|
// Register Type ID
|
||||||
wrapper.user().get(EntityTracker1_13.class).addEntity(entityId, entType);
|
wrapper.user().get(EntityTracker1_13.class).addEntity(entityId, entType);
|
||||||
|
|
||||||
protocol.get(MetadataRewriter1_13_1To1_13.class).handleMetadata(entityId, entType, wrapper.get(Types1_13.METADATA_LIST, 0), wrapper.user());
|
metadataRewriter.handleMetadata(entityId, wrapper.get(Types1_13.METADATA_LIST, 0), wrapper.user());
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -108,45 +107,16 @@ public class EntityPackets {
|
|||||||
Entity1_13Types.EntityType entType = Entity1_13Types.EntityType.PLAYER;
|
Entity1_13Types.EntityType entType = Entity1_13Types.EntityType.PLAYER;
|
||||||
// Register Type ID
|
// Register Type ID
|
||||||
wrapper.user().get(EntityTracker1_13.class).addEntity(entityId, entType);
|
wrapper.user().get(EntityTracker1_13.class).addEntity(entityId, entType);
|
||||||
protocol.get(MetadataRewriter1_13_1To1_13.class).handleMetadata(entityId, entType, wrapper.get(Types1_13.METADATA_LIST, 0), wrapper.user());
|
metadataRewriter.handleMetadata(entityId, wrapper.get(Types1_13.METADATA_LIST, 0), wrapper.user());
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// Destroy entities
|
// Destroy entities
|
||||||
protocol.registerOutgoing(State.PLAY, 0x35, 0x35, new PacketRemapper() {
|
metadataRewriter.registerEntityDestroy(0x35);
|
||||||
@Override
|
|
||||||
public void registerMap() {
|
|
||||||
map(Type.VAR_INT_ARRAY); // 0 - Entity IDS
|
|
||||||
|
|
||||||
handler(new PacketHandler() {
|
|
||||||
@Override
|
|
||||||
public void handle(PacketWrapper wrapper) throws Exception {
|
|
||||||
for (int entity : wrapper.get(Type.VAR_INT_ARRAY, 0))
|
|
||||||
wrapper.user().get(EntityTracker1_13.class).removeEntity(entity);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
|
|
||||||
// Metadata packet
|
// Metadata packet
|
||||||
protocol.registerOutgoing(State.PLAY, 0x3F, 0x3F, new PacketRemapper() {
|
metadataRewriter.registerMetadataRewriter(0x3F, 0x3F, Types1_13.METADATA_LIST);
|
||||||
@Override
|
|
||||||
public void registerMap() {
|
|
||||||
map(Type.VAR_INT); // 0 - Entity ID
|
|
||||||
map(Types1_13.METADATA_LIST); // 1 - Metadata list
|
|
||||||
handler(new PacketHandler() {
|
|
||||||
@Override
|
|
||||||
public void handle(PacketWrapper wrapper) throws Exception {
|
|
||||||
int entityId = wrapper.get(Type.VAR_INT, 0);
|
|
||||||
|
|
||||||
Optional<Entity1_13Types.EntityType> type = wrapper.user().get(EntityTracker1_13.class).getEntity(entityId);
|
|
||||||
protocol.get(MetadataRewriter1_13_1To1_13.class).handleMetadata(entityId, type.orElse(null), wrapper.get(Types1_13.METADATA_LIST, 0), wrapper.user());
|
|
||||||
}
|
}
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -132,7 +132,7 @@ public class Protocol1_13To1_12_2 extends Protocol {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void registerPackets() {
|
protected void registerPackets() {
|
||||||
put(new MetadataRewriter1_13To1_12_2());
|
new MetadataRewriter1_13To1_12_2(this);
|
||||||
|
|
||||||
// Register grouped packet changes
|
// Register grouped packet changes
|
||||||
EntityPackets.register(this);
|
EntityPackets.register(this);
|
||||||
|
@ -2,21 +2,27 @@ package us.myles.ViaVersion.protocols.protocol1_13to1_12_2.metadata;
|
|||||||
|
|
||||||
import us.myles.ViaVersion.api.data.UserConnection;
|
import us.myles.ViaVersion.api.data.UserConnection;
|
||||||
import us.myles.ViaVersion.api.entities.Entity1_13Types;
|
import us.myles.ViaVersion.api.entities.Entity1_13Types;
|
||||||
import us.myles.ViaVersion.api.entities.Entity1_13Types.EntityType;
|
import us.myles.ViaVersion.api.entities.EntityType;
|
||||||
import us.myles.ViaVersion.api.minecraft.item.Item;
|
import us.myles.ViaVersion.api.minecraft.item.Item;
|
||||||
import us.myles.ViaVersion.api.minecraft.metadata.Metadata;
|
import us.myles.ViaVersion.api.minecraft.metadata.Metadata;
|
||||||
import us.myles.ViaVersion.api.minecraft.metadata.types.MetaType1_13;
|
import us.myles.ViaVersion.api.minecraft.metadata.types.MetaType1_13;
|
||||||
import us.myles.ViaVersion.api.rewriters.MetadataRewriter;
|
import us.myles.ViaVersion.api.rewriters.MetadataRewriter;
|
||||||
import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.ChatRewriter;
|
import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.ChatRewriter;
|
||||||
|
import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.Protocol1_13To1_12_2;
|
||||||
import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.data.Particle;
|
import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.data.Particle;
|
||||||
import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.data.ParticleRewriter;
|
import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.data.ParticleRewriter;
|
||||||
import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.packets.InventoryPackets;
|
import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.packets.InventoryPackets;
|
||||||
import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.packets.WorldPackets;
|
import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.packets.WorldPackets;
|
||||||
|
import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.storage.EntityTracker1_13;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
public class MetadataRewriter1_13To1_12_2 extends MetadataRewriter<Entity1_13Types.EntityType> {
|
public class MetadataRewriter1_13To1_12_2 extends MetadataRewriter<Protocol1_13To1_12_2> {
|
||||||
|
|
||||||
|
public MetadataRewriter1_13To1_12_2(Protocol1_13To1_12_2 protocol) {
|
||||||
|
super(protocol, EntityTracker1_13.class);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void handleMetadata(int entityId, EntityType type, Metadata metadata, List<Metadata> metadatas, Map<Integer, Metadata> metadataMap, UserConnection connection) throws Exception {
|
protected void handleMetadata(int entityId, EntityType type, Metadata metadata, List<Metadata> metadatas, Map<Integer, Metadata> metadataMap, UserConnection connection) throws Exception {
|
||||||
@ -50,18 +56,18 @@ public class MetadataRewriter1_13To1_12_2 extends MetadataRewriter<Entity1_13Typ
|
|||||||
if (type == null) return;
|
if (type == null) return;
|
||||||
|
|
||||||
// Handle new colors
|
// Handle new colors
|
||||||
if (type.is(EntityType.WOLF) && metadata.getId() == 17) {
|
if (type == Entity1_13Types.EntityType.WOLF && metadata.getId() == 17) {
|
||||||
metadata.setValue(15 - (int) metadata.getValue());
|
metadata.setValue(15 - (int) metadata.getValue());
|
||||||
}
|
}
|
||||||
|
|
||||||
// Handle new zombie meta (INDEX 15 - Boolean - Zombie is shaking while enabled)
|
// Handle new zombie meta (INDEX 15 - Boolean - Zombie is shaking while enabled)
|
||||||
if (type.isOrHasParent(EntityType.ZOMBIE)) {
|
if (type.isOrHasParent(Entity1_13Types.EntityType.ZOMBIE)) {
|
||||||
if (metadata.getId() > 14)
|
if (metadata.getId() > 14)
|
||||||
metadata.setId(metadata.getId() + 1);
|
metadata.setId(metadata.getId() + 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Handle Minecart inner block
|
// Handle Minecart inner block
|
||||||
if (type.isOrHasParent(EntityType.MINECART_ABSTRACT) && metadata.getId() == 9) {
|
if (type.isOrHasParent(Entity1_13Types.EntityType.MINECART_ABSTRACT) && metadata.getId() == 9) {
|
||||||
// New block format
|
// New block format
|
||||||
int oldId = (int) metadata.getValue();
|
int oldId = (int) metadata.getValue();
|
||||||
int combined = (((oldId & 4095) << 4) | (oldId >> 12 & 15));
|
int combined = (((oldId & 4095) << 4) | (oldId >> 12 & 15));
|
||||||
@ -70,7 +76,7 @@ public class MetadataRewriter1_13To1_12_2 extends MetadataRewriter<Entity1_13Typ
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Handle other changes
|
// Handle other changes
|
||||||
if (type.is(EntityType.AREA_EFFECT_CLOUD)) {
|
if (type == Entity1_13Types.EntityType.AREA_EFFECT_CLOUD) {
|
||||||
if (metadata.getId() == 9) {
|
if (metadata.getId() == 9) {
|
||||||
int particleId = (int) metadata.getValue();
|
int particleId = (int) metadata.getValue();
|
||||||
int parameter1 = metadataMap.containsKey(10) ? (int) metadataMap.get(10).getValue() : 0;
|
int parameter1 = metadataMap.containsKey(10) ? (int) metadataMap.get(10).getValue() : 0;
|
||||||
|
@ -17,7 +17,7 @@ import java.util.Optional;
|
|||||||
|
|
||||||
public class EntityPackets {
|
public class EntityPackets {
|
||||||
public static void register(final Protocol protocol) {
|
public static void register(final Protocol protocol) {
|
||||||
// Outgoing packets
|
MetadataRewriter1_13To1_12_2 metadataRewriter = protocol.get(MetadataRewriter1_13To1_12_2.class);
|
||||||
|
|
||||||
// Spawn Object
|
// Spawn Object
|
||||||
protocol.registerOutgoing(State.PLAY, 0x0, 0x0, new PacketRemapper() {
|
protocol.registerOutgoing(State.PLAY, 0x0, 0x0, new PacketRemapper() {
|
||||||
@ -113,7 +113,7 @@ public class EntityPackets {
|
|||||||
// Register Type ID
|
// Register Type ID
|
||||||
wrapper.user().get(EntityTracker1_13.class).addEntity(entityId, entType);
|
wrapper.user().get(EntityTracker1_13.class).addEntity(entityId, entType);
|
||||||
|
|
||||||
protocol.get(MetadataRewriter1_13To1_12_2.class).handleMetadata(entityId, entType, wrapper.get(Types1_13.METADATA_LIST, 0), wrapper.user());
|
metadataRewriter.handleMetadata(entityId, wrapper.get(Types1_13.METADATA_LIST, 0), wrapper.user());
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -140,43 +140,16 @@ public class EntityPackets {
|
|||||||
Entity1_13Types.EntityType entType = Entity1_13Types.EntityType.PLAYER;
|
Entity1_13Types.EntityType entType = Entity1_13Types.EntityType.PLAYER;
|
||||||
// Register Type ID
|
// Register Type ID
|
||||||
wrapper.user().get(EntityTracker1_13.class).addEntity(entityId, entType);
|
wrapper.user().get(EntityTracker1_13.class).addEntity(entityId, entType);
|
||||||
protocol.get(MetadataRewriter1_13To1_12_2.class).handleMetadata(entityId, entType, wrapper.get(Types1_13.METADATA_LIST, 0), wrapper.user());
|
metadataRewriter.handleMetadata(entityId, wrapper.get(Types1_13.METADATA_LIST, 0), wrapper.user());
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
// Destroy entities
|
|
||||||
protocol.registerOutgoing(State.PLAY, 0x32, 0x35, new PacketRemapper() {
|
|
||||||
@Override
|
|
||||||
public void registerMap() {
|
|
||||||
map(Type.VAR_INT_ARRAY); // 0 - Entity IDS
|
|
||||||
|
|
||||||
handler(new PacketHandler() {
|
// Destroy entities
|
||||||
@Override
|
metadataRewriter.registerEntityDestroy(0x32, 0x35);
|
||||||
public void handle(PacketWrapper wrapper) throws Exception {
|
|
||||||
for (int entity : wrapper.get(Type.VAR_INT_ARRAY, 0))
|
|
||||||
wrapper.user().get(EntityTracker1_13.class).removeEntity(entity);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
// Metadata packet
|
// Metadata packet
|
||||||
protocol.registerOutgoing(State.PLAY, 0x3C, 0x3F, new PacketRemapper() {
|
metadataRewriter.registerMetadataRewriter(0x3C, 0x3F, Types1_12.METADATA_LIST, Types1_13.METADATA_LIST);
|
||||||
@Override
|
|
||||||
public void registerMap() {
|
|
||||||
map(Type.VAR_INT); // 0 - Entity ID
|
|
||||||
map(Types1_12.METADATA_LIST, Types1_13.METADATA_LIST); // 1 - Metadata list
|
|
||||||
handler(new PacketHandler() {
|
|
||||||
@Override
|
|
||||||
public void handle(PacketWrapper wrapper) throws Exception {
|
|
||||||
int entityId = wrapper.get(Type.VAR_INT, 0);
|
|
||||||
|
|
||||||
Optional<Entity1_13Types.EntityType> type = wrapper.user().get(EntityTracker1_13.class).getEntity(entityId);
|
|
||||||
protocol.get(MetadataRewriter1_13To1_12_2.class).handleMetadata(entityId, type.orElse(null), wrapper.get(Types1_13.METADATA_LIST, 0), wrapper.user());
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,11 +1,10 @@
|
|||||||
package us.myles.ViaVersion.protocols.protocol1_13to1_12_2.storage;
|
package us.myles.ViaVersion.protocols.protocol1_13to1_12_2.storage;
|
||||||
|
|
||||||
import us.myles.ViaVersion.api.data.UserConnection;
|
import us.myles.ViaVersion.api.data.UserConnection;
|
||||||
import us.myles.ViaVersion.api.entities.Entity1_13Types;
|
|
||||||
import us.myles.ViaVersion.api.entities.Entity1_13Types.EntityType;
|
import us.myles.ViaVersion.api.entities.Entity1_13Types.EntityType;
|
||||||
import us.myles.ViaVersion.api.storage.EntityTracker;
|
import us.myles.ViaVersion.api.storage.EntityTracker;
|
||||||
|
|
||||||
public class EntityTracker1_13 extends EntityTracker<Entity1_13Types.EntityType> {
|
public class EntityTracker1_13 extends EntityTracker {
|
||||||
|
|
||||||
public EntityTracker1_13(UserConnection user) {
|
public EntityTracker1_13(UserConnection user) {
|
||||||
super(user, EntityType.PLAYER);
|
super(user, EntityType.PLAYER);
|
||||||
|
@ -10,7 +10,7 @@ public class Protocol1_14_1To1_14 extends Protocol {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void registerPackets() {
|
protected void registerPackets() {
|
||||||
put(new MetadataRewriter1_14_1To1_14());
|
new MetadataRewriter1_14_1To1_14(this);
|
||||||
|
|
||||||
EntityPackets.register(this);
|
EntityPackets.register(this);
|
||||||
}
|
}
|
||||||
|
@ -2,18 +2,25 @@ package us.myles.ViaVersion.protocols.protocol1_14_1to1_14.metadata;
|
|||||||
|
|
||||||
import us.myles.ViaVersion.api.data.UserConnection;
|
import us.myles.ViaVersion.api.data.UserConnection;
|
||||||
import us.myles.ViaVersion.api.entities.Entity1_14Types;
|
import us.myles.ViaVersion.api.entities.Entity1_14Types;
|
||||||
import us.myles.ViaVersion.api.entities.Entity1_14Types.EntityType;
|
import us.myles.ViaVersion.api.entities.EntityType;
|
||||||
import us.myles.ViaVersion.api.minecraft.metadata.Metadata;
|
import us.myles.ViaVersion.api.minecraft.metadata.Metadata;
|
||||||
import us.myles.ViaVersion.api.rewriters.MetadataRewriter;
|
import us.myles.ViaVersion.api.rewriters.MetadataRewriter;
|
||||||
|
import us.myles.ViaVersion.protocols.protocol1_14_1to1_14.Protocol1_14_1To1_14;
|
||||||
|
import us.myles.ViaVersion.protocols.protocol1_14_1to1_14.storage.EntityTracker1_14_1;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class MetadataRewriter1_14_1To1_14 extends MetadataRewriter<Entity1_14Types.EntityType> {
|
public class MetadataRewriter1_14_1To1_14 extends MetadataRewriter<Protocol1_14_1To1_14> {
|
||||||
|
|
||||||
|
public MetadataRewriter1_14_1To1_14(Protocol1_14_1To1_14 protocol) {
|
||||||
|
super(protocol, EntityTracker1_14_1.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public void handleMetadata(int entityId, EntityType type, Metadata metadata, List<Metadata> metadatas, UserConnection connection) {
|
public void handleMetadata(int entityId, EntityType type, Metadata metadata, List<Metadata> metadatas, UserConnection connection) {
|
||||||
if (type == null) return;
|
if (type == null) return;
|
||||||
|
|
||||||
if (type.is(EntityType.VILLAGER) || type.is(EntityType.WANDERING_TRADER)) {
|
if (type == Entity1_14Types.EntityType.VILLAGER || type == Entity1_14Types.EntityType.WANDERING_TRADER) {
|
||||||
if (metadata.getId() >= 15) {
|
if (metadata.getId() >= 15) {
|
||||||
metadata.setId(metadata.getId() + 1);
|
metadata.setId(metadata.getId() + 1);
|
||||||
}
|
}
|
||||||
|
@ -11,11 +11,10 @@ import us.myles.ViaVersion.packets.State;
|
|||||||
import us.myles.ViaVersion.protocols.protocol1_14_1to1_14.metadata.MetadataRewriter1_14_1To1_14;
|
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;
|
import us.myles.ViaVersion.protocols.protocol1_14_1to1_14.storage.EntityTracker1_14_1;
|
||||||
|
|
||||||
import java.util.Optional;
|
|
||||||
|
|
||||||
public class EntityPackets {
|
public class EntityPackets {
|
||||||
|
|
||||||
public static void register(final Protocol protocol) {
|
public static void register(final Protocol protocol) {
|
||||||
|
MetadataRewriter1_14_1To1_14 metadataRewriter = protocol.get(MetadataRewriter1_14_1To1_14.class);
|
||||||
|
|
||||||
// Spawn Mob
|
// Spawn Mob
|
||||||
protocol.registerOutgoing(State.PLAY, 0x03, 0x03, new PacketRemapper() {
|
protocol.registerOutgoing(State.PLAY, 0x03, 0x03, new PacketRemapper() {
|
||||||
@ -46,7 +45,7 @@ public class EntityPackets {
|
|||||||
// Register Type ID
|
// Register Type ID
|
||||||
wrapper.user().get(EntityTracker1_14_1.class).addEntity(entityId, entType);
|
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());
|
metadataRewriter.handleMetadata(entityId, wrapper.get(Types1_14.METADATA_LIST, 0), wrapper.user());
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -74,29 +73,13 @@ public class EntityPackets {
|
|||||||
|
|
||||||
// Register Type ID
|
// Register Type ID
|
||||||
wrapper.user().get(EntityTracker1_14_1.class).addEntity(entityId, entType);
|
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());
|
metadataRewriter.handleMetadata(entityId, wrapper.get(Types1_14.METADATA_LIST, 0), wrapper.user());
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// Entity Metadata
|
// Entity Metadata
|
||||||
protocol.registerOutgoing(State.PLAY, 0x43, 0x43, new PacketRemapper() {
|
metadataRewriter.registerMetadataRewriter(0x43, 0x43, Types1_14.METADATA_LIST);
|
||||||
@Override
|
|
||||||
public void registerMap() {
|
|
||||||
map(Type.VAR_INT); // 0 - Entity ID
|
|
||||||
map(Types1_14.METADATA_LIST); // 1 - Metadata list
|
|
||||||
|
|
||||||
handler(new PacketHandler() {
|
|
||||||
@Override
|
|
||||||
public void handle(PacketWrapper wrapper) throws Exception {
|
|
||||||
int entityId = wrapper.get(Type.VAR_INT, 0);
|
|
||||||
|
|
||||||
Optional<Entity1_14Types.EntityType> type = wrapper.user().get(EntityTracker1_14_1.class).getEntity(entityId);
|
|
||||||
protocol.get(MetadataRewriter1_14_1To1_14.class).handleMetadata(entityId, type.orElse(null), wrapper.get(Types1_14.METADATA_LIST, 0), wrapper.user());
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,11 +1,10 @@
|
|||||||
package us.myles.ViaVersion.protocols.protocol1_14_1to1_14.storage;
|
package us.myles.ViaVersion.protocols.protocol1_14_1to1_14.storage;
|
||||||
|
|
||||||
import us.myles.ViaVersion.api.data.UserConnection;
|
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.entities.Entity1_14Types.EntityType;
|
||||||
import us.myles.ViaVersion.api.storage.EntityTracker;
|
import us.myles.ViaVersion.api.storage.EntityTracker;
|
||||||
|
|
||||||
public class EntityTracker1_14_1 extends EntityTracker<Entity1_14Types.EntityType> {
|
public class EntityTracker1_14_1 extends EntityTracker {
|
||||||
|
|
||||||
public EntityTracker1_14_1(UserConnection user) {
|
public EntityTracker1_14_1(UserConnection user) {
|
||||||
super(user, EntityType.PLAYER);
|
super(user, EntityType.PLAYER);
|
||||||
|
@ -25,7 +25,7 @@ public class Protocol1_14To1_13_2 extends Protocol {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void registerPackets() {
|
protected void registerPackets() {
|
||||||
put(new MetadataRewriter1_14To1_13_2());
|
new MetadataRewriter1_14To1_13_2(this);
|
||||||
|
|
||||||
InventoryPackets.register(this);
|
InventoryPackets.register(this);
|
||||||
EntityPackets.register(this);
|
EntityPackets.register(this);
|
||||||
|
@ -3,7 +3,7 @@ package us.myles.ViaVersion.protocols.protocol1_14to1_13_2.metadata;
|
|||||||
import us.myles.ViaVersion.api.PacketWrapper;
|
import us.myles.ViaVersion.api.PacketWrapper;
|
||||||
import us.myles.ViaVersion.api.data.UserConnection;
|
import us.myles.ViaVersion.api.data.UserConnection;
|
||||||
import us.myles.ViaVersion.api.entities.Entity1_14Types;
|
import us.myles.ViaVersion.api.entities.Entity1_14Types;
|
||||||
import us.myles.ViaVersion.api.entities.Entity1_14Types.EntityType;
|
import us.myles.ViaVersion.api.entities.EntityType;
|
||||||
import us.myles.ViaVersion.api.minecraft.VillagerData;
|
import us.myles.ViaVersion.api.minecraft.VillagerData;
|
||||||
import us.myles.ViaVersion.api.minecraft.item.Item;
|
import us.myles.ViaVersion.api.minecraft.item.Item;
|
||||||
import us.myles.ViaVersion.api.minecraft.metadata.Metadata;
|
import us.myles.ViaVersion.api.minecraft.metadata.Metadata;
|
||||||
@ -17,7 +17,11 @@ import us.myles.ViaVersion.protocols.protocol1_14to1_13_2.storage.EntityTracker1
|
|||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class MetadataRewriter1_14To1_13_2 extends MetadataRewriter<Entity1_14Types.EntityType> {
|
public class MetadataRewriter1_14To1_13_2 extends MetadataRewriter<Protocol1_14To1_13_2> {
|
||||||
|
|
||||||
|
public MetadataRewriter1_14To1_13_2(Protocol1_14To1_13_2 protocol) {
|
||||||
|
super(protocol, EntityTracker1_14.class);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void handleMetadata(int entityId, EntityType type, Metadata metadata, List<Metadata> metadatas, UserConnection connection) throws Exception {
|
protected void handleMetadata(int entityId, EntityType type, Metadata metadata, List<Metadata> metadatas, UserConnection connection) throws Exception {
|
||||||
@ -41,11 +45,11 @@ public class MetadataRewriter1_14To1_13_2 extends MetadataRewriter<Entity1_14Typ
|
|||||||
}
|
}
|
||||||
|
|
||||||
//Metadata 12 added to living_entity
|
//Metadata 12 added to living_entity
|
||||||
if (metadata.getId() > 11 && type.isOrHasParent(EntityType.LIVINGENTITY)) {
|
if (metadata.getId() > 11 && type.isOrHasParent(Entity1_14Types.EntityType.LIVINGENTITY)) {
|
||||||
metadata.setId(metadata.getId() + 1);
|
metadata.setId(metadata.getId() + 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (type.isOrHasParent(EntityType.ABSTRACT_INSENTIENT)) {
|
if (type.isOrHasParent(Entity1_14Types.EntityType.ABSTRACT_INSENTIENT)) {
|
||||||
if (metadata.getId() == 13) {
|
if (metadata.getId() == 13) {
|
||||||
tracker.setInsentientData(entityId, (byte) ((((Number) metadata.getValue()).byteValue() & ~0x4)
|
tracker.setInsentientData(entityId, (byte) ((((Number) metadata.getValue()).byteValue() & ~0x4)
|
||||||
| (tracker.getInsentientData(entityId) & 0x4))); // New attacking metadata
|
| (tracker.getInsentientData(entityId) & 0x4))); // New attacking metadata
|
||||||
@ -53,7 +57,7 @@ public class MetadataRewriter1_14To1_13_2 extends MetadataRewriter<Entity1_14Typ
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (type.isOrHasParent(EntityType.PLAYER)) {
|
if (type.isOrHasParent(Entity1_14Types.EntityType.PLAYER)) {
|
||||||
if (entityId != tracker.getClientEntityId()) {
|
if (entityId != tracker.getClientEntityId()) {
|
||||||
if (metadata.getId() == 0) {
|
if (metadata.getId() == 0) {
|
||||||
byte flags = ((Number) metadata.getValue()).byteValue();
|
byte flags = ((Number) metadata.getValue()).byteValue();
|
||||||
@ -66,7 +70,7 @@ public class MetadataRewriter1_14To1_13_2 extends MetadataRewriter<Entity1_14Typ
|
|||||||
metadatas.add(new Metadata(6, MetaType1_14.Pose, recalculatePlayerPose(entityId, tracker)));
|
metadatas.add(new Metadata(6, MetaType1_14.Pose, recalculatePlayerPose(entityId, tracker)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (type.isOrHasParent(EntityType.ZOMBIE)) {
|
} else if (type.isOrHasParent(Entity1_14Types.EntityType.ZOMBIE)) {
|
||||||
if (metadata.getId() == 16) {
|
if (metadata.getId() == 16) {
|
||||||
tracker.setInsentientData(entityId, (byte) ((tracker.getInsentientData(entityId) & ~0x4)
|
tracker.setInsentientData(entityId, (byte) ((tracker.getInsentientData(entityId) & ~0x4)
|
||||||
| ((boolean) metadata.getValue() ? 0x4 : 0))); // New attacking
|
| ((boolean) metadata.getValue() ? 0x4 : 0))); // New attacking
|
||||||
@ -77,13 +81,13 @@ public class MetadataRewriter1_14To1_13_2 extends MetadataRewriter<Entity1_14Typ
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (type.isOrHasParent(EntityType.MINECART_ABSTRACT)) {
|
if (type.isOrHasParent(Entity1_14Types.EntityType.MINECART_ABSTRACT)) {
|
||||||
if (metadata.getId() == 10) {
|
if (metadata.getId() == 10) {
|
||||||
// New block format
|
// New block format
|
||||||
int data = (int) metadata.getValue();
|
int data = (int) metadata.getValue();
|
||||||
metadata.setValue(Protocol1_14To1_13_2.getNewBlockStateId(data));
|
metadata.setValue(Protocol1_14To1_13_2.getNewBlockStateId(data));
|
||||||
}
|
}
|
||||||
} else if (type.is(EntityType.HORSE)) {
|
} else if (type.is(Entity1_14Types.EntityType.HORSE)) {
|
||||||
if (metadata.getId() == 18) {
|
if (metadata.getId() == 18) {
|
||||||
metadatas.remove(metadata);
|
metadatas.remove(metadata);
|
||||||
|
|
||||||
@ -103,43 +107,43 @@ public class MetadataRewriter1_14To1_13_2 extends MetadataRewriter<Entity1_14Typ
|
|||||||
equipmentPacket.write(Type.FLAT_VAR_INT_ITEM, armorItem);
|
equipmentPacket.write(Type.FLAT_VAR_INT_ITEM, armorItem);
|
||||||
equipmentPacket.send(Protocol1_14To1_13_2.class);
|
equipmentPacket.send(Protocol1_14To1_13_2.class);
|
||||||
}
|
}
|
||||||
} else if (type.is(EntityType.VILLAGER)) {
|
} else if (type.is(Entity1_14Types.EntityType.VILLAGER)) {
|
||||||
if (metadata.getId() == 15) {
|
if (metadata.getId() == 15) {
|
||||||
// plains
|
// plains
|
||||||
metadata.setValue(new VillagerData(2, getNewProfessionId((int) metadata.getValue()), 0));
|
metadata.setValue(new VillagerData(2, getNewProfessionId((int) metadata.getValue()), 0));
|
||||||
metadata.setMetaType(MetaType1_14.VillagerData);
|
metadata.setMetaType(MetaType1_14.VillagerData);
|
||||||
}
|
}
|
||||||
} else if (type.is(EntityType.ZOMBIE_VILLAGER)) {
|
} else if (type.is(Entity1_14Types.EntityType.ZOMBIE_VILLAGER)) {
|
||||||
if (metadata.getId() == 18) {
|
if (metadata.getId() == 18) {
|
||||||
// plains
|
// plains
|
||||||
metadata.setValue(new VillagerData(2, getNewProfessionId((int) metadata.getValue()), 0));
|
metadata.setValue(new VillagerData(2, getNewProfessionId((int) metadata.getValue()), 0));
|
||||||
metadata.setMetaType(MetaType1_14.VillagerData);
|
metadata.setMetaType(MetaType1_14.VillagerData);
|
||||||
}
|
}
|
||||||
} else if (type.isOrHasParent(EntityType.ABSTRACT_ARROW)) {
|
} else if (type.isOrHasParent(Entity1_14Types.EntityType.ABSTRACT_ARROW)) {
|
||||||
if (metadata.getId() >= 9) { // New piercing
|
if (metadata.getId() >= 9) { // New piercing
|
||||||
metadata.setId(metadata.getId() + 1);
|
metadata.setId(metadata.getId() + 1);
|
||||||
}
|
}
|
||||||
} else if (type.is(EntityType.FIREWORKS_ROCKET)) {
|
} else if (type.is(Entity1_14Types.EntityType.FIREWORKS_ROCKET)) {
|
||||||
if (metadata.getId() == 8) {
|
if (metadata.getId() == 8) {
|
||||||
if (metadata.getValue().equals(0))
|
if (metadata.getValue().equals(0))
|
||||||
metadata.setValue(null); // https://bugs.mojang.com/browse/MC-111480
|
metadata.setValue(null); // https://bugs.mojang.com/browse/MC-111480
|
||||||
metadata.setMetaType(MetaType1_14.OptVarInt);
|
metadata.setMetaType(MetaType1_14.OptVarInt);
|
||||||
}
|
}
|
||||||
} else if (type.isOrHasParent(EntityType.ABSTRACT_SKELETON)) {
|
} else if (type.isOrHasParent(Entity1_14Types.EntityType.ABSTRACT_SKELETON)) {
|
||||||
if (metadata.getId() == 14) {
|
if (metadata.getId() == 14) {
|
||||||
tracker.setInsentientData(entityId, (byte) ((tracker.getInsentientData(entityId) & ~0x4)
|
tracker.setInsentientData(entityId, (byte) ((tracker.getInsentientData(entityId) & ~0x4)
|
||||||
| ((boolean) metadata.getValue() ? 0x4 : 0))); // New attacking
|
| ((boolean) metadata.getValue() ? 0x4 : 0))); // New attacking
|
||||||
metadatas.remove(metadata); // "Is swinging arms"
|
metadatas.remove(metadata); // "Is swinging arms"
|
||||||
metadatas.add(new Metadata(13, MetaType1_14.Byte, tracker.getInsentientData(entityId)));
|
metadatas.add(new Metadata(13, MetaType1_14.Byte, tracker.getInsentientData(entityId)));
|
||||||
}
|
}
|
||||||
} else if (type.is(EntityType.AREA_EFFECT_CLOUD)) {
|
} else if (type.is(Entity1_14Types.EntityType.AREA_EFFECT_CLOUD)) {
|
||||||
if (metadata.getId() == 10) {
|
if (metadata.getId() == 10) {
|
||||||
Particle particle = (Particle) metadata.getValue();
|
Particle particle = (Particle) metadata.getValue();
|
||||||
particle.setId(getNewParticleId(particle.getId()));
|
particle.setId(getNewParticleId(particle.getId()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (type.isOrHasParent(EntityType.ABSTRACT_ILLAGER_BASE)) {
|
if (type.isOrHasParent(Entity1_14Types.EntityType.ABSTRACT_ILLAGER_BASE)) {
|
||||||
if (metadata.getId() == 14) {
|
if (metadata.getId() == 14) {
|
||||||
tracker.setInsentientData(entityId, (byte) ((tracker.getInsentientData(entityId) & ~0x4)
|
tracker.setInsentientData(entityId, (byte) ((tracker.getInsentientData(entityId) & ~0x4)
|
||||||
| (((Number) metadata.getValue()).byteValue() != 0 ? 0x4 : 0))); // New attacking
|
| (((Number) metadata.getValue()).byteValue() != 0 ? 0x4 : 0))); // New attacking
|
||||||
@ -149,7 +153,7 @@ public class MetadataRewriter1_14To1_13_2 extends MetadataRewriter<Entity1_14Typ
|
|||||||
}
|
}
|
||||||
|
|
||||||
// TODO Are witch and ravager also abstract illagers? They all inherit the new metadata 14 added in 19w13a
|
// TODO Are witch and ravager also abstract illagers? They all inherit the new metadata 14 added in 19w13a
|
||||||
if (type.is(EntityType.WITCH) || type.is(EntityType.RAVAGER) || type.isOrHasParent(EntityType.ABSTRACT_ILLAGER_BASE)) {
|
if (type.is(Entity1_14Types.EntityType.WITCH) || type.is(Entity1_14Types.EntityType.RAVAGER) || type.isOrHasParent(Entity1_14Types.EntityType.ABSTRACT_ILLAGER_BASE)) {
|
||||||
if (metadata.getId() >= 14) { // TODO 19w13 added a new boolean (raid participant - is celebrating) with id 14
|
if (metadata.getId() >= 14) { // TODO 19w13 added a new boolean (raid participant - is celebrating) with id 14
|
||||||
metadata.setId(metadata.getId() + 1);
|
metadata.setId(metadata.getId() + 1);
|
||||||
}
|
}
|
||||||
|
@ -20,11 +20,11 @@ import us.myles.ViaVersion.protocols.protocol1_14to1_13_2.storage.EntityTracker1
|
|||||||
|
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Optional;
|
|
||||||
|
|
||||||
public class EntityPackets {
|
public class EntityPackets {
|
||||||
|
|
||||||
public static void register(final Protocol protocol) {
|
public static void register(final Protocol protocol) {
|
||||||
|
MetadataRewriter1_14To1_13_2 metadataRewriter = protocol.get(MetadataRewriter1_14To1_13_2.class);
|
||||||
|
|
||||||
// Spawn entity
|
// Spawn entity
|
||||||
protocol.registerOutgoing(State.PLAY, 0x00, 0x00, new PacketRemapper() {
|
protocol.registerOutgoing(State.PLAY, 0x00, 0x00, new PacketRemapper() {
|
||||||
@ -135,7 +135,7 @@ public class EntityPackets {
|
|||||||
// Register Type ID
|
// Register Type ID
|
||||||
wrapper.user().get(EntityTracker1_14.class).addEntity(entityId, entType);
|
wrapper.user().get(EntityTracker1_14.class).addEntity(entityId, entType);
|
||||||
|
|
||||||
protocol.get(MetadataRewriter1_14To1_13_2.class).handleMetadata(entityId, entType, wrapper.get(Types1_14.METADATA_LIST, 0), wrapper.user());
|
metadataRewriter.handleMetadata(entityId, wrapper.get(Types1_14.METADATA_LIST, 0), wrapper.user());
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -174,7 +174,7 @@ public class EntityPackets {
|
|||||||
Entity1_14Types.EntityType entType = Entity1_14Types.EntityType.PLAYER;
|
Entity1_14Types.EntityType entType = Entity1_14Types.EntityType.PLAYER;
|
||||||
// Register Type ID
|
// Register Type ID
|
||||||
wrapper.user().get(EntityTracker1_14.class).addEntity(entityId, entType);
|
wrapper.user().get(EntityTracker1_14.class).addEntity(entityId, entType);
|
||||||
protocol.get(MetadataRewriter1_14To1_13_2.class).handleMetadata(entityId, entType, wrapper.get(Types1_14.METADATA_LIST, 0), wrapper.user());
|
metadataRewriter.handleMetadata(entityId, wrapper.get(Types1_14.METADATA_LIST, 0), wrapper.user());
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -234,37 +234,9 @@ public class EntityPackets {
|
|||||||
});
|
});
|
||||||
|
|
||||||
// Destroy entities
|
// Destroy entities
|
||||||
protocol.registerOutgoing(State.PLAY, 0x35, 0x37, new PacketRemapper() {
|
metadataRewriter.registerEntityDestroy(0x35, 0x37);
|
||||||
@Override
|
|
||||||
public void registerMap() {
|
|
||||||
map(Type.VAR_INT_ARRAY); // 0 - Entity IDS
|
|
||||||
|
|
||||||
handler(new PacketHandler() {
|
|
||||||
@Override
|
|
||||||
public void handle(PacketWrapper wrapper) throws Exception {
|
|
||||||
for (int entity : wrapper.get(Type.VAR_INT_ARRAY, 0))
|
|
||||||
wrapper.user().get(EntityTracker1_14.class).removeEntity(entity);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
// Metadata packet
|
// Metadata packet
|
||||||
protocol.registerOutgoing(State.PLAY, 0x3F, 0x43, new PacketRemapper() {
|
metadataRewriter.registerMetadataRewriter(0x3F, 0x43, Types1_13_2.METADATA_LIST, Types1_14.METADATA_LIST);
|
||||||
@Override
|
|
||||||
public void registerMap() {
|
|
||||||
map(Type.VAR_INT); // 0 - Entity ID
|
|
||||||
map(Types1_13_2.METADATA_LIST, Types1_14.METADATA_LIST); // 1 - Metadata list
|
|
||||||
handler(new PacketHandler() {
|
|
||||||
@Override
|
|
||||||
public void handle(PacketWrapper wrapper) throws Exception {
|
|
||||||
int entityId = wrapper.get(Type.VAR_INT, 0);
|
|
||||||
|
|
||||||
Optional<Entity1_14Types.EntityType> type = wrapper.user().get(EntityTracker1_14.class).getEntity(entityId);
|
|
||||||
protocol.get(MetadataRewriter1_14To1_13_2.class).handleMetadata(entityId, type.orElse(null), wrapper.get(Types1_14.METADATA_LIST, 0), wrapper.user());
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -4,7 +4,6 @@ import lombok.Getter;
|
|||||||
import lombok.Setter;
|
import lombok.Setter;
|
||||||
import us.myles.ViaVersion.api.PacketWrapper;
|
import us.myles.ViaVersion.api.PacketWrapper;
|
||||||
import us.myles.ViaVersion.api.data.UserConnection;
|
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.entities.Entity1_14Types.EntityType;
|
||||||
import us.myles.ViaVersion.api.storage.EntityTracker;
|
import us.myles.ViaVersion.api.storage.EntityTracker;
|
||||||
import us.myles.ViaVersion.api.type.Type;
|
import us.myles.ViaVersion.api.type.Type;
|
||||||
@ -14,7 +13,7 @@ import us.myles.ViaVersion.protocols.protocol1_14to1_13_2.packets.WorldPackets;
|
|||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
|
||||||
public class EntityTracker1_14 extends EntityTracker<Entity1_14Types.EntityType> {
|
public class EntityTracker1_14 extends EntityTracker {
|
||||||
private final Map<Integer, Byte> insentientData = new ConcurrentHashMap<>();
|
private final Map<Integer, Byte> insentientData = new ConcurrentHashMap<>();
|
||||||
// 0x1 = sleeping, 0x2 = riptide
|
// 0x1 = sleeping, 0x2 = riptide
|
||||||
private final Map<Integer, Byte> sleepingAndRiptideData = new ConcurrentHashMap<>();
|
private final Map<Integer, Byte> sleepingAndRiptideData = new ConcurrentHashMap<>();
|
||||||
|
@ -1,45 +0,0 @@
|
|||||||
package us.myles.ViaVersion.protocols.protocol1_15to1_14_4;
|
|
||||||
|
|
||||||
import us.myles.ViaVersion.api.Via;
|
|
||||||
import us.myles.ViaVersion.api.data.UserConnection;
|
|
||||||
import us.myles.ViaVersion.api.entities.Entity1_15Types;
|
|
||||||
import us.myles.ViaVersion.api.minecraft.item.Item;
|
|
||||||
import us.myles.ViaVersion.api.minecraft.metadata.Metadata;
|
|
||||||
import us.myles.ViaVersion.api.minecraft.metadata.types.MetaType1_14;
|
|
||||||
import us.myles.ViaVersion.protocols.protocol1_15to1_14_4.packets.InventoryPackets;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
public class MetadataRewriter {
|
|
||||||
|
|
||||||
public static void handleMetadata(int entityId, Entity1_15Types.EntityType type, List<Metadata> metadatas, UserConnection connection) {
|
|
||||||
for (Metadata metadata : new ArrayList<>(metadatas)) {
|
|
||||||
try {
|
|
||||||
if (metadata.getMetaType() == MetaType1_14.Slot) {
|
|
||||||
InventoryPackets.toClient((Item) metadata.getValue());
|
|
||||||
} else if (metadata.getMetaType() == MetaType1_14.BlockID) {
|
|
||||||
// Convert to new block id
|
|
||||||
int data = (int) metadata.getValue();
|
|
||||||
metadata.setValue(Protocol1_15To1_14_4.getNewBlockStateId(data));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (type == null) continue;
|
|
||||||
|
|
||||||
// Metadata 12 added to abstract_living
|
|
||||||
if (metadata.getId() > 11 && type.isOrHasParent(Entity1_15Types.EntityType.LIVINGENTITY)) {
|
|
||||||
metadata.setId(metadata.getId() + 1); //TODO is it 11 or 12? what is it for?
|
|
||||||
}
|
|
||||||
|
|
||||||
//TODO new boolean with id 17 for enderman?
|
|
||||||
} 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();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -9,6 +9,7 @@ import us.myles.ViaVersion.api.remapper.PacketRemapper;
|
|||||||
import us.myles.ViaVersion.api.type.Type;
|
import us.myles.ViaVersion.api.type.Type;
|
||||||
import us.myles.ViaVersion.packets.State;
|
import us.myles.ViaVersion.packets.State;
|
||||||
import us.myles.ViaVersion.protocols.protocol1_15to1_14_4.data.MappingData;
|
import us.myles.ViaVersion.protocols.protocol1_15to1_14_4.data.MappingData;
|
||||||
|
import us.myles.ViaVersion.protocols.protocol1_15to1_14_4.metadata.MetadataRewriter1_15To1_14_4;
|
||||||
import us.myles.ViaVersion.protocols.protocol1_15to1_14_4.packets.EntityPackets;
|
import us.myles.ViaVersion.protocols.protocol1_15to1_14_4.packets.EntityPackets;
|
||||||
import us.myles.ViaVersion.protocols.protocol1_15to1_14_4.packets.InventoryPackets;
|
import us.myles.ViaVersion.protocols.protocol1_15to1_14_4.packets.InventoryPackets;
|
||||||
import us.myles.ViaVersion.protocols.protocol1_15to1_14_4.packets.PlayerPackets;
|
import us.myles.ViaVersion.protocols.protocol1_15to1_14_4.packets.PlayerPackets;
|
||||||
@ -20,7 +21,8 @@ public class Protocol1_15To1_14_4 extends Protocol {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void registerPackets() {
|
protected void registerPackets() {
|
||||||
MappingData.init();
|
new MetadataRewriter1_15To1_14_4(this);
|
||||||
|
|
||||||
EntityPackets.register(this);
|
EntityPackets.register(this);
|
||||||
PlayerPackets.register(this);
|
PlayerPackets.register(this);
|
||||||
WorldPackets.register(this);
|
WorldPackets.register(this);
|
||||||
|
@ -0,0 +1,41 @@
|
|||||||
|
package us.myles.ViaVersion.protocols.protocol1_15to1_14_4.metadata;
|
||||||
|
|
||||||
|
import us.myles.ViaVersion.api.data.UserConnection;
|
||||||
|
import us.myles.ViaVersion.api.entities.Entity1_15Types;
|
||||||
|
import us.myles.ViaVersion.api.entities.EntityType;
|
||||||
|
import us.myles.ViaVersion.api.minecraft.item.Item;
|
||||||
|
import us.myles.ViaVersion.api.minecraft.metadata.Metadata;
|
||||||
|
import us.myles.ViaVersion.api.minecraft.metadata.types.MetaType1_14;
|
||||||
|
import us.myles.ViaVersion.api.rewriters.MetadataRewriter;
|
||||||
|
import us.myles.ViaVersion.protocols.protocol1_15to1_14_4.Protocol1_15To1_14_4;
|
||||||
|
import us.myles.ViaVersion.protocols.protocol1_15to1_14_4.packets.InventoryPackets;
|
||||||
|
import us.myles.ViaVersion.protocols.protocol1_15to1_14_4.storage.EntityTracker1_15;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class MetadataRewriter1_15To1_14_4 extends MetadataRewriter<Protocol1_15To1_14_4> {
|
||||||
|
|
||||||
|
public MetadataRewriter1_15To1_14_4(Protocol1_15To1_14_4 protocol) {
|
||||||
|
super(protocol, EntityTracker1_15.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void handleMetadata(int entityId, EntityType type, Metadata metadata, List<Metadata> metadatas, UserConnection connection) throws Exception {
|
||||||
|
if (metadata.getMetaType() == MetaType1_14.Slot) {
|
||||||
|
InventoryPackets.toClient((Item) metadata.getValue());
|
||||||
|
} else if (metadata.getMetaType() == MetaType1_14.BlockID) {
|
||||||
|
// Convert to new block id
|
||||||
|
int data = (int) metadata.getValue();
|
||||||
|
metadata.setValue(Protocol1_15To1_14_4.getNewBlockStateId(data));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (type == null) return;
|
||||||
|
|
||||||
|
// Metadata 12 added to abstract_living
|
||||||
|
if (metadata.getId() > 11 && type.isOrHasParent(Entity1_15Types.EntityType.LIVINGENTITY)) {
|
||||||
|
metadata.setId(metadata.getId() + 1); //TODO is it 11 or 12? what is it for?
|
||||||
|
}
|
||||||
|
|
||||||
|
//TODO new boolean with id 17 for enderman
|
||||||
|
}
|
||||||
|
}
|
@ -8,16 +8,17 @@ import us.myles.ViaVersion.api.remapper.PacketRemapper;
|
|||||||
import us.myles.ViaVersion.api.type.Type;
|
import us.myles.ViaVersion.api.type.Type;
|
||||||
import us.myles.ViaVersion.api.type.types.version.Types1_14;
|
import us.myles.ViaVersion.api.type.types.version.Types1_14;
|
||||||
import us.myles.ViaVersion.packets.State;
|
import us.myles.ViaVersion.packets.State;
|
||||||
import us.myles.ViaVersion.protocols.protocol1_15to1_14_4.MetadataRewriter;
|
|
||||||
import us.myles.ViaVersion.protocols.protocol1_15to1_14_4.Protocol1_15To1_14_4;
|
import us.myles.ViaVersion.protocols.protocol1_15to1_14_4.Protocol1_15To1_14_4;
|
||||||
|
import us.myles.ViaVersion.protocols.protocol1_15to1_14_4.metadata.MetadataRewriter1_15To1_14_4;
|
||||||
import us.myles.ViaVersion.protocols.protocol1_15to1_14_4.storage.EntityTracker1_15;
|
import us.myles.ViaVersion.protocols.protocol1_15to1_14_4.storage.EntityTracker1_15;
|
||||||
|
|
||||||
import java.util.Optional;
|
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
public class EntityPackets {
|
public class EntityPackets {
|
||||||
|
|
||||||
public static void register(Protocol protocol) {
|
public static void register(Protocol protocol) {
|
||||||
|
MetadataRewriter1_15To1_14_4 metadataRewriter = protocol.get(MetadataRewriter1_15To1_14_4.class);
|
||||||
|
|
||||||
// Spawn entity
|
// Spawn entity
|
||||||
protocol.registerOutgoing(State.PLAY, 0x00, 0x00, new PacketRemapper() {
|
protocol.registerOutgoing(State.PLAY, 0x00, 0x00, new PacketRemapper() {
|
||||||
@Override
|
@Override
|
||||||
@ -113,21 +114,7 @@ public class EntityPackets {
|
|||||||
});
|
});
|
||||||
|
|
||||||
// Metadata packet
|
// Metadata packet
|
||||||
protocol.registerOutgoing(State.PLAY, 0x43, 0x44, new PacketRemapper() {
|
metadataRewriter.registerMetadataRewriter(0x43, 0x44, Types1_14.METADATA_LIST);
|
||||||
@Override
|
|
||||||
public void registerMap() {
|
|
||||||
map(Type.VAR_INT); // 0 - Entity ID
|
|
||||||
map(Types1_14.METADATA_LIST); // 1 - Metadata list
|
|
||||||
handler(new PacketHandler() {
|
|
||||||
@Override
|
|
||||||
public void handle(PacketWrapper wrapper) throws Exception {
|
|
||||||
int entityId = wrapper.get(Type.VAR_INT, 0);
|
|
||||||
Optional<Entity1_15Types.EntityType> type = wrapper.user().get(EntityTracker1_15.class).getEntity(entityId);
|
|
||||||
MetadataRewriter.handleMetadata(entityId, type.orElse(null), wrapper.get(Types1_14.METADATA_LIST, 0), wrapper.user());
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int getNewEntityId(int oldId) {
|
public static int getNewEntityId(int oldId) {
|
||||||
|
@ -1,12 +1,12 @@
|
|||||||
package us.myles.ViaVersion.protocols.protocol1_15to1_14_4.storage;
|
package us.myles.ViaVersion.protocols.protocol1_15to1_14_4.storage;
|
||||||
|
|
||||||
import us.myles.ViaVersion.api.data.UserConnection;
|
import us.myles.ViaVersion.api.data.UserConnection;
|
||||||
import us.myles.ViaVersion.api.entities.Entity1_15Types;
|
import us.myles.ViaVersion.api.entities.Entity1_15Types.EntityType;
|
||||||
import us.myles.ViaVersion.api.storage.EntityTracker;
|
import us.myles.ViaVersion.api.storage.EntityTracker;
|
||||||
|
|
||||||
public class EntityTracker1_15 extends EntityTracker<Entity1_15Types.EntityType> {
|
public class EntityTracker1_15 extends EntityTracker {
|
||||||
|
|
||||||
public EntityTracker1_15(UserConnection user) {
|
public EntityTracker1_15(UserConnection user) {
|
||||||
super(user, Entity1_15Types.EntityType.PLAYER);
|
super(user, EntityType.PLAYER);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -73,7 +73,7 @@ public class Protocol1_9To1_8 extends Protocol {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void registerPackets() {
|
protected void registerPackets() {
|
||||||
put(new MetadataRewriter1_9To1_8());
|
new MetadataRewriter1_9To1_8(this);
|
||||||
|
|
||||||
// Disconnect workaround (JSON!)
|
// Disconnect workaround (JSON!)
|
||||||
registerOutgoing(State.LOGIN, 0x00, 0x00, new PacketRemapper() {
|
registerOutgoing(State.LOGIN, 0x00, 0x00, new PacketRemapper() {
|
||||||
|
@ -3,6 +3,7 @@ package us.myles.ViaVersion.protocols.protocol1_9to1_8.metadata;
|
|||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import us.myles.ViaVersion.api.Pair;
|
import us.myles.ViaVersion.api.Pair;
|
||||||
import us.myles.ViaVersion.api.entities.Entity1_10Types;
|
import us.myles.ViaVersion.api.entities.Entity1_10Types;
|
||||||
|
import us.myles.ViaVersion.api.entities.EntityType;
|
||||||
import us.myles.ViaVersion.api.minecraft.metadata.types.MetaType1_8;
|
import us.myles.ViaVersion.api.minecraft.metadata.types.MetaType1_8;
|
||||||
import us.myles.ViaVersion.api.minecraft.metadata.types.MetaType1_9;
|
import us.myles.ViaVersion.api.minecraft.metadata.types.MetaType1_9;
|
||||||
|
|
||||||
@ -146,14 +147,14 @@ public enum MetaIndex {
|
|||||||
|
|
||||||
static {
|
static {
|
||||||
for (MetaIndex index : MetaIndex.values())
|
for (MetaIndex index : MetaIndex.values())
|
||||||
metadataRewrites.put(new Pair<>(index.getClazz(), index.getIndex()), index);
|
metadataRewrites.put(new Pair<>(index.clazz, index.index), index);
|
||||||
}
|
}
|
||||||
|
|
||||||
private Entity1_10Types.EntityType clazz;
|
private final Entity1_10Types.EntityType clazz;
|
||||||
private int newIndex;
|
private final int newIndex;
|
||||||
private MetaType1_9 newType;
|
private final MetaType1_9 newType;
|
||||||
private MetaType1_8 oldType;
|
private final MetaType1_8 oldType;
|
||||||
private int index;
|
private final int index;
|
||||||
|
|
||||||
MetaIndex(Entity1_10Types.EntityType type, int index, MetaType1_8 oldType, MetaType1_9 newType) {
|
MetaIndex(Entity1_10Types.EntityType type, int index, MetaType1_8 oldType, MetaType1_9 newType) {
|
||||||
this.clazz = type;
|
this.clazz = type;
|
||||||
@ -171,13 +172,13 @@ public enum MetaIndex {
|
|||||||
this.newType = newType;
|
this.newType = newType;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Optional<MetaIndex> getIndex(Entity1_10Types.EntityType type, int index) {
|
private static Optional<MetaIndex> getIndex(EntityType type, int index) {
|
||||||
Pair pair = new Pair<>(type, index);
|
Pair pair = new Pair<>(type, index);
|
||||||
return Optional.ofNullable(metadataRewrites.get(pair));
|
return Optional.ofNullable(metadataRewrites.get(pair));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static MetaIndex searchIndex(Entity1_10Types.EntityType type, int index) {
|
public static MetaIndex searchIndex(EntityType type, int index) {
|
||||||
Entity1_10Types.EntityType currentType = type;
|
EntityType currentType = type;
|
||||||
do {
|
do {
|
||||||
Optional<MetaIndex> optMeta = getIndex(currentType, index);
|
Optional<MetaIndex> optMeta = getIndex(currentType, index);
|
||||||
|
|
||||||
|
@ -2,7 +2,7 @@ package us.myles.ViaVersion.protocols.protocol1_9to1_8.metadata;
|
|||||||
|
|
||||||
import us.myles.ViaVersion.api.data.UserConnection;
|
import us.myles.ViaVersion.api.data.UserConnection;
|
||||||
import us.myles.ViaVersion.api.entities.Entity1_10Types;
|
import us.myles.ViaVersion.api.entities.Entity1_10Types;
|
||||||
import us.myles.ViaVersion.api.entities.Entity1_10Types.EntityType;
|
import us.myles.ViaVersion.api.entities.EntityType;
|
||||||
import us.myles.ViaVersion.api.minecraft.EulerAngle;
|
import us.myles.ViaVersion.api.minecraft.EulerAngle;
|
||||||
import us.myles.ViaVersion.api.minecraft.Vector;
|
import us.myles.ViaVersion.api.minecraft.Vector;
|
||||||
import us.myles.ViaVersion.api.minecraft.item.Item;
|
import us.myles.ViaVersion.api.minecraft.item.Item;
|
||||||
@ -13,12 +13,17 @@ import us.myles.ViaVersion.api.minecraft.metadata.types.MetaType1_9;
|
|||||||
import us.myles.ViaVersion.api.rewriters.MetadataRewriter;
|
import us.myles.ViaVersion.api.rewriters.MetadataRewriter;
|
||||||
import us.myles.ViaVersion.protocols.protocol1_9to1_8.ItemRewriter;
|
import us.myles.ViaVersion.protocols.protocol1_9to1_8.ItemRewriter;
|
||||||
import us.myles.ViaVersion.protocols.protocol1_9to1_8.Protocol1_9To1_8;
|
import us.myles.ViaVersion.protocols.protocol1_9to1_8.Protocol1_9To1_8;
|
||||||
|
import us.myles.ViaVersion.protocols.protocol1_9to1_8.storage.EntityTracker1_9;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
public class MetadataRewriter1_9To1_8 extends MetadataRewriter<Entity1_10Types.EntityType> {
|
public class MetadataRewriter1_9To1_8 extends MetadataRewriter<Protocol1_9To1_8> {
|
||||||
|
|
||||||
|
public MetadataRewriter1_9To1_8(Protocol1_9To1_8 protocol) {
|
||||||
|
super(protocol, EntityTracker1_9.class);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void handleMetadata(int entityId, EntityType type, Metadata metadata, List<Metadata> metadatas, Map<Integer, Metadata> metadataMap, UserConnection connection) throws Exception {
|
protected void handleMetadata(int entityId, EntityType type, Metadata metadata, List<Metadata> metadatas, Map<Integer, Metadata> metadataMap, UserConnection connection) throws Exception {
|
||||||
@ -35,7 +40,7 @@ public class MetadataRewriter1_9To1_8 extends MetadataRewriter<Entity1_10Types.E
|
|||||||
metadata.setId(metaIndex.getNewIndex());
|
metadata.setId(metaIndex.getNewIndex());
|
||||||
metadata.setMetaType(metaIndex.getNewType());
|
metadata.setMetaType(metaIndex.getNewType());
|
||||||
|
|
||||||
if (type == EntityType.ENDERMAN && metaIndex.getNewType() == MetaType1_9.BlockID) {
|
if (type == Entity1_10Types.EntityType.ENDERMAN && metaIndex.getNewType() == MetaType1_9.BlockID) {
|
||||||
if (metaIndex.getOldType() == MetaType1_8.Short) {
|
if (metaIndex.getOldType() == MetaType1_8.Short) {
|
||||||
int id = (Short) metadata.getValue();
|
int id = (Short) metadata.getValue();
|
||||||
int data = metadataMap.containsKey(17) ? (Byte) metadataMap.get(17).getValue() : 0;
|
int data = metadataMap.containsKey(17) ? (Byte) metadataMap.get(17).getValue() : 0;
|
||||||
@ -58,7 +63,7 @@ public class MetadataRewriter1_9To1_8 extends MetadataRewriter<Entity1_10Types.E
|
|||||||
metadata.setValue(((Integer) value).byteValue());
|
metadata.setValue(((Integer) value).byteValue());
|
||||||
}
|
}
|
||||||
// After writing the last one
|
// After writing the last one
|
||||||
if (metaIndex == MetaIndex.ENTITY_STATUS && type == EntityType.PLAYER) {
|
if (metaIndex == MetaIndex.ENTITY_STATUS && type == Entity1_10Types.EntityType.PLAYER) {
|
||||||
Byte val = 0;
|
Byte val = 0;
|
||||||
if ((((Byte) value) & 0x10) == 0x10) { // Player eating/aiming/drinking
|
if ((((Byte) value) & 0x10) == 0x10) { // Player eating/aiming/drinking
|
||||||
val = 1;
|
val = 1;
|
||||||
@ -74,7 +79,8 @@ public class MetadataRewriter1_9To1_8 extends MetadataRewriter<Entity1_10Types.E
|
|||||||
if (!owner.isEmpty()) {
|
if (!owner.isEmpty()) {
|
||||||
try {
|
try {
|
||||||
toWrite = UUID.fromString(owner);
|
toWrite = UUID.fromString(owner);
|
||||||
} catch (Exception ignored) {}
|
} catch (Exception ignored) {
|
||||||
|
}
|
||||||
}
|
}
|
||||||
metadata.setValue(toWrite);
|
metadata.setValue(toWrite);
|
||||||
break;
|
break;
|
||||||
|
@ -5,7 +5,6 @@ import us.myles.ViaVersion.api.PacketWrapper;
|
|||||||
import us.myles.ViaVersion.api.Pair;
|
import us.myles.ViaVersion.api.Pair;
|
||||||
import us.myles.ViaVersion.api.Triple;
|
import us.myles.ViaVersion.api.Triple;
|
||||||
import us.myles.ViaVersion.api.Via;
|
import us.myles.ViaVersion.api.Via;
|
||||||
import us.myles.ViaVersion.api.entities.Entity1_10Types;
|
|
||||||
import us.myles.ViaVersion.api.minecraft.item.Item;
|
import us.myles.ViaVersion.api.minecraft.item.Item;
|
||||||
import us.myles.ViaVersion.api.minecraft.metadata.Metadata;
|
import us.myles.ViaVersion.api.minecraft.metadata.Metadata;
|
||||||
import us.myles.ViaVersion.api.protocol.Protocol;
|
import us.myles.ViaVersion.api.protocol.Protocol;
|
||||||
@ -193,9 +192,8 @@ public class EntityPackets {
|
|||||||
List<Metadata> metadataList = wrapper.get(Types1_9.METADATA_LIST, 0);
|
List<Metadata> metadataList = wrapper.get(Types1_9.METADATA_LIST, 0);
|
||||||
int entityId = wrapper.get(Type.VAR_INT, 0);
|
int entityId = wrapper.get(Type.VAR_INT, 0);
|
||||||
EntityTracker1_9 tracker = wrapper.user().get(EntityTracker1_9.class);
|
EntityTracker1_9 tracker = wrapper.user().get(EntityTracker1_9.class);
|
||||||
Optional<Entity1_10Types.EntityType> type = tracker.getEntity(entityId);
|
if (tracker.hasEntity(entityId)) {
|
||||||
if (type.isPresent()) {
|
protocol.get(MetadataRewriter1_9To1_8.class).handleMetadata(entityId, metadataList, wrapper.user());
|
||||||
protocol.get(MetadataRewriter1_9To1_8.class).handleMetadata(entityId, type.get(), metadataList, wrapper.user());
|
|
||||||
} else {
|
} else {
|
||||||
// Buffer
|
// Buffer
|
||||||
tracker.addMetadataToBuffer(entityId, metadataList);
|
tracker.addMetadataToBuffer(entityId, metadataList);
|
||||||
|
@ -22,7 +22,6 @@ import us.myles.ViaVersion.protocols.protocol1_9to1_8.storage.EntityTracker1_9;
|
|||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Optional;
|
|
||||||
|
|
||||||
public class SpawnPackets {
|
public class SpawnPackets {
|
||||||
public static final ValueTransformer<Integer, Double> toNewDouble = new ValueTransformer<Integer, Double>(Type.DOUBLE) {
|
public static final ValueTransformer<Integer, Double> toNewDouble = new ValueTransformer<Integer, Double>(Type.DOUBLE) {
|
||||||
@ -215,9 +214,8 @@ public class SpawnPackets {
|
|||||||
List<Metadata> metadataList = wrapper.get(Types1_9.METADATA_LIST, 0);
|
List<Metadata> metadataList = wrapper.get(Types1_9.METADATA_LIST, 0);
|
||||||
int entityId = wrapper.get(Type.VAR_INT, 0);
|
int entityId = wrapper.get(Type.VAR_INT, 0);
|
||||||
EntityTracker1_9 tracker = wrapper.user().get(EntityTracker1_9.class);
|
EntityTracker1_9 tracker = wrapper.user().get(EntityTracker1_9.class);
|
||||||
Optional<Entity1_10Types.EntityType> type = tracker.getEntity(entityId);
|
if (tracker.hasEntity(entityId)) {
|
||||||
if (type.isPresent()) {
|
protocol.get(MetadataRewriter1_9To1_8.class).handleMetadata(entityId, metadataList, wrapper.user());
|
||||||
protocol.get(MetadataRewriter1_9To1_8.class).handleMetadata(entityId, type.get(), metadataList, wrapper.user());
|
|
||||||
} else {
|
} else {
|
||||||
Via.getPlatform().getLogger().warning("Unable to find entity for metadata, entity ID: " + entityId);
|
Via.getPlatform().getLogger().warning("Unable to find entity for metadata, entity ID: " + entityId);
|
||||||
metadataList.clear();
|
metadataList.clear();
|
||||||
@ -321,9 +319,8 @@ public class SpawnPackets {
|
|||||||
List<Metadata> metadataList = wrapper.get(Types1_9.METADATA_LIST, 0);
|
List<Metadata> metadataList = wrapper.get(Types1_9.METADATA_LIST, 0);
|
||||||
int entityId = wrapper.get(Type.VAR_INT, 0);
|
int entityId = wrapper.get(Type.VAR_INT, 0);
|
||||||
EntityTracker1_9 tracker = wrapper.user().get(EntityTracker1_9.class);
|
EntityTracker1_9 tracker = wrapper.user().get(EntityTracker1_9.class);
|
||||||
Optional<Entity1_10Types.EntityType> type = tracker.getEntity(entityId);
|
if (tracker.hasEntity(entityId)) {
|
||||||
if (type.isPresent()) {
|
protocol.get(MetadataRewriter1_9To1_8.class).handleMetadata(entityId, metadataList, wrapper.user());
|
||||||
protocol.get(MetadataRewriter1_9To1_8.class).handleMetadata(entityId, type.get(), metadataList, wrapper.user());
|
|
||||||
} else {
|
} else {
|
||||||
Via.getPlatform().getLogger().warning("Unable to find entity for metadata, entity ID: " + entityId);
|
Via.getPlatform().getLogger().warning("Unable to find entity for metadata, entity ID: " + entityId);
|
||||||
metadataList.clear();
|
metadataList.clear();
|
||||||
|
@ -31,7 +31,7 @@ import java.util.concurrent.ConcurrentHashMap;
|
|||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
@Getter
|
@Getter
|
||||||
public class EntityTracker1_9 extends EntityTracker<EntityType> {
|
public class EntityTracker1_9 extends EntityTracker {
|
||||||
private final Map<Integer, UUID> uuidMap = new ConcurrentHashMap<>();
|
private final Map<Integer, UUID> uuidMap = new ConcurrentHashMap<>();
|
||||||
private final Map<Integer, List<Metadata>> metadataBuffer = new ConcurrentHashMap<>();
|
private final Map<Integer, List<Metadata>> metadataBuffer = new ConcurrentHashMap<>();
|
||||||
private final Map<Integer, Integer> vehicleMap = new ConcurrentHashMap<>();
|
private final Map<Integer, Integer> vehicleMap = new ConcurrentHashMap<>();
|
||||||
@ -116,7 +116,7 @@ public class EntityTracker1_9 extends EntityTracker<EntityType> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void handleMetadata(int entityId, List<Metadata> metadataList) {
|
public void handleMetadata(int entityId, List<Metadata> metadataList) {
|
||||||
EntityType type = getEntity(entityId).orElse(null);
|
us.myles.ViaVersion.api.entities.EntityType type = getEntity(entityId);
|
||||||
if (type == null) {
|
if (type == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -292,7 +292,7 @@ public class EntityTracker1_9 extends EntityTracker<EntityType> {
|
|||||||
wrapper.write(Type.VAR_INT, entityId);
|
wrapper.write(Type.VAR_INT, entityId);
|
||||||
wrapper.write(Types1_9.METADATA_LIST, metadataList);
|
wrapper.write(Types1_9.METADATA_LIST, metadataList);
|
||||||
getUser().get(ProtocolInfo.class).getPipeline().getProtocol(Protocol1_9To1_8.class).get(MetadataRewriter1_9To1_8.class)
|
getUser().get(ProtocolInfo.class).getPipeline().getProtocol(Protocol1_9To1_8.class).get(MetadataRewriter1_9To1_8.class)
|
||||||
.handleMetadata(entityId, getEntity(entityId).orElse(null), metadataList, getUser());
|
.handleMetadata(entityId, metadataList, getUser());
|
||||||
handleMetadata(entityId, metadataList);
|
handleMetadata(entityId, metadataList);
|
||||||
if (!metadataList.isEmpty()) {
|
if (!metadataList.isEmpty()) {
|
||||||
try {
|
try {
|
||||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren