use of com.viaversion.viaversion.rewriter.TagRewriter in project ViaBackwards by ViaVersion.
the class Protocol1_16_4To1_17 method registerPackets.
@Override
protected void registerPackets() {
executeAsyncAfterLoaded(Protocol1_17To1_16_4.class, MAPPINGS::load);
translatableRewriter.registerChatMessage(ClientboundPackets1_17.CHAT_MESSAGE);
translatableRewriter.registerBossBar(ClientboundPackets1_17.BOSSBAR);
translatableRewriter.registerDisconnect(ClientboundPackets1_17.DISCONNECT);
translatableRewriter.registerTabList(ClientboundPackets1_17.TAB_LIST);
translatableRewriter.registerOpenWindow(ClientboundPackets1_17.OPEN_WINDOW);
translatableRewriter.registerPing();
blockItemPackets = new BlockItemPackets1_17(this);
blockItemPackets.register();
entityRewriter.register();
SoundRewriter soundRewriter = new SoundRewriter(this);
soundRewriter.registerSound(ClientboundPackets1_17.SOUND);
soundRewriter.registerSound(ClientboundPackets1_17.ENTITY_SOUND);
soundRewriter.registerNamedSound(ClientboundPackets1_17.NAMED_SOUND);
soundRewriter.registerStopSound(ClientboundPackets1_17.STOP_SOUND);
TagRewriter tagRewriter = new TagRewriter(this);
registerClientbound(ClientboundPackets1_17.TAGS, new PacketRemapper() {
@Override
public void registerMap() {
handler(wrapper -> {
Map<String, List<TagData>> tags = new HashMap<>();
int length = wrapper.read(Type.VAR_INT);
for (int i = 0; i < length; i++) {
String resourceKey = wrapper.read(Type.STRING);
if (resourceKey.startsWith("minecraft:")) {
resourceKey = resourceKey.substring(10);
}
List<TagData> tagList = new ArrayList<>();
tags.put(resourceKey, tagList);
int tagLength = wrapper.read(Type.VAR_INT);
for (int j = 0; j < tagLength; j++) {
String identifier = wrapper.read(Type.STRING);
int[] entries = wrapper.read(Type.VAR_INT_ARRAY_PRIMITIVE);
tagList.add(new TagData(identifier, entries));
}
}
// Put them into the hardcoded order of Vanilla tags (and only those), rewrite ids
for (RegistryType type : RegistryType.getValues()) {
List<TagData> tagList = tags.get(type.getResourceLocation());
IdRewriteFunction rewriter = tagRewriter.getRewriter(type);
wrapper.write(Type.VAR_INT, tagList.size());
for (TagData tagData : tagList) {
int[] entries = tagData.entries();
if (rewriter != null) {
// Handle id rewriting now
IntList idList = new IntArrayList(entries.length);
for (int id : entries) {
int mappedId = rewriter.rewrite(id);
if (mappedId != -1) {
idList.add(mappedId);
}
}
entries = idList.toArray(EMPTY_ARRAY);
}
wrapper.write(Type.STRING, tagData.identifier());
wrapper.write(Type.VAR_INT_ARRAY_PRIMITIVE, entries);
}
// Stop after the entity types
if (type == RegistryType.ENTITY) {
break;
}
}
});
}
});
new StatisticsRewriter(this).register(ClientboundPackets1_17.STATISTICS);
registerClientbound(ClientboundPackets1_17.RESOURCE_PACK, new PacketRemapper() {
@Override
public void registerMap() {
handler(wrapper -> {
wrapper.passthrough(Type.STRING);
wrapper.passthrough(Type.STRING);
// Required
wrapper.read(Type.BOOLEAN);
// Prompt message
wrapper.read(Type.OPTIONAL_COMPONENT);
});
}
});
registerClientbound(ClientboundPackets1_17.EXPLOSION, new PacketRemapper() {
@Override
public void registerMap() {
// X
map(Type.FLOAT);
// Y
map(Type.FLOAT);
// Z
map(Type.FLOAT);
// Strength
map(Type.FLOAT);
handler(wrapper -> {
// Collection length
wrapper.write(Type.INT, wrapper.read(Type.VAR_INT));
});
}
});
registerClientbound(ClientboundPackets1_17.SPAWN_POSITION, new PacketRemapper() {
@Override
public void registerMap() {
map(Type.POSITION1_14);
handler(wrapper -> {
// Angle (which Mojang just forgot to write to the buffer, lol)
wrapper.read(Type.FLOAT);
});
}
});
registerClientbound(ClientboundPackets1_17.PING, null, new PacketRemapper() {
@Override
public void registerMap() {
handler(wrapper -> {
wrapper.cancel();
int id = wrapper.read(Type.INT);
short shortId = (short) id;
if (id == shortId && ViaBackwards.getConfig().handlePingsAsInvAcknowledgements()) {
wrapper.user().get(PingRequests.class).addId(shortId);
// Send inventory acknowledgement to replace ping packet functionality in the unsigned byte range
PacketWrapper acknowledgementPacket = wrapper.create(ClientboundPackets1_16_2.WINDOW_CONFIRMATION);
// Inventory id
acknowledgementPacket.write(Type.UNSIGNED_BYTE, (short) 0);
// Confirmation id
acknowledgementPacket.write(Type.SHORT, shortId);
// Accepted
acknowledgementPacket.write(Type.BOOLEAN, false);
acknowledgementPacket.send(Protocol1_16_4To1_17.class);
return;
}
// Plugins expecting a real response will have to handle this accordingly themselves
PacketWrapper pongPacket = wrapper.create(ServerboundPackets1_17.PONG);
pongPacket.write(Type.INT, id);
pongPacket.sendToServer(Protocol1_16_4To1_17.class);
});
}
});
registerServerbound(ServerboundPackets1_16_2.CLIENT_SETTINGS, new PacketRemapper() {
@Override
public void registerMap() {
// Locale
map(Type.STRING);
// View distance
map(Type.BYTE);
// Chat mode
map(Type.VAR_INT);
// Chat colors
map(Type.BOOLEAN);
// Chat flags
map(Type.UNSIGNED_BYTE);
// Main hand
map(Type.VAR_INT);
handler(wrapper -> {
// Text filtering
wrapper.write(Type.BOOLEAN, false);
});
}
});
// TODO translatables
mergePacket(ClientboundPackets1_17.TITLE_TEXT, ClientboundPackets1_16_2.TITLE, 0);
mergePacket(ClientboundPackets1_17.TITLE_SUBTITLE, ClientboundPackets1_16_2.TITLE, 1);
mergePacket(ClientboundPackets1_17.ACTIONBAR, ClientboundPackets1_16_2.TITLE, 2);
mergePacket(ClientboundPackets1_17.TITLE_TIMES, ClientboundPackets1_16_2.TITLE, 3);
registerClientbound(ClientboundPackets1_17.CLEAR_TITLES, ClientboundPackets1_16_2.TITLE, new PacketRemapper() {
@Override
public void registerMap() {
handler(wrapper -> {
if (wrapper.read(Type.BOOLEAN)) {
// Reset times
wrapper.write(Type.VAR_INT, 5);
} else {
// Simple clear
wrapper.write(Type.VAR_INT, 4);
}
});
}
});
cancelClientbound(ClientboundPackets1_17.ADD_VIBRATION_SIGNAL);
}
use of com.viaversion.viaversion.rewriter.TagRewriter in project ViaBackwards by ViaVersion.
the class Protocol1_17_1To1_18 method registerPackets.
@Override
protected void registerPackets() {
executeAsyncAfterLoaded(Protocol1_18To1_17_1.class, MAPPINGS::load);
translatableRewriter.registerComponentPacket(ClientboundPackets1_18.CHAT_MESSAGE);
translatableRewriter.registerComponentPacket(ClientboundPackets1_18.ACTIONBAR);
translatableRewriter.registerComponentPacket(ClientboundPackets1_18.TITLE_TEXT);
translatableRewriter.registerComponentPacket(ClientboundPackets1_18.TITLE_SUBTITLE);
translatableRewriter.registerBossBar(ClientboundPackets1_18.BOSSBAR);
translatableRewriter.registerDisconnect(ClientboundPackets1_18.DISCONNECT);
translatableRewriter.registerTabList(ClientboundPackets1_18.TAB_LIST);
translatableRewriter.registerOpenWindow(ClientboundPackets1_18.OPEN_WINDOW);
translatableRewriter.registerCombatKill(ClientboundPackets1_18.COMBAT_KILL);
translatableRewriter.registerPing();
itemRewriter = new BlockItemPackets1_18(this);
entityRewriter.register();
itemRewriter.register();
final SoundRewriter soundRewriter = new SoundRewriter(this);
soundRewriter.registerSound(ClientboundPackets1_18.SOUND);
soundRewriter.registerSound(ClientboundPackets1_18.ENTITY_SOUND);
soundRewriter.registerStopSound(ClientboundPackets1_18.STOP_SOUND);
soundRewriter.registerNamedSound(ClientboundPackets1_18.NAMED_SOUND);
final TagRewriter tagRewriter = new TagRewriter(this);
tagRewriter.addEmptyTag(RegistryType.BLOCK, "minecraft:lava_pool_stone_replaceables");
tagRewriter.registerGeneric(ClientboundPackets1_18.TAGS);
registerServerbound(ServerboundPackets1_17.CLIENT_SETTINGS, new PacketRemapper() {
@Override
public void registerMap() {
// Language
map(Type.STRING);
// View distance
map(Type.BYTE);
// Chat visibility
map(Type.VAR_INT);
// Chat colors
map(Type.BOOLEAN);
// Model customization
map(Type.UNSIGNED_BYTE);
// Main hand
map(Type.VAR_INT);
// Text filtering enabled
map(Type.BOOLEAN);
// Allow listing in server list preview
create(Type.BOOLEAN, true);
}
});
registerClientbound(ClientboundPackets1_18.SCOREBOARD_OBJECTIVE, new PacketRemapper() {
@Override
public void registerMap() {
// Name
map(Type.STRING);
handler(cutName(0, 16));
}
});
registerClientbound(ClientboundPackets1_18.DISPLAY_SCOREBOARD, new PacketRemapper() {
@Override
public void registerMap() {
// Slot
map(Type.BYTE);
// Name
map(Type.STRING);
handler(cutName(0, 16));
}
});
registerClientbound(ClientboundPackets1_18.TEAMS, new PacketRemapper() {
@Override
public void registerMap() {
// Name
map(Type.STRING);
handler(cutName(0, 16));
}
});
registerClientbound(ClientboundPackets1_18.UPDATE_SCORE, new PacketRemapper() {
@Override
public void registerMap() {
// Owner
map(Type.STRING);
// Method
map(Type.VAR_INT);
// Name
map(Type.STRING);
handler(cutName(0, 40));
handler(cutName(1, 16));
}
});
}
use of com.viaversion.viaversion.rewriter.TagRewriter 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.rewriter.TagRewriter in project ViaVersion by ViaVersion.
the class Protocol1_16_2To1_16_1 method registerPackets.
@Override
protected void registerPackets() {
metadataRewriter.register();
itemRewriter.register();
EntityPackets.register(this);
WorldPackets.register(this);
tagRewriter = new TagRewriter(this);
tagRewriter.register(ClientboundPackets1_16.TAGS, RegistryType.ENTITY);
new StatisticsRewriter(this).register(ClientboundPackets1_16.STATISTICS);
SoundRewriter soundRewriter = new SoundRewriter(this);
soundRewriter.registerSound(ClientboundPackets1_16.SOUND);
soundRewriter.registerSound(ClientboundPackets1_16.ENTITY_SOUND);
// Recipe book data has been split into 2 separate packets
registerServerbound(ServerboundPackets1_16_2.RECIPE_BOOK_DATA, new PacketRemapper() {
@Override
public void registerMap() {
handler(wrapper -> {
int recipeType = wrapper.read(Type.VAR_INT);
boolean open = wrapper.read(Type.BOOLEAN);
boolean filter = wrapper.read(Type.BOOLEAN);
// Settings
wrapper.write(Type.VAR_INT, 1);
// Crafting
wrapper.write(Type.BOOLEAN, recipeType == 0 && open);
wrapper.write(Type.BOOLEAN, filter);
// Furnace
wrapper.write(Type.BOOLEAN, recipeType == 1 && open);
wrapper.write(Type.BOOLEAN, filter);
// Blast Furnace
wrapper.write(Type.BOOLEAN, recipeType == 2 && open);
wrapper.write(Type.BOOLEAN, filter);
// Smoker
wrapper.write(Type.BOOLEAN, recipeType == 3 && open);
wrapper.write(Type.BOOLEAN, filter);
});
}
});
registerServerbound(ServerboundPackets1_16_2.SEEN_RECIPE, ServerboundPackets1_16.RECIPE_BOOK_DATA, new PacketRemapper() {
@Override
public void registerMap() {
handler(wrapper -> {
String recipe = wrapper.read(Type.STRING);
// Shown
wrapper.write(Type.VAR_INT, 0);
wrapper.write(Type.STRING, recipe);
});
}
});
}
use of com.viaversion.viaversion.rewriter.TagRewriter in project ViaVersion by ViaVersion.
the class Protocol1_15To1_14_4 method registerPackets.
@Override
protected void registerPackets() {
metadataRewriter.register();
itemRewriter.register();
EntityPackets.register(this);
PlayerPackets.register(this);
WorldPackets.register(this);
SoundRewriter soundRewriter = new SoundRewriter(this);
// Entity Sound Effect (added somewhere in 1.14)
soundRewriter.registerSound(ClientboundPackets1_14.ENTITY_SOUND);
soundRewriter.registerSound(ClientboundPackets1_14.SOUND);
new StatisticsRewriter(this).register(ClientboundPackets1_14.STATISTICS);
registerServerbound(ServerboundPackets1_14.EDIT_BOOK, new PacketRemapper() {
@Override
public void registerMap() {
handler(wrapper -> itemRewriter.handleItemToServer(wrapper.passthrough(Type.FLAT_VAR_INT_ITEM)));
}
});
tagRewriter = new TagRewriter(this);
tagRewriter.register(ClientboundPackets1_14.TAGS, RegistryType.ENTITY);
}
Aggregations