better fan stream advancement trigger

This commit is contained in:
grimmauld 2021-02-19 16:39:01 +01:00
parent d0357df863
commit 5b65a5d78b
12 changed files with 106 additions and 57 deletions

View File

@ -337,7 +337,7 @@ e8b0a401c10d1ba67ed71ba31bd5f9bc28571b65 assets/create/blockstates/powered_toggl
d06cd9a1101b18d306a786320aab12018b1325d6 assets/create/blockstates/purple_sail.json d06cd9a1101b18d306a786320aab12018b1325d6 assets/create/blockstates/purple_sail.json
92957119abd5fbcca36a113b2a80255fd70fc303 assets/create/blockstates/purple_seat.json 92957119abd5fbcca36a113b2a80255fd70fc303 assets/create/blockstates/purple_seat.json
61035f8afe75ff7bbd291da5d8690bcbebe679eb assets/create/blockstates/purple_valve_handle.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 45877c4d90a7185c2f304edbd67379d800920439 assets/create/blockstates/red_sail.json
da1b08387af7afa0855ee8d040f620c01f20660a assets/create/blockstates/red_seat.json da1b08387af7afa0855ee8d040f620c01f20660a assets/create/blockstates/red_seat.json
722fc77bbf387af8a4016e42cbf9501d2b968881 assets/create/blockstates/red_valve_handle.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 77edd30e3d60b4d492662c673387910f66b5a276 data/create/advancements/dual_extendo_grip.json
04eaf829696d735244c0e4798dd3bdeb26e13a32 data/create/advancements/electron_tube.json 04eaf829696d735244c0e4798dd3bdeb26e13a32 data/create/advancements/electron_tube.json
b78fe4e539fef1b3419f2eb4d1db47cb4a201992 data/create/advancements/extendo_grip.json b78fe4e539fef1b3419f2eb4d1db47cb4a201992 data/create/advancements/extendo_grip.json
4dbbf5f39441fdfe0561022ea7bbaa8e1f9733b7 data/create/advancements/fan.json b1699baaadaac7ebce642c09428519d156e21594 data/create/advancements/fan.json
9e2369129a52ffb4c67907ca5e81e342766f7867 data/create/advancements/fan_lava.json 5aa76cba3b40a1c234ffa84a89ecca630990fc0f data/create/advancements/fan_lava.json
acef16596b7ae82aaf853142d69bcea7094b8173 data/create/advancements/fan_smoke.json 716a9816558300a3652ed8d8d568517017813f5c data/create/advancements/fan_smoke.json
36f72396d1b4ac9a89f4a9139fa10ed659f5954a data/create/advancements/fan_water.json a61eb63d02604e88836519f89f74b252a640d485 data/create/advancements/fan_water.json
69e96e926a4d72e59cc6390c25f064166ddb62d2 data/create/advancements/fist_bump.json 69e96e926a4d72e59cc6390c25f064166ddb62d2 data/create/advancements/fist_bump.json
99ee1bf5390b9a4f2a2419c78f259ff5d2ab9ae9 data/create/advancements/flywheel.json 99ee1bf5390b9a4f2a2419c78f259ff5d2ab9ae9 data/create/advancements/flywheel.json
489c58a0508a2a41cc0849dfb933eb5ac96ef364 data/create/advancements/glass_pipe.json 489c58a0508a2a41cc0849dfb933eb5ac96ef364 data/create/advancements/glass_pipe.json

View File

