mirror of
https://github.com/GeyserMC/Geyser.git
synced 2025-04-17 19:12:14 +02:00
Introduce component converter for tool component and use in custom item registry populator
This commit is contained in:
parent
1b0d3f6fd6
commit
8641196776
3 changed files with 9 additions and 9 deletions
api/src/main/java/org/geysermc/geyser/api/item/custom/v2/component
core/src/main/java/org/geysermc/geyser
|
@ -83,7 +83,7 @@ public final class DataComponent<T> {
|
|||
*/
|
||||
public static final DataComponent<Integer> ENCHANTABLE = create("enchantable", i -> i >= 0);
|
||||
/**
|
||||
* This component is only used for the {@link ToolProperties#canDestroyBlocksInCreative()} option, which will be a feature in Java 1.21.5, but is already in use in Geyser.
|
||||
* This component is only used for the {@link ToolProperties#canDestroyBlocksInCreative()} option.
|
||||
*
|
||||
* <p>Like other components, when not set this will fall back to the default value.</p>
|
||||
*
|
||||
|
|
|
@ -36,6 +36,7 @@ import org.geysermc.mcprotocollib.protocol.data.game.item.component.DataComponen
|
|||
import org.geysermc.mcprotocollib.protocol.data.game.item.component.DataComponents;
|
||||
import org.geysermc.mcprotocollib.protocol.data.game.item.component.Equippable;
|
||||
import org.geysermc.mcprotocollib.protocol.data.game.item.component.FoodProperties;
|
||||
import org.geysermc.mcprotocollib.protocol.data.game.item.component.ToolData;
|
||||
import org.geysermc.mcprotocollib.protocol.data.game.item.component.UseCooldown;
|
||||
import org.geysermc.mcprotocollib.protocol.data.game.level.sound.BuiltinSound;
|
||||
|
||||
|
@ -55,10 +56,8 @@ import java.util.Map;
|
|||
/**
|
||||
* This class is used to convert components from the API module to MCPL ones.
|
||||
*
|
||||
* <p>Most components convert over nicely, and it is very much preferred to have every API component have a converter in here. However, this is not always possible. At the moment, there are 3 exceptions:
|
||||
* <p>Most components convert over nicely, and it is very much preferred to have every API component have a converter in here. However, this is not always possible. At the moment, there are 2 exceptions:
|
||||
* <ul>
|
||||
* <li>The {@link DataComponent#TOOL} component doesn't convert over to its MCPL counterpart as the only reason it's in the API as of right now is the {@code canDestroyInCreative} property. This is a 1.21.5 property,
|
||||
* and once Geyser for 1.21.5 releases, this component should have a converter in here.</li>
|
||||
* <li>The MCPL counterpart of the {@link DataComponent#REPAIRABLE} component is just an ID holder set, which can't be used in the custom item registry populator.
|
||||
* Also see {@link org.geysermc.geyser.registry.populator.CustomItemRegistryPopulator#computeRepairableProperties(Repairable, NbtMapBuilder)}.</li>
|
||||
* <li>Non-vanilla data components (from {@link org.geysermc.geyser.api.item.custom.v2.component.GeyserDataComponent}) don't have converters registered, for obvious reasons.
|
||||
|
@ -109,6 +108,9 @@ public class ComponentConverters {
|
|||
new UseCooldown(value.seconds(), MinecraftKey.identifierToKey(value.cooldownGroup()))));
|
||||
|
||||
registerConverter(DataComponent.ENCHANTABLE, (itemMap, value) -> itemMap.put(DataComponentTypes.ENCHANTABLE, value));
|
||||
|
||||
registerConverter(DataComponent.TOOL, (itemMap, value) -> itemMap.put(DataComponentTypes.TOOL,
|
||||
new ToolData(List.of(), 1.0F, 1, value.canDestroyBlocksInCreative())));
|
||||
}
|
||||
|
||||
private static <T> void registerConverter(DataComponent<T> component, ComponentConverter<T> converter) {
|
||||
|
|
|
@ -44,7 +44,6 @@ import org.geysermc.geyser.api.item.custom.v2.component.Chargeable;
|
|||
import org.geysermc.geyser.api.item.custom.v2.component.DataComponent;
|
||||
import org.geysermc.geyser.api.item.custom.v2.component.GeyserDataComponent;
|
||||
import org.geysermc.geyser.api.item.custom.v2.component.Repairable;
|
||||
import org.geysermc.geyser.api.item.custom.v2.component.ToolProperties;
|
||||
import org.geysermc.geyser.api.item.custom.v2.predicate.CustomItemPredicate;
|
||||
import org.geysermc.geyser.api.item.custom.v2.predicate.condition.ConditionPredicateProperty;
|
||||
import org.geysermc.geyser.api.util.CreativeCategory;
|
||||
|
@ -66,6 +65,7 @@ import org.geysermc.mcprotocollib.protocol.data.game.item.component.DataComponen
|
|||
import org.geysermc.mcprotocollib.protocol.data.game.item.component.DataComponents;
|
||||
import org.geysermc.mcprotocollib.protocol.data.game.item.component.Equippable;
|
||||
import org.geysermc.mcprotocollib.protocol.data.game.item.component.FoodProperties;
|
||||
import org.geysermc.mcprotocollib.protocol.data.game.item.component.ToolData;
|
||||
import org.geysermc.mcprotocollib.protocol.data.game.item.component.UseCooldown;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
@ -279,10 +279,8 @@ public class CustomItemRegistryPopulator {
|
|||
.build());
|
||||
}
|
||||
|
||||
// Temporary workaround: when 1.21.5 releases, this value will be mapped to an MCPL tool component, and this code will look nicer
|
||||
// since we can get the value from the vanilla item component instead of using the vanilla mapping.
|
||||
ToolProperties toolProperties = customItemDefinition.components().get(DataComponent.TOOL);
|
||||
boolean canDestroyInCreative = toolProperties == null ? !"sword".equals(vanillaMapping.map(GeyserMappingItem::getToolType).orElse("")) : toolProperties.canDestroyBlocksInCreative();
|
||||
ToolData toolData = components.get(DataComponentTypes.TOOL);
|
||||
boolean canDestroyInCreative = toolData == null || toolData.isCanDestroyBlocksInCreative();
|
||||
computeCreativeDestroyProperties(canDestroyInCreative, itemProperties, componentBuilder);
|
||||
|
||||
// Using API component here because MCPL one is just an ID holder set
|
||||
|
|
Loading…
Add table
Reference in a new issue