From 3f9ee09953116232406e72c98d7df7e8c52e0f09 Mon Sep 17 00:00:00 2001 From: grimmauld Date: Fri, 19 Feb 2021 14:12:26 +0100 Subject: [PATCH 1/5] Rework Bracket trigger to now be a registry trigger based on base block --- src/generated/resources/.cache/cache | 12 +-- .../create/blockstates/radial_chassis.json | 24 +++--- .../data/create/advancements/aesthetics.json | 22 +++++- .../advancements/infinite_chocolate.json | 4 +- .../create/advancements/infinite_lava.json | 4 +- .../create/advancements/infinite_water.json | 4 +- .../data/create/advancements/mixer.json | 4 +- .../fluids/pipes/FluidPipeTileEntity.java | 2 +- .../BracketedTileEntityBehaviour.java | 18 ++--- .../elementary/SimpleKineticTileEntity.java | 2 +- .../advancement/AllAdvancements.java | 10 +-- .../foundation/advancement/AllTriggers.java | 4 +- .../advancement/CriterionTriggerBase.java | 2 +- .../advancement/RegistryTrigger.java | 79 ++++++++++++------- 14 files changed, 116 insertions(+), 75 deletions(-) diff --git a/src/generated/resources/.cache/cache b/src/generated/resources/.cache/cache index 74d15e740..b529b1fdb 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 -5d1b30c2bab556f57c78e7780fd445b08f541a50 assets/create/blockstates/radial_chassis.json +4439fc83a8c7370ab44b211a3fd48abde20a4728 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 @@ -1586,7 +1586,7 @@ d080b1b25e5bc8baf5aee68691b08c7f12ece3b0 assets/create/models/item/windmill_bear 9f9455ccb5fc9e3cbfce73862b46078346a522a5 assets/create/models/item/zinc_nugget.json b1689617190c05ef34bd18456b0c7ae09bb3210f assets/create/models/item/zinc_ore.json e76041b7ae829fdd7dc0524f6ca4d2f89fca51bb assets/create/sounds.json -cb9641eaf33211af46daf57241c76733cf371ed2 data/create/advancements/aesthetics.json +0f1b4b980afba9bf2caf583b88e261bba8b10313 data/create/advancements/aesthetics.json 187921fa131b06721bfaf63f2623a28c141aae9a data/create/advancements/andesite_alloy.json 0ea2db7173b5be28b289ea7c9a6a0cf5805c60c7 data/create/advancements/andesite_casing.json 356f4855a2a6c65be3fb51d7d1aabf2ca6034d42 data/create/advancements/arm_blaze_burner.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 -a8595e5fdf6517e5c9c790afccc99fe9d3dd95aa data/create/advancements/infinite_chocolate.json -50460d4470e9630b2d3ae1ec4f24d00d8d7c7e6b data/create/advancements/infinite_lava.json -19d9794ac08cee962c7c718085d3e3ba5e89a328 data/create/advancements/infinite_water.json +9f642faf92b75a28c564e90be8448b9a4328af5e data/create/advancements/infinite_chocolate.json +a933fa5e7217e2ffe123ae035cfbc9210ba69fd5 data/create/advancements/infinite_lava.json +a8ab0e4ffba358d23f9efaa9f51245b6d490a8be 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 -6f872e1e8be9d8e5fa378db1384b1de72fadac23 data/create/advancements/mixer.json +f41d548c21a8540428ea043451e5fbb641fc2e58 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 04e5c08ae..8bd829ffc 100644 --- a/src/generated/resources/assets/create/blockstates/radial_chassis.json +++ b/src/generated/resources/assets/create/blockstates/radial_chassis.json @@ -207,8 +207,8 @@ }, { "when": { - "sticky_east": "true", - "axis": "x" + "axis": "x", + "sticky_east": "true" }, "apply": { "model": "create:block/radial_chassis_side_x_sticky", @@ -217,8 +217,8 @@ }, { "when": { - "sticky_east": "true", - "axis": "y" + "axis": "y", + "sticky_east": "true" }, "apply": { "model": "create:block/radial_chassis_side_y_sticky", @@ -227,8 +227,8 @@ }, { "when": { - "sticky_east": "true", - "axis": "z" + "axis": "z", + "sticky_east": "true" }, "apply": { "model": "create:block/radial_chassis_side_z_sticky" @@ -236,8 +236,8 @@ }, { "when": { - "sticky_east": "false", - "axis": "x" + "axis": "x", + "sticky_east": "false" }, "apply": { "model": "create:block/radial_chassis_side_x", @@ -246,8 +246,8 @@ }, { "when": { - "sticky_east": "false", - "axis": "y" + "axis": "y", + "sticky_east": "false" }, "apply": { "model": "create:block/radial_chassis_side_y", @@ -256,8 +256,8 @@ }, { "when": { - "sticky_east": "false", - "axis": "z" + "axis": "z", + "sticky_east": "false" }, "apply": { "model": "create:block/radial_chassis_side_z" diff --git a/src/generated/resources/data/create/advancements/aesthetics.json b/src/generated/resources/data/create/advancements/aesthetics.json index 722bd2ec7..d723cbe38 100644 --- a/src/generated/resources/data/create/advancements/aesthetics.json +++ b/src/generated/resources/data/create/advancements/aesthetics.json @@ -17,13 +17,29 @@ }, "criteria": { "0": { - "trigger": "create:bracket_shaft" + "trigger": "create:bracket_apply", + "conditions": { + "accepted_entries": [ + "create:shaft" + ] + } }, "1": { - "trigger": "create:bracket_cog" + "trigger": "create:bracket_apply", + "conditions": { + "accepted_entries": [ + "create:cogwheel", + "create:large_cogwheel" + ] + } }, "2": { - "trigger": "create:bracket_pipe" + "trigger": "create:bracket_apply", + "conditions": { + "accepted_entries": [ + "create:fluid_pipe" + ] + } } }, "requirements": [ diff --git a/src/generated/resources/data/create/advancements/infinite_chocolate.json b/src/generated/resources/data/create/advancements/infinite_chocolate.json index d192ca113..5715963c3 100644 --- a/src/generated/resources/data/create/advancements/infinite_chocolate.json +++ b/src/generated/resources/data/create/advancements/infinite_chocolate.json @@ -19,7 +19,9 @@ "0": { "trigger": "create:infinite_fluid", "conditions": { - "registry_entry": "create:chocolate" + "accepted_entries": [ + "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 40b98a1fd..5d634ef94 100644 --- a/src/generated/resources/data/create/advancements/infinite_lava.json +++ b/src/generated/resources/data/create/advancements/infinite_lava.json @@ -19,7 +19,9 @@ "0": { "trigger": "create:infinite_fluid", "conditions": { - "registry_entry": "minecraft:lava" + "accepted_entries": [ + "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 0f4771011..27b8c7a64 100644 --- a/src/generated/resources/data/create/advancements/infinite_water.json +++ b/src/generated/resources/data/create/advancements/infinite_water.json @@ -19,7 +19,9 @@ "0": { "trigger": "create:infinite_fluid", "conditions": { - "registry_entry": "minecraft:water" + "accepted_entries": [ + "minecraft:water" + ] } } }, diff --git a/src/generated/resources/data/create/advancements/mixer.json b/src/generated/resources/data/create/advancements/mixer.json index ab35b7f7d..145bea240 100644 --- a/src/generated/resources/data/create/advancements/mixer.json +++ b/src/generated/resources/data/create/advancements/mixer.json @@ -25,7 +25,9 @@ "1": { "trigger": "create:kinetic_block", "conditions": { - "registry_entry": "create:mechanical_mixer" + "accepted_entries": [ + "create:mechanical_mixer" + ] } }, "2": { diff --git a/src/main/java/com/simibubi/create/content/contraptions/fluids/pipes/FluidPipeTileEntity.java b/src/main/java/com/simibubi/create/content/contraptions/fluids/pipes/FluidPipeTileEntity.java index 0763e60d9..ede978f67 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/fluids/pipes/FluidPipeTileEntity.java +++ b/src/main/java/com/simibubi/create/content/contraptions/fluids/pipes/FluidPipeTileEntity.java @@ -25,7 +25,7 @@ public class FluidPipeTileEntity extends SmartTileEntity { public void addBehaviours(List behaviours) { behaviours.add(new StandardPipeFluidTransportBehaviour(this)); behaviours.add(new BracketedTileEntityBehaviour(this, this::canHaveBracket) - .withTrigger(state -> AllTriggers.BRACKET_PIPE)); + .withTrigger(state -> AllTriggers.BRACKET_APPLY_TRIGGER.constructTriggerFor(state.getBlock()))); } private boolean canHaveBracket(BlockState state) { diff --git a/src/main/java/com/simibubi/create/content/contraptions/relays/elementary/BracketedTileEntityBehaviour.java b/src/main/java/com/simibubi/create/content/contraptions/relays/elementary/BracketedTileEntityBehaviour.java index ef69047a0..8bc847faf 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/relays/elementary/BracketedTileEntityBehaviour.java +++ b/src/main/java/com/simibubi/create/content/contraptions/relays/elementary/BracketedTileEntityBehaviour.java @@ -1,17 +1,11 @@ package com.simibubi.create.content.contraptions.relays.elementary; -import java.util.Optional; -import java.util.function.Function; -import java.util.function.Predicate; - -import com.google.common.base.Predicates; import com.simibubi.create.foundation.advancement.AllTriggers; -import com.simibubi.create.foundation.advancement.SimpleTrigger; +import com.simibubi.create.foundation.advancement.ITriggerable; import com.simibubi.create.foundation.tileEntity.SmartTileEntity; import com.simibubi.create.foundation.tileEntity.TileEntityBehaviour; import com.simibubi.create.foundation.tileEntity.behaviour.BehaviourType; import com.simibubi.create.foundation.utility.NBTHelper; - import net.minecraft.block.Block; import net.minecraft.block.BlockState; import net.minecraft.block.Blocks; @@ -20,6 +14,10 @@ import net.minecraft.nbt.CompoundNBT; import net.minecraft.nbt.NBTUtil; import net.minecraft.world.World; +import java.util.Optional; +import java.util.function.Function; +import java.util.function.Predicate; + public class BracketedTileEntityBehaviour extends TileEntityBehaviour { public static BehaviourType TYPE = new BehaviourType<>(); @@ -28,10 +26,10 @@ public class BracketedTileEntityBehaviour extends TileEntityBehaviour { private boolean reRender; private Predicate pred; - private Function trigger; + private Function trigger; public BracketedTileEntityBehaviour(SmartTileEntity te) { - this(te, Predicates.alwaysTrue()); + this(te, state -> true); } public BracketedTileEntityBehaviour(SmartTileEntity te, Predicate pred) { @@ -40,7 +38,7 @@ public class BracketedTileEntityBehaviour extends TileEntityBehaviour { bracket = Optional.empty(); } - public BracketedTileEntityBehaviour withTrigger(Function trigger) { + public BracketedTileEntityBehaviour withTrigger(Function trigger) { this.trigger = trigger; return this; } diff --git a/src/main/java/com/simibubi/create/content/contraptions/relays/elementary/SimpleKineticTileEntity.java b/src/main/java/com/simibubi/create/content/contraptions/relays/elementary/SimpleKineticTileEntity.java index df6b20f6f..ddf55f972 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/relays/elementary/SimpleKineticTileEntity.java +++ b/src/main/java/com/simibubi/create/content/contraptions/relays/elementary/SimpleKineticTileEntity.java @@ -23,7 +23,7 @@ public class SimpleKineticTileEntity extends KineticTileEntity { public void addBehaviours(List behaviours) { behaviours.add( new BracketedTileEntityBehaviour(this, state -> state.getBlock() instanceof AbstractShaftBlock).withTrigger( - state -> state.getBlock() instanceof ShaftBlock ? AllTriggers.BRACKET_SHAFT : AllTriggers.BRACKET_COG)); + state -> AllTriggers.BRACKET_APPLY_TRIGGER.constructTriggerFor(state.getBlock()))); super.addBehaviours(behaviours); } 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 e73c1cfc8..043b36303 100644 --- a/src/main/java/com/simibubi/create/foundation/advancement/AllAdvancements.java +++ b/src/main/java/com/simibubi/create/foundation/advancement/AllAdvancements.java @@ -64,9 +64,9 @@ public class AllAdvancements implements IDataProvider { Advancement aesthetics = advancement("aesthetics", AllBlocks.WOODEN_BRACKET.get(), TaskType.NORMAL).withParent(andesite_alloy) - .withCriterion("0", AllTriggers.BRACKET_SHAFT.instance()) - .withCriterion("1", AllTriggers.BRACKET_COG.instance()) - .withCriterion("2", AllTriggers.BRACKET_PIPE.instance()) + .withCriterion("0", AllTriggers.BRACKET_APPLY_TRIGGER.forEntries(AllBlocks.SHAFT.get())) + .withCriterion("1", AllTriggers.BRACKET_APPLY_TRIGGER.forEntries(AllBlocks.COGWHEEL.get(), AllBlocks.LARGE_COGWHEEL.get())) + .withCriterion("2", AllTriggers.BRACKET_APPLY_TRIGGER.forEntries(AllBlocks.FLUID_PIPE.get())) .register(t, id + ":aesthetics"); Advancement reinforced = @@ -497,11 +497,11 @@ public class AllAdvancements implements IDataProvider { } public RegistryTrigger.Instance isPowered(Block block) { - return AllTriggers.KINETIC_BLOCK.forEntry(block); + return AllTriggers.KINETIC_BLOCK.forEntries(block); } public RegistryTrigger.Instance isInfinite(FlowingFluid fluid) { - return AllTriggers.INFINITE_FLUID.forEntry(fluid.getStillFluid()); + return AllTriggers.INFINITE_FLUID.forEntries(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 67b5f2332..c98942bc1 100644 --- a/src/main/java/com/simibubi/create/foundation/advancement/AllTriggers.java +++ b/src/main/java/com/simibubi/create/foundation/advancement/AllTriggers.java @@ -19,6 +19,7 @@ public class AllTriggers { 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 RegistryTrigger BRACKET_APPLY_TRIGGER = add(new RegistryTrigger<>("bracket_apply", Block.class)); public static SimpleTrigger ROTATION = simple("rotation"), @@ -40,9 +41,6 @@ public class AllTriggers { MECHANICAL_ARM = simple("mechanical_arm"), MUSICAL_ARM = simple("musical_arm"), CUCKOO = simple("cuckoo"), - BRACKET_SHAFT = simple("bracket_shaft"), - BRACKET_COG = simple("bracket_cog"), - BRACKET_PIPE = simple("bracket_pipe"), CASING_SHAFT = simple("casing_shaft"), CASING_BELT = simple("casing_belt"), CASING_PIPE = simple("casing_pipe"), 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 14006415b..368c3bc3c 100644 --- a/src/main/java/com/simibubi/create/foundation/advancement/CriterionTriggerBase.java +++ b/src/main/java/com/simibubi/create/foundation/advancement/CriterionTriggerBase.java @@ -77,7 +77,7 @@ public abstract class CriterionTriggerBase> extends Criterion this.registryType = registryType; } - public Instance forEntry(@Nullable T registryEntry) { - return new Instance<>(getId(), registryEntry); + @SafeVarargs + public final Instance forEntries(@Nullable T... entries) { + return new Instance<>(getId(), entries == null ? null : Sets.newHashSet(entries)); } 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 ITriggerable constructTriggerFor(T entry) { + BiConsumer trigger = this::trigger; + return player -> trigger.accept(player, entry); } + @Override + public Instance deserializeInstance(JsonObject json, JsonDeserializationContext context) { + if (json.has("accepted_entries")) { + JsonArray elements = json.getAsJsonArray("accepted_entries"); + IForgeRegistry registry = RegistryManager.ACTIVE.getRegistry(registryType); + + return new Instance<>(getId(), + StreamSupport.stream(elements.spliterator(), false).map(JsonElement::getAsString).map(ResourceLocation::new) + .map(rl -> { + T entry = registry.getValue(rl); + if (entry == null) + throw new JsonSyntaxException("Unknown registry entry '" + rl + "'"); + return entry; + }).collect(Collectors.toSet())); + } + + return forEntries((T) null); + } public static class Instance> extends CriterionTriggerBase.Instance { @Nullable - private final T entry; + private final Set entries; - public Instance(ResourceLocation id, @Nullable T registryEntry) { + public Instance(ResourceLocation id, @Nullable Set registryEntries) { super(id); - entry = registryEntry; + entries = registryEntries; } @Override protected boolean test(@Nullable List> suppliers) { - if (entry == null || suppliers == null || suppliers.isEmpty()) + if (entries == null || suppliers == null || suppliers.isEmpty()) return false; - return entry.equals(suppliers.get(0).get()); + return entries.contains(suppliers.get(0).get()); } @Override public JsonElement serialize() { JsonObject jsonobject = new JsonObject(); - if (entry == null) - return jsonobject; + JsonArray elements = new JsonArray(); - ResourceLocation key = RegistryManager.ACTIVE.getRegistry(entry.getRegistryType()).getKey(entry); - if (key != null) { - jsonobject.addProperty("registry_entry", key.toString()); + if (entries == null) { + jsonobject.add("accepted_entries", elements); + return jsonobject; } + + for (T entry : entries) { + if (entry == null) + continue; + ResourceLocation key = RegistryManager.ACTIVE.getRegistry(entry.getRegistryType()).getKey(entry); + if (key != null) + elements.add(key.toString()); + } + + jsonobject.add("accepted_entries", elements); return jsonobject; } } From 667c2135068bcb8aded2d4a24934fdd630f4c277 Mon Sep 17 00:00:00 2001 From: grimmauld Date: Fri, 19 Feb 2021 14:13:18 +0100 Subject: [PATCH 2/5] remove unused light absorb trigger --- .../create/content/curiosities/ChromaticCompoundItem.java | 8 -------- .../create/foundation/advancement/AllTriggers.java | 1 - 2 files changed, 9 deletions(-) diff --git a/src/main/java/com/simibubi/create/content/curiosities/ChromaticCompoundItem.java b/src/main/java/com/simibubi/create/content/curiosities/ChromaticCompoundItem.java index 5d85d663f..4b853139a 100644 --- a/src/main/java/com/simibubi/create/content/curiosities/ChromaticCompoundItem.java +++ b/src/main/java/com/simibubi/create/content/curiosities/ChromaticCompoundItem.java @@ -1,10 +1,8 @@ package com.simibubi.create.content.curiosities; -import java.util.List; import java.util.Random; import com.simibubi.create.AllItems; -import com.simibubi.create.foundation.advancement.AllTriggers; import com.simibubi.create.foundation.config.AllConfigs; import com.simibubi.create.foundation.config.CRecipes; import com.simibubi.create.foundation.utility.ColorHelper; @@ -13,7 +11,6 @@ import com.simibubi.create.foundation.utility.VecHelper; import net.minecraft.block.BlockState; import net.minecraft.block.Blocks; import net.minecraft.entity.item.ItemEntity; -import net.minecraft.entity.player.ServerPlayerEntity; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.nbt.CompoundNBT; @@ -21,7 +18,6 @@ import net.minecraft.particles.ParticleTypes; import net.minecraft.tileentity.BeaconTileEntity; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.Direction; -import net.minecraft.util.math.AxisAlignedBB; import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.MathHelper; import net.minecraft.util.math.RayTraceContext; @@ -152,10 +148,6 @@ public class ChromaticCompoundItem extends Item { data.putBoolean("FromLight", true); entity.setItem(newStack); - List players = - world.getEntitiesWithinAABB(ServerPlayerEntity.class, new AxisAlignedBB(entity.getPosition()).grow(8)); - players.forEach(AllTriggers.ABSORBED_LIGHT::trigger); - return false; } 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 c98942bc1..1578db80b 100644 --- a/src/main/java/com/simibubi/create/foundation/advancement/AllTriggers.java +++ b/src/main/java/com/simibubi/create/foundation/advancement/AllTriggers.java @@ -31,7 +31,6 @@ public class AllTriggers { LAVA_WHEEL = simple("lava_wheel"), CHOCOLATE_WHEEL = simple("chocolate_wheel"), DEPLOYER_BOOP = simple("deployer"), - ABSORBED_LIGHT = simple("light_absorbed"), SPEED_READ = simple("speed_read"), BASIN_THROW = simple("basin"), PRESS_COMPACT = simple("compact"), From 589572df6ce29c447e320cbcdd0cd5ce225c1908 Mon Sep 17 00:00:00 2001 From: grimmauld Date: Fri, 19 Feb 2021 14:21:02 +0100 Subject: [PATCH 3/5] kill kinetic block trigger, clean up unused stuff --- src/generated/resources/.cache/cache | 6 +- .../create/blockstates/radial_chassis.json | 96 +++++++++---------- .../data/create/advancements/aesthetics.json | 4 +- .../data/create/advancements/mixer.json | 11 --- .../contraptions/base/KineticTileEntity.java | 4 - .../fluids/actors/FluidDrainingBehaviour.java | 13 +-- .../advancement/AllAdvancements.java | 7 +- .../foundation/advancement/AllTriggers.java | 1 - 8 files changed, 55 insertions(+), 87 deletions(-) diff --git a/src/generated/resources/.cache/cache b/src/generated/resources/.cache/cache index b529b1fdb..ecde36955 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 -4439fc83a8c7370ab44b211a3fd48abde20a4728 assets/create/blockstates/radial_chassis.json +8d7e653bfd9846e684a0d3725595714a19201017 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 @@ -1586,7 +1586,7 @@ d080b1b25e5bc8baf5aee68691b08c7f12ece3b0 assets/create/models/item/windmill_bear 9f9455ccb5fc9e3cbfce73862b46078346a522a5 assets/create/models/item/zinc_nugget.json b1689617190c05ef34bd18456b0c7ae09bb3210f assets/create/models/item/zinc_ore.json e76041b7ae829fdd7dc0524f6ca4d2f89fca51bb assets/create/sounds.json -0f1b4b980afba9bf2caf583b88e261bba8b10313 data/create/advancements/aesthetics.json +5d0cc4c0255dc241e61c173b31ddca70c88d08e4 data/create/advancements/aesthetics.json 187921fa131b06721bfaf63f2623a28c141aae9a data/create/advancements/andesite_alloy.json 0ea2db7173b5be28b289ea7c9a6a0cf5805c60c7 data/create/advancements/andesite_casing.json 356f4855a2a6c65be3fb51d7d1aabf2ca6034d42 data/create/advancements/arm_blaze_burner.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 -f41d548c21a8540428ea043451e5fbb641fc2e58 data/create/advancements/mixer.json +238ac410eb4de16a82ae05cc16fef80e55a4b61b 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 8bd829ffc..9d00ea8b1 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": { - "axis": "x", - "sticky_south": "true" + "sticky_south": "true", + "axis": "x" }, "apply": { "model": "create:block/radial_chassis_side_x_sticky", @@ -39,8 +39,8 @@ }, { "when": { - "axis": "y", - "sticky_south": "true" + "sticky_south": "true", + "axis": "y" }, "apply": { "model": "create:block/radial_chassis_side_y_sticky" @@ -48,8 +48,8 @@ }, { "when": { - "axis": "z", - "sticky_south": "true" + "sticky_south": "true", + "axis": "z" }, "apply": { "model": "create:block/radial_chassis_side_x_sticky", @@ -59,8 +59,8 @@ }, { "when": { - "axis": "x", - "sticky_south": "false" + "sticky_south": "false", + "axis": "x" }, "apply": { "model": "create:block/radial_chassis_side_x", @@ -69,8 +69,8 @@ }, { "when": { - "axis": "y", - "sticky_south": "false" + "sticky_south": "false", + "axis": "y" }, "apply": { "model": "create:block/radial_chassis_side_y" @@ -78,8 +78,8 @@ }, { "when": { - "axis": "z", - "sticky_south": "false" + "sticky_south": "false", + "axis": "z" }, "apply": { "model": "create:block/radial_chassis_side_x", @@ -89,8 +89,8 @@ }, { "when": { - "axis": "x", - "sticky_west": "true" + "sticky_west": "true", + "axis": "x" }, "apply": { "model": "create:block/radial_chassis_side_x_sticky", @@ -99,8 +99,8 @@ }, { "when": { - "axis": "y", - "sticky_west": "true" + "sticky_west": "true", + "axis": "y" }, "apply": { "model": "create:block/radial_chassis_side_y_sticky", @@ -109,8 +109,8 @@ }, { "when": { - "axis": "z", - "sticky_west": "true" + "sticky_west": "true", + "axis": "z" }, "apply": { "model": "create:block/radial_chassis_side_z_sticky", @@ -119,8 +119,8 @@ }, { "when": { - "axis": "x", - "sticky_west": "false" + "sticky_west": "false", + "axis": "x" }, "apply": { "model": "create:block/radial_chassis_side_x", @@ -129,8 +129,8 @@ }, { "when": { - "axis": "y", - "sticky_west": "false" + "sticky_west": "false", + "axis": "y" }, "apply": { "model": "create:block/radial_chassis_side_y", @@ -139,8 +139,8 @@ }, { "when": { - "axis": "z", - "sticky_west": "false" + "sticky_west": "false", + "axis": "z" }, "apply": { "model": "create:block/radial_chassis_side_z", @@ -149,8 +149,8 @@ }, { "when": { - "axis": "x", - "sticky_north": "true" + "sticky_north": "true", + "axis": "x" }, "apply": { "model": "create:block/radial_chassis_side_x_sticky" @@ -158,8 +158,8 @@ }, { "when": { - "axis": "y", - "sticky_north": "true" + "sticky_north": "true", + "axis": "y" }, "apply": { "model": "create:block/radial_chassis_side_y_sticky", @@ -168,8 +168,8 @@ }, { "when": { - "axis": "z", - "sticky_north": "true" + "sticky_north": "true", + "axis": "z" }, "apply": { "model": "create:block/radial_chassis_side_x_sticky", @@ -178,8 +178,8 @@ }, { "when": { - "axis": "x", - "sticky_north": "false" + "sticky_north": "false", + "axis": "x" }, "apply": { "model": "create:block/radial_chassis_side_x" @@ -187,8 +187,8 @@ }, { "when": { - "axis": "y", - "sticky_north": "false" + "sticky_north": "false", + "axis": "y" }, "apply": { "model": "create:block/radial_chassis_side_y", @@ -197,8 +197,8 @@ }, { "when": { - "axis": "z", - "sticky_north": "false" + "sticky_north": "false", + "axis": "z" }, "apply": { "model": "create:block/radial_chassis_side_x", @@ -207,8 +207,8 @@ }, { "when": { - "axis": "x", - "sticky_east": "true" + "sticky_east": "true", + "axis": "x" }, "apply": { "model": "create:block/radial_chassis_side_x_sticky", @@ -217,8 +217,8 @@ }, { "when": { - "axis": "y", - "sticky_east": "true" + "sticky_east": "true", + "axis": "y" }, "apply": { "model": "create:block/radial_chassis_side_y_sticky", @@ -227,8 +227,8 @@ }, { "when": { - "axis": "z", - "sticky_east": "true" + "sticky_east": "true", + "axis": "z" }, "apply": { "model": "create:block/radial_chassis_side_z_sticky" @@ -236,8 +236,8 @@ }, { "when": { - "axis": "x", - "sticky_east": "false" + "sticky_east": "false", + "axis": "x" }, "apply": { "model": "create:block/radial_chassis_side_x", @@ -246,8 +246,8 @@ }, { "when": { - "axis": "y", - "sticky_east": "false" + "sticky_east": "false", + "axis": "y" }, "apply": { "model": "create:block/radial_chassis_side_y", @@ -256,8 +256,8 @@ }, { "when": { - "axis": "z", - "sticky_east": "false" + "sticky_east": "false", + "axis": "z" }, "apply": { "model": "create:block/radial_chassis_side_z" diff --git a/src/generated/resources/data/create/advancements/aesthetics.json b/src/generated/resources/data/create/advancements/aesthetics.json index d723cbe38..59a86f429 100644 --- a/src/generated/resources/data/create/advancements/aesthetics.json +++ b/src/generated/resources/data/create/advancements/aesthetics.json @@ -28,8 +28,8 @@ "trigger": "create:bracket_apply", "conditions": { "accepted_entries": [ - "create:cogwheel", - "create:large_cogwheel" + "create:large_cogwheel", + "create:cogwheel" ] } }, diff --git a/src/generated/resources/data/create/advancements/mixer.json b/src/generated/resources/data/create/advancements/mixer.json index 145bea240..b67d6b70d 100644 --- a/src/generated/resources/data/create/advancements/mixer.json +++ b/src/generated/resources/data/create/advancements/mixer.json @@ -23,14 +23,6 @@ } }, "1": { - "trigger": "create:kinetic_block", - "conditions": { - "accepted_entries": [ - "create:mechanical_mixer" - ] - } - }, - "2": { "trigger": "create:mixer" } }, @@ -40,9 +32,6 @@ ], [ "1" - ], - [ - "2" ] ] } \ No newline at end of file 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 cf1815817..088ce8618 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 @@ -173,10 +173,6 @@ public abstract class KineticTileEntity extends SmartTileEntity boolean directionSwap = !fromOrToZero && Math.signum(previousSpeed) != Math.signum(getSpeed()); if (fromOrToZero || directionSwap) flickerTally = getFlickerScore() + 5; - - if (fromOrToZero && previousSpeed == 0 && !world.isRemote) - AllTriggers.getPlayersInRange(world, pos, 4) - .forEach(p -> AllTriggers.KINETIC_BLOCK.trigger(p, getBlockState().getBlock())); } @Override diff --git a/src/main/java/com/simibubi/create/content/contraptions/fluids/actors/FluidDrainingBehaviour.java b/src/main/java/com/simibubi/create/content/contraptions/fluids/actors/FluidDrainingBehaviour.java index 3423c9704..8cc65f55a 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/fluids/actors/FluidDrainingBehaviour.java +++ b/src/main/java/com/simibubi/create/content/contraptions/fluids/actors/FluidDrainingBehaviour.java @@ -8,8 +8,6 @@ import java.util.Set; import javax.annotation.Nullable; -import com.simibubi.create.AllFluids; -import com.simibubi.create.foundation.advancement.AllAdvancements; import com.simibubi.create.foundation.advancement.AllTriggers; import com.simibubi.create.foundation.fluid.FluidHelper; import com.simibubi.create.foundation.tileEntity.SmartTileEntity; @@ -134,16 +132,7 @@ public class FluidDrainingBehaviour extends FluidManipulationBehaviour { AllTriggers.triggerForNearbyPlayers(AllTriggers.HOSE_PULLEY, world, tileEntity.getPos(), 8); if (infinite) { - Fluid stillFluid = FluidHelper.convertToStill(fluid); - AllTriggers.getPlayersInRange(world, tileEntity.getPos(), 8) - .forEach(p -> AllTriggers.INFINITE_FLUID.trigger(p, FluidHelper.convertToStill(stillFluid))); - /* - if (FluidHelper.isLava(fluid)) - AllTriggers.triggerForNearbyPlayers(AllTriggers.INFINITE_LAVA, world, tileEntity.getPos(), 8); - if (FluidHelper.isWater(fluid)) - AllTriggers.triggerForNearbyPlayers(AllTriggers.INFINITE_WATER, world, tileEntity.getPos(), 8); - if (fluid.isEquivalentTo(AllFluids.CHOCOLATE.get())) - AllTriggers.triggerForNearbyPlayers(AllTriggers.INFINITE_CHOCOLATE, world, tileEntity.getPos(), 8);*/ + AllTriggers.triggerForNearbyPlayers(AllTriggers.INFINITE_FLUID.constructTriggerFor(FluidHelper.convertToStill(fluid)), world, tileEntity.getPos(), 8); return true; } 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 043b36303..5355f9bb5 100644 --- a/src/main/java/com/simibubi/create/foundation/advancement/AllAdvancements.java +++ b/src/main/java/com/simibubi/create/foundation/advancement/AllAdvancements.java @@ -160,8 +160,7 @@ public class AllAdvancements implements IDataProvider { Advancement mixer = advancement("mixer", AllBlocks.MECHANICAL_MIXER.get(), TaskType.MILESTONE) .withCriterion("0", placeBlock(AllBlocks.MECHANICAL_MIXER.get())) - .withCriterion("1", isPowered(AllBlocks.MECHANICAL_MIXER.get())) - .withCriterion("2", AllTriggers.MIXER_MIX.instance()) + .withCriterion("1", AllTriggers.MIXER_MIX.instance()) .withParent(basin) .register(t, id + ":mixer"); @@ -496,10 +495,6 @@ public class AllAdvancements implements IDataProvider { return PlacedBlockTrigger.Instance.placedBlock(block); } - public RegistryTrigger.Instance isPowered(Block block) { - return AllTriggers.KINETIC_BLOCK.forEntries(block); - } - public RegistryTrigger.Instance isInfinite(FlowingFluid fluid) { return AllTriggers.INFINITE_FLUID.forEntries(fluid.getStillFluid()); } 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 1578db80b..e021575f8 100644 --- a/src/main/java/com/simibubi/create/foundation/advancement/AllTriggers.java +++ b/src/main/java/com/simibubi/create/foundation/advancement/AllTriggers.java @@ -17,7 +17,6 @@ public class AllTriggers { private static final List> triggers = new LinkedList<>(); - 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 RegistryTrigger BRACKET_APPLY_TRIGGER = add(new RegistryTrigger<>("bracket_apply", Block.class)); From d0357df8631e35f3f8ca35db53f6d857bd1e8340 Mon Sep 17 00:00:00 2001 From: grimmauld Date: Fri, 19 Feb 2021 15:08:50 +0100 Subject: [PATCH 4/5] Move stuff of RegistryTrigger over to StringSerializableTrigger to make future expansion possible --- src/generated/resources/.cache/cache | 2 +- .../data/create/advancements/aesthetics.json | 4 +- .../advancement/RegistryTrigger.java | 91 ++-------------- .../StringSerializableTrigger.java | 103 ++++++++++++++++++ 4 files changed, 117 insertions(+), 83 deletions(-) create mode 100644 src/main/java/com/simibubi/create/foundation/advancement/StringSerializableTrigger.java diff --git a/src/generated/resources/.cache/cache b/src/generated/resources/.cache/cache index ecde36955..e1d242c23 100644 --- a/src/generated/resources/.cache/cache +++ b/src/generated/resources/.cache/cache @@ -1586,7 +1586,7 @@ d080b1b25e5bc8baf5aee68691b08c7f12ece3b0 assets/create/models/item/windmill_bear 9f9455ccb5fc9e3cbfce73862b46078346a522a5 assets/create/models/item/zinc_nugget.json b1689617190c05ef34bd18456b0c7ae09bb3210f assets/create/models/item/zinc_ore.json e76041b7ae829fdd7dc0524f6ca4d2f89fca51bb assets/create/sounds.json -5d0cc4c0255dc241e61c173b31ddca70c88d08e4 data/create/advancements/aesthetics.json +0f1b4b980afba9bf2caf583b88e261bba8b10313 data/create/advancements/aesthetics.json 187921fa131b06721bfaf63f2623a28c141aae9a data/create/advancements/andesite_alloy.json 0ea2db7173b5be28b289ea7c9a6a0cf5805c60c7 data/create/advancements/andesite_casing.json 356f4855a2a6c65be3fb51d7d1aabf2ca6034d42 data/create/advancements/arm_blaze_burner.json diff --git a/src/generated/resources/data/create/advancements/aesthetics.json b/src/generated/resources/data/create/advancements/aesthetics.json index 59a86f429..d723cbe38 100644 --- a/src/generated/resources/data/create/advancements/aesthetics.json +++ b/src/generated/resources/data/create/advancements/aesthetics.json @@ -28,8 +28,8 @@ "trigger": "create:bracket_apply", "conditions": { "accepted_entries": [ - "create:large_cogwheel", - "create:cogwheel" + "create:cogwheel", + "create:large_cogwheel" ] } }, 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 468820b3c..0a70e87b0 100644 --- a/src/main/java/com/simibubi/create/foundation/advancement/RegistryTrigger.java +++ b/src/main/java/com/simibubi/create/foundation/advancement/RegistryTrigger.java @@ -1,9 +1,6 @@ package com.simibubi.create.foundation.advancement; -import com.google.common.collect.Sets; -import com.google.gson.*; import mcp.MethodsReturnNonnullByDefault; -import net.minecraft.entity.player.ServerPlayerEntity; import net.minecraft.util.ResourceLocation; import net.minecraftforge.registries.IForgeRegistry; import net.minecraftforge.registries.IForgeRegistryEntry; @@ -11,94 +8,28 @@ import net.minecraftforge.registries.RegistryManager; import javax.annotation.Nullable; 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; @ParametersAreNonnullByDefault @MethodsReturnNonnullByDefault -public class RegistryTrigger> extends CriterionTriggerBase> { - private final Class registryType; +public class RegistryTrigger> extends StringSerializableTrigger { + private final IForgeRegistry registry; public RegistryTrigger(String id, Class registryType) { super(id); - this.registryType = registryType; - } - - @SafeVarargs - public final Instance forEntries(@Nullable T... entries) { - return new Instance<>(getId(), entries == null ? null : Sets.newHashSet(entries)); - } - - public void trigger(ServerPlayerEntity player, T registryEntry) { - trigger(player, Collections.singletonList(() -> registryEntry)); - } - - public ITriggerable constructTriggerFor(T entry) { - BiConsumer trigger = this::trigger; - return player -> trigger.accept(player, entry); + this.registry = RegistryManager.ACTIVE.getRegistry(registryType); } + @Nullable @Override - public Instance deserializeInstance(JsonObject json, JsonDeserializationContext context) { - if (json.has("accepted_entries")) { - JsonArray elements = json.getAsJsonArray("accepted_entries"); - IForgeRegistry registry = RegistryManager.ACTIVE.getRegistry(registryType); + protected T getValue(String key) { - return new Instance<>(getId(), - StreamSupport.stream(elements.spliterator(), false).map(JsonElement::getAsString).map(ResourceLocation::new) - .map(rl -> { - T entry = registry.getValue(rl); - if (entry == null) - throw new JsonSyntaxException("Unknown registry entry '" + rl + "'"); - return entry; - }).collect(Collectors.toSet())); - } - - return forEntries((T) null); + return registry.getValue(new ResourceLocation(key)); } - public static class Instance> extends CriterionTriggerBase.Instance { - - @Nullable - private final Set entries; - - public Instance(ResourceLocation id, @Nullable Set registryEntries) { - super(id); - entries = registryEntries; - } - - @Override - protected boolean test(@Nullable List> suppliers) { - if (entries == null || suppliers == null || suppliers.isEmpty()) - return false; - return entries.contains(suppliers.get(0).get()); - } - - @Override - public JsonElement serialize() { - JsonObject jsonobject = new JsonObject(); - JsonArray elements = new JsonArray(); - - if (entries == null) { - jsonobject.add("accepted_entries", elements); - return jsonobject; - } - - for (T entry : entries) { - if (entry == null) - continue; - ResourceLocation key = RegistryManager.ACTIVE.getRegistry(entry.getRegistryType()).getKey(entry); - if (key != null) - elements.add(key.toString()); - } - - jsonobject.add("accepted_entries", elements); - return jsonobject; - } + @Nullable + @Override + protected String getKey(T value) { + ResourceLocation key = registry.getKey(value); + return key == null ? null : key.toString(); } } diff --git a/src/main/java/com/simibubi/create/foundation/advancement/StringSerializableTrigger.java b/src/main/java/com/simibubi/create/foundation/advancement/StringSerializableTrigger.java new file mode 100644 index 000000000..21e823a63 --- /dev/null +++ b/src/main/java/com/simibubi/create/foundation/advancement/StringSerializableTrigger.java @@ -0,0 +1,103 @@ +package com.simibubi.create.foundation.advancement; + +import com.google.common.collect.Sets; +import com.google.gson.*; +import mcp.MethodsReturnNonnullByDefault; +import net.minecraft.entity.player.ServerPlayerEntity; + +import javax.annotation.Nullable; +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; + +@MethodsReturnNonnullByDefault +@ParametersAreNonnullByDefault +public abstract class StringSerializableTrigger extends CriterionTriggerBase> { + public StringSerializableTrigger(String id) { + super(id); + } + + @SafeVarargs + public final Instance forEntries(@Nullable T... entries) { + return new Instance<>(this, entries == null ? null : Sets.newHashSet(entries)); + } + + public void trigger(ServerPlayerEntity player, T registryEntry) { + trigger(player, Collections.singletonList(() -> registryEntry)); + } + + public ITriggerable constructTriggerFor(T entry) { + BiConsumer trigger = this::trigger; + return player -> trigger.accept(player, entry); + } + + @Override + public Instance deserializeInstance(JsonObject json, JsonDeserializationContext context) { + if (json.has("accepted_entries")) { + JsonArray elements = json.getAsJsonArray("accepted_entries"); + return new Instance<>(this, + StreamSupport.stream(elements.spliterator(), false).map(JsonElement::getAsString) + .map(rl -> { + T entry = getValue(rl); + if (entry == null) + throw new JsonSyntaxException("Unknown entry '" + rl + "'"); + return entry; + }).collect(Collectors.toSet())); + } + + return forEntries((T) null); + } + + @Nullable + abstract protected T getValue(String key); + + @Nullable + abstract protected String getKey(T value); + + public static class Instance extends CriterionTriggerBase.Instance { + + @Nullable + private final Set entries; + private final StringSerializableTrigger trigger; + + public Instance(StringSerializableTrigger trigger, @Nullable Set entries) { + super(trigger.getId()); + this.trigger = trigger; + this.entries = entries; + } + + @Override + protected boolean test(@Nullable List> suppliers) { + if (entries == null || suppliers == null || suppliers.isEmpty()) + return false; + return entries.contains(suppliers.get(0).get()); + } + + @Override + public JsonElement serialize() { + JsonObject jsonobject = new JsonObject(); + JsonArray elements = new JsonArray(); + + if (entries == null) { + jsonobject.add("accepted_entries", elements); + return jsonobject; + } + + for (T entry : entries) { + if (entry == null) + continue; + String key = trigger.getKey(entry); + if (key != null) + elements.add(key); + } + + jsonobject.add("accepted_entries", elements); + return jsonobject; + } + } +} From 5b65a5d78b5bf18bab0ebb00607c0357bc193fdb Mon Sep 17 00:00:00 2001 From: grimmauld Date: Fri, 19 Feb 2021 16:39:01 +0100 Subject: [PATCH 5/5] better fan stream advancement trigger --- src/generated/resources/.cache/cache | 10 ++-- .../create/blockstates/radial_chassis.json | 48 +++++++++---------- .../data/create/advancements/fan.json | 7 ++- .../data/create/advancements/fan_lava.json | 7 ++- .../data/create/advancements/fan_smoke.json | 7 ++- .../data/create/advancements/fan_water.json | 7 ++- .../components/fan/AirCurrent.java | 19 +++----- .../content/logistics/InWorldProcessing.java | 4 +- .../advancement/AllAdvancements.java | 9 ++-- .../foundation/advancement/AllTriggers.java | 6 +-- .../foundation/advancement/EnumTrigger.java | 35 ++++++++++++++ .../StringSerializableTrigger.java | 4 +- 12 files changed, 106 insertions(+), 57 deletions(-) create mode 100644 src/main/java/com/simibubi/create/foundation/advancement/EnumTrigger.java diff --git a/src/generated/resources/.cache/cache b/src/generated/resources/.cache/cache index e1d242c23..3a320bbb2 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 +143d66a7262ccd29f36784d6b064d4a13ba374b6 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 @@ -1616,10 +1616,10 @@ d1fbc14303c7327e9fc02e505e7e434591b7f785 data/create/advancements/crushing_wheel 77edd30e3d60b4d492662c673387910f66b5a276 data/create/advancements/dual_extendo_grip.json 04eaf829696d735244c0e4798dd3bdeb26e13a32 data/create/advancements/electron_tube.json b78fe4e539fef1b3419f2eb4d1db47cb4a201992 data/create/advancements/extendo_grip.json -4dbbf5f39441fdfe0561022ea7bbaa8e1f9733b7 data/create/advancements/fan.json -9e2369129a52ffb4c67907ca5e81e342766f7867 data/create/advancements/fan_lava.json -acef16596b7ae82aaf853142d69bcea7094b8173 data/create/advancements/fan_smoke.json -36f72396d1b4ac9a89f4a9139fa10ed659f5954a data/create/advancements/fan_water.json +b1699baaadaac7ebce642c09428519d156e21594 data/create/advancements/fan.json +5aa76cba3b40a1c234ffa84a89ecca630990fc0f data/create/advancements/fan_lava.json +716a9816558300a3652ed8d8d568517017813f5c data/create/advancements/fan_smoke.json +a61eb63d02604e88836519f89f74b252a640d485 data/create/advancements/fan_water.json 69e96e926a4d72e59cc6390c25f064166ddb62d2 data/create/advancements/fist_bump.json 99ee1bf5390b9a4f2a2419c78f259ff5d2ab9ae9 data/create/advancements/flywheel.json 489c58a0508a2a41cc0849dfb933eb5ac96ef364 data/create/advancements/glass_pipe.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..83d44d583 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", diff --git a/src/generated/resources/data/create/advancements/fan.json b/src/generated/resources/data/create/advancements/fan.json index fd00498a5..bafda450d 100644 --- a/src/generated/resources/data/create/advancements/fan.json +++ b/src/generated/resources/data/create/advancements/fan.json @@ -17,7 +17,12 @@ }, "criteria": { "0": { - "trigger": "create:fan" + "trigger": "create:fan_processing", + "conditions": { + "accepted_entries": [ + "NONE" + ] + } } }, "requirements": [ diff --git a/src/generated/resources/data/create/advancements/fan_lava.json b/src/generated/resources/data/create/advancements/fan_lava.json index 1b15d56b6..6e6362c0a 100644 --- a/src/generated/resources/data/create/advancements/fan_lava.json +++ b/src/generated/resources/data/create/advancements/fan_lava.json @@ -17,7 +17,12 @@ }, "criteria": { "0": { - "trigger": "create:fan_lava" + "trigger": "create:fan_processing", + "conditions": { + "accepted_entries": [ + "BLASTING" + ] + } } }, "requirements": [ diff --git a/src/generated/resources/data/create/advancements/fan_smoke.json b/src/generated/resources/data/create/advancements/fan_smoke.json index 51cd3cdc1..017a1b6f7 100644 --- a/src/generated/resources/data/create/advancements/fan_smoke.json +++ b/src/generated/resources/data/create/advancements/fan_smoke.json @@ -17,7 +17,12 @@ }, "criteria": { "0": { - "trigger": "create:fan_smoke" + "trigger": "create:fan_processing", + "conditions": { + "accepted_entries": [ + "SMOKING" + ] + } } }, "requirements": [ diff --git a/src/generated/resources/data/create/advancements/fan_water.json b/src/generated/resources/data/create/advancements/fan_water.json index a70ae1092..3e7368f4b 100644 --- a/src/generated/resources/data/create/advancements/fan_water.json +++ b/src/generated/resources/data/create/advancements/fan_water.json @@ -17,7 +17,12 @@ }, "criteria": { "0": { - "trigger": "create:fan_water" + "trigger": "create:fan_processing", + "conditions": { + "accepted_entries": [ + "SPLASHING" + ] + } } }, "requirements": [ diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/fan/AirCurrent.java b/src/main/java/com/simibubi/create/content/contraptions/components/fan/AirCurrent.java index 8f499bce8..53c2eac1d 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/fan/AirCurrent.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/fan/AirCurrent.java @@ -114,9 +114,10 @@ public class AirCurrent { entityDistance -= .5f; InWorldProcessing.Type processingType = getSegmentAt((float) entityDistance); - if (processingType == null) { - if (entity instanceof ServerPlayerEntity) - AllTriggers.triggerFor(AllTriggers.FAN, (PlayerEntity) entity); + if (entity instanceof ServerPlayerEntity) + AllTriggers.triggerFor(AllTriggers.FAN_PROCESSING.constructTriggerFor(processingType), (PlayerEntity) entity); + + if (processingType == null || processingType == Type.NONE) { continue; } @@ -139,24 +140,18 @@ public class AirCurrent { entity.setFire(10); entity.attackEntityFrom(damageSourceLava, 4); } - if (entity instanceof ServerPlayerEntity) - AllTriggers.triggerFor(AllTriggers.FAN_LAVA, (PlayerEntity) entity); break; case SMOKING: if (!entity.isImmuneToFire()) { entity.setFire(2); entity.attackEntityFrom(damageSourceFire, 2); } - if (entity instanceof ServerPlayerEntity) - AllTriggers.triggerFor(AllTriggers.FAN_SMOKE, (PlayerEntity) entity); break; case SPLASHING: if (entity instanceof EndermanEntity || entity.getType() == EntityType.SNOW_GOLEM || entity.getType() == EntityType.BLAZE) { entity.attackEntityFrom(DamageSource.DROWN, 2); } - if (entity instanceof ServerPlayerEntity) - AllTriggers.triggerFor(AllTriggers.FAN_WATER, (PlayerEntity) entity); if (!entity.isBurning()) break; entity.extinguish(); @@ -193,7 +188,7 @@ public class AirCurrent { AirCurrentSegment currentSegment = new AirCurrentSegment(); segments.clear(); currentSegment.startOffset = 0; - InWorldProcessing.Type type = null; + InWorldProcessing.Type type = Type.NONE; int limit = (int) (maxDistance + .5f); int searchStart = pushing ? 0 : limit; @@ -203,7 +198,7 @@ public class AirCurrent { for (int i = searchStart; i * searchStep <= searchEnd * searchStep; i += searchStep) { BlockPos currentPos = start.offset(direction, i); InWorldProcessing.Type newType = InWorldProcessing.Type.byBlock(world, currentPos); - if (newType != null) + if (newType != Type.NONE) type = newType; if (currentSegment.type != type || currentSegment.startOffset == 0) { currentSegment.endOffset = i; @@ -341,7 +336,7 @@ public class AirCurrent { continue; return airCurrentSegment.type; } - return null; + return InWorldProcessing.Type.NONE; } public static class AirCurrentSegment { diff --git a/src/main/java/com/simibubi/create/content/logistics/InWorldProcessing.java b/src/main/java/com/simibubi/create/content/logistics/InWorldProcessing.java index 88a5fe2fb..8ce46bffa 100644 --- a/src/main/java/com/simibubi/create/content/logistics/InWorldProcessing.java +++ b/src/main/java/com/simibubi/create/content/logistics/InWorldProcessing.java @@ -58,7 +58,7 @@ public class InWorldProcessing { public static SplashingInv splashingInv = new SplashingInv(); public enum Type { - SMOKING, BLASTING, SPLASHING + SMOKING, BLASTING, SPLASHING, NONE ; @@ -74,7 +74,7 @@ public class InWorldProcessing { return Type.SMOKING; if (block == Blocks.LAVA || getHeatLevelOf(blockState).isAtLeast(BlazeBurnerBlock.HeatLevel.FADING)) return Type.BLASTING; - return null; + return Type.NONE; } } 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 5355f9bb5..013a6282e 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 com.simibubi.create.content.logistics.InWorldProcessing; import net.minecraft.fluid.FlowingFluid; import net.minecraft.fluid.Fluid; import net.minecraft.fluid.Fluids; @@ -125,19 +126,19 @@ public class AllAdvancements implements IDataProvider { .register(t, id + ":press"); Advancement fan = advancement("fan", AllBlocks.ENCASED_FAN.get(), TaskType.NORMAL).withParent(press) - .withCriterion("0", AllTriggers.FAN.instance()) + .withCriterion("0", AllTriggers.FAN_PROCESSING.forEntries(InWorldProcessing.Type.NONE)) .register(t, id + ":fan"); Advancement fan_lava = advancement("fan_lava", Items.LAVA_BUCKET, TaskType.NORMAL).withParent(fan) - .withCriterion("0", AllTriggers.FAN_LAVA.instance()) + .withCriterion("0", AllTriggers.FAN_PROCESSING.forEntries(InWorldProcessing.Type.BLASTING)) .register(t, id + ":fan_lava"); Advancement fan_smoke = advancement("fan_smoke", Items.CAMPFIRE, TaskType.NORMAL).withParent(fan) - .withCriterion("0", AllTriggers.FAN_SMOKE.instance()) + .withCriterion("0", AllTriggers.FAN_PROCESSING.forEntries(InWorldProcessing.Type.SMOKING)) .register(t, id + ":fan_smoke"); Advancement fan_water = advancement("fan_water", Items.WATER_BUCKET, TaskType.NORMAL).withParent(fan) - .withCriterion("0", AllTriggers.FAN_WATER.instance()) + .withCriterion("0", AllTriggers.FAN_PROCESSING.forEntries(InWorldProcessing.Type.SPLASHING)) .register(t, id + ":fan_water"); Advancement rose_quartz = 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 e021575f8..51ae96434 100644 --- a/src/main/java/com/simibubi/create/foundation/advancement/AllTriggers.java +++ b/src/main/java/com/simibubi/create/foundation/advancement/AllTriggers.java @@ -4,6 +4,7 @@ import java.util.LinkedList; import java.util.List; import java.util.function.Predicate; +import com.simibubi.create.content.logistics.InWorldProcessing; import net.minecraft.advancements.CriteriaTriggers; import net.minecraft.block.Block; import net.minecraft.entity.player.PlayerEntity; @@ -19,6 +20,7 @@ public class AllTriggers { 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 SimpleTrigger ROTATION = simple("rotation"), @@ -47,10 +49,6 @@ public class AllTriggers { PLACE_TUNNEL = simple("place_tunnel"), CONNECT_TUNNEL = simple("connect_tunnel"), UPWARD_CHUTE = simple("upward_chute"), - FAN = simple("fan"), - FAN_LAVA = simple("fan_lava"), - FAN_SMOKE = simple("fan_smoke"), - FAN_WATER = simple("fan_water"), BELT_FUNNEL = simple("belt_funnel"), BELT_FUNNEL_KISS = simple("belt_funnel_kiss"), CLOCKWORK_BEARING = simple("clockwork_bearing"), diff --git a/src/main/java/com/simibubi/create/foundation/advancement/EnumTrigger.java b/src/main/java/com/simibubi/create/foundation/advancement/EnumTrigger.java new file mode 100644 index 000000000..ed3952658 --- /dev/null +++ b/src/main/java/com/simibubi/create/foundation/advancement/EnumTrigger.java @@ -0,0 +1,35 @@ +package com.simibubi.create.foundation.advancement; + +import mcp.MethodsReturnNonnullByDefault; + +import javax.annotation.Nullable; +import javax.annotation.ParametersAreNonnullByDefault; + +@ParametersAreNonnullByDefault +@MethodsReturnNonnullByDefault +public class EnumTrigger> extends StringSerializableTrigger { + private final Class reference; + + public EnumTrigger(String id, Class reference) { + super(id); + this.reference = reference; + } + + @Nullable + @Override + protected T getValue(String key) { + try { + return Enum.valueOf(reference, key); + } catch (IllegalArgumentException | NullPointerException e) { + return null; + } + } + + @Nullable + @Override + protected String getKey(@Nullable T value) { + if (value == null) + return null; + return value.name(); + } +} 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 21e823a63..ae6f4d83d 100644 --- a/src/main/java/com/simibubi/create/foundation/advancement/StringSerializableTrigger.java +++ b/src/main/java/com/simibubi/create/foundation/advancement/StringSerializableTrigger.java @@ -27,11 +27,11 @@ public abstract class StringSerializableTrigger extends CriterionTriggerBase< return new Instance<>(this, entries == null ? null : Sets.newHashSet(entries)); } - public void trigger(ServerPlayerEntity player, T registryEntry) { + public void trigger(ServerPlayerEntity player, @Nullable T registryEntry) { trigger(player, Collections.singletonList(() -> registryEntry)); } - public ITriggerable constructTriggerFor(T entry) { + public ITriggerable constructTriggerFor(@Nullable T entry) { BiConsumer trigger = this::trigger; return player -> trigger.accept(player, entry); }