Skip to content

Commit c35f090

Browse files
committed
better defaults, add minecraft:any and minecraft:unspecified types
1 parent d932a4d commit c35f090

4 files changed

Lines changed: 23 additions & 17 deletions

File tree

‎src/main/java/cloud/grabsky/heads/object/EntityLootEntry.java‎

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,12 @@ public class EntityLootEntry {
6060
@Getter(AccessLevel.PUBLIC)
6161
private @UnknownNullability ItemStack item;
6262

63+
// This NamespacedKey is used to match any attacker or damage type.
64+
private static final NamespacedKey ANY = new NamespacedKey("minecraft", "any");
65+
66+
// This NamespacedKey is used to match unspecified / null attacker or damage type.
67+
private static final NamespacedKey UNSPECIFIED = new NamespacedKey("minecraft", "unspecified");
68+
6369
@Accessors(fluent = true)
6470
@NoArgsConstructor(access = AccessLevel.PROTECTED)
6571
public static class Chance {
@@ -92,8 +98,8 @@ public static class Matcher {
9298

9399
public boolean matches(final @Nullable String variant, final @Nullable NamespacedKey attacker, final @Nullable NamespacedKey damageType) {
94100
final boolean isVariantMatch = (this.variant == null) || Objects.equals(this.variant, variant);
95-
final boolean isAttackerMatch = (attackers == null || attacker == null) || attackers.contains(attacker);
96-
final boolean isDamageMatch = (damageTypes == null || damageType == null) || damageTypes.contains(damageType);
101+
final boolean isAttackerMatch = (this.attackers != null) && ((this.attackers.contains(ANY) == true || this.attackers.contains(attacker) == true) || (this.attackers.contains(UNSPECIFIED) == false && attacker == null));
102+
final boolean isDamageMatch = (this.damageTypes != null) && ((this.damageTypes.contains(ANY) == true || this.damageTypes.contains(damageType) == true) || (this.damageTypes.contains(UNSPECIFIED) == false && damageType == null));
97103
// Returning whether provided values match.
98104
return isVariantMatch && isAttackerMatch && isDamageMatch;
99105
}

‎src/main/resources/aggressive.json‎

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@
88
"default_matcher": {
99
// Default variant to match. Omitting this field or setting to null will match any variant.
1010
"variant": null,
11-
// Default list of attackers that can initiate the head drop. Omitting this field or setting to null will match any attacker.
12-
"attackers": null,
13-
// Default list of damages that can initiate the head drop. Omitting this field or setting to an null will match any damage type.
14-
"damage_types": null
11+
// Default list of attackers that can initiate the head drop.
12+
"attackers": ["minecraft:player"],
13+
// Default list of damages that can initiate the head drop.
14+
"damage_types": ["minecraft:any"]
1515
},
1616
// Default permission required to initiate the head drop. Setting to "" will disable the condition check.
17-
"permission": "heads.plugin.can_receive_drops",
17+
"permission": "",
1818
// Default message that will be sent to the player when they receive a head.
1919
"message": "<dark_gray>› <green>Congrats! <gray>You received <item><reset><gray> from the killed mob.",
2020
// List of entity definitions defined within this group.
@@ -69,6 +69,8 @@
6969
],
7070
"minecraft:creaking": [
7171
{
72+
// Creaking death might not be caused by a player.
73+
"matcher": { "attackers": ["minecraft:any"] },
7274
"item": {
7375
"material": "minecraft:player_head",
7476
"meta": {

‎src/main/resources/passive.json‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@
88
"default_matcher": {
99
// Default variant to match. Omitting this field or setting to null will match any variant.
1010
"variant": null,
11-
// Default list of attackers that can initiate the head drop. Omitting this field or setting to null will match any attacker.
12-
"attackers": null,
13-
// Default list of damages that can initiate the head drop. Omitting this field or setting to an null will match any damage type.
14-
"damage_types": null
11+
// Default list of attackers that can initiate the head drop.
12+
"attackers": ["minecraft:player"],
13+
// Default list of damages that can initiate the head drop.
14+
"damage_types": ["minecraft:any"]
1515
},
1616
// Default permission required to initiate the head drop. Setting to "" will disable the condition check.
17-
"permission": "heads.plugin.can_receive_drops",
17+
"permission": "",
1818
// Default message that will be sent to the player when they receive a head.
1919
"message": "<dark_gray>› <green>Congrats! <gray>You received <item><reset><gray> from the killed mob.",
2020
// List of entity definitions defined within this group.

‎src/main/resources/player.json‎

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,13 @@
66
"per_looting_level": 0.0
77
},
88
"default_matcher": {
9-
// Default variant to match. Omitting this field or setting to null will match any variant.
10-
"variant": null,
11-
// Default list of attackers that can initiate the head drop. Omitting this field or setting to null will match any attacker.
9+
// Default list of attackers that can initiate the head drop.
1210
"attackers": ["minecraft:player"],
13-
// Default list of damages that can initiate the head drop. Omitting this field or setting to an null will match any damage type.
11+
// Default list of damages that can initiate the head drop.
1412
"damage_types": ["minecraft:player_attack"]
1513
},
1614
// Default permission required to initiate the head drop. Setting to "" will disable the condition check.
17-
"permission": "heads.plugin.can_receive_drops",
15+
"permission": "",
1816
// Default message that will be sent to the player when they receive a head.
1917
"message": "<dark_gray>› <green>Congrats! <gray>You received <item><reset><gray> from the killed player.",
2018
// List of entity definitions defined within this group.

0 commit comments

Comments
 (0)