Implement the changes in Geyser

This commit is contained in:
Eclipse 2024-11-30 09:34:54 +00:00
parent 4af8e124fa
commit efae1f3665
No known key found for this signature in database
GPG key ID: 95E6998F82EC938A
5 changed files with 30 additions and 17 deletions

View file

@ -30,7 +30,6 @@ import org.checkerframework.checker.nullness.qual.Nullable;
import org.geysermc.geyser.api.GeyserApi;
import org.geysermc.geyser.api.item.custom.CustomRenderOffsets;
import java.util.OptionalInt;
import java.util.Set;
/**
@ -113,7 +112,7 @@ public interface CustomItemBedrockOptions {
Builder displayHandheld(boolean displayHandheld);
Builder creativeCategory(int creativeCategory);
Builder creativeCategory(BedrockCreativeTab creativeCategory);
Builder creativeGroup(@Nullable String creativeGroup);

View file

@ -36,10 +36,10 @@ import org.geysermc.mcprotocollib.protocol.data.game.item.component.DataComponen
public interface CustomItemDefinition {
/**
* 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
* The Bedrock identifier for this custom item. This can't be in the {@code minecraft} namespace. If the {@code minecraft} namespace is given in the builder, the default
* namespace of the implementation is used.
*
* @implNote for Geyser, this is the {@code geyser_custom} namespace.
* @implNote for Geyser, the default namespace is the {@code geyser_custom} namespace.
*/
@NonNull Key bedrockIdentifier();
@ -89,12 +89,14 @@ public interface CustomItemDefinition {
*/
@NonNull DataComponents components();
static Builder builder(Key itemModel) {
return GeyserApi.api().provider(Builder.class, itemModel);
static Builder builder(Key identifier, Key itemModel) {
return GeyserApi.api().provider(Builder.class, identifier, itemModel);
}
interface Builder {
Builder displayName(String displayName);
Builder bedrockOptions(CustomItemBedrockOptions.@NonNull Builder options);
// TODO do we want another format for this?

View file

@ -28,21 +28,21 @@ package org.geysermc.geyser.item.custom;
import org.checkerframework.checker.nullness.qual.NonNull;
import org.checkerframework.checker.nullness.qual.Nullable;
import org.geysermc.geyser.api.item.custom.CustomRenderOffsets;
import org.geysermc.geyser.api.item.custom.v2.BedrockCreativeTab;
import org.geysermc.geyser.api.item.custom.v2.CustomItemBedrockOptions;
import java.util.HashSet;
import java.util.Objects;
import java.util.OptionalInt;
import java.util.Set;
public record GeyserCustomItemBedrockOptions(@Nullable String icon, boolean allowOffhand, boolean displayHandheld, @NonNull OptionalInt creativeCategory, @Nullable String creativeGroup,
public record GeyserCustomItemBedrockOptions(@Nullable String icon, boolean allowOffhand, boolean displayHandheld, @NonNull BedrockCreativeTab creativeCategory, @Nullable String creativeGroup,
int textureSize, @Nullable CustomRenderOffsets renderOffsets, @NonNull Set<String> tags) implements CustomItemBedrockOptions {
public static class Builder implements CustomItemBedrockOptions.Builder {
private String icon = null;
private boolean allowOffhand = true;
private boolean displayHandheld = false;
private OptionalInt creativeCategory = OptionalInt.empty();
private BedrockCreativeTab creativeCategory = BedrockCreativeTab.NONE;
private String creativeGroup = null;
private int textureSize = 16;
private CustomRenderOffsets renderOffsets = null;
@ -67,9 +67,8 @@ public record GeyserCustomItemBedrockOptions(@Nullable String icon, boolean allo
}
@Override
public Builder creativeCategory(int creativeCategory) {
this.creativeCategory = OptionalInt.of(creativeCategory);
// TODO validation?
public Builder creativeCategory(BedrockCreativeTab creativeCategory) {
this.creativeCategory = creativeCategory;
return this;
}

View file

@ -31,17 +31,30 @@ import org.geysermc.geyser.api.item.custom.v2.CustomItemBedrockOptions;
import org.geysermc.geyser.api.item.custom.v2.CustomItemDefinition;
import org.geysermc.mcprotocollib.protocol.data.game.item.component.DataComponents;
public record GeyserCustomItemDefinition(@NonNull Key model, @NonNull CustomItemBedrockOptions bedrockOptions, @NonNull DataComponents components) implements CustomItemDefinition {
import java.util.HashMap;
public record GeyserCustomItemDefinition(@NonNull Key bedrockIdentifier, String displayName, @NonNull Key model,
@NonNull CustomItemBedrockOptions bedrockOptions, @NonNull DataComponents components) implements CustomItemDefinition {
public static class Builder implements CustomItemDefinition.Builder {
private final Key bedrockIdentifier;
private final Key model;
private String displayName;
private CustomItemBedrockOptions bedrockOptions = CustomItemBedrockOptions.builder().build();
private DataComponents components;
private DataComponents components = new DataComponents(new HashMap<>());
public Builder(Key model) {
public Builder(Key bedrockIdentifier, Key model) {
this.bedrockIdentifier = bedrockIdentifier;
this.displayName = bedrockIdentifier.asString();
this.model = model;
}
@Override
public CustomItemDefinition.Builder displayName(String displayName) {
this.displayName = displayName;
return this;
}
@Override
public CustomItemDefinition.Builder bedrockOptions(CustomItemBedrockOptions.@NonNull Builder options) {
this.bedrockOptions = options.build();
@ -56,7 +69,7 @@ public record GeyserCustomItemDefinition(@NonNull Key model, @NonNull CustomItem
@Override
public CustomItemDefinition build() {
return new GeyserCustomItemDefinition(model, bedrockOptions, components);
return new GeyserCustomItemDefinition(bedrockIdentifier, displayName, model, bedrockOptions, components);
}
}
}

View file

@ -90,7 +90,7 @@ public class ProviderRegistryLoader implements RegistryLoader<Map<Class<?>, Prov
providers.put(NonVanillaCustomItemData.Builder.class, args -> new GeyserNonVanillaCustomItemData.Builder());
// items v2
providers.put(CustomItemDefinition.Builder.class, args -> new GeyserCustomItemDefinition.Builder((Key) args[0]));
providers.put(CustomItemDefinition.Builder.class, args -> new GeyserCustomItemDefinition.Builder((Key) args[0], (Key) args[1]));
providers.put(CustomItemBedrockOptions.Builder.class, args -> new GeyserCustomItemBedrockOptions.Builder());
// cameras