Fix 1.12 recipes containing stone as placeholder, improve empty handling in 1.20.5/1.21.2 (#4284)

This commit is contained in:
Valaphee The Meerkat 2024-11-26 17:04:50 +01:00 committed by GitHub
parent 896c6accfb
commit 2d663db53f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
7 changed files with 295 additions and 690 deletions

View File

@ -50,7 +50,7 @@ public class RecipeRewriter1_19_3<C extends ClientboundPacketType> extends Recip
wrapper.passthrough(Types.STRING); // Group
wrapper.passthrough(Types.VAR_INT); // Crafting book category
handleIngredients(wrapper);
wrapper.write(mappedItemType(), rewrite(wrapper.user(), wrapper.read(itemType())));
handleResult(wrapper);
}
@Override
@ -61,8 +61,7 @@ public class RecipeRewriter1_19_3<C extends ClientboundPacketType> extends Recip
for (int i = 0; i < ingredients; i++) {
handleIngredient(wrapper);
}
final Item result = rewrite(wrapper.user(), wrapper.read(itemType()));
wrapper.write(mappedItemType(), result);
handleResult(wrapper);
}
@Override
@ -70,8 +69,7 @@ public class RecipeRewriter1_19_3<C extends ClientboundPacketType> extends Recip
wrapper.passthrough(Types.STRING); // Group
wrapper.passthrough(Types.VAR_INT); // Crafting book category
handleIngredient(wrapper);
final Item result = rewrite(wrapper.user(), wrapper.read(itemType()));
wrapper.write(mappedItemType(), result);
handleResult(wrapper);
wrapper.passthrough(Types.FLOAT); // EXP
wrapper.passthrough(Types.VAR_INT); // Cooking time
}

View File

@ -39,9 +39,7 @@ public class RecipeRewriter1_20_3<C extends ClientboundPacketType> extends Recip
for (int i = 0; i < ingredients; i++) {
handleIngredient(wrapper);
}
final Item item = rewrite(wrapper.user(), wrapper.read(itemType())); // Result
wrapper.write(mappedItemType(), item);
handleResult(wrapper);
wrapper.passthrough(Types.BOOLEAN); // Show notification
}

View File

@ -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) {
@Override
protected Item rewrite(final UserConnection connection, @Nullable Item item) {
return handleNonEmptyItemToClient(connection, item);
}
};
final RecipeRewriter1_20_5<ClientboundPacket1_20_3> recipeRewriter = new RecipeRewriter1_20_5<>(protocol);
protocol.registerClientbound(ClientboundPackets1_20_3.UPDATE_RECIPES, wrapper -> {
final int size = wrapper.passthrough(Types.VAR_INT);
for (int i = 0; i < size; i++) {

View File

@ -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);
}
}

View File

@ -327,6 +327,10 @@ final class RecipeRewriter1_21_2 extends RecipeRewriter1_20_3<ClientboundPacket1
wrapper.write(Types.VAR_INT, Recipe.SLOT_DISPLAY_EMPTY);
return;
}
if (ingredient.length == 1) {
writeItemDisplay(wrapper, ingredient[0]);
return;
}
wrapper.write(Types.VAR_INT, Recipe.SLOT_DISPLAY_COMPOSITE);
wrapper.write(Types.VAR_INT, ingredient.length);

View File

@ -108,23 +108,19 @@ public class RecipeRewriter<C extends ClientboundPacketType> {
for (int i = 0; i < ingredientsNo; i++) {
handleIngredient(wrapper);
}
final Item result = rewrite(wrapper.user(), wrapper.read(itemType()));
wrapper.write(mappedItemType(), result);
handleResult(wrapper);
}
public void handleCraftingShapeless(PacketWrapper wrapper) {
wrapper.passthrough(Types.STRING); // Group
handleIngredients(wrapper);
final Item result = rewrite(wrapper.user(), wrapper.read(itemType()));
wrapper.write(mappedItemType(), result);
handleResult(wrapper);
}
public void handleSmelting(PacketWrapper wrapper) {
wrapper.passthrough(Types.STRING); // Group
handleIngredient(wrapper);
final Item result = rewrite(wrapper.user(), wrapper.read(itemType()));
wrapper.write(mappedItemType(), result);
handleResult(wrapper);
wrapper.passthrough(Types.FLOAT); // EXP
wrapper.passthrough(Types.VAR_INT); // Cooking time
}
@ -132,15 +128,13 @@ public class RecipeRewriter<C extends ClientboundPacketType> {
public void handleStonecutting(PacketWrapper wrapper) {
wrapper.passthrough(Types.STRING); // Group
handleIngredient(wrapper);
final Item result = rewrite(wrapper.user(), wrapper.read(itemType()));
wrapper.write(mappedItemType(), result);
handleResult(wrapper);
}
public void handleSmithing(PacketWrapper wrapper) {
handleIngredient(wrapper); // Base
handleIngredient(wrapper); // Addition
final Item result = rewrite(wrapper.user(), wrapper.read(itemType()));
wrapper.write(mappedItemType(), result);
handleResult(wrapper);
}
public void handleSimpleRecipe(final PacketWrapper wrapper) {
@ -151,8 +145,7 @@ public class RecipeRewriter<C extends ClientboundPacketType> {
handleIngredient(wrapper); // Template
handleIngredient(wrapper); // Base
handleIngredient(wrapper); // Additions
final Item result = rewrite(wrapper.user(), wrapper.read(itemType()));
wrapper.write(mappedItemType(), result);
handleResult(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
public interface RecipeConsumer {