Skip to content

Commit

Permalink
Rename stuff to better match conditions
Browse files Browse the repository at this point in the history
  • Loading branch information
LLytho committed Jul 6, 2024
1 parent 9042568 commit 286d3cc
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 14 deletions.
31 changes: 31 additions & 0 deletions example_scripts/predicates.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,3 +131,34 @@ LootJS.modifiers(event => {

event.addEntityModifier("minecraft:chicken").addLoot(entry)
})

/**
* Distance predicate test
*/
LootJS.modifiers(event => {
const entry = LootEntry.testItem("ItemPredicate").matchTool({
items: {
type: "neoforge:or",
values: [
"@minecraft",
"#c:tools",
/someRegexValue/,
{
type: "neoforge:any"
}
]
},
predicates: {
enchantments: [
{
enchantments: "@minecraft", // Checks if nested holder set still works in predicate
levels: {
min: 3
}
}
]
}
})

event.addEntityModifier("minecraft:chicken").addLoot(entry)
})
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,7 @@ public void registerBindings(BindingRegistry bindings) {
bindings.add("LootCondition", new LootCondition());
bindings.add("LootFunction", new LootFunction());

bindings.add("IntBounds", MinMaxBounds.Ints.class);
bindings.add("Bounds", MinMaxBounds.Doubles.class);

bindings.add("Range", MinMaxBounds.Doubles.class);
bindings.add("NumberProvider", NumberProviderWrapper.class);

bindings.add("Predicates", Predicates.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ default C isLightLevel(int min, int max) {
}

default C luck(MinMaxBounds.Doubles bounds) {
return customPlayerCheck(serverPlayer -> bounds.matches(serverPlayer.getLuck()));
return matchPlayerCustom(serverPlayer -> bounds.matches(serverPlayer.getLuck()));
}

default C killedByPlayer() {
Expand All @@ -161,13 +161,13 @@ default C matchEntity(EntityPredicate entityPredicate) {
.build());
}

default C matchKiller(EntityPredicate entityPredicate) {
default C matchAttacker(EntityPredicate entityPredicate) {
return addCondition(LootItemEntityPropertyCondition
.hasProperties(LootContext.EntityTarget.ATTACKER, entityPredicate)
.build());
}

default C matchDirectKiller(EntityPredicate entityPredicate) {
default C matchDirectAttacker(EntityPredicate entityPredicate) {
return addCondition(LootItemEntityPropertyCondition
.hasProperties(LootContext.EntityTarget.DIRECT_ATTACKER, entityPredicate)
.build());
Expand All @@ -181,23 +181,23 @@ default C matchDamageSource(DamageSourcePredicate predicate) {
return addCondition(new DamageSourceCondition(Optional.of(predicate)));
}

default C distance(DistancePredicate distancePredicate) {
default C matchDistance(DistancePredicate distancePredicate) {
return addCondition(new MatchKillerDistance(distancePredicate));
}

default C customPlayerCheck(Predicate<ServerPlayer> predicate) {
default C matchPlayerCustom(Predicate<ServerPlayer> predicate) {
return addCondition(new PlayerParamPredicate(predicate));
}

default C customEntityCheck(Predicate<Entity> predicate) {
default C matchEntityCustom(Predicate<Entity> predicate) {
return addCondition(new CustomParamPredicate<>(LootContextParams.THIS_ENTITY, predicate));
}

default C customKillerCheck(Predicate<Entity> predicate) {
default C matchAttackerCustom(Predicate<Entity> predicate) {
return addCondition(new CustomParamPredicate<>(LootContextParams.ATTACKING_ENTITY, predicate));
}

default C customDirectKillerCheck(Predicate<Entity> predicate) {
default C matchDirectAttackerCustom(Predicate<Entity> predicate) {
return addCondition(new CustomParamPredicate<>(LootContextParams.DIRECT_ATTACKING_ENTITY, predicate));
}

Expand Down Expand Up @@ -232,7 +232,7 @@ default C matchAllOf(LootItemCondition... conditions) {
return addCondition(new AllOfCondition(Arrays.asList(conditions)));
}

default C jsonCondition(JsonObject json) {
default C matchCustomCondition(JsonObject json) {
var regOps = RegistryOps.create(JsonOps.INSTANCE, LootJS.lookup());
var condition = LootItemCondition.CODEC.parse(regOps, json).getOrThrow().value();
return addCondition(condition);
Expand Down
4 changes: 2 additions & 2 deletions src/test/java/testmod/gametest/ConditionsContainer.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public void entityTarget_Entity(GameTestHelper helper) {
@GameTest(template = GameTestTemplates.EMPTY)
public void entityTarget_Killer(GameTestHelper helper) {
helper.succeedIf(() -> {
var condition = (LootItemEntityPropertyCondition) new LootCondition().matchKiller(EntityPredicate.Builder
var condition = (LootItemEntityPropertyCondition) new LootCondition().matchAttacker(EntityPredicate.Builder
.entity()
.build());
GameTestUtils.assertEquals(helper,
Expand All @@ -41,7 +41,7 @@ public void entityTarget_Killer(GameTestHelper helper) {
@GameTest(template = GameTestTemplates.EMPTY)
public void entityTarget_DirectKiller(GameTestHelper helper) {
helper.succeedIf(() -> {
var condition = (LootItemEntityPropertyCondition) new LootCondition().matchDirectKiller(EntityPredicate.Builder
var condition = (LootItemEntityPropertyCondition) new LootCondition().matchDirectAttacker(EntityPredicate.Builder
.entity()
.build());
GameTestUtils.assertEquals(helper,
Expand Down

0 comments on commit 286d3cc

Please sign in to comment.