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 51ae96434..4f16caa6e 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.World; +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(World 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 ae6f4d83d..fa2ca7a03 100644 --- a/src/main/java/com/simibubi/create/foundation/advancement/StringSerializableTrigger.java +++ b/src/main/java/com/simibubi/create/foundation/advancement/StringSerializableTrigger.java @@ -10,7 +10,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; @@ -18,7 +17,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); } @@ -32,32 +36,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 deserializeInstance(JsonObject json, JsonDeserializationContext 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 { @@ -84,7 +86,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; } @@ -96,7 +98,7 @@ public abstract class StringSerializableTrigger extends CriterionTriggerBase< elements.add(key); } - jsonobject.add("accepted_entries", elements); + jsonobject.add(trigger.getJsonKey(), elements); return jsonobject; } }