-
Notifications
You must be signed in to change notification settings - Fork 91
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
62 additions
and
102 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
53 changes: 22 additions & 31 deletions
53
src/main/java/com/jsorrell/carpetskyadditions/advancements/criterion/AllayVexTrigger.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 |
---|---|---|
@@ -1,54 +1,45 @@ | ||
package com.jsorrell.carpetskyadditions.advancements.criterion; | ||
|
||
import com.google.gson.JsonObject; | ||
import com.mojang.serialization.Codec; | ||
import com.mojang.serialization.codecs.RecordCodecBuilder; | ||
import java.util.Optional; | ||
import net.minecraft.advancements.critereon.*; | ||
import net.minecraft.server.level.ServerPlayer; | ||
import net.minecraft.util.ExtraCodecs; | ||
import net.minecraft.world.entity.animal.allay.Allay; | ||
import net.minecraft.world.entity.monster.Vex; | ||
import net.minecraft.world.level.storage.loot.LootContext; | ||
|
||
@SuppressWarnings("OptionalUsedAsFieldOrParameterType") | ||
public class AllayVexTrigger extends SimpleCriterionTrigger<AllayVexTrigger.TriggerInstance> { | ||
@Override | ||
public Codec<TriggerInstance> codec() { | ||
return TriggerInstance.CODEC; | ||
} | ||
|
||
public void trigger(ServerPlayer player, Vex vex, Allay allay) { | ||
LootContext vexLootContext = EntityPredicate.createContext(player, vex); | ||
LootContext allayLootContext = EntityPredicate.createContext(player, allay); | ||
trigger(player, triggerInstance -> triggerInstance.matches(vexLootContext, allayLootContext)); | ||
} | ||
|
||
@Override | ||
public TriggerInstance createInstance( | ||
JsonObject json, Optional<ContextAwarePredicate> player, DeserializationContext context) { | ||
Optional<ContextAwarePredicate> vexPredicate = EntityPredicate.fromJson(json, "vex", context); | ||
Optional<ContextAwarePredicate> allayPredicate = EntityPredicate.fromJson(json, "allay", context); | ||
return new TriggerInstance(player, vexPredicate, allayPredicate); | ||
} | ||
|
||
public static class TriggerInstance extends AbstractCriterionTriggerInstance { | ||
private final Optional<ContextAwarePredicate> vex; | ||
private final Optional<ContextAwarePredicate> allay; | ||
|
||
public TriggerInstance( | ||
Optional<ContextAwarePredicate> player, | ||
Optional<ContextAwarePredicate> vex, | ||
Optional<ContextAwarePredicate> allay) { | ||
super(player); | ||
this.vex = vex; | ||
this.allay = allay; | ||
} | ||
public record TriggerInstance( | ||
Optional<ContextAwarePredicate> player, | ||
Optional<ContextAwarePredicate> vex, | ||
Optional<ContextAwarePredicate> allay) | ||
implements SimpleInstance { | ||
|
||
public static final Codec<TriggerInstance> CODEC = RecordCodecBuilder.create(instance -> instance.group( | ||
ExtraCodecs.strictOptionalField(EntityPredicate.ADVANCEMENT_CODEC, "player") | ||
.forGetter(TriggerInstance::player), | ||
ExtraCodecs.strictOptionalField(EntityPredicate.ADVANCEMENT_CODEC, "vex") | ||
.forGetter(TriggerInstance::vex), | ||
ExtraCodecs.strictOptionalField(EntityPredicate.ADVANCEMENT_CODEC, "allay") | ||
.forGetter(TriggerInstance::allay)) | ||
.apply(instance, TriggerInstance::new)); | ||
|
||
public boolean matches(LootContext vexContext, LootContext allayContext) { | ||
return (vex.isEmpty() || vex.get().matches(vexContext)) | ||
&& (allay.isEmpty() || allay.get().matches(allayContext)); | ||
} | ||
|
||
@Override | ||
public JsonObject serializeToJson() { | ||
JsonObject jsonObject = super.serializeToJson(); | ||
|
||
vex.ifPresent(v -> jsonObject.add("vex", v.toJson())); | ||
allay.ifPresent(a -> jsonObject.add("allay", a.toJson())); | ||
return jsonObject; | ||
} | ||
} | ||
} |
51 changes: 21 additions & 30 deletions
51
...ain/java/com/jsorrell/carpetskyadditions/advancements/criterion/ConvertSpiderTrigger.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 |
---|---|---|
@@ -1,53 +1,44 @@ | ||
package com.jsorrell.carpetskyadditions.advancements.criterion; | ||
|
||
import com.google.gson.JsonObject; | ||
import com.mojang.serialization.Codec; | ||
import com.mojang.serialization.codecs.RecordCodecBuilder; | ||
import java.util.Optional; | ||
import net.minecraft.advancements.critereon.*; | ||
import net.minecraft.server.level.ServerPlayer; | ||
import net.minecraft.util.ExtraCodecs; | ||
import net.minecraft.world.entity.monster.CaveSpider; | ||
import net.minecraft.world.entity.monster.Spider; | ||
import net.minecraft.world.level.storage.loot.LootContext; | ||
|
||
@SuppressWarnings("OptionalUsedAsFieldOrParameterType") | ||
public class ConvertSpiderTrigger extends SimpleCriterionTrigger<ConvertSpiderTrigger.TriggerInstance> { | ||
@Override | ||
public Codec<TriggerInstance> codec() { | ||
return TriggerInstance.CODEC; | ||
} | ||
|
||
public void trigger(ServerPlayer player, Spider spider, CaveSpider caveSpider) { | ||
LootContext spiderLootContext = EntityPredicate.createContext(player, spider); | ||
LootContext caveSpiderLootContext = EntityPredicate.createContext(player, caveSpider); | ||
trigger(player, triggerInstance -> triggerInstance.matches(spiderLootContext, caveSpiderLootContext)); | ||
} | ||
|
||
@Override | ||
public TriggerInstance createInstance( | ||
JsonObject json, Optional<ContextAwarePredicate> player, DeserializationContext context) { | ||
Optional<ContextAwarePredicate> spiderPredicate = EntityPredicate.fromJson(json, "spider", context); | ||
Optional<ContextAwarePredicate> caveSpiderPredicate = EntityPredicate.fromJson(json, "cave_spider", context); | ||
return new TriggerInstance(player, spiderPredicate, caveSpiderPredicate); | ||
} | ||
|
||
public static class TriggerInstance extends AbstractCriterionTriggerInstance { | ||
private final Optional<ContextAwarePredicate> spider; | ||
private final Optional<ContextAwarePredicate> caveSpider; | ||
|
||
public TriggerInstance( | ||
Optional<ContextAwarePredicate> player, | ||
Optional<ContextAwarePredicate> spider, | ||
Optional<ContextAwarePredicate> caveSpider) { | ||
super(player); | ||
this.spider = spider; | ||
this.caveSpider = caveSpider; | ||
} | ||
public record TriggerInstance( | ||
Optional<ContextAwarePredicate> player, | ||
Optional<ContextAwarePredicate> spider, | ||
Optional<ContextAwarePredicate> caveSpider) | ||
implements SimpleInstance { | ||
public static final Codec<TriggerInstance> CODEC = RecordCodecBuilder.create(instance -> instance.group( | ||
ExtraCodecs.strictOptionalField(EntityPredicate.ADVANCEMENT_CODEC, "player") | ||
.forGetter(TriggerInstance::player), | ||
ExtraCodecs.strictOptionalField(EntityPredicate.ADVANCEMENT_CODEC, "spider") | ||
.forGetter(TriggerInstance::spider), | ||
ExtraCodecs.strictOptionalField(EntityPredicate.ADVANCEMENT_CODEC, "cave_spider") | ||
.forGetter(TriggerInstance::caveSpider)) | ||
.apply(instance, TriggerInstance::new)); | ||
|
||
public boolean matches(LootContext spiderContext, LootContext caveSpiderContext) { | ||
return (spider.isEmpty() || spider.get().matches(spiderContext)) | ||
&& (caveSpider.isEmpty() || caveSpider.get().matches(caveSpiderContext)); | ||
} | ||
|
||
@Override | ||
public JsonObject serializeToJson() { | ||
JsonObject jsonObject = super.serializeToJson(); | ||
spider.ifPresent(s -> jsonObject.add("spider", s.toJson())); | ||
caveSpider.ifPresent(cs -> jsonObject.add("cave_spider", cs.toJson())); | ||
return jsonObject; | ||
} | ||
} | ||
} |
12 changes: 3 additions & 9 deletions
12
.../com/jsorrell/carpetskyadditions/advancements/criterion/SkyAdditionsCriteriaTriggers.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
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
16 changes: 0 additions & 16 deletions
16
src/main/java/com/jsorrell/carpetskyadditions/mixin/CriteriaTriggersAccessor.java
This file was deleted.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
{ | ||
"pack": { | ||
"pack_format": 18, | ||
"pack_format": 26, | ||
"description": "Accompanying datapack to the Carpet Sky Additions mod" | ||
} | ||
} |
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 |
---|---|---|
@@ -1,6 +1,6 @@ | ||
{ | ||
"pack": { | ||
"pack_format": 18, | ||
"pack_format": 26, | ||
"description": "Acacia start - Also enable SkyBlock datapack" | ||
} | ||
} |
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 |
---|---|---|
@@ -1,6 +1,6 @@ | ||
{ | ||
"pack": { | ||
"pack_format": 18, | ||
"pack_format": 22, | ||
"description": "Translations for the accompanying datapack to the Carpet Sky Additions mod" | ||
} | ||
} |