use of com.viaversion.viaversion.api.minecraft.RegistryType 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.api.minecraft.RegistryType in project ViaVersion by ViaVersion.
the class Protocol1_17To1_16_4 method registerPackets.
@Override
protected void registerPackets() {
entityRewriter.register();
itemRewriter.register();
WorldPackets.register(this);
registerClientbound(ClientboundPackets1_16_2.TAGS, new PacketRemapper() {
@Override
public void registerMap() {
handler(wrapper -> {
// Tags are now generically written with resource location - 5 different Vanilla types
wrapper.write(Type.VAR_INT, 5);
for (RegistryType type : RegistryType.getValues()) {
// Prefix with resource location
wrapper.write(Type.STRING, type.resourceLocation());
// Id conversion
tagRewriter.handle(wrapper, tagRewriter.getRewriter(type), tagRewriter.getNewTags(type));
// Stop iterating after entity types
if (type == RegistryType.ENTITY) {
break;
}
}
// New Game Event tags type
wrapper.write(Type.STRING, RegistryType.GAME_EVENT.resourceLocation());
wrapper.write(Type.VAR_INT, NEW_GAME_EVENT_TAGS.length);
for (String tag : NEW_GAME_EVENT_TAGS) {
wrapper.write(Type.STRING, tag);
wrapper.write(Type.VAR_INT_ARRAY_PRIMITIVE, new int[0]);
}
});
}
});
new StatisticsRewriter(this).register(ClientboundPackets1_16_2.STATISTICS);
SoundRewriter soundRewriter = new SoundRewriter(this);
soundRewriter.registerSound(ClientboundPackets1_16_2.SOUND);
soundRewriter.registerSound(ClientboundPackets1_16_2.ENTITY_SOUND);
registerClientbound(ClientboundPackets1_16_2.RESOURCE_PACK, new PacketRemapper() {
@Override
public void registerMap() {
handler(wrapper -> {
wrapper.passthrough(Type.STRING);
wrapper.passthrough(Type.STRING);
// Required
wrapper.write(Type.BOOLEAN, Via.getConfig().isForcedUse1_17ResourcePack());
// Prompt message
wrapper.write(Type.OPTIONAL_COMPONENT, Via.getConfig().get1_17ResourcePackPrompt());
});
}
});
registerClientbound(ClientboundPackets1_16_2.MAP_DATA, new PacketRemapper() {
@Override
public void registerMap() {
handler(wrapper -> {
wrapper.passthrough(Type.VAR_INT);
wrapper.passthrough(Type.BYTE);
// Tracking position removed
wrapper.read(Type.BOOLEAN);
wrapper.passthrough(Type.BOOLEAN);
int size = wrapper.read(Type.VAR_INT);
// Write whether markers exists or not
if (size != 0) {
wrapper.write(Type.BOOLEAN, true);
wrapper.write(Type.VAR_INT, size);
} else {
wrapper.write(Type.BOOLEAN, false);
}
});
}
});
registerClientbound(ClientboundPackets1_16_2.TITLE, null, new PacketRemapper() {
@Override
public void registerMap() {
handler(wrapper -> {
// Title packet actions have been split into individual packets (the content hasn't changed)
int type = wrapper.read(Type.VAR_INT);
ClientboundPacketType packetType;
switch(type) {
case 0:
packetType = ClientboundPackets1_17.TITLE_TEXT;
break;
case 1:
packetType = ClientboundPackets1_17.TITLE_SUBTITLE;
break;
case 2:
packetType = ClientboundPackets1_17.ACTIONBAR;
break;
case 3:
packetType = ClientboundPackets1_17.TITLE_TIMES;
break;
case 4:
packetType = ClientboundPackets1_17.CLEAR_TITLES;
// Reset times
wrapper.write(Type.BOOLEAN, false);
break;
case 5:
packetType = ClientboundPackets1_17.CLEAR_TITLES;
// Reset times
wrapper.write(Type.BOOLEAN, true);
break;
default:
throw new IllegalArgumentException("Invalid title type received: " + type);
}
wrapper.setId(packetType.getId());
});
}
});
registerClientbound(ClientboundPackets1_16_2.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 is now a var int
wrapper.write(Type.VAR_INT, wrapper.read(Type.INT));
});
}
});
registerClientbound(ClientboundPackets1_16_2.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.write(Type.FLOAT, 0f);
});
}
});
registerServerbound(ServerboundPackets1_17.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.read(Type.BOOLEAN);
});
}
});
}
Aggregations