Skip to content

Commit 597ba14

Browse files
authored
Merge pull request #46 from dshadowwolf/new-api-proposal
New api proposal
2 parents 08e8e11 + 55d904b commit 597ba14

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

59 files changed

+2260
-957
lines changed

CHANGELOG.txt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,14 @@
1+
#Version 3.1.0:
2+
Minor Version number bumped because of major internal changes
3+
New Annotation-based plugin system
4+
New API for new plugin system
5+
Update JSON config format to version 1.1 to allow for new feature
6+
Implement BiomeDictionary support
7+
Implement Whitelisting and Blacklisting support for Biomes
8+
Ensure that resources stored in JAR's can be copied out to the config directory for loading and parsing
9+
Add the ability to specify parameters for the default feature generator to the addore command
10+
11+
#Version 3.0.0:
112
Ported to 1.11.2
213
Complete rewrite of internals for better stability
314
Change of JSON config format (See Wiki for details!)

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

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,8 @@
88
import java.util.Random;
99
import java.util.Set;
1010

11-
import com.mcmoddev.orespawn.api.OreSpawnAPI;
12-
import com.mcmoddev.orespawn.api.SpawnEntry;
13-
import com.mcmoddev.orespawn.api.SpawnLogic;
11+
import com.mcmoddev.orespawn.api.os3.BuilderLogic;
12+
import com.mcmoddev.orespawn.api.os3.SpawnBuilder;
1413
import com.mcmoddev.orespawn.data.Config;
1514
import com.mcmoddev.orespawn.data.Constants;
1615

