mirror of
https://github.com/ViaVersion/ViaVersion.git
synced 2024-11-25 03:25:11 +01:00
Flatten some PacketHandlers in rewriters
This commit is contained in:
parent
3caaed00dc
commit
d60a37f7e6
@ -20,7 +20,6 @@ package com.viaversion.viaversion.protocols.template;
|
|||||||
import com.viaversion.viaversion.api.minecraft.RegistryEntry;
|
import com.viaversion.viaversion.api.minecraft.RegistryEntry;
|
||||||
import com.viaversion.viaversion.api.minecraft.entities.EntityType;
|
import com.viaversion.viaversion.api.minecraft.entities.EntityType;
|
||||||
import com.viaversion.viaversion.api.minecraft.entities.EntityTypes1_20_5;
|
import com.viaversion.viaversion.api.minecraft.entities.EntityTypes1_20_5;
|
||||||
import com.viaversion.viaversion.api.protocol.remapper.PacketHandlers;
|
|
||||||
import com.viaversion.viaversion.api.type.Types;
|
import com.viaversion.viaversion.api.type.Types;
|
||||||
import com.viaversion.viaversion.api.type.types.version.Types1_21;
|
import com.viaversion.viaversion.api.type.types.version.Types1_21;
|
||||||
import com.viaversion.viaversion.protocols.v1_20_5to1_21.packet.ClientboundConfigurationPackets1_21;
|
import com.viaversion.viaversion.protocols.v1_20_5to1_21.packet.ClientboundConfigurationPackets1_21;
|
||||||
@ -51,23 +50,22 @@ final class EntityPacketRewriter1_99 extends EntityRewriter<ClientboundPacket1_2
|
|||||||
handleRegistryData1_20_5(wrapper.user(), registryKey, entries); // Caches dimensions to access data like height later and tracks the amount of biomes sent for chunk data
|
handleRegistryData1_20_5(wrapper.user(), registryKey, entries); // Caches dimensions to access data like height later and tracks the amount of biomes sent for chunk data
|
||||||
});
|
});
|
||||||
|
|
||||||
protocol.registerClientbound(ClientboundPackets1_21.LOGIN, new PacketHandlers() {
|
protocol.registerClientbound(ClientboundPackets1_21.LOGIN, wrapper -> {
|
||||||
@Override
|
final int entityId = wrapper.passthrough(Types.INT); // Entity id
|
||||||
public void register() {
|
wrapper.passthrough(Types.BOOLEAN); // Hardcore
|
||||||
map(Types.INT); // Entity id
|
wrapper.passthrough(Types.STRING_ARRAY); // World List
|
||||||
map(Types.BOOLEAN); // Hardcore
|
wrapper.passthrough(Types.VAR_INT); // Max players
|
||||||
map(Types.STRING_ARRAY); // World List
|
wrapper.passthrough(Types.VAR_INT); // View distance
|
||||||
map(Types.VAR_INT); // Max players
|
wrapper.passthrough(Types.VAR_INT); // Simulation distance
|
||||||
map(Types.VAR_INT); // View distance
|
wrapper.passthrough(Types.BOOLEAN); // Reduced debug info
|
||||||
map(Types.VAR_INT); // Simulation distance
|
wrapper.passthrough(Types.BOOLEAN); // Show death screen
|
||||||
map(Types.BOOLEAN); // Reduced debug info
|
wrapper.passthrough(Types.BOOLEAN); // Limited crafting
|
||||||
map(Types.BOOLEAN); // Show death screen
|
|
||||||
map(Types.BOOLEAN); // Limited crafting
|
final int dimensionId = wrapper.passthrough(Types.VAR_INT);
|
||||||
map(Types.VAR_INT); // Dimension id
|
final String world = wrapper.passthrough(Types.STRING);
|
||||||
map(Types.STRING); // World
|
trackWorldDataByKey1_20_5(wrapper.user(), dimensionId, world);
|
||||||
handler(worldDataTrackerHandlerByKey1_20_5(3)); // Tracks world height and name for chunk data and entity (un)tracking
|
|
||||||
handler(playerTrackerHandler());
|
trackPlayer(wrapper.user(), entityId);
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
protocol.registerClientbound(ClientboundPackets1_21.RESPAWN, wrapper -> {
|
protocol.registerClientbound(ClientboundPackets1_21.RESPAWN, wrapper -> {
|
||||||
|
@ -35,7 +35,6 @@ import com.viaversion.viaversion.api.protocol.Protocol;
|
|||||||
import com.viaversion.viaversion.api.protocol.packet.ClientboundPacketType;
|
import com.viaversion.viaversion.api.protocol.packet.ClientboundPacketType;
|
||||||
import com.viaversion.viaversion.api.protocol.packet.PacketWrapper;
|
import com.viaversion.viaversion.api.protocol.packet.PacketWrapper;
|
||||||
import com.viaversion.viaversion.api.protocol.remapper.PacketHandler;
|
import com.viaversion.viaversion.api.protocol.remapper.PacketHandler;
|
||||||
import com.viaversion.viaversion.api.protocol.remapper.PacketHandlers;
|
|
||||||
import com.viaversion.viaversion.api.type.Type;
|
import com.viaversion.viaversion.api.type.Type;
|
||||||
import com.viaversion.viaversion.api.type.Types;
|
import com.viaversion.viaversion.api.type.Types;
|
||||||
import com.viaversion.viaversion.util.MathUtil;
|
import com.viaversion.viaversion.util.MathUtil;
|
||||||
@ -68,83 +67,61 @@ public class BlockRewriter<C extends ClientboundPacketType> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void registerBlockEvent(C packetType) {
|
public void registerBlockEvent(C packetType) {
|
||||||
protocol.registerClientbound(packetType, new PacketHandlers() {
|
if (protocol.getMappingData().getBlockMappings() == null) {
|
||||||
@Override
|
return;
|
||||||
public void register() {
|
}
|
||||||
map(positionType); // Location
|
|
||||||
map(Types.UNSIGNED_BYTE); // Action id
|
|
||||||
map(Types.UNSIGNED_BYTE); // Action param
|
|
||||||
map(Types.VAR_INT); // Block id - /!\ NOT BLOCK STATE
|
|
||||||
handler(wrapper -> {
|
|
||||||
if (protocol.getMappingData().getBlockMappings() == null) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
int id = wrapper.get(Types.VAR_INT, 0);
|
protocol.registerClientbound(packetType, wrapper -> {
|
||||||
int mappedId = protocol.getMappingData().getNewBlockId(id);
|
wrapper.passthrough(positionType); // Location
|
||||||
if (mappedId == -1) {
|
wrapper.passthrough(Types.UNSIGNED_BYTE); // Action id
|
||||||
// Block (action) has been removed
|
wrapper.passthrough(Types.UNSIGNED_BYTE); // Action param
|
||||||
wrapper.cancel();
|
final int blockId = wrapper.passthrough(Types.VAR_INT);
|
||||||
return;
|
final int mappedId = protocol.getMappingData().getNewBlockId(blockId);
|
||||||
}
|
if (mappedId == -1) {
|
||||||
|
wrapper.cancel();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
wrapper.set(Types.VAR_INT, 0, mappedId);
|
if (blockId != mappedId) {
|
||||||
});
|
wrapper.set(Types.VAR_INT, 0, mappedId);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public void registerBlockUpdate(C packetType) {
|
public void registerBlockUpdate(C packetType) {
|
||||||
protocol.registerClientbound(packetType, new PacketHandlers() {
|
protocol.registerClientbound(packetType, wrapper -> {
|
||||||
@Override
|
wrapper.passthrough(positionType);
|
||||||
public void register() {
|
|
||||||
map(positionType);
|
final int blockId = wrapper.read(Types.VAR_INT);
|
||||||
map(Types.VAR_INT);
|
wrapper.write(Types.VAR_INT, protocol.getMappingData().getNewBlockStateId(blockId));
|
||||||
handler(wrapper -> wrapper.set(Types.VAR_INT, 0, protocol.getMappingData().getNewBlockStateId(wrapper.get(Types.VAR_INT, 0))));
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public void registerChunkBlocksUpdate(C packetType) {
|
public void registerChunkBlocksUpdate(C packetType) {
|
||||||
protocol.registerClientbound(packetType, new PacketHandlers() {
|
protocol.registerClientbound(packetType, wrapper -> {
|
||||||
@Override
|
wrapper.passthrough(Types.INT); // Chunk X
|
||||||
public void register() {
|
wrapper.passthrough(Types.INT); // Chunk Z
|
||||||
map(Types.INT); // 0 - Chunk X
|
for (BlockChangeRecord record : wrapper.passthrough(Types.BLOCK_CHANGE_ARRAY)) {
|
||||||
map(Types.INT); // 1 - Chunk Z
|
record.setBlockId(protocol.getMappingData().getNewBlockStateId(record.getBlockId()));
|
||||||
handler(wrapper -> {
|
|
||||||
for (BlockChangeRecord record : wrapper.passthrough(Types.BLOCK_CHANGE_ARRAY)) {
|
|
||||||
record.setBlockId(protocol.getMappingData().getNewBlockStateId(record.getBlockId()));
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public void registerSectionBlocksUpdate(C packetType) {
|
public void registerSectionBlocksUpdate(C packetType) {
|
||||||
protocol.registerClientbound(packetType, new PacketHandlers() {
|
protocol.registerClientbound(packetType, wrapper -> {
|
||||||
@Override
|
wrapper.passthrough(Types.LONG); // Chunk position
|
||||||
public void register() {
|
wrapper.passthrough(Types.BOOLEAN); // Suppress light updates
|
||||||
map(Types.LONG); // Chunk position
|
for (BlockChangeRecord record : wrapper.passthrough(Types.VAR_LONG_BLOCK_CHANGE_ARRAY)) {
|
||||||
map(Types.BOOLEAN); // Suppress light updates
|
record.setBlockId(protocol.getMappingData().getNewBlockStateId(record.getBlockId()));
|
||||||
handler(wrapper -> {
|
|
||||||
for (BlockChangeRecord record : wrapper.passthrough(Types.VAR_LONG_BLOCK_CHANGE_ARRAY)) {
|
|
||||||
record.setBlockId(protocol.getMappingData().getNewBlockStateId(record.getBlockId()));
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public void registerSectionBlocksUpdate1_20(C packetType) {
|
public void registerSectionBlocksUpdate1_20(C packetType) {
|
||||||
protocol.registerClientbound(packetType, new PacketHandlers() {
|
protocol.registerClientbound(packetType, wrapper -> {
|
||||||
@Override
|
wrapper.passthrough(Types.LONG); // Chunk position
|
||||||
public void register() {
|
for (BlockChangeRecord record : wrapper.passthrough(Types.VAR_LONG_BLOCK_CHANGE_ARRAY)) {
|
||||||
map(Types.LONG); // Chunk position
|
record.setBlockId(protocol.getMappingData().getNewBlockStateId(record.getBlockId()));
|
||||||
handler(wrapper -> {
|
|
||||||
for (BlockChangeRecord record : wrapper.passthrough(Types.VAR_LONG_BLOCK_CHANGE_ARRAY)) {
|
|
||||||
record.setBlockId(protocol.getMappingData().getNewBlockStateId(record.getBlockId()));
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -33,7 +33,6 @@ import com.viaversion.viaversion.api.protocol.Protocol;
|
|||||||
import com.viaversion.viaversion.api.protocol.packet.ClientboundPacketType;
|
import com.viaversion.viaversion.api.protocol.packet.ClientboundPacketType;
|
||||||
import com.viaversion.viaversion.api.protocol.packet.PacketWrapper;
|
import com.viaversion.viaversion.api.protocol.packet.PacketWrapper;
|
||||||
import com.viaversion.viaversion.api.protocol.packet.State;
|
import com.viaversion.viaversion.api.protocol.packet.State;
|
||||||
import com.viaversion.viaversion.api.protocol.remapper.PacketHandlers;
|
|
||||||
import com.viaversion.viaversion.api.type.Types;
|
import com.viaversion.viaversion.api.type.Types;
|
||||||
import com.viaversion.viaversion.protocols.base.ClientboundLoginPackets;
|
import com.viaversion.viaversion.protocols.base.ClientboundLoginPackets;
|
||||||
import com.viaversion.viaversion.util.ComponentUtil;
|
import com.viaversion.viaversion.util.ComponentUtil;
|
||||||
@ -66,17 +65,11 @@ public class ComponentRewriter<C extends ClientboundPacketType> implements com.v
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void registerBossEvent(final C packetType) {
|
public void registerBossEvent(final C packetType) {
|
||||||
protocol.registerClientbound(packetType, new PacketHandlers() {
|
protocol.registerClientbound(packetType, wrapper -> {
|
||||||
@Override
|
wrapper.passthrough(Types.UUID);
|
||||||
public void register() {
|
final int action = wrapper.passthrough(Types.VAR_INT);
|
||||||
map(Types.UUID);
|
if (action == 0 || action == 3) {
|
||||||
map(Types.VAR_INT);
|
passthroughAndProcess(wrapper);
|
||||||
handler(wrapper -> {
|
|
||||||
final int action = wrapper.get(Types.VAR_INT, 0);
|
|
||||||
if (action == 0 || action == 3) {
|
|
||||||
passthroughAndProcess(wrapper);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -112,24 +105,18 @@ public class ComponentRewriter<C extends ClientboundPacketType> implements com.v
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void registerLegacyOpenWindow(final C packetType) {
|
public void registerLegacyOpenWindow(final C packetType) {
|
||||||
protocol.registerClientbound(packetType, new PacketHandlers() {
|
protocol.registerClientbound(packetType, wrapper -> {
|
||||||
@Override
|
wrapper.passthrough(Types.UNSIGNED_BYTE); // Id
|
||||||
public void register() {
|
wrapper.passthrough(Types.STRING); // Window Type
|
||||||
map(Types.UNSIGNED_BYTE); // Id
|
processText(wrapper.user(), wrapper.passthrough(Types.COMPONENT));
|
||||||
map(Types.STRING); // Window Type
|
|
||||||
handler(wrapper -> processText(wrapper.user(), wrapper.passthrough(Types.COMPONENT)));
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public void registerOpenScreen(final C packetType) {
|
public void registerOpenScreen(final C packetType) {
|
||||||
protocol.registerClientbound(packetType, new PacketHandlers() {
|
protocol.registerClientbound(packetType, wrapper -> {
|
||||||
@Override
|
wrapper.passthrough(Types.VAR_INT); // Id
|
||||||
public void register() {
|
wrapper.passthrough(Types.VAR_INT); // Window Type
|
||||||
map(Types.VAR_INT); // Id
|
passthroughAndProcess(wrapper);
|
||||||
map(Types.VAR_INT); // Window Type
|
|
||||||
handler(wrapper -> passthroughAndProcess(wrapper));
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -222,23 +209,17 @@ public class ComponentRewriter<C extends ClientboundPacketType> implements com.v
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void registerPlayerCombatKill(final C packetType) {
|
public void registerPlayerCombatKill(final C packetType) {
|
||||||
protocol.registerClientbound(packetType, new PacketHandlers() {
|
protocol.registerClientbound(packetType, wrapper -> {
|
||||||
@Override
|
wrapper.passthrough(Types.VAR_INT); // Player ID
|
||||||
public void register() {
|
wrapper.passthrough(Types.INT); // Killer ID
|
||||||
map(Types.VAR_INT); // Player ID
|
processText(wrapper.user(), wrapper.passthrough(Types.COMPONENT));
|
||||||
map(Types.INT); // Killer ID
|
|
||||||
handler(wrapper -> processText(wrapper.user(), wrapper.passthrough(Types.COMPONENT)));
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public void registerPlayerCombatKill1_20(final C packetType) {
|
public void registerPlayerCombatKill1_20(final C packetType) {
|
||||||
protocol.registerClientbound(packetType, new PacketHandlers() {
|
protocol.registerClientbound(packetType, wrapper -> {
|
||||||
@Override
|
wrapper.passthrough(Types.VAR_INT); // Player ID
|
||||||
public void register() {
|
passthroughAndProcess(wrapper);
|
||||||
map(Types.VAR_INT); // Player ID
|
|
||||||
handler(wrapper -> passthroughAndProcess(wrapper));
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -38,6 +38,7 @@ import com.viaversion.viaversion.api.minecraft.entitydata.EntityData;
|
|||||||
import com.viaversion.viaversion.api.minecraft.entitydata.EntityDataType;
|
import com.viaversion.viaversion.api.minecraft.entitydata.EntityDataType;
|
||||||
import com.viaversion.viaversion.api.protocol.Protocol;
|
import com.viaversion.viaversion.api.protocol.Protocol;
|
||||||
import com.viaversion.viaversion.api.protocol.packet.ClientboundPacketType;
|
import com.viaversion.viaversion.api.protocol.packet.ClientboundPacketType;
|
||||||
|
import com.viaversion.viaversion.api.protocol.packet.PacketWrapper;
|
||||||
import com.viaversion.viaversion.api.protocol.remapper.PacketHandler;
|
import com.viaversion.viaversion.api.protocol.remapper.PacketHandler;
|
||||||
import com.viaversion.viaversion.api.protocol.remapper.PacketHandlers;
|
import com.viaversion.viaversion.api.protocol.remapper.PacketHandlers;
|
||||||
import com.viaversion.viaversion.api.rewriter.RewriterBase;
|
import com.viaversion.viaversion.api.rewriter.RewriterBase;
|
||||||
@ -260,14 +261,11 @@ public abstract class EntityRewriter<C extends ClientboundPacketType, T extends
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void registerTracker(C packetType) {
|
public void registerTracker(C packetType) {
|
||||||
protocol.registerClientbound(packetType, new PacketHandlers() {
|
protocol.registerClientbound(packetType, wrapper -> {
|
||||||
@Override
|
wrapper.passthrough(Types.VAR_INT); // Entity ID
|
||||||
public void register() {
|
wrapper.passthrough(Types.UUID); // Entity UUID
|
||||||
map(Types.VAR_INT); // 0 - Entity ID
|
wrapper.passthrough(Types.VAR_INT); // Entity Type
|
||||||
map(Types.UUID); // 1 - Entity UUID
|
trackerHandler().handle(wrapper);
|
||||||
map(Types.VAR_INT); // 2 - Entity Type
|
|
||||||
handler(trackerHandler());
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -275,15 +273,15 @@ public abstract class EntityRewriter<C extends ClientboundPacketType, T extends
|
|||||||
protocol.registerClientbound(packetType, new PacketHandlers() {
|
protocol.registerClientbound(packetType, new PacketHandlers() {
|
||||||
@Override
|
@Override
|
||||||
public void register() {
|
public void register() {
|
||||||
map(Types.VAR_INT); // 0 - Entity id
|
map(Types.VAR_INT); // Entity id
|
||||||
map(Types.UUID); // 1 - Entity UUID
|
map(Types.UUID); // Entity UUID
|
||||||
map(Types.VAR_INT); // 2 - Entity Type
|
map(Types.VAR_INT); // Entity Type
|
||||||
map(Types.DOUBLE); // 3 - X
|
map(Types.DOUBLE); // X
|
||||||
map(Types.DOUBLE); // 4 - Y
|
map(Types.DOUBLE); // Y
|
||||||
map(Types.DOUBLE); // 5 - Z
|
map(Types.DOUBLE); // Z
|
||||||
map(Types.BYTE); // 6 - Pitch
|
map(Types.BYTE); // Pitch
|
||||||
map(Types.BYTE); // 7 - Yaw
|
map(Types.BYTE); // Yaw
|
||||||
map(Types.INT); // 8 - Data
|
map(Types.INT); // Data
|
||||||
handler(trackerHandler());
|
handler(trackerHandler());
|
||||||
handler(wrapper -> {
|
handler(wrapper -> {
|
||||||
int entityId = wrapper.get(Types.VAR_INT, 0);
|
int entityId = wrapper.get(Types.VAR_INT, 0);
|
||||||
@ -297,31 +295,22 @@ public abstract class EntityRewriter<C extends ClientboundPacketType, T extends
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void registerTrackerWithData1_19(C packetType, EntityType fallingBlockType) {
|
public void registerTrackerWithData1_19(C packetType, EntityType fallingBlockType) {
|
||||||
protocol.registerClientbound(packetType, new PacketHandlers() {
|
protocol.registerClientbound(packetType, wrapper -> {
|
||||||
@Override
|
final int entityId = wrapper.passthrough(Types.VAR_INT);
|
||||||
public void register() {
|
wrapper.passthrough(Types.UUID); // Entity UUID
|
||||||
map(Types.VAR_INT); // Entity id
|
final int entityTypeId = wrapper.passthrough(Types.VAR_INT);
|
||||||
map(Types.UUID); // Entity UUID
|
wrapper.passthrough(Types.DOUBLE); // X
|
||||||
map(Types.VAR_INT); // Entity type
|
wrapper.passthrough(Types.DOUBLE); // Y
|
||||||
map(Types.DOUBLE); // X
|
wrapper.passthrough(Types.DOUBLE); // Z
|
||||||
map(Types.DOUBLE); // Y
|
wrapper.passthrough(Types.BYTE); // Pitch
|
||||||
map(Types.DOUBLE); // Z
|
wrapper.passthrough(Types.BYTE); // Yaw
|
||||||
map(Types.BYTE); // Pitch
|
wrapper.passthrough(Types.BYTE); // Head yaw
|
||||||
map(Types.BYTE); // Yaw
|
final int data = wrapper.passthrough(Types.VAR_INT);
|
||||||
map(Types.BYTE); // Head yaw
|
|
||||||
map(Types.VAR_INT); // Data
|
|
||||||
handler(trackerHandler());
|
|
||||||
handler(wrapper -> {
|
|
||||||
if (protocol.getMappingData() == null) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
int entityId = wrapper.get(Types.VAR_INT, 0);
|
final EntityType entityType = trackAndRewrite(wrapper, entityTypeId, entityId);
|
||||||
EntityType entityType = tracker(wrapper.user()).entityType(entityId);
|
if (protocol.getMappingData() != null && entityType == fallingBlockType) {
|
||||||
if (entityType == fallingBlockType) {
|
final int mappedBlockStateId = protocol.getMappingData().getNewBlockStateId(data);
|
||||||
wrapper.set(Types.VAR_INT, 2, protocol.getMappingData().getNewBlockStateId(wrapper.get(Types.VAR_INT, 2)));
|
wrapper.set(Types.VAR_INT, 2, mappedBlockStateId);
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -388,12 +377,13 @@ public abstract class EntityRewriter<C extends ClientboundPacketType, T extends
|
|||||||
}
|
}
|
||||||
|
|
||||||
public PacketHandler playerTrackerHandler() {
|
public PacketHandler playerTrackerHandler() {
|
||||||
return wrapper -> {
|
return wrapper -> trackPlayer(wrapper.user(), wrapper.get(Types.INT, 0));
|
||||||
final EntityTracker tracker = tracker(wrapper.user());
|
}
|
||||||
final int entityId = wrapper.get(Types.INT, 0);
|
|
||||||
tracker.setClientEntityId(entityId);
|
public void trackPlayer(final UserConnection connection, final int entityId) {
|
||||||
tracker.addEntity(entityId, tracker.playerType());
|
final EntityTracker tracker = tracker(connection);
|
||||||
};
|
tracker.setClientEntityId(entityId);
|
||||||
|
tracker.addEntity(entityId, tracker.playerType());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -533,6 +523,17 @@ public abstract class EntityRewriter<C extends ClientboundPacketType, T extends
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public EntityType trackAndRewrite(final PacketWrapper wrapper, final int typeId, final int entityId) {
|
||||||
|
final int mappedTypeId = newEntityId(typeId);
|
||||||
|
if (mappedTypeId != typeId) {
|
||||||
|
wrapper.set(Types.VAR_INT, 1, mappedTypeId);
|
||||||
|
}
|
||||||
|
|
||||||
|
final EntityType entityType = typeFromId(trackMappedType ? mappedTypeId : typeId);
|
||||||
|
tracker(wrapper.user()).addEntity(entityId, entityType);
|
||||||
|
return entityType;
|
||||||
|
}
|
||||||
|
|
||||||
// ---------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------
|
||||||
// Sub 1.14.1 methods
|
// Sub 1.14.1 methods
|
||||||
|
|
||||||
@ -546,16 +547,7 @@ public abstract class EntityRewriter<C extends ClientboundPacketType, T extends
|
|||||||
return wrapper -> {
|
return wrapper -> {
|
||||||
int entityId = wrapper.get(Types.VAR_INT, 0);
|
int entityId = wrapper.get(Types.VAR_INT, 0);
|
||||||
int type = wrapper.get(Types.VAR_INT, 1);
|
int type = wrapper.get(Types.VAR_INT, 1);
|
||||||
|
trackAndRewrite(wrapper, type, entityId);
|
||||||
int newType = newEntityId(type);
|
|
||||||
if (newType != type) {
|
|
||||||
wrapper.set(Types.VAR_INT, 1, newType);
|
|
||||||
}
|
|
||||||
|
|
||||||
EntityType entType = typeFromId(trackMappedType ? newType : type);
|
|
||||||
// Register Type ID
|
|
||||||
tracker(wrapper.user()).addEntity(entityId, entType);
|
|
||||||
|
|
||||||
if (dataType != null) {
|
if (dataType != null) {
|
||||||
handleEntityData(entityId, wrapper.get(dataType, 0), wrapper.user());
|
handleEntityData(entityId, wrapper.get(dataType, 0), wrapper.user());
|
||||||
}
|
}
|
||||||
|
@ -145,13 +145,10 @@ public class ItemRewriter<C extends ClientboundPacketType, S extends Serverbound
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void registerSetSlot(C packetType) {
|
public void registerSetSlot(C packetType) {
|
||||||
protocol.registerClientbound(packetType, new PacketHandlers() {
|
protocol.registerClientbound(packetType, wrapper -> {
|
||||||
@Override
|
wrapper.passthrough(Types.UNSIGNED_BYTE); // Container id
|
||||||
public void register() {
|
wrapper.passthrough(Types.SHORT); // Slot id
|
||||||
map(Types.UNSIGNED_BYTE); // Container id
|
passthroughClientboundItem(wrapper);
|
||||||
map(Types.SHORT); // Slot id
|
|
||||||
handler(wrapper -> passthroughClientboundItem(wrapper));
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -174,56 +171,42 @@ public class ItemRewriter<C extends ClientboundPacketType, S extends Serverbound
|
|||||||
|
|
||||||
// Sub 1.16
|
// Sub 1.16
|
||||||
public void registerSetEquippedItem(C packetType) {
|
public void registerSetEquippedItem(C packetType) {
|
||||||
protocol.registerClientbound(packetType, new PacketHandlers() {
|
protocol.registerClientbound(packetType, wrapper -> {
|
||||||
@Override
|
wrapper.passthrough(Types.VAR_INT); // Entity ID
|
||||||
public void register() {
|
wrapper.passthrough(Types.VAR_INT); // Slot ID
|
||||||
map(Types.VAR_INT); // Entity ID
|
passthroughClientboundItem(wrapper);
|
||||||
map(Types.VAR_INT); // Slot ID
|
|
||||||
handler(wrapper -> passthroughClientboundItem(wrapper));
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// 1.16+
|
// 1.16+
|
||||||
public void registerSetEquipment(C packetType) {
|
public void registerSetEquipment(C packetType) {
|
||||||
protocol.registerClientbound(packetType, new PacketHandlers() {
|
protocol.registerClientbound(packetType, wrapper -> {
|
||||||
@Override
|
wrapper.passthrough(Types.VAR_INT); // Entity ID
|
||||||
public void register() {
|
|
||||||
map(Types.VAR_INT); // 0 - Entity ID
|
|
||||||
|
|
||||||
handler(wrapper -> {
|
byte slot;
|
||||||
byte slot;
|
do {
|
||||||
do {
|
slot = wrapper.passthrough(Types.BYTE);
|
||||||
slot = wrapper.passthrough(Types.BYTE);
|
// & 0x7F into an extra variable if slot is needed
|
||||||
// & 0x7F into an extra variable if slot is needed
|
passthroughClientboundItem(wrapper);
|
||||||
passthroughClientboundItem(wrapper);
|
} while (slot < 0);
|
||||||
} while (slot < 0);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public void registerSetCreativeModeSlot(S packetType) {
|
public void registerSetCreativeModeSlot(S packetType) {
|
||||||
protocol.registerServerbound(packetType, new PacketHandlers() {
|
protocol.registerServerbound(packetType, wrapper -> {
|
||||||
@Override
|
wrapper.passthrough(Types.SHORT); // Slot
|
||||||
public void register() {
|
passthroughServerboundItem(wrapper);
|
||||||
map(Types.SHORT); // 0 - Slot
|
|
||||||
handler(wrapper -> passthroughServerboundItem(wrapper));
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public void registerContainerClick(S packetType) {
|
public void registerContainerClick(S packetType) {
|
||||||
protocol.registerServerbound(packetType, new PacketHandlers() {
|
protocol.registerServerbound(packetType, wrapper -> {
|
||||||
@Override
|
wrapper.passthrough(Types.UNSIGNED_BYTE); // Container ID
|
||||||
public void register() {
|
wrapper.passthrough(Types.SHORT); // Slot
|
||||||
map(Types.UNSIGNED_BYTE); // 0 - Container ID
|
wrapper.passthrough(Types.BYTE); // Button
|
||||||
map(Types.SHORT); // 1 - Slot
|
wrapper.passthrough(Types.SHORT); // Action number
|
||||||
map(Types.BYTE); // 2 - Button
|
wrapper.passthrough(Types.VAR_INT); // Mode
|
||||||
map(Types.SHORT); // 3 - Action number
|
passthroughServerboundItem(wrapper);
|
||||||
map(Types.VAR_INT); // 4 - Mode
|
|
||||||
handler(wrapper -> passthroughServerboundItem(wrapper));
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -460,22 +443,18 @@ public class ItemRewriter<C extends ClientboundPacketType, S extends Serverbound
|
|||||||
|
|
||||||
// Pre 1.21 for enchantments
|
// Pre 1.21 for enchantments
|
||||||
public void registerContainerSetData(C packetType) {
|
public void registerContainerSetData(C packetType) {
|
||||||
protocol.registerClientbound(packetType, new PacketHandlers() {
|
protocol.registerClientbound(packetType, wrapper -> {
|
||||||
@Override
|
wrapper.passthrough(Types.UNSIGNED_BYTE); // Container id
|
||||||
public void register() {
|
|
||||||
map(Types.UNSIGNED_BYTE); // Container id
|
|
||||||
handler(wrapper -> {
|
|
||||||
Mappings mappings = protocol.getMappingData().getEnchantmentMappings();
|
|
||||||
if (mappings == null) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
short property = wrapper.passthrough(Types.SHORT);
|
Mappings mappings = protocol.getMappingData().getEnchantmentMappings();
|
||||||
if (property >= 4 && property <= 6) { // Enchantment id
|
if (mappings == null) {
|
||||||
short enchantmentId = (short) mappings.getNewId(wrapper.read(Types.SHORT));
|
return;
|
||||||
wrapper.write(Types.SHORT, enchantmentId);
|
}
|
||||||
}
|
|
||||||
});
|
short property = wrapper.passthrough(Types.SHORT);
|
||||||
|
if (property >= 4 && property <= 6) { // Enchantment id
|
||||||
|
short enchantmentId = (short) mappings.getNewId(wrapper.read(Types.SHORT));
|
||||||
|
wrapper.write(Types.SHORT, enchantmentId);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -22,7 +22,6 @@ import com.viaversion.viaversion.api.minecraft.SoundEvent;
|
|||||||
import com.viaversion.viaversion.api.protocol.Protocol;
|
import com.viaversion.viaversion.api.protocol.Protocol;
|
||||||
import com.viaversion.viaversion.api.protocol.packet.ClientboundPacketType;
|
import com.viaversion.viaversion.api.protocol.packet.ClientboundPacketType;
|
||||||
import com.viaversion.viaversion.api.protocol.remapper.PacketHandler;
|
import com.viaversion.viaversion.api.protocol.remapper.PacketHandler;
|
||||||
import com.viaversion.viaversion.api.protocol.remapper.PacketHandlers;
|
|
||||||
import com.viaversion.viaversion.api.type.Types;
|
import com.viaversion.viaversion.api.type.Types;
|
||||||
|
|
||||||
public class SoundRewriter<C extends ClientboundPacketType> {
|
public class SoundRewriter<C extends ClientboundPacketType> {
|
||||||
@ -40,12 +39,9 @@ public class SoundRewriter<C extends ClientboundPacketType> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void registerSound(C packetType) {
|
public void registerSound(C packetType) {
|
||||||
protocol.registerClientbound(packetType, new PacketHandlers() {
|
protocol.registerClientbound(packetType, wrapper -> {
|
||||||
@Override
|
wrapper.passthrough(Types.VAR_INT); // Sound id
|
||||||
public void register() {
|
getSoundHandler().handle(wrapper);
|
||||||
map(Types.VAR_INT); // Sound id
|
|
||||||
handler(getSoundHandler());
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user