@ -29,8 +29,8 @@
}, },
{ {
"when": { "when": {
"sticky_south": "true", "axis": "x",
"axis": "x" "sticky_south": "true"
}, },
"apply": { "apply": {
"model": "create:block/radial_chassis_side_x_sticky", "model": "create:block/radial_chassis_side_x_sticky",
@ -39,8 +39,8 @@
}, },
{ {
"when": { "when": {
"sticky_south": "true", "axis": "y",
"axis": "y" "sticky_south": "true"
}, },
"apply": { "apply": {
"model": "create:block/radial_chassis_side_y_sticky" "model": "create:block/radial_chassis_side_y_sticky"
@ -48,8 +48,8 @@
}, },
{ {
"when": { "when": {
"sticky_south": "true", "axis": "z",
"axis": "z" "sticky_south": "true"
}, },
"apply": { "apply": {
"model": "create:block/radial_chassis_side_x_sticky", "model": "create:block/radial_chassis_side_x_sticky",
@ -59,8 +59,8 @@
}, },
{ {
"when": { "when": {
"sticky_south": "false", "axis": "x",
"axis": "x" "sticky_south": "false"
}, },
"apply": { "apply": {
"model": "create:block/radial_chassis_side_x", "model": "create:block/radial_chassis_side_x",
@ -69,8 +69,8 @@
}, },
{ {
"when": { "when": {
"sticky_south": "false", "axis": "y",
"axis": "y" "sticky_south": "false"
}, },
"apply": { "apply": {
"model": "create:block/radial_chassis_side_y" "model": "create:block/radial_chassis_side_y"
@ -78,8 +78,8 @@
}, },
{ {
"when": { "when": {
"sticky_south": "false", "axis": "z",
"axis": "z" "sticky_south": "false"
}, },
"apply": { "apply": {
"model": "create:block/radial_chassis_side_x", "model": "create:block/radial_chassis_side_x",
@ -89,8 +89,8 @@
}, },
{ {
"when": { "when": {
"sticky_west": "true", "axis": "x",
"axis": "x" "sticky_west": "true"
}, },
"apply": { "apply": {
"model": "create:block/radial_chassis_side_x_sticky", "model": "create:block/radial_chassis_side_x_sticky",
@ -99,8 +99,8 @@
}, },
{ {
"when": { "when": {
"sticky_west": "true", "axis": "y",
"axis": "y" "sticky_west": "true"
}, },
"apply": { "apply": {
"model": "create:block/radial_chassis_side_y_sticky", "model": "create:block/radial_chassis_side_y_sticky",
@ -109,8 +109,8 @@
}, },
{ {
"when": { "when": {
"sticky_west": "true", "axis": "z",
"axis": "z" "sticky_west": "true"
}, },
"apply": { "apply": {
"model": "create:block/radial_chassis_side_z_sticky", "model": "create:block/radial_chassis_side_z_sticky",
@ -119,8 +119,8 @@
}, },
{ {
"when": { "when": {
"sticky_west": "false", "axis": "x",
"axis": "x" "sticky_west": "false"
}, },
"apply": { "apply": {
"model": "create:block/radial_chassis_side_x", "model": "create:block/radial_chassis_side_x",
@ -129,8 +129,8 @@
}, },
{ {
"when": { "when": {
"sticky_west": "false", "axis": "y",
"axis": "y" "sticky_west": "false"
}, },
"apply": { "apply": {
"model": "create:block/radial_chassis_side_y", "model": "create:block/radial_chassis_side_y",
@ -139,8 +139,8 @@
}, },
{ {
"when": { "when": {
"sticky_west": "false", "axis": "z",
"axis": "z" "sticky_west": "false"
}, },
"apply": { "apply": {
"model": "create:block/radial_chassis_side_z", "model": "create:block/radial_chassis_side_z",

View File

@ -17,7 +17,12 @@
}, },
"criteria": { "criteria": {
"0": { "0": {
"trigger": "create:fan" "trigger": "create:fan_processing",
"conditions": {
"accepted_entries": [
"NONE"
]
}
} }
}, },
"requirements": [ "requirements": [

View File

@ -17,7 +17,12 @@
}, },
"criteria": { "criteria": {
"0": { "0": {
"trigger": "create:fan_lava" "trigger": "create:fan_processing",
"conditions": {
"accepted_entries": [
"BLASTING"
]
}
} }
}, },
"requirements": [ "requirements": [

View File

@ -17,7 +17,12 @@
}, },
"criteria": { "criteria": {
"0": { "0": {
"trigger": "create:fan_smoke" "trigger": "create:fan_processing",
"conditions": {
"accepted_entries": [
"SMOKING"
]
}
} }
}, },
"requirements": [ "requirements": [

View File

@ -17,7 +17,12 @@
}, },
"criteria": { "criteria": {
"0": { "0": {
"trigger": "create:fan_water" "trigger": "create:fan_processing",
"conditions": {
"accepted_entries": [
"SPLASHING"
]
}
} }
}, },
"requirements": [ "requirements": [

View File

@ -114,9 +114,10 @@ public class AirCurrent {
entityDistance -= .5f; entityDistance -= .5f;
InWorldProcessing.Type processingType = getSegmentAt((float) entityDistance); InWorldProcessing.Type processingType = getSegmentAt((float) entityDistance);
if (processingType == null) { if (entity instanceof ServerPlayerEntity)
if (entity instanceof ServerPlayerEntity) AllTriggers.triggerFor(AllTriggers.FAN_PROCESSING.constructTriggerFor(processingType), (PlayerEntity) entity);
AllTriggers.triggerFor(AllTriggers.FAN, (PlayerEntity) entity);
if (processingType == null || processingType == Type.NONE) {
continue; continue;
} }
@ -139,24 +140,18 @@ public class AirCurrent {
entity.setFire(10); entity.setFire(10);
entity.attackEntityFrom(damageSourceLava, 4); entity.attackEntityFrom(damageSourceLava, 4);
} }
if (entity instanceof ServerPlayerEntity)
AllTriggers.triggerFor(AllTriggers.FAN_LAVA, (PlayerEntity) entity);
break; break;
case SMOKING: case SMOKING:
if (!entity.isImmuneToFire()) { if (!entity.isImmuneToFire()) {
entity.setFire(2); entity.setFire(2);
entity.attackEntityFrom(damageSourceFire, 2); entity.attackEntityFrom(damageSourceFire, 2);
} }
if (entity instanceof ServerPlayerEntity)
AllTriggers.triggerFor(AllTriggers.FAN_SMOKE, (PlayerEntity) entity);
break; break;
case SPLASHING: case SPLASHING:
if (entity instanceof EndermanEntity || entity.getType() == EntityType.SNOW_GOLEM if (entity instanceof EndermanEntity || entity.getType() == EntityType.SNOW_GOLEM
|| entity.getType() == EntityType.BLAZE) { || entity.getType() == EntityType.BLAZE) {
entity.attackEntityFrom(DamageSource.DROWN, 2); entity.attackEntityFrom(DamageSource.DROWN, 2);
} }
if (entity instanceof ServerPlayerEntity)
AllTriggers.triggerFor(AllTriggers.FAN_WATER, (PlayerEntity) entity);
if (!entity.isBurning()) if (!entity.isBurning())
break; break;
entity.extinguish(); entity.extinguish();
@ -193,7 +188,7 @@ public class AirCurrent {
AirCurrentSegment currentSegment = new AirCurrentSegment(); AirCurrentSegment currentSegment = new AirCurrentSegment();
segments.clear(); segments.clear();
currentSegment.startOffset = 0; currentSegment.startOffset = 0;
InWorldProcessing.Type type = null; InWorldProcessing.Type type = Type.NONE;
int limit = (int) (maxDistance + .5f); int limit = (int) (maxDistance + .5f);
int searchStart = pushing ? 0 : limit; int searchStart = pushing ? 0 : limit;
@ -203,7 +198,7 @@ public class AirCurrent {
for (int i = searchStart; i * searchStep <= searchEnd * searchStep; i += searchStep) { for (int i = searchStart; i * searchStep <= searchEnd * searchStep; i += searchStep) {
BlockPos currentPos = start.offset(direction, i); BlockPos currentPos = start.offset(direction, i);
InWorldProcessing.Type newType = InWorldProcessing.Type.byBlock(world, currentPos); InWorldProcessing.Type newType = InWorldProcessing.Type.byBlock(world, currentPos);
if (newType != null) if (newType != Type.NONE)
type = newType; type = newType;
if (currentSegment.type != type || currentSegment.startOffset == 0) { if (currentSegment.type != type || currentSegment.startOffset == 0) {
currentSegment.endOffset = i; currentSegment.endOffset = i;
@ -341,7 +336,7 @@ public class AirCurrent {
continue; continue;
return airCurrentSegment.type; return airCurrentSegment.type;
} }
return null; return InWorldProcessing.Type.NONE;
} }
public static class AirCurrentSegment { public static class AirCurrentSegment {

View File

@ -58,7 +58,7 @@ public class InWorldProcessing {
public static SplashingInv splashingInv = new SplashingInv(); public static SplashingInv splashingInv = new SplashingInv();
public enum Type { public enum Type {
SMOKING, BLASTING, SPLASHING SMOKING, BLASTING, SPLASHING, NONE
; ;
@ -74,7 +74,7 @@ public class InWorldProcessing {
return Type.SMOKING; return Type.SMOKING;
if (block == Blocks.LAVA || getHeatLevelOf(blockState).isAtLeast(BlazeBurnerBlock.HeatLevel.FADING)) if (block == Blocks.LAVA || getHeatLevelOf(blockState).isAtLeast(BlazeBurnerBlock.HeatLevel.FADING))
return Type.BLASTING; return Type.BLASTING;
return null; return Type.NONE;
} }
} }

View File

@ -6,6 +6,7 @@ import java.util.Set;
import java.util.function.Consumer; import java.util.function.Consumer;
import java.util.function.Supplier; import java.util.function.Supplier;
import com.simibubi.create.content.logistics.InWorldProcessing;
import net.minecraft.fluid.FlowingFluid; import net.minecraft.fluid.FlowingFluid;
import net.minecraft.fluid.Fluid; import net.minecraft.fluid.Fluid;
import net.minecraft.fluid.Fluids; import net.minecraft.fluid.Fluids;
@ -125,19 +126,19 @@ public class AllAdvancements implements IDataProvider {
.register(t, id + ":press"); .register(t, id + ":press");
Advancement fan = advancement("fan", AllBlocks.ENCASED_FAN.get(), TaskType.NORMAL).withParent(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"); .register(t, id + ":fan");
Advancement fan_lava = advancement("fan_lava", Items.LAVA_BUCKET, TaskType.NORMAL).withParent(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"); .register(t, id + ":fan_lava");
Advancement fan_smoke = advancement("fan_smoke", Items.CAMPFIRE, TaskType.NORMAL).withParent(fan) 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"); .register(t, id + ":fan_smoke");
Advancement fan_water = advancement("fan_water", Items.WATER_BUCKET, TaskType.NORMAL).withParent(fan) 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"); .register(t, id + ":fan_water");
Advancement rose_quartz = Advancement rose_quartz =

View File

@ -4,6 +4,7 @@ import java.util.LinkedList;
import java.util.List; import java.util.List;
import java.util.function.Predicate; import java.util.function.Predicate;
import com.simibubi.create.content.logistics.InWorldProcessing;
import net.minecraft.advancements.CriteriaTriggers; import net.minecraft.advancements.CriteriaTriggers;
import net.minecraft.block.Block; import net.minecraft.block.Block;
import net.minecraft.entity.player.PlayerEntity; import net.minecraft.entity.player.PlayerEntity;
@ -19,6 +20,7 @@ public class AllTriggers {
public static RegistryTrigger<Fluid> INFINITE_FLUID = add(new RegistryTrigger<>("infinite_fluid", Fluid.class)); public static RegistryTrigger<Fluid> INFINITE_FLUID = add(new RegistryTrigger<>("infinite_fluid", Fluid.class));
public static RegistryTrigger<Block> BRACKET_APPLY_TRIGGER = add(new RegistryTrigger<>("bracket_apply", Block.class)); public static RegistryTrigger<Block> BRACKET_APPLY_TRIGGER = add(new RegistryTrigger<>("bracket_apply", Block.class));
public static EnumTrigger<InWorldProcessing.Type> FAN_PROCESSING = add(new EnumTrigger<>("fan_processing", InWorldProcessing.Type.class));
public static SimpleTrigger public static SimpleTrigger
ROTATION = simple("rotation"), ROTATION = simple("rotation"),
@ -47,10 +49,6 @@ public class AllTriggers {
PLACE_TUNNEL = simple("place_tunnel"), PLACE_TUNNEL = simple("place_tunnel"),
CONNECT_TUNNEL = simple("connect_tunnel"), CONNECT_TUNNEL = simple("connect_tunnel"),
UPWARD_CHUTE = simple("upward_chute"), 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 = simple("belt_funnel"),
BELT_FUNNEL_KISS = simple("belt_funnel_kiss"), BELT_FUNNEL_KISS = simple("belt_funnel_kiss"),
CLOCKWORK_BEARING = simple("clockwork_bearing"), CLOCKWORK_BEARING = simple("clockwork_bearing"),

View File

@ -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<T extends Enum<T>> extends StringSerializableTrigger<T> {
private final Class<T> reference;
public EnumTrigger(String id, Class<T> 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();
}
}

View File

@ -27,11 +27,11 @@ public abstract class StringSerializableTrigger<T> extends CriterionTriggerBase<
return new Instance<>(this, entries == null ? null : Sets.newHashSet(entries)); 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)); trigger(player, Collections.singletonList(() -> registryEntry));
} }
public ITriggerable constructTriggerFor(T entry) { public ITriggerable constructTriggerFor(@Nullable T entry) {
BiConsumer<ServerPlayerEntity, T> trigger = this::trigger; BiConsumer<ServerPlayerEntity, T> trigger = this::trigger;
return player -> trigger.accept(player, entry); return player -> trigger.accept(player, entry);
} }