diff --git a/.gitignore b/.gitignore index 494a860..62f1a10 100644 --- a/.gitignore +++ b/.gitignore @@ -6,8 +6,7 @@ # Sources !/src -!/mc17 -!/mc18 +!/minecraft # github !/.gitignore diff --git a/build.gradle b/build.gradle index 9d1035f..921d44f 100644 --- a/build.gradle +++ b/build.gradle @@ -1,25 +1,25 @@ plugins { id "java" - id "nova.gradle" version "0.2.3" + id "nova.gradle" version "0.2.6" id "maven-publish" id "com.jfrog.artifactory" version "3.1.1" } - apply from: "https://raw.githubusercontent.com/NOVA-Team/NOVA-Gradle/master/shared-scripts/java.gradle" -dependencies novaApi("0.1.0-SNAPSHOT") +dependencies { + compile nova(nova_version) +} nova { wrappers { "17" { - wrapper "nova.wrapper.mc1710:NovaWrapper-MC1.7.10:0.1-SNAPSHOT:deobf" - runtime project(":mc17") + wrapper "nova.core:NOVA-Core-Wrapper-MC1.7:$nova_version" + runtime project(":minecraft:1.7") } - "18" { - wrapper "nova.wrapper.mc18:NovaWrapper-MC1.8:0.1-SNAPSHOT:deobf" - runtime project(":mc18") + wrapper "nova.core:NOVA-Core-Wrapper-MC1.8:$nova_version" + runtime project(":minecraft:1.8") } } } diff --git a/gradle.properties b/gradle.properties index facb242..d2695d7 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,6 +1,6 @@ version = 0.0.1-SNAPSHOT group = nova.worldgen -novaVersion = 0.1.0-SNAPSHOT +nova_version = 0.1.0-SNAPSHOT packaging = jar info.inceptionYear = 2015 diff --git a/minecraft/.gitignore b/minecraft/.gitignore new file mode 100644 index 0000000..a4c6e69 --- /dev/null +++ b/minecraft/.gitignore @@ -0,0 +1,7 @@ +/* + +!/build.gradle +!/.gitignore + +!/1.8 +!/1.7 diff --git a/minecraft/1.7/.gitignore b/minecraft/1.7/.gitignore new file mode 100644 index 0000000..85be317 --- /dev/null +++ b/minecraft/1.7/.gitignore @@ -0,0 +1,17 @@ +# Ignore All +/* + +# Sources +!/src + +# github +!/.gitignore +!/README.md + +# gradle +!/build.gradle +!/build.properties +!/settings.gradle +!/gradle.properties +!/gradlew* +!/gradle diff --git a/mc17/build.gradle b/minecraft/1.7/build.gradle similarity index 84% rename from mc17/build.gradle rename to minecraft/1.7/build.gradle index e8f4a49..7cd5aee 100644 --- a/mc17/build.gradle +++ b/minecraft/1.7/build.gradle @@ -24,7 +24,7 @@ publishing { main(MavenPublication) { from components.java - artifactId "NovaWorldgen-Wrapper-MC1.7.10" + artifactId "NOVA-Worldgen-Wrapper-MC1.7.10" artifact sourcesJar artifact javadocJar @@ -56,8 +56,8 @@ minecraft { dependencies { compile rootProject - compile group: "nova.core", name: "NovaCore", version: property("nova.version"), changing: true - compile "nova.wrapper.mc1710:NovaWrapper-MC1.7.10:0.1-SNAPSHOT:deobf" + compile group: "nova.core", name: "NOVA-Core", version: property("nova_version"), changing: true + compile group: "nova.core", name: "NOVA-Core-Wrapper-MC1.7", version: property("nova_version"), classifier: "deobf", changing: true } processResources { diff --git a/mc17/gradle.properties b/minecraft/1.7/gradle.properties similarity index 68% rename from mc17/gradle.properties rename to minecraft/1.7/gradle.properties index 480e6c0..1ab3696 100644 --- a/mc17/gradle.properties +++ b/minecraft/1.7/gradle.properties @@ -1,9 +1,6 @@ -version = 0.0.1-SNAPSHOT -group = nova.worldgen.wrapper.mc17 - -nova.version = 0.1.0-SNAPSHOT minecraft.version = 1.7.10 forge.version = 10.13.4.1448-1.7.10 +forgeGradleVersion = 1.2-SNAPSHOT packaging = jar info.inceptionYear = 2015 diff --git a/minecraft/1.7/src/main/java/nova/worldgen/wrapper/mc/forge/v1_7_10/depmodules/MCWorldgenModule.java b/minecraft/1.7/src/main/java/nova/worldgen/wrapper/mc/forge/v1_7_10/depmodules/MCWorldgenModule.java new file mode 100644 index 0000000..2c20428 --- /dev/null +++ b/minecraft/1.7/src/main/java/nova/worldgen/wrapper/mc/forge/v1_7_10/depmodules/MCWorldgenModule.java @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2017 NOVA, All rights reserved. + * This library is free software, licensed under GNU Lesser General Public License version 3 + * + * This file is part of NOVA. + * + * NOVA is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * NOVA is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with NOVA. If not, see . + */ + +package nova.worldgen.wrapper.mc.forge.v1_7_10.depmodules; + +import nova.worldgen.world.WorldInfo; +import nova.worldgen.wrapper.mc.forge.v1_7_10.wrapper.world.MCWorldInfo; +import se.jbee.inject.bind.BinderModule; +import se.jbee.inject.util.Scoped; + +/** + * @author ExE Boss + */ +public class MCWorldgenModule extends BinderModule { + + @Override + protected void declare() { + per(Scoped.APPLICATION).bind(WorldInfo.class).to(MCWorldInfo.class); + } +} diff --git a/minecraft/1.7/src/main/java/nova/worldgen/wrapper/mc/forge/v1_7_10/launch/NovaWorldgenWrapper.java b/minecraft/1.7/src/main/java/nova/worldgen/wrapper/mc/forge/v1_7_10/launch/NovaWorldgenWrapper.java new file mode 100644 index 0000000..868dd23 --- /dev/null +++ b/minecraft/1.7/src/main/java/nova/worldgen/wrapper/mc/forge/v1_7_10/launch/NovaWorldgenWrapper.java @@ -0,0 +1,59 @@ +/* + * Copyright (c) 2015 NOVA, All rights reserved. + * This library is free software, licensed under GNU Lesser General Public License version 3 + * + * This file is part of NOVA. + * + * NOVA is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * NOVA is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with NOVA. If not, see . + */ + +package nova.worldgen.wrapper.mc.forge.v1_7_10.launch; + +import cpw.mods.fml.common.event.FMLPreInitializationEvent; +import cpw.mods.fml.common.registry.GameRegistry; +import nova.core.loader.Mod; +import nova.core.wrapper.mc.forge.v17.launcher.ForgeLoadable; +import nova.internal.worldgen.depmodules.WorldgenModule; +import nova.worldgen.WorldgenManager; +import nova.worldgen.wrapper.mc.forge.v1_7_10.depmodules.MCWorldgenModule; +import nova.worldgen.wrapper.mc.forge.v1_7_10.wrapper.world.MCWorldInfo; +import nova.worldgen.wrapper.mc.forge.v1_7_10.wrapper.world.forward.FWWorldGenerator; + +/** + * + * @author ExE Boss + */ +@Mod(id = NovaWorldgenWrapper.id, name = NovaWorldgenWrapper.name, version = NovaWorldgenWrapper.version, modules = { MCWorldgenModule.class, WorldgenModule.class }, novaVersion = "0.0.1") +public class NovaWorldgenWrapper implements ForgeLoadable { + + public static final String version = "0.0.1"; + public static final String id = "nova-worldgen-wrapper"; + public static final String name = "NOVA Worldgen"; + + public final WorldgenManager worldgenManager; + + public FWWorldGenerator worldGenerator; + + public NovaWorldgenWrapper(WorldgenManager worldgenManager) { + this.worldgenManager = worldgenManager; + ((MCWorldInfo)this.worldgenManager.getWorldInfo()).init(worldgenManager); + this.worldGenerator = new FWWorldGenerator(this.worldgenManager); + } + + @Override + public void preInit(FMLPreInitializationEvent evt) { + GameRegistry.registerWorldGenerator(this.worldGenerator, 0); + worldgenManager.init(); + } +} diff --git a/minecraft/1.7/src/main/java/nova/worldgen/wrapper/mc/forge/v1_7_10/wrapper/world/MCWorldInfo.java b/minecraft/1.7/src/main/java/nova/worldgen/wrapper/mc/forge/v1_7_10/wrapper/world/MCWorldInfo.java new file mode 100644 index 0000000..f7e0359 --- /dev/null +++ b/minecraft/1.7/src/main/java/nova/worldgen/wrapper/mc/forge/v1_7_10/wrapper/world/MCWorldInfo.java @@ -0,0 +1,55 @@ +/* + * Copyright (c) 2017 NOVA, All rights reserved. + * This library is free software, licensed under GNU Lesser General Public License version 3 + * + * This file is part of NOVA. + * + * NOVA is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * NOVA is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with NOVA. If not, see . + */ + +package nova.worldgen.wrapper.mc.forge.v1_7_10.wrapper.world; + +import nova.core.util.registry.Registry; +import nova.core.util.shape.Cuboid; +import nova.worldgen.WorldgenManager; +import nova.worldgen.ore.Ore; +import nova.worldgen.world.WorldInfo; + +/** + * @author ExE Boss + */ +public class MCWorldInfo extends WorldInfo { + + private WorldgenManager worldgenManager; + + public void init(WorldgenManager worldgenManager) { + this.worldgenManager = worldgenManager; + } + + @Override + public Cuboid getWorldDimmensions() { + return new Cuboid(Double.NEGATIVE_INFINITY, 0, Double.NEGATIVE_INFINITY, + Double.POSITIVE_INFINITY, 256, Double.POSITIVE_INFINITY); + } + + @Override + public Cuboid getWorldGenerationUnitDimmensions() { + return new Cuboid(0, 0, 0, 16, 16, 16); + } + + @Override + public Registry getOreGenerationRegistry() { + return worldgenManager.registry.stream().filter(gen -> gen instanceof Ore).map(ore -> (Ore) ore).collect(Registry::new, Registry::register, (r1, r2) -> r2.forEach(r1::register)); + } +} diff --git a/minecraft/1.7/src/main/java/nova/worldgen/wrapper/mc/forge/v1_7_10/wrapper/world/forward/FWWorldGenerator.java b/minecraft/1.7/src/main/java/nova/worldgen/wrapper/mc/forge/v1_7_10/wrapper/world/forward/FWWorldGenerator.java new file mode 100644 index 0000000..c73558d --- /dev/null +++ b/minecraft/1.7/src/main/java/nova/worldgen/wrapper/mc/forge/v1_7_10/wrapper/world/forward/FWWorldGenerator.java @@ -0,0 +1,97 @@ +/* + * Copyright (c) 2015 NOVA, All rights reserved. + * This library is free software, licensed under GNU Lesser General Public License version 3 + * + * This file is part of NOVA. + * + * NOVA is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * NOVA is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with NOVA. If not, see . + */ + +package nova.worldgen.wrapper.mc.forge.v1_7_10.wrapper.world.forward; + +import cpw.mods.fml.common.IWorldGenerator; +import net.minecraft.block.Block; +import net.minecraft.world.World; +import net.minecraft.world.chunk.IChunkProvider; +import net.minecraft.world.gen.feature.WorldGenMinable; +import nova.internal.core.Game; +import nova.worldgen.WorldgenManager; +import nova.worldgen.event.WorldgenEvent; +import nova.worldgen.generator.CustomGenerator; +import nova.worldgen.ore.Ore; +import nova.worldgen.ore.OreHeight; + +import java.util.Arrays; +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Random; +import java.util.Set; +import java.util.stream.Collectors; + +/** + * + * @author ExE Boss + */ +public class FWWorldGenerator implements IWorldGenerator { + + private final Map oreGen; + private final Set customGenerators; + private final WorldgenManager worldgenManager; + + public FWWorldGenerator(WorldgenManager worldgenManager) { + this.worldgenManager = worldgenManager; + this.oreGen = new HashMap<>(); + this.customGenerators = new HashSet<>(); + Game.events().on(WorldgenEvent.Register.class).bind(evt -> { + if (evt.generable instanceof Ore) { + this.oreGen.put((Ore) evt.generable, new WorldGenMinable(((Block)Game.natives().toNative(((Ore)evt.generable).block.build())), (int) Math.round(((Ore)evt.generable).clusterSize * 5))); + } else if (evt.generable instanceof CustomGenerator) { + this.customGenerators.add((CustomGenerator) evt.generable); + } + }); + } + + @Override + public void generate(Random random, int chunkX, int chunkZ, World world, IChunkProvider chunkGenerator, IChunkProvider chunkProvider) { + double worldScale = world.provider.getAverageGroundLevel() / 64D; + this.oreGen.forEach((ore, generator) -> { + double baseCount = 12 * ore.rarity * worldScale; + int count = (int) Math.round(random.nextGaussian() * Math.sqrt(baseCount) + baseCount); + for(int i = 0; i < count; i++) { + // OreHeight Values: (when world.provider.getAverageGroundLevel() == 64) + // SURFACE = 60 (55-65) + // UNDERSURFACE = 50 (45-55) + // DEEP = 40 (35-45) + // DEEPER = 30 (25-35) + // DEEPERER = 20 (15-25) + // REALLYDEEP = 10 (5-15) + + List oreHeightList = Arrays.stream(OreHeight.values()).filter(ore.oreLayers::allows).collect(Collectors.toList()); + if (oreHeightList.isEmpty()) return; + + OreHeight height = oreHeightList.get(random.nextInt(oreHeightList.size())); + double yAdd = (OreHeight.values().length - height.ordinal() - 1) * (10 * worldScale) + (5 * worldScale); + + int x = chunkX + random.nextInt(16); + int y = (int) Math.round(yAdd + (random.nextDouble() * 10 * worldScale)); + int z = chunkZ + random.nextInt(16); + + generator.generate(world, random, x, y, z); + } + }); + this.customGenerators.forEach(generator -> generator.generate(random, chunkX, chunkZ, worldScale, Game.natives().toNova(world), this.worldgenManager.getWorldInfo())); + } +} diff --git a/minecraft/1.8/.gitignore b/minecraft/1.8/.gitignore new file mode 100644 index 0000000..85be317 --- /dev/null +++ b/minecraft/1.8/.gitignore @@ -0,0 +1,17 @@ +# Ignore All +/* + +# Sources +!/src + +# github +!/.gitignore +!/README.md + +# gradle +!/build.gradle +!/build.properties +!/settings.gradle +!/gradle.properties +!/gradlew* +!/gradle diff --git a/mc18/build.gradle b/minecraft/1.8/build.gradle similarity index 84% rename from mc18/build.gradle rename to minecraft/1.8/build.gradle index bebb8fc..51f6204 100644 --- a/mc18/build.gradle +++ b/minecraft/1.8/build.gradle @@ -24,7 +24,7 @@ publishing { main(MavenPublication) { from components.java - artifactId "NovaWorldgen-Wrapper-MC1.8" + artifactId "NOVA-Worldgen-Wrapper-MC1.8" artifact sourcesJar artifact javadocJar @@ -57,8 +57,8 @@ minecraft { dependencies { compile rootProject - compile group: "nova.core", name: "NovaCore", version: property("nova.version"), changing: true - compile "nova.wrapper.mc18:NovaWrapper-MC1.8:0.1-SNAPSHOT:deobf" + compile group: "nova.core", name: "NOVA-Core", version: property("nova_version"), changing: true + compile group: "nova.core", name: "NOVA-Core-Wrapper-MC1.8", version: property("nova_version"), classifier: "deobf", changing: true } processResources { diff --git a/mc18/gradle.properties b/minecraft/1.8/gradle.properties similarity index 56% rename from mc18/gradle.properties rename to minecraft/1.8/gradle.properties index 3554efd..ac2a829 100644 --- a/mc18/gradle.properties +++ b/minecraft/1.8/gradle.properties @@ -1,9 +1,6 @@ -version = 0.0.1-SNAPSHOT -group = nova.worldgen.wrapper.mc18 - -nova.version = 0.1.0-SNAPSHOT minecraft.version = 1.8 -forge.version = 11.14.3.1446 +forge.version = 11.14.3.1491 +forgeGradleVersion = 1.2-SNAPSHOT packaging = jar info.inceptionYear = 2015 diff --git a/minecraft/1.8/src/main/java/nova/worldgen/wrapper/mc/forge/v1_8/depmodules/MCWorldgenModule.java b/minecraft/1.8/src/main/java/nova/worldgen/wrapper/mc/forge/v1_8/depmodules/MCWorldgenModule.java new file mode 100644 index 0000000..694de48 --- /dev/null +++ b/minecraft/1.8/src/main/java/nova/worldgen/wrapper/mc/forge/v1_8/depmodules/MCWorldgenModule.java @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2017 NOVA, All rights reserved. + * This library is free software, licensed under GNU Lesser General Public License version 3 + * + * This file is part of NOVA. + * + * NOVA is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * NOVA is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with NOVA. If not, see . + */ +package nova.worldgen.wrapper.mc.forge.v1_8.depmodules; + +import nova.worldgen.world.WorldInfo; +import nova.worldgen.wrapper.mc.forge.v1_8.wrapper.world.MCWorldInfo; +import se.jbee.inject.bind.BinderModule; +import se.jbee.inject.util.Scoped; + +/** + * @author ExE Boss + */ +public class MCWorldgenModule extends BinderModule { + + @Override + protected void declare() { + per(Scoped.APPLICATION).bind(WorldInfo.class).to(MCWorldInfo.class); + } +} diff --git a/minecraft/1.8/src/main/java/nova/worldgen/wrapper/mc/forge/v1_8/launch/NovaWorldgenWrapper.java b/minecraft/1.8/src/main/java/nova/worldgen/wrapper/mc/forge/v1_8/launch/NovaWorldgenWrapper.java new file mode 100644 index 0000000..d298d43 --- /dev/null +++ b/minecraft/1.8/src/main/java/nova/worldgen/wrapper/mc/forge/v1_8/launch/NovaWorldgenWrapper.java @@ -0,0 +1,59 @@ +/* + * Copyright (c) 2015 NOVA, All rights reserved. + * This library is free software, licensed under GNU Lesser General Public License version 3 + * + * This file is part of NOVA. + * + * NOVA is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * NOVA is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with NOVA. If not, see . + */ + +package nova.worldgen.wrapper.mc.forge.v1_8.launch; + +import net.minecraftforge.fml.common.event.FMLPreInitializationEvent; +import net.minecraftforge.fml.common.registry.GameRegistry; +import nova.core.loader.Mod; +import nova.core.wrapper.mc.forge.v18.launcher.ForgeLoadable; +import nova.internal.worldgen.depmodules.WorldgenModule; +import nova.worldgen.WorldgenManager; +import nova.worldgen.wrapper.mc.forge.v1_8.depmodules.MCWorldgenModule; +import nova.worldgen.wrapper.mc.forge.v1_8.wrapper.world.MCWorldInfo; +import nova.worldgen.wrapper.mc.forge.v1_8.wrapper.world.forward.FWWorldGenerator; + +/** + * + * @author ExE Boss + */ +@Mod(id = NovaWorldgenWrapper.id, name = NovaWorldgenWrapper.name, version = NovaWorldgenWrapper.version, modules = { MCWorldgenModule.class, WorldgenModule.class }, novaVersion = "0.0.1") +public class NovaWorldgenWrapper implements ForgeLoadable { + + public static final String version = "0.0.1"; + public static final String id = "nova-worldgen-wrapper"; + public static final String name = "NOVA Worldgen"; + + public final WorldgenManager worldgenManager; + + public FWWorldGenerator worldGenerator; + + public NovaWorldgenWrapper(WorldgenManager worldgenManager) { + this.worldgenManager = worldgenManager; + ((MCWorldInfo)this.worldgenManager.getWorldInfo()).init(worldgenManager); + this.worldGenerator = new FWWorldGenerator(this.worldgenManager); + } + + @Override + public void preInit(FMLPreInitializationEvent evt) { + GameRegistry.registerWorldGenerator(this.worldGenerator, 0); + worldgenManager.init(); + } +} diff --git a/minecraft/1.8/src/main/java/nova/worldgen/wrapper/mc/forge/v1_8/wrapper/world/MCWorldInfo.java b/minecraft/1.8/src/main/java/nova/worldgen/wrapper/mc/forge/v1_8/wrapper/world/MCWorldInfo.java new file mode 100644 index 0000000..10095e7 --- /dev/null +++ b/minecraft/1.8/src/main/java/nova/worldgen/wrapper/mc/forge/v1_8/wrapper/world/MCWorldInfo.java @@ -0,0 +1,55 @@ +/* + * Copyright (c) 2017 NOVA, All rights reserved. + * This library is free software, licensed under GNU Lesser General Public License version 3 + * + * This file is part of NOVA. + * + * NOVA is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * NOVA is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with NOVA. If not, see . + */ + +package nova.worldgen.wrapper.mc.forge.v1_8.wrapper.world; + +import nova.core.util.registry.Registry; +import nova.core.util.shape.Cuboid; +import nova.worldgen.WorldgenManager; +import nova.worldgen.ore.Ore; +import nova.worldgen.world.WorldInfo; + +/** + * @author ExE Boss + */ +public class MCWorldInfo extends WorldInfo { + + private WorldgenManager worldgenManager; + + public void init(WorldgenManager worldgenManager) { + this.worldgenManager = worldgenManager; + } + + @Override + public Cuboid getWorldDimmensions() { + return new Cuboid(Double.NEGATIVE_INFINITY, 0, Double.NEGATIVE_INFINITY, + Double.POSITIVE_INFINITY, 256, Double.POSITIVE_INFINITY); + } + + @Override + public Cuboid getWorldGenerationUnitDimmensions() { + return new Cuboid(0, 0, 0, 16, 16, 16); + } + + @Override + public Registry getOreGenerationRegistry() { + return worldgenManager.registry.stream().filter(gen -> gen instanceof Ore).map(ore -> (Ore) ore).collect(Registry::new, Registry::register, (r1, r2) -> r2.forEach(r1::register)); + } +} diff --git a/minecraft/1.8/src/main/java/nova/worldgen/wrapper/mc/forge/v1_8/wrapper/world/forward/FWWorldGenerator.java b/minecraft/1.8/src/main/java/nova/worldgen/wrapper/mc/forge/v1_8/wrapper/world/forward/FWWorldGenerator.java new file mode 100644 index 0000000..a70f272 --- /dev/null +++ b/minecraft/1.8/src/main/java/nova/worldgen/wrapper/mc/forge/v1_8/wrapper/world/forward/FWWorldGenerator.java @@ -0,0 +1,98 @@ +/* + * Copyright (c) 2015 NOVA, All rights reserved. + * This library is free software, licensed under GNU Lesser General Public License version 3 + * + * This file is part of NOVA. + * + * NOVA is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * NOVA is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with NOVA. If not, see . + */ + +package nova.worldgen.wrapper.mc.forge.v1_8.wrapper.world.forward; + +import net.minecraft.block.Block; +import net.minecraft.util.BlockPos; +import net.minecraft.world.World; +import net.minecraft.world.chunk.IChunkProvider; +import net.minecraft.world.gen.feature.WorldGenMinable; +import net.minecraftforge.fml.common.IWorldGenerator; +import nova.internal.core.Game; +import nova.worldgen.WorldgenManager; +import nova.worldgen.event.WorldgenEvent; +import nova.worldgen.generator.CustomGenerator; +import nova.worldgen.ore.Ore; +import nova.worldgen.ore.OreHeight; + +import java.util.Arrays; +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Random; +import java.util.Set; +import java.util.stream.Collectors; + +/** + * + * @author ExE Boss + */ +public class FWWorldGenerator implements IWorldGenerator { + + private final Map oreGen; + private final Set customGenerators; + private final WorldgenManager worldgenManager; + + public FWWorldGenerator(WorldgenManager worldgenManager) { + this.worldgenManager = worldgenManager; + this.oreGen = new HashMap<>(); + this.customGenerators = new HashSet<>(); + Game.events().on(WorldgenEvent.Register.class).bind(evt -> { + if (evt.generable instanceof Ore) { + this.oreGen.put((Ore) evt.generable, new WorldGenMinable(((Block)Game.natives().toNative(((Ore)evt.generable).block.build())).getDefaultState(), (int) Math.round(((Ore)evt.generable).clusterSize * 5))); + } else if (evt.generable instanceof CustomGenerator) { + this.customGenerators.add((CustomGenerator) evt.generable); + } + }); + } + + @Override + public void generate(Random random, int chunkX, int chunkZ, World world, IChunkProvider chunkGenerator, IChunkProvider chunkProvider) { + double worldScale = world.provider.getAverageGroundLevel() / 64D; + this.oreGen.forEach((ore, generator) -> { + double baseCount = 12 * ore.rarity * worldScale; + int count = (int) Math.round(random.nextGaussian() * Math.sqrt(baseCount) + baseCount); + for(int i = 0; i < count; i++) { + // OreHeight Values: (when world.provider.getAverageGroundLevel() == 64) + // SURFACE = 60 (55-65) + // UNDERSURFACE = 50 (45-55) + // DEEP = 40 (35-45) + // DEEPER = 30 (25-35) + // DEEPERER = 20 (15-25) + // REALLYDEEP = 10 (5-15) + + List oreHeightList = Arrays.stream(OreHeight.values()).filter(ore.oreLayers::allows).collect(Collectors.toList()); + if (oreHeightList.isEmpty()) return; + + OreHeight height = oreHeightList.get(random.nextInt(oreHeightList.size())); + double yAdd = (OreHeight.values().length - height.ordinal() - 1) * (10 * worldScale) + (5 * worldScale); + + int x = chunkX + random.nextInt(16); + int y = (int) Math.round(yAdd + (random.nextDouble() * 10 * worldScale)); + int z = chunkZ + random.nextInt(16); + + generator.generate(world, random, new BlockPos(x, y, z)); + } + }); + this.customGenerators.forEach(generator -> generator.generate(random, chunkX, chunkZ, worldScale, Game.natives().toNova(world), this.worldgenManager.getWorldInfo())); + } +} diff --git a/minecraft/build.gradle b/minecraft/build.gradle new file mode 100644 index 0000000..905f27d --- /dev/null +++ b/minecraft/build.gradle @@ -0,0 +1,19 @@ +subprojects { + buildscript { + repositories { + mavenCentral() + maven { + name "forge" + url "http://files.minecraftforge.net/maven" + } + maven { + name "sonatype" + url "https://oss.sonatype.org/content/repositories/snapshots/" + } + } + dependencies { + // Minecraft 1.11 requires newer ForgeGradle, while 1.7 and 1.8 require older. + classpath 'net.minecraftforge.gradle:ForgeGradle:' + property('forgeGradleVersion') + } + } +} diff --git a/settings.gradle b/settings.gradle index 064e60f..6c5737d 100644 --- a/settings.gradle +++ b/settings.gradle @@ -1,3 +1,4 @@ -rootProject.name = "NOVA-WORLDGEN" +rootProject.name = "NOVA-Worldgen" -include "mc17", "mc18" \ No newline at end of file +include "minecraft:1.8" +include "minecraft:1.7" diff --git a/src/main/java/nova/internal/worldgen/depmodules/WorldgenModule.java b/src/main/java/nova/internal/worldgen/depmodules/WorldgenModule.java new file mode 100644 index 0000000..b1d94fd --- /dev/null +++ b/src/main/java/nova/internal/worldgen/depmodules/WorldgenModule.java @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2017 NOVA, All rights reserved. + * This library is free software, licensed under GNU Lesser General Public License version 3 + * + * This file is part of NOVA. + * + * NOVA is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * NOVA is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with NOVA. If not, see . + */ + +package nova.internal.worldgen.depmodules; + +import nova.worldgen.WorldgenManager; +import nova.worldgen.world.WorldInfo; +import se.jbee.inject.bind.BinderModule; +import se.jbee.inject.util.Scoped; + +/** + * + * @author ExE Boss + */ +public class WorldgenModule extends BinderModule { + + @Override + protected void declare() { + per(Scoped.APPLICATION).bind(WorldgenManager.class).toConstructor(); + } +} diff --git a/src/main/java/nova/worldgen/Chunk.java b/src/main/java/nova/worldgen/Chunk.java index 59cfe2d..3b1c362 100644 --- a/src/main/java/nova/worldgen/Chunk.java +++ b/src/main/java/nova/worldgen/Chunk.java @@ -1,3 +1,23 @@ +/* + * Copyright (c) 2015 NOVA, All rights reserved. + * This library is free software, licensed under GNU Lesser General Public License version 3 + * + * This file is part of NOVA. + * + * NOVA is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * NOVA is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with NOVA. If not, see . + */ + package nova.worldgen; import nova.core.block.Block; diff --git a/src/main/java/nova/worldgen/WorldgenManager.java b/src/main/java/nova/worldgen/WorldgenManager.java new file mode 100644 index 0000000..8f1571a --- /dev/null +++ b/src/main/java/nova/worldgen/WorldgenManager.java @@ -0,0 +1,82 @@ +/* + * Copyright (c) 2015 NOVA, All rights reserved. + * This library is free software, licensed under GNU Lesser General Public License version 3 + * + * This file is part of NOVA. + * + * NOVA is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * NOVA is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with NOVA. If not, see . + */ + +package nova.worldgen; + +import nova.worldgen.generator.Generator; +import nova.core.event.bus.GlobalEvents; +import nova.core.util.registry.Manager; +import nova.core.util.registry.Registry; +import nova.worldgen.event.WorldgenEvent; +import nova.worldgen.generator.CustomGenerator; +import nova.worldgen.ore.Ore; +import nova.worldgen.world.WorldInfo; + +import java.util.Optional; + +/** + * + * @author ExE Boss + */ +public class WorldgenManager extends Manager { + public final Registry registry; + + private final WorldInfo worldInfo; + private final GlobalEvents events; + + public WorldgenManager(Registry registry, GlobalEvents events, WorldInfo worldInfo) { + this.registry = registry; + this.events = events; + this.worldInfo = worldInfo; + } + + public Ore register(Ore ore) { + WorldgenEvent.Register event = new WorldgenEvent.Register<>(ore); + this.events.publish(event); + registry.register(event.generable); + return event.generable; + } + + public CustomGenerator register(CustomGenerator generator) { + WorldgenEvent.Register event = new WorldgenEvent.Register<>(generator); + this.events.publish(event); + registry.register(event.generable); + return event.generable; + } + + public Optional get(String ID) { + return registry.get(ID); + } + + public WorldInfo getWorldInfo() { + return this.worldInfo; + } + + @Override + public void init() { + this.events.publish(new Init(this)); + } + + public class Init extends ManagerEvent { + public Init(WorldgenManager manager) { + super(manager); + } + } +} diff --git a/src/main/java/nova/worldgen/event/WorldgenEvent.java b/src/main/java/nova/worldgen/event/WorldgenEvent.java new file mode 100644 index 0000000..3ad904b --- /dev/null +++ b/src/main/java/nova/worldgen/event/WorldgenEvent.java @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2015 NOVA, All rights reserved. + * This library is free software, licensed under GNU Lesser General Public License version 3 + * + * This file is part of NOVA. + * + * NOVA is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * NOVA is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with NOVA. If not, see . + */ + +package nova.worldgen.event; + +import nova.core.event.bus.CancelableEvent; +import nova.worldgen.generator.Generator; +import nova.worldgen.ore.Ore; + +/** + * + * @author ExE Boss + */ +public abstract class WorldgenEvent extends CancelableEvent { + + public static class Register extends CancelableEvent { + public T generable; + + public Register(T generable) { + this.generable = generable; + } + } +} diff --git a/src/main/java/nova/worldgen/generator/CustomGenerator.java b/src/main/java/nova/worldgen/generator/CustomGenerator.java new file mode 100644 index 0000000..3e47421 --- /dev/null +++ b/src/main/java/nova/worldgen/generator/CustomGenerator.java @@ -0,0 +1,45 @@ +/* + * Copyright (c) 2017 NOVA, All rights reserved. + * This library is free software, licensed under GNU Lesser General Public License version 3 + * + * This file is part of NOVA. + * + * NOVA is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * NOVA is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with NOVA. If not, see . + */ +package nova.worldgen.generator; + +import nova.core.world.World; +import nova.worldgen.WorldgenManager; +import nova.worldgen.world.WorldInfo; + +import java.util.Random; + +/** + * This is a black box generator. + * Unlike {@link nova.worldgen.ore.Ore}, + * this one is implemented by the mod, not the game. + * + * @author ExE Boss + */ +public abstract class CustomGenerator extends Generator { + + protected final WorldgenManager worldgenManager; + + public CustomGenerator(String id, WorldgenManager worldgenManager) { + super(id); + this.worldgenManager = worldgenManager; + } + + public abstract void generate(Random random, int chunkX, int chunkZ, double worldScale, World worlda, WorldInfo worldInfo); +} diff --git a/src/main/java/nova/worldgen/generator/Generator.java b/src/main/java/nova/worldgen/generator/Generator.java new file mode 100644 index 0000000..a812bb7 --- /dev/null +++ b/src/main/java/nova/worldgen/generator/Generator.java @@ -0,0 +1,27 @@ +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ +package nova.worldgen.generator; + +import nova.core.util.Identifiable; + +/** + * This class describes a structure that will be generated + * in the world by the world generator. + * + * @author ExE Boss + */ +public abstract class Generator implements Identifiable { + public final String id; + + public Generator(String id) { + this.id = id; + } + + @Override + public final String getID() { + return id; + } +} diff --git a/src/main/java/nova/worldgen/ore/Ore.java b/src/main/java/nova/worldgen/ore/Ore.java index b430b2f..de91d60 100644 --- a/src/main/java/nova/worldgen/ore/Ore.java +++ b/src/main/java/nova/worldgen/ore/Ore.java @@ -1,37 +1,53 @@ +/* + * Copyright (c) 2015 NOVA, All rights reserved. + * This library is free software, licensed under GNU Lesser General Public License version 3 + * + * This file is part of NOVA. + * + * NOVA is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * NOVA is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with NOVA. If not, see . + */ + package nova.worldgen.ore; import nova.core.block.BlockFactory; -import nova.core.util.Identifiable; -import nova.worldgen.util.EnumSelector; +import nova.core.util.EnumSelector; +import nova.worldgen.generator.Generator; /** - * This class describes resource that will be placed by world generator - * in world structure as ore. + * This class describes a resource that will be placed in the world + * as an ore by the world generator. */ -public final class Ore implements Identifiable { - public final String oreGenName; +public final class Ore extends Generator { public final BlockFactory block; public final double rarity; public final double clusterSize; public final EnumSelector oreLayers; /** - * @param oreGenName Ore name in world generator, used to identify the ore + * Create the ore generator instance. + * + * @param id Ore name in world generator, used to identify the ore * @param block Block factory of the ore * @param rarity How rare is the ore, 1 should be considered base rarity, lower value means less common ore * @param clusterSize Ore cluster size multiplier, base value is 1, bigger value means bigger ore cluster * @param oreLayers World layers at which the ore can be found */ - public Ore(String oreGenName, BlockFactory block, double rarity, double clusterSize, EnumSelector oreLayers) { - this.oreGenName = oreGenName; + public Ore(String id, BlockFactory block, double rarity, double clusterSize, EnumSelector oreLayers) { + super(id); this.block = block; this.rarity = rarity; this.clusterSize = clusterSize; this.oreLayers = oreLayers; } - - @Override - public String getID() { - return oreGenName; - } -} \ No newline at end of file +} diff --git a/src/main/java/nova/worldgen/ore/OreGenerationRegistry.java b/src/main/java/nova/worldgen/ore/OreGenerationRegistry.java deleted file mode 100644 index 881f4b6..0000000 --- a/src/main/java/nova/worldgen/ore/OreGenerationRegistry.java +++ /dev/null @@ -1,8 +0,0 @@ -package nova.worldgen.ore; - -import nova.core.util.Registry; -import nova.worldgen.ore.Ore; - -public class OreGenerationRegistry extends Registry { - -} diff --git a/src/main/java/nova/worldgen/ore/OreHeight.java b/src/main/java/nova/worldgen/ore/OreHeight.java index 479e8be..10902aa 100644 --- a/src/main/java/nova/worldgen/ore/OreHeight.java +++ b/src/main/java/nova/worldgen/ore/OreHeight.java @@ -1,3 +1,23 @@ +/* + * Copyright (c) 2015 NOVA, All rights reserved. + * This library is free software, licensed under GNU Lesser General Public License version 3 + * + * This file is part of NOVA. + * + * NOVA is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * NOVA is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with NOVA. If not, see . + */ + package nova.worldgen.ore; //TODO: Find better names for those diff --git a/src/main/java/nova/worldgen/util/EnumSelector.java b/src/main/java/nova/worldgen/util/EnumSelector.java deleted file mode 100644 index b67694f..0000000 --- a/src/main/java/nova/worldgen/util/EnumSelector.java +++ /dev/null @@ -1,68 +0,0 @@ -package nova.worldgen.util; - -import java.util.EnumSet; - -/** - * This class is used to mark certain values from specified enum as allowed. - * Note that you must specify default state via #allowAll or #blockAll methods - * - * @param The enum - */ -public class EnumSelector> { - private EnumSet exceptions; - private boolean defaultAllow, defaultBlock = false; - private boolean locked = false; - - private EnumSelector(Class enumClass) { - exceptions = EnumSet.noneOf(enumClass); - } - - public static > EnumSelector of(Class enumClass) { - return new EnumSelector(enumClass); - } - - private void checkLocked() { - if (locked) - throw new IllegalStateException("No edits are allowed after EnumSelector has been locked."); - } - - public void allowAll() { - checkLocked(); - if (!defaultBlock) - defaultAllow = true; - else - throw new IllegalStateException("You can't allow all enum values when you are already blocking them."); - } - - public void blockAll() { - checkLocked(); - if (!defaultAllow) - defaultBlock = true; - else - throw new IllegalStateException("You can't block all enum values when you are already allowing them."); - } - - public void apart(T value) { - checkLocked(); - exceptions.add(value); - } - - public void lock() { - if (defaultAllow || defaultBlock) - locked = true; - else - throw new IllegalStateException("Cannot lock EnumSelector without specifying default behaviour."); - } - - public boolean locked() { - - return locked; - } - - public boolean allows(T value) { - if (!locked) - throw new IllegalStateException("Cannot use EnumSelector that is not locked."); - else - return defaultAllow ^ exceptions.contains(value); - } -} diff --git a/src/main/java/nova/worldgen/world/WorldInfo.java b/src/main/java/nova/worldgen/world/WorldInfo.java index 6f28dce..226ca86 100644 --- a/src/main/java/nova/worldgen/world/WorldInfo.java +++ b/src/main/java/nova/worldgen/world/WorldInfo.java @@ -1,24 +1,47 @@ +/* + * Copyright (c) 2015 NOVA, All rights reserved. + * This library is free software, licensed under GNU Lesser General Public License version 3 + * + * This file is part of NOVA. + * + * NOVA is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * NOVA is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with NOVA. If not, see . + */ + package nova.worldgen.world; +import nova.core.util.registry.Registry; import nova.core.util.shape.Cuboid; -import nova.worldgen.ore.OreGenerationRegistry; +import nova.worldgen.ore.Ore; /** - * This class profides information on world that world generator may need + * This class provides information on world that world generator may need */ public abstract class WorldInfo { /** - * @return Size of the world, can be infinite for some directions + * @return Size of the world, can be infinite for some directions. + * Minimum value is inclusive, maximum value is exclusive. */ public abstract Cuboid getWorldDimmensions(); /** - * @return Size of chunk that is generated by world generator + * @return Size of chunk that is generated by world generator. + * Minimum value is inclusive, maximum value is exclusive. */ public abstract Cuboid getWorldGenerationUnitDimmensions(); /** - * @return {@link OreGenerationRegistry} for the world + * @return {@link Registry}{@code <}{@link Ore}{@code >} for the world. */ - public abstract OreGenerationRegistry getOreGenerationRegistry(); + public abstract Registry getOreGenerationRegistry(); }