mirror of
https://github.com/ViaVersion/ViaVersion.git
synced 2024-12-23 08:57:39 +01:00
Reduce RecipeRewriter extends chain
This commit is contained in:
parent
fb0381e76a
commit
1faf1f3f49
@ -22,7 +22,6 @@ import com.viaversion.viaversion.api.type.Type;
|
||||
import com.viaversion.viaversion.protocols.protocol1_13_1to1_13.Protocol1_13_1To1_13;
|
||||
import com.viaversion.viaversion.protocols.protocol1_13to1_12_2.ClientboundPackets1_13;
|
||||
import com.viaversion.viaversion.protocols.protocol1_13to1_12_2.ServerboundPackets1_13;
|
||||
import com.viaversion.viaversion.protocols.protocol1_13to1_12_2.data.RecipeRewriter1_13_2;
|
||||
import com.viaversion.viaversion.rewriter.ItemRewriter;
|
||||
import com.viaversion.viaversion.rewriter.RecipeRewriter;
|
||||
|
||||
@ -72,7 +71,7 @@ public class InventoryPackets extends ItemRewriter<ClientboundPackets1_13, Serve
|
||||
|
||||
registerEntityEquipment(ClientboundPackets1_13.ENTITY_EQUIPMENT, Type.FLAT_ITEM);
|
||||
|
||||
RecipeRewriter<ClientboundPackets1_13> recipeRewriter = new RecipeRewriter1_13_2<>(protocol);
|
||||
RecipeRewriter<ClientboundPackets1_13> recipeRewriter = new RecipeRewriter<>(protocol);
|
||||
protocol.registerClientbound(ClientboundPackets1_13.DECLARE_RECIPES, wrapper -> {
|
||||
int size = wrapper.passthrough(Type.VAR_INT);
|
||||
for (int i = 0; i < size; i++) {
|
||||
|
@ -401,59 +401,56 @@ public class Protocol1_13To1_12_2 extends AbstractProtocol<ClientboundPackets1_1
|
||||
wrapper.write(Type.STRING_ARRAY, stringIds);
|
||||
}
|
||||
if (action == 0) {
|
||||
wrapper.create(ClientboundPackets1_13.DECLARE_RECIPES, new PacketHandler() { // Declare recipes
|
||||
@Override
|
||||
public void handle(PacketWrapper wrapper) throws Exception {
|
||||
wrapper.write(Type.VAR_INT, RecipeData.recipes.size());
|
||||
wrapper.create(ClientboundPackets1_13.DECLARE_RECIPES, wrapper1 -> {
|
||||
wrapper1.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());
|
||||
wrapper1.write(Type.STRING, entry.getKey()); // Id
|
||||
wrapper1.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);
|
||||
wrapper1.write(Type.STRING, entry.getValue().getGroup());
|
||||
wrapper1.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++) {
|
||||
if (clone[i] == null) continue;
|
||||
clone[i] = new DataItem(clone[i]);
|
||||
}
|
||||
wrapper.write(Type.FLAT_ITEM_ARRAY_VAR_INT, clone);
|
||||
wrapper1.write(Type.FLAT_ITEM_ARRAY_VAR_INT, clone);
|
||||
}
|
||||
wrapper.write(Type.FLAT_ITEM, new DataItem(entry.getValue().getResult()));
|
||||
wrapper1.write(Type.FLAT_ITEM, new DataItem(entry.getValue().getResult()));
|
||||
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());
|
||||
wrapper1.write(Type.VAR_INT, entry.getValue().getWidth());
|
||||
wrapper1.write(Type.VAR_INT, entry.getValue().getHeight());
|
||||
wrapper1.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++) {
|
||||
if (clone[i] == null) continue;
|
||||
clone[i] = new DataItem(clone[i]);
|
||||
}
|
||||
wrapper.write(Type.FLAT_ITEM_ARRAY_VAR_INT, clone);
|
||||
wrapper1.write(Type.FLAT_ITEM_ARRAY_VAR_INT, clone);
|
||||
}
|
||||
wrapper.write(Type.FLAT_ITEM, new DataItem(entry.getValue().getResult()));
|
||||
wrapper1.write(Type.FLAT_ITEM, new DataItem(entry.getValue().getResult()));
|
||||
break;
|
||||
}
|
||||
case "smelting": {
|
||||
wrapper.write(Type.STRING, entry.getValue().getGroup());
|
||||
wrapper1.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++) {
|
||||
if (clone[i] == null) continue;
|
||||
clone[i] = new DataItem(clone[i]);
|
||||
}
|
||||
wrapper.write(Type.FLAT_ITEM_ARRAY_VAR_INT, clone);
|
||||
wrapper.write(Type.FLAT_ITEM, new DataItem(entry.getValue().getResult()));
|
||||
wrapper.write(Type.FLOAT, entry.getValue().getExperience());
|
||||
wrapper.write(Type.VAR_INT, entry.getValue().getCookingTime());
|
||||
wrapper1.write(Type.FLAT_ITEM_ARRAY_VAR_INT, clone);
|
||||
wrapper1.write(Type.FLAT_ITEM, new DataItem(entry.getValue().getResult()));
|
||||
wrapper1.write(Type.FLOAT, entry.getValue().getExperience());
|
||||
wrapper1.write(Type.VAR_INT, entry.getValue().getCookingTime());
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}).send(Protocol1_13To1_12_2.class);
|
||||
}
|
||||
});
|
||||
|
@ -1,75 +0,0 @@
|
||||
/*
|
||||
* This file is part of ViaVersion - https://github.com/ViaVersion/ViaVersion
|
||||
* Copyright (C) 2016-2023 ViaVersion and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.viaversion.viaversion.protocols.protocol1_13to1_12_2.data;
|
||||
|
||||
import com.viaversion.viaversion.api.minecraft.item.Item;
|
||||
import com.viaversion.viaversion.api.protocol.Protocol;
|
||||
import com.viaversion.viaversion.api.protocol.packet.ClientboundPacketType;
|
||||
import com.viaversion.viaversion.api.protocol.packet.PacketWrapper;
|
||||
import com.viaversion.viaversion.api.type.Type;
|
||||
import com.viaversion.viaversion.rewriter.RecipeRewriter;
|
||||
|
||||
/**
|
||||
* For 1.13.2, not 1.13 (1.13 reads recipe type and id in swapped order)!
|
||||
*/
|
||||
public class RecipeRewriter1_13_2<C extends ClientboundPacketType> extends RecipeRewriter<C> {
|
||||
|
||||
public RecipeRewriter1_13_2(Protocol<C, ?, ?, ?> protocol) {
|
||||
super(protocol);
|
||||
recipeHandlers.put("crafting_shapeless", this::handleCraftingShapeless);
|
||||
recipeHandlers.put("crafting_shaped", this::handleCraftingShaped);
|
||||
recipeHandlers.put("smelting", this::handleSmelting);
|
||||
}
|
||||
|
||||
public void handleSmelting(PacketWrapper wrapper) throws Exception {
|
||||
wrapper.passthrough(Type.STRING); // Group
|
||||
Item[] items = wrapper.passthrough(Type.FLAT_VAR_INT_ITEM_ARRAY_VAR_INT); // Ingredients
|
||||
for (Item item : items) {
|
||||
rewrite(item);
|
||||
}
|
||||
|
||||
rewrite(wrapper.passthrough(Type.FLAT_VAR_INT_ITEM)); // Result
|
||||
|
||||
wrapper.passthrough(Type.FLOAT); // EXP
|
||||
wrapper.passthrough(Type.VAR_INT); // Cooking time
|
||||
}
|
||||
|
||||
public void handleCraftingShaped(PacketWrapper wrapper) throws Exception {
|
||||
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) {
|
||||
rewrite(item);
|
||||
}
|
||||
}
|
||||
rewrite(wrapper.passthrough(Type.FLAT_VAR_INT_ITEM)); // Result
|
||||
}
|
||||
|
||||
public void handleCraftingShapeless(PacketWrapper wrapper) throws Exception {
|
||||
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) {
|
||||
rewrite(item);
|
||||
}
|
||||
}
|
||||
rewrite(wrapper.passthrough(Type.FLAT_VAR_INT_ITEM)); // Result
|
||||
}
|
||||
}
|
@ -1,47 +0,0 @@
|
||||
/*
|
||||
* This file is part of ViaVersion - https://github.com/ViaVersion/ViaVersion
|
||||
* Copyright (C) 2016-2023 ViaVersion and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.viaversion.viaversion.protocols.protocol1_14to1_13_2.data;
|
||||
|
||||
import com.viaversion.viaversion.api.minecraft.item.Item;
|
||||
import com.viaversion.viaversion.api.protocol.Protocol;
|
||||
import com.viaversion.viaversion.api.protocol.packet.ClientboundPacketType;
|
||||
import com.viaversion.viaversion.api.protocol.packet.PacketWrapper;
|
||||
import com.viaversion.viaversion.api.type.Type;
|
||||
import com.viaversion.viaversion.protocols.protocol1_13to1_12_2.data.RecipeRewriter1_13_2;
|
||||
|
||||
public class RecipeRewriter1_14<C extends ClientboundPacketType> extends RecipeRewriter1_13_2<C> {
|
||||
|
||||
public RecipeRewriter1_14(Protocol<C, ?, ?, ?> protocol) {
|
||||
super(protocol);
|
||||
recipeHandlers.put("stonecutting", this::handleStonecutting);
|
||||
|
||||
recipeHandlers.put("blasting", this::handleSmelting);
|
||||
recipeHandlers.put("smoking", this::handleSmelting);
|
||||
recipeHandlers.put("campfire_cooking", this::handleSmelting);
|
||||
}
|
||||
|
||||
public void handleStonecutting(PacketWrapper wrapper) throws Exception {
|
||||
wrapper.passthrough(Type.STRING);
|
||||
Item[] items = wrapper.passthrough(Type.FLAT_VAR_INT_ITEM_ARRAY_VAR_INT); // Ingredients
|
||||
for (Item item : items) {
|
||||
rewrite(item);
|
||||
}
|
||||
|
||||
rewrite(wrapper.passthrough(Type.FLAT_VAR_INT_ITEM)); // Result
|
||||
}
|
||||
}
|
@ -34,7 +34,6 @@ import com.viaversion.viaversion.api.type.Type;
|
||||
import com.viaversion.viaversion.protocols.protocol1_13to1_12_2.ChatRewriter;
|
||||
import com.viaversion.viaversion.protocols.protocol1_13to1_12_2.ClientboundPackets1_13;
|
||||
import com.viaversion.viaversion.protocols.protocol1_13to1_12_2.ServerboundPackets1_13;
|
||||
import com.viaversion.viaversion.protocols.protocol1_13to1_12_2.data.RecipeRewriter1_13_2;
|
||||
import com.viaversion.viaversion.protocols.protocol1_14to1_13_2.ClientboundPackets1_14;
|
||||
import com.viaversion.viaversion.protocols.protocol1_14to1_13_2.Protocol1_14To1_13_2;
|
||||
import com.viaversion.viaversion.protocols.protocol1_14to1_13_2.ServerboundPackets1_14;
|
||||
@ -191,7 +190,7 @@ public class InventoryPackets extends ItemRewriter<ClientboundPackets1_13, Serve
|
||||
|
||||
registerEntityEquipment(ClientboundPackets1_13.ENTITY_EQUIPMENT, Type.FLAT_VAR_INT_ITEM);
|
||||
|
||||
RecipeRewriter<ClientboundPackets1_13> recipeRewriter = new RecipeRewriter1_13_2<>(protocol);
|
||||
RecipeRewriter<ClientboundPackets1_13> recipeRewriter = new RecipeRewriter<>(protocol);
|
||||
protocol.registerClientbound(ClientboundPackets1_13.DECLARE_RECIPES, wrapper -> {
|
||||
int size = wrapper.passthrough(Type.VAR_INT);
|
||||
int deleted = 0;
|
||||
|
@ -20,9 +20,9 @@ package com.viaversion.viaversion.protocols.protocol1_15to1_14_4.packets;
|
||||
import com.viaversion.viaversion.api.type.Type;
|
||||
import com.viaversion.viaversion.protocols.protocol1_14to1_13_2.ClientboundPackets1_14;
|
||||
import com.viaversion.viaversion.protocols.protocol1_14to1_13_2.ServerboundPackets1_14;
|
||||
import com.viaversion.viaversion.protocols.protocol1_14to1_13_2.data.RecipeRewriter1_14;
|
||||
import com.viaversion.viaversion.protocols.protocol1_15to1_14_4.Protocol1_15To1_14_4;
|
||||
import com.viaversion.viaversion.rewriter.ItemRewriter;
|
||||
import com.viaversion.viaversion.rewriter.RecipeRewriter;
|
||||
|
||||
public class InventoryPackets extends ItemRewriter<ClientboundPackets1_14, ServerboundPackets1_14, Protocol1_15To1_14_4> {
|
||||
|
||||
@ -39,7 +39,7 @@ public class InventoryPackets extends ItemRewriter<ClientboundPackets1_14, Serve
|
||||
registerEntityEquipment(ClientboundPackets1_14.ENTITY_EQUIPMENT, Type.FLAT_VAR_INT_ITEM);
|
||||
registerAdvancements(ClientboundPackets1_14.ADVANCEMENTS, Type.FLAT_VAR_INT_ITEM);
|
||||
|
||||
new RecipeRewriter1_14<>(protocol).registerDefaultHandler(ClientboundPackets1_14.DECLARE_RECIPES);
|
||||
new RecipeRewriter<>(protocol).register(ClientboundPackets1_14.DECLARE_RECIPES);
|
||||
|
||||
registerClickWindow(ServerboundPackets1_14.CLICK_WINDOW, Type.FLAT_VAR_INT_ITEM);
|
||||
registerCreativeInvAction(ServerboundPackets1_14.CREATIVE_INVENTORY_ACTION, Type.FLAT_VAR_INT_ITEM);
|
||||
|
@ -21,8 +21,8 @@ import com.viaversion.viaversion.api.type.Type;
|
||||
import com.viaversion.viaversion.protocols.protocol1_16_2to1_16_1.Protocol1_16_2To1_16_1;
|
||||
import com.viaversion.viaversion.protocols.protocol1_16_2to1_16_1.ServerboundPackets1_16_2;
|
||||
import com.viaversion.viaversion.protocols.protocol1_16to1_15_2.ClientboundPackets1_16;
|
||||
import com.viaversion.viaversion.protocols.protocol1_16to1_15_2.data.RecipeRewriter1_16;
|
||||
import com.viaversion.viaversion.rewriter.ItemRewriter;
|
||||
import com.viaversion.viaversion.rewriter.RecipeRewriter;
|
||||
|
||||
public class InventoryPackets extends ItemRewriter<ClientboundPackets1_16, ServerboundPackets1_16_2, Protocol1_16_2To1_16_1> {
|
||||
|
||||
@ -52,7 +52,7 @@ public class InventoryPackets extends ItemRewriter<ClientboundPackets1_16, Serve
|
||||
wrapper.write(Type.BOOLEAN, false);
|
||||
});
|
||||
|
||||
new RecipeRewriter1_16<>(protocol).registerDefaultHandler(ClientboundPackets1_16.DECLARE_RECIPES);
|
||||
new RecipeRewriter<>(protocol).register(ClientboundPackets1_16.DECLARE_RECIPES);
|
||||
|
||||
registerClickWindow(ServerboundPackets1_16_2.CLICK_WINDOW, Type.FLAT_VAR_INT_ITEM);
|
||||
registerCreativeInvAction(ServerboundPackets1_16_2.CREATIVE_INVENTORY_ACTION, Type.FLAT_VAR_INT_ITEM);
|
||||
|
@ -30,13 +30,13 @@ import com.viaversion.viaversion.api.protocol.remapper.PacketHandler;
|
||||
import com.viaversion.viaversion.api.protocol.remapper.PacketHandlers;
|
||||
import com.viaversion.viaversion.api.type.Type;
|
||||
import com.viaversion.viaversion.api.type.types.UUIDIntArrayType;
|
||||
import com.viaversion.viaversion.protocols.protocol1_14to1_13_2.data.RecipeRewriter1_14;
|
||||
import com.viaversion.viaversion.protocols.protocol1_15to1_14_4.ClientboundPackets1_15;
|
||||
import com.viaversion.viaversion.protocols.protocol1_16to1_15_2.ClientboundPackets1_16;
|
||||
import com.viaversion.viaversion.protocols.protocol1_16to1_15_2.Protocol1_16To1_15_2;
|
||||
import com.viaversion.viaversion.protocols.protocol1_16to1_15_2.ServerboundPackets1_16;
|
||||
import com.viaversion.viaversion.protocols.protocol1_16to1_15_2.storage.InventoryTracker1_16;
|
||||
import com.viaversion.viaversion.rewriter.ItemRewriter;
|
||||
import com.viaversion.viaversion.rewriter.RecipeRewriter;
|
||||
import java.util.UUID;
|
||||
|
||||
public class InventoryPackets extends ItemRewriter<ClientboundPackets1_15, ServerboundPackets1_16, Protocol1_16To1_15_2> {
|
||||
@ -125,7 +125,7 @@ public class InventoryPackets extends ItemRewriter<ClientboundPackets1_15, Serve
|
||||
}
|
||||
});
|
||||
|
||||
new RecipeRewriter1_14<>(protocol).registerDefaultHandler(ClientboundPackets1_15.DECLARE_RECIPES);
|
||||
new RecipeRewriter<>(protocol).register(ClientboundPackets1_15.DECLARE_RECIPES);
|
||||
|
||||
registerClickWindow(ServerboundPackets1_16.CLICK_WINDOW, Type.FLAT_VAR_INT_ITEM);
|
||||
registerCreativeInvAction(ServerboundPackets1_16.CREATIVE_INVENTORY_ACTION, Type.FLAT_VAR_INT_ITEM);
|
||||
|
@ -23,12 +23,12 @@ import com.viaversion.viaversion.api.protocol.remapper.PacketHandlers;
|
||||
import com.viaversion.viaversion.api.type.Type;
|
||||
import com.viaversion.viaversion.protocols.protocol1_16_2to1_16_1.ClientboundPackets1_16_2;
|
||||
import com.viaversion.viaversion.protocols.protocol1_16_2to1_16_1.ServerboundPackets1_16_2;
|
||||
import com.viaversion.viaversion.protocols.protocol1_16to1_15_2.data.RecipeRewriter1_16;
|
||||
import com.viaversion.viaversion.protocols.protocol1_17to1_16_4.ClientboundPackets1_17;
|
||||
import com.viaversion.viaversion.protocols.protocol1_17to1_16_4.Protocol1_17To1_16_4;
|
||||
import com.viaversion.viaversion.protocols.protocol1_17to1_16_4.ServerboundPackets1_17;
|
||||
import com.viaversion.viaversion.protocols.protocol1_17to1_16_4.storage.InventoryAcknowledgements;
|
||||
import com.viaversion.viaversion.rewriter.ItemRewriter;
|
||||
import com.viaversion.viaversion.rewriter.RecipeRewriter;
|
||||
|
||||
public final class InventoryPackets extends ItemRewriter<ClientboundPackets1_16_2, ServerboundPackets1_17, Protocol1_17To1_16_4> {
|
||||
|
||||
@ -46,7 +46,7 @@ public final class InventoryPackets extends ItemRewriter<ClientboundPackets1_16_
|
||||
registerEntityEquipmentArray(ClientboundPackets1_16_2.ENTITY_EQUIPMENT);
|
||||
registerSpawnParticle(ClientboundPackets1_16_2.SPAWN_PARTICLE, Type.FLAT_VAR_INT_ITEM, Type.DOUBLE);
|
||||
|
||||
new RecipeRewriter1_16<>(protocol).registerDefaultHandler(ClientboundPackets1_16_2.DECLARE_RECIPES);
|
||||
new RecipeRewriter<>(protocol).register(ClientboundPackets1_16_2.DECLARE_RECIPES);
|
||||
|
||||
registerCreativeInvAction(ServerboundPackets1_17.CREATIVE_INVENTORY_ACTION, Type.FLAT_VAR_INT_ITEM);
|
||||
|
||||
|
@ -20,11 +20,11 @@ package com.viaversion.viaversion.protocols.protocol1_18to1_17_1.packets;
|
||||
import com.viaversion.viaversion.api.data.ParticleMappings;
|
||||
import com.viaversion.viaversion.api.protocol.remapper.PacketHandlers;
|
||||
import com.viaversion.viaversion.api.type.Type;
|
||||
import com.viaversion.viaversion.protocols.protocol1_16to1_15_2.data.RecipeRewriter1_16;
|
||||
import com.viaversion.viaversion.protocols.protocol1_17_1to1_17.ClientboundPackets1_17_1;
|
||||
import com.viaversion.viaversion.protocols.protocol1_17to1_16_4.ServerboundPackets1_17;
|
||||
import com.viaversion.viaversion.protocols.protocol1_18to1_17_1.Protocol1_18To1_17_1;
|
||||
import com.viaversion.viaversion.rewriter.ItemRewriter;
|
||||
import com.viaversion.viaversion.rewriter.RecipeRewriter;
|
||||
|
||||
public final class InventoryPackets extends ItemRewriter<ClientboundPackets1_17_1, ServerboundPackets1_17, Protocol1_18To1_17_1> {
|
||||
|
||||
@ -97,7 +97,7 @@ public final class InventoryPackets extends ItemRewriter<ClientboundPackets1_17_
|
||||
}
|
||||
});
|
||||
|
||||
new RecipeRewriter1_16<>(protocol).registerDefaultHandler(ClientboundPackets1_17_1.DECLARE_RECIPES);
|
||||
new RecipeRewriter<>(protocol).register(ClientboundPackets1_17_1.DECLARE_RECIPES);
|
||||
|
||||
registerClickWindow1_17_1(ServerboundPackets1_17.CLICK_WINDOW);
|
||||
registerCreativeInvAction(ServerboundPackets1_17.CREATIVE_INVENTORY_ACTION, Type.FLAT_VAR_INT_ITEM);
|
||||
|
@ -17,17 +17,17 @@
|
||||
*/
|
||||
package com.viaversion.viaversion.protocols.protocol1_19_3to1_19_1.data;
|
||||
|
||||
import com.viaversion.viaversion.api.minecraft.item.Item;
|
||||
import com.viaversion.viaversion.api.protocol.Protocol;
|
||||
import com.viaversion.viaversion.api.protocol.packet.ClientboundPacketType;
|
||||
import com.viaversion.viaversion.api.protocol.packet.PacketWrapper;
|
||||
import com.viaversion.viaversion.api.type.Type;
|
||||
import com.viaversion.viaversion.protocols.protocol1_16to1_15_2.data.RecipeRewriter1_16;
|
||||
import com.viaversion.viaversion.rewriter.RecipeRewriter;
|
||||
|
||||
public class RecipeRewriter1_19_3<C extends ClientboundPacketType> extends RecipeRewriter1_16<C> {
|
||||
public class RecipeRewriter1_19_3<C extends ClientboundPacketType> extends RecipeRewriter<C> {
|
||||
|
||||
public RecipeRewriter1_19_3(final Protocol<C, ?, ?, ?> protocol) {
|
||||
super(protocol);
|
||||
// Existed before, but now have serialization data
|
||||
recipeHandlers.put("crafting_special_armordye", this::handleSimpleRecipe);
|
||||
recipeHandlers.put("crafting_special_bookcloning", this::handleSimpleRecipe);
|
||||
recipeHandlers.put("crafting_special_mapcloning", this::handleSimpleRecipe);
|
||||
@ -47,13 +47,7 @@ public class RecipeRewriter1_19_3<C extends ClientboundPacketType> extends Recip
|
||||
public void handleCraftingShapeless(final PacketWrapper wrapper) throws Exception {
|
||||
wrapper.passthrough(Type.STRING); // Group
|
||||
wrapper.passthrough(Type.VAR_INT); // Crafting book category
|
||||
final int ingredients = wrapper.passthrough(Type.VAR_INT);
|
||||
for (int j = 0; j < ingredients; j++) {
|
||||
final Item[] items = wrapper.passthrough(Type.FLAT_VAR_INT_ITEM_ARRAY_VAR_INT); // Ingredients
|
||||
for (final Item item : items) {
|
||||
rewrite(item);
|
||||
}
|
||||
}
|
||||
handleIngredients(wrapper);
|
||||
rewrite(wrapper.passthrough(Type.FLAT_VAR_INT_ITEM)); // Result
|
||||
}
|
||||
|
||||
@ -62,11 +56,8 @@ public class RecipeRewriter1_19_3<C extends ClientboundPacketType> extends Recip
|
||||
final int ingredients = wrapper.passthrough(Type.VAR_INT) * wrapper.passthrough(Type.VAR_INT);
|
||||
wrapper.passthrough(Type.STRING); // Group
|
||||
wrapper.passthrough(Type.VAR_INT); // Crafting book category
|
||||
for (int j = 0; j < ingredients; j++) {
|
||||
final Item[] items = wrapper.passthrough(Type.FLAT_VAR_INT_ITEM_ARRAY_VAR_INT); // Ingredients
|
||||
for (final Item item : items) {
|
||||
rewrite(item);
|
||||
}
|
||||
for (int i = 0; i < ingredients; i++) {
|
||||
handleIngredient(wrapper);
|
||||
}
|
||||
rewrite(wrapper.passthrough(Type.FLAT_VAR_INT_ITEM)); // Result
|
||||
}
|
||||
@ -75,16 +66,9 @@ public class RecipeRewriter1_19_3<C extends ClientboundPacketType> extends Recip
|
||||
public void handleSmelting(final PacketWrapper wrapper) throws Exception {
|
||||
wrapper.passthrough(Type.STRING); // Group
|
||||
wrapper.passthrough(Type.VAR_INT); // Crafting book category
|
||||
final Item[] items = wrapper.passthrough(Type.FLAT_VAR_INT_ITEM_ARRAY_VAR_INT); // Ingredients
|
||||
for (final Item item : items) {
|
||||
rewrite(item);
|
||||
}
|
||||
handleIngredient(wrapper);
|
||||
rewrite(wrapper.passthrough(Type.FLAT_VAR_INT_ITEM)); // Result
|
||||
wrapper.passthrough(Type.FLOAT); // EXP
|
||||
wrapper.passthrough(Type.VAR_INT); // Cooking time
|
||||
}
|
||||
|
||||
public void handleSimpleRecipe(final PacketWrapper wrapper) throws Exception {
|
||||
wrapper.passthrough(Type.VAR_INT); // Crafting book category
|
||||
}
|
||||
}
|
||||
|
@ -20,13 +20,13 @@ package com.viaversion.viaversion.protocols.protocol1_19_3to1_19_1.packets;
|
||||
import com.viaversion.viaversion.api.minecraft.item.Item;
|
||||
import com.viaversion.viaversion.api.protocol.remapper.PacketHandlers;
|
||||
import com.viaversion.viaversion.api.type.Type;
|
||||
import com.viaversion.viaversion.protocols.protocol1_16to1_15_2.data.RecipeRewriter1_16;
|
||||
import com.viaversion.viaversion.protocols.protocol1_18to1_17_1.types.Chunk1_18Type;
|
||||
import com.viaversion.viaversion.protocols.protocol1_19_1to1_19.ClientboundPackets1_19_1;
|
||||
import com.viaversion.viaversion.protocols.protocol1_19_3to1_19_1.Protocol1_19_3To1_19_1;
|
||||
import com.viaversion.viaversion.protocols.protocol1_19_3to1_19_1.ServerboundPackets1_19_3;
|
||||
import com.viaversion.viaversion.rewriter.BlockRewriter;
|
||||
import com.viaversion.viaversion.rewriter.ItemRewriter;
|
||||
import com.viaversion.viaversion.rewriter.RecipeRewriter;
|
||||
|
||||
public final class InventoryPackets extends ItemRewriter<ClientboundPackets1_19_1, ServerboundPackets1_19_3, Protocol1_19_3To1_19_1> {
|
||||
|
||||
@ -57,7 +57,7 @@ public final class InventoryPackets extends ItemRewriter<ClientboundPackets1_19_
|
||||
registerWindowPropertyEnchantmentHandler(ClientboundPackets1_19_1.WINDOW_PROPERTY);
|
||||
registerSpawnParticle1_19(ClientboundPackets1_19_1.SPAWN_PARTICLE);
|
||||
|
||||
final RecipeRewriter1_16<ClientboundPackets1_19_1> recipeRewriter = new RecipeRewriter1_16<>(protocol);
|
||||
final RecipeRewriter<ClientboundPackets1_19_1> recipeRewriter = new RecipeRewriter<>(protocol);
|
||||
protocol.registerClientbound(ClientboundPackets1_19_1.DECLARE_RECIPES, wrapper -> {
|
||||
final int size = wrapper.passthrough(Type.VAR_INT);
|
||||
for (int i = 0; i < size; i++) {
|
||||
|
@ -15,31 +15,26 @@
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.viaversion.viaversion.protocols.protocol1_16to1_15_2.data;
|
||||
package com.viaversion.viaversion.protocols.protocol1_19_4to1_19_3.data;
|
||||
|
||||
import com.viaversion.viaversion.api.minecraft.item.Item;
|
||||
import com.viaversion.viaversion.api.protocol.Protocol;
|
||||
import com.viaversion.viaversion.api.protocol.packet.ClientboundPacketType;
|
||||
import com.viaversion.viaversion.api.protocol.packet.PacketWrapper;
|
||||
import com.viaversion.viaversion.api.type.Type;
|
||||
import com.viaversion.viaversion.protocols.protocol1_14to1_13_2.data.RecipeRewriter1_14;
|
||||
import com.viaversion.viaversion.protocols.protocol1_19_3to1_19_1.data.RecipeRewriter1_19_3;
|
||||
|
||||
public class RecipeRewriter1_16<C extends ClientboundPacketType> extends RecipeRewriter1_14<C> {
|
||||
public class RecipeRewriter1_19_4<C extends ClientboundPacketType> extends RecipeRewriter1_19_3<C> {
|
||||
|
||||
public RecipeRewriter1_16(Protocol<C, ?, ?, ?> protocol) {
|
||||
public RecipeRewriter1_19_4(final Protocol<C, ?, ?, ?> protocol) {
|
||||
super(protocol);
|
||||
recipeHandlers.put("smithing", this::handleSmithing);
|
||||
}
|
||||
|
||||
public void handleSmithing(PacketWrapper wrapper) throws Exception {
|
||||
Item[] baseIngredients = wrapper.passthrough(Type.FLAT_VAR_INT_ITEM_ARRAY_VAR_INT);
|
||||
for (Item item : baseIngredients) {
|
||||
rewrite(item);
|
||||
}
|
||||
Item[] ingredients = wrapper.passthrough(Type.FLAT_VAR_INT_ITEM_ARRAY_VAR_INT);
|
||||
for (Item item : ingredients) {
|
||||
rewrite(item);
|
||||
}
|
||||
@Override
|
||||
public void handleCraftingShapeless(final PacketWrapper wrapper) throws Exception {
|
||||
wrapper.passthrough(Type.STRING); // Group
|
||||
wrapper.passthrough(Type.VAR_INT); // Crafting book category
|
||||
handleIngredients(wrapper);
|
||||
rewrite(wrapper.passthrough(Type.FLAT_VAR_INT_ITEM)); // Result
|
||||
wrapper.passthrough(Type.BOOLEAN); // Show notification
|
||||
}
|
||||
}
|
@ -26,13 +26,30 @@ import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
|
||||
public abstract class RecipeRewriter<C extends ClientboundPacketType> {
|
||||
public class RecipeRewriter<C extends ClientboundPacketType> {
|
||||
|
||||
protected final Protocol<C, ?, ?, ?> protocol;
|
||||
protected final Map<String, RecipeConsumer> recipeHandlers = new HashMap<>();
|
||||
|
||||
protected RecipeRewriter(Protocol<C, ?, ?, ?> protocol) {
|
||||
public RecipeRewriter(Protocol<C, ?, ?, ?> protocol) {
|
||||
this.protocol = protocol;
|
||||
recipeHandlers.put("crafting_shapeless", this::handleCraftingShapeless);
|
||||
recipeHandlers.put("crafting_shaped", this::handleCraftingShaped);
|
||||
recipeHandlers.put("smelting", this::handleSmelting);
|
||||
|
||||
// Added in 1.14
|
||||
recipeHandlers.put("stonecutting", this::handleStonecutting);
|
||||
recipeHandlers.put("blasting", this::handleSmelting);
|
||||
recipeHandlers.put("smoking", this::handleSmelting);
|
||||
recipeHandlers.put("campfire_cooking", this::handleSmelting);
|
||||
|
||||
// Added in 1.16
|
||||
recipeHandlers.put("smithing", this::handleSmithing);
|
||||
|
||||
// Added in 1.19.4
|
||||
recipeHandlers.put("smithing_transform", this::handleSmithingTransform);
|
||||
recipeHandlers.put("smithing_trim", this::handleSmithingTransform);
|
||||
recipeHandlers.put("crafting_decorated_pot", this::handleSimpleRecipe);
|
||||
}
|
||||
|
||||
public void handleRecipeType(PacketWrapper wrapper, String type) throws Exception {
|
||||
@ -42,7 +59,12 @@ public abstract class RecipeRewriter<C extends ClientboundPacketType> {
|
||||
}
|
||||
}
|
||||
|
||||
public void registerDefaultHandler(C packetType) {
|
||||
/**
|
||||
* Registers a packet handler to rewrite recipe types, for 1.14+.
|
||||
*
|
||||
* @param packetType packet type
|
||||
*/
|
||||
public void register(C packetType) {
|
||||
protocol.registerClientbound(packetType, wrapper -> {
|
||||
int size = wrapper.passthrough(Type.VAR_INT);
|
||||
for (int i = 0; i < size; i++) {
|
||||
@ -53,12 +75,72 @@ public abstract class RecipeRewriter<C extends ClientboundPacketType> {
|
||||
});
|
||||
}
|
||||
|
||||
public void handleCraftingShaped(PacketWrapper wrapper) throws Exception {
|
||||
int ingredientsNo = wrapper.passthrough(Type.VAR_INT) * wrapper.passthrough(Type.VAR_INT);
|
||||
wrapper.passthrough(Type.STRING); // Group
|
||||
for (int i = 0; i < ingredientsNo; i++) {
|
||||
handleIngredient(wrapper);
|
||||
}
|
||||
rewrite(wrapper.passthrough(Type.FLAT_VAR_INT_ITEM)); // Result
|
||||
}
|
||||
|
||||
public void handleCraftingShapeless(PacketWrapper wrapper) throws Exception {
|
||||
wrapper.passthrough(Type.STRING); // Group
|
||||
handleIngredients(wrapper);
|
||||
rewrite(wrapper.passthrough(Type.FLAT_VAR_INT_ITEM)); // Result
|
||||
}
|
||||
|
||||
public void handleSmelting(PacketWrapper wrapper) throws Exception {
|
||||
wrapper.passthrough(Type.STRING); // Group
|
||||
handleIngredient(wrapper);
|
||||
rewrite(wrapper.passthrough(Type.FLAT_VAR_INT_ITEM)); // Result
|
||||
wrapper.passthrough(Type.FLOAT); // EXP
|
||||
wrapper.passthrough(Type.VAR_INT); // Cooking time
|
||||
}
|
||||
|
||||
public void handleStonecutting(PacketWrapper wrapper) throws Exception {
|
||||
wrapper.passthrough(Type.STRING);
|
||||
handleIngredient(wrapper);
|
||||
rewrite(wrapper.passthrough(Type.FLAT_VAR_INT_ITEM)); // Result
|
||||
}
|
||||
|
||||
public void handleSmithing(PacketWrapper wrapper) throws Exception {
|
||||
handleIngredient(wrapper); // Base
|
||||
handleIngredient(wrapper); // Addition
|
||||
rewrite(wrapper.passthrough(Type.FLAT_VAR_INT_ITEM)); // Result
|
||||
}
|
||||
|
||||
public void handleSimpleRecipe(final PacketWrapper wrapper) throws Exception {
|
||||
wrapper.passthrough(Type.VAR_INT); // Crafting book category
|
||||
}
|
||||
|
||||
public void handleSmithingTransform(final PacketWrapper wrapper) throws Exception {
|
||||
handleIngredient(wrapper); // Template
|
||||
handleIngredient(wrapper); // Base
|
||||
handleIngredient(wrapper); // Additions
|
||||
rewrite(wrapper.passthrough(Type.FLAT_VAR_INT_ITEM)); // Result
|
||||
}
|
||||
|
||||
protected void rewrite(@Nullable Item item) {
|
||||
if (protocol.getItemRewriter() != null) {
|
||||
protocol.getItemRewriter().handleItemToClient(item);
|
||||
}
|
||||
}
|
||||
|
||||
protected void handleIngredient(final PacketWrapper wrapper) throws Exception {
|
||||
final Item[] items = wrapper.passthrough(Type.FLAT_VAR_INT_ITEM_ARRAY_VAR_INT);
|
||||
for (final Item item : items) {
|
||||
rewrite(item);
|
||||
}
|
||||
}
|
||||
|
||||
protected void handleIngredients(final PacketWrapper wrapper) throws Exception {
|
||||
final int ingredients = wrapper.passthrough(Type.VAR_INT);
|
||||
for (int i = 0; i < ingredients; i++) {
|
||||
handleIngredient(wrapper);
|
||||
}
|
||||
}
|
||||
|
||||
@FunctionalInterface
|
||||
public interface RecipeConsumer {
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user