mirror of
https://github.com/ViaVersion/ViaVersion.git
synced 2024-11-23 02:25:19 +01:00
Finish 19w35a
This commit is contained in:
parent
ea25b559ed
commit
f35eb3054c
@ -73,7 +73,7 @@ public class MappingData {
|
||||
}
|
||||
}
|
||||
|
||||
private static void mapIdentifiers(Map<Integer, Integer> output, JsonObject oldIdentifiers, JsonObject newIdentifiers) {
|
||||
public static void mapIdentifiers(Map<Integer, Integer> output, JsonObject oldIdentifiers, JsonObject newIdentifiers) {
|
||||
for (Map.Entry<String, JsonElement> entry : oldIdentifiers.entrySet()) {
|
||||
Map.Entry<String, JsonElement> value = findValue(newIdentifiers, entry.getValue().getAsString());
|
||||
if (value == null) {
|
||||
@ -137,10 +137,10 @@ public class MappingData {
|
||||
int getNewSound(int old);
|
||||
}
|
||||
|
||||
private static class SoundMappingShortArray implements SoundMappings {
|
||||
public static class SoundMappingShortArray implements SoundMappings {
|
||||
private short[] oldToNew;
|
||||
|
||||
private SoundMappingShortArray(JsonArray mapping1_13_2, JsonArray mapping1_14) {
|
||||
public SoundMappingShortArray(JsonArray mapping1_13_2, JsonArray mapping1_14) {
|
||||
oldToNew = new short[mapping1_13_2.size()];
|
||||
Arrays.fill(oldToNew, (short) -1);
|
||||
mapIdentifiers(oldToNew, mapping1_13_2, mapping1_14);
|
||||
@ -156,10 +156,10 @@ public class MappingData {
|
||||
int getNewBlock(int old);
|
||||
}
|
||||
|
||||
private static class BlockMappingsShortArray implements BlockMappings {
|
||||
public static class BlockMappingsShortArray implements BlockMappings {
|
||||
private short[] oldToNew;
|
||||
|
||||
private BlockMappingsShortArray(JsonObject mapping1_13_2, JsonObject mapping1_14) {
|
||||
public BlockMappingsShortArray(JsonObject mapping1_13_2, JsonObject mapping1_14) {
|
||||
oldToNew = new short[mapping1_13_2.entrySet().size()];
|
||||
Arrays.fill(oldToNew, (short) -1);
|
||||
mapIdentifiers(oldToNew, mapping1_13_2, mapping1_14);
|
||||
|
@ -26,7 +26,6 @@ import java.util.UUID;
|
||||
public class EntityPackets {
|
||||
|
||||
public static void register(Protocol protocol) {
|
||||
|
||||
// Spawn entity
|
||||
protocol.registerOutgoing(State.PLAY, 0x00, 0x00, new PacketRemapper() {
|
||||
@Override
|
||||
|
@ -1,6 +1,7 @@
|
||||
package us.myles.ViaVersion.protocols.protocol1_15to1_14_4;
|
||||
|
||||
import us.myles.ViaVersion.api.PacketWrapper;
|
||||
import us.myles.ViaVersion.api.Via;
|
||||
import us.myles.ViaVersion.api.data.UserConnection;
|
||||
import us.myles.ViaVersion.api.entities.Entity1_15Types;
|
||||
import us.myles.ViaVersion.api.protocol.Protocol;
|
||||
@ -10,17 +11,18 @@ import us.myles.ViaVersion.api.type.Type;
|
||||
import us.myles.ViaVersion.packets.State;
|
||||
import us.myles.ViaVersion.protocols.protocol1_15to1_14_4.data.MappingData;
|
||||
import us.myles.ViaVersion.protocols.protocol1_15to1_14_4.packets.EntityPackets;
|
||||
import us.myles.ViaVersion.protocols.protocol1_15to1_14_4.packets.InventoryPackets;
|
||||
import us.myles.ViaVersion.protocols.protocol1_15to1_14_4.packets.WorldPackets;
|
||||
import us.myles.ViaVersion.protocols.protocol1_15to1_14_4.storage.EntityTracker;
|
||||
|
||||
public class Protocol1_15To1_14_4 extends Protocol {
|
||||
|
||||
@Override
|
||||
protected void registerPackets() {
|
||||
//TODO do the new tags have to be sent?
|
||||
//TODO sound, item, possibly block remaps (and blockstates should be the same with the new ones just being appended?)
|
||||
|
||||
MappingData.init();
|
||||
EntityPackets.register(this);
|
||||
WorldPackets.register(this);
|
||||
InventoryPackets.register(this);
|
||||
|
||||
// Join Game
|
||||
registerOutgoing(State.PLAY, 0x25, 0x26, new PacketRemapper() {
|
||||
@ -38,6 +40,20 @@ public class Protocol1_15To1_14_4 extends Protocol {
|
||||
}
|
||||
});
|
||||
|
||||
// Entity Sound Effect (added somewhere in 1.14)
|
||||
registerOutgoing(State.PLAY, 0x50, 0x51, new PacketRemapper() {
|
||||
@Override
|
||||
public void registerMap() {
|
||||
map(Type.VAR_INT); // Sound Id
|
||||
handler(new PacketHandler() {
|
||||
@Override
|
||||
public void handle(PacketWrapper wrapper) throws Exception {
|
||||
wrapper.set(Type.VAR_INT, 0, MappingData.soundMappings.getNewSound(wrapper.get(Type.VAR_INT, 0)));
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
// Sound Effect
|
||||
registerOutgoing(State.PLAY, 0x51, 0x52, new PacketRemapper() {
|
||||
@Override
|
||||
@ -52,11 +68,111 @@ public class Protocol1_15To1_14_4 extends Protocol {
|
||||
}
|
||||
});
|
||||
|
||||
// Edit Book
|
||||
registerIncoming(State.PLAY, 0x0C, 0x0D, new PacketRemapper() {
|
||||
@Override
|
||||
public void registerMap() {
|
||||
handler(new PacketHandler() {
|
||||
@Override
|
||||
public void handle(PacketWrapper wrapper) throws Exception {
|
||||
InventoryPackets.toServer(wrapper.passthrough(Type.FLAT_VAR_INT_ITEM));
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
// Advancements
|
||||
registerOutgoing(State.PLAY, 0x57, 0x58, new PacketRemapper() {
|
||||
@Override
|
||||
public void registerMap() {
|
||||
handler(new PacketHandler() {
|
||||
@Override
|
||||
public void handle(PacketWrapper wrapper) throws Exception {
|
||||
wrapper.passthrough(Type.BOOLEAN); // Reset/clear
|
||||
int size = wrapper.passthrough(Type.VAR_INT); // Mapping size
|
||||
|
||||
for (int i = 0; i < size; i++) {
|
||||
wrapper.passthrough(Type.STRING); // Identifier
|
||||
|
||||
// Parent
|
||||
if (wrapper.passthrough(Type.BOOLEAN))
|
||||
wrapper.passthrough(Type.STRING);
|
||||
|
||||
// Display data
|
||||
if (wrapper.passthrough(Type.BOOLEAN)) {
|
||||
wrapper.passthrough(Type.STRING); // Title
|
||||
wrapper.passthrough(Type.STRING); // Description
|
||||
InventoryPackets.toClient(wrapper.passthrough(Type.FLAT_VAR_INT_ITEM)); // Icon
|
||||
wrapper.passthrough(Type.VAR_INT); // Frame type
|
||||
int flags = wrapper.passthrough(Type.INT); // Flags
|
||||
if ((flags & 1) != 0)
|
||||
wrapper.passthrough(Type.STRING); // Background texture
|
||||
wrapper.passthrough(Type.FLOAT); // X
|
||||
wrapper.passthrough(Type.FLOAT); // Y
|
||||
}
|
||||
|
||||
wrapper.passthrough(Type.STRING_ARRAY); // Criteria
|
||||
|
||||
int arrayLength = wrapper.passthrough(Type.VAR_INT);
|
||||
for (int array = 0; array < arrayLength; array++) {
|
||||
wrapper.passthrough(Type.STRING_ARRAY); // String array
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
// Tags
|
||||
registerOutgoing(State.PLAY, 0x5B, 0x5C, new PacketRemapper() {
|
||||
@Override
|
||||
public void registerMap() {
|
||||
handler(new PacketHandler() {
|
||||
@Override
|
||||
public void handle(PacketWrapper wrapper) throws Exception {
|
||||
//TODO do the new (flower) tags have to be sent?
|
||||
int blockTagsSize = wrapper.passthrough(Type.VAR_INT);
|
||||
for (int i = 0; i < blockTagsSize; i++) {
|
||||
wrapper.passthrough(Type.STRING);
|
||||
Integer[] blockIds = wrapper.passthrough(Type.VAR_INT_ARRAY);
|
||||
for (int j = 0; j < blockIds.length; j++) {
|
||||
blockIds[j] = getNewBlockId(blockIds[j]);
|
||||
}
|
||||
}
|
||||
|
||||
int itemTagsSize = wrapper.passthrough(Type.VAR_INT);
|
||||
for (int i = 0; i < itemTagsSize; i++) {
|
||||
wrapper.passthrough(Type.STRING);
|
||||
Integer[] itemIds = wrapper.passthrough(Type.VAR_INT_ARRAY);
|
||||
for (int j = 0; j < itemIds.length; j++) {
|
||||
itemIds[j] = InventoryPackets.getNewItemId(itemIds[j]);
|
||||
}
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
int entityTagsSize = wrapper.passthrough(Type.VAR_INT); // entity tags
|
||||
for (int i = 0; i < entityTagsSize; i++) {
|
||||
wrapper.passthrough(Type.STRING);
|
||||
Integer[] entitIds = wrapper.passthrough(Type.VAR_INT_ARRAY);
|
||||
for (int j = 0; j < entitIds.length; j++) {
|
||||
entitIds[j] = EntityPackets.getNewEntityId(entitIds[j]);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
registerOutgoing(State.PLAY, 0x08, 0x09);
|
||||
registerOutgoing(State.PLAY, 0x09, 0x0A);
|
||||
registerOutgoing(State.PLAY, 0x0A, 0x0B);
|
||||
registerOutgoing(State.PLAY, 0x0B, 0x0C);
|
||||
registerOutgoing(State.PLAY, 0x0C, 0x0D);
|
||||
|
||||
registerOutgoing(State.PLAY, 0x0D, 0x0E);
|
||||
registerOutgoing(State.PLAY, 0x0E, 0x0F);
|
||||
registerOutgoing(State.PLAY, 0x0F, 0x10);
|
||||
@ -64,9 +180,9 @@ public class Protocol1_15To1_14_4 extends Protocol {
|
||||
registerOutgoing(State.PLAY, 0x11, 0x12);
|
||||
registerOutgoing(State.PLAY, 0x12, 0x13);
|
||||
registerOutgoing(State.PLAY, 0x13, 0x14);
|
||||
registerOutgoing(State.PLAY, 0x14, 0x15);
|
||||
|
||||
registerOutgoing(State.PLAY, 0x15, 0x16);
|
||||
registerOutgoing(State.PLAY, 0x16, 0x17);
|
||||
|
||||
registerOutgoing(State.PLAY, 0x17, 0x18);
|
||||
registerOutgoing(State.PLAY, 0x18, 0x19);
|
||||
registerOutgoing(State.PLAY, 0x19, 0x1A);
|
||||
@ -78,12 +194,12 @@ public class Protocol1_15To1_14_4 extends Protocol {
|
||||
registerOutgoing(State.PLAY, 0x1F, 0x20);
|
||||
registerOutgoing(State.PLAY, 0x20, 0x21);
|
||||
registerOutgoing(State.PLAY, 0x21, 0x22);
|
||||
registerOutgoing(State.PLAY, 0x22, 0x23);
|
||||
registerOutgoing(State.PLAY, 0x23, 0x24);
|
||||
|
||||
|
||||
registerOutgoing(State.PLAY, 0x24, 0x25);
|
||||
|
||||
registerOutgoing(State.PLAY, 0x26, 0x27);
|
||||
registerOutgoing(State.PLAY, 0x27, 0x28);
|
||||
|
||||
registerOutgoing(State.PLAY, 0x28, 0x29);
|
||||
registerOutgoing(State.PLAY, 0x29, 0x2A);
|
||||
registerOutgoing(State.PLAY, 0x2A, 0x2B);
|
||||
@ -114,7 +230,7 @@ public class Protocol1_15To1_14_4 extends Protocol {
|
||||
|
||||
registerOutgoing(State.PLAY, 0x44, 0x45);
|
||||
registerOutgoing(State.PLAY, 0x45, 0x46);
|
||||
registerOutgoing(State.PLAY, 0x46, 0x47);
|
||||
|
||||
registerOutgoing(State.PLAY, 0x47, 0x48);
|
||||
registerOutgoing(State.PLAY, 0x48, 0x49);
|
||||
registerOutgoing(State.PLAY, 0x49, 0x4A);
|
||||
@ -124,21 +240,30 @@ public class Protocol1_15To1_14_4 extends Protocol {
|
||||
registerOutgoing(State.PLAY, 0x4D, 0x4E);
|
||||
registerOutgoing(State.PLAY, 0x4E, 0x4F);
|
||||
registerOutgoing(State.PLAY, 0x4F, 0x50);
|
||||
registerOutgoing(State.PLAY, 0x50, 0x51);
|
||||
|
||||
|
||||
registerOutgoing(State.PLAY, 0x52, 0x53);
|
||||
registerOutgoing(State.PLAY, 0x53, 0x54);
|
||||
registerOutgoing(State.PLAY, 0x54, 0x55);
|
||||
registerOutgoing(State.PLAY, 0x55, 0x56);
|
||||
registerOutgoing(State.PLAY, 0x56, 0x57);
|
||||
registerOutgoing(State.PLAY, 0x57, 0x58);
|
||||
|
||||
registerOutgoing(State.PLAY, 0x58, 0x59);
|
||||
registerOutgoing(State.PLAY, 0x59, 0x5A);
|
||||
registerOutgoing(State.PLAY, 0x5A, 0x5B);
|
||||
registerOutgoing(State.PLAY, 0x5B, 0x5C);
|
||||
|
||||
|
||||
registerOutgoing(State.PLAY, 0x5C, 0x08);
|
||||
}
|
||||
|
||||
public static int getNewBlockId(int id) {
|
||||
int newId = MappingData.blockMappings.getNewBlock(id);
|
||||
if (newId == -1) {
|
||||
Via.getPlatform().getLogger().warning("Missing 1.15 block for 1.14 block " + id);
|
||||
return 0;
|
||||
}
|
||||
return newId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void init(UserConnection userConnection) {
|
||||
userConnection.put(new EntityTracker(userConnection));
|
||||
|
@ -1,82 +1,26 @@
|
||||
package us.myles.ViaVersion.protocols.protocol1_15to1_14_4.data;
|
||||
|
||||
import com.google.gson.JsonArray;
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.common.collect.BiMap;
|
||||
import com.google.common.collect.HashBiMap;
|
||||
import com.google.gson.JsonObject;
|
||||
import us.myles.ViaVersion.api.Via;
|
||||
import us.myles.ViaVersion.util.GsonUtil;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.util.Arrays;
|
||||
|
||||
public class MappingData {
|
||||
|
||||
public static SoundMappings soundMappings;
|
||||
public static BiMap<Integer, Integer> oldToNewItems = HashBiMap.create();
|
||||
public static us.myles.ViaVersion.protocols.protocol1_14to1_13_2.data.MappingData.BlockMappings blockMappings;
|
||||
public static us.myles.ViaVersion.protocols.protocol1_14to1_13_2.data.MappingData.SoundMappings soundMappings;
|
||||
|
||||
public static void init() {
|
||||
JsonObject mapping1_14 = loadData("mapping-1.14.json");
|
||||
JsonObject mapping1_15 = loadData("mapping-1.15.json");
|
||||
JsonObject mapping1_14 = us.myles.ViaVersion.protocols.protocol1_14to1_13_2.data.MappingData.loadData("mapping-1.14.json");
|
||||
JsonObject mapping1_15 = us.myles.ViaVersion.protocols.protocol1_14to1_13_2.data.MappingData.loadData("mapping-1.15.json");
|
||||
|
||||
// New blockstates have just been appended to the old, so mappings are not (yet) necessary.
|
||||
|
||||
Via.getPlatform().getLogger().info("Loading 1.14 -> 1.15 block mapping...");
|
||||
blockMappings = new us.myles.ViaVersion.protocols.protocol1_14to1_13_2.data.MappingData.BlockMappingsShortArray(mapping1_14.getAsJsonObject("blocks"), mapping1_15.getAsJsonObject("blocks"));
|
||||
Via.getPlatform().getLogger().info("Loading 1.14 -> 1.15 item mapping...");
|
||||
us.myles.ViaVersion.protocols.protocol1_14to1_13_2.data.MappingData.mapIdentifiers(oldToNewItems, mapping1_14.getAsJsonObject("items"), mapping1_15.getAsJsonObject("items"));
|
||||
Via.getPlatform().getLogger().info("Loading 1.14 -> 1.15 sound mapping...");
|
||||
soundMappings = new SoundMappingShortArray(mapping1_14.getAsJsonArray("sounds"), mapping1_15.getAsJsonArray("sounds"));
|
||||
}
|
||||
|
||||
private static JsonObject loadData(String name) {
|
||||
InputStream stream = MappingData.class.getClassLoader().getResourceAsStream("assets/viaversion/data/" + name);
|
||||
InputStreamReader reader = new InputStreamReader(stream);
|
||||
try {
|
||||
return GsonUtil.getGson().fromJson(reader, JsonObject.class);
|
||||
} finally {
|
||||
try {
|
||||
reader.close();
|
||||
} catch (IOException ignored) {
|
||||
// Ignored
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void mapIdentifiers(short[] output, JsonArray oldIdentifiers, JsonArray newIdentifiers) {
|
||||
for (int i = 0; i < oldIdentifiers.size(); i++) {
|
||||
JsonElement v = oldIdentifiers.get(i);
|
||||
Integer index = findIndex(newIdentifiers, v.getAsString());
|
||||
if (index == null) {
|
||||
if (Via.getManager().isDebug()) {
|
||||
Via.getPlatform().getLogger().warning("No key for " + v + " :( ");
|
||||
}
|
||||
continue;
|
||||
}
|
||||
output[i] = index.shortValue();
|
||||
}
|
||||
}
|
||||
|
||||
private static Integer findIndex(JsonArray array, String value) {
|
||||
for (int i = 0; i < array.size(); i++) {
|
||||
JsonElement v = array.get(i);
|
||||
if (v.getAsString().equals(value)) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public interface SoundMappings {
|
||||
int getNewSound(int old);
|
||||
}
|
||||
|
||||
private static class SoundMappingShortArray implements SoundMappings {
|
||||
private short[] oldToNew;
|
||||
|
||||
private SoundMappingShortArray(JsonArray mapping1_14, JsonArray mapping1_15) {
|
||||
oldToNew = new short[mapping1_14.size()];
|
||||
Arrays.fill(oldToNew, (short) -1);
|
||||
mapIdentifiers(oldToNew, mapping1_14, mapping1_15);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getNewSound(int old) {
|
||||
return old >= 0 && old < oldToNew.length ? oldToNew[old] : -1;
|
||||
}
|
||||
soundMappings = new us.myles.ViaVersion.protocols.protocol1_14to1_13_2.data.MappingData.SoundMappingShortArray(mapping1_14.getAsJsonArray("sounds"), mapping1_15.getAsJsonArray("sounds"));
|
||||
}
|
||||
}
|
||||
|
@ -1,12 +1,210 @@
|
||||
package us.myles.ViaVersion.protocols.protocol1_15to1_14_4.packets;
|
||||
|
||||
import us.myles.ViaVersion.api.PacketWrapper;
|
||||
import us.myles.ViaVersion.api.Via;
|
||||
import us.myles.ViaVersion.api.minecraft.item.Item;
|
||||
import us.myles.ViaVersion.api.protocol.Protocol;
|
||||
import us.myles.ViaVersion.api.remapper.PacketHandler;
|
||||
import us.myles.ViaVersion.api.remapper.PacketRemapper;
|
||||
import us.myles.ViaVersion.api.type.Type;
|
||||
import us.myles.ViaVersion.packets.State;
|
||||
import us.myles.ViaVersion.protocols.protocol1_15to1_14_4.data.MappingData;
|
||||
|
||||
public class InventoryPackets {
|
||||
|
||||
public static void register(Protocol protocol) {
|
||||
//TODO eeeeverything
|
||||
// Window items packet
|
||||
protocol.registerOutgoing(State.PLAY, 0x14, 0x15, new PacketRemapper() {
|
||||
@Override
|
||||
public void registerMap() {
|
||||
map(Type.UNSIGNED_BYTE); // 0 - Window ID
|
||||
map(Type.FLAT_VAR_INT_ITEM_ARRAY); // 1 - Window Values
|
||||
|
||||
handler(new PacketHandler() {
|
||||
@Override
|
||||
public void handle(PacketWrapper wrapper) throws Exception {
|
||||
Item[] stacks = wrapper.get(Type.FLAT_VAR_INT_ITEM_ARRAY, 0);
|
||||
for (Item stack : stacks) toClient(stack);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
// Trade list packet
|
||||
protocol.registerOutgoing(State.PLAY, 0x27, 0x28, new PacketRemapper() {
|
||||
@Override
|
||||
public void registerMap() {
|
||||
handler(new PacketHandler() {
|
||||
@Override
|
||||
public void handle(PacketWrapper wrapper) throws Exception {
|
||||
wrapper.passthrough(Type.VAR_INT);
|
||||
int size = wrapper.passthrough(Type.UNSIGNED_BYTE);
|
||||
for (int i = 0; i < size; i++) {
|
||||
Item input = wrapper.passthrough(Type.FLAT_VAR_INT_ITEM);
|
||||
toClient(input);
|
||||
|
||||
Item output = wrapper.passthrough(Type.FLAT_VAR_INT_ITEM);
|
||||
toClient(output);
|
||||
|
||||
if (wrapper.passthrough(Type.BOOLEAN)) { // Has second item
|
||||
// Second Item
|
||||
Item second = wrapper.passthrough(Type.FLAT_VAR_INT_ITEM);
|
||||
toClient(second);
|
||||
}
|
||||
|
||||
wrapper.passthrough(Type.BOOLEAN); // Trade disabled
|
||||
wrapper.passthrough(Type.INT); // Number of tools uses
|
||||
wrapper.passthrough(Type.INT); // Maximum number of trade uses
|
||||
|
||||
wrapper.passthrough(Type.INT);
|
||||
wrapper.passthrough(Type.INT);
|
||||
wrapper.passthrough(Type.FLOAT);
|
||||
}
|
||||
|
||||
wrapper.passthrough(Type.VAR_INT);
|
||||
wrapper.passthrough(Type.VAR_INT);
|
||||
wrapper.passthrough(Type.BOOLEAN);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
// Set slot packet
|
||||
protocol.registerOutgoing(State.PLAY, 0x16, 0x17, new PacketRemapper() {
|
||||
@Override
|
||||
public void registerMap() {
|
||||
map(Type.BYTE); // 0 - Window ID
|
||||
map(Type.SHORT); // 1 - Slot ID
|
||||
map(Type.FLAT_VAR_INT_ITEM); // 2 - Slot Value
|
||||
|
||||
handler(new PacketHandler() {
|
||||
@Override
|
||||
public void handle(PacketWrapper wrapper) throws Exception {
|
||||
toClient(wrapper.get(Type.FLAT_VAR_INT_ITEM, 0));
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
// Entity Equipment Packet
|
||||
protocol.registerOutgoing(State.PLAY, 0x46, 0x47, new PacketRemapper() {
|
||||
@Override
|
||||
public void registerMap() {
|
||||
map(Type.VAR_INT); // 0 - Entity ID
|
||||
map(Type.VAR_INT); // 1 - Slot ID
|
||||
map(Type.FLAT_VAR_INT_ITEM); // 2 - Item
|
||||
|
||||
handler(new PacketHandler() {
|
||||
@Override
|
||||
public void handle(PacketWrapper wrapper) throws Exception {
|
||||
toClient(wrapper.get(Type.FLAT_VAR_INT_ITEM, 0));
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
// Declare Recipes
|
||||
protocol.registerOutgoing(State.PLAY, 0x5A, 0x5B, new PacketRemapper() {
|
||||
@Override
|
||||
public void registerMap() {
|
||||
handler(new PacketHandler() {
|
||||
@Override
|
||||
public void handle(PacketWrapper wrapper) throws Exception {
|
||||
int size = wrapper.passthrough(Type.VAR_INT);
|
||||
for (int i = 0; i < size; i++) {
|
||||
String type = wrapper.passthrough(Type.STRING).replace("minecraft:", "");
|
||||
String id = wrapper.passthrough(Type.STRING);
|
||||
|
||||
switch (type) {
|
||||
case "crafting_shapeless": {
|
||||
wrapper.passthrough(Type.STRING); // Group
|
||||
|
||||
int ingredientsNo = wrapper.passthrough(Type.VAR_INT);
|
||||
for (int j = 0; j < ingredientsNo; j++) {
|
||||
Item[] items = wrapper.passthrough(Type.FLAT_VAR_INT_ITEM_ARRAY_VAR_INT); // Ingredients
|
||||
for (Item item : items) toClient(item);
|
||||
}
|
||||
toClient(wrapper.passthrough(Type.FLAT_VAR_INT_ITEM)); // Result
|
||||
|
||||
break;
|
||||
}
|
||||
case "crafting_shaped": {
|
||||
int ingredientsNo = wrapper.passthrough(Type.VAR_INT) * wrapper.passthrough(Type.VAR_INT);
|
||||
wrapper.passthrough(Type.STRING); // Group
|
||||
|
||||
for (int j = 0; j < ingredientsNo; j++) {
|
||||
Item[] items = wrapper.passthrough(Type.FLAT_VAR_INT_ITEM_ARRAY_VAR_INT); // Ingredients
|
||||
for (Item item : items) toClient(item);
|
||||
}
|
||||
toClient(wrapper.passthrough(Type.FLAT_VAR_INT_ITEM)); // Result
|
||||
|
||||
break;
|
||||
}
|
||||
case "blasting":
|
||||
case "smoking":
|
||||
case "campfire_cooking":
|
||||
case "smelting": {
|
||||
wrapper.passthrough(Type.STRING); // Group
|
||||
|
||||
Item[] items = wrapper.passthrough(Type.FLAT_VAR_INT_ITEM_ARRAY_VAR_INT); // Ingredients
|
||||
|
||||
for (Item item : items) toClient(item);
|
||||
toClient(wrapper.passthrough(Type.FLAT_VAR_INT_ITEM));
|
||||
wrapper.passthrough(Type.FLOAT); // EXP
|
||||
|
||||
wrapper.passthrough(Type.VAR_INT); // Cooking time
|
||||
|
||||
break;
|
||||
}
|
||||
case "stonecutting": {
|
||||
wrapper.passthrough(Type.STRING);
|
||||
Item[] items = wrapper.passthrough(Type.FLAT_VAR_INT_ITEM_ARRAY_VAR_INT); // Ingredients
|
||||
for (Item item : items) toClient(item);
|
||||
toClient(wrapper.passthrough(Type.FLAT_VAR_INT_ITEM));
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
// Click window packet
|
||||
protocol.registerIncoming(State.PLAY, 0x09, 0x09, new PacketRemapper() {
|
||||
@Override
|
||||
public void registerMap() {
|
||||
map(Type.UNSIGNED_BYTE); // 0 - Window ID
|
||||
map(Type.SHORT); // 1 - Slot
|
||||
map(Type.BYTE); // 2 - Button
|
||||
map(Type.SHORT); // 3 - Action number
|
||||
map(Type.VAR_INT); // 4 - Mode
|
||||
map(Type.FLAT_VAR_INT_ITEM); // 5 - Clicked Item
|
||||
|
||||
handler(new PacketHandler() {
|
||||
@Override
|
||||
public void handle(PacketWrapper wrapper) throws Exception {
|
||||
toServer(wrapper.get(Type.FLAT_VAR_INT_ITEM, 0));
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
// Creative Inventory Action
|
||||
protocol.registerIncoming(State.PLAY, 0x26, 0x26, new PacketRemapper() {
|
||||
@Override
|
||||
public void registerMap() {
|
||||
map(Type.SHORT); // 0 - Slot
|
||||
map(Type.FLAT_VAR_INT_ITEM); // 1 - Clicked Item
|
||||
|
||||
handler(new PacketHandler() {
|
||||
@Override
|
||||
public void handle(PacketWrapper wrapper) throws Exception {
|
||||
toServer(wrapper.get(Type.FLAT_VAR_INT_ITEM, 0));
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public static void toClient(Item item) {
|
||||
@ -20,10 +218,16 @@ public class InventoryPackets {
|
||||
}
|
||||
|
||||
public static int getNewItemId(int id) {
|
||||
return id;
|
||||
Integer newId = MappingData.oldToNewItems.get(id);
|
||||
if (newId == null) {
|
||||
Via.getPlatform().getLogger().warning("Missing 1.15 item for 1.14 item " + id);
|
||||
return 1;
|
||||
}
|
||||
return newId;
|
||||
}
|
||||
|
||||
public static int getOldItemId(int id) {
|
||||
return id;
|
||||
Integer oldId = MappingData.oldToNewItems.inverse().get(id);
|
||||
return oldId != null ? oldId : 1;
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,78 @@
|
||||
package us.myles.ViaVersion.protocols.protocol1_15to1_14_4.packets;
|
||||
|
||||
import us.myles.ViaVersion.api.PacketWrapper;
|
||||
import us.myles.ViaVersion.api.protocol.Protocol;
|
||||
import us.myles.ViaVersion.api.remapper.PacketHandler;
|
||||
import us.myles.ViaVersion.api.remapper.PacketRemapper;
|
||||
import us.myles.ViaVersion.api.type.Type;
|
||||
import us.myles.ViaVersion.packets.State;
|
||||
import us.myles.ViaVersion.protocols.protocol1_14to1_13_2.packets.InventoryPackets;
|
||||
import us.myles.ViaVersion.protocols.protocol1_15to1_14_4.Protocol1_15To1_14_4;
|
||||
|
||||
public class WorldPackets {
|
||||
|
||||
public static void register(Protocol protocol) {
|
||||
// Block Action
|
||||
protocol.registerOutgoing(State.PLAY, 0x0A, 0x0B, new PacketRemapper() {
|
||||
@Override
|
||||
public void registerMap() {
|
||||
map(Type.POSITION1_14); // Location
|
||||
map(Type.UNSIGNED_BYTE); // Action id
|
||||
map(Type.UNSIGNED_BYTE); // Action param
|
||||
map(Type.VAR_INT); // Block id - /!\ NOT BLOCK STATE
|
||||
handler(new PacketHandler() {
|
||||
@Override
|
||||
public void handle(PacketWrapper wrapper) throws Exception {
|
||||
wrapper.set(Type.VAR_INT, 0, Protocol1_15To1_14_4.getNewBlockId(wrapper.get(Type.VAR_INT, 0)));
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
// Effect
|
||||
protocol.registerOutgoing(State.PLAY, 0x22, 0x23, new PacketRemapper() {
|
||||
@Override
|
||||
public void registerMap() {
|
||||
map(Type.INT); // Effect Id
|
||||
map(Type.POSITION1_14); // Location
|
||||
map(Type.INT); // Data
|
||||
handler(new PacketHandler() {
|
||||
@Override
|
||||
public void handle(PacketWrapper wrapper) throws Exception {
|
||||
int id = wrapper.get(Type.INT, 0);
|
||||
if (id == 1010) { // Play record
|
||||
int data = wrapper.get(Type.INT, 1);
|
||||
wrapper.set(Type.INT, 1, InventoryPackets.getNewItemId(data));
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
// Spawn Particle
|
||||
protocol.registerOutgoing(State.PLAY, 0x23, 0x24, new PacketRemapper() {
|
||||
@Override
|
||||
public void registerMap() {
|
||||
map(Type.INT); // 0 - Particle ID
|
||||
map(Type.BOOLEAN); // 1 - Long Distance
|
||||
map(Type.FLOAT); // 2 - X
|
||||
map(Type.FLOAT); // 3 - Y
|
||||
map(Type.FLOAT); // 4 - Z
|
||||
map(Type.FLOAT); // 5 - Offset X
|
||||
map(Type.FLOAT); // 6 - Offset Y
|
||||
map(Type.FLOAT); // 7 - Offset Z
|
||||
map(Type.FLOAT); // 8 - Particle Data
|
||||
map(Type.INT); // 9 - Particle Count
|
||||
handler(new PacketHandler() {
|
||||
@Override
|
||||
public void handle(PacketWrapper wrapper) throws Exception {
|
||||
int id = wrapper.get(Type.INT, 0);
|
||||
if (id == 27) {
|
||||
InventoryPackets.toClient(wrapper.passthrough(Type.FLAT_VAR_INT_ITEM));
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user