mirror of
https://github.com/GeyserMC/Geyser.git
synced 2025-01-24 09:16:05 +01:00
Implement range dispatch predicates when converting old mappings to new one's
This commit is contained in:
parent
49f31c9661
commit
9139af2782
4 changed files with 37 additions and 6 deletions
|
@ -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 {
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -215,7 +215,7 @@ public class MappingsReader_v1 extends MappingsReader {
|
|||
customItemData.tags(tagsSet);
|
||||
}
|
||||
|
||||
return customItemData.build().toDefinition(identifier);
|
||||
return customItemData.build().toDefinition(identifier).build();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Add table
Reference in a new issue