@@ -48,18 +47,18 @@ public void onChunkSave(ChunkDataEvent.Save ev) {
4847
NBTTagList features = new NBTTagList();
4948
features.appendTag( new NBTTagString("orespawn:default"));
5049

51-
for( Entry<String, SpawnLogic> ent : OreSpawn.API.getAllSpawnLogic().entrySet() ) {
52-
SpawnLogic log = ent.getValue();
50+
for( Entry<String, BuilderLogic> ent : OreSpawn.API.getSpawns().entrySet() ) {
51+
BuilderLogic log = ent.getValue();
5352
if( log.getAllDimensions().containsKey(ev.getWorld().provider.getDimension()) ) {
54-
Collection<SpawnEntry> vals = log.getDimension(ev.getWorld().provider.getDimension()).getEntries();
55-
for( SpawnEntry s : vals ) {
56-
ores.appendTag( new NBTTagString( s.getState().getBlock().getRegistryName().toString()) );
53+
Collection<SpawnBuilder> vals = log.getDimension(ev.getWorld().provider.getDimension()).getAllSpawns();
54+
for( SpawnBuilder s : vals ) {
55+
ores.appendTag( new NBTTagString( s.getOres().get(0).getOre().getBlock().getRegistryName().toString() ) );
5756
}
5857
}
59-
if( log.getAllDimensions().containsKey(OreSpawnAPI.DIMENSION_WILDCARD) ) {
60-
Collection<SpawnEntry> vals = log.getDimension(OreSpawnAPI.DIMENSION_WILDCARD).getEntries();
61-
for( SpawnEntry s : vals ) {
62-
ores.appendTag( new NBTTagString( s.getState().getBlock().getRegistryName().toString()) );
58+
if( log.getAllDimensions().containsKey(OreSpawn.API.dimensionWildcard()) ) {
59+
Collection<SpawnBuilder> vals = log.getDimension(OreSpawn.API.dimensionWildcard()).getAllSpawns();
60+
for( SpawnBuilder s : vals ) {
61+
ores.appendTag( new NBTTagString( s.getOres().get(0).getOre().getBlock().getRegistryName().toString() ) );
6362
}
6463
}
6564
}
@@ -108,12 +107,12 @@ public void onChunkLoad(ChunkDataEvent.Load ev) {
108107

109108
private int countOres(int dim) {
110109
int acc = 0;
111-
for( Entry<String, SpawnLogic> sL : OreSpawn.API.getAllSpawnLogic().entrySet() ) {
110+
for( Entry<String, BuilderLogic> sL : OreSpawn.API.getSpawns().entrySet() ) {
112111
if( sL.getValue().getAllDimensions().containsKey(dim) ) {
113-
acc += sL.getValue().getAllDimensions().get(dim).getEntries().size();
112+
acc += sL.getValue().getAllDimensions().get(dim).getAllSpawns().size();
114113
}
115-
if( sL.getValue().getAllDimensions().containsKey(OreSpawnAPI.DIMENSION_WILDCARD) ) {
116-
acc += sL.getValue().getAllDimensions().get(OreSpawnAPI.DIMENSION_WILDCARD).getEntries().size();
114+
if( sL.getValue().getAllDimensions().containsKey(OreSpawn.API.dimensionWildcard()) ) {
115+
acc += sL.getValue().getAllDimensions().get(OreSpawn.API.dimensionWildcard()).getAllSpawns().size();
117116
}
118117
}
119118
return acc;

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

Lines changed: 21 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -2,28 +2,24 @@
22

33
import com.mcmoddev.orespawn.data.Constants;
44
import com.mcmoddev.orespawn.data.FeatureRegistry;
5-
import com.mcmoddev.orespawn.impl.OreSpawnImpl;
5+
import com.mcmoddev.orespawn.impl.os3.OS3APIImpl;
66
import com.mcmoddev.orespawn.json.OS1Reader;
77
import com.mcmoddev.orespawn.json.OS2Reader;
88
import com.mcmoddev.orespawn.json.OS3Reader;
99
import com.mcmoddev.orespawn.json.OS3Writer;
10-
import com.mcmoddev.orespawn.api.OreSpawnAPI;
11-
import com.mcmoddev.orespawn.api.SpawnEntry;
1210
import com.mcmoddev.orespawn.commands.AddOreCommand;
1311
import com.mcmoddev.orespawn.commands.ClearChunkCommand;
1412
import com.mcmoddev.orespawn.commands.WriteConfigsCommand;
1513
import com.mcmoddev.orespawn.commands.DumpBiomesCommand;
1614
import com.mcmoddev.orespawn.data.Config;
17-
import com.mcmoddev.orespawn.api.SpawnLogic;
15+
import com.mcmoddev.orespawn.api.os3.OS3API;
16+
import com.mcmoddev.orespawn.api.os3.SpawnBuilder;
17+
import com.mcmoddev.orespawn.api.plugin.PluginLoader;
1818

1919
import java.nio.file.Paths;
2020
import java.util.HashMap;
2121
import java.util.List;
2222
import java.util.Map;
23-
import java.util.Map.Entry;
24-
25-
import com.google.common.base.Function;
26-
import com.google.common.base.Optional;
2723

2824
import org.apache.logging.log4j.LogManager;
2925
import org.apache.logging.log4j.Logger;
@@ -34,7 +30,6 @@
3430
import net.minecraftforge.fml.common.Mod.EventHandler;
3531
import net.minecraftforge.fml.common.Mod.Instance;
3632
import net.minecraftforge.fml.common.event.FMLInitializationEvent;
37-
import net.minecraftforge.fml.common.event.FMLInterModComms;
3833
import net.minecraftforge.fml.common.event.FMLPostInitializationEvent;
3934
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;
4035
import net.minecraftforge.fml.common.event.FMLServerStartingEvent;
@@ -53,18 +48,24 @@
5348
public class OreSpawn {
5449
@Instance
5550
public static OreSpawn INSTANCE = null;
56-
public final static Logger LOGGER = LogManager.getFormatterLogger(Constants.MODID);
57-
public final static OreSpawnAPI API = new OreSpawnImpl();
51+
public static final Logger LOGGER = LogManager.getFormatterLogger(Constants.MODID);
52+
public static final OS3API API = new OS3APIImpl();
5853
public static final OS3Writer writer = new OS3Writer();
5954
public static final EventHandlers eventHandlers = new EventHandlers();
6055
public static final FeatureRegistry FEATURES = new FeatureRegistry();
61-
private String OS1ConfigPath;
62-
public static final Map<Integer, List<SpawnEntry>> spawns = new HashMap<>();
56+
private String os1ConfigPath;
57+
protected static final Map<Integer, List<SpawnBuilder>> spawns = new HashMap<>();
58+
59+
public static Map<Integer, List<SpawnBuilder>> getSpawns() {
60+
return spawns;
61+
}
6362

6463
@EventHandler
6564
public void preInit(FMLPreInitializationEvent ev) {
6665
Config.loadConfig();
6766

67+
PluginLoader.INSTANCE.load(ev);
68+
6869
if( Config.getBoolean(Constants.RETROGEN_KEY) ) {
6970
MinecraftForge.EVENT_BUS.register(eventHandlers);
7071
}
@@ -73,15 +74,17 @@ public void preInit(FMLPreInitializationEvent ev) {
7374
MinecraftForge.ORE_GEN_BUS.register(eventHandlers);
7475
}
7576

76-
this.OS1ConfigPath = Paths.get(ev.getSuggestedConfigurationFile().toPath().getParent().toString(),"orespawn").toString();
77-
FMLInterModComms.sendFunctionMessage("orespawn", "api", "com.mcmoddev.orespawn.data.VanillaOrespawn");
77+
this.os1ConfigPath = Paths.get(ev.getSuggestedConfigurationFile().toPath().getParent().toString(),"orespawn").toString();
7878
}
7979

8080
@EventHandler
8181
public void init(FMLInitializationEvent ev) {
82-
OS1Reader.loadEntries(Paths.get(OS1ConfigPath));
83-
OS2Reader.loadEntries();
82+
PluginLoader.INSTANCE.register();
83+
// we prefer the OS3 version of files
84+
// but will take OS2 and OS1 versions - in that order
8485
OS3Reader.loadEntries();
86+
OS2Reader.loadEntries();
87+
OS1Reader.loadEntries(Paths.get(os1ConfigPath));
8588
API.registerSpawns();
8689
}
8790

@@ -90,17 +93,7 @@ public void postInit(FMLPostInitializationEvent ev) {
9093
writer.writeSpawnEntries();
9194
Config.saveConfig();
9295
}
93-
94-
@EventHandler
95-
public void onIMC(FMLInterModComms.IMCEvent event) {
96-
event.getMessages().stream().filter(message -> "api".equalsIgnoreCase(message.key)).forEach(message -> {
97-
Optional<Function<OreSpawnAPI, SpawnLogic>> value = message.getFunctionValue(OreSpawnAPI.class, SpawnLogic.class);
98-
if (OreSpawn.API.getSpawnLogic(message.getSender()) == null && value.isPresent()) {
99-
OreSpawn.API.registerSpawnLogic(message.getSender(), value.get().apply(OreSpawn.API));
100-
}
101-
});
102-
}
103-
96+
10497
@EventHandler
10598
public void onServerStarting(FMLServerStartingEvent ev) {
10699
ev.registerServerCommand(new ClearChunkCommand());
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package com.mcmoddev.orespawn.api;
2+
3+
import com.google.common.collect.ImmutableList;
4+
5+
import com.mcmoddev.orespawn.util.Collectors2;
6+
import net.minecraft.world.biome.Biome;
7+
import net.minecraftforge.fml.common.registry.ForgeRegistries;
8+
9+
public interface BiomeLocation {
10+
boolean matches(Biome biome);
11+
12+
default ImmutableList<Biome> getBiomes() {
13+
return ForgeRegistries.BIOMES.getValues().stream().filter(this::matches).collect(Collectors2.toImmutableList());
14+
}
15+
}

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

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

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,16 @@
55
import com.google.gson.JsonObject;
66

77
import net.minecraft.block.state.IBlockState;
8+
import net.minecraft.util.math.ChunkPos;
89
import net.minecraft.world.World;
910
import net.minecraft.world.chunk.IChunkGenerator;
1011
import net.minecraft.world.chunk.IChunkProvider;
1112

1213
public interface IFeature {
13-
void generate(Random random, int chunkX, int chunkZ, World world, IChunkGenerator chunkGenerator,
14+
void generate(ChunkPos pos, World world, IChunkGenerator chunkGenerator,
1415
IChunkProvider chunkProvider, JsonObject parameters, IBlockState block, IBlockState blockReplace );
16+
17+
void setRandom(Random rand);
18+
19+
JsonObject getDefaultParameters();
1520
}

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

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

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

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

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

Lines changed: 0 additions & 9 deletions
This file was deleted.
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package com.mcmoddev.orespawn.api.os3;
2+
3+
import javax.annotation.Nonnull;
4+
5+
import com.mcmoddev.orespawn.api.BiomeLocation;
6+
7+
import net.minecraft.world.biome.Biome;
8+
9+
public interface BiomeBuilder {
10+
// should have left this for @pau101 as he's the genius behind the BiomeLocation stuff
11+
// but I'm on a roll :)
12+
13+
BiomeBuilder whitelistBiome( @Nonnull Biome biome );
14+
BiomeBuilder whitelistBiomeByName( @Nonnull String biomeName );
15+
BiomeBuilder whitelistBiomeByDictionary( @Nonnull String biomeDictionaryName );
16+
BiomeBuilder blacklistBiome( @Nonnull Biome biome );
17+
BiomeBuilder blacklistBiomeByName( @Nonnull String biomeName );
18+
BiomeBuilder blacklistBiomeByDictionary( @Nonnull String biomeDictionaryName );
19+
BiomeBuilder setFromBiomeLocation( @Nonnull BiomeLocation biomes );
20+
21+
BiomeLocation getBiomes();
22+
}

0 commit comments

Comments
 (0)