diff --git a/src/generated/resources/.cache/cache b/src/generated/resources/.cache/cache index 3a4af4390..74d15e740 100644 --- a/src/generated/resources/.cache/cache +++ b/src/generated/resources/.cache/cache @@ -337,7 +337,7 @@ e8b0a401c10d1ba67ed71ba31bd5f9bc28571b65 assets/create/blockstates/powered_toggl d06cd9a1101b18d306a786320aab12018b1325d6 assets/create/blockstates/purple_sail.json 92957119abd5fbcca36a113b2a80255fd70fc303 assets/create/blockstates/purple_seat.json 61035f8afe75ff7bbd291da5d8690bcbebe679eb assets/create/blockstates/purple_valve_handle.json -8d7e653bfd9846e684a0d3725595714a19201017 assets/create/blockstates/radial_chassis.json +5d1b30c2bab556f57c78e7780fd445b08f541a50 assets/create/blockstates/radial_chassis.json 45877c4d90a7185c2f304edbd67379d800920439 assets/create/blockstates/red_sail.json da1b08387af7afa0855ee8d040f620c01f20660a assets/create/blockstates/red_seat.json 722fc77bbf387af8a4016e42cbf9501d2b968881 assets/create/blockstates/red_valve_handle.json @@ -1625,9 +1625,9 @@ acef16596b7ae82aaf853142d69bcea7094b8173 data/create/advancements/fan_smoke.json 489c58a0508a2a41cc0849dfb933eb5ac96ef364 data/create/advancements/glass_pipe.json 62f3610188f7dbd3900ab305edc2d06282705a38 data/create/advancements/goggles.json 10c8686da9cec2ae30c10f434836ac15a1b88666 data/create/advancements/hose_pulley.json -783149a4aaba84d2fb93e036f6f642540c1d7f78 data/create/advancements/infinite_chocolate.json -4e626cc34af70e2be6bd2e209b745515293784af data/create/advancements/infinite_lava.json -07a74e519f5244c4ce5d6c8549f6c8a668238953 data/create/advancements/infinite_water.json +a8595e5fdf6517e5c9c790afccc99fe9d3dd95aa data/create/advancements/infinite_chocolate.json +50460d4470e9630b2d3ae1ec4f24d00d8d7c7e6b data/create/advancements/infinite_lava.json +19d9794ac08cee962c7c718085d3e3ba5e89a328 data/create/advancements/infinite_water.json 9beb622c79e9f5ce2397c22222cac0faf272f388 data/create/advancements/integrated_circuit.json 316bed3d8985d0a371200967d7edd2936f1b9f94 data/create/advancements/integrated_circuit_eob.json a80eea863bfdc7777b8bade39a81655b2f99e02f data/create/advancements/item_drain.json @@ -1638,7 +1638,7 @@ a80eea863bfdc7777b8bade39a81655b2f99e02f data/create/advancements/item_drain.jso 218568a4e416c5fa559c55a5c92aa4e93f88b837 data/create/advancements/mechanical_drill.json 6dc84ad2f0512495fe3f01f99d3c547849351e33 data/create/advancements/mechanical_saw.json 3bc549c06dc6d9568f92e1abc9654c9b4c33f035 data/create/advancements/millstone.json -704c7fc0ed357b1a116ffdc0b6c64fe64e337a5a data/create/advancements/mixer.json +6f872e1e8be9d8e5fa378db1384b1de72fadac23 data/create/advancements/mixer.json 325d4cef263ce301b143ee0498fb15afdb2c125b data/create/advancements/musical_arm.json c9c4060ed207226b69fada2d61e01a97d7077eae data/create/advancements/nixie_tube.json 9329cb210a954c0de1dcf517e7dff1ece77c19c0 data/create/advancements/overstress_flywheel.json diff --git a/src/generated/resources/assets/create/blockstates/radial_chassis.json b/src/generated/resources/assets/create/blockstates/radial_chassis.json index 9d00ea8b1..04e5c08ae 100644 --- a/src/generated/resources/assets/create/blockstates/radial_chassis.json +++ b/src/generated/resources/assets/create/blockstates/radial_chassis.json @@ -29,8 +29,8 @@ }, { "when": { - "sticky_south": "true", - "axis": "x" + "axis": "x", + "sticky_south": "true" }, "apply": { "model": "create:block/radial_chassis_side_x_sticky", @@ -39,8 +39,8 @@ }, { "when": { - "sticky_south": "true", - "axis": "y" + "axis": "y", + "sticky_south": "true" }, "apply": { "model": "create:block/radial_chassis_side_y_sticky" @@ -48,8 +48,8 @@ }, { "when": { - "sticky_south": "true", - "axis": "z" + "axis": "z", + "sticky_south": "true" }, "apply": { "model": "create:block/radial_chassis_side_x_sticky", @@ -59,8 +59,8 @@ }, { "when": { - "sticky_south": "false", - "axis": "x" + "axis": "x", + "sticky_south": "false" }, "apply": { "model": "create:block/radial_chassis_side_x", @@ -69,8 +69,8 @@ }, { "when": { - "sticky_south": "false", - "axis": "y" + "axis": "y", + "sticky_south": "false" }, "apply": { "model": "create:block/radial_chassis_side_y" @@ -78,8 +78,8 @@ }, { "when": { - "sticky_south": "false", - "axis": "z" + "axis": "z", + "sticky_south": "false" }, "apply": { "model": "create:block/radial_chassis_side_x", @@ -89,8 +89,8 @@ }, { "when": { - "sticky_west": "true", - "axis": "x" + "axis": "x", + "sticky_west": "true" }, "apply": { "model": "create:block/radial_chassis_side_x_sticky", @@ -99,8 +99,8 @@ }, { "when": { - "sticky_west": "true", - "axis": "y" + "axis": "y", + "sticky_west": "true" }, "apply": { "model": "create:block/radial_chassis_side_y_sticky", @@ -109,8 +109,8 @@ }, { "when": { - "sticky_west": "true", - "axis": "z" + "axis": "z", + "sticky_west": "true" }, "apply": { "model": "create:block/radial_chassis_side_z_sticky", @@ -119,8 +119,8 @@ }, { "when": { - "sticky_west": "false", - "axis": "x" + "axis": "x", + "sticky_west": "false" }, "apply": { "model": "create:block/radial_chassis_side_x", @@ -129,8 +129,8 @@ }, { "when": { - "sticky_west": "false", - "axis": "y" + "axis": "y", + "sticky_west": "false" }, "apply": { "model": "create:block/radial_chassis_side_y", @@ -139,8 +139,8 @@ }, { "when": { - "sticky_west": "false", - "axis": "z" + "axis": "z", + "sticky_west": "false" }, "apply": { "model": "create:block/radial_chassis_side_z", @@ -149,8 +149,8 @@ }, { "when": { - "sticky_north": "true", - "axis": "x" + "axis": "x", + "sticky_north": "true" }, "apply": { "model": "create:block/radial_chassis_side_x_sticky" @@ -158,8 +158,8 @@ }, { "when": { - "sticky_north": "true", - "axis": "y" + "axis": "y", + "sticky_north": "true" }, "apply": { "model": "create:block/radial_chassis_side_y_sticky", @@ -168,8 +168,8 @@ }, { "when": { - "sticky_north": "true", - "axis": "z" + "axis": "z", + "sticky_north": "true" }, "apply": { "model": "create:block/radial_chassis_side_x_sticky", @@ -178,8 +178,8 @@ }, { "when": { - "sticky_north": "false", - "axis": "x" + "axis": "x", + "sticky_north": "false" }, "apply": { "model": "create:block/radial_chassis_side_x" @@ -187,8 +187,8 @@ }, { "when": { - "sticky_north": "false", - "axis": "y" + "axis": "y", + "sticky_north": "false" }, "apply": { "model": "create:block/radial_chassis_side_y", @@ -197,8 +197,8 @@ }, { "when": { - "sticky_north": "false", - "axis": "z" + "axis": "z", + "sticky_north": "false" }, "apply": { "model": "create:block/radial_chassis_side_x", diff --git a/src/generated/resources/data/create/advancements/infinite_chocolate.json b/src/generated/resources/data/create/advancements/infinite_chocolate.json index d119ec219..d192ca113 100644 --- a/src/generated/resources/data/create/advancements/infinite_chocolate.json +++ b/src/generated/resources/data/create/advancements/infinite_chocolate.json @@ -19,7 +19,7 @@ "0": { "trigger": "create:infinite_fluid", "conditions": { - "fluid": "create:chocolate" + "registry_entry": "create:chocolate" } } }, diff --git a/src/generated/resources/data/create/advancements/infinite_lava.json b/src/generated/resources/data/create/advancements/infinite_lava.json index 95db7901d..40b98a1fd 100644 --- a/src/generated/resources/data/create/advancements/infinite_lava.json +++ b/src/generated/resources/data/create/advancements/infinite_lava.json @@ -19,7 +19,7 @@ "0": { "trigger": "create:infinite_fluid", "conditions": { - "fluid": "minecraft:lava" + "registry_entry": "minecraft:lava" } } }, diff --git a/src/generated/resources/data/create/advancements/infinite_water.json b/src/generated/resources/data/create/advancements/infinite_water.json index 5af5a31fa..0f4771011 100644 --- a/src/generated/resources/data/create/advancements/infinite_water.json +++ b/src/generated/resources/data/create/advancements/infinite_water.json @@ -19,7 +19,7 @@ "0": { "trigger": "create:infinite_fluid", "conditions": { - "fluid": "minecraft:water" + "registry_entry": "minecraft:water" } } }, diff --git a/src/generated/resources/data/create/advancements/mixer.json b/src/generated/resources/data/create/advancements/mixer.json index 5988c6b10..ab35b7f7d 100644 --- a/src/generated/resources/data/create/advancements/mixer.json +++ b/src/generated/resources/data/create/advancements/mixer.json @@ -25,7 +25,7 @@ "1": { "trigger": "create:kinetic_block", "conditions": { - "block": "create:mechanical_mixer" + "registry_entry": "create:mechanical_mixer" } }, "2": { diff --git a/src/main/java/com/simibubi/create/content/contraptions/base/KineticTileEntity.java b/src/main/java/com/simibubi/create/content/contraptions/base/KineticTileEntity.java index f99113046..cf1815817 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/base/KineticTileEntity.java +++ b/src/main/java/com/simibubi/create/content/contraptions/base/KineticTileEntity.java @@ -176,7 +176,7 @@ public abstract class KineticTileEntity extends SmartTileEntity if (fromOrToZero && previousSpeed == 0 && !world.isRemote) AllTriggers.getPlayersInRange(world, pos, 4) - .forEach(p -> AllTriggers.KINETIC_BLOCK.trigger(p, getBlockState())); + .forEach(p -> AllTriggers.KINETIC_BLOCK.trigger(p, getBlockState().getBlock())); } @Override diff --git a/src/main/java/com/simibubi/create/foundation/advancement/AllAdvancements.java b/src/main/java/com/simibubi/create/foundation/advancement/AllAdvancements.java index dbcc383a0..e73c1cfc8 100644 --- a/src/main/java/com/simibubi/create/foundation/advancement/AllAdvancements.java +++ b/src/main/java/com/simibubi/create/foundation/advancement/AllAdvancements.java @@ -6,6 +6,7 @@ import java.util.Set; import java.util.function.Consumer; import java.util.function.Supplier; +import net.minecraft.fluid.FlowingFluid; import net.minecraft.fluid.Fluid; import net.minecraft.fluid.Fluids; import org.apache.logging.log4j.LogManager; @@ -295,20 +296,17 @@ public class AllAdvancements implements IDataProvider { Advancement infinite_water = advancement("infinite_water", Items.WATER_BUCKET, TaskType.NORMAL).withParent(hose_pulley) - // .withCriterion("0", AllTriggers.INFINITE_WATER.instance()) - .withCriterion("0", isInfinite(Fluids.WATER.getFluid())) + .withCriterion("0", isInfinite(Fluids.WATER)) .register(t, id + ":infinite_water"); Advancement infinite_lava = advancement("infinite_lava", Items.LAVA_BUCKET, TaskType.GOAL).withParent(hose_pulley) - // .withCriterion("0", AllTriggers.INFINITE_LAVA.instance()) - .withCriterion("0", isInfinite(Fluids.LAVA.getFluid())) + .withCriterion("0", isInfinite(Fluids.LAVA)) .register(t, id + ":infinite_lava"); Advancement infinite_chocolate = advancement("infinite_chocolate", AllFluids.CHOCOLATE.get() .getFilledBucket(), TaskType.CHALLENGE).withParent(hose_pulley) - // .withCriterion("0", AllTriggers.INFINITE_CHOCOLATE.instance()) - .withCriterion("0", isInfinite(AllFluids.CHOCOLATE.get().getFluid())) + .withCriterion("0", isInfinite(AllFluids.CHOCOLATE.get())) .register(t, id + ":infinite_chocolate"); } @@ -498,12 +496,12 @@ public class AllAdvancements implements IDataProvider { return PlacedBlockTrigger.Instance.placedBlock(block); } - public KineticBlockTrigger.Instance isPowered(Block block) { - return AllTriggers.KINETIC_BLOCK.forBlock(block); + public RegistryTrigger.Instance isPowered(Block block) { + return AllTriggers.KINETIC_BLOCK.forEntry(block); } - public CriterionTriggerBase.Instance isInfinite(Fluid fluid) { - return AllTriggers.INFINITE_FLUID.forFluid(fluid); + public RegistryTrigger.Instance isInfinite(FlowingFluid fluid) { + return AllTriggers.INFINITE_FLUID.forEntry(fluid.getStillFluid()); } public InventoryChangeTrigger.Instance itemGathered(IItemProvider itemprovider) { 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 9189414fe..67b5f2332 100644 --- a/src/main/java/com/simibubi/create/foundation/advancement/AllTriggers.java +++ b/src/main/java/com/simibubi/create/foundation/advancement/AllTriggers.java @@ -5,18 +5,20 @@ import java.util.List; import java.util.function.Predicate; import net.minecraft.advancements.CriteriaTriggers; +import net.minecraft.block.Block; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.entity.player.ServerPlayerEntity; +import net.minecraft.fluid.Fluid; import net.minecraft.util.math.AxisAlignedBB; import net.minecraft.util.math.BlockPos; import net.minecraft.world.World; public class AllTriggers { - private static List> triggers = new LinkedList<>(); + private static final List> triggers = new LinkedList<>(); - public static KineticBlockTrigger KINETIC_BLOCK = add(new KineticBlockTrigger("kinetic_block")); - public static InfiniteFluidTrigger INFINITE_FLUID = add(new InfiniteFluidTrigger("infinite_fluid")); + public static RegistryTrigger KINETIC_BLOCK = add(new RegistryTrigger<>("kinetic_block", Block.class)); + public static RegistryTrigger INFINITE_FLUID = add(new RegistryTrigger<>("infinite_fluid", Fluid.class)); public static SimpleTrigger ROTATION = simple("rotation"), @@ -68,9 +70,6 @@ public class AllTriggers { PIPE_COLLISION = simple("pipe_collision"), PIPE_SPILL = simple("pipe_spill"), HOSE_PULLEY = simple("hose_pulley"), - INFINITE_WATER = simple("infinite_water"), - INFINITE_LAVA = simple("infinite_lava"), - INFINITE_CHOCOLATE = simple("infinite_chocolate"), MIXER_MIX = simple("mixer"); private static SimpleTrigger simple(String id) { diff --git a/src/main/java/com/simibubi/create/foundation/advancement/CriterionTriggerBase.java b/src/main/java/com/simibubi/create/foundation/advancement/CriterionTriggerBase.java index 61fc561f6..14006415b 100644 --- a/src/main/java/com/simibubi/create/foundation/advancement/CriterionTriggerBase.java +++ b/src/main/java/com/simibubi/create/foundation/advancement/CriterionTriggerBase.java @@ -10,19 +10,25 @@ import java.util.function.Supplier; import com.google.common.collect.Maps; import com.simibubi.create.Create; +import mcp.MethodsReturnNonnullByDefault; import net.minecraft.advancements.ICriterionTrigger; import net.minecraft.advancements.PlayerAdvancements; import net.minecraft.advancements.criterion.CriterionInstance; import net.minecraft.entity.player.ServerPlayerEntity; import net.minecraft.util.ResourceLocation; +import javax.annotation.Nullable; +import javax.annotation.ParametersAreNonnullByDefault; + +@ParametersAreNonnullByDefault +@MethodsReturnNonnullByDefault public abstract class CriterionTriggerBase implements ICriterionTrigger { public CriterionTriggerBase(String id) { this.ID = new ResourceLocation(Create.ID, id); } - private ResourceLocation ID; + private final ResourceLocation ID; protected final Map>> listeners = Maps.newHashMap(); @Override @@ -53,7 +59,7 @@ public abstract class CriterionTriggerBase> suppliers){ + protected void trigger(ServerPlayerEntity player, @Nullable List> suppliers){ PlayerAdvancements playerAdvancements = player.getAdvancements(); Set> playerListeners = this.listeners.get(playerAdvancements); if (playerListeners != null){ @@ -77,7 +83,7 @@ public abstract class CriterionTriggerBase> suppliers); + protected abstract boolean test(@Nullable List> suppliers); } diff --git a/src/main/java/com/simibubi/create/foundation/advancement/InfiniteFluidTrigger.java b/src/main/java/com/simibubi/create/foundation/advancement/InfiniteFluidTrigger.java deleted file mode 100644 index 4f295a424..000000000 --- a/src/main/java/com/simibubi/create/foundation/advancement/InfiniteFluidTrigger.java +++ /dev/null @@ -1,80 +0,0 @@ -package com.simibubi.create.foundation.advancement; - -import com.google.gson.JsonDeserializationContext; -import com.google.gson.JsonElement; -import com.google.gson.JsonObject; -import com.google.gson.JsonSyntaxException; -import com.simibubi.create.Create; -import com.simibubi.create.foundation.fluid.FluidHelper; -import mcp.MethodsReturnNonnullByDefault; -import net.minecraft.entity.player.ServerPlayerEntity; -import net.minecraft.fluid.Fluid; -import net.minecraft.util.JSONUtils; -import net.minecraft.util.ResourceLocation; -import net.minecraftforge.registries.ForgeRegistries; - -import javax.annotation.Nullable; -import javax.annotation.ParametersAreNonnullByDefault; -import java.util.Collections; -import java.util.List; -import java.util.function.Supplier; - -@MethodsReturnNonnullByDefault -@ParametersAreNonnullByDefault -public class InfiniteFluidTrigger extends CriterionTriggerBase { - private static final ResourceLocation ID = new ResourceLocation(Create.ID, "infinite_fluid"); - - public InfiniteFluidTrigger(String id) { - super(id); - } - - public Instance forFluid(Fluid fluid) { - return new Instance(fluid); - } - - @Override - public Instance deserializeInstance(JsonObject json, JsonDeserializationContext context) { - Fluid fluid = null; - if (json.has("fluid")) { - ResourceLocation resourcelocation = new ResourceLocation(JSONUtils.getString(json, "fluid")); - fluid = ForgeRegistries.FLUIDS.getValue(resourcelocation); - - if (fluid == null) - throw new JsonSyntaxException("Unknown fluid type '" + resourcelocation + "'"); - } - - return new Instance(fluid); - } - - public void trigger(ServerPlayerEntity player, Fluid fluid) { - trigger(player, Collections.singletonList(() -> fluid)); - } - - - public static class Instance extends CriterionTriggerBase.Instance { - - private final Fluid fluid; - - public Instance(@Nullable Fluid fluid) { - super(InfiniteFluidTrigger.ID); - this.fluid = FluidHelper.convertToStill(fluid); - } - - @Override - protected boolean test(List> suppliers) { - if (fluid == null || suppliers.isEmpty()) - return false; - return fluid.equals(suppliers.get(0).get()); - } - - @Override - public JsonElement serialize() { - JsonObject jsonobject = new JsonObject(); - ResourceLocation key = ForgeRegistries.FLUIDS.getKey(this.fluid); - if (key != null) - jsonobject.addProperty("fluid", key.toString()); - return jsonobject; - } - } - -} diff --git a/src/main/java/com/simibubi/create/foundation/advancement/KineticBlockTrigger.java b/src/main/java/com/simibubi/create/foundation/advancement/KineticBlockTrigger.java deleted file mode 100644 index a72bc6f78..000000000 --- a/src/main/java/com/simibubi/create/foundation/advancement/KineticBlockTrigger.java +++ /dev/null @@ -1,76 +0,0 @@ -package com.simibubi.create.foundation.advancement; - -import java.util.Arrays; -import java.util.List; -import java.util.function.Supplier; - -import com.google.gson.JsonDeserializationContext; -import com.google.gson.JsonElement; -import com.google.gson.JsonObject; -import com.google.gson.JsonSyntaxException; -import com.simibubi.create.Create; - -import net.minecraft.block.Block; -import net.minecraft.block.BlockState; -import net.minecraft.entity.player.ServerPlayerEntity; -import net.minecraft.util.JSONUtils; -import net.minecraft.util.ResourceLocation; -import net.minecraft.util.registry.Registry; - -public class KineticBlockTrigger extends CriterionTriggerBase { - - private static final ResourceLocation ID = new ResourceLocation(Create.ID, "kinetic_block"); - - public KineticBlockTrigger(String id) { - super(id); - } - - public Instance forBlock(Block block) { - return new Instance(block); - } - - @Override - @SuppressWarnings("deprecation") - public Instance deserializeInstance(JsonObject json, JsonDeserializationContext context) { - Block block = null; - if (json.has("block")) { - ResourceLocation resourcelocation = new ResourceLocation(JSONUtils.getString(json, "block")); - block = Registry.BLOCK.getValue(resourcelocation).orElseThrow(() -> { - return new JsonSyntaxException("Unknown block type '" + resourcelocation + "'"); - }); - } - - return new Instance(block); - } - - public void trigger(ServerPlayerEntity player, BlockState state) { - trigger(player, Arrays.asList(() -> state.getBlock())); - } - - public static class Instance extends CriterionTriggerBase.Instance { - private final Block block; - - public Instance(Block block) { - super(KineticBlockTrigger.ID); - this.block = block; - } - - @Override - protected boolean test(List> suppliers) { - if (suppliers.isEmpty()) - return false; - return block == suppliers.get(0).get(); - } - - @Override - @SuppressWarnings("deprecation") - public JsonElement serialize() { - JsonObject jsonobject = new JsonObject(); - if (this.block != null) - jsonobject.addProperty("block", Registry.BLOCK.getKey(this.block).toString()); - return jsonobject; - } - } - - -} diff --git a/src/main/java/com/simibubi/create/foundation/advancement/RegistryTrigger.java b/src/main/java/com/simibubi/create/foundation/advancement/RegistryTrigger.java new file mode 100644 index 000000000..3851bdf2d --- /dev/null +++ b/src/main/java/com/simibubi/create/foundation/advancement/RegistryTrigger.java @@ -0,0 +1,83 @@ +package com.simibubi.create.foundation.advancement; + +import com.google.gson.JsonDeserializationContext; +import com.google.gson.JsonElement; +import com.google.gson.JsonObject; +import com.google.gson.JsonSyntaxException; +import mcp.MethodsReturnNonnullByDefault; +import net.minecraft.entity.player.ServerPlayerEntity; +import net.minecraft.util.JSONUtils; +import net.minecraft.util.ResourceLocation; +import net.minecraftforge.registries.IForgeRegistryEntry; +import net.minecraftforge.registries.RegistryManager; + +import javax.annotation.Nullable; +import javax.annotation.ParametersAreNonnullByDefault; +import java.util.Collections; +import java.util.List; +import java.util.function.Supplier; + +@ParametersAreNonnullByDefault +@MethodsReturnNonnullByDefault +public class RegistryTrigger> extends CriterionTriggerBase> { + private final Class registryType; + + public RegistryTrigger(String id, Class registryType) { + super(id); + this.registryType = registryType; + } + + public Instance forEntry(@Nullable T registryEntry) { + return new Instance<>(getId(), registryEntry); + } + + public void trigger(ServerPlayerEntity player, T registryEntry) { + trigger(player, Collections.singletonList(() -> registryEntry)); + } + + @Override + public Instance deserializeInstance(JsonObject json, JsonDeserializationContext context) { + T entry = null; + if (json.has("registry_entry")) { + ResourceLocation entryLocation = new ResourceLocation(JSONUtils.getString(json, "registry_entry")); + entry = RegistryManager.ACTIVE.getRegistry(registryType).getValue(entryLocation); + + if (entry == null) + throw new JsonSyntaxException("Unknown registry entry '" + entryLocation + "'"); + } + + return forEntry(entry); + } + + + public static class Instance> extends CriterionTriggerBase.Instance { + + @Nullable + private final T entry; + + public Instance(ResourceLocation id, @Nullable T registryEntry) { + super(id); + entry = registryEntry; + } + + @Override + protected boolean test(@Nullable List> suppliers) { + if (entry == null || suppliers == null || suppliers.isEmpty()) + return false; + return entry.equals(suppliers.get(0).get()); + } + + @Override + public JsonElement serialize() { + JsonObject jsonobject = new JsonObject(); + if (entry == null) + return jsonobject; + + ResourceLocation key = RegistryManager.ACTIVE.getRegistry(entry.getRegistryType()).getKey(entry); + if (key != null) { + jsonobject.addProperty("registry_entry", key.toString()); + } + return jsonobject; + } + } +} diff --git a/src/main/java/com/simibubi/create/foundation/advancement/SimpleTrigger.java b/src/main/java/com/simibubi/create/foundation/advancement/SimpleTrigger.java index 375bdb3a2..4d78b956e 100644 --- a/src/main/java/com/simibubi/create/foundation/advancement/SimpleTrigger.java +++ b/src/main/java/com/simibubi/create/foundation/advancement/SimpleTrigger.java @@ -6,9 +6,15 @@ import java.util.function.Supplier; import com.google.gson.JsonDeserializationContext; import com.google.gson.JsonObject; +import mcp.MethodsReturnNonnullByDefault; import net.minecraft.entity.player.ServerPlayerEntity; import net.minecraft.util.ResourceLocation; +import javax.annotation.Nullable; +import javax.annotation.ParametersAreNonnullByDefault; + +@MethodsReturnNonnullByDefault +@ParametersAreNonnullByDefault public class SimpleTrigger extends CriterionTriggerBase implements ITriggerable { public SimpleTrigger(String id) { @@ -35,7 +41,7 @@ public class SimpleTrigger extends CriterionTriggerBase } @Override - protected boolean test(List> suppliers) { + protected boolean test(@Nullable List> suppliers) { return true; } }