3
0
Mirror von https://github.com/ViaVersion/ViaVersion.git synchronisiert 2024-11-03 14:50:30 +01:00

trying recipes, currently not working

Dieser Commit ist enthalten in:
creeper123123321 2018-12-10 10:11:56 -02:00
Ursprung 43e93e74b1
Commit 649676e811
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: 0AC57D54786721D1
3 geänderte Dateien mit 23274 neuen und 7 gelöschten Zeilen

Datei anzeigen

@ -21,6 +21,7 @@ import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.blockconnections.Conne
import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.blockconnections.providers.BlockConnectionProvider; import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.blockconnections.providers.BlockConnectionProvider;
import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.blockconnections.providers.PacketBlockConnectionProvider; import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.blockconnections.providers.PacketBlockConnectionProvider;
import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.data.MappingData; import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.data.MappingData;
import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.data.RecipeData;
import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.packets.EntityPackets; import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.packets.EntityPackets;
import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.packets.InventoryPackets; import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.packets.InventoryPackets;
import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.packets.WorldPackets; import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.packets.WorldPackets;
@ -99,6 +100,67 @@ public class Protocol1_13To1_12_2 extends Protocol {
} }
} }
}).send(Protocol1_13To1_12_2.class); }).send(Protocol1_13To1_12_2.class);
w.create(0x54, new ValueCreator() { // Declare recipes
@Override
public void write(PacketWrapper wrapper) throws Exception {
wrapper.write(Type.VAR_INT, RecipeData.recipes.size());
for (Map.Entry<String, RecipeData.Recipe> entry : RecipeData.recipes.entrySet()) {
wrapper.write(Type.STRING, entry.getKey()); // Id
wrapper.write(Type.STRING, entry.getValue().getType());
switch (entry.getValue().getType()) {
case "crafting_shapeless": {
wrapper.write(Type.STRING, entry.getValue().getGroup());
wrapper.write(Type.VAR_INT, entry.getValue().getIngredients().length);
for (Item[] ingredient : entry.getValue().getIngredients()) {
Item[] clone = ingredient.clone(); // Clone because array and item is mutable
for (int i = 0; i < clone.length; i++) {
clone[i] = new Item(clone[i].getId(), clone[i].getAmount(),
(short) 0, null);
}
wrapper.write(Type.FLAT_ITEM_ARRAY_VAR_INT, clone);
}
wrapper.write(Type.FLAT_ITEM, new Item(
entry.getValue().getResult().getId(),
entry.getValue().getResult().getAmount(), (short) 0, null));
break;
}
case "crafting_shaped": {
wrapper.write(Type.VAR_INT, entry.getValue().getWidth());
wrapper.write(Type.VAR_INT, entry.getValue().getHeight());
wrapper.write(Type.STRING, entry.getValue().getGroup());
for (Item[] ingredient : entry.getValue().getIngredients()) {
Item[] clone = ingredient.clone(); // Clone because array and item is mutable
for (int i = 0; i < clone.length; i++) {
clone[i] = new Item(clone[i].getId(), clone[i].getAmount(),
(short) 0, null);
}
wrapper.write(Type.FLAT_ITEM_ARRAY_VAR_INT, clone);
}
wrapper.write(Type.FLAT_ITEM, new Item(
entry.getValue().getResult().getId(),
entry.getValue().getResult().getAmount(), (short) 0, null));
break;
}
case "smelting": {
wrapper.write(Type.STRING, entry.getValue().getGroup());
Item[] clone = entry.getValue().getIngredient().clone(); // Clone because array and item is mutable
for (int i = 0; i < clone.length; i++) {
clone[i] = new Item(clone[i].getId(), clone[i].getAmount(),
(short) 0, null);
}
wrapper.write(Type.FLAT_ITEM_ARRAY_VAR_INT, clone);
wrapper.write(Type.FLAT_ITEM, new Item(
entry.getValue().getResult().getId(),
entry.getValue().getResult().getAmount(), (short) 0, null));
wrapper.write(Type.FLOAT, entry.getValue().getExperience());
wrapper.write(Type.VAR_INT, entry.getValue().getCookingTime());
break;
}
}
}
}
}).send(Protocol1_13To1_12_2.class);
} }
}; };
@ -126,6 +188,7 @@ public class Protocol1_13To1_12_2 extends Protocol {
SCOREBOARD_TEAM_NAME_REWRITE.put(ChatColor.WHITE, '?'); SCOREBOARD_TEAM_NAME_REWRITE.put(ChatColor.WHITE, '?');
MappingData.init(); MappingData.init();
ConnectionData.init(); ConnectionData.init();
RecipeData.init();
} }
@Override @Override
@ -429,11 +492,11 @@ public class Protocol1_13To1_12_2 extends Protocol {
registerOutgoing(State.PLAY, 0x2B, 0x2D, new PacketRemapper() { registerOutgoing(State.PLAY, 0x2B, 0x2D, new PacketRemapper() {
@Override @Override
public void registerMap() { public void registerMap() {
map(Type.BYTE);
handler(new PacketHandler() { handler(new PacketHandler() {
@Override @Override
public void handle(PacketWrapper wrapper) throws Exception { public void handle(PacketWrapper wrapper) throws Exception {
// TODO This packet changed wrapper.write(Type.STRING, "viaversion:legacy/" + wrapper.read(Type.VAR_INT));
wrapper.cancel();
} }
}); });
} }
@ -464,11 +527,28 @@ public class Protocol1_13To1_12_2 extends Protocol {
registerOutgoing(State.PLAY, 0x31, 0x34, new PacketRemapper() { registerOutgoing(State.PLAY, 0x31, 0x34, new PacketRemapper() {
@Override @Override
public void registerMap() { public void registerMap() {
map(Type.VAR_INT); // action
map(Type.BOOLEAN); // crafting book open
map(Type.BOOLEAN); // crafting filter active
create(new ValueCreator() {
@Override
public void write(PacketWrapper wrapper) throws Exception {
wrapper.write(Type.BOOLEAN, false); // smelting book open
wrapper.write(Type.BOOLEAN, false); // smelting filter active
}
});
handler(new PacketHandler() { handler(new PacketHandler() {
@Override @Override
public void handle(PacketWrapper wrapper) throws Exception { public void handle(PacketWrapper wrapper) throws Exception {
// TODO: This has changed >.> int action = wrapper.get(Type.VAR_INT, 0);
wrapper.cancel(); for (int i = 0; i < (action == 0 ? 2 : 1); i++) {
Integer[] ids = wrapper.read(Type.VAR_INT_ARRAY);
String[] stringIds = new String[ids.length];
for (int j = 0; j < ids.length; j++) {
stringIds[j] = "viaversion:legacy/" + ids[j];
}
wrapper.write(Type.STRING_ARRAY, stringIds);
}
} }
}); });
} }
@ -838,8 +918,13 @@ public class Protocol1_13To1_12_2 extends Protocol {
handler(new PacketHandler() { handler(new PacketHandler() {
@Override @Override
public void handle(PacketWrapper wrapper) throws Exception { public void handle(PacketWrapper wrapper) throws Exception {
// TODO: This has changed >.> map(Type.BYTE); // Window id
wrapper.cancel(); map(Type.STRING, new ValueTransformer<String, Integer>(Type.VAR_INT) {
@Override
public Integer transform(PacketWrapper wrapper, String inputValue) throws Exception {
return Integer.parseInt(inputValue.substring(18));
}
});
} }
}); });
} }
@ -860,7 +945,9 @@ public class Protocol1_13To1_12_2 extends Protocol {
public void handle(PacketWrapper wrapper) throws Exception { public void handle(PacketWrapper wrapper) throws Exception {
int type = wrapper.get(Type.VAR_INT, 0); int type = wrapper.get(Type.VAR_INT, 0);
if (type == 1) { if (type == 0) {
wrapper.write(Type.VAR_INT, Integer.parseInt(wrapper.read(Type.STRING).substring(18)));
} if (type == 1) {
wrapper.passthrough(Type.BOOLEAN); // Crafting Recipe Book Open wrapper.passthrough(Type.BOOLEAN); // Crafting Recipe Book Open
wrapper.passthrough(Type.BOOLEAN); // Crafting Recipe Filter Active wrapper.passthrough(Type.BOOLEAN); // Crafting Recipe Filter Active
wrapper.read(Type.BOOLEAN); // Smelting Recipe Book Open | IGNORE NEW 1.13 FIELD wrapper.read(Type.BOOLEAN); // Smelting Recipe Book Open | IGNORE NEW 1.13 FIELD

Datei anzeigen

@ -0,0 +1,55 @@
package us.myles.ViaVersion.protocols.protocol1_13to1_12_2.data;
import com.google.gson.reflect.TypeToken;
import lombok.Data;
import lombok.NonNull;
import us.myles.ViaVersion.api.minecraft.item.Item;
import us.myles.ViaVersion.util.GsonUtil;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.Map;
public class RecipeData {
public static Map<String, Recipe> recipes;
public static void init() {
InputStream stream = MappingData.class.getClassLoader()
.getResourceAsStream("assets/viaversion/data/itemrecipes1_12_2to1_13.json");
InputStreamReader reader = new InputStreamReader(stream);
try {
recipes = GsonUtil.getGson().fromJson(
reader,
new TypeToken<Map<String, Recipe>>() {
}.getType()
);
} finally {
try {
reader.close();
} catch (IOException ignored) {
// Ignored
}
}
}
// todo remove this debug
public static void main(String[] args) {
init();
System.out.println(recipes);
}
@Data
public static class Recipe {
@NonNull
private String type;
private String group = "";
private int width;
private int height;
private float experience;
private int cookingTime;
private Item[] ingredient;
private Item[][] ingredients;
private Item result;
}
}

Datei-Diff unterdrückt, da er zu groß ist Diff laden