3
0
Mirror von https://github.com/ViaVersion/ViaVersion.git synchronisiert 2024-12-27 08:30:09 +01:00

Remove more debug code

Correct casting detector in packet wrapper.
Re-order some packets
Implement Plugin Message Transformers
Implement Sound Transformer
Implement Block Entity Transformer
Dieser Commit ist enthalten in:
Myles 2016-03-17 13:58:49 +00:00
Ursprung ccda9f11c8
Commit 7a98cdd28f
9 geänderte Dateien mit 122 neuen und 22 gelöschten Zeilen

Datei anzeigen

@ -94,12 +94,12 @@ public class PacketWrapper {
try {
Object value = packetValue.getValue();
if (value != null) {
if (!value.getClass().equals(packetValue.getKey().getOutputClass())) {
if (!packetValue.getKey().getOutputClass().isAssignableFrom(value.getClass())) {
// attempt conversion
if (packetValue.getKey() instanceof TypeConverter) {
value = ((TypeConverter) packetValue.getKey()).from(value);
} else {
System.out.println("Possible type mismatch: " + value.getClass().getName() + " -> " + packetValue.getKey().getTypeName());
System.out.println("Possible type mismatch: " + value.getClass().getName() + " -> " + packetValue.getKey().getOutputClass());
}
}
}

Datei anzeigen

@ -135,7 +135,6 @@ public class MetadataRewriter {
list.remove(entry);
break;
}
System.out.println("List Item: " + entry.getType().getTypeName() + " - " + entry.getValue() + " New Type: " + metaIndex.getNewType());
} else {
list.remove(entry);
}

Datei anzeigen

@ -82,7 +82,6 @@ public class EntityPackets {
handler(new PacketHandler() {
@Override
public void handle(PacketWrapper wrapper) throws Exception {
System.out.println("handling holo for tp");
int entityID = wrapper.get(Type.VAR_INT, 0);
if (((ViaVersionPlugin) ViaVersion.getInstance()).isHologramPatch()) {
EntityTracker tracker = wrapper.user().get(EntityTracker.class);
@ -116,7 +115,6 @@ public class EntityPackets {
handler(new PacketHandler() {
@Override
public void handle(PacketWrapper wrapper) throws Exception {
System.out.println("look move");
int entityID = wrapper.get(Type.VAR_INT, 0);
if (((ViaVersionPlugin) ViaVersion.getInstance()).isHologramPatch()) {
EntityTracker tracker = wrapper.user().get(EntityTracker.class);

Datei anzeigen

@ -291,11 +291,6 @@ public class InventoryPackets {
}
});
/* Packets which do not have any field remapping or handlers */
protocol.registerIncoming(State.PLAY, 0x0F, 0x05); // Confirm Transaction Packet
protocol.registerIncoming(State.PLAY, 0x11, 0x06); // Enchant Item Packet
// Held Item Change Packet
protocol.registerIncoming(State.PLAY, 0x09, 0x17, new PacketRemapper() {
@Override
@ -313,5 +308,12 @@ public class InventoryPackets {
});
}
});
/* Packets which do not have any field remapping or handlers */
protocol.registerIncoming(State.PLAY, 0x0F, 0x05); // Confirm Transaction Packet
protocol.registerIncoming(State.PLAY, 0x11, 0x06); // Enchant Item Packet
}
}

Datei anzeigen

@ -221,6 +221,23 @@ public class PlayerPackets {
});
}
});
// Packet Plugin Message Outgoing
protocol.registerOutgoing(State.PLAY, 0x3F, 0x18, new PacketRemapper() {
@Override
public void registerMap() {
map(Type.STRING); // 0 - Channel Name
handler(new PacketHandler() {
@Override
public void handle(PacketWrapper wrapper) throws Exception {
String name = wrapper.get(Type.STRING, 0);
if(name.equalsIgnoreCase("MC|BOpen")){
wrapper.passthrough(Type.REMAINING_BYTES); // This is so ugly, :(
wrapper.write(Type.VAR_INT, 0);
}
}
});
}
});
/* Packets which do not have any field remapping or handlers */
@ -359,6 +376,39 @@ public class PlayerPackets {
}
});
// Packet Plugin Message Incoming
protocol.registerIncoming(State.PLAY, 0x17, 0x09, new PacketRemapper() {
@Override
public void registerMap() {
map(Type.STRING); // 0 - Channel Name
handler(new PacketHandler() {
@Override
public void handle(PacketWrapper wrapper) throws Exception {
String name = wrapper.get(Type.STRING, 0);
if(name.equalsIgnoreCase("MC|BSign")){
Item item = wrapper.passthrough(Type.ITEM);
if(item != null){
item.setId((short) Material.WRITTEN_BOOK.getId());
}
}
if(name.equalsIgnoreCase("MC|AutoCmd")){
wrapper.set(Type.STRING, 0, "MC|AdvCdm");
wrapper.write(Type.BYTE, (byte) 0);
wrapper.passthrough(Type.INT); // X
wrapper.passthrough(Type.INT); // Y
wrapper.passthrough(Type.INT); // Z
wrapper.passthrough(Type.STRING); // Command
wrapper.passthrough(Type.BOOLEAN); // Flag
wrapper.clearInputBuffer();
}
if(name.equalsIgnoreCase("MC|AdvCmd")){
wrapper.set(Type.STRING, 0, "MC|AdvCdm");
}
}
});
}
});
/* Packets which do not have any field remapping or handlers */
protocol.registerIncoming(State.PLAY, 0x01, 0x02); // Chat Message Packet
@ -373,8 +423,5 @@ public class PlayerPackets {
protocol.registerIncoming(State.PLAY, 0x05, 0x0E, new PlayerMovementMapper()); // Player Look Packet
protocol.registerIncoming(State.PLAY, 0x03, 0x0F, new PlayerMovementMapper()); // Player Packet
// TODO Plugin Channels :(
protocol.registerIncoming(State.PLAY, 0x17, 0x09); // plugin message incoming
protocol.registerOutgoing(State.PLAY, 0x3F, 0x18); // plugin message outgoing
}
}

