diff --git a/src/main/java/com/simibubi/create/foundation/advancement/AllTriggers.java b/src/main/java/com/simibubi/create/foundation/advancement/AllTriggers.java index dc245702f..a0dadaf81 100644 --- a/src/main/java/com/simibubi/create/foundation/advancement/AllTriggers.java +++ b/src/main/java/com/simibubi/create/foundation/advancement/AllTriggers.java @@ -13,16 +13,17 @@ import net.minecraft.fluid.Fluid; import net.minecraft.util.math.AxisAlignedBB; import net.minecraft.util.math.BlockPos; import net.minecraft.world.IWorld; +import net.minecraftforge.registries.ForgeRegistries; public class AllTriggers { private static final List> triggers = new LinkedList<>(); - public static RegistryTrigger INFINITE_FLUID = add(new RegistryTrigger<>("infinite_fluid", Fluid.class)); - public static RegistryTrigger BRACKET_APPLY_TRIGGER = add(new RegistryTrigger<>("bracket_apply", Block.class)); - public static EnumTrigger FAN_PROCESSING = add(new EnumTrigger<>("fan_processing", InWorldProcessing.Type.class)); + public static final RegistryTrigger INFINITE_FLUID = add(new RegistryTrigger<>("infinite_fluid", ForgeRegistries.FLUIDS)); + public static final RegistryTrigger BRACKET_APPLY_TRIGGER = add(new RegistryTrigger<>("bracket_apply", ForgeRegistries.BLOCKS)); + public static final EnumTrigger FAN_PROCESSING = add(new EnumTrigger<>("fan_processing", InWorldProcessing.Type.class)); - public static SimpleTrigger + public static final SimpleTrigger ROTATION = simple("rotation"), OVERSTRESSED = simple("overstressed"), SHIFTING_GEARS = simple("shifting_gears"), @@ -99,9 +100,6 @@ public class AllTriggers { } public static List getPlayersInRange(IWorld world, BlockPos pos, int range) { - List players = - world.getEntitiesWithinAABB(ServerPlayerEntity.class, new AxisAlignedBB(pos).grow(range)); - return players; + return world.getEntitiesWithinAABB(ServerPlayerEntity.class, new AxisAlignedBB(pos).grow(range)); } - } diff --git a/src/main/java/com/simibubi/create/foundation/advancement/RegistryTrigger.java b/src/main/java/com/simibubi/create/foundation/advancement/RegistryTrigger.java index 0a70e87b0..9a57c528e 100644 --- a/src/main/java/com/simibubi/create/foundation/advancement/RegistryTrigger.java +++ b/src/main/java/com/simibubi/create/foundation/advancement/RegistryTrigger.java @@ -4,7 +4,6 @@ import mcp.MethodsReturnNonnullByDefault; import net.minecraft.util.ResourceLocation; import net.minecraftforge.registries.IForgeRegistry; import net.minecraftforge.registries.IForgeRegistryEntry; -import net.minecraftforge.registries.RegistryManager; import javax.annotation.Nullable; import javax.annotation.ParametersAreNonnullByDefault; @@ -14,15 +13,14 @@ import javax.annotation.ParametersAreNonnullByDefault; public class RegistryTrigger> extends StringSerializableTrigger { private final IForgeRegistry registry; - public RegistryTrigger(String id, Class registryType) { + public RegistryTrigger(String id, IForgeRegistry registry) { super(id); - this.registry = RegistryManager.ACTIVE.getRegistry(registryType); + this.registry = registry; } @Nullable @Override protected T getValue(String key) { - return registry.getValue(new ResourceLocation(key)); } diff --git a/src/main/java/com/simibubi/create/foundation/advancement/StringSerializableTrigger.java b/src/main/java/com/simibubi/create/foundation/advancement/StringSerializableTrigger.java index c92b75b8a..a52a83d6b 100644 --- a/src/main/java/com/simibubi/create/foundation/advancement/StringSerializableTrigger.java +++ b/src/main/java/com/simibubi/create/foundation/advancement/StringSerializableTrigger.java @@ -16,7 +16,6 @@ import javax.annotation.ParametersAreNonnullByDefault; import java.util.Collections; import java.util.List; import java.util.Set; -import java.util.function.BiConsumer; import java.util.function.Supplier; import java.util.stream.Collectors; import java.util.stream.StreamSupport; @@ -24,7 +23,12 @@ import java.util.stream.StreamSupport; @MethodsReturnNonnullByDefault @ParametersAreNonnullByDefault public abstract class StringSerializableTrigger extends CriterionTriggerBase> { - public StringSerializableTrigger(String id) { + + protected String getJsonKey() { + return "accepted_entries"; + } + + protected StringSerializableTrigger(String id) { super(id); } @@ -38,32 +42,30 @@ public abstract class StringSerializableTrigger extends CriterionTriggerBase< } public ITriggerable constructTriggerFor(@Nullable T entry) { - BiConsumer trigger = this::trigger; - return player -> trigger.accept(player, entry); + return player -> trigger(player, entry); } @Override public Instance conditionsFromJson(JsonObject json, ConditionArrayParser context) { - if (json.has("accepted_entries")) { - JsonArray elements = json.getAsJsonArray("accepted_entries"); + if (json.has(getJsonKey())) { + JsonArray elements = json.getAsJsonArray(getJsonKey()); return new Instance<>(this, StreamSupport.stream(elements.spliterator(), false).map(JsonElement::getAsString) - .map(rl -> { - T entry = getValue(rl); + .map(key -> { + T entry = getValue(key); if (entry == null) - throw new JsonSyntaxException("Unknown entry '" + rl + "'"); + throw new JsonSyntaxException("Unknown entry '" + key + "'"); return entry; }).collect(Collectors.toSet())); } - - return forEntries((T) null); + return new Instance<>(this, null); } @Nullable - abstract protected T getValue(String key); + protected abstract T getValue(String key); @Nullable - abstract protected String getKey(T value); + protected abstract String getKey(T value); public static class Instance extends CriterionTriggerBase.Instance { @@ -90,7 +92,7 @@ public abstract class StringSerializableTrigger extends CriterionTriggerBase< JsonArray elements = new JsonArray(); if (entries == null) { - jsonobject.add("accepted_entries", elements); + jsonobject.add(trigger.getJsonKey(), elements); return jsonobject; } @@ -102,7 +104,7 @@ public abstract class StringSerializableTrigger extends CriterionTriggerBase< elements.add(key); } - jsonobject.add("accepted_entries", elements); + jsonobject.add(trigger.getJsonKey(), elements); return jsonobject; } }