Skip to content

Commit f72e28d

Browse files
authored
Merge pull request #43 from dshadowwolf/v3
QOL Fixes and API Updates
2 parents c0eed12 + b8e5e23 commit f72e28d

File tree

10 files changed

+73
-212
lines changed

10 files changed

+73
-212
lines changed

src/main/java/com/mcmoddev/orespawn/OreSpawn.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import com.mcmoddev.orespawn.api.SpawnEntry;
1212
import com.mcmoddev.orespawn.commands.AddOreCommand;
1313
import com.mcmoddev.orespawn.commands.ClearChunkCommand;
14+
import com.mcmoddev.orespawn.commands.WriteConfigsCommand;
1415
import com.mcmoddev.orespawn.commands.DumpBiomesCommand;
1516
import com.mcmoddev.orespawn.data.Config;
1617
import com.mcmoddev.orespawn.api.SpawnLogic;
@@ -105,5 +106,6 @@ public void onServerStarting(FMLServerStartingEvent ev) {
105106
ev.registerServerCommand(new ClearChunkCommand());
106107
ev.registerServerCommand(new DumpBiomesCommand());
107108
ev.registerServerCommand(new AddOreCommand());
109+
ev.registerServerCommand(new WriteConfigsCommand());
108110
}
109111
}

src/main/java/com/mcmoddev/orespawn/api/DimensionLogic.java

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,19 @@
88
import com.google.gson.JsonObject;
99

1010
public interface DimensionLogic {
11-
DimensionLogic addOre(IBlockState state, int size, int variation, float frequency, int minHeight, int maxHeight, Biome... biomes);
12-
13-
DimensionLogic addOre(IBlockState state, int size, int variation, int frequency, int minHeight, int maxHeight, Biome... biomes);
14-
15-
Collection<SpawnEntry> getEntries();
11+
DimensionLogic addOre(IBlockState state, int size, int variation, float frequency, int minHeight, int maxHeight, Biome... biomes);
1612

17-
SpawnLogic end();
13+
DimensionLogic addOre(IBlockState state, int size, int variation, int frequency, int minHeight, int maxHeight, Biome... biomes);
14+
15+
Collection<SpawnEntry> getEntries();
16+
17+
SpawnLogic end();
1818

1919
DimensionLogic addOre(IBlockState state, int size, int variation, float frequency, int minHeight, int maxHeight,
2020
Biome[] array, IFeature featureGen, IBlockState blockRep);
21-
21+
22+
DimensionLogic addOre(IBlockState state, int size, int variation, float frequency, int minHeight, int maxHeight,
23+
Biome[] array, String featureName, IBlockState blockRep);
24+
2225
DimensionLogic addOre(IBlockState state, JsonObject parameters, Biome[] array, IFeature featureGen, IBlockState blockRep);
2326
}

src/main/java/com/mcmoddev/orespawn/api/OreSpawnAPI.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,6 @@ public interface OreSpawnAPI {
1919
OreSpawnWorldGen getWorldGenerator();
2020

2121
void registerSpawns();
22+
23+
void addFeatureGenerator(String name, String className);
2224
}

