Implement range dispatch predicates when converting old mappings to new one's

This commit is contained in:
Eclipse 2024-12-06 10:26:32 +00:00
parent 49f31c9661
commit 9139af2782
No known key found for this signature in database
GPG key ID: 95E6998F82EC938A
4 changed files with 37 additions and 6 deletions

View file

@ -32,7 +32,9 @@ import org.geysermc.geyser.api.GeyserApi;
import org.geysermc.geyser.api.item.custom.v2.BedrockCreativeTab;
import org.geysermc.geyser.api.item.custom.v2.CustomItemBedrockOptions;
import org.geysermc.geyser.api.item.custom.v2.CustomItemDefinition;
import org.geysermc.geyser.api.item.custom.v2.predicate.RangeDispatchPredicate;
import java.util.List;
import java.util.OptionalInt;
import java.util.Set;
@ -125,9 +127,9 @@ public interface CustomItemData {
return GeyserApi.api().provider(CustomItemData.Builder.class);
}
default CustomItemDefinition toDefinition(String javaItem) {
// TODO predicate
return CustomItemDefinition.builder(Key.key(javaItem), Key.key(javaItem))
default CustomItemDefinition.Builder toDefinition(String javaItem) {
// TODO non vanilla, unbreakable predicate?
CustomItemDefinition.Builder definition = CustomItemDefinition.builder(Key.key(javaItem), Key.key(javaItem))
.displayName(displayName())
.bedrockOptions(CustomItemBedrockOptions.builder()
.icon(icon())
@ -138,8 +140,17 @@ public interface CustomItemData {
.textureSize(textureSize())
.renderOffsets(renderOffsets())
.tags(tags())
)
.build();
);
CustomItemOptions options = customItemOptions();
if (options.customModelData().isPresent()) {
definition.predicate(new RangeDispatchPredicate(RangeDispatchPredicate.RangeDispatchProperty.CUSTOM_MODEL_DATA,
options.customModelData().getAsInt(), 1.0, false, 0));
}
if (options.damagePredicate().isPresent()) {
definition.predicate(new RangeDispatchPredicate(RangeDispatchPredicate.RangeDispatchProperty.DAMAGE, options.damagePredicate().getAsInt()));
}
return definition;
}
interface Builder {

View file

@ -27,6 +27,14 @@ package org.geysermc.geyser.api.item.custom.v2.predicate;
public record ConditionPredicate(ConditionProperty property, boolean expected, int index) implements CustomItemPredicate {
public ConditionPredicate(ConditionProperty property, boolean expected) {
this(property, expected, 0);
}
public ConditionPredicate(ConditionProperty property) {
this(property, true);
}
// TODO maybe we can extend this
public enum ConditionProperty {
BROKEN,

View file

@ -27,6 +27,18 @@ package org.geysermc.geyser.api.item.custom.v2.predicate;
public record RangeDispatchPredicate(RangeDispatchProperty property, double threshold, double scale, boolean normalizeIfPossible, int index) implements CustomItemPredicate {
public RangeDispatchPredicate(RangeDispatchProperty property, double threshold, double scale, boolean normalizeIfPossible) {
this(property, threshold, scale, normalizeIfPossible, 0);
}
public RangeDispatchPredicate(RangeDispatchProperty property, double threshold, double scale) {
this(property, threshold, scale, false);
}
public RangeDispatchPredicate(RangeDispatchProperty property, double threshold) {
this(property, threshold, 1.0);
}
// TODO check if we can change items while bedrock is using them, and if bedrock will continue to use them
public enum RangeDispatchProperty {
BUNDLE_FULLNESS,

View file

@ -215,7 +215,7 @@ public class MappingsReader_v1 extends MappingsReader {
customItemData.tags(tagsSet);
}
return customItemData.build().toDefinition(identifier);
return customItemData.build().toDefinition(identifier).build();
}
/**