-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add advancement triggers and some new advancements (#96)
* Start custom advancement triggers * Add advancement triggers and some new advancements
- Loading branch information
Showing
13 changed files
with
291 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
55 changes: 55 additions & 0 deletions
55
src/generated/resources/data/allomancy/advancements/main/consequences.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
{ | ||
"parent": "allomancy:main/metallurgist", | ||
"criteria": { | ||
"pulled_iron_golem": { | ||
"conditions": { | ||
"entity": [ | ||
{ | ||
"condition": "minecraft:entity_properties", | ||
"entity": "this", | ||
"predicate": { | ||
"type": "minecraft:iron_golem" | ||
} | ||
} | ||
], | ||
"metal": "iron" | ||
}, | ||
"trigger": "allomancy:metal_used_on_entity" | ||
}, | ||
"pushed_iron_golem": { | ||
"conditions": { | ||
"entity": [ | ||
{ | ||
"condition": "minecraft:entity_properties", | ||
"entity": "this", | ||
"predicate": { | ||
"type": "minecraft:iron_golem" | ||
} | ||
} | ||
], | ||
"metal": "steel" | ||
}, | ||
"trigger": "allomancy:metal_used_on_entity" | ||
} | ||
}, | ||
"display": { | ||
"announce_to_chat": false, | ||
"description": { | ||
"translate": "advancements.consequences.desc" | ||
}, | ||
"hidden": true, | ||
"icon": { | ||
"item": "minecraft:iron_block" | ||
}, | ||
"title": { | ||
"translate": "advancements.consequences.title" | ||
} | ||
}, | ||
"requirements": [ | ||
[ | ||
"pushed_iron_golem", | ||
"pulled_iron_golem" | ||
] | ||
], | ||
"sends_telemetry_event": true | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
...ain/java/com/legobmw99/allomancy/modules/extras/advancement/MetalUsedOnEntityTrigger.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package com.legobmw99.allomancy.modules.extras.advancement; | ||
|
||
import com.legobmw99.allomancy.api.enums.Metal; | ||
import com.legobmw99.allomancy.modules.extras.ExtrasSetup; | ||
import com.mojang.serialization.Codec; | ||
import com.mojang.serialization.codecs.RecordCodecBuilder; | ||
import net.minecraft.advancements.Criterion; | ||
import net.minecraft.advancements.critereon.ContextAwarePredicate; | ||
import net.minecraft.advancements.critereon.EntityPredicate; | ||
import net.minecraft.advancements.critereon.SimpleCriterionTrigger; | ||
import net.minecraft.server.level.ServerPlayer; | ||
import net.minecraft.util.ExtraCodecs; | ||
import net.minecraft.world.entity.Entity; | ||
import net.minecraft.world.level.storage.loot.LootContext; | ||
|
||
import java.util.Optional; | ||
|
||
/** | ||
* Triggered when a player affects a mob with Allomancy | ||
* This currently only means: zinc, brass, iron, steel | ||
*/ | ||
public class MetalUsedOnEntityTrigger extends SimpleCriterionTrigger<MetalUsedOnEntityTrigger.TriggerInstance> { | ||
@Override | ||
public Codec codec() { | ||
return TriggerInstance.CODEC; | ||
} | ||
|
||
public void trigger(ServerPlayer player, Entity entity, Metal mt, boolean enhanced) { | ||
LootContext lootcontext = EntityPredicate.createContext(player, entity); | ||
this.trigger(player, p_48112_ -> p_48112_.matches(lootcontext, mt, enhanced)); | ||
} | ||
|
||
public record TriggerInstance(Optional<ContextAwarePredicate> player, Optional<ContextAwarePredicate> entityPredicate, Metal mt, | ||
Optional<Boolean> enhanced) implements SimpleCriterionTrigger.SimpleInstance { | ||
public static final Codec<TriggerInstance> CODEC = RecordCodecBuilder.create(builder -> builder | ||
.group(ExtraCodecs.strictOptionalField(EntityPredicate.ADVANCEMENT_CODEC, "player").forGetter(TriggerInstance::player), | ||
ExtraCodecs.strictOptionalField(EntityPredicate.ADVANCEMENT_CODEC, "entity").forGetter(TriggerInstance::entityPredicate), | ||
Metal.CODEC.fieldOf("metal").forGetter(TriggerInstance::mt), Codec.BOOL.optionalFieldOf("enhanced").forGetter(TriggerInstance::enhanced)) | ||
.apply(builder, TriggerInstance::new)); | ||
|
||
public static Criterion<TriggerInstance> instance(Optional<ContextAwarePredicate> player, Optional<ContextAwarePredicate> entityPredicate, Metal mt) { | ||
return ExtrasSetup.METAL_USED_ON_ENTITY_TRIGGER.get().createCriterion(new TriggerInstance(player, entityPredicate, mt, Optional.empty())); | ||
} | ||
|
||
public static Criterion<TriggerInstance> instance(Optional<ContextAwarePredicate> player, Optional<ContextAwarePredicate> entityPredicate, Metal mt, boolean enhanced) { | ||
return ExtrasSetup.METAL_USED_ON_ENTITY_TRIGGER.get().createCriterion(new TriggerInstance(player, entityPredicate, mt, Optional.of(enhanced))); | ||
} | ||
|
||
boolean matches(LootContext entity, Metal mt, boolean enhanced) { | ||
return this.mt == mt && (this.entityPredicate.isEmpty() || this.entityPredicate.get().matches(entity)) && | ||
(this.enhanced().isEmpty() || this.enhanced().get() == enhanced); | ||
} | ||
} | ||
} |
52 changes: 52 additions & 0 deletions
52
...ain/java/com/legobmw99/allomancy/modules/extras/advancement/MetalUsedOnPlayerTrigger.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package com.legobmw99.allomancy.modules.extras.advancement; | ||
|
||
import com.legobmw99.allomancy.api.enums.Metal; | ||
import com.legobmw99.allomancy.modules.extras.ExtrasSetup; | ||
import com.mojang.serialization.Codec; | ||
import com.mojang.serialization.codecs.RecordCodecBuilder; | ||
import net.minecraft.advancements.Criterion; | ||
import net.minecraft.advancements.critereon.ContextAwarePredicate; | ||
import net.minecraft.advancements.critereon.EntityPredicate; | ||
import net.minecraft.advancements.critereon.SimpleCriterionTrigger; | ||
import net.minecraft.server.level.ServerPlayer; | ||
import net.minecraft.util.ExtraCodecs; | ||
|
||
import java.util.Optional; | ||
|
||
/** | ||
* Triggered when a player is affected by Allomancy from another player | ||
* This currently only means: chromium, nicrosil, iron, steel | ||
*/ | ||
public class MetalUsedOnPlayerTrigger extends SimpleCriterionTrigger<MetalUsedOnPlayerTrigger.TriggerInstance> { | ||
@Override | ||
public Codec codec() { | ||
return TriggerInstance.CODEC; | ||
} | ||
|
||
public void trigger(ServerPlayer player, Metal mt, boolean enhanced) { | ||
this.trigger(player, p_48112_ -> p_48112_.matches(mt, enhanced)); | ||
} | ||
|
||
public record TriggerInstance(Optional<ContextAwarePredicate> player, Metal mt, Optional<Boolean> enhanced) implements SimpleInstance { | ||
public static final Codec<TriggerInstance> CODEC = RecordCodecBuilder.create(builder -> builder | ||
.group(ExtraCodecs.strictOptionalField(EntityPredicate.ADVANCEMENT_CODEC, "player").forGetter(TriggerInstance::player), | ||
Metal.CODEC.fieldOf("metal").forGetter(TriggerInstance::mt), Codec.BOOL.optionalFieldOf("enhanced").forGetter(TriggerInstance::enhanced)) | ||
.apply(builder, TriggerInstance::new)); | ||
|
||
|
||
public static Criterion<TriggerInstance> instance(Optional<ContextAwarePredicate> player, Metal mt) { | ||
return ExtrasSetup.METAL_USED_ON_PLAYER_TRIGGER.get().createCriterion(new TriggerInstance(player, mt, Optional.empty())); | ||
} | ||
|
||
public static Criterion<TriggerInstance> instance(Optional<ContextAwarePredicate> player, Metal mt, boolean enhanced) { | ||
return ExtrasSetup.METAL_USED_ON_PLAYER_TRIGGER.get().createCriterion(new TriggerInstance(player, mt, Optional.of(enhanced))); | ||
} | ||
|
||
|
||
boolean matches(Metal mt, boolean enhanced) { | ||
return this.mt == mt && (this.enhanced().isEmpty() || this.enhanced().get() == enhanced); | ||
} | ||
|
||
|
||
} | ||
} |
Oops, something went wrong.