src/main/java/com/mcmoddev/orespawn/api/SpawnEntry.java

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,6 @@
1010
public interface SpawnEntry {
1111
IBlockState getState();
1212

13-
int getSize();
14-
15-
int getVariation();
16-
17-
float getFrequency();
18-
19-
int getMinHeight();
20-
21-
int getMaxHeight();
22-
2313
List<Biome> getBiomes();
2414

2515
IFeature getFeatureGen();
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package com.mcmoddev.orespawn.commands;
2+
3+
import com.mcmoddev.orespawn.OreSpawn;
4+
5+
import net.minecraft.command.CommandBase;
6+
import net.minecraft.command.CommandException;
7+
import net.minecraft.command.ICommandSender;
8+
import net.minecraft.server.MinecraftServer;
9+
10+
public class WriteConfigsCommand extends CommandBase {
11+
12+
@Override
13+
public String getName() {
14+
return "osSaveConfigs";
15+
}
16+
17+
@Override
18+
public String getUsage(ICommandSender sender) {
19+
return "/osSaveConfigs";
20+
}
21+
22+
@Override
23+
public void execute(MinecraftServer server, ICommandSender sender, String[] args) throws CommandException {
24+
OreSpawn.writer.writeSpawnEntries();
25+
}
26+
27+
}

src/main/java/com/mcmoddev/orespawn/data/FeatureRegistry.java

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,13 +64,21 @@ public boolean hasFeature(String name) {
6464
public boolean hasFeature(IFeature feature) {
6565
return featuresInverse.containsKey(feature);
6666
}
67+
6768

6869
public void addFeature(JsonObject entry) {
69-
IFeature feature = getInstance(entry.get("class").getAsString());
70+
this.addFeature(entry.get("name").getAsString(), entry.get("class").getAsString());
71+
}
72+
73+
public void addFeature(String name, String className) {
74+
IFeature feature = getInstance(className);
7075
if( feature != null ) {
71-
features.put(entry.get("name").getAsString(), feature);
72-
featuresInverse.put(feature, entry.get("name").getAsString());
73-
}
76+
// the feature might already be registered
77+
if( !features.containsKey(name) ) {
78+
features.put(name, feature);
79+
featuresInverse.put(feature, name);
80+
}
81+
}
7482
}
7583

7684
private IFeature getInstance(String className) {

src/main/java/com/mcmoddev/orespawn/impl/DimensionLogicImpl.java

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -26,22 +26,12 @@ public DimensionLogicImpl(SpawnLogic parent) {
2626

2727
@Override
2828
public DimensionLogic addOre(IBlockState state, int size, int variation, float frequency, int minHeight, int maxHeight, Biome... biomes) {
29-
if( state.getBlock() != null ) {
30-
this.logic.add(new SpawnEntryImpl(state, size, variation, frequency, minHeight, maxHeight, biomes));
31-
} else {
32-
OreSpawn.LOGGER.warn("Trying to register a non-existent block!");
33-
}
34-
return this;
29+
return this.addOre(state, size, variation, frequency, minHeight, maxHeight, biomes, "default", null);
3530
}
3631

3732
@Override
3833
public DimensionLogic addOre(IBlockState state, int size, int variation, int frequency, int minHeight, int maxHeight, Biome... biomes) {
39-
if( state.getBlock() != null ) {
40-
this.logic.add(new SpawnEntryImpl(state, size, variation, (float)frequency, minHeight, maxHeight, biomes));
41-
} else {
42-
OreSpawn.LOGGER.warn("Trying to register a non-existent block!");
43-
}
44-
return this;
34+
return this.addOre(state, size, variation, (float)frequency, minHeight, maxHeight, biomes);
4535
}
4636

4737
@Override
@@ -57,12 +47,13 @@ public SpawnLogic end() {
5747
@Override
5848
public DimensionLogic addOre(IBlockState state, int size, int variation, float frequency, int minHeight, int maxHeight,
5949
Biome[] biomes, IFeature featureGen, IBlockState blockRep) {
60-
if( state.getBlock() != null ) {
61-
this.logic.add(new SpawnEntryImpl(state, size, variation, frequency, minHeight, maxHeight, biomes, featureGen, blockRep));
62-
} else {
63-
OreSpawn.LOGGER.warn("Trying to register a non-existent block!");
64-
}
65-
return this;
50+
JsonObject p = new JsonObject();
51+
p.addProperty("size", size);
52+
p.addProperty("variation", variation);
53+
p.addProperty("frequency", frequency);
54+
p.addProperty("minHeight", minHeight);
55+
p.addProperty("maxHeight", maxHeight);
56+
return this.addOre(state, p, biomes, featureGen, blockRep);
6657
}
6758

6859
@Override
@@ -75,4 +66,10 @@ public DimensionLogic addOre(IBlockState state, JsonObject parameters, Biome[] b
7566
}
7667
return this;
7768
}
69+
70+
@Override
71+
public DimensionLogic addOre(IBlockState state, int size, int variation, float frequency, int minHeight,
72+
int maxHeight, Biome[] biomes, String featureName, IBlockState blockRep) {
73+
return this.addOre(state, size, variation, frequency, minHeight, maxHeight, biomes, OreSpawn.FEATURES.getFeature(featureName), blockRep);
74+
}
7875
}

src/main/java/com/mcmoddev/orespawn/impl/OreSpawnImpl.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,4 +61,9 @@ public void registerSpawns() {
6161
public OreSpawnWorldGen getWorldGenerator() {
6262
return worldGenerator;
6363
}
64+
65+
@Override
66+
public void addFeatureGenerator(String name, String className) {
67+
OreSpawn.FEATURES.addFeature(name, className);
68+
}
6469
}

src/main/java/com/mcmoddev/orespawn/impl/SpawnEntryImpl.java

Lines changed: 0 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
import com.google.gson.JsonObject;
88
import com.mcmoddev.orespawn.api.IFeature;
99
import com.mcmoddev.orespawn.api.SpawnEntry;
10-
import com.mcmoddev.orespawn.impl.features.DefaultFeatureGenerator;
1110

1211
import net.minecraft.block.state.IBlockState;
1312
import net.minecraft.world.biome.Biome;
@@ -18,55 +17,6 @@ public class SpawnEntryImpl implements SpawnEntry {
1817
private final List<Biome> biomes;
1918
private final IFeature generator;
2019
private final IBlockState blockRep;
21-
private final static String sz = "size";
22-
private final static String var = "variation";
23-
private final static String freq = "frequency";
24-
private final static String mny = "minHeight";
25-
private final static String mxy = "maxHeight";
26-
27-
public SpawnEntryImpl(IBlockState state, int size, int variation, float frequency, int minHeight, int maxHeight, Biome[] biomes) {
28-
this.paramStore = new JsonObject();
29-
this.paramStore.addProperty(sz, size);
30-
this.paramStore.addProperty(var, variation);
31-
this.paramStore.addProperty(freq, frequency);
32-
this.paramStore.addProperty(mny, minHeight);
33-
this.paramStore.addProperty(mxy, maxHeight);
34-
this.state = state;
35-
this.blockRep = null;
36-
37-
if( biomes == null || biomes.length == 0 ) {
38-
this.biomes = Collections.<Biome>emptyList();;
39-
} else {
40-
this.biomes = new ArrayList<>();
41-
for( Biome b : biomes ) {
42-
this.biomes.add(b);
43-
}
44-
}
45-
this.generator = new DefaultFeatureGenerator();
46-
// OreSpawn.LOGGER.fatal("OreSpawnAPI: registering block "+state.getBlock()+" for generation");
47-
}
48-
49-
public SpawnEntryImpl(IBlockState state, int size, int variation, float frequency, int minHeight, int maxHeight,
50-
Biome[] biomes, IFeature featureGen, IBlockState blockRep) {
51-
this.paramStore = new JsonObject();
52-
this.paramStore.addProperty(sz, size);
53-
this.paramStore.addProperty(var, variation);
54-
this.paramStore.addProperty(freq, frequency);
55-
this.paramStore.addProperty(mny, minHeight);
56-
this.paramStore.addProperty(mxy, maxHeight);
57-
this.generator = featureGen;
58-
this.blockRep = blockRep;
59-
this.state = state;
60-
61-
if( biomes == null || biomes.length == 0 ) {
62-
this.biomes = Collections.<Biome>emptyList();
63-
} else {
64-
this.biomes = new ArrayList<>();
65-
for( Biome b : biomes ) {
66-
this.biomes.add(b);
67-
}
68-
}
69-
}
7020

7121
public SpawnEntryImpl(IBlockState state, JsonObject parameters, Biome[] biomes, IFeature featureGen,
7222
IBlockState blockRep) {
@@ -90,31 +40,6 @@ public IBlockState getState() {
9040
return this.state;
9141
}
9242

93-
@Override
94-
public int getSize() {
95-
return this.paramStore.get(sz).getAsInt();
96-
}
97-
98-
@Override
99-
public int getVariation() {
100-
return this.paramStore.get(var).getAsInt();
101-
}
102-
103-
@Override
104-
public float getFrequency() {
105-
return this.paramStore.get(freq).getAsFloat();
106-
}
107-
108-
@Override
109-
public int getMinHeight() {
110-
return this.paramStore.get(mny).getAsInt();
111-
}
112-
113-
@Override
114-
public int getMaxHeight() {
115-
return this.paramStore.get(mxy).getAsInt();
116-
}
117-
11843
@Override
11944
public List<Biome> getBiomes() {
12045
return Collections.unmodifiableList(this.biomes);

src/main/java/com/mcmoddev/orespawn/json/OS2Writer.java

Lines changed: 0 additions & 98 deletions
This file was deleted.

0 commit comments

Comments
 (0)