mirror of
https://github.com/Creators-of-Create/Create.git
synced 2024-11-10 20:11:35 +01:00
Rework Bracket trigger to now be a registry trigger based on base block
This commit is contained in:
parent
d9aa912796
commit
3f9ee09953
14 changed files with 116 additions and 75 deletions
|
@ -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
|
||||
|
|
|
@ -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"
|
||||
|
|
|
@ -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": [
|
||||
|
|
|
@ -19,7 +19,9 @@
|
|||
"0": {
|
||||
"trigger": "create:infinite_fluid",
|
||||
"conditions": {
|
||||
"registry_entry": "create:chocolate"
|
||||
"accepted_entries": [
|
||||
"create:chocolate"
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
|
|
|
@ -19,7 +19,9 @@
|
|||
"0": {
|
||||
"trigger": "create:infinite_fluid",
|
||||
"conditions": {
|
||||
"registry_entry": "minecraft:lava"
|
||||
"accepted_entries": [
|
||||
"minecraft:lava"
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
|
|
|
@ -19,7 +19,9 @@
|
|||
"0": {
|
||||
"trigger": "create:infinite_fluid",
|
||||
"conditions": {
|
||||
"registry_entry": "minecraft:water"
|
||||
"accepted_entries": [
|
||||
"minecraft:water"
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
|
|
|
@ -25,7 +25,9 @@
|
|||
"1": {
|
||||
"trigger": "create:kinetic_block",
|
||||
"conditions": {
|
||||
"registry_entry": "create:mechanical_mixer"
|
||||
"accepted_entries": [
|
||||
"create:mechanical_mixer"
|
||||
]
|
||||
}
|
||||
},
|
||||
"2": {
|
||||
|
|
|
@ -25,7 +25,7 @@ public class FluidPipeTileEntity extends SmartTileEntity {
|
|||
public void addBehaviours(List<TileEntityBehaviour> 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) {
|
||||
|
|
|
@ -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<BracketedTileEntityBehaviour> TYPE = new BehaviourType<>();
|
||||
|
@ -28,10 +26,10 @@ public class BracketedTileEntityBehaviour extends TileEntityBehaviour {
|
|||
private boolean reRender;
|
||||
|
||||
private Predicate<BlockState> pred;
|
||||
private Function<BlockState, SimpleTrigger> trigger;
|
||||
private Function<BlockState, ITriggerable> trigger;
|
||||
|
||||
public BracketedTileEntityBehaviour(SmartTileEntity te) {
|
||||
this(te, Predicates.alwaysTrue());
|
||||
this(te, state -> true);
|
||||
}
|
||||
|
||||
public BracketedTileEntityBehaviour(SmartTileEntity te, Predicate<BlockState> pred) {
|
||||
|
@ -40,7 +38,7 @@ public class BracketedTileEntityBehaviour extends TileEntityBehaviour {
|
|||
bracket = Optional.empty();
|
||||
}
|
||||
|
||||
public BracketedTileEntityBehaviour withTrigger(Function<BlockState, SimpleTrigger> trigger) {
|
||||
public BracketedTileEntityBehaviour withTrigger(Function<BlockState, ITriggerable> trigger) {
|
||||
this.trigger = trigger;
|
||||
return this;
|
||||
}
|
||||
|
|
|
@ -23,7 +23,7 @@ public class SimpleKineticTileEntity extends KineticTileEntity {
|
|||
public void addBehaviours(List<TileEntityBehaviour> 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);
|
||||
}
|
||||
|
||||
|
|
|
@ -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<Block> isPowered(Block block) {
|
||||
return AllTriggers.KINETIC_BLOCK.forEntry(block);
|
||||
return AllTriggers.KINETIC_BLOCK.forEntries(block);
|
||||
}
|
||||
|
||||
public RegistryTrigger.Instance<Fluid> isInfinite(FlowingFluid fluid) {
|
||||
return AllTriggers.INFINITE_FLUID.forEntry(fluid.getStillFluid());
|
||||
return AllTriggers.INFINITE_FLUID.forEntries(fluid.getStillFluid());
|
||||
}
|
||||
|
||||
public InventoryChangeTrigger.Instance itemGathered(IItemProvider itemprovider) {
|
||||
|
|
|
@ -19,6 +19,7 @@ public class AllTriggers {
|
|||
|
||||
public static RegistryTrigger<Block> KINETIC_BLOCK = add(new RegistryTrigger<>("kinetic_block", Block.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 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"),
|
||||
|
|
|
@ -77,7 +77,7 @@ public abstract class CriterionTriggerBase<T extends CriterionTriggerBase.Instan
|
|||
}
|
||||
}
|
||||
|
||||
protected abstract static class Instance extends CriterionInstance {
|
||||
public abstract static class Instance extends CriterionInstance {
|
||||
|
||||
public Instance(ResourceLocation idIn) {
|
||||
super(idIn);
|
||||
|
|
|
@ -1,13 +1,11 @@
|
|||
package com.simibubi.create.foundation.advancement;
|
||||
|
||||
import com.google.gson.JsonDeserializationContext;
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.google.gson.JsonSyntaxException;
|
||||
import com.google.common.collect.Sets;
|
||||
import com.google.gson.*;
|
||||
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;
|
||||
|
||||
|
@ -15,7 +13,11 @@ 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
|
||||
|
@ -27,56 +29,75 @@ public class RegistryTrigger<T extends IForgeRegistryEntry<T>> extends Criterion
|
|||
this.registryType = registryType;
|
||||
}
|
||||
|
||||
public Instance<T> forEntry(@Nullable T registryEntry) {
|
||||
return new Instance<>(getId(), registryEntry);
|
||||
@SafeVarargs
|
||||
public final Instance<T> 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<T> 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<ServerPlayerEntity, T> trigger = this::trigger;
|
||||
return player -> trigger.accept(player, entry);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Instance<T> deserializeInstance(JsonObject json, JsonDeserializationContext context) {
|
||||
if (json.has("accepted_entries")) {
|
||||
JsonArray elements = json.getAsJsonArray("accepted_entries");
|
||||
IForgeRegistry<T> 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<T extends IForgeRegistryEntry<T>> extends CriterionTriggerBase.Instance {
|
||||
|
||||
@Nullable
|
||||
private final T entry;
|
||||
private final Set<T> entries;
|
||||
|
||||
public Instance(ResourceLocation id, @Nullable T registryEntry) {
|
||||
public Instance(ResourceLocation id, @Nullable Set<T> registryEntries) {
|
||||
super(id);
|
||||
entry = registryEntry;
|
||||
entries = registryEntries;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean test(@Nullable List<Supplier<Object>> 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;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue