use of com.viaversion.viaversion.api.protocol.remapper.PacketRemapper in project ViaBackwards by ViaVersion.
the class PlayerPackets1_14 method registerPackets.
@Override
protected void registerPackets() {
protocol.registerClientbound(ClientboundPackets1_14.SERVER_DIFFICULTY, new PacketRemapper() {
@Override
public void registerMap() {
map(Type.UNSIGNED_BYTE);
// Locked
map(Type.BOOLEAN, Type.NOTHING);
handler(wrapper -> {
byte difficulty = wrapper.get(Type.UNSIGNED_BYTE, 0).byteValue();
wrapper.user().get(DifficultyStorage.class).setDifficulty(difficulty);
});
}
});
protocol.registerClientbound(ClientboundPackets1_14.OPEN_SIGN_EDITOR, new // c
PacketRemapper() {
@Override
public void registerMap() {
map(Type.POSITION1_14, Type.POSITION);
}
});
protocol.registerServerbound(ServerboundPackets1_13.QUERY_BLOCK_NBT, new PacketRemapper() {
@Override
public void registerMap() {
map(Type.VAR_INT);
map(Type.POSITION, Type.POSITION1_14);
}
});
protocol.registerServerbound(ServerboundPackets1_13.PLAYER_DIGGING, new PacketRemapper() {
@Override
public void registerMap() {
// Action
map(Type.VAR_INT);
// Position
map(Type.POSITION, Type.POSITION1_14);
}
});
protocol.registerServerbound(ServerboundPackets1_13.RECIPE_BOOK_DATA, new PacketRemapper() {
@Override
public void registerMap() {
map(Type.VAR_INT);
handler(new PacketHandler() {
@Override
public void handle(PacketWrapper wrapper) throws Exception {
int type = wrapper.get(Type.VAR_INT, 0);
if (type == 0) {
wrapper.passthrough(Type.STRING);
} else if (type == 1) {
// Crafting Recipe Book Open
wrapper.passthrough(Type.BOOLEAN);
// Crafting Recipe Filter Active
wrapper.passthrough(Type.BOOLEAN);
// Smelting Recipe Book Open
wrapper.passthrough(Type.BOOLEAN);
// Smelting Recipe Filter Active
wrapper.passthrough(Type.BOOLEAN);
// Blast furnace/smoker data
wrapper.write(Type.BOOLEAN, false);
wrapper.write(Type.BOOLEAN, false);
wrapper.write(Type.BOOLEAN, false);
wrapper.write(Type.BOOLEAN, false);
}
}
});
}
});
protocol.registerServerbound(ServerboundPackets1_13.UPDATE_COMMAND_BLOCK, new PacketRemapper() {
@Override
public void registerMap() {
map(Type.POSITION, Type.POSITION1_14);
}
});
protocol.registerServerbound(ServerboundPackets1_13.UPDATE_STRUCTURE_BLOCK, new PacketRemapper() {
@Override
public void registerMap() {
map(Type.POSITION, Type.POSITION1_14);
}
});
protocol.registerServerbound(ServerboundPackets1_13.UPDATE_SIGN, new PacketRemapper() {
@Override
public void registerMap() {
map(Type.POSITION, Type.POSITION1_14);
}
});
protocol.registerServerbound(ServerboundPackets1_13.PLAYER_BLOCK_PLACEMENT, new PacketRemapper() {
@Override
public void registerMap() {
handler(new PacketHandler() {
@Override
public void handle(PacketWrapper wrapper) throws Exception {
Position position = wrapper.read(Type.POSITION);
int face = wrapper.read(Type.VAR_INT);
int hand = wrapper.read(Type.VAR_INT);
float x = wrapper.read(Type.FLOAT);
float y = wrapper.read(Type.FLOAT);
float z = wrapper.read(Type.FLOAT);
wrapper.write(Type.VAR_INT, hand);
wrapper.write(Type.POSITION1_14, position);
wrapper.write(Type.VAR_INT, face);
wrapper.write(Type.FLOAT, x);
wrapper.write(Type.FLOAT, y);
wrapper.write(Type.FLOAT, z);
// Inside block
wrapper.write(Type.BOOLEAN, false);
}
});
}
});
}
use of com.viaversion.viaversion.api.protocol.remapper.PacketRemapper in project ViaBackwards by ViaVersion.
the class SoundPackets1_14 method registerPackets.
@Override
protected void registerPackets() {
SoundRewriter soundRewriter = new SoundRewriter(protocol);
soundRewriter.registerSound(ClientboundPackets1_14.SOUND);
soundRewriter.registerNamedSound(ClientboundPackets1_14.NAMED_SOUND);
soundRewriter.registerStopSound(ClientboundPackets1_14.STOP_SOUND);
// Entity Sound Effect
protocol.registerClientbound(ClientboundPackets1_14.ENTITY_SOUND, null, new PacketRemapper() {
@Override
public void registerMap() {
handler(wrapper -> {
wrapper.cancel();
int soundId = wrapper.read(Type.VAR_INT);
int newId = protocol.getMappingData().getSoundMappings().getNewId(soundId);
if (newId == -1)
return;
int category = wrapper.read(Type.VAR_INT);
int entityId = wrapper.read(Type.VAR_INT);
StoredEntityData storedEntity = wrapper.user().getEntityTracker(protocol.getClass()).entityData(entityId);
EntityPositionStorage1_14 entityStorage;
if (storedEntity == null || (entityStorage = storedEntity.get(EntityPositionStorage1_14.class)) == null) {
ViaBackwards.getPlatform().getLogger().warning("Untracked entity with id " + entityId);
return;
}
float volume = wrapper.read(Type.FLOAT);
float pitch = wrapper.read(Type.FLOAT);
int x = (int) (entityStorage.getX() * 8D);
int y = (int) (entityStorage.getY() * 8D);
int z = (int) (entityStorage.getZ() * 8D);
PacketWrapper soundPacket = wrapper.create(ClientboundPackets1_13.SOUND);
soundPacket.write(Type.VAR_INT, newId);
soundPacket.write(Type.VAR_INT, category);
soundPacket.write(Type.INT, x);
soundPacket.write(Type.INT, y);
soundPacket.write(Type.INT, z);
soundPacket.write(Type.FLOAT, volume);
soundPacket.write(Type.FLOAT, pitch);
soundPacket.send(Protocol1_13_2To1_14.class);
});
}
});
}
use of com.viaversion.viaversion.api.protocol.remapper.PacketRemapper in project ViaBackwards by ViaVersion.
the class Protocol1_17To1_17_1 method registerPackets.
@Override
protected void registerPackets() {
registerClientbound(ClientboundPackets1_17_1.REMOVE_ENTITIES, null, new PacketRemapper() {
@Override
public void registerMap() {
handler(wrapper -> {
int[] entityIds = wrapper.read(Type.VAR_INT_ARRAY_PRIMITIVE);
wrapper.cancel();
for (int entityId : entityIds) {
// Send individual remove packets
PacketWrapper newPacket = wrapper.create(ClientboundPackets1_17.REMOVE_ENTITY);
newPacket.write(Type.VAR_INT, entityId);
newPacket.send(Protocol1_17To1_17_1.class);
}
});
}
});
registerClientbound(ClientboundPackets1_17_1.CLOSE_WINDOW, new PacketRemapper() {
@Override
public void registerMap() {
handler(wrapper -> {
short containerId = wrapper.passthrough(Type.UNSIGNED_BYTE);
wrapper.user().get(InventoryStateIds.class).removeStateId(containerId);
});
}
});
registerClientbound(ClientboundPackets1_17_1.SET_SLOT, new PacketRemapper() {
@Override
public void registerMap() {
handler(wrapper -> {
short containerId = wrapper.passthrough(Type.UNSIGNED_BYTE);
int stateId = wrapper.read(Type.VAR_INT);
wrapper.user().get(InventoryStateIds.class).setStateId(containerId, stateId);
});
}
});
registerClientbound(ClientboundPackets1_17_1.WINDOW_ITEMS, new PacketRemapper() {
@Override
public void registerMap() {
handler(wrapper -> {
short containerId = wrapper.passthrough(Type.UNSIGNED_BYTE);
int stateId = wrapper.read(Type.VAR_INT);
wrapper.user().get(InventoryStateIds.class).setStateId(containerId, stateId);
// Length is encoded as a var int in 1.17.1
wrapper.write(Type.FLAT_VAR_INT_ITEM_ARRAY, wrapper.read(Type.FLAT_VAR_INT_ITEM_ARRAY_VAR_INT));
// Carried item - should work without adding it to the array above
wrapper.read(Type.FLAT_VAR_INT_ITEM);
});
}
});
registerServerbound(ServerboundPackets1_17.CLOSE_WINDOW, new PacketRemapper() {
@Override
public void registerMap() {
handler(wrapper -> {
short containerId = wrapper.passthrough(Type.UNSIGNED_BYTE);
wrapper.user().get(InventoryStateIds.class).removeStateId(containerId);
});
}
});
registerServerbound(ServerboundPackets1_17.CLICK_WINDOW, new PacketRemapper() {
@Override
public void registerMap() {
handler(wrapper -> {
short containerId = wrapper.passthrough(Type.UNSIGNED_BYTE);
int stateId = wrapper.user().get(InventoryStateIds.class).removeStateId(containerId);
wrapper.write(Type.VAR_INT, stateId == Integer.MAX_VALUE ? 0 : stateId);
});
}
});
registerServerbound(ServerboundPackets1_17.EDIT_BOOK, new PacketRemapper() {
@Override
public void registerMap() {
handler(wrapper -> {
Item item = wrapper.read(Type.FLAT_VAR_INT_ITEM);
boolean signing = wrapper.read(Type.BOOLEAN);
// Slot comes first
wrapper.passthrough(Type.VAR_INT);
CompoundTag tag = item.tag();
ListTag pagesTag;
StringTag titleTag = null;
// Sanity checks
if (tag == null || (pagesTag = tag.get("pages")) == null || (signing && (titleTag = tag.get("title")) == null)) {
// Pages length
wrapper.write(Type.VAR_INT, 0);
// Optional title
wrapper.write(Type.BOOLEAN, false);
return;
}
// Write pages - limit them first
if (pagesTag.size() > MAX_PAGES) {
pagesTag = new ListTag(pagesTag.getValue().subList(0, MAX_PAGES));
}
wrapper.write(Type.VAR_INT, pagesTag.size());
for (Tag pageTag : pagesTag) {
String page = ((StringTag) pageTag).getValue();
// Limit page length
if (page.length() > MAX_PAGE_LENGTH) {
page = page.substring(0, MAX_PAGE_LENGTH);
}
wrapper.write(Type.STRING, page);
}
// Write optional title
wrapper.write(Type.BOOLEAN, signing);
if (signing) {
if (titleTag == null) {
titleTag = tag.get("title");
}
// Limit title length
String title = titleTag.getValue();
if (title.length() > MAX_TITLE_LENGTH) {
title = title.substring(0, MAX_TITLE_LENGTH);
}
wrapper.write(Type.STRING, title);
}
});
}
});
}
use of com.viaversion.viaversion.api.protocol.remapper.PacketRemapper in project ViaBackwards by ViaVersion.
the class Protocol1_16_1To1_16_2 method registerPackets.
@Override
protected void registerPackets() {
executeAsyncAfterLoaded(Protocol1_16_2To1_16_1.class, MAPPINGS::load);
translatableRewriter.registerBossBar(ClientboundPackets1_16_2.BOSSBAR);
translatableRewriter.registerCombatEvent(ClientboundPackets1_16_2.COMBAT_EVENT);
translatableRewriter.registerDisconnect(ClientboundPackets1_16_2.DISCONNECT);
translatableRewriter.registerTabList(ClientboundPackets1_16_2.TAB_LIST);
translatableRewriter.registerTitle(ClientboundPackets1_16_2.TITLE);
translatableRewriter.registerOpenWindow(ClientboundPackets1_16_2.OPEN_WINDOW);
translatableRewriter.registerPing();
new CommandRewriter1_16_2(this).registerDeclareCommands(ClientboundPackets1_16_2.DECLARE_COMMANDS);
(blockItemPackets = new BlockItemPackets1_16_2(this)).register();
entityRewriter.register();
SoundRewriter soundRewriter = new SoundRewriter(this);
soundRewriter.registerSound(ClientboundPackets1_16_2.SOUND);
soundRewriter.registerSound(ClientboundPackets1_16_2.ENTITY_SOUND);
soundRewriter.registerNamedSound(ClientboundPackets1_16_2.NAMED_SOUND);
soundRewriter.registerStopSound(ClientboundPackets1_16_2.STOP_SOUND);
registerClientbound(ClientboundPackets1_16_2.CHAT_MESSAGE, new PacketRemapper() {
@Override
public void registerMap() {
handler(wrapper -> {
JsonElement message = wrapper.passthrough(Type.COMPONENT);
translatableRewriter.processText(message);
byte position = wrapper.passthrough(Type.BYTE);
if (position == 2) {
// https://bugs.mojang.com/browse/MC-119145
wrapper.clearPacket();
wrapper.setId(ClientboundPackets1_16.TITLE.ordinal());
wrapper.write(Type.VAR_INT, 2);
wrapper.write(Type.COMPONENT, message);
}
});
}
});
// Recipe book data has been split into 2 separate packets
registerServerbound(ServerboundPackets1_16.RECIPE_BOOK_DATA, new PacketRemapper() {
@Override
public void registerMap() {
handler(new PacketHandler() {
@Override
public void handle(PacketWrapper wrapper) throws Exception {
int type = wrapper.read(Type.VAR_INT);
if (type == 0) {
// Shown, change to its own packet
// Recipe
wrapper.passthrough(Type.STRING);
wrapper.setId(ServerboundPackets1_16_2.SEEN_RECIPE.ordinal());
} else {
wrapper.cancel();
// Settings
for (int i = 0; i < 3; i++) {
sendSeenRecipePacket(i, wrapper);
}
}
}
private void sendSeenRecipePacket(int recipeType, PacketWrapper wrapper) throws Exception {
boolean open = wrapper.read(Type.BOOLEAN);
boolean filter = wrapper.read(Type.BOOLEAN);
PacketWrapper newPacket = wrapper.create(ServerboundPackets1_16_2.RECIPE_BOOK_DATA);
newPacket.write(Type.VAR_INT, recipeType);
newPacket.write(Type.BOOLEAN, open);
newPacket.write(Type.BOOLEAN, filter);
newPacket.sendToServer(Protocol1_16_1To1_16_2.class);
}
});
}
});
new TagRewriter(this).register(ClientboundPackets1_16_2.TAGS, RegistryType.ENTITY);
new StatisticsRewriter(this).register(ClientboundPackets1_16_2.STATISTICS);
}
use of com.viaversion.viaversion.api.protocol.remapper.PacketRemapper in project ViaBackwards by ViaVersion.
the class Protocol1_16_3To1_16_4 method registerPackets.
@Override
protected void registerPackets() {
registerServerbound(ServerboundPackets1_16_2.EDIT_BOOK, new PacketRemapper() {
@Override
public void registerMap() {
map(Type.FLAT_VAR_INT_ITEM);
map(Type.BOOLEAN);
handler(wrapper -> {
int slot = wrapper.read(Type.VAR_INT);
if (slot == 1) {
// offhand
wrapper.write(Type.VAR_INT, 40);
} else {
wrapper.write(Type.VAR_INT, wrapper.user().get(PlayerHandStorage.class).getCurrentHand());
}
});
}
});
registerServerbound(ServerboundPackets1_16_2.HELD_ITEM_CHANGE, new PacketRemapper() {
@Override
public void registerMap() {
handler(wrapper -> {
short slot = wrapper.passthrough(Type.SHORT);
wrapper.user().get(PlayerHandStorage.class).setCurrentHand(slot);
});
}
});
}
Aggregations