Datei anzeigen

@ -1,9 +1,14 @@
package us.myles.ViaVersion2.api.protocol1_9to1_8.packets;
import org.spacehq.opennbt.tag.builtin.CompoundTag;
import org.spacehq.opennbt.tag.builtin.StringTag;
import us.myles.ViaVersion.CancelException;
import us.myles.ViaVersion.ViaVersionPlugin;
import us.myles.ViaVersion.api.ViaVersion;
import us.myles.ViaVersion.chunks.Chunk;
import us.myles.ViaVersion.packets.State;
import us.myles.ViaVersion.sounds.SoundEffect;
import us.myles.ViaVersion.util.PacketUtil;
import us.myles.ViaVersion2.api.PacketWrapper;
import us.myles.ViaVersion2.api.item.Item;
import us.myles.ViaVersion2.api.protocol.Protocol;
@ -37,11 +42,17 @@ public class WorldPackets {
map(Type.INT); // 0 - Effect ID
// Everything else get's written through
// TODO: Effect canceller patch
handler(new PacketHandler() {
@Override
public void handle(PacketWrapper wrapper) throws Exception {
wrapper.cancel();
int id = wrapper.get(Type.INT, 0);
if (id >= 1000 && id < 2000 && id != 1005) { // Sound Effect
wrapper.cancel();
}
if (id == 1005) { // Fix jukebox
id = 1010;
}
wrapper.set(Type.INT, 0, id);
}
});
}
@ -55,11 +66,24 @@ public class WorldPackets {
// 1 - Sound Category ID
// Everything else get's written through
// TODO: Sound Effect translator patch
handler(new PacketHandler() {
@Override
public void handle(PacketWrapper wrapper) throws Exception {
wrapper.cancel();
String name = wrapper.get(Type.STRING, 0);
SoundEffect effect = SoundEffect.getByName(name);
int catid = 0;
String newname = name;
if (effect != null) {
if (effect.isBreaksound()) {
wrapper.cancel();
return;
}
catid = effect.getCategory().getId();
newname = effect.getNewName();
}
wrapper.set(Type.STRING, 0, newname);
wrapper.write(Type.VAR_INT, catid); // Write Category ID
}
});
}
@ -86,11 +110,44 @@ public class WorldPackets {
}
});
// Update Block Entity Packet
protocol.registerOutgoing(State.PLAY, 0x35, 0x09, new PacketRemapper() {
@Override
public void registerMap() {
map(Type.POSITION); // 0 - Block Position
map(Type.UNSIGNED_BYTE); // 1 - Action
map(Type.NBT); // 2 - NBT (Might not be present)
handler(new PacketHandler() {
@Override
public void handle(PacketWrapper wrapper) throws Exception {
int action = wrapper.get(Type.UNSIGNED_BYTE, 0);
if (action == 1) { // Update Spawner
CompoundTag tag = wrapper.get(Type.NBT, 0);
if (tag != null) {
if (tag.contains("EntityId")) {
String entity = (String) tag.get("EntityId").getValue();
CompoundTag spawn = new CompoundTag("SpawnData");
spawn.put(new StringTag("id", entity));
tag.put(spawn);
} else { // EntityID does not exist
CompoundTag spawn = new CompoundTag("SpawnData");
spawn.put(new StringTag("id", "AreaEffectCloud")); //Make spawners show up as empty when no EntityId is given.
tag.put(spawn);
}
}
}
if (action == 2) { // Update Command Block
// To prevent window issues don't send updates
wrapper.cancel();
}
}
});
}
});
/* Packets which do not have any field remapping or handlers */
protocol.registerOutgoing(State.PLAY, 0x25, 0x08); // Block Break Animation Packet
protocol.registerOutgoing(State.PLAY, 0x35, 0x09); // Update Block Entity Packet
// TODO: Update_Block_Entity actually implement
protocol.registerOutgoing(State.PLAY, 0x24, 0x0A); // Block Action Packet
protocol.registerOutgoing(State.PLAY, 0x23, 0x0B); // Block Change Packet
protocol.registerOutgoing(State.PLAY, 0x22, 0x10); // Multi Block Change Packet

Datei anzeigen

@ -31,7 +31,6 @@ public class MetadataListType extends Type<List<Metadata>> {
public void write(ByteBuf buffer, List<Metadata> object) throws Exception {
for (Metadata m : object) {
Protocol1_9TO1_8.METADATA.write(buffer, m);
System.out.println("Writing meta data: " + m.getType().getTypeName() + " - " + m.getId() + " - " + m.getTypeID());
}
// Write end of list
Protocol1_9TO1_8.METADATA.write(buffer, null);

Datei anzeigen

@ -26,7 +26,6 @@ public class MetadataType extends Type<Metadata> {
public void write(ByteBuf buffer, Metadata object) throws Exception {
if (object == null) {
buffer.writeByte(255);
System.out.println("writing null :)");
} else {
buffer.writeByte(object.getId());
buffer.writeByte(object.getTypeID());

Datei anzeigen

@ -18,7 +18,6 @@ public class ArrayType<T> extends Type<T[]> {
int amount = Type.VAR_INT.read(buffer);
T[] array = (T[]) Array.newInstance(elementType.getOutputClass(), amount);
System.out.println("READING ARRAY " + array.length);
for (int i = 0; i < amount; i++) {
array[i] = elementType.read(buffer);
}