diff --git a/src/generated/resources/.cache/cache b/src/generated/resources/.cache/cache index 08ece2aab..046c32d3a 100644 --- a/src/generated/resources/.cache/cache +++ b/src/generated/resources/.cache/cache @@ -1587,7 +1587,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 @@ -1617,18 +1617,18 @@ 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 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 @@ -1639,7 +1639,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 +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..2e2d16cf1 100644 --- a/src/generated/resources/assets/create/blockstates/radial_chassis.json +++ b/src/generated/resources/assets/create/blockstates/radial_chassis.json @@ -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", 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/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/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..b67d6b70d 100644 --- a/src/generated/resources/data/create/advancements/mixer.json +++ b/src/generated/resources/data/create/advancements/mixer.json @@ -23,12 +23,6 @@ } }, "1": { - "trigger": "create:kinetic_block", - "conditions": { - "registry_entry": "create:mechanical_mixer" - } - }, - "2": { "trigger": "create:mixer" } }, @@ -38,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/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/contraptions/fluids/actors/FluidDrainingBehaviour.java b/src/main/java/com/simibubi/create/content/contraptions/fluids/actors/FluidDrainingBehaviour.java index a38b1bab2..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 @@ -132,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/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/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/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 e73c1cfc8..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; @@ -64,9 +65,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 = @@ -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 = @@ -160,8 +161,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,12 +496,8 @@ public class AllAdvancements implements IDataProvider { return PlacedBlockTrigger.Instance.placedBlock(block); } - public RegistryTrigger.Instance isPowered(Block block) { - return AllTriggers.KINETIC_BLOCK.forEntry(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..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; @@ -17,8 +18,9 @@ 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)); + public static EnumTrigger FAN_PROCESSING = add(new EnumTrigger<>("fan_processing", InWorldProcessing.Type.class)); public static SimpleTrigger ROTATION = simple("rotation"), @@ -30,7 +32,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"), @@ -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"), @@ -51,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/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 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/RegistryTrigger.java b/src/main/java/com/simibubi/create/foundation/advancement/RegistryTrigger.java index 3851bdf2d..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,83 +1,35 @@ 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.IForgeRegistry; 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 class RegistryTrigger> extends StringSerializableTrigger { + private final IForgeRegistry registry; 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)); + this.registry = RegistryManager.ACTIVE.getRegistry(registryType); } + @Nullable @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); + protected T getValue(String key) { - if (entry == null) - throw new JsonSyntaxException("Unknown registry entry '" + entryLocation + "'"); - } - - return forEntry(entry); + return registry.getValue(new ResourceLocation(key)); } - - 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; - } + @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..ae6f4d83d --- /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, @Nullable T registryEntry) { + trigger(player, Collections.singletonList(() -> registryEntry)); + } + + public ITriggerable constructTriggerFor(@Nullable 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; + } + } +}