Mirror von
https://github.com/ViaVersion/ViaVersion.git
synchronisiert 2024-12-24 23:30:15 +01:00
Merge pull request #1477 from KennyTV/abstraction
Cleanup more entity tracking and rewriting
Dieser Commit ist enthalten in:
Commit
857ae523cf
@ -331,13 +331,6 @@ public interface ViaVersionConfig {
|
||||
|
||||
boolean is1_14HealthNaNFix();
|
||||
|
||||
/**
|
||||
* Fixes non full blocks having 0 light for 1.14+ clients on sub 1.14 servers.
|
||||
*
|
||||
* @return True if enabled
|
||||
*/
|
||||
boolean isNonFullBlockLightFix();
|
||||
|
||||
/**
|
||||
* Should 1.15 clients respawn instantly / without showing the death screen
|
||||
*
|
||||
|
@ -116,6 +116,19 @@ public abstract class Protocol {
|
||||
incoming.put(pair, protocolPacket);
|
||||
}
|
||||
|
||||
public void cancelIncoming(State state, int oldPacketID, int newPacketID) {
|
||||
registerIncoming(state, oldPacketID, newPacketID, new PacketRemapper() {
|
||||
@Override
|
||||
public void registerMap() {
|
||||
handler(PacketWrapper::cancel);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void cancelIncoming(State state, int newPacketID) {
|
||||
cancelIncoming(state, -1, newPacketID);
|
||||
}
|
||||
|
||||
/**
|
||||
* Register an outgoing packet, with simple id transformation.
|
||||
*
|
||||
@ -149,6 +162,19 @@ public abstract class Protocol {
|
||||
outgoing.put(pair, protocolPacket);
|
||||
}
|
||||
|
||||
public void cancelOutgoing(State state, int oldPacketID, int newPacketID) {
|
||||
registerOutgoing(state, oldPacketID, newPacketID, new PacketRemapper() {
|
||||
@Override
|
||||
public void registerMap() {
|
||||
handler(PacketWrapper::cancel);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void cancelOutgoing(State state, int oldPacketID) {
|
||||
cancelOutgoing(state, oldPacketID, -1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Transform a packet using this protocol
|
||||
*
|
||||
|
@ -78,23 +78,71 @@ public abstract class MetadataRewriter<T extends Protocol> extends Rewriter<T> {
|
||||
registerMetadataRewriter(oldPacketId, newPacketId, null, metaType);
|
||||
}
|
||||
|
||||
public void registerExtraTracker(int packetId, EntityType entityType, Type intType) {
|
||||
getProtocol().registerOutgoing(State.PLAY, packetId, packetId, new PacketRemapper() {
|
||||
/**
|
||||
* Returns a packethandler to track and rewrite an entity.
|
||||
*
|
||||
* @param metaType type of the metadata list
|
||||
* @return handler for tracking and rewriting entities
|
||||
*/
|
||||
public PacketHandler getTrackerAndRewriter(Type<List<Metadata>> metaType) {
|
||||
return new PacketHandler() {
|
||||
@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 handle(PacketWrapper wrapper) throws Exception {
|
||||
int entityId = wrapper.get(Type.VAR_INT, 0);
|
||||
int type = wrapper.get(Type.VAR_INT, 1);
|
||||
|
||||
int newType = getNewEntityId(type);
|
||||
if (newType != type) {
|
||||
wrapper.set(Type.VAR_INT, 1, newType);
|
||||
}
|
||||
|
||||
EntityType entType = getTypeFromId(newType);
|
||||
// Register Type ID
|
||||
wrapper.user().get(entityTrackerClass).addEntity(entityId, entType);
|
||||
|
||||
if (metaType != null) {
|
||||
handleMetadata(entityId, wrapper.get(metaType, 0), wrapper.user());
|
||||
}
|
||||
}
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
public void registerExtraTracker(int packetId, EntityType entityType) {
|
||||
registerExtraTracker(packetId, entityType, Type.VAR_INT);
|
||||
public PacketHandler getTracker() {
|
||||
return getTrackerAndRewriter(null);
|
||||
}
|
||||
|
||||
public PacketHandler getTrackerAndRewriter(Type<List<Metadata>> metaType, EntityType entityType) {
|
||||
return new PacketHandler() {
|
||||
@Override
|
||||
public void handle(PacketWrapper wrapper) throws Exception {
|
||||
int entityId = wrapper.get(Type.VAR_INT, 0);
|
||||
// Register Type ID
|
||||
wrapper.user().get(entityTrackerClass).addEntity(entityId, entityType);
|
||||
|
||||
if (metaType != null) {
|
||||
handleMetadata(entityId, wrapper.get(metaType, 0), wrapper.user());
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a packethandler to track an object entity.
|
||||
*
|
||||
* @return handler for tracking and rewriting entities
|
||||
*/
|
||||
public PacketHandler getObjectTracker() {
|
||||
return new PacketHandler() {
|
||||
@Override
|
||||
public void handle(PacketWrapper wrapper) throws Exception {
|
||||
int entityId = wrapper.get(Type.VAR_INT, 0);
|
||||
byte type = wrapper.get(Type.BYTE, 0);
|
||||
|
||||
EntityType entType = getObjectTypeFromId(type);
|
||||
// Register Type ID
|
||||
wrapper.user().get(entityTrackerClass).addEntity(entityId, entType);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
public void registerEntityDestroy(int oldPacketId, int newPacketId) {
|
||||
@ -119,6 +167,16 @@ public abstract class MetadataRewriter<T extends Protocol> extends Rewriter<T> {
|
||||
registerEntityDestroy(packetId, packetId);
|
||||
}
|
||||
|
||||
protected abstract EntityType getTypeFromId(int type);
|
||||
|
||||
protected EntityType getObjectTypeFromId(int type) {
|
||||
return getTypeFromId(type);
|
||||
}
|
||||
|
||||
protected int getNewEntityId(int oldId) {
|
||||
return oldId;
|
||||
}
|
||||
|
||||
protected void handleMetadata(int entityId, EntityType type, Metadata metadata, List<Metadata> metadatas, UserConnection connection) throws Exception {
|
||||
}
|
||||
|
||||
|
@ -44,19 +44,7 @@ public class Protocol1_11To1_10 extends Protocol {
|
||||
map(Type.BYTE); // 2 - Type
|
||||
|
||||
// Track Entity
|
||||
handler(new PacketHandler() {
|
||||
@Override
|
||||
public void handle(PacketWrapper wrapper) throws Exception {
|
||||
|
||||
int entityId = wrapper.get(Type.VAR_INT, 0);
|
||||
byte type = wrapper.get(Type.BYTE, 0);
|
||||
|
||||
Entity1_11Types.EntityType entType = Entity1_11Types.getTypeFromId(type, true);
|
||||
|
||||
// Register Type ID
|
||||
wrapper.user().get(EntityTracker1_11.class).addEntity(entityId, entType);
|
||||
}
|
||||
});
|
||||
handler(metadataRewriter.getObjectTracker());
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -3,6 +3,7 @@ package us.myles.ViaVersion.protocols.protocol1_11to1_10.metadata;
|
||||
import us.myles.ViaVersion.api.PacketWrapper;
|
||||
import us.myles.ViaVersion.api.Via;
|
||||
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.minecraft.item.Item;
|
||||
import us.myles.ViaVersion.api.minecraft.metadata.Metadata;
|
||||
@ -130,6 +131,16 @@ public class MetadataRewriter1_11To1_10 extends MetadataRewriter<Protocol1_11To1
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected us.myles.ViaVersion.api.entities.EntityType getTypeFromId(int type) {
|
||||
return Entity1_11Types.getTypeFromId(type, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected us.myles.ViaVersion.api.entities.EntityType getObjectTypeFromId(int type) {
|
||||
return Entity1_11Types.getTypeFromId(type, true);
|
||||
}
|
||||
|
||||
public static EntityType rewriteEntityType(int numType, List<Metadata> metadata) {
|
||||
Optional<EntityType> optType = EntityType.findById(numType);
|
||||
if (!optType.isPresent()) {
|
||||
|
@ -8,7 +8,6 @@ import com.google.gson.JsonParser;
|
||||
import us.myles.ViaVersion.api.PacketWrapper;
|
||||
import us.myles.ViaVersion.api.Via;
|
||||
import us.myles.ViaVersion.api.data.UserConnection;
|
||||
import us.myles.ViaVersion.api.entities.Entity1_12Types;
|
||||
import us.myles.ViaVersion.api.minecraft.chunks.Chunk;
|
||||
import us.myles.ViaVersion.api.minecraft.chunks.ChunkSection;
|
||||
import us.myles.ViaVersion.api.platform.providers.ViaProviders;
|
||||
@ -43,19 +42,7 @@ public class Protocol1_12To1_11_1 extends Protocol {
|
||||
map(Type.BYTE); // 2 - Type
|
||||
|
||||
// Track Entity
|
||||
handler(new PacketHandler() {
|
||||
@Override
|
||||
public void handle(PacketWrapper wrapper) throws Exception {
|
||||
|
||||
int entityId = wrapper.get(Type.VAR_INT, 0);
|
||||
byte type = wrapper.get(Type.BYTE, 0);
|
||||
|
||||
Entity1_12Types.EntityType entType = Entity1_12Types.getTypeFromId(type, true);
|
||||
|
||||
// Register Type ID
|
||||
wrapper.user().get(EntityTracker1_12.class).addEntity(entityId, entType);
|
||||
}
|
||||
});
|
||||
handler(metadataRewriter.getObjectTracker());
|
||||
}
|
||||
});
|
||||
|
||||
@ -77,19 +64,8 @@ public class Protocol1_12To1_11_1 extends Protocol {
|
||||
map(Type.SHORT); // 11 - Velocity Z
|
||||
map(Types1_12.METADATA_LIST); // 12 - Metadata
|
||||
|
||||
handler(new PacketHandler() {
|
||||
@Override
|
||||
public void handle(PacketWrapper wrapper) throws Exception {
|
||||
int entityId = wrapper.get(Type.VAR_INT, 0);
|
||||
// Change Type :)
|
||||
int type = wrapper.get(Type.VAR_INT, 1);
|
||||
|
||||
Entity1_12Types.EntityType entType = Entity1_12Types.getTypeFromId(type, false);
|
||||
// Register Type ID
|
||||
wrapper.user().get(EntityTracker1_12.class).addEntity(entityId, entType);
|
||||
metadataRewriter.handleMetadata(entityId, wrapper.get(Types1_12.METADATA_LIST, 0), wrapper.user());
|
||||
}
|
||||
});
|
||||
// Track mob and rewrite metadata
|
||||
handler(metadataRewriter.getTrackerAndRewriter(Types1_12.METADATA_LIST));
|
||||
}
|
||||
});
|
||||
|
||||
@ -272,18 +248,8 @@ public class Protocol1_12To1_11_1 extends Protocol {
|
||||
|
||||
// Incoming
|
||||
// New packet at 0x01
|
||||
registerIncoming(State.PLAY, 0x01, 0x01, new PacketRemapper() {
|
||||
@Override
|
||||
public void registerMap() {
|
||||
handler(new PacketHandler() {
|
||||
cancelIncoming(State.PLAY, 0x01, 0x01);
|
||||
|
||||
@Override
|
||||
public void handle(PacketWrapper wrapper) throws Exception {
|
||||
wrapper.cancel();
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
registerIncoming(State.PLAY, 0x01, 0x02);
|
||||
registerIncoming(State.PLAY, 0x02, 0x03);
|
||||
registerIncoming(State.PLAY, 0x03, 0x04);
|
||||
@ -336,33 +302,15 @@ public class Protocol1_12To1_11_1 extends Protocol {
|
||||
registerIncoming(State.PLAY, 0x13, 0x14);
|
||||
registerIncoming(State.PLAY, 0x14, 0x15);
|
||||
registerIncoming(State.PLAY, 0x15, 0x16);
|
||||
|
||||
// New packet at 0x17
|
||||
registerIncoming(State.PLAY, 0x17, 0x17, new PacketRemapper() {
|
||||
@Override
|
||||
public void registerMap() {
|
||||
handler(new PacketHandler() {
|
||||
cancelIncoming(State.PLAY, 0x17, 0x17);
|
||||
|
||||
@Override
|
||||
public void handle(PacketWrapper wrapper) throws Exception {
|
||||
wrapper.cancel();
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
registerIncoming(State.PLAY, 0x16, 0x18);
|
||||
// New packet 0x19
|
||||
registerIncoming(State.PLAY, 0x19, 0x19, new PacketRemapper() {
|
||||
@Override
|
||||
public void registerMap() {
|
||||
handler(new PacketHandler() {
|
||||
|
||||
@Override
|
||||
public void handle(PacketWrapper wrapper) throws Exception {
|
||||
wrapper.cancel();
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
// New packet 0x19
|
||||
cancelIncoming(State.PLAY, 0x19, 0x19);
|
||||
|
||||
registerIncoming(State.PLAY, 0x17, 0x1a);
|
||||
// registerIncoming(State.PLAY, 0x18, 0x1b); - Handled in InventoryPackets
|
||||
registerIncoming(State.PLAY, 0x19, 0x1c);
|
||||
|
@ -33,4 +33,14 @@ public class MetadataRewriter1_12To1_11_1 extends MetadataRewriter<Protocol1_12T
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected EntityType getTypeFromId(int type) {
|
||||
return Entity1_12Types.getTypeFromId(type, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected EntityType getObjectTypeFromId(int type) {
|
||||
return Entity1_12Types.getTypeFromId(type, true);
|
||||
}
|
||||
}
|
||||
|
@ -43,4 +43,13 @@ public class MetadataRewriter1_13_1To1_13 extends MetadataRewriter<Protocol1_13_
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected EntityType getTypeFromId(int type) {
|
||||
return Entity1_13Types.getTypeFromId(type, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected EntityType getObjectTypeFromId(int type) {
|
||||
return Entity1_13Types.getTypeFromId(type, true);
|
||||
}
|
||||
}
|
||||
|
@ -51,6 +51,7 @@ public class EntityPackets {
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
// Spawn mob packet
|
||||
protocol.registerOutgoing(State.PLAY, 0x3, 0x3, new PacketRemapper() {
|
||||
@Override
|
||||
@ -69,20 +70,7 @@ public class EntityPackets {
|
||||
map(Type.SHORT); // 11 - Velocity Z
|
||||
map(Types1_13.METADATA_LIST); // 12 - Metadata
|
||||
|
||||
handler(new PacketHandler() {
|
||||
@Override
|
||||
public void handle(PacketWrapper wrapper) throws Exception {
|
||||
int entityId = wrapper.get(Type.VAR_INT, 0);
|
||||
int type = wrapper.get(Type.VAR_INT, 1);
|
||||
|
||||
Entity1_13Types.EntityType entType = Entity1_13Types.getTypeFromId(type, false);
|
||||
|
||||
// Register Type ID
|
||||
wrapper.user().get(EntityTracker1_13.class).addEntity(entityId, entType);
|
||||
|
||||
metadataRewriter.handleMetadata(entityId, wrapper.get(Types1_13.METADATA_LIST, 0), wrapper.user());
|
||||
}
|
||||
});
|
||||
handler(metadataRewriter.getTrackerAndRewriter(Types1_13.METADATA_LIST));
|
||||
}
|
||||
});
|
||||
|
||||
@ -99,17 +87,7 @@ public class EntityPackets {
|
||||
map(Type.BYTE); // 6 - Pitch
|
||||
map(Types1_13.METADATA_LIST); // 7 - Metadata
|
||||
|
||||
handler(new PacketHandler() {
|
||||
@Override
|
||||
public void handle(PacketWrapper wrapper) throws Exception {
|
||||
int entityId = wrapper.get(Type.VAR_INT, 0);
|
||||
|
||||
Entity1_13Types.EntityType entType = Entity1_13Types.EntityType.PLAYER;
|
||||
// Register Type ID
|
||||
wrapper.user().get(EntityTracker1_13.class).addEntity(entityId, entType);
|
||||
metadataRewriter.handleMetadata(entityId, wrapper.get(Types1_13.METADATA_LIST, 0), wrapper.user());
|
||||
}
|
||||
});
|
||||
handler(metadataRewriter.getTrackerAndRewriter(Types1_13.METADATA_LIST, Entity1_13Types.EntityType.PLAYER));
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -799,30 +799,10 @@ public class Protocol1_13To1_12_2 extends Protocol {
|
||||
// Incoming packets
|
||||
|
||||
// New packet 0x02 - Login Plugin Message
|
||||
registerIncoming(State.LOGIN, -1, 0x02, new PacketRemapper() {
|
||||
@Override
|
||||
public void registerMap() {
|
||||
handler(new PacketHandler() {
|
||||
@Override
|
||||
public void handle(PacketWrapper wrapper) throws Exception {
|
||||
wrapper.cancel();
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
cancelIncoming(State.LOGIN, 0x02);
|
||||
|
||||
// New 0x01 - Query Block NBT
|
||||
registerIncoming(State.PLAY, -1, 0x01, new PacketRemapper() {
|
||||
@Override
|
||||
public void registerMap() {
|
||||
handler(new PacketHandler() {
|
||||
@Override
|
||||
public void handle(PacketWrapper wrapper) throws Exception {
|
||||
wrapper.cancel();
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
cancelIncoming(State.PLAY, 0x01);
|
||||
|
||||
// Tab-Complete
|
||||
registerIncoming(State.PLAY, 0x1, 0x5, new PacketRemapper() {
|
||||
@ -890,17 +870,8 @@ public class Protocol1_13To1_12_2 extends Protocol {
|
||||
}
|
||||
});
|
||||
// New 0x0C - Query Entity NBT
|
||||
registerIncoming(State.PLAY, -1, 0x0C, new PacketRemapper() {
|
||||
@Override
|
||||
public void registerMap() {
|
||||
handler(new PacketHandler() {
|
||||
@Override
|
||||
public void handle(PacketWrapper wrapper) throws Exception {
|
||||
wrapper.cancel();
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
cancelIncoming(State.PLAY, 0x0C);
|
||||
|
||||
registerIncoming(State.PLAY, 0x0A, 0x0D);
|
||||
registerIncoming(State.PLAY, 0x0B, 0x0E);
|
||||
registerIncoming(State.PLAY, 0x0C, 0x0F);
|
||||
|
@ -9,6 +9,7 @@ import us.myles.ViaVersion.api.minecraft.metadata.types.MetaType1_13;
|
||||
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.Protocol1_13To1_12_2;
|
||||
import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.data.EntityTypeRewriter;
|
||||
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.packets.InventoryPackets;
|
||||
@ -98,4 +99,19 @@ public class MetadataRewriter1_13To1_12_2 extends MetadataRewriter<Protocol1_13T
|
||||
|
||||
// TODO: Boat has changed
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getNewEntityId(final int oldId) {
|
||||
return EntityTypeRewriter.getNewId(oldId).orElse(oldId);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected EntityType getTypeFromId(int type) {
|
||||
return Entity1_13Types.getTypeFromId(type, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected EntityType getObjectTypeFromId(int type) {
|
||||
return Entity1_13Types.getTypeFromId(type, true);
|
||||
}
|
||||
}
|
||||
|
@ -9,12 +9,9 @@ import us.myles.ViaVersion.api.type.Type;
|
||||
import us.myles.ViaVersion.api.type.types.version.Types1_12;
|
||||
import us.myles.ViaVersion.api.type.types.version.Types1_13;
|
||||
import us.myles.ViaVersion.packets.State;
|
||||
import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.data.EntityTypeRewriter;
|
||||
import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.metadata.MetadataRewriter1_13To1_12_2;
|
||||
import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.storage.EntityTracker1_13;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
public class EntityPackets {
|
||||
public static void register(final Protocol protocol) {
|
||||
MetadataRewriter1_13To1_12_2 metadataRewriter = protocol.get(MetadataRewriter1_13To1_12_2.class);
|
||||
@ -97,25 +94,7 @@ public class EntityPackets {
|
||||
map(Type.SHORT); // 11 - Velocity Z
|
||||
map(Types1_12.METADATA_LIST, Types1_13.METADATA_LIST); // 12 - Metadata
|
||||
|
||||
handler(new PacketHandler() {
|
||||
@Override
|
||||
public void handle(PacketWrapper wrapper) throws Exception {
|
||||
int entityId = wrapper.get(Type.VAR_INT, 0);
|
||||
int type = wrapper.get(Type.VAR_INT, 1);
|
||||
|
||||
Optional<Integer> optNewType = EntityTypeRewriter.getNewId(type);
|
||||
type = optNewType.orElse(type);
|
||||
Entity1_13Types.EntityType entType = Entity1_13Types.getTypeFromId(type, false);
|
||||
|
||||
wrapper.set(Type.VAR_INT, 1, type);
|
||||
|
||||
|
||||
// Register Type ID
|
||||
wrapper.user().get(EntityTracker1_13.class).addEntity(entityId, entType);
|
||||
|
||||
metadataRewriter.handleMetadata(entityId, wrapper.get(Types1_13.METADATA_LIST, 0), wrapper.user());
|
||||
}
|
||||
});
|
||||
handler(metadataRewriter.getTrackerAndRewriter(Types1_13.METADATA_LIST));
|
||||
}
|
||||
});
|
||||
|
||||
@ -132,17 +111,7 @@ public class EntityPackets {
|
||||
map(Type.BYTE); // 6 - Pitch
|
||||
map(Types1_12.METADATA_LIST, Types1_13.METADATA_LIST); // 7 - Metadata
|
||||
|
||||
handler(new PacketHandler() {
|
||||
@Override
|
||||
public void handle(PacketWrapper wrapper) throws Exception {
|
||||
int entityId = wrapper.get(Type.VAR_INT, 0);
|
||||
|
||||
Entity1_13Types.EntityType entType = Entity1_13Types.EntityType.PLAYER;
|
||||
// Register Type ID
|
||||
wrapper.user().get(EntityTracker1_13.class).addEntity(entityId, entType);
|
||||
metadataRewriter.handleMetadata(entityId, wrapper.get(Types1_13.METADATA_LIST, 0), wrapper.user());
|
||||
}
|
||||
});
|
||||
handler(metadataRewriter.getTrackerAndRewriter(Types1_13.METADATA_LIST, Entity1_13Types.EntityType.PLAYER));
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -26,4 +26,9 @@ public class MetadataRewriter1_14_1To1_14 extends MetadataRewriter<Protocol1_14_
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected EntityType getTypeFromId(int type) {
|
||||
return Entity1_14Types.getTypeFromId(type);
|
||||
}
|
||||
}
|
||||
|
@ -1,15 +1,12 @@
|
||||
package us.myles.ViaVersion.protocols.protocol1_14_1to1_14.packets;
|
||||
|
||||
import us.myles.ViaVersion.api.PacketWrapper;
|
||||
import us.myles.ViaVersion.api.entities.Entity1_14Types;
|
||||
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.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.metadata.MetadataRewriter1_14_1To1_14;
|
||||
import us.myles.ViaVersion.protocols.protocol1_14_1to1_14.storage.EntityTracker1_14_1;
|
||||
|
||||
public class EntityPackets {
|
||||
|
||||
@ -34,38 +31,12 @@ public class EntityPackets {
|
||||
map(Type.SHORT); // 11 - Velocity Z
|
||||
map(Types1_14.METADATA_LIST); // 12 - Metadata
|
||||
|
||||
handler(new PacketHandler() {
|
||||
@Override
|
||||
public void handle(PacketWrapper wrapper) throws Exception {
|
||||
int entityId = wrapper.get(Type.VAR_INT, 0);
|
||||
int type = wrapper.get(Type.VAR_INT, 1);
|
||||
|
||||
Entity1_14Types.EntityType entType = Entity1_14Types.getTypeFromId(type);
|
||||
|
||||
// Register Type ID
|
||||
wrapper.user().get(EntityTracker1_14_1.class).addEntity(entityId, entType);
|
||||
|
||||
metadataRewriter.handleMetadata(entityId, wrapper.get(Types1_14.METADATA_LIST, 0), wrapper.user());
|
||||
}
|
||||
});
|
||||
handler(metadataRewriter.getTrackerAndRewriter(Types1_14.METADATA_LIST));
|
||||
}
|
||||
});
|
||||
|
||||
// Destroy entities
|
||||
protocol.registerOutgoing(State.PLAY, 0x37, 0x37, 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 {
|
||||
for (int entity : wrapper.get(Type.VAR_INT_ARRAY, 0)) {
|
||||
wrapper.user().get(EntityTracker.class).removeEntity(entity);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
metadataRewriter.registerEntityDestroy(0x37);
|
||||
|
||||
// Spawn Player
|
||||
protocol.registerOutgoing(State.PLAY, 0x05, 0x05, new PacketRemapper() {
|
||||
@ -80,18 +51,7 @@ public class EntityPackets {
|
||||
map(Type.BYTE); // 6 - Pitch
|
||||
map(Types1_14.METADATA_LIST); // 7 - Metadata
|
||||
|
||||
handler(new PacketHandler() {
|
||||
@Override
|
||||
public void handle(PacketWrapper wrapper) throws Exception {
|
||||
int entityId = wrapper.get(Type.VAR_INT, 0);
|
||||
|
||||
Entity1_14Types.EntityType entType = Entity1_14Types.EntityType.PLAYER;
|
||||
|
||||
// Register Type ID
|
||||
wrapper.user().get(EntityTracker1_14_1.class).addEntity(entityId, entType);
|
||||
metadataRewriter.handleMetadata(entityId, wrapper.get(Types1_14.METADATA_LIST, 0), wrapper.user());
|
||||
}
|
||||
});
|
||||
handler(metadataRewriter.getTrackerAndRewriter(Types1_14.METADATA_LIST, Entity1_14Types.EntityType.PLAYER));
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -217,17 +217,8 @@ public class Protocol1_14To1_13_2 extends Protocol {
|
||||
});
|
||||
|
||||
//Set Difficulty packet added in 19w11a
|
||||
registerIncoming(State.PLAY, -1, 0x02, new PacketRemapper() {
|
||||
@Override
|
||||
public void registerMap() {
|
||||
handler(new PacketHandler() {
|
||||
@Override
|
||||
public void handle(PacketWrapper wrapper) {
|
||||
wrapper.cancel();
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
cancelIncoming(State.PLAY, 0x02);
|
||||
|
||||
registerIncoming(State.PLAY, 0x02, 0x03);
|
||||
registerIncoming(State.PLAY, 0x03, 0x04);
|
||||
registerIncoming(State.PLAY, 0x04, 0x05);
|
||||
@ -242,17 +233,8 @@ public class Protocol1_14To1_13_2 extends Protocol {
|
||||
registerIncoming(State.PLAY, 0x0D, 0x0E);
|
||||
|
||||
//Lock Difficulty packet added in 19w11a
|
||||
registerIncoming(State.PLAY, -1, 0x10, new PacketRemapper() {
|
||||
@Override
|
||||
public void registerMap() {
|
||||
handler(new PacketHandler() {
|
||||
@Override
|
||||
public void handle(PacketWrapper wrapper) {
|
||||
wrapper.cancel();
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
cancelIncoming(State.PLAY, 0x10);
|
||||
|
||||
registerIncoming(State.PLAY, 0x0E, 0x0F);
|
||||
registerIncoming(State.PLAY, 0x0F, 0x14);
|
||||
registerIncoming(State.PLAY, 0x10, 0x11);
|
||||
@ -276,17 +258,7 @@ public class Protocol1_14To1_13_2 extends Protocol {
|
||||
registerIncoming(State.PLAY, 0x23, 0x25);
|
||||
|
||||
//Unknown packet added in 19w13a
|
||||
registerIncoming(State.PLAY, -1, 0x27, new PacketRemapper() {
|
||||
@Override
|
||||
public void registerMap() {
|
||||
handler(new PacketHandler() {
|
||||
@Override
|
||||
public void handle(PacketWrapper wrapper) {
|
||||
wrapper.cancel();
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
cancelIncoming(State.PLAY, 0x27);
|
||||
|
||||
registerIncoming(State.PLAY, 0x27, 0x2A);
|
||||
registerIncoming(State.PLAY, 0x28, 0x2B);
|
||||
|
@ -13,6 +13,7 @@ import us.myles.ViaVersion.api.rewriters.MetadataRewriter;
|
||||
import us.myles.ViaVersion.api.type.Type;
|
||||
import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.data.Particle;
|
||||
import us.myles.ViaVersion.protocols.protocol1_14to1_13_2.Protocol1_14To1_13_2;
|
||||
import us.myles.ViaVersion.protocols.protocol1_14to1_13_2.data.EntityTypeRewriter;
|
||||
import us.myles.ViaVersion.protocols.protocol1_14to1_13_2.packets.InventoryPackets;
|
||||
import us.myles.ViaVersion.protocols.protocol1_14to1_13_2.storage.EntityTracker1_14;
|
||||
|
||||
@ -167,6 +168,16 @@ public class MetadataRewriter1_14To1_13_2 extends MetadataRewriter<Protocol1_14T
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getNewEntityId(final int oldId) {
|
||||
return EntityTypeRewriter.getNewId(oldId).orElse(oldId);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected EntityType getTypeFromId(int type) {
|
||||
return Entity1_14Types.getTypeFromId(type);
|
||||
}
|
||||
|
||||
private static boolean isSneaking(byte flags) {
|
||||
return (flags & 0x2) != 0;
|
||||
}
|
||||
|
@ -122,22 +122,7 @@ public class EntityPackets {
|
||||
map(Type.SHORT); // 11 - Velocity Z
|
||||
map(Types1_13_2.METADATA_LIST, Types1_14.METADATA_LIST); // 12 - Metadata
|
||||
|
||||
handler(new PacketHandler() {
|
||||
@Override
|
||||
public void handle(PacketWrapper wrapper) throws Exception {
|
||||
int entityId = wrapper.get(Type.VAR_INT, 0);
|
||||
int type = wrapper.get(Type.VAR_INT, 1);
|
||||
|
||||
type = EntityTypeRewriter.getNewId(type).orElse(type);
|
||||
wrapper.set(Type.VAR_INT, 1, type);
|
||||
|
||||
Entity1_14Types.EntityType entType = Entity1_14Types.getTypeFromId(type);
|
||||
// Register Type ID
|
||||
wrapper.user().get(EntityTracker1_14.class).addEntity(entityId, entType);
|
||||
|
||||
metadataRewriter.handleMetadata(entityId, wrapper.get(Types1_14.METADATA_LIST, 0), wrapper.user());
|
||||
}
|
||||
});
|
||||
handler(metadataRewriter.getTrackerAndRewriter(Types1_14.METADATA_LIST));
|
||||
}
|
||||
});
|
||||
|
||||
@ -166,17 +151,7 @@ public class EntityPackets {
|
||||
map(Type.BYTE); // 6 - Pitch
|
||||
map(Types1_13_2.METADATA_LIST, Types1_14.METADATA_LIST); // 7 - Metadata
|
||||
|
||||
handler(new PacketHandler() {
|
||||
@Override
|
||||
public void handle(PacketWrapper wrapper) throws Exception {
|
||||
int entityId = wrapper.get(Type.VAR_INT, 0);
|
||||
|
||||
Entity1_14Types.EntityType entType = Entity1_14Types.EntityType.PLAYER;
|
||||
// Register Type ID
|
||||
wrapper.user().get(EntityTracker1_14.class).addEntity(entityId, entType);
|
||||
metadataRewriter.handleMetadata(entityId, wrapper.get(Types1_14.METADATA_LIST, 0), wrapper.user());
|
||||
}
|
||||
});
|
||||
handler(metadataRewriter.getTrackerAndRewriter(Types1_14.METADATA_LIST, Entity1_14Types.EntityType.PLAYER));
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -8,6 +8,7 @@ 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.EntityPackets;
|
||||
import us.myles.ViaVersion.protocols.protocol1_15to1_14_4.packets.InventoryPackets;
|
||||
import us.myles.ViaVersion.protocols.protocol1_15to1_14_4.storage.EntityTracker1_15;
|
||||
|
||||
@ -38,4 +39,14 @@ public class MetadataRewriter1_15To1_14_4 extends MetadataRewriter<Protocol1_15T
|
||||
|
||||
//TODO new boolean with id 17 for enderman
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getNewEntityId(final int oldId) {
|
||||
return EntityPackets.getNewEntityId(oldId);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected EntityType getTypeFromId(int type) {
|
||||
return Entity1_15Types.getTypeFromId(type);
|
||||
}
|
||||
}
|
||||
|
@ -130,4 +130,13 @@ public class MetadataRewriter1_9To1_8 extends MetadataRewriter<Protocol1_9To1_8>
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected EntityType getTypeFromId(int type) {
|
||||
return Entity1_10Types.getTypeFromId(type, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected EntityType getObjectTypeFromId(int type) {
|
||||
return Entity1_10Types.getTypeFromId(type, true);
|
||||
}
|
||||
}
|
||||
|
@ -249,17 +249,7 @@ public class EntityPackets {
|
||||
|
||||
|
||||
// Update Entity NBT
|
||||
protocol.registerOutgoing(State.PLAY, 0x49, 0x49, new PacketRemapper() {
|
||||
@Override
|
||||
public void registerMap() {
|
||||
handler(new PacketHandler() {
|
||||
@Override
|
||||
public void handle(PacketWrapper wrapper) throws Exception {
|
||||
wrapper.cancel();
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
protocol.cancelOutgoing(State.PLAY, 0x49, 0x49);
|
||||
|
||||
// Combat Event Packet
|
||||
protocol.registerOutgoing(State.PLAY, 0x42, 0x2C, new PacketRemapper() {
|
||||
|
@ -402,17 +402,7 @@ public class PlayerPackets {
|
||||
/* Removed packets */
|
||||
|
||||
// Set Compression
|
||||
protocol.registerOutgoing(State.PLAY, 0x46, 0x46, new PacketRemapper() {
|
||||
@Override
|
||||
public void registerMap() {
|
||||
handler(new PacketHandler() {
|
||||
@Override
|
||||
public void handle(PacketWrapper wrapper) throws Exception {
|
||||
wrapper.cancel();
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
protocol.cancelOutgoing(State.PLAY, 0x46, 0x46);
|
||||
|
||||
/* Packets which do not have any field remapping or handlers */
|
||||
|
||||
@ -482,43 +472,13 @@ public class PlayerPackets {
|
||||
});
|
||||
|
||||
// TP Confirm
|
||||
protocol.registerIncoming(State.PLAY, -1, 0x00, new PacketRemapper() {
|
||||
@Override
|
||||
public void registerMap() {
|
||||
handler(new PacketHandler() {
|
||||
@Override
|
||||
public void handle(PacketWrapper wrapper) throws Exception {
|
||||
wrapper.cancel();
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
protocol.cancelIncoming(State.PLAY, 0x00);
|
||||
|
||||
// Vehicle Move
|
||||
protocol.registerIncoming(State.PLAY, -1, 0x10, new PacketRemapper() {
|
||||
@Override
|
||||
public void registerMap() {
|
||||
handler(new PacketHandler() {
|
||||
@Override
|
||||
public void handle(PacketWrapper wrapper) throws Exception {
|
||||
wrapper.cancel();
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
protocol.cancelIncoming(State.PLAY, 0x10);
|
||||
|
||||
// Steer Boat
|
||||
protocol.registerIncoming(State.PLAY, -1, 0x11, new PacketRemapper() {
|
||||
@Override
|
||||
public void registerMap() {
|
||||
handler(new PacketHandler() {
|
||||
@Override
|
||||
public void handle(PacketWrapper wrapper) throws Exception {
|
||||
wrapper.cancel();
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
protocol.cancelIncoming(State.PLAY, 0x11);
|
||||
|
||||
// Packet Plugin Message Incoming
|
||||
protocol.registerIncoming(State.PLAY, 0x17, 0x09, new PacketRemapper() {
|
||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren