Cleanup some tag rewriting

This commit is contained in:
KennyTV 2020-06-30 21:16:19 +02:00
parent f5bb30559d
commit bb583065f3
No known key found for this signature in database
GPG Key ID: 6BE3B555EBC5982B
2 changed files with 12 additions and 75 deletions

View File

@ -12,6 +12,7 @@ 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.remapper.ValueTransformer; import us.myles.ViaVersion.api.remapper.ValueTransformer;
import us.myles.ViaVersion.api.rewriters.TagRewriter;
import us.myles.ViaVersion.api.type.Type; import us.myles.ViaVersion.api.type.Type;
import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.ClientboundPackets1_13; import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.ClientboundPackets1_13;
import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.ServerboundPackets1_13; import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.ServerboundPackets1_13;
@ -160,32 +161,8 @@ public class Protocol1_13To1_13_1 extends BackwardsProtocol<ClientboundPackets1_
} }
}); });
registerOutgoing(ClientboundPackets1_13.TAGS, new PacketRemapper() { new TagRewriter(this, Protocol1_13To1_13_1::getNewBlockId,
@Override InventoryPackets1_13_1::getOldItemId, null).register(ClientboundPackets1_13.TAGS);
public void registerMap() {
handler(new PacketHandler() {
@Override
public void handle(PacketWrapper wrapper) throws Exception {
int blockTagsSize = wrapper.passthrough(Type.VAR_INT); // block tags
for (int i = 0; i < blockTagsSize; i++) {
wrapper.passthrough(Type.STRING);
int[] blocks = wrapper.passthrough(Type.VAR_INT_ARRAY_PRIMITIVE);
for (int j = 0; j < blocks.length; j++) {
blocks[j] = getNewBlockId(blocks[j]);
}
}
int itemTagsSize = wrapper.passthrough(Type.VAR_INT); // item tags
for (int i = 0; i < itemTagsSize; i++) {
wrapper.passthrough(Type.STRING);
int[] items = wrapper.passthrough(Type.VAR_INT_ARRAY_PRIMITIVE);
for (int j = 0; j < items.length; j++) {
items[j] = InventoryPackets1_13_1.getOldItemId(items[j]);
}
}
}
});
}
});
} }
public static int getNewBlockStateId(int blockId) { public static int getNewBlockStateId(int blockId) {

View File

@ -14,8 +14,8 @@ import us.myles.ViaVersion.api.PacketWrapper;
import us.myles.ViaVersion.api.data.UserConnection; import us.myles.ViaVersion.api.data.UserConnection;
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.rewriters.TagRewriter;
import us.myles.ViaVersion.api.type.Type; import us.myles.ViaVersion.api.type.Type;
import us.myles.ViaVersion.packets.State;
import us.myles.ViaVersion.protocols.protocol1_14to1_13_2.ClientboundPackets1_14; import us.myles.ViaVersion.protocols.protocol1_14to1_13_2.ClientboundPackets1_14;
import us.myles.ViaVersion.protocols.protocol1_14to1_13_2.ServerboundPackets1_14; import us.myles.ViaVersion.protocols.protocol1_14to1_13_2.ServerboundPackets1_14;
import us.myles.ViaVersion.protocols.protocol1_15to1_14_4.ClientboundPackets1_15; import us.myles.ViaVersion.protocols.protocol1_15to1_14_4.ClientboundPackets1_15;
@ -119,50 +119,8 @@ public class Protocol1_14_4To1_15 extends BackwardsProtocol<ClientboundPackets1_
} }
}); });
registerOutgoing(ClientboundPackets1_15.TAGS, new PacketRemapper() { new TagRewriter(this, id -> BackwardsMappings.blockMappings.getNewId(id),
@Override id -> MappingData.oldToNewItems.inverse().get(id), EntityTypeMapping::getOldEntityId).register(ClientboundPackets1_15.TAGS);
public void registerMap() {
handler(new PacketHandler() {
@Override
public void handle(PacketWrapper wrapper) throws Exception {
int blockTagsSize = wrapper.passthrough(Type.VAR_INT);
for (int i = 0; i < blockTagsSize; i++) {
wrapper.passthrough(Type.STRING);
int[] blockIds = wrapper.passthrough(Type.VAR_INT_ARRAY_PRIMITIVE);
for (int j = 0; j < blockIds.length; j++) {
int id = blockIds[j];
blockIds[j] = BackwardsMappings.blockMappings.getNewId(id);
}
}
int itemTagsSize = wrapper.passthrough(Type.VAR_INT);
for (int i = 0; i < itemTagsSize; i++) {
wrapper.passthrough(Type.STRING);
int[] itemIds = wrapper.passthrough(Type.VAR_INT_ARRAY_PRIMITIVE);
for (int j = 0; j < itemIds.length; j++) {
int oldId = MappingData.oldToNewItems.inverse().get(itemIds[j]);
itemIds[j] = oldId;
}
}
int fluidTagsSize = wrapper.passthrough(Type.VAR_INT); // fluid tags
for (int i = 0; i < fluidTagsSize; i++) {
wrapper.passthrough(Type.STRING);
wrapper.passthrough(Type.VAR_INT_ARRAY_PRIMITIVE);
}
int entityTagsSize = wrapper.passthrough(Type.VAR_INT);
for (int i = 0; i < entityTagsSize; i++) {
wrapper.passthrough(Type.STRING);
int[] entityIds = wrapper.passthrough(Type.VAR_INT_ARRAY_PRIMITIVE);
for (int j = 0; j < entityIds.length; j++) {
entityIds[j] = EntityTypeMapping.getOldEntityId(entityIds[j]);
}
}
}
});
}
});
} }
public static int getNewBlockStateId(int id) { public static int getNewBlockStateId(int id) {
@ -174,7 +132,6 @@ public class Protocol1_14_4To1_15 extends BackwardsProtocol<ClientboundPackets1_
return newId; return newId;
} }
public static int getNewBlockId(int id) { public static int getNewBlockId(int id) {
int newId = BackwardsMappings.blockMappings.getNewId(id); int newId = BackwardsMappings.blockMappings.getNewId(id);
if (newId == -1) { if (newId == -1) {
@ -186,12 +143,15 @@ public class Protocol1_14_4To1_15 extends BackwardsProtocol<ClientboundPackets1_
@Override @Override
public void init(UserConnection user) { public void init(UserConnection user) {
if (!user.has(ClientWorld.class)) if (!user.has(ClientWorld.class)) {
user.put(new ClientWorld(user)); user.put(new ClientWorld(user));
if (!user.has(ImmediateRespawn.class)) }
if (!user.has(ImmediateRespawn.class)) {
user.put(new ImmediateRespawn(user)); user.put(new ImmediateRespawn(user));
if (!user.has(EntityTracker.class)) }
if (!user.has(EntityTracker.class)) {
user.put(new EntityTracker(user)); user.put(new EntityTracker(user));
}
user.get(EntityTracker.class).initProtocol(this); user.get(EntityTracker.class).initProtocol(this);
} }