mirror of
https://github.com/ViaVersion/ViaBackwards.git
synced 2024-11-26 12:55:46 +01:00
Fix action bar coloring in chat packets (#271)
This commit is contained in:
parent
0c040db6f0
commit
9a09e53572
@ -10,15 +10,18 @@
|
|||||||
|
|
||||||
package nl.matsv.viabackwards.protocol.protocol1_10to1_11.packets;
|
package nl.matsv.viabackwards.protocol.protocol1_10to1_11.packets;
|
||||||
|
|
||||||
|
import net.md_5.bungee.api.chat.BaseComponent;
|
||||||
|
import net.md_5.bungee.api.chat.TextComponent;
|
||||||
|
import net.md_5.bungee.chat.ComponentSerializer;
|
||||||
import nl.matsv.viabackwards.protocol.protocol1_10to1_11.Protocol1_10To1_11;
|
import nl.matsv.viabackwards.protocol.protocol1_10to1_11.Protocol1_10To1_11;
|
||||||
import us.myles.ViaVersion.api.PacketWrapper;
|
import us.myles.ViaVersion.api.PacketWrapper;
|
||||||
import us.myles.ViaVersion.api.remapper.PacketHandler;
|
|
||||||
import us.myles.ViaVersion.api.remapper.PacketRemapper;
|
import us.myles.ViaVersion.api.remapper.PacketRemapper;
|
||||||
import us.myles.ViaVersion.api.remapper.ValueTransformer;
|
import us.myles.ViaVersion.api.remapper.ValueTransformer;
|
||||||
import us.myles.ViaVersion.api.type.Type;
|
import us.myles.ViaVersion.api.type.Type;
|
||||||
import us.myles.ViaVersion.protocols.protocol1_9_3to1_9_1_2.ClientboundPackets1_9_3;
|
import us.myles.ViaVersion.protocols.protocol1_9_3to1_9_1_2.ClientboundPackets1_9_3;
|
||||||
import us.myles.ViaVersion.protocols.protocol1_9_3to1_9_1_2.ServerboundPackets1_9_3;
|
import us.myles.ViaVersion.protocols.protocol1_9_3to1_9_1_2.ServerboundPackets1_9_3;
|
||||||
import us.myles.viaversion.libs.gson.JsonElement;
|
import us.myles.viaversion.libs.gson.JsonElement;
|
||||||
|
import us.myles.viaversion.libs.gson.JsonObject;
|
||||||
|
|
||||||
public class PlayerPackets1_11 {
|
public class PlayerPackets1_11 {
|
||||||
private static final ValueTransformer<Short, Float> TO_NEW_FLOAT = new ValueTransformer<Short, Float>(Type.FLOAT) {
|
private static final ValueTransformer<Short, Float> TO_NEW_FLOAT = new ValueTransformer<Short, Float>(Type.FLOAT) {
|
||||||
@ -34,28 +37,25 @@ public class PlayerPackets1_11 {
|
|||||||
public void registerMap() {
|
public void registerMap() {
|
||||||
map(Type.VAR_INT); // 0 - Action
|
map(Type.VAR_INT); // 0 - Action
|
||||||
|
|
||||||
handler(new PacketHandler() {
|
handler(wrapper -> {
|
||||||
@Override
|
int action = wrapper.get(Type.VAR_INT, 0);
|
||||||
public void handle(PacketWrapper wrapper) throws Exception {
|
|
||||||
int action = wrapper.get(Type.VAR_INT, 0);
|
|
||||||
|
|
||||||
// Handle the new ActionBar
|
if (action == 2) { // Handle the new ActionBar
|
||||||
if (action == 2) {
|
JsonElement message = wrapper.read(Type.COMPONENT);
|
||||||
// Convert to the old actionbar way
|
|
||||||
PacketWrapper actionbar = new PacketWrapper(0x0F, null, wrapper.user()); // Chat Message packet
|
|
||||||
JsonElement msg = wrapper.read(Type.COMPONENT);
|
|
||||||
actionbar.write(Type.COMPONENT, msg);
|
|
||||||
actionbar.write(Type.BYTE, (byte) 2); // Above hotbar
|
|
||||||
|
|
||||||
actionbar.send(Protocol1_10To1_11.class);
|
wrapper.clearPacket();
|
||||||
|
wrapper.setId(ClientboundPackets1_9_3.CHAT_MESSAGE.ordinal());
|
||||||
|
|
||||||
wrapper.cancel(); // Cancel the title packet
|
// https://bugs.mojang.com/browse/MC-119145to
|
||||||
return;
|
BaseComponent[] parsed = ComponentSerializer.parse(message.toString());
|
||||||
}
|
String legacy = TextComponent.toLegacyText(parsed);
|
||||||
|
message = new JsonObject();
|
||||||
|
message.getAsJsonObject().addProperty("text", legacy);
|
||||||
|
|
||||||
if (action > 2) {
|
wrapper.write(Type.COMPONENT, message);
|
||||||
wrapper.set(Type.VAR_INT, 0, action - 1); // Move everything one position down
|
wrapper.write(Type.BYTE, (byte) 2);
|
||||||
}
|
} else if (action > 2) {
|
||||||
|
wrapper.set(Type.VAR_INT, 0, action - 1); // Move everything one position down
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -19,6 +19,7 @@ import us.myles.ViaVersion.protocols.protocol1_16_2to1_16_1.Protocol1_16_2To1_16
|
|||||||
import us.myles.ViaVersion.protocols.protocol1_16_2to1_16_1.ServerboundPackets1_16_2;
|
import us.myles.ViaVersion.protocols.protocol1_16_2to1_16_1.ServerboundPackets1_16_2;
|
||||||
import us.myles.ViaVersion.protocols.protocol1_16to1_15_2.ClientboundPackets1_16;
|
import us.myles.ViaVersion.protocols.protocol1_16to1_15_2.ClientboundPackets1_16;
|
||||||
import us.myles.ViaVersion.protocols.protocol1_16to1_15_2.ServerboundPackets1_16;
|
import us.myles.ViaVersion.protocols.protocol1_16to1_15_2.ServerboundPackets1_16;
|
||||||
|
import us.myles.viaversion.libs.gson.JsonElement;
|
||||||
|
|
||||||
public class Protocol1_16_1To1_16_2 extends BackwardsProtocol<ClientboundPackets1_16_2, ClientboundPackets1_16, ServerboundPackets1_16_2, ServerboundPackets1_16> {
|
public class Protocol1_16_1To1_16_2 extends BackwardsProtocol<ClientboundPackets1_16_2, ClientboundPackets1_16, ServerboundPackets1_16_2, ServerboundPackets1_16> {
|
||||||
|
|
||||||
@ -54,6 +55,23 @@ public class Protocol1_16_1To1_16_2 extends BackwardsProtocol<ClientboundPackets
|
|||||||
soundRewriter.registerNamedSound(ClientboundPackets1_16_2.NAMED_SOUND);
|
soundRewriter.registerNamedSound(ClientboundPackets1_16_2.NAMED_SOUND);
|
||||||
soundRewriter.registerStopSound(ClientboundPackets1_16_2.STOP_SOUND);
|
soundRewriter.registerStopSound(ClientboundPackets1_16_2.STOP_SOUND);
|
||||||
|
|
||||||
|
registerOutgoing(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
|
// Recipe book data has been split into 2 separate packets
|
||||||
registerIncoming(ServerboundPackets1_16.RECIPE_BOOK_DATA, new PacketRemapper() {
|
registerIncoming(ServerboundPackets1_16.RECIPE_BOOK_DATA, new PacketRemapper() {
|
||||||
@Override
|
@Override
|
||||||
|
Loading…
Reference in New Issue
Block a user