mirror of
https://github.com/Ellpeck/NaturesAura.git
synced 2024-11-22 11:53:29 +01:00
Added an easy way to override aura types based on dimensions via code or config.
In relation to #18
This commit is contained in:
parent
08fd796fe2
commit
2603c590b1
4 changed files with 47 additions and 11 deletions
|
@ -1,6 +1,10 @@
|
||||||
package de.ellpeck.naturesaura;
|
package de.ellpeck.naturesaura;
|
||||||
|
|
||||||
import de.ellpeck.naturesaura.api.NaturesAuraAPI;
|
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;
|
||||||
import net.minecraftforge.common.config.Config.Comment;
|
import net.minecraftforge.common.config.Config.Comment;
|
||||||
import net.minecraftforge.common.config.Config.RangeDouble;
|
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")
|
@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];
|
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")
|
@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;
|
public int fieldCreatorRange = 10;
|
||||||
}
|
}
|
||||||
|
@ -68,6 +75,17 @@ public final class ModConfig {
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
NaturesAura.LOGGER.warn("Error parsing additionalFlowers", 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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -78,10 +78,10 @@ public final class NaturesAuraAPI {
|
||||||
* easily registered using {@link BasicAuraType#register()}.
|
* easily registered using {@link BasicAuraType#register()}.
|
||||||
*/
|
*/
|
||||||
public static final Map<ResourceLocation, IAuraType> AURA_TYPES = new HashMap<>();
|
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 BasicAuraType TYPE_OVERWORLD = new BasicAuraType(new ResourceLocation(MOD_ID, "overworld"), DimensionType.OVERWORLD, 0xbef224, 0).register();
|
||||||
public static final IAuraType TYPE_NETHER = new BasicAuraType(new ResourceLocation(MOD_ID, "nether"), DimensionType.NETHER, 0x871c0c).register();
|
public static final BasicAuraType TYPE_NETHER = new BasicAuraType(new ResourceLocation(MOD_ID, "nether"), DimensionType.NETHER, 0x871c0c, 0).register();
|
||||||
public static final IAuraType TYPE_END = new BasicAuraType(new ResourceLocation(MOD_ID, "end"), DimensionType.THE_END, 0x302624).register();
|
public static final BasicAuraType TYPE_END = new BasicAuraType(new ResourceLocation(MOD_ID, "end"), DimensionType.THE_END, 0x302624, 0).register();
|
||||||
public static final IAuraType TYPE_OTHER = new BasicAuraType(new ResourceLocation(MOD_ID, "other"), null, 0x2fa8a0).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
|
* A map of all {@link IDrainSpotEffect} suppliers which are effects that
|
||||||
* happen passively at every spot that Aura has been drained from in the
|
* happen passively at every spot that Aura has been drained from in the
|
||||||
|
|
|
@ -5,16 +5,22 @@ import net.minecraft.util.ResourceLocation;
|
||||||
import net.minecraft.world.DimensionType;
|
import net.minecraft.world.DimensionType;
|
||||||
import net.minecraft.world.World;
|
import net.minecraft.world.World;
|
||||||
|
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
public class BasicAuraType implements IAuraType {
|
public class BasicAuraType implements IAuraType {
|
||||||
|
|
||||||
private final ResourceLocation name;
|
private final ResourceLocation name;
|
||||||
private final DimensionType dimension;
|
|
||||||
private final int color;
|
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.name = name;
|
||||||
this.dimension = dimension;
|
|
||||||
this.color = color;
|
this.color = color;
|
||||||
|
this.priority = priority;
|
||||||
|
if (dimension != null)
|
||||||
|
this.dimensions.add(dimension);
|
||||||
}
|
}
|
||||||
|
|
||||||
public BasicAuraType register() {
|
public BasicAuraType register() {
|
||||||
|
@ -29,11 +35,20 @@ public class BasicAuraType implements IAuraType {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isPresentInWorld(World world) {
|
public boolean isPresentInWorld(World world) {
|
||||||
return world.provider.getDimensionType() == this.dimension;
|
return this.dimensions.isEmpty() || this.dimensions.contains(world.provider.getDimensionType());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getColor() {
|
public int getColor() {
|
||||||
return this.color;
|
return this.color;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getPriority() {
|
||||||
|
return this.priority;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addDimensionType(DimensionType type) {
|
||||||
|
this.dimensions.add(type);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,10 +7,11 @@ import net.minecraft.world.World;
|
||||||
public interface IAuraType {
|
public interface IAuraType {
|
||||||
|
|
||||||
static IAuraType forWorld(World world) {
|
static IAuraType forWorld(World world) {
|
||||||
|
IAuraType highestType = NaturesAuraAPI.TYPE_OTHER;
|
||||||
for (IAuraType type : NaturesAuraAPI.AURA_TYPES.values())
|
for (IAuraType type : NaturesAuraAPI.AURA_TYPES.values())
|
||||||
if (type.isPresentInWorld(world))
|
if (type.isPresentInWorld(world) && type.getPriority() > highestType.getPriority())
|
||||||
return type;
|
highestType = type;
|
||||||
return NaturesAuraAPI.TYPE_OTHER;
|
return highestType;
|
||||||
}
|
}
|
||||||
|
|
||||||
ResourceLocation getName();
|
ResourceLocation getName();
|
||||||
|
@ -18,4 +19,6 @@ public interface IAuraType {
|
||||||
boolean isPresentInWorld(World world);
|
boolean isPresentInWorld(World world);
|
||||||
|
|
||||||
int getColor();
|
int getColor();
|
||||||
|
|
||||||
|
int getPriority();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue