use of com.viaversion.viaversion.api.protocol.packet.PacketWrapper in project ViaBackwards by ViaVersion.
the class Protocol1_14_4To1_15 method registerPackets.
@Override
protected void registerPackets() {
executeAsyncAfterLoaded(Protocol1_15To1_14_4.class, MAPPINGS::load);
translatableRewriter.registerBossBar(ClientboundPackets1_15.BOSSBAR);
translatableRewriter.registerChatMessage(ClientboundPackets1_15.CHAT_MESSAGE);
translatableRewriter.registerCombatEvent(ClientboundPackets1_15.COMBAT_EVENT);
translatableRewriter.registerDisconnect(ClientboundPackets1_15.DISCONNECT);
translatableRewriter.registerOpenWindow(ClientboundPackets1_15.OPEN_WINDOW);
translatableRewriter.registerTabList(ClientboundPackets1_15.TAB_LIST);
translatableRewriter.registerTitle(ClientboundPackets1_15.TITLE);
translatableRewriter.registerPing();
(blockItemPackets = new BlockItemPackets1_15(this)).register();
entityRewriter.register();
SoundRewriter soundRewriter = new SoundRewriter(this);
soundRewriter.registerSound(ClientboundPackets1_15.SOUND);
soundRewriter.registerSound(ClientboundPackets1_15.ENTITY_SOUND);
soundRewriter.registerNamedSound(ClientboundPackets1_15.NAMED_SOUND);
soundRewriter.registerStopSound(ClientboundPackets1_15.STOP_SOUND);
// Explosion - manually send an explosion sound
registerClientbound(ClientboundPackets1_15.EXPLOSION, new PacketRemapper() {
@Override
public void registerMap() {
// x
map(Type.FLOAT);
// y
map(Type.FLOAT);
// z
map(Type.FLOAT);
handler(wrapper -> {
PacketWrapper soundPacket = wrapper.create(ClientboundPackets1_14.SOUND);
// entity.generic.explode
soundPacket.write(Type.VAR_INT, 243);
// blocks category
soundPacket.write(Type.VAR_INT, 4);
// x
soundPacket.write(Type.INT, toEffectCoordinate(wrapper.get(Type.FLOAT, 0)));
// y
soundPacket.write(Type.INT, toEffectCoordinate(wrapper.get(Type.FLOAT, 1)));
// z
soundPacket.write(Type.INT, toEffectCoordinate(wrapper.get(Type.FLOAT, 2)));
// volume
soundPacket.write(Type.FLOAT, 4F);
// pitch - usually semi randomized by the server, but we don't really have to care about that
soundPacket.write(Type.FLOAT, 1F);
soundPacket.send(Protocol1_14_4To1_15.class);
});
}
private int toEffectCoordinate(float coordinate) {
return (int) (coordinate * 8);
}
});
new TagRewriter(this).register(ClientboundPackets1_15.TAGS, RegistryType.ENTITY);
new StatisticsRewriter(this).register(ClientboundPackets1_15.STATISTICS);
}
use of com.viaversion.viaversion.api.protocol.packet.PacketWrapper in project ViaBackwards by ViaVersion.
the class Protocol1_13_2To1_14 method registerPackets.
@Override
protected void registerPackets() {
executeAsyncAfterLoaded(Protocol1_14To1_13_2.class, MAPPINGS::load);
translatableRewriter.registerBossBar(ClientboundPackets1_14.BOSSBAR);
translatableRewriter.registerChatMessage(ClientboundPackets1_14.CHAT_MESSAGE);
translatableRewriter.registerCombatEvent(ClientboundPackets1_14.COMBAT_EVENT);
translatableRewriter.registerDisconnect(ClientboundPackets1_14.DISCONNECT);
translatableRewriter.registerTabList(ClientboundPackets1_14.TAB_LIST);
translatableRewriter.registerTitle(ClientboundPackets1_14.TITLE);
translatableRewriter.registerPing();
new CommandRewriter1_14(this).registerDeclareCommands(ClientboundPackets1_14.DECLARE_COMMANDS);
blockItemPackets = new BlockItemPackets1_14(this);
blockItemPackets.register();
entityRewriter.register();
new PlayerPackets1_14(this).register();
new SoundPackets1_14(this).register();
new StatisticsRewriter(this).register(ClientboundPackets1_14.STATISTICS);
cancelClientbound(ClientboundPackets1_14.UPDATE_VIEW_POSITION);
cancelClientbound(ClientboundPackets1_14.UPDATE_VIEW_DISTANCE);
cancelClientbound(ClientboundPackets1_14.ACKNOWLEDGE_PLAYER_DIGGING);
registerClientbound(ClientboundPackets1_14.TAGS, new PacketRemapper() {
@Override
public void registerMap() {
handler(new PacketHandler() {
@Override
public void handle(PacketWrapper wrapper) throws Exception {
int blockTagsSize = wrapper.passthrough(Type.VAR_INT);
for (int i = 0; i < blockTagsSize; i++) {
wrapper.passthrough(Type.STRING);
int[] blockIds = wrapper.passthrough(Type.VAR_INT_ARRAY_PRIMITIVE);
for (int j = 0; j < blockIds.length; j++) {
int id = blockIds[j];
// Ignore new blocktags
int blockId = getMappingData().getNewBlockId(id);
blockIds[j] = blockId;
}
}
int itemTagsSize = wrapper.passthrough(Type.VAR_INT);
for (int i = 0; i < itemTagsSize; i++) {
wrapper.passthrough(Type.STRING);
int[] itemIds = wrapper.passthrough(Type.VAR_INT_ARRAY_PRIMITIVE);
for (int j = 0; j < itemIds.length; j++) {
int itemId = itemIds[j];
// Ignore new itemtags
int oldId = getMappingData().getItemMappings().get(itemId);
itemIds[j] = oldId;
}
}
// fluid tags
int fluidTagsSize = wrapper.passthrough(Type.VAR_INT);
for (int i = 0; i < fluidTagsSize; i++) {
wrapper.passthrough(Type.STRING);
wrapper.passthrough(Type.VAR_INT_ARRAY_PRIMITIVE);
}
// Eat entity tags
int entityTagsSize = wrapper.read(Type.VAR_INT);
for (int i = 0; i < entityTagsSize; i++) {
wrapper.read(Type.STRING);
wrapper.read(Type.VAR_INT_ARRAY_PRIMITIVE);
}
}
});
}
});
registerClientbound(ClientboundPackets1_14.UPDATE_LIGHT, null, new PacketRemapper() {
@Override
public void registerMap() {
handler(new PacketHandler() {
@Override
public void handle(PacketWrapper wrapper) throws Exception {
int x = wrapper.read(Type.VAR_INT);
int z = wrapper.read(Type.VAR_INT);
int skyLightMask = wrapper.read(Type.VAR_INT);
int blockLightMask = wrapper.read(Type.VAR_INT);
int emptySkyLightMask = wrapper.read(Type.VAR_INT);
int emptyBlockLightMask = wrapper.read(Type.VAR_INT);
byte[][] skyLight = new byte[16][];
// we don't need void and +256 light
if (isSet(skyLightMask, 0)) {
wrapper.read(Type.BYTE_ARRAY_PRIMITIVE);
}
for (int i = 0; i < 16; i++) {
if (isSet(skyLightMask, i + 1)) {
skyLight[i] = wrapper.read(Type.BYTE_ARRAY_PRIMITIVE);
} else if (isSet(emptySkyLightMask, i + 1)) {
skyLight[i] = ChunkLightStorage.EMPTY_LIGHT;
}
}
if (isSet(skyLightMask, 17)) {
wrapper.read(Type.BYTE_ARRAY_PRIMITIVE);
}
byte[][] blockLight = new byte[16][];
if (isSet(blockLightMask, 0)) {
wrapper.read(Type.BYTE_ARRAY_PRIMITIVE);
}
for (int i = 0; i < 16; i++) {
if (isSet(blockLightMask, i + 1)) {
blockLight[i] = wrapper.read(Type.BYTE_ARRAY_PRIMITIVE);
} else if (isSet(emptyBlockLightMask, i + 1)) {
blockLight[i] = ChunkLightStorage.EMPTY_LIGHT;
}
}
if (isSet(blockLightMask, 17)) {
wrapper.read(Type.BYTE_ARRAY_PRIMITIVE);
}
// TODO Soft memory leak: Don't store light if chunk is already loaded
wrapper.user().get(ChunkLightStorage.class).setStoredLight(skyLight, blockLight, x, z);
wrapper.cancel();
}
private boolean isSet(int mask, int i) {
return (mask & (1 << i)) != 0;
}
});
}
});
}
use of com.viaversion.viaversion.api.protocol.packet.PacketWrapper in project ViaFabric by ViaVersion.
the class AbstractFabricVersionProvider method handleMulticonnectPing.
private void handleMulticonnectPing(UserConnection connection, ProtocolInfo info, boolean blocked, int serverVer) throws Exception {
if (info.getState() == State.STATUS && info.getProtocolVersion() == -1 && isMulticonnectHandler(connection.getChannel().pipeline()) && (blocked || ProtocolUtils.isSupported(serverVer, getVersionForMulticonnect(serverVer)))) {
// Intercept the connection
int multiconnectSuggestion = blocked ? -1 : getVersionForMulticonnect(serverVer);
getLogger().info("Sending " + ProtocolVersion.getProtocol(multiconnectSuggestion) + " for multiconnect version detector");
PacketWrapper newAnswer = PacketWrapper.create(0x00, null, connection);
newAnswer.write(Type.STRING, "{\"version\":{\"name\":\"viafabric integration\",\"protocol\":" + multiconnectSuggestion + "}}");
newAnswer.send(info.getPipeline().contains(BaseProtocol1_16.class) ? BaseProtocol1_16.class : BaseProtocol1_7.class);
throw CancelException.generate();
}
}
use of com.viaversion.viaversion.api.protocol.packet.PacketWrapper in project ViaVersion by ViaVersion.
the class VelocityMovementTransmitter method sendPlayer.
public void sendPlayer(UserConnection userConnection) {
if (userConnection.getProtocolInfo().getState() == State.PLAY) {
PacketWrapper wrapper = PacketWrapper.create(ServerboundPackets1_8.PLAYER_MOVEMENT, null, userConnection);
MovementTracker tracker = userConnection.get(MovementTracker.class);
wrapper.write(Type.BOOLEAN, tracker.isGround());
try {
wrapper.scheduleSendToServer(Protocol1_9To1_8.class);
} catch (Exception e) {
e.printStackTrace();
}
tracker.incrementIdlePacket();
}
}
use of com.viaversion.viaversion.api.protocol.packet.PacketWrapper in project ViaVersion by ViaVersion.
the class EntityPackets method register.
public static void register(Protocol1_14To1_13_2 protocol) {
MetadataRewriter1_14To1_13_2 metadataRewriter = protocol.get(MetadataRewriter1_14To1_13_2.class);
protocol.registerClientbound(ClientboundPackets1_13.SPAWN_ENTITY, new PacketRemapper() {
@Override
public void registerMap() {
// 0 - Entity id
map(Type.VAR_INT);
// 1 - UUID
map(Type.UUID);
// 2 - Type
map(Type.BYTE, Type.VAR_INT);
// 3 - X
map(Type.DOUBLE);
// 4 - Y
map(Type.DOUBLE);
// 5 - Z
map(Type.DOUBLE);
// 6 - Pitch
map(Type.BYTE);
// 7 - Yaw
map(Type.BYTE);
// 8 - Data
map(Type.INT);
// 9 - Velocity X
map(Type.SHORT);
// 10 - Velocity Y
map(Type.SHORT);
// 11 - Velocity Z
map(Type.SHORT);
// Track Entity
handler(new PacketHandler() {
@Override
public void handle(PacketWrapper wrapper) throws Exception {
int entityId = wrapper.get(Type.VAR_INT, 0);
int typeId = wrapper.get(Type.VAR_INT, 1);
Entity1_13Types.EntityType type1_13 = Entity1_13Types.getTypeFromId(typeId, true);
typeId = metadataRewriter.newEntityId(type1_13.getId());
EntityType type1_14 = Entity1_14Types.getTypeFromId(typeId);
if (type1_14 != null) {
int data = wrapper.get(Type.INT, 0);
if (type1_14.is(Entity1_14Types.FALLING_BLOCK)) {
wrapper.set(Type.INT, 0, protocol.getMappingData().getNewBlockStateId(data));
} else if (type1_14.is(Entity1_14Types.MINECART)) {
// default is 0 = rideable minecart
switch(data) {
case 1:
typeId = Entity1_14Types.CHEST_MINECART.getId();
break;
case 2:
typeId = Entity1_14Types.FURNACE_MINECART.getId();
break;
case 3:
typeId = Entity1_14Types.TNT_MINECART.getId();
break;
case 4:
typeId = Entity1_14Types.SPAWNER_MINECART.getId();
break;
case 5:
typeId = Entity1_14Types.HOPPER_MINECART.getId();
break;
case 6:
typeId = Entity1_14Types.COMMAND_BLOCK_MINECART.getId();
break;
}
} else if ((type1_14.is(Entity1_14Types.ITEM) && data > 0) || type1_14.isOrHasParent(Entity1_14Types.ABSTRACT_ARROW)) {
if (type1_14.isOrHasParent(Entity1_14Types.ABSTRACT_ARROW)) {
wrapper.set(Type.INT, 0, data - 1);
}
// send velocity in separate packet, 1.14 is now ignoring the velocity
PacketWrapper velocity = wrapper.create(0x45);
velocity.write(Type.VAR_INT, entityId);
velocity.write(Type.SHORT, wrapper.get(Type.SHORT, 0));
velocity.write(Type.SHORT, wrapper.get(Type.SHORT, 1));
velocity.write(Type.SHORT, wrapper.get(Type.SHORT, 2));
velocity.scheduleSend(Protocol1_14To1_13_2.class);
}
// Register Type ID
wrapper.user().getEntityTracker(Protocol1_14To1_13_2.class).addEntity(entityId, type1_14);
}
wrapper.set(Type.VAR_INT, 1, typeId);
}
});
}
});
protocol.registerClientbound(ClientboundPackets1_13.SPAWN_MOB, new PacketRemapper() {
@Override
public void registerMap() {
// 0 - Entity ID
map(Type.VAR_INT);
// 1 - Entity UUID
map(Type.UUID);
// 2 - Entity Type
map(Type.VAR_INT);
// 3 - X
map(Type.DOUBLE);
// 4 - Y
map(Type.DOUBLE);
// 5 - Z
map(Type.DOUBLE);
// 6 - Yaw
map(Type.BYTE);
// 7 - Pitch
map(Type.BYTE);
// 8 - Head Pitch
map(Type.BYTE);
// 9 - Velocity X
map(Type.SHORT);
// 10 - Velocity Y
map(Type.SHORT);
// 11 - Velocity Z
map(Type.SHORT);
// 12 - Metadata
map(Types1_13_2.METADATA_LIST, Types1_14.METADATA_LIST);
handler(metadataRewriter.trackerAndRewriterHandler(Types1_14.METADATA_LIST));
}
});
protocol.registerClientbound(ClientboundPackets1_13.SPAWN_PAINTING, new PacketRemapper() {
@Override
public void registerMap() {
map(Type.VAR_INT);
map(Type.UUID);
map(Type.VAR_INT);
map(Type.POSITION, Type.POSITION1_14);
map(Type.BYTE);
}
});
protocol.registerClientbound(ClientboundPackets1_13.SPAWN_PLAYER, new PacketRemapper() {
@Override
public void registerMap() {
// 0 - Entity ID
map(Type.VAR_INT);
// 1 - Player UUID
map(Type.UUID);
// 2 - X
map(Type.DOUBLE);
// 3 - Y
map(Type.DOUBLE);
// 4 - Z
map(Type.DOUBLE);
// 5 - Yaw
map(Type.BYTE);
// 6 - Pitch
map(Type.BYTE);
// 7 - Metadata
map(Types1_13_2.METADATA_LIST, Types1_14.METADATA_LIST);
handler(metadataRewriter.trackerAndRewriterHandler(Types1_14.METADATA_LIST, Entity1_14Types.PLAYER));
}
});
protocol.registerClientbound(ClientboundPackets1_13.ENTITY_ANIMATION, new PacketRemapper() {
@Override
public void registerMap() {
map(Type.VAR_INT);
handler(new PacketHandler() {
@Override
public void handle(PacketWrapper wrapper) throws Exception {
short animation = wrapper.passthrough(Type.UNSIGNED_BYTE);
if (animation == 2) {
// Leave bed
EntityTracker1_14 tracker = wrapper.user().getEntityTracker(Protocol1_14To1_13_2.class);
int entityId = wrapper.get(Type.VAR_INT, 0);
tracker.setSleeping(entityId, false);
PacketWrapper metadataPacket = wrapper.create(ClientboundPackets1_14.ENTITY_METADATA);
metadataPacket.write(Type.VAR_INT, entityId);
List<Metadata> metadataList = new LinkedList<>();
if (tracker.clientEntityId() != entityId) {
metadataList.add(new Metadata(6, Types1_14.META_TYPES.poseType, MetadataRewriter1_14To1_13_2.recalculatePlayerPose(entityId, tracker)));
}
metadataList.add(new Metadata(12, Types1_14.META_TYPES.optionalPositionType, null));
metadataPacket.write(Types1_14.METADATA_LIST, metadataList);
metadataPacket.scheduleSend(Protocol1_14To1_13_2.class);
}
}
});
}
});
protocol.registerClientbound(ClientboundPackets1_13.USE_BED, ClientboundPackets1_14.ENTITY_METADATA, new PacketRemapper() {
@Override
public void registerMap() {
map(Type.VAR_INT);
handler(new PacketHandler() {
@Override
public void handle(PacketWrapper wrapper) throws Exception {
EntityTracker1_14 tracker = wrapper.user().getEntityTracker(Protocol1_14To1_13_2.class);
int entityId = wrapper.get(Type.VAR_INT, 0);
tracker.setSleeping(entityId, true);
Position position = wrapper.read(Type.POSITION);
List<Metadata> metadataList = new LinkedList<>();
metadataList.add(new Metadata(12, Types1_14.META_TYPES.optionalPositionType, position));
if (tracker.clientEntityId() != entityId) {
metadataList.add(new Metadata(6, Types1_14.META_TYPES.poseType, MetadataRewriter1_14To1_13_2.recalculatePlayerPose(entityId, tracker)));
}
wrapper.write(Types1_14.METADATA_LIST, metadataList);
}
});
}
});
metadataRewriter.registerRemoveEntities(ClientboundPackets1_13.DESTROY_ENTITIES);
metadataRewriter.registerMetadataRewriter(ClientboundPackets1_13.ENTITY_METADATA, Types1_13_2.METADATA_LIST, Types1_14.METADATA_LIST);
}
Aggregations