From 650cb8d4733f52fa19020a0cf4c8631e205b65fa Mon Sep 17 00:00:00 2001 From: onebeastchris Date: Tue, 3 Dec 2024 18:35:02 +0800 Subject: [PATCH] remove isValidRepairItem in favor of component, remove unneeded item tiers, deprecate repair items and tool tier in NonVanillaCustomItemData --- .../item/custom/NonVanillaCustomItemData.java | 10 ++- .../java/org/geysermc/geyser/item/Items.java | 6 +- .../geyser/item/components/ToolTier.java | 64 ------------------- .../geysermc/geyser/item/type/ArmorItem.java | 10 +-- .../geyser/item/type/DyeableArmorItem.java | 5 +- .../geysermc/geyser/item/type/ElytraItem.java | 39 ----------- .../geysermc/geyser/item/type/LightItem.java | 1 - .../geysermc/geyser/item/type/MaceItem.java | 39 ----------- .../geysermc/geyser/item/type/ShieldItem.java | 7 -- .../geysermc/geyser/item/type/TieredItem.java | 46 ------------- .../geyser/item/type/WolfArmorItem.java | 5 +- .../CustomItemRegistryPopulator.java | 18 +++--- .../geyser/registry/type/ItemMapping.java | 2 - 13 files changed, 19 insertions(+), 233 deletions(-) delete mode 100644 core/src/main/java/org/geysermc/geyser/item/components/ToolTier.java delete mode 100644 core/src/main/java/org/geysermc/geyser/item/type/ElytraItem.java delete mode 100644 core/src/main/java/org/geysermc/geyser/item/type/MaceItem.java delete mode 100644 core/src/main/java/org/geysermc/geyser/item/type/TieredItem.java diff --git a/api/src/main/java/org/geysermc/geyser/api/item/custom/NonVanillaCustomItemData.java b/api/src/main/java/org/geysermc/geyser/api/item/custom/NonVanillaCustomItemData.java index 2c283780c..2fff247a7 100644 --- a/api/src/main/java/org/geysermc/geyser/api/item/custom/NonVanillaCustomItemData.java +++ b/api/src/main/java/org/geysermc/geyser/api/item/custom/NonVanillaCustomItemData.java @@ -80,10 +80,9 @@ public interface NonVanillaCustomItemData extends CustomItemData { @Nullable String toolType(); /** - * Gets the tool tier of the item. - * - * @return the tool tier of the item + * @deprecated no longer used */ + @Deprecated(forRemoval = true) @Nullable String toolTier(); /** @@ -108,10 +107,9 @@ public interface NonVanillaCustomItemData extends CustomItemData { @Nullable String translationString(); /** - * Gets the repair materials of the item. - * - * @return the repair materials of the item + * @deprecated No longer used. */ + @Deprecated(forRemoval = true) @Nullable Set repairMaterials(); /** diff --git a/core/src/main/java/org/geysermc/geyser/item/Items.java b/core/src/main/java/org/geysermc/geyser/item/Items.java index 4a2d5827a..5cdb6c4ce 100644 --- a/core/src/main/java/org/geysermc/geyser/item/Items.java +++ b/core/src/main/java/org/geysermc/geyser/item/Items.java @@ -36,7 +36,6 @@ import org.geysermc.geyser.item.type.CrossbowItem; import org.geysermc.geyser.item.type.DecoratedPotItem; import org.geysermc.geyser.item.type.DyeItem; import org.geysermc.geyser.item.type.DyeableArmorItem; -import org.geysermc.geyser.item.type.ElytraItem; import org.geysermc.geyser.item.type.EnchantedBookItem; import org.geysermc.geyser.item.type.FilledMapItem; import org.geysermc.geyser.item.type.FireworkRocketItem; @@ -44,7 +43,6 @@ import org.geysermc.geyser.item.type.FireworkStarItem; import org.geysermc.geyser.item.type.FishingRodItem; import org.geysermc.geyser.item.type.GoatHornItem; import org.geysermc.geyser.item.type.Item; -import org.geysermc.geyser.item.type.MaceItem; import org.geysermc.geyser.item.type.MapItem; import org.geysermc.geyser.item.type.PlayerHeadItem; import org.geysermc.geyser.item.type.PotionItem; @@ -873,7 +871,7 @@ public final class Items { public static final Item CARROT_ON_A_STICK = register(new Item("carrot_on_a_stick", builder())); public static final Item WARPED_FUNGUS_ON_A_STICK = register(new Item("warped_fungus_on_a_stick", builder())); public static final Item PHANTOM_MEMBRANE = register(new Item("phantom_membrane", builder())); - public static final Item ELYTRA = register(new ElytraItem("elytra", builder())); + public static final Item ELYTRA = register(new Item("elytra", builder())); public static final Item OAK_BOAT = register(new BoatItem("oak_boat", builder())); public static final Item OAK_CHEST_BOAT = register(new BoatItem("oak_chest_boat", builder())); public static final Item SPRUCE_BOAT = register(new BoatItem("spruce_boat", builder())); @@ -1215,7 +1213,7 @@ public final class Items { public static final Item WRITABLE_BOOK = register(new WritableBookItem("writable_book", builder())); public static final Item WRITTEN_BOOK = register(new WrittenBookItem("written_book", builder())); public static final Item BREEZE_ROD = register(new Item("breeze_rod", builder())); - public static final Item MACE = register(new MaceItem("mace", builder())); + public static final Item MACE = register(new Item("mace", builder())); public static final Item ITEM_FRAME = register(new Item("item_frame", builder())); public static final Item GLOW_ITEM_FRAME = register(new Item("glow_item_frame", builder())); public static final Item FLOWER_POT = register(new BlockItem(builder(), Blocks.FLOWER_POT)); diff --git a/core/src/main/java/org/geysermc/geyser/item/components/ToolTier.java b/core/src/main/java/org/geysermc/geyser/item/components/ToolTier.java deleted file mode 100644 index a8832df1e..000000000 --- a/core/src/main/java/org/geysermc/geyser/item/components/ToolTier.java +++ /dev/null @@ -1,64 +0,0 @@ -/* - * Copyright (c) 2019-2022 GeyserMC. http://geysermc.org - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - * - * @author GeyserMC - * @link https://github.com/GeyserMC/Geyser - */ - -package org.geysermc.geyser.item.components; - -import com.google.common.base.Suppliers; -import org.geysermc.geyser.item.Items; -import org.geysermc.geyser.item.type.Item; - -import java.util.Collections; -import java.util.Locale; -import java.util.Set; -import java.util.function.Supplier; - -public enum ToolTier { - WOODEN(2, () -> Set.of(Items.OAK_PLANKS, Items.SPRUCE_PLANKS, Items.BIRCH_PLANKS, Items.JUNGLE_PLANKS, Items.ACACIA_PLANKS, Items.DARK_OAK_PLANKS, Items.CRIMSON_PLANKS, Items.WARPED_PLANKS, Items.MANGROVE_PLANKS)), // PLANKS tag // TODO ? - STONE(4, () -> Set.of(Items.COBBLESTONE, Items.BLACKSTONE, Items.COBBLED_DEEPSLATE)), // STONE_TOOL_MATERIALS tag - IRON(6, () -> Collections.singleton(Items.IRON_INGOT)), - GOLDEN(12, () -> Collections.singleton(Items.GOLD_INGOT)), - DIAMOND(8, () -> Collections.singleton(Items.DIAMOND)), - NETHERITE(9, () -> Collections.singleton(Items.NETHERITE_INGOT)); - - private static final ToolTier[] VALUES = values(); - - private final int speed; - private final Supplier> repairIngredients; - - ToolTier(int speed, Supplier> repairIngredients) { - this.speed = speed; - // Lazily initialize as this will likely be called as items are loading - this.repairIngredients = Suppliers.memoize(repairIngredients::get); - } - - public Set getRepairIngredients() { - return repairIngredients.get(); - } - - @Override - public String toString() { - return this.name().toLowerCase(Locale.ROOT); - } -} diff --git a/core/src/main/java/org/geysermc/geyser/item/type/ArmorItem.java b/core/src/main/java/org/geysermc/geyser/item/type/ArmorItem.java index 0a25a8d4f..ec87728a9 100644 --- a/core/src/main/java/org/geysermc/geyser/item/type/ArmorItem.java +++ b/core/src/main/java/org/geysermc/geyser/item/type/ArmorItem.java @@ -30,7 +30,6 @@ import org.cloudburstmc.nbt.NbtMap; import org.cloudburstmc.nbt.NbtMapBuilder; import org.cloudburstmc.protocol.bedrock.data.TrimMaterial; import org.cloudburstmc.protocol.bedrock.data.TrimPattern; -import org.geysermc.geyser.item.ArmorMaterial; import org.geysermc.geyser.session.GeyserSession; import org.geysermc.geyser.translator.item.BedrockItemBuilder; import org.geysermc.mcprotocollib.protocol.data.game.item.component.ArmorTrim; @@ -38,11 +37,9 @@ import org.geysermc.mcprotocollib.protocol.data.game.item.component.DataComponen import org.geysermc.mcprotocollib.protocol.data.game.item.component.DataComponents; public class ArmorItem extends Item { - private final ArmorMaterial material; - public ArmorItem(String javaIdentifier, ArmorMaterial material, Builder builder) { + public ArmorItem(String javaIdentifier, Builder builder) { super(javaIdentifier, builder); - this.material = material; } @Override @@ -68,11 +65,6 @@ public class ArmorItem extends Item { } } - @Override - public boolean isValidRepairItem(Item other) { - return material.getRepairIngredient() == other; - } - // TODO maybe some kind of namespace util? private static String getNamespace(String identifier) { int i = identifier.indexOf(':'); diff --git a/core/src/main/java/org/geysermc/geyser/item/type/DyeableArmorItem.java b/core/src/main/java/org/geysermc/geyser/item/type/DyeableArmorItem.java index 8c63eaeb0..480385d07 100644 --- a/core/src/main/java/org/geysermc/geyser/item/type/DyeableArmorItem.java +++ b/core/src/main/java/org/geysermc/geyser/item/type/DyeableArmorItem.java @@ -26,14 +26,13 @@ package org.geysermc.geyser.item.type; import org.checkerframework.checker.nullness.qual.NonNull; -import org.geysermc.geyser.item.ArmorMaterial; import org.geysermc.geyser.session.GeyserSession; import org.geysermc.geyser.translator.item.BedrockItemBuilder; import org.geysermc.mcprotocollib.protocol.data.game.item.component.DataComponents; public class DyeableArmorItem extends ArmorItem { - public DyeableArmorItem(String javaIdentifier, ArmorMaterial material, Builder builder) { - super(javaIdentifier, material, builder); + public DyeableArmorItem(String javaIdentifier, Builder builder) { + super(javaIdentifier, builder); } @Override diff --git a/core/src/main/java/org/geysermc/geyser/item/type/ElytraItem.java b/core/src/main/java/org/geysermc/geyser/item/type/ElytraItem.java deleted file mode 100644 index e5d94eb8b..000000000 --- a/core/src/main/java/org/geysermc/geyser/item/type/ElytraItem.java +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Copyright (c) 2019-2022 GeyserMC. http://geysermc.org - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - * - * @author GeyserMC - * @link https://github.com/GeyserMC/Geyser - */ - -package org.geysermc.geyser.item.type; - -import org.geysermc.geyser.item.Items; - -public class ElytraItem extends Item { - public ElytraItem(String javaIdentifier, Builder builder) { - super(javaIdentifier, builder); - } - - @Override - public boolean isValidRepairItem(Item other) { - return other == Items.PHANTOM_MEMBRANE; - } -} diff --git a/core/src/main/java/org/geysermc/geyser/item/type/LightItem.java b/core/src/main/java/org/geysermc/geyser/item/type/LightItem.java index fa10b08b1..d176ff367 100644 --- a/core/src/main/java/org/geysermc/geyser/item/type/LightItem.java +++ b/core/src/main/java/org/geysermc/geyser/item/type/LightItem.java @@ -60,7 +60,6 @@ public class LightItem extends BlockItem { return super.toBedrockDefinition(components, mappings); } - private static ItemMapping getLightLevelMapping(DataComponents components, ItemMappings mappings) { String lightLevel = "15"; if (components != null) { diff --git a/core/src/main/java/org/geysermc/geyser/item/type/MaceItem.java b/core/src/main/java/org/geysermc/geyser/item/type/MaceItem.java deleted file mode 100644 index e7b9a8684..000000000 --- a/core/src/main/java/org/geysermc/geyser/item/type/MaceItem.java +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Copyright (c) 2019-2024 GeyserMC. http://geysermc.org - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - * - * @author GeyserMC - * @link https://github.com/GeyserMC/Geyser - */ - -package org.geysermc.geyser.item.type; - -import org.geysermc.geyser.item.Items; - -public class MaceItem extends Item { - public MaceItem(String javaIdentifier, Builder builder) { - super(javaIdentifier, builder); - } - - @Override - public boolean isValidRepairItem(Item other) { - return other == Items.BREEZE_ROD; - } -} diff --git a/core/src/main/java/org/geysermc/geyser/item/type/ShieldItem.java b/core/src/main/java/org/geysermc/geyser/item/type/ShieldItem.java index 14d41a073..98ef80d95 100644 --- a/core/src/main/java/org/geysermc/geyser/item/type/ShieldItem.java +++ b/core/src/main/java/org/geysermc/geyser/item/type/ShieldItem.java @@ -26,7 +26,6 @@ package org.geysermc.geyser.item.type; import org.checkerframework.checker.nullness.qual.NonNull; -import org.geysermc.geyser.item.components.ToolTier; import org.geysermc.geyser.session.GeyserSession; import org.geysermc.geyser.translator.item.BedrockItemBuilder; import org.geysermc.mcprotocollib.protocol.data.game.item.component.BannerPatternLayer; @@ -54,10 +53,4 @@ public class ShieldItem extends Item { builder.putInt("Base", 15 - baseColor); } } - - @Override - public boolean isValidRepairItem(Item other) { - // Java Edition 1.19.3 checks the tag, but TODO check to see if we want it or are simulating what Bedrock is doing - return ToolTier.WOODEN.getRepairIngredients().contains(other); - } } diff --git a/core/src/main/java/org/geysermc/geyser/item/type/TieredItem.java b/core/src/main/java/org/geysermc/geyser/item/type/TieredItem.java deleted file mode 100644 index d998eb0d4..000000000 --- a/core/src/main/java/org/geysermc/geyser/item/type/TieredItem.java +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Copyright (c) 2019-2022 GeyserMC. http://geysermc.org - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - * - * @author GeyserMC - * @link https://github.com/GeyserMC/Geyser - */ - -package org.geysermc.geyser.item.type; - -import org.geysermc.geyser.item.components.ToolTier; - -public class TieredItem extends Item { - private final ToolTier tier; - - public TieredItem(String javaIdentifier, ToolTier tier, Builder builder) { - super(javaIdentifier, builder); - this.tier = tier; - } - - public ToolTier tier() { - return tier; - } - - @Override - public boolean isValidRepairItem(Item other) { - return tier.getRepairIngredients().contains(other); - } -} diff --git a/core/src/main/java/org/geysermc/geyser/item/type/WolfArmorItem.java b/core/src/main/java/org/geysermc/geyser/item/type/WolfArmorItem.java index bd97a6a7d..52ded0407 100644 --- a/core/src/main/java/org/geysermc/geyser/item/type/WolfArmorItem.java +++ b/core/src/main/java/org/geysermc/geyser/item/type/WolfArmorItem.java @@ -26,14 +26,13 @@ package org.geysermc.geyser.item.type; import org.checkerframework.checker.nullness.qual.NonNull; -import org.geysermc.geyser.item.ArmorMaterial; import org.geysermc.geyser.session.GeyserSession; import org.geysermc.geyser.translator.item.BedrockItemBuilder; import org.geysermc.mcprotocollib.protocol.data.game.item.component.DataComponents; public class WolfArmorItem extends ArmorItem { - public WolfArmorItem(String javaIdentifier, ArmorMaterial material, Builder builder) { - super(javaIdentifier, material, builder); + public WolfArmorItem(String javaIdentifier, Builder builder) { + super(javaIdentifier, builder); } @Override diff --git a/core/src/main/java/org/geysermc/geyser/registry/populator/CustomItemRegistryPopulator.java b/core/src/main/java/org/geysermc/geyser/registry/populator/CustomItemRegistryPopulator.java index ec094ea31..3d2ca4ef9 100644 --- a/core/src/main/java/org/geysermc/geyser/registry/populator/CustomItemRegistryPopulator.java +++ b/core/src/main/java/org/geysermc/geyser/registry/populator/CustomItemRegistryPopulator.java @@ -51,7 +51,13 @@ import org.geysermc.geyser.registry.type.NonVanillaItemRegistration; import org.geysermc.mcprotocollib.protocol.data.game.item.component.DataComponentType; import org.geysermc.mcprotocollib.protocol.data.game.item.component.DataComponents; -import java.util.*; +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Objects; +import java.util.Set; public class CustomItemRegistryPopulator { public static void populate(Map items, Multimap customItems, List nonVanillaCustomItems) { @@ -129,18 +135,11 @@ public class CustomItemRegistryPopulator { public static NonVanillaItemRegistration registerCustomItem(NonVanillaCustomItemData customItemData, int customItemId, int protocolVersion) { String customIdentifier = customItemData.identifier(); - Set repairMaterials = customItemData.repairMaterials(); - DataComponents components = new DataComponents(new HashMap<>()); components.put(DataComponentType.MAX_STACK_SIZE, customItemData.stackSize()); components.put(DataComponentType.MAX_DAMAGE, customItemData.maxDamage()); - Item item = new Item(customIdentifier, Item.builder().components(components)) { - @Override - public boolean isValidRepairItem(Item other) { - return repairMaterials != null && repairMaterials.contains(other.javaIdentifier()); - } - }; + Item item = new Item(customIdentifier, Item.builder().components(components)); Items.register(item, customItemData.javaId()); ItemMapping customItemMapping = ItemMapping.builder() @@ -148,7 +147,6 @@ public class CustomItemRegistryPopulator { .bedrockData(0) .bedrockBlockDefinition(null) .toolType(customItemData.toolType()) - .toolTier(customItemData.toolTier()) .translationString(customItemData.translationString()) .customItemOptions(Collections.emptyList()) .javaItem(item) diff --git a/core/src/main/java/org/geysermc/geyser/registry/type/ItemMapping.java b/core/src/main/java/org/geysermc/geyser/registry/type/ItemMapping.java index 8a2c77f28..d940db6e0 100644 --- a/core/src/main/java/org/geysermc/geyser/registry/type/ItemMapping.java +++ b/core/src/main/java/org/geysermc/geyser/registry/type/ItemMapping.java @@ -52,7 +52,6 @@ public class ItemMapping { null, // Air is never sent in full over the network for this to serialize. null, null, - null, Collections.emptyList(), Items.AIR ); @@ -68,7 +67,6 @@ public class ItemMapping { BlockDefinition bedrockBlockDefinition; String toolType; - String toolTier; String translationString;