mirror of
https://github.com/ViaVersion/ViaVersion.git
synced 2024-12-22 16:38:20 +01:00
Fix 1.12 recipes containing stone as placeholder, improve empty handling in 1.20.5/1.21.2 (#4284)
This commit is contained in:
parent
896c6accfb
commit
2d663db53f
@ -50,7 +50,7 @@ public class RecipeRewriter1_19_3<C extends ClientboundPacketType> extends Recip
|
|||||||
wrapper.passthrough(Types.STRING); // Group
|
wrapper.passthrough(Types.STRING); // Group
|
||||||
wrapper.passthrough(Types.VAR_INT); // Crafting book category
|
wrapper.passthrough(Types.VAR_INT); // Crafting book category
|
||||||
handleIngredients(wrapper);
|
handleIngredients(wrapper);
|
||||||
wrapper.write(mappedItemType(), rewrite(wrapper.user(), wrapper.read(itemType())));
|
handleResult(wrapper);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -61,8 +61,7 @@ public class RecipeRewriter1_19_3<C extends ClientboundPacketType> extends Recip
|
|||||||
for (int i = 0; i < ingredients; i++) {
|
for (int i = 0; i < ingredients; i++) {
|
||||||
handleIngredient(wrapper);
|
handleIngredient(wrapper);
|
||||||
}
|
}
|
||||||
final Item result = rewrite(wrapper.user(), wrapper.read(itemType()));
|
handleResult(wrapper);
|
||||||
wrapper.write(mappedItemType(), result);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -70,8 +69,7 @@ public class RecipeRewriter1_19_3<C extends ClientboundPacketType> extends Recip
|
|||||||
wrapper.passthrough(Types.STRING); // Group
|
wrapper.passthrough(Types.STRING); // Group
|
||||||
wrapper.passthrough(Types.VAR_INT); // Crafting book category
|
wrapper.passthrough(Types.VAR_INT); // Crafting book category
|
||||||
handleIngredient(wrapper);
|
handleIngredient(wrapper);
|
||||||
final Item result = rewrite(wrapper.user(), wrapper.read(itemType()));
|
handleResult(wrapper);
|
||||||
wrapper.write(mappedItemType(), result);
|
|
||||||
wrapper.passthrough(Types.FLOAT); // EXP
|
wrapper.passthrough(Types.FLOAT); // EXP
|
||||||
wrapper.passthrough(Types.VAR_INT); // Cooking time
|
wrapper.passthrough(Types.VAR_INT); // Cooking time
|
||||||
}
|
}
|
||||||
|
@ -39,9 +39,7 @@ public class RecipeRewriter1_20_3<C extends ClientboundPacketType> extends Recip
|
|||||||
for (int i = 0; i < ingredients; i++) {
|
for (int i = 0; i < ingredients; i++) {
|
||||||
handleIngredient(wrapper);
|
handleIngredient(wrapper);
|
||||||
}
|
}
|
||||||
|
handleResult(wrapper);
|
||||||
final Item item = rewrite(wrapper.user(), wrapper.read(itemType())); // Result
|
|
||||||
wrapper.write(mappedItemType(), item);
|
|
||||||
wrapper.passthrough(Types.BOOLEAN); // Show notification
|
wrapper.passthrough(Types.BOOLEAN); // Show notification
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -342,12 +342,7 @@ public final class BlockItemPacketRewriter1_20_5 extends ItemRewriter<Clientboun
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
final RecipeRewriter1_20_3<ClientboundPacket1_20_3> recipeRewriter = new RecipeRewriter1_20_3<>(protocol) {
|
final RecipeRewriter1_20_5<ClientboundPacket1_20_3> recipeRewriter = new RecipeRewriter1_20_5<>(protocol);
|
||||||
@Override
|
|
||||||
protected Item rewrite(final UserConnection connection, @Nullable Item item) {
|
|
||||||
return handleNonEmptyItemToClient(connection, item);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
protocol.registerClientbound(ClientboundPackets1_20_3.UPDATE_RECIPES, wrapper -> {
|
protocol.registerClientbound(ClientboundPackets1_20_3.UPDATE_RECIPES, wrapper -> {
|
||||||
final int size = wrapper.passthrough(Types.VAR_INT);
|
final int size = wrapper.passthrough(Types.VAR_INT);
|
||||||
for (int i = 0; i < size; i++) {
|
for (int i = 0; i < size; i++) {
|
||||||
|
@ -0,0 +1,54 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of ViaVersion - https://github.com/ViaVersion/ViaVersion
|
||||||
|
* Copyright (C) 2016-2024 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.v1_20_3to1_20_5.rewriter;
|
||||||
|
|
||||||
|
import com.viaversion.viaversion.api.minecraft.item.Item;
|
||||||
|
import com.viaversion.viaversion.api.minecraft.item.StructuredItem;
|
||||||
|
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.protocols.v1_20_2to1_20_3.rewriter.RecipeRewriter1_20_3;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
final class RecipeRewriter1_20_5 <C extends ClientboundPacketType> extends RecipeRewriter1_20_3<C> {
|
||||||
|
|
||||||
|
public RecipeRewriter1_20_5(final Protocol<C, ?, ?, ?> protocol) {
|
||||||
|
super(protocol);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void handleIngredient(final PacketWrapper wrapper) {
|
||||||
|
final Item[] items = wrapper.read(itemArrayType());
|
||||||
|
final List<Item> newItems = new ArrayList<>(items.length);
|
||||||
|
for (final Item item : items) {
|
||||||
|
if (item == null || item.isEmpty()) continue;
|
||||||
|
newItems.add(item);
|
||||||
|
}
|
||||||
|
wrapper.write(mappedItemArrayType(), newItems.toArray(new Item[0]));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void handleResult(final PacketWrapper wrapper) {
|
||||||
|
Item result = rewrite(wrapper.user(), wrapper.read(itemType()));
|
||||||
|
if (result == null || result.isEmpty()) {
|
||||||
|
result = new StructuredItem(1, 1);
|
||||||
|
}
|
||||||
|
wrapper.write(mappedItemType(), result);
|
||||||
|
}
|
||||||
|
}
|
@ -327,6 +327,10 @@ final class RecipeRewriter1_21_2 extends RecipeRewriter1_20_3<ClientboundPacket1
|
|||||||
wrapper.write(Types.VAR_INT, Recipe.SLOT_DISPLAY_EMPTY);
|
wrapper.write(Types.VAR_INT, Recipe.SLOT_DISPLAY_EMPTY);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
if (ingredient.length == 1) {
|
||||||
|
writeItemDisplay(wrapper, ingredient[0]);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
wrapper.write(Types.VAR_INT, Recipe.SLOT_DISPLAY_COMPOSITE);
|
wrapper.write(Types.VAR_INT, Recipe.SLOT_DISPLAY_COMPOSITE);
|
||||||
wrapper.write(Types.VAR_INT, ingredient.length);
|
wrapper.write(Types.VAR_INT, ingredient.length);
|
||||||
|
@ -108,23 +108,19 @@ public class RecipeRewriter<C extends ClientboundPacketType> {
|
|||||||
for (int i = 0; i < ingredientsNo; i++) {
|
for (int i = 0; i < ingredientsNo; i++) {
|
||||||
handleIngredient(wrapper);
|
handleIngredient(wrapper);
|
||||||
}
|
}
|
||||||
|
handleResult(wrapper);
|
||||||
final Item result = rewrite(wrapper.user(), wrapper.read(itemType()));
|
|
||||||
wrapper.write(mappedItemType(), result);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void handleCraftingShapeless(PacketWrapper wrapper) {
|
public void handleCraftingShapeless(PacketWrapper wrapper) {
|
||||||
wrapper.passthrough(Types.STRING); // Group
|
wrapper.passthrough(Types.STRING); // Group
|
||||||
handleIngredients(wrapper);
|
handleIngredients(wrapper);
|
||||||
final Item result = rewrite(wrapper.user(), wrapper.read(itemType()));
|
handleResult(wrapper);
|
||||||
wrapper.write(mappedItemType(), result);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void handleSmelting(PacketWrapper wrapper) {
|
public void handleSmelting(PacketWrapper wrapper) {
|
||||||
wrapper.passthrough(Types.STRING); // Group
|
wrapper.passthrough(Types.STRING); // Group
|
||||||
handleIngredient(wrapper);
|
handleIngredient(wrapper);
|
||||||
final Item result = rewrite(wrapper.user(), wrapper.read(itemType()));
|
handleResult(wrapper);
|
||||||
wrapper.write(mappedItemType(), result);
|
|
||||||
wrapper.passthrough(Types.FLOAT); // EXP
|
wrapper.passthrough(Types.FLOAT); // EXP
|
||||||
wrapper.passthrough(Types.VAR_INT); // Cooking time
|
wrapper.passthrough(Types.VAR_INT); // Cooking time
|
||||||
}
|
}
|
||||||
@ -132,15 +128,13 @@ public class RecipeRewriter<C extends ClientboundPacketType> {
|
|||||||
public void handleStonecutting(PacketWrapper wrapper) {
|
public void handleStonecutting(PacketWrapper wrapper) {
|
||||||
wrapper.passthrough(Types.STRING); // Group
|
wrapper.passthrough(Types.STRING); // Group
|
||||||
handleIngredient(wrapper);
|
handleIngredient(wrapper);
|
||||||
final Item result = rewrite(wrapper.user(), wrapper.read(itemType()));
|
handleResult(wrapper);
|
||||||
wrapper.write(mappedItemType(), result);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void handleSmithing(PacketWrapper wrapper) {
|
public void handleSmithing(PacketWrapper wrapper) {
|
||||||
handleIngredient(wrapper); // Base
|
handleIngredient(wrapper); // Base
|
||||||
handleIngredient(wrapper); // Addition
|
handleIngredient(wrapper); // Addition
|
||||||
final Item result = rewrite(wrapper.user(), wrapper.read(itemType()));
|
handleResult(wrapper);
|
||||||
wrapper.write(mappedItemType(), result);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void handleSimpleRecipe(final PacketWrapper wrapper) {
|
public void handleSimpleRecipe(final PacketWrapper wrapper) {
|
||||||
@ -151,8 +145,7 @@ public class RecipeRewriter<C extends ClientboundPacketType> {
|
|||||||
handleIngredient(wrapper); // Template
|
handleIngredient(wrapper); // Template
|
||||||
handleIngredient(wrapper); // Base
|
handleIngredient(wrapper); // Base
|
||||||
handleIngredient(wrapper); // Additions
|
handleIngredient(wrapper); // Additions
|
||||||
final Item result = rewrite(wrapper.user(), wrapper.read(itemType()));
|
handleResult(wrapper);
|
||||||
wrapper.write(mappedItemType(), result);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void handleSmithingTrim(final PacketWrapper wrapper) {
|
public void handleSmithingTrim(final PacketWrapper wrapper) {
|
||||||
@ -190,6 +183,11 @@ public class RecipeRewriter<C extends ClientboundPacketType> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected void handleResult(final PacketWrapper wrapper) {
|
||||||
|
final Item result = rewrite(wrapper.user(), wrapper.read(itemType()));
|
||||||
|
wrapper.write(mappedItemType(), result);
|
||||||
|
}
|
||||||
|
|
||||||
@FunctionalInterface
|
@FunctionalInterface
|
||||||
public interface RecipeConsumer {
|
public interface RecipeConsumer {
|
||||||
|
|
||||||
|
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user