3
0
Mirror von https://github.com/ViaVersion/ViaBackwards.git synchronisiert 2024-11-20 06:50:10 +01:00

Plugin messages/new packets

Dieser Commit ist enthalten in:
Gerrygames 2019-01-17 17:30:25 +01:00
Ursprung c950fe2125
Commit 8d7fee16b8
6 geänderte Dateien mit 189 neuen und 14 gelöschten Zeilen

Datei anzeigen

@ -41,7 +41,6 @@ public class Protocol1_12_2To1_13 extends BackwardsProtocol {
out(State.PLAY, 0x07, 0x07, cancel()); // Statistics TODO MODIFIED out(State.PLAY, 0x07, 0x07, cancel()); // Statistics TODO MODIFIED
out(State.PLAY, 0x09, 0x09, cancel()); // Update Block Entity TODO MODIFIED out(State.PLAY, 0x09, 0x09, cancel()); // Update Block Entity TODO MODIFIED
out(State.PLAY, 0x0E, 0x0F); // Chat Message (clientbound) out(State.PLAY, 0x0E, 0x0F); // Chat Message (clientbound)
out(State.PLAY, 0x0F, 0x10, cancel()); // Multi Block Change TODO MODIFIED
out(State.PLAY, 0x10, 0x0E, cancel()); // Tab-Complete (clientbound) TODO MODIFIED out(State.PLAY, 0x10, 0x0E, cancel()); // Tab-Complete (clientbound) TODO MODIFIED
out(State.PLAY, 0x11, -1, cancel()); // Declare Commands TODO NEW out(State.PLAY, 0x11, -1, cancel()); // Declare Commands TODO NEW
out(State.PLAY, 0x12, 0x11); // Confirm Transaction (clientbound) out(State.PLAY, 0x12, 0x11); // Confirm Transaction (clientbound)
@ -49,7 +48,6 @@ public class Protocol1_12_2To1_13 extends BackwardsProtocol {
out(State.PLAY, 0x14, 0x13); // Open Window out(State.PLAY, 0x14, 0x13); // Open Window
out(State.PLAY, 0x16, 0x15); // Window Property out(State.PLAY, 0x16, 0x15); // Window Property
out(State.PLAY, 0x18, 0x17); // Set Cooldown out(State.PLAY, 0x18, 0x17); // Set Cooldown
out(State.PLAY, 0x19, 0x18); // Plugin Message (clientbound) TODO MODIFIED
out(State.PLAY, 0x1B, 0x1A); // Disconnect (play) out(State.PLAY, 0x1B, 0x1A); // Disconnect (play)
out(State.PLAY, 0x1C, 0x1B); // Entity Status out(State.PLAY, 0x1C, 0x1B); // Entity Status
out(State.PLAY, 0x1D, -1, cancel()); // NBT Query Response (client won't send a request, so the server should not answer) out(State.PLAY, 0x1D, -1, cancel()); // NBT Query Response (client won't send a request, so the server should not answer)
@ -114,7 +112,6 @@ public class Protocol1_12_2To1_13 extends BackwardsProtocol {
out(State.PLAY, 0x49, 0x46); // Spawn Position out(State.PLAY, 0x49, 0x46); // Spawn Position
out(State.PLAY, 0x4A, 0x47); // Time Update out(State.PLAY, 0x4A, 0x47); // Time Update
out(State.PLAY, 0x4B, 0x48); // Title out(State.PLAY, 0x4B, 0x48); // Title
out(State.PLAY, 0x4C, -1, cancel()); // Stop Sound TODO NEW
out(State.PLAY, 0x4E, 0x4A); // Player List Header And Footer out(State.PLAY, 0x4E, 0x4A); // Player List Header And Footer
out(State.PLAY, 0x4F, 0x4B); // Collect Item out(State.PLAY, 0x4F, 0x4B); // Collect Item
out(State.PLAY, 0x50, 0x4C); // Entity Teleport out(State.PLAY, 0x50, 0x4C); // Entity Teleport
@ -129,8 +126,6 @@ public class Protocol1_12_2To1_13 extends BackwardsProtocol {
in(State.PLAY, 0x06, 0x05); // Confirm Transaction (serverbound) in(State.PLAY, 0x06, 0x05); // Confirm Transaction (serverbound)
in(State.PLAY, 0x07, 0x06); // Enchant Item in(State.PLAY, 0x07, 0x06); // Enchant Item
in(State.PLAY, 0x09, 0x08); // Close Window (serverbound) in(State.PLAY, 0x09, 0x08); // Close Window (serverbound)
in(State.PLAY, 0x0A, 0x09, cancel()); // Plugin message (serverbound) TODO MODIFIED
in(State.PLAY, 0x0B, -1, cancel()); // Edit Book TODO NEW
in(State.PLAY, 0x0D, 0x0A); // Use Entity in(State.PLAY, 0x0D, 0x0A); // Use Entity
in(State.PLAY, 0x0E, 0x0B); // Keep Alive (serverbound) in(State.PLAY, 0x0E, 0x0B); // Keep Alive (serverbound)
in(State.PLAY, 0x0F, 0x0C); // Player in(State.PLAY, 0x0F, 0x0C); // Player
@ -139,22 +134,17 @@ public class Protocol1_12_2To1_13 extends BackwardsProtocol {
in(State.PLAY, 0x12, 0x0F); // Player Look in(State.PLAY, 0x12, 0x0F); // Player Look
in(State.PLAY, 0x13, 0x10); // Vehicle Move (serverbound) in(State.PLAY, 0x13, 0x10); // Vehicle Move (serverbound)
in(State.PLAY, 0x14, 0x11); // Steer Boat in(State.PLAY, 0x14, 0x11); // Steer Boat
in(State.PLAY, 0x15, -1, cancel()); // Pick Item TODO NEW
in(State.PLAY, 0x16, 0x12, cancel()); // Craft Recipe Request TODO MODIFIED in(State.PLAY, 0x16, 0x12, cancel()); // Craft Recipe Request TODO MODIFIED
in(State.PLAY, 0x17, 0x13); // Player Abilities (serverbound) in(State.PLAY, 0x17, 0x13); // Player Abilities (serverbound)
in(State.PLAY, 0x18, 0x14); // Player Digging in(State.PLAY, 0x18, 0x14); // Player Digging
in(State.PLAY, 0x19, 0x15); // Entity Action in(State.PLAY, 0x19, 0x15); // Entity Action
in(State.PLAY, 0x1A, 0x16); // Steer Vehicle in(State.PLAY, 0x1A, 0x16); // Steer Vehicle
in(State.PLAY, 0x1B, 0x17); // Recipe Book Data in(State.PLAY, 0x1B, 0x17); // Recipe Book Data
in(State.PLAY, 0x1C, -1, cancel()); // Name Item TODO NEW
in(State.PLAY, 0x1D, 0x18); // Resource Pack Status in(State.PLAY, 0x1D, 0x18); // Resource Pack Status
in(State.PLAY, 0x1E, 0x19); // Advancement Tab in(State.PLAY, 0x1E, 0x19); // Advancement Tab
in(State.PLAY, 0x1F, -1); // Select Trade in(State.PLAY, 0x1F, -1); // Select Trade
in(State.PLAY, 0x20, -1); // Set Beacon Effect in(State.PLAY, 0x20, -1); // Set Beacon Effect
in(State.PLAY, 0x21, 0x1A); // Held Item Change (serverbound) in(State.PLAY, 0x21, 0x1A); // Held Item Change (serverbound)
in(State.PLAY, 0x22, -1, cancel()); // Update Command Block TODO NEW
in(State.PLAY, 0x23, -1, cancel()); // Update Command Block Minecart TODO NEW
in(State.PLAY, 0x25, -1, cancel()); // Update Structure Block TODO NEW
in(State.PLAY, 0x26, 0x1C); // Update Sign in(State.PLAY, 0x26, 0x1C); // Update Sign
in(State.PLAY, 0x27, 0x1D); // Animation (serverbound) in(State.PLAY, 0x27, 0x1D); // Animation (serverbound)
in(State.PLAY, 0x28, 0x1E); // Spectate in(State.PLAY, 0x28, 0x1E); // Spectate

Datei anzeigen

@ -144,7 +144,7 @@ public class BlockItemPackets1_13 extends BlockItemRewriter<Protocol1_12_2To1_13
); );
//Effect //Effect
protocol.out(State.PLAY, 0x21, 0x23, new PacketRemapper() { protocol.out(State.PLAY, 0x23, 0x21, new PacketRemapper() {
@Override @Override
public void registerMap() { public void registerMap() {
map(Type.INT); // Effect Id map(Type.INT); // Effect Id

Datei anzeigen

@ -98,7 +98,7 @@ public class EntityPackets1_13 extends EntityRewriter<Protocol1_12_2To1_13> {
}); });
//Spawn Global Entity //Spawn Global Entity
protocol.registerOutgoing(State.PLAY, 0x02, 0x02, new PacketRemapper() { protocol.out(State.PLAY, 0x02, 0x02, new PacketRemapper() {
@Override @Override
public void registerMap() { public void registerMap() {
map(Type.VAR_INT); map(Type.VAR_INT);
@ -162,7 +162,7 @@ public class EntityPackets1_13 extends EntityRewriter<Protocol1_12_2To1_13> {
}); });
// Spawn Player // Spawn Player
protocol.registerOutgoing(State.PLAY, 0x05, 0x05, new PacketRemapper() { protocol.out(State.PLAY, 0x05, 0x05, new PacketRemapper() {
@Override @Override
public void registerMap() { public void registerMap() {
map(Type.VAR_INT); map(Type.VAR_INT);

Datei anzeigen

@ -1,18 +1,71 @@
package nl.matsv.viabackwards.protocol.protocol1_12_2to1_13.packets; package nl.matsv.viabackwards.protocol.protocol1_12_2to1_13.packets;
import nl.matsv.viabackwards.ViaBackwards;
import nl.matsv.viabackwards.api.rewriters.Rewriter; import nl.matsv.viabackwards.api.rewriters.Rewriter;
import nl.matsv.viabackwards.protocol.protocol1_12_2to1_13.Protocol1_12_2To1_13; import nl.matsv.viabackwards.protocol.protocol1_12_2to1_13.Protocol1_12_2To1_13;
import us.myles.ViaVersion.api.PacketWrapper; import us.myles.ViaVersion.api.PacketWrapper;
import us.myles.ViaVersion.api.minecraft.Position;
import us.myles.ViaVersion.api.minecraft.item.Item;
import us.myles.ViaVersion.api.remapper.PacketHandler; 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.type.Type; import us.myles.ViaVersion.api.type.Type;
import us.myles.ViaVersion.packets.State; import us.myles.ViaVersion.packets.State;
import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.ChatRewriter; import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.ChatRewriter;
import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.packets.InventoryPackets;
public class PlayerPacket1_13 extends Rewriter<Protocol1_12_2To1_13> { public class PlayerPacket1_13 extends Rewriter<Protocol1_12_2To1_13> {
@Override @Override
protected void registerPackets(Protocol1_12_2To1_13 protocol) { protected void registerPackets(Protocol1_12_2To1_13 protocol) {
//Plugin Message
protocol.out(State.PLAY, 0x19, 0x18, new PacketRemapper() {
@Override
public void registerMap() {
handler(new PacketHandler() {
@Override
public void handle(PacketWrapper wrapper) throws Exception {
String channel = wrapper.read(Type.STRING);
if (channel.equals("minecraft:trader_list")) {
wrapper.write(Type.STRING, "MC|TrList");
wrapper.passthrough(Type.INT); //Passthrough Window ID
int size = wrapper.passthrough(Type.UNSIGNED_BYTE);
for (int i = 0; i < size; i++) {
//Input Item
Item input = wrapper.read(Type.FLAT_ITEM);
BlockItemPackets1_13.toClient(input);
wrapper.write(Type.ITEM, input);
//Output Item
Item output = wrapper.read(Type.FLAT_ITEM);
BlockItemPackets1_13.toClient(output);
wrapper.write(Type.ITEM, output);
boolean secondItem = wrapper.passthrough(Type.BOOLEAN); //Has second item
if (secondItem) {
//Second Item
Item second = wrapper.read(Type.FLAT_ITEM);
BlockItemPackets1_13.toClient(second);
wrapper.write(Type.ITEM, second);
}
wrapper.passthrough(Type.BOOLEAN); //Trade disabled
wrapper.passthrough(Type.INT); //Number of tools uses
wrapper.passthrough(Type.INT); //Maximum number of trade uses
}
} else {
String oldChannel = InventoryPackets.getOldPluginChannelId(channel);
if (oldChannel == null) {
ViaBackwards.getPlatform().getLogger().warning("Could not find old channel for " + channel);
wrapper.cancel();
return;
}
wrapper.write(Type.STRING, oldChannel);
}
}
});
}
});
//Scoreboard Objective //Scoreboard Objective
protocol.out(State.PLAY, 0x45, 0x42, new PacketRemapper() { protocol.out(State.PLAY, 0x45, 0x42, new PacketRemapper() {
@Override @Override
@ -79,7 +132,112 @@ public class PlayerPacket1_13 extends Rewriter<Protocol1_12_2To1_13> {
} }
}); });
//Plugin Message
protocol.in(State.PLAY, 0x0A, 0x09, new PacketRemapper() {
@Override
public void registerMap() {
handler(new PacketHandler() {
@Override
public void handle(PacketWrapper wrapper) throws Exception {
String channel = wrapper.read(Type.STRING);
if (channel.equals("MC|BSign") || channel.equals("MC|BEdit")) {
wrapper.setId(0x0B);
Item book = wrapper.read(Type.ITEM);
System.out.println(book);
BlockItemPackets1_13.toServer(book);
System.out.println(book);
wrapper.write(Type.FLAT_ITEM, book);
boolean signing = channel.equals("MC|BSign");
System.out.println(channel);
System.out.println(signing);
wrapper.write(Type.BOOLEAN, signing);
} else if (channel.equals("MC|ItemName")) {
wrapper.setId(0x1C);
} else if (channel.equals("MC|AdvCmd")) {
byte type = wrapper.read(Type.BYTE);
if (type == 0) {
//Information from https://wiki.vg/index.php?title=Plugin_channels&oldid=14089
//The Notchain client only uses this for command block minecarts and uses MC|AutoCmd for blocks, but the Notchian server still accepts it for either.
//Maybe older versions used this and we need to implement this? The issues is that we would have to save the command block types
wrapper.setId(0x22);
wrapper.cancel();
ViaBackwards.getPlatform().getLogger().warning("Client send MC|AdvCmd custom payload to update command block, weird!");
} else if (type == 1) {
wrapper.setId(0x23);
wrapper.write(Type.VAR_INT, wrapper.read(Type.INT)); //Entity Id
wrapper.passthrough(Type.STRING); //Command
wrapper.passthrough(Type.BOOLEAN); //Track Output
} else {
wrapper.cancel();
}
} else if (channel.equals("MC|AutoCmd")) {
wrapper.setId(0x22);
Integer x = wrapper.read(Type.INT);
Integer y = wrapper.read(Type.INT);
Integer z = wrapper.read(Type.INT);
wrapper.write(Type.POSITION, new Position(x.longValue(), y.longValue(), z.longValue()));
wrapper.passthrough(Type.STRING); //Command
byte flags = 0;
if (wrapper.read(Type.BOOLEAN)) flags |= 0x01; //Track Output
String mode = wrapper.read(Type.STRING);
int modeId = mode.equals("SEQUENCE") ? 0 : mode.equals("AUTO") ? 1 : 2;
wrapper.write(Type.VAR_INT, modeId);
if (wrapper.read(Type.BOOLEAN)) flags |= 0x02; //Is conditional
if (wrapper.read(Type.BOOLEAN)) flags |= 0x04; //Automatic
} else if (channel.equals("MC|Struct")) {
wrapper.setId(0x25);
Integer x = wrapper.read(Type.INT);
Integer y = wrapper.read(Type.INT);
Integer z = wrapper.read(Type.INT);
wrapper.write(Type.POSITION, new Position(x.longValue(), y.longValue(), z.longValue()));
wrapper.write(Type.VAR_INT, wrapper.read(Type.BYTE) - 1);
String mode = wrapper.read(Type.STRING);
int modeId = mode.equals("SAVE") ? 0 : mode.equals("LOAD") ? 1 : mode.equals("CORNER") ? 2 : 3;
wrapper.write(Type.VAR_INT, modeId);
wrapper.passthrough(Type.STRING); //Name
wrapper.write(Type.BYTE, wrapper.read(Type.INT).byteValue()); //Offset X
wrapper.write(Type.BYTE, wrapper.read(Type.INT).byteValue()); //Offset Y
wrapper.write(Type.BYTE, wrapper.read(Type.INT).byteValue()); //Offset Z
wrapper.write(Type.BYTE, wrapper.read(Type.INT).byteValue()); //Size X
wrapper.write(Type.BYTE, wrapper.read(Type.INT).byteValue()); //Size Y
wrapper.write(Type.BYTE, wrapper.read(Type.INT).byteValue()); //Size Z
String mirror = wrapper.read(Type.STRING);
int mirrorId = mode.equals("NONE") ? 0 : mode.equals("LEFT_RIGHT") ? 1 : 2;
String rotation = wrapper.read(Type.STRING);
int rotationId = mode.equals("NONE") ? 0 : mode.equals("CLOCKWISE_90") ? 1 : mode.equals("CLOCKWISE_180") ? 2 : 3;
wrapper.passthrough(Type.STRING); //Metadata
byte flags = 0;
if (wrapper.read(Type.BOOLEAN)) flags |= 0x01; //Ignore entities
if (wrapper.read(Type.BOOLEAN)) flags |= 0x02; //Show air
if (wrapper.read(Type.BOOLEAN)) flags |= 0x04; //Show bounding box
wrapper.passthrough(Type.FLOAT); //Integrity
wrapper.passthrough(Type.VAR_LONG); //Seed
wrapper.write(Type.BYTE, flags);
} else if (channel.equals("MC|Beacon")) {
wrapper.setId(0x20);
wrapper.write(Type.VAR_INT, wrapper.read(Type.INT)); //Primary Effect
wrapper.write(Type.VAR_INT, wrapper.read(Type.INT)); //Secondary Effect
} else if (channel.equals("MC|TrSel")) {
wrapper.setId(0x1F);
wrapper.write(Type.VAR_INT, wrapper.read(Type.INT)); //Slot
} else if (channel.equals("MC|PickItem")) {
wrapper.setId(0x15);
} else {
String newChannel = InventoryPackets.getNewPluginChannelId(channel);
if (newChannel == null) {
ViaBackwards.getPlatform().getLogger().warning("Could not find new channel for " + channel);
wrapper.cancel();
return;
}
wrapper.write(Type.STRING, newChannel);
//TODO REGISTER and UNREGISTER (see ViaVersion)
wrapper.cancel();
}
}
});
}
});
} }
@Override @Override

Datei anzeigen

@ -11,6 +11,8 @@ import us.myles.ViaVersion.api.type.Type;
import us.myles.ViaVersion.packets.State; import us.myles.ViaVersion.packets.State;
public class SoundPackets1_13 extends Rewriter<Protocol1_12_2To1_13> { public class SoundPackets1_13 extends Rewriter<Protocol1_12_2To1_13> {
private static final String[] SOUND_SOURCES = {"master", "music", "record", "weather", "block", "hostile", "neutral", "player", "ambient", "voice"};
@Override @Override
protected void registerPackets(Protocol1_12_2To1_13 protocol) { protected void registerPackets(Protocol1_12_2To1_13 protocol) {
@ -32,6 +34,30 @@ public class SoundPackets1_13 extends Rewriter<Protocol1_12_2To1_13> {
} }
}); });
//Stop Sound
protocol.out(State.PLAY, 0x4C, 0x18, new PacketRemapper() {
@Override
public void registerMap() {
handler(new PacketHandler() {
@Override
public void handle(PacketWrapper wrapper) throws Exception {
wrapper.write(Type.STRING, "MC|StopSound");
byte flags = wrapper.read(Type.BYTE);
String source;
if ((flags & 0x01) != 0) {
source = SOUND_SOURCES[wrapper.read(Type.VAR_INT)];
} else {
source = "";
}
String sound = (flags & 0x02) != 0 ? wrapper.read(Type.STRING) : "";
wrapper.write(Type.STRING, source);
wrapper.write(Type.STRING, sound);
}
});
}
});
//Sound Effect //Sound Effect
protocol.out(State.PLAY, 0x4D, 0x49, new PacketRemapper() { protocol.out(State.PLAY, 0x4D, 0x49, new PacketRemapper() {
@Override @Override

Datei anzeigen

@ -47,6 +47,7 @@ public class Protocol1_13To1_13_1 extends BackwardsProtocol {
handler(new PacketHandler() { handler(new PacketHandler() {
@Override @Override
public void handle(PacketWrapper wrapper) throws Exception { public void handle(PacketWrapper wrapper) throws Exception {
InventoryPackets.toServer(wrapper.get(Type.FLAT_ITEM, 0));
wrapper.write(Type.VAR_INT, 0); wrapper.write(Type.VAR_INT, 0);
} }
}); });