Fix 1.21 food using_converts_to handling

Fixes #4280
This commit is contained in:
Nassim Jahnke 2024-11-25 10:14:12 +01:00
parent f93c64d6aa
commit e32205ddaf
No known key found for this signature in database
GPG Key ID: EF6771C01F6EF02F
2 changed files with 11 additions and 2 deletions

View File

@ -28,9 +28,10 @@ import com.viaversion.viaversion.api.type.Types;
import com.viaversion.viaversion.api.type.types.ArrayType;
import com.viaversion.viaversion.api.type.types.version.Types1_21;
import io.netty.buffer.ByteBuf;
import org.checkerframework.checker.nullness.qual.Nullable;
public record FoodProperties1_20_5(int nutrition, float saturationModifier, boolean canAlwaysEat, float eatSeconds,
Item usingConvertsTo, FoodEffect[] possibleEffects) {
@Nullable Item usingConvertsTo, FoodEffect[] possibleEffects) {
public static final Type<FoodProperties1_20_5> TYPE1_20_5 = new Type<>(FoodProperties1_20_5.class) {
@Override

View File

@ -423,12 +423,20 @@ public final class BlockItemPacketRewriter1_21_2 extends StructuredItemRewriter<
}
super.handleItemToClient(connection, item);
// Handle food properties item manually here - the only protocol that has it
// The other way around it's handled by the super handleItemToServer method
final StructuredDataContainer data = item.dataContainer();
final FoodProperties1_20_5 food = data.get(StructuredDataKey.FOOD1_21);
if (food != null && food.usingConvertsTo() != null) {
this.handleItemToClient(connection, food.usingConvertsTo());
}
updateItemData(item);
// Add data components to fix issues in older protocols
appendItemDataFixComponents(connection, item);
final StructuredDataContainer data = item.dataContainer();
final Enchantments enchantments = data.get(StructuredDataKey.ENCHANTMENTS);
if (enchantments != null && enchantments.size() != 0) {
// Level 0 is no longer allowed