3
0
Mirror von https://github.com/GeyserMC/Geyser.git synchronisiert 2024-12-24 15:20:25 +01:00

remove isValidRepairItem in favor of component, remove unneeded item tiers, deprecate repair items and tool tier in NonVanillaCustomItemData

Dieser Commit ist enthalten in:
onebeastchris 2024-12-03 18:35:02 +08:00
Ursprung 289a74975d
Commit 650cb8d473
13 geänderte Dateien mit 19 neuen und 233 gelöschten Zeilen

Datei anzeigen

@ -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<String> repairMaterials();
/**

Datei anzeigen

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

Datei anzeigen

@ -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<Set<Item>> repairIngredients;
ToolTier(int speed, Supplier<Set<Item>> repairIngredients) {
this.speed = speed;
// Lazily initialize as this will likely be called as items are loading
this.repairIngredients = Suppliers.memoize(repairIngredients::get);
}
public Set<Item> getRepairIngredients() {
return repairIngredients.get();
}
@Override
public String toString() {
return this.name().toLowerCase(Locale.ROOT);
}
}

Datei anzeigen

@ -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(':');

Datei anzeigen

@ -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

Datei anzeigen

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

Datei anzeigen

@ -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) {

Datei anzeigen

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

Datei anzeigen

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

Datei anzeigen

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

Datei anzeigen

@ -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

Datei anzeigen

@ -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<String, GeyserMappingItem> items, Multimap<String, CustomItemData> customItems, List<NonVanillaCustomItemData> nonVanillaCustomItems) {
@ -129,18 +135,11 @@ public class CustomItemRegistryPopulator {
public static NonVanillaItemRegistration registerCustomItem(NonVanillaCustomItemData customItemData, int customItemId, int protocolVersion) {
String customIdentifier = customItemData.identifier();
Set<String> 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)

Datei anzeigen

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