add cloud type and skybox enums

This commit is contained in:
Sen 2025-05-25 21:32:32 +02:00
parent c0369d14b8
commit e66758cd73
4 changed files with 92 additions and 45 deletions

View file

@ -2,14 +2,11 @@ package common.dimension;
import java.util.List;
import java.util.Map;
import java.util.Set;
import common.biome.Biome;
import common.biome.IBiome;
import common.block.foliage.LeavesType;
import common.collect.Lists;
import common.collect.Maps;
import common.collect.Sets;
import common.init.BlockRegistry;
import common.init.Blocks;
import common.init.MetalType;
@ -19,6 +16,8 @@ import common.nbt.NBTTagList;
import common.nbt.NBTTagString;
import common.util.ExtMath;
import common.util.Vec3;
import common.world.CloudType;
import common.world.SkyboxType;
import common.world.State;
import common.world.Weather;
@ -196,19 +195,8 @@ public abstract class Dimension extends Nameable implements Comparable<Dimension
private static final int[] METAL_SIZES = new int[] {13, 11, 11, 9, 9, 7, 6, 5, 4, 3};
private static final int[] METAL_COUNTS = new int[] {20, 12, 8, 5, 3, 1, -2, -4, -6, -8};
private static final int[] METAL_OFFSETS = new int[] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
private static final int[] METAL_HEIGHTS = new int[] {64, 56, 48, 38, 32, 28, 16, 14, 12, 10};
private static final Set<Character> SAFE_CHARS = Sets.newHashSet();
// private static final FeatureOres[] DEFAULT_ORES;
//
// static {
// List<OreSettings> ores = Lists.<OreSettings>newArrayList();
// OreRegistry.populateDefault(ores);
// DEFAULT_ORES = new FeatureOres[ores.size()];
// for(int z = 0; z < DEFAULT_ORES.length; z++) {
// DEFAULT_ORES[z] = ores.get(z).createGenerator();
// }
// }
private final int id;
private final String name;
@ -223,8 +211,8 @@ public abstract class Dimension extends Nameable implements Comparable<Dimension
private int cloudColor = 0x000000;
private float starBrightness = 0.0f;
private float deepstarBrightness = 0.0f;
private String cloudTexture = "clouds";
private String skyboxTexture = null;
private CloudType cloudTexture = CloudType.NORMAL;
private SkyboxType skyboxTexture = null;
private ColorGenerator starColorFunc = null;
private ColorGenerator deepstarColorFunc = null;
private String fullName; // synced only
@ -291,24 +279,6 @@ public abstract class Dimension extends Nameable implements Comparable<Dimension
private long seed = 0L;
static {
final String safe = "0123456789abcdefghijklmnopqrstuvwxyz_";
for(int z = 0; z < safe.length(); z++) {
SAFE_CHARS.add(safe.charAt(z));
}
}
private static String getSafeFilename(String name, String fallback) {
if(name.length() < 1 || name.length() > 32)
return fallback;
for(int z = 0; z < name.length(); z++) {
if(!SAFE_CHARS.contains(name.charAt(z))) {
return fallback;
}
}
return name;
}
public Dimension(int id, String name) {
this.id = id;
this.name = name;
@ -599,7 +569,7 @@ public abstract class Dimension extends Nameable implements Comparable<Dimension
for(MetalType metal : metals) {
int count = METAL_COUNTS[metal.rarity];
this.ores.add(new Ore(BlockRegistry.getRegisteredBlock(metal.name + "_ore").getState(),
count < 0 ? 0 : count, count < 0 ? (-count) : 0, METAL_SIZES[metal.rarity], 0, METAL_HEIGHTS[metal.rarity], false));
count < 0 ? 0 : count, count < 0 ? (-count) : 0, METAL_SIZES[metal.rarity], METAL_OFFSETS[metal.rarity], METAL_HEIGHTS[metal.rarity], false));
}
return this;
}
@ -688,12 +658,12 @@ public abstract class Dimension extends Nameable implements Comparable<Dimension
return this;
}
public final Dimension setCloudTexture(String value) {
public final Dimension setCloudTexture(CloudType value) {
this.cloudTexture = value;
return this;
}
public final Dimension setSkyBoxTexture(String value) {
public final Dimension setSkyBoxTexture(SkyboxType value) {
this.skyboxTexture = value;
return this;
}
@ -790,11 +760,11 @@ public abstract class Dimension extends Nameable implements Comparable<Dimension
}
public final String getCloudTexture() {
return "textures/world/" + this.cloudTexture + ".png";
return "textures/world/" + this.cloudTexture.getTexture() + ".png";
}
public final String getSkyBoxTexture() {
return this.skyboxTexture == null ? null : ("textures/world/" + this.skyboxTexture + ".png");
return this.skyboxTexture == null ? null : ("textures/world/" + this.skyboxTexture.getTexture() + ".png");
}
public final boolean hasDenseFog() {
@ -1151,9 +1121,9 @@ public abstract class Dimension extends Nameable implements Comparable<Dimension
this.deepstarBrightness = tag.getFloat("DStarBrightness");
this.orbitalPeriod = tag.getLong("OrbitalPeriod");
this.rotationPeriod = tag.getLong("RotationPeriod");
this.cloudTexture = getSafeFilename(tag.getString("CloudTexture"), "clouds");
this.cloudTexture = CloudType.getByName(tag.getString("CloudTexture"));
this.skyboxTexture = tag.hasKey("SkyBoxTexture", 8) ?
getSafeFilename(tag.getString("SkyBoxTexture"), null) : null;
SkyboxType.getByName(tag.getString("SkyBoxTexture")) : null;
if(tag.hasKey("StarColor", 3)) {
this.setStarColor(tag.getInteger("StarColor"));
}
@ -1360,9 +1330,9 @@ public abstract class Dimension extends Nameable implements Comparable<Dimension
tag.setFloat("DStarBrightness", this.deepstarBrightness);
tag.setLong("OrbitalPeriod", this.orbitalPeriod);
tag.setLong("RotationPeriod", this.rotationPeriod);
tag.setString("CloudTexture", this.cloudTexture);
tag.setString("CloudTexture", this.cloudTexture.toString());
if(this.skyboxTexture != null)
tag.setString("SkyBoxTexture", this.skyboxTexture);
tag.setString("SkyBoxTexture", this.skyboxTexture.toString());
if(this.starColorFunc instanceof SingleColorGen) {
tag.setInteger("StarColor", ((SingleColorGen)this.starColorFunc).color);
}

View file

@ -32,6 +32,7 @@ import common.nbt.NBTTagCompound;
import common.nbt.NBTTagList;
import common.rng.Random;
import common.util.PortalType;
import common.world.CloudType;
import common.world.State;
import common.world.Weather;
@ -640,7 +641,7 @@ public abstract class UniverseRegistry {
// .addOre(Blocks.PLACEHOLDER_ore.getState(), 0, 2, 3, 0, 12, false)
, "ovrol");
registerDimension("Der Warp", new Semi(-1, "warp", 0x0c001f, 0x0c001f, 0x190033, 285.0f, 3).setCloudTexture("clouds_dense").setCloudHeight(238.0f)
registerDimension("Der Warp", new Semi(-1, "warp", 0x0c001f, 0x0c001f, 0x190033, 285.0f, 3).setCloudTexture(CloudType.DENSE).setCloudHeight(238.0f)
.setPerlinGen(Blocks.obsidian.getState(), Blocks.lava.getState(), 63)
.setBiome(Biome.CHAOS).enableCavesRavines(Blocks.air.getState()).enableLongCaves().enableMobs().enableSnow()
.addLake(Blocks.water.getState(), null, Blocks.obsidian.getState(), 8, 0, 255, false)

View file

@ -0,0 +1,39 @@
package common.world;
import java.util.Map;
import common.collect.Maps;
public enum CloudType {
NORMAL("normal", "clouds"),
DENSE("dense", "clouds_dense");
private static final Map<String, CloudType> LOOKUP = Maps.newHashMap();
private final String name;
private final String texture;
private CloudType(String name, String texture) {
this.name = name;
this.texture = texture;
}
public String toString() {
return this.name;
}
public String getTexture() {
return this.texture;
}
public static CloudType getByName(String name) {
CloudType type = LOOKUP.get(name.toLowerCase());
return type == null ? NORMAL : type;
}
static {
for(CloudType type : values()) {
LOOKUP.put(type.name, type);
}
}
}

View file

@ -0,0 +1,37 @@
package common.world;
import java.util.Map;
import common.collect.Maps;
public enum SkyboxType {
;
private static final Map<String, SkyboxType> LOOKUP = Maps.newHashMap();
private final String name;
private final String texture;
private SkyboxType(String name, String texture) {
this.name = name;
this.texture = texture;
}
public String toString() {
return this.name;
}
public String getTexture() {
return this.texture;
}
public static SkyboxType getByName(String name) {
return LOOKUP.get(name.toLowerCase());
}
static {
for(SkyboxType type : values()) {
LOOKUP.put(type.name, type);
}
}
}