Skip to content

Commit

Permalink
ported to 1.20.2
Browse files Browse the repository at this point in the history
  • Loading branch information
Luke100000 committed Jan 30, 2024
1 parent 23ee3c5 commit bb4177b
Show file tree
Hide file tree
Showing 50 changed files with 313 additions and 425 deletions.
Original file line number Diff line number Diff line change
@@ -1,39 +1,31 @@
package net.mca.advancement.criterion;

import com.google.gson.JsonObject;
import net.mca.MCA;
import net.minecraft.advancement.criterion.AbstractCriterion;
import net.minecraft.advancement.criterion.AbstractCriterionConditions;
import net.minecraft.predicate.NumberRange;
import net.minecraft.predicate.entity.AdvancementEntityPredicateDeserializer;
import net.minecraft.predicate.entity.AdvancementEntityPredicateSerializer;
import net.minecraft.predicate.entity.LootContextPredicate;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.util.Identifier;

public class BabyCriterion extends AbstractCriterion<BabyCriterion.Conditions> {
private static final Identifier ID = MCA.locate("baby");

@Override
public Identifier getId() {
return ID;
}
import java.util.Optional;

public class BabyCriterion extends AbstractCriterion<BabyCriterion.Conditions> {
@Override
public Conditions conditionsFromJson(JsonObject json, LootContextPredicate player, AdvancementEntityPredicateDeserializer deserializer) {
public Conditions conditionsFromJson(JsonObject json, Optional<LootContextPredicate> player, AdvancementEntityPredicateDeserializer deserializer) {
NumberRange.IntRange c = NumberRange.IntRange.fromJson(json.get("count"));
return new Conditions(player, c);
}

public void trigger(ServerPlayerEntity player, int c) {
trigger(player, (conditions) -> conditions.test(c));
trigger(player, conditions -> conditions.test(c));
}

public static class Conditions extends AbstractCriterionConditions {
private final NumberRange.IntRange count;

public Conditions(LootContextPredicate player, NumberRange.IntRange count) {
super(BabyCriterion.ID, player);
public Conditions(Optional<LootContextPredicate> player, NumberRange.IntRange count) {
super(player);
this.count = count;
}

Expand All @@ -42,8 +34,8 @@ public boolean test(int c) {
}

@Override
public JsonObject toJson(AdvancementEntityPredicateSerializer serializer) {
JsonObject json = super.toJson(serializer);
public JsonObject toJson() {
JsonObject json = super.toJson();
json.add("count", count.toJson());
return json;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,39 +1,31 @@
package net.mca.advancement.criterion;

import com.google.gson.JsonObject;
import net.mca.MCA;
import net.minecraft.advancement.criterion.AbstractCriterion;
import net.minecraft.advancement.criterion.AbstractCriterionConditions;
import net.minecraft.predicate.NumberRange;
import net.minecraft.predicate.entity.AdvancementEntityPredicateDeserializer;
import net.minecraft.predicate.entity.AdvancementEntityPredicateSerializer;
import net.minecraft.predicate.entity.LootContextPredicate;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.util.Identifier;

public class BabyDroppedCriterion extends AbstractCriterion<BabyDroppedCriterion.Conditions> {
private static final Identifier ID = MCA.locate("baby_dropped");

@Override
public Identifier getId() {
return ID;
}
import java.util.Optional;

public class BabyDroppedCriterion extends AbstractCriterion<BabyDroppedCriterion.Conditions> {
@Override
public Conditions conditionsFromJson(JsonObject json, LootContextPredicate player, AdvancementEntityPredicateDeserializer deserializer) {
public Conditions conditionsFromJson(JsonObject json, Optional<LootContextPredicate> player, AdvancementEntityPredicateDeserializer deserializer) {
NumberRange.IntRange c = NumberRange.IntRange.atLeast(json.get("count").getAsInt());
return new Conditions(player, c);
}

public void trigger(ServerPlayerEntity player, int c) {
trigger(player, (conditions) -> conditions.test(c));
trigger(player, conditions -> conditions.test(c));
}

public static class Conditions extends AbstractCriterionConditions {
private final NumberRange.IntRange count;

public Conditions(LootContextPredicate player, NumberRange.IntRange count) {
super(BabyDroppedCriterion.ID, player);
public Conditions(Optional<LootContextPredicate> player, NumberRange.IntRange count) {
super(player);
this.count = count;
}

Expand All @@ -42,8 +34,8 @@ public boolean test(int c) {
}

@Override
public JsonObject toJson(AdvancementEntityPredicateSerializer serializer) {
JsonObject json = super.toJson(serializer);
public JsonObject toJson() {
JsonObject json = super.toJson();
json.add("count", count.toJson());
return json;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,39 +1,31 @@
package net.mca.advancement.criterion;

import com.google.gson.JsonObject;
import net.mca.MCA;
import net.minecraft.advancement.criterion.AbstractCriterion;
import net.minecraft.advancement.criterion.AbstractCriterionConditions;
import net.minecraft.predicate.NumberRange;
import net.minecraft.predicate.entity.AdvancementEntityPredicateDeserializer;
import net.minecraft.predicate.entity.AdvancementEntityPredicateSerializer;
import net.minecraft.predicate.entity.LootContextPredicate;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.util.Identifier;

public class BabySirbenSmeltedCriterion extends AbstractCriterion<BabySirbenSmeltedCriterion.Conditions> {
private static final Identifier ID = MCA.locate("baby_sirben_smelted");

@Override
public Identifier getId() {
return ID;
}
import java.util.Optional;

public class BabySirbenSmeltedCriterion extends AbstractCriterion<BabySirbenSmeltedCriterion.Conditions> {
@Override
public Conditions conditionsFromJson(JsonObject json, LootContextPredicate player, AdvancementEntityPredicateDeserializer deserializer) {
public Conditions conditionsFromJson(JsonObject json, Optional<LootContextPredicate> player, AdvancementEntityPredicateDeserializer deserializer) {
NumberRange.IntRange c = NumberRange.IntRange.atLeast(json.get("count").getAsInt());
return new Conditions(player, c);
}

public void trigger(ServerPlayerEntity player, int c) {
trigger(player, (conditions) -> conditions.test(c));
trigger(player, conditions -> conditions.test(c));
}

public static class Conditions extends AbstractCriterionConditions {
private final NumberRange.IntRange count;

public Conditions(LootContextPredicate player, NumberRange.IntRange count) {
super(BabySirbenSmeltedCriterion.ID, player);
public Conditions(Optional<LootContextPredicate> player, NumberRange.IntRange count) {
super(player);
this.count = count;
}

Expand All @@ -42,8 +34,8 @@ public boolean test(int c) {
}

@Override
public JsonObject toJson(AdvancementEntityPredicateSerializer serializer) {
JsonObject json = super.toJson(serializer);
public JsonObject toJson() {
JsonObject json = super.toJson();
json.add("count", count.toJson());
return json;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,39 +1,31 @@
package net.mca.advancement.criterion;

import com.google.gson.JsonObject;
import net.mca.MCA;
import net.minecraft.advancement.criterion.AbstractCriterion;
import net.minecraft.advancement.criterion.AbstractCriterionConditions;
import net.minecraft.predicate.NumberRange;
import net.minecraft.predicate.entity.AdvancementEntityPredicateDeserializer;
import net.minecraft.predicate.entity.AdvancementEntityPredicateSerializer;
import net.minecraft.predicate.entity.LootContextPredicate;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.util.Identifier;

public class BabySmeltedCriterion extends AbstractCriterion<BabySmeltedCriterion.Conditions> {
private static final Identifier ID = MCA.locate("baby_smelted");

@Override
public Identifier getId() {
return ID;
}
import java.util.Optional;

public class BabySmeltedCriterion extends AbstractCriterion<BabySmeltedCriterion.Conditions> {
@Override
public Conditions conditionsFromJson(JsonObject json, LootContextPredicate player, AdvancementEntityPredicateDeserializer deserializer) {
public Conditions conditionsFromJson(JsonObject json, Optional<LootContextPredicate> player, AdvancementEntityPredicateDeserializer deserializer) {
NumberRange.IntRange c = NumberRange.IntRange.atLeast(json.get("count").getAsInt());
return new Conditions(player, c);
}

public void trigger(ServerPlayerEntity player, int c) {
trigger(player, (conditions) -> conditions.test(c));
trigger(player, conditions -> conditions.test(c));
}

public static class Conditions extends AbstractCriterionConditions {
private final NumberRange.IntRange count;

public Conditions(LootContextPredicate player, NumberRange.IntRange count) {
super(BabySmeltedCriterion.ID, player);
public Conditions(Optional<LootContextPredicate> player, NumberRange.IntRange count) {
super(player);
this.count = count;
}

Expand All @@ -42,8 +34,8 @@ public boolean test(int c) {
}

@Override
public JsonObject toJson(AdvancementEntityPredicateSerializer serializer) {
JsonObject json = super.toJson(serializer);
public JsonObject toJson() {
JsonObject json = super.toJson();
json.add("count", count.toJson());
return json;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,38 +2,30 @@

import com.google.gson.JsonObject;
import com.google.gson.JsonPrimitive;
import net.mca.MCA;
import net.minecraft.advancement.criterion.AbstractCriterion;
import net.minecraft.advancement.criterion.AbstractCriterionConditions;
import net.minecraft.predicate.entity.AdvancementEntityPredicateDeserializer;
import net.minecraft.predicate.entity.AdvancementEntityPredicateSerializer;
import net.minecraft.predicate.entity.LootContextPredicate;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.util.Identifier;

public class ChildAgeStateChangeCriterion extends AbstractCriterion<ChildAgeStateChangeCriterion.Conditions> {
private static final Identifier ID = MCA.locate("child_age_state_change");

@Override
public Identifier getId() {
return ID;
}
import java.util.Optional;

public class ChildAgeStateChangeCriterion extends AbstractCriterion<ChildAgeStateChangeCriterion.Conditions> {
@Override
public Conditions conditionsFromJson(JsonObject json, LootContextPredicate player, AdvancementEntityPredicateDeserializer deserializer) {
public Conditions conditionsFromJson(JsonObject json, Optional<LootContextPredicate> player, AdvancementEntityPredicateDeserializer deserializer) {
String event = json.has("state") ? json.get("state").getAsString() : "";
return new Conditions(player, event);
}

public void trigger(ServerPlayerEntity player, String event) {
trigger(player, (conditions) -> conditions.test(event));
trigger(player, conditions -> conditions.test(event));
}

public static class Conditions extends AbstractCriterionConditions {
private final String event;

public Conditions(LootContextPredicate player, String event) {
super(ChildAgeStateChangeCriterion.ID, player);
public Conditions(Optional<LootContextPredicate> player, String event) {
super(player);
this.event = event;
}

Expand All @@ -42,8 +34,8 @@ public boolean test(String event) {
}

@Override
public JsonObject toJson(AdvancementEntityPredicateSerializer serializer) {
JsonObject json = super.toJson(serializer);
public JsonObject toJson() {
JsonObject json = super.toJson();
json.add("state", new JsonPrimitive(event));
return json;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,23 +1,24 @@
package net.mca.advancement.criterion;

import net.mca.mixin.MixinCriteria;
import net.minecraft.advancement.criterion.Criteria;
import net.minecraft.advancement.criterion.Criterion;

public interface CriterionMCA {
BabyCriterion BABY_CRITERION = register(new BabyCriterion());
BabyDroppedCriterion BABY_DROPPED_CRITERION = register(new BabyDroppedCriterion());
BabySmeltedCriterion BABY_SMELTED_CRITERION = register(new BabySmeltedCriterion());
BabySirbenSmeltedCriterion BABY_SIRBEN_SMELTED_CRITERION = register(new BabySirbenSmeltedCriterion());
HeartsCriterion HEARTS_CRITERION = register(new HeartsCriterion());
GenericEventCriterion GENERIC_EVENT_CRITERION = register(new GenericEventCriterion());
ChildAgeStateChangeCriterion CHILD_AGE_STATE_CHANGE = register(new ChildAgeStateChangeCriterion());
FamilyCriterion FAMILY = register(new FamilyCriterion());
RankCriterion RANK = register(new RankCriterion());
VillagerFateCriterion FATE = register(new VillagerFateCriterion());
BabyCriterion BABY = register("baby", new BabyCriterion());
BabyDroppedCriterion BABY_DROPPED = register("baby_dropped", new BabyDroppedCriterion());
BabySmeltedCriterion BABY_SMELTED = register("baby_smelted", new BabySmeltedCriterion());
BabySirbenSmeltedCriterion BABY_SIRBEN_SMELTED = register("baby_sirben_smelted", new BabySirbenSmeltedCriterion());
HeartsCriterion HEARTS = register("hearts", new HeartsCriterion());
GenericEventCriterion GENERIC_EVENT = register("generic_event", new GenericEventCriterion());
ChildAgeStateChangeCriterion CHILD_AGE_STATE_CHANGE = register("child_age_state_change", new ChildAgeStateChangeCriterion());
FamilyCriterion FAMILY = register("family", new FamilyCriterion());
RankCriterion RANK = register("rank", new RankCriterion());
VillagerFateCriterion VILLAGER_FATE = register("villager_fate", new VillagerFateCriterion());

static <T extends Criterion<?>> T register(T obj) {
return MixinCriteria.register(obj);
static <T extends Criterion<?>> T register(String id, T obj) {
return Criteria.register("mca:" + id, obj);
}

static void bootstrap() { }
static void bootstrap() {
}
}
Original file line number Diff line number Diff line change
@@ -1,28 +1,20 @@
package net.mca.advancement.criterion;

import com.google.gson.JsonObject;
import net.mca.MCA;
import net.mca.server.world.data.FamilyTree;
import net.mca.server.world.data.FamilyTreeNode;
import net.minecraft.advancement.criterion.AbstractCriterion;
import net.minecraft.advancement.criterion.AbstractCriterionConditions;
import net.minecraft.predicate.NumberRange;
import net.minecraft.predicate.entity.AdvancementEntityPredicateDeserializer;
import net.minecraft.predicate.entity.AdvancementEntityPredicateSerializer;
import net.minecraft.predicate.entity.LootContextPredicate;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.util.Identifier;

public class FamilyCriterion extends AbstractCriterion<FamilyCriterion.Conditions> {
private static final Identifier ID = MCA.locate("family");

@Override
public Identifier getId() {
return ID;
}
import java.util.Optional;

public class FamilyCriterion extends AbstractCriterion<FamilyCriterion.Conditions> {
@Override
public Conditions conditionsFromJson(JsonObject json, LootContextPredicate player, AdvancementEntityPredicateDeserializer deserializer) {
public Conditions conditionsFromJson(JsonObject json, Optional<LootContextPredicate> player, AdvancementEntityPredicateDeserializer deserializer) {
// quite limited, but I do not assume any more use cases
NumberRange.IntRange c = NumberRange.IntRange.fromJson(json.get("children"));
NumberRange.IntRange gc = NumberRange.IntRange.fromJson(json.get("grandchildren"));
Expand All @@ -41,8 +33,8 @@ public static class Conditions extends AbstractCriterionConditions {
private final NumberRange.IntRange children;
private final NumberRange.IntRange grandchildren;

public Conditions(LootContextPredicate player, NumberRange.IntRange children, NumberRange.IntRange grandchildren) {
super(FamilyCriterion.ID, player);
public Conditions(Optional<LootContextPredicate> player, NumberRange.IntRange children, NumberRange.IntRange grandchildren) {
super(player);
this.children = children;
this.grandchildren = grandchildren;
}
Expand All @@ -52,8 +44,8 @@ public boolean test(int c, int gc) {
}

@Override
public JsonObject toJson(AdvancementEntityPredicateSerializer serializer) {
JsonObject json = super.toJson(serializer);
public JsonObject toJson() {
JsonObject json = super.toJson();
json.add("children", children.toJson());
json.add("grandchildren", grandchildren.toJson());
return json;
Expand Down
Loading

0 comments on commit bb4177b

Please sign in to comment.