Added an easy way to override aura types based on dimensions via code or config.

In relation to #18
This commit is contained in:
Ellpeck 2018-12-02 13:49:20 +01:00
parent 08fd796fe2
commit 2603c590b1
4 changed files with 47 additions and 11 deletions

View file

@ -1,6 +1,10 @@
package de.ellpeck.naturesaura;
import de.ellpeck.naturesaura.api.NaturesAuraAPI;
import de.ellpeck.naturesaura.api.aura.type.BasicAuraType;
import de.ellpeck.naturesaura.api.aura.type.IAuraType;
import net.minecraft.util.ResourceLocation;
import net.minecraft.world.DimensionType;
import net.minecraftforge.common.config.Config;
import net.minecraftforge.common.config.Config.Comment;
import net.minecraftforge.common.config.Config.RangeDouble;
@ -20,6 +24,9 @@ public final class ModConfig {
@Comment("Additional blocks that several mechanics identify as flowers. Each entry needs to be formatted as modid:block[prop1=value1,...] where block state properties are optional")
public String[] additionalFlowers = new String[0];
@Comment("Additional dimensions that map to Aura types that should be present in them. This is useful if you have a modpack with custom dimensions that should have Aura act similarly to an existing dimension in them. Each entry needs to be formatted as dimension_name->aura_type, where aura_type can be any of naturesaura:overworld, naturesaura:nether and naturesaura:end.")
public String[] auraTypeOverrides = new String[0];
@Comment("The amount of blocks that can be between two Aura Field Creators for them to be connectable and work together")
public int fieldCreatorRange = 10;
}
@ -68,6 +75,17 @@ public final class ModConfig {
} catch (Exception e) {
NaturesAura.LOGGER.warn("Error parsing additionalFlowers", e);
}
try {
for (String s : general.auraTypeOverrides) {
String[] split = s.split("->");
IAuraType type = NaturesAuraAPI.AURA_TYPES.get(new ResourceLocation(split[1]));
if (type instanceof BasicAuraType)
((BasicAuraType) type).addDimensionType(DimensionType.byName(split[0]));
}
} catch (Exception e) {
NaturesAura.LOGGER.warn("Error parsing auraTypeOverrides", e);
}
}
}
}

View file

@ -78,10 +78,10 @@ public final class NaturesAuraAPI {
* easily registered using {@link BasicAuraType#register()}.
*/
public static final Map<ResourceLocation, IAuraType> AURA_TYPES = new HashMap<>();
public static final IAuraType TYPE_OVERWORLD = new BasicAuraType(new ResourceLocation(MOD_ID, "overworld"), DimensionType.OVERWORLD, 0xbef224).register();
public static final IAuraType TYPE_NETHER = new BasicAuraType(new ResourceLocation(MOD_ID, "nether"), DimensionType.NETHER, 0x871c0c).register();
public static final IAuraType TYPE_END = new BasicAuraType(new ResourceLocation(MOD_ID, "end"), DimensionType.THE_END, 0x302624).register();
public static final IAuraType TYPE_OTHER = new BasicAuraType(new ResourceLocation(MOD_ID, "other"), null, 0x2fa8a0).register();
public static final BasicAuraType TYPE_OVERWORLD = new BasicAuraType(new ResourceLocation(MOD_ID, "overworld"), DimensionType.OVERWORLD, 0xbef224, 0).register();
public static final BasicAuraType TYPE_NETHER = new BasicAuraType(new ResourceLocation(MOD_ID, "nether"), DimensionType.NETHER, 0x871c0c, 0).register();
public static final BasicAuraType TYPE_END = new BasicAuraType(new ResourceLocation(MOD_ID, "end"), DimensionType.THE_END, 0x302624, 0).register();
public static final BasicAuraType TYPE_OTHER = new BasicAuraType(new ResourceLocation(MOD_ID, "other"), null, 0x2fa8a0, Integer.MIN_VALUE).register();
/**
* A map of all {@link IDrainSpotEffect} suppliers which are effects that
* happen passively at every spot that Aura has been drained from in the

View file

@ -5,16 +5,22 @@ import net.minecraft.util.ResourceLocation;
import net.minecraft.world.DimensionType;
import net.minecraft.world.World;
import java.util.HashSet;
import java.util.Set;
public class BasicAuraType implements IAuraType {
private final ResourceLocation name;
private final DimensionType dimension;
private final int color;
private final int priority;
private final Set<DimensionType> dimensions = new HashSet<>();
public BasicAuraType(ResourceLocation name, DimensionType dimension, int color) {
public BasicAuraType(ResourceLocation name, DimensionType dimension, int color, int priority) {
this.name = name;
this.dimension = dimension;
this.color = color;
this.priority = priority;
if (dimension != null)
this.dimensions.add(dimension);
}
public BasicAuraType register() {
@ -29,11 +35,20 @@ public class BasicAuraType implements IAuraType {
@Override
public boolean isPresentInWorld(World world) {
return world.provider.getDimensionType() == this.dimension;
return this.dimensions.isEmpty() || this.dimensions.contains(world.provider.getDimensionType());
}
@Override
public int getColor() {
return this.color;
}
@Override
public int getPriority() {
return this.priority;
}
public void addDimensionType(DimensionType type) {
this.dimensions.add(type);
}
}

View file

@ -7,10 +7,11 @@ import net.minecraft.world.World;
public interface IAuraType {
static IAuraType forWorld(World world) {
IAuraType highestType = NaturesAuraAPI.TYPE_OTHER;
for (IAuraType type : NaturesAuraAPI.AURA_TYPES.values())
if (type.isPresentInWorld(world))
return type;
return NaturesAuraAPI.TYPE_OTHER;
if (type.isPresentInWorld(world) && type.getPriority() > highestType.getPriority())
highestType = type;
return highestType;
}
ResourceLocation getName();
@ -18,4 +19,6 @@ public interface IAuraType {
boolean isPresentInWorld(World world);
int getColor();
int getPriority();
}