mirror of
https://github.com/GeyserMC/Geyser.git
synced 2025-03-13 11:18:19 +01:00
Add documentation and change some stuff in the API
This commit is contained in:
parent
1dd854a8b6
commit
4af8e124fa
5 changed files with 87 additions and 23 deletions
|
@ -0,0 +1,34 @@
|
|||
/*
|
||||
* Copyright (c) 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.api.item.custom.v2;
|
||||
|
||||
public enum BedrockCreativeTab {
|
||||
NONE,
|
||||
CONSTRUCTION,
|
||||
NATURE,
|
||||
EQUIPMENT,
|
||||
ITEMS
|
||||
}
|
|
@ -39,34 +39,35 @@ import java.util.Set;
|
|||
public interface CustomItemBedrockOptions {
|
||||
|
||||
/**
|
||||
* Gets the item's icon. When not present, {@code <item model namespace>.<item model path>} is used.
|
||||
* Gets the item's icon. When not present, the item's Bedrock identifier is used.
|
||||
*
|
||||
* @return the item's icon
|
||||
* @see CustomItemDefinition#icon()
|
||||
*/
|
||||
@Nullable
|
||||
String icon();
|
||||
|
||||
/**
|
||||
* Gets if the item is allowed to be put into the offhand.
|
||||
* If the item is allowed to be put into the offhand. Defaults to true.
|
||||
*
|
||||
* @return true if the item is allowed to be used in the offhand, false otherwise
|
||||
*/
|
||||
boolean allowOffhand();
|
||||
|
||||
/**
|
||||
* Gets if the item should be displayed as handheld, like a tool.
|
||||
* If the item should be displayed as handheld, like a tool.
|
||||
*
|
||||
* @return true if the item should be displayed as handheld, false otherwise
|
||||
*/
|
||||
boolean displayHandheld();
|
||||
|
||||
/**
|
||||
* Gets the item's creative category, or tab id.
|
||||
* The item's creative category. Defaults to {@code NONE}.
|
||||
*
|
||||
* @return the item's creative category
|
||||
*/
|
||||
@NonNull
|
||||
OptionalInt creativeCategory();
|
||||
BedrockCreativeTab creativeCategory();
|
||||
|
||||
/**
|
||||
* Gets the item's creative group.
|
||||
|
|
|
@ -31,33 +31,62 @@ import org.geysermc.geyser.api.GeyserApi;
|
|||
import org.geysermc.mcprotocollib.protocol.data.game.item.component.DataComponents;
|
||||
|
||||
/**
|
||||
* This is used to store data for a custom item.
|
||||
*
|
||||
* V2. TODO.
|
||||
* This is used to define a custom item and its properties.
|
||||
*/
|
||||
public interface CustomItemDefinition {
|
||||
|
||||
/**
|
||||
* Gets the item model this definition is for. This model can't be in the Minecraft namespace.
|
||||
* The Bedrock identifier for this custom item. This can't be in the {@code minecraft} namespace. If no namespace is given in the builder, the default
|
||||
* namespace of the implementation is used.
|
||||
*
|
||||
* @implNote for Geyser, this is the {@code geyser_custom} namespace.
|
||||
*/
|
||||
@NonNull Key model(); // TODO name??
|
||||
@NonNull Key bedrockIdentifier();
|
||||
|
||||
default String name() {
|
||||
return model().namespace() + "_" + model().value();
|
||||
} // TODO, also display name ? also, rename to identifier
|
||||
/**
|
||||
* The display name of the item. If none is set, the display name is taken from the item's Bedrock identifier.
|
||||
*/
|
||||
@NonNull String displayName();
|
||||
|
||||
default String icon() {
|
||||
return bedrockOptions().icon() == null ? name() : bedrockOptions().icon();
|
||||
} // TODO
|
||||
/**
|
||||
* The item model this definition is for. If the model is in the {@code minecraft} namespace, then the definition is required to have a predicate.
|
||||
*/
|
||||
@NonNull Key model();
|
||||
|
||||
/**
|
||||
* The icon used for this item.
|
||||
*
|
||||
* <p>If none is set in the item's Bedrock options, then the item's Bedrock identifier is used,
|
||||
* the namespace separator replaced with {@code .} and the path separators ({@code /}) replaced with {@code _}.</p>
|
||||
*/
|
||||
default @NonNull String icon() {
|
||||
return bedrockOptions().icon() == null ? bedrockIdentifier().asString().replaceAll(":", ".").replaceAll("/", "_") : bedrockOptions().icon();
|
||||
}
|
||||
|
||||
// TODO predicate
|
||||
|
||||
// TODO bedrock options
|
||||
|
||||
/**
|
||||
* The item's Bedrock options. These describe item properties that can't be described in item components, e.g. item texture size and if the item is allowed in the off-hand.
|
||||
*/
|
||||
@NonNull CustomItemBedrockOptions bedrockOptions();
|
||||
|
||||
// TODO components
|
||||
|
||||
/**
|
||||
* The item's data components. It is expected that the item <em>always</em> has these components on the server. If the components mismatch, bugs will occur.
|
||||
*
|
||||
* <p>Currently, the following components are supported:</p>
|
||||
*
|
||||
* <ul>
|
||||
* <li>{@code minecraft:consumable}</li>
|
||||
* <li>{@code minecraft:equippable}</li>
|
||||
* <li>{@code minecraft:food}</li>
|
||||
* <li>{@code minecraft:max_damage}</li>
|
||||
* <li>{@code minecraft:max_stack_size}</li>
|
||||
* <li>{@code minecraft:use_cooldown}</li>
|
||||
* </ul>
|
||||
*
|
||||
* <p>Note: some components, for example {@code minecraft:rarity}, {@code minecraft:enchantment_glint_override}, and {@code minecraft:attribute_modifiers} are translated automatically,
|
||||
* and do not have to be specified here.</p>
|
||||
*/
|
||||
@NonNull DataComponents components();
|
||||
|
||||
static Builder builder(Key itemModel) {
|
||||
|
|
|
@ -104,7 +104,7 @@ public class CustomItemRegistryPopulator_v2 {
|
|||
|
||||
static boolean initialCheck(CustomItemDefinition item, Map<String, GeyserMappingItem> mappings) {
|
||||
// TODO check if there's already a same model without predicate and this hasn't a predicate either
|
||||
String name = item.name(); // TODO rename to identifier
|
||||
String name = item.bedrockIdentifier(); // TODO rename to identifier
|
||||
if (name.isEmpty()) {
|
||||
GeyserImpl.getInstance().getLogger().warning("Custom item name is empty?");
|
||||
} else if (Character.isDigit(name.charAt(0))) {
|
||||
|
@ -124,7 +124,7 @@ public class CustomItemRegistryPopulator_v2 {
|
|||
NbtMapBuilder componentBuilder = NbtMap.builder();
|
||||
|
||||
DataComponents components = patchDataComponents(vanillaJavaItem, customItemDefinition);
|
||||
setupBasicItemInfo(customItemDefinition.name(), customItemDefinition, components, itemProperties, componentBuilder);
|
||||
setupBasicItemInfo(customItemDefinition.bedrockIdentifier(), customItemDefinition, components, itemProperties, componentBuilder);
|
||||
|
||||
boolean canDestroyInCreative = true;
|
||||
if (vanillaMapping.getToolType() != null) { // This is not using the isTool boolean because it is not just a render type here.
|
||||
|
|
|
@ -463,7 +463,7 @@ public class ItemRegistryPopulator {
|
|||
for (CustomItemDefinition customItem : customItemsToLoad) {
|
||||
int customProtocolId = nextFreeBedrockId++;
|
||||
|
||||
String customItemName = customItem instanceof NonVanillaCustomItemData nonVanillaItem ? nonVanillaItem.identifier() : Constants.GEYSER_CUSTOM_NAMESPACE + ":" + customItem.name(); // TODO bedrock identifier + non vanilla stuff
|
||||
String customItemName = customItem instanceof NonVanillaCustomItemData nonVanillaItem ? nonVanillaItem.identifier() : Constants.GEYSER_CUSTOM_NAMESPACE + ":" + customItem.bedrockIdentifier(); // TODO bedrock identifier + non vanilla stuff
|
||||
if (!registeredItemNames.add(customItemName)) {
|
||||
if (firstMappingsPass) {
|
||||
GeyserImpl.getInstance().getLogger().error("Custom item name '" + customItemName + "' already exists and was registered again! Skipping...");
|
||||
|
|
Loading…
Add table
Reference in a new issue