Some cleanup
This commit is contained in:
parent
a3f2fbe788
commit
6542f2f087
3 changed files with 25 additions and 27 deletions
|
@ -13,16 +13,17 @@ import net.minecraft.fluid.Fluid;
|
|||
import net.minecraft.util.math.AxisAlignedBB;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.registries.ForgeRegistries;
|
||||
|
||||
public class AllTriggers {
|
||||
|
||||
private static final List<CriterionTriggerBase<?>> triggers = new LinkedList<>();
|
||||
|
||||
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 EnumTrigger<InWorldProcessing.Type> FAN_PROCESSING = add(new EnumTrigger<>("fan_processing", InWorldProcessing.Type.class));
|
||||
public static final RegistryTrigger<Fluid> INFINITE_FLUID = add(new RegistryTrigger<>("infinite_fluid", ForgeRegistries.FLUIDS));
|
||||
public static final RegistryTrigger<Block> BRACKET_APPLY_TRIGGER = add(new RegistryTrigger<>("bracket_apply", ForgeRegistries.BLOCKS));
|
||||
public static final EnumTrigger<InWorldProcessing.Type> FAN_PROCESSING = add(new EnumTrigger<>("fan_processing", InWorldProcessing.Type.class));
|
||||
|
||||
public static SimpleTrigger
|
||||
public static final SimpleTrigger
|
||||
ROTATION = simple("rotation"),
|
||||
OVERSTRESSED = simple("overstressed"),
|
||||
SHIFTING_GEARS = simple("shifting_gears"),
|
||||
|
@ -99,9 +100,6 @@ public class AllTriggers {
|
|||
}
|
||||
|
||||
public static List<ServerPlayerEntity> getPlayersInRange(World world, BlockPos pos, int range) {
|
||||
List<ServerPlayerEntity> players =
|
||||
world.getEntitiesWithinAABB(ServerPlayerEntity.class, new AxisAlignedBB(pos).grow(range));
|
||||
return players;
|
||||
return world.getEntitiesWithinAABB(ServerPlayerEntity.class, new AxisAlignedBB(pos).grow(range));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -4,7 +4,6 @@ import mcp.MethodsReturnNonnullByDefault;
|
|||
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;
|
||||
|
@ -14,15 +13,14 @@ import javax.annotation.ParametersAreNonnullByDefault;
|
|||
public class RegistryTrigger<T extends IForgeRegistryEntry<T>> extends StringSerializableTrigger<T> {
|
||||
private final IForgeRegistry<T> registry;
|
||||
|
||||
public RegistryTrigger(String id, Class<T> registryType) {
|
||||
public RegistryTrigger(String id, IForgeRegistry<T> registry) {
|
||||
super(id);
|
||||
this.registry = RegistryManager.ACTIVE.getRegistry(registryType);
|
||||
this.registry = registry;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
protected T getValue(String key) {
|
||||
|
||||
return registry.getValue(new ResourceLocation(key));
|
||||
}
|
||||
|
||||
|
|
|
@ -10,7 +10,6 @@ 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;
|
||||
|
@ -18,7 +17,12 @@ import java.util.stream.StreamSupport;
|
|||
@MethodsReturnNonnullByDefault
|
||||
@ParametersAreNonnullByDefault
|
||||
public abstract class StringSerializableTrigger<T> extends CriterionTriggerBase<StringSerializableTrigger.Instance<T>> {
|
||||
public StringSerializableTrigger(String id) {
|
||||
|
||||
protected String getJsonKey() {
|
||||
return "accepted_entries";
|
||||
}
|
||||
|
||||
protected StringSerializableTrigger(String id) {
|
||||
super(id);
|
||||
}
|
||||
|
||||
|
@ -32,32 +36,30 @@ public abstract class StringSerializableTrigger<T> extends CriterionTriggerBase<
|
|||
}
|
||||
|
||||
public ITriggerable constructTriggerFor(@Nullable T entry) {
|
||||
BiConsumer<ServerPlayerEntity, T> trigger = this::trigger;
|
||||
return player -> trigger.accept(player, entry);
|
||||
return player -> trigger(player, entry);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Instance<T> deserializeInstance(JsonObject json, JsonDeserializationContext context) {
|
||||
if (json.has("accepted_entries")) {
|
||||
JsonArray elements = json.getAsJsonArray("accepted_entries");
|
||||
if (json.has(getJsonKey())) {
|
||||
JsonArray elements = json.getAsJsonArray(getJsonKey());
|
||||
return new Instance<>(this,
|
||||
StreamSupport.stream(elements.spliterator(), false).map(JsonElement::getAsString)
|
||||
.map(rl -> {
|
||||
T entry = getValue(rl);
|
||||
.map(key -> {
|
||||
T entry = getValue(key);
|
||||
if (entry == null)
|
||||
throw new JsonSyntaxException("Unknown entry '" + rl + "'");
|
||||
throw new JsonSyntaxException("Unknown entry '" + key + "'");
|
||||
return entry;
|
||||
}).collect(Collectors.toSet()));
|
||||
}
|
||||
|
||||
return forEntries((T) null);
|
||||
return new Instance<>(this, null);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
abstract protected T getValue(String key);
|
||||
protected abstract T getValue(String key);
|
||||
|
||||
@Nullable
|
||||
abstract protected String getKey(T value);
|
||||
protected abstract String getKey(T value);
|
||||
|
||||
public static class Instance<T> extends CriterionTriggerBase.Instance {
|
||||
|
||||
|
@ -84,7 +86,7 @@ public abstract class StringSerializableTrigger<T> extends CriterionTriggerBase<
|
|||
JsonArray elements = new JsonArray();
|
||||
|
||||
if (entries == null) {
|
||||
jsonobject.add("accepted_entries", elements);
|
||||
jsonobject.add(trigger.getJsonKey(), elements);
|
||||
return jsonobject;
|
||||
}
|
||||
|
||||
|
@ -96,7 +98,7 @@ public abstract class StringSerializableTrigger<T> extends CriterionTriggerBase<
|
|||
elements.add(key);
|
||||
}
|
||||
|
||||
jsonobject.add("accepted_entries", elements);
|
||||
jsonobject.add(trigger.getJsonKey(), elements);
|
||||
return jsonobject;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue