diff --git a/.gitignore b/.gitignore index 494a860..7e0526e 100644 --- a/.gitignore +++ b/.gitignore @@ -6,8 +6,8 @@ # Sources !/src -!/mc17 -!/mc18 +!/guidelines +!/minecraft # github !/.gitignore diff --git a/build.gradle b/build.gradle index 9d1035f..6bfade8 100644 --- a/build.gradle +++ b/build.gradle @@ -1,25 +1,29 @@ 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") + } + "1_11" { + wrapper "nova.core:NOVA-Core-Wrapper-MC1.11:$nova_version" + runtime project(":minecraft:1.11") } } } 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..896c508 --- /dev/null +++ b/minecraft/.gitignore @@ -0,0 +1,8 @@ +/* + +!/build.gradle +!/.gitignore + +!/1.11 +!/1.8 +!/1.7 diff --git a/minecraft/1.11/.gitignore b/minecraft/1.11/.gitignore new file mode 100644 index 0000000..85be317 --- /dev/null +++ b/minecraft/1.11/.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/minecraft/1.11/build.gradle b/minecraft/1.11/build.gradle new file mode 100644 index 0000000..9a9f6e5 --- /dev/null +++ b/minecraft/1.11/build.gradle @@ -0,0 +1,64 @@ +apply plugin: "maven-publish" +apply plugin: "com.jfrog.artifactory" +apply from: "https://raw.githubusercontent.com/NOVA-Team/NOVA-Gradle/master/shared-scripts/java.gradle" + +publishing { + publications { + main(MavenPublication) { + from components.java + + artifactId "NOVA-Worldgen-Wrapper-MC1.11" + + artifact sourcesJar + artifact javadocJar + + pom.withXml(writePom(project.properties)) + } + } +} + +artifactory { + publish { + defaults { + publications("main") + publishPom = true + } + } +} + +artifacts { + archives jar +} + +apply plugin: 'net.minecraftforge.gradle.forge' + +minecraft { + version = property("minecraft.version") + "-" + property("forge.version") + mappings = 'snapshot_20161220' + runDir = "run" +} + +dependencies { + compile rootProject + compile group: "nova.core", name: "NOVA-Core", version: property("nova_version"), changing: true + compile group: "nova.core", name: "NOVA-Core-Wrapper-MC1.11", version: property("nova_version"), classifier: "deobf", changing: true +} + +processResources { + // this will ensure that this task is redone when the versions change. + inputs.property "version", project.version + inputs.property "mcversion", project.minecraft.version + + // replace stuff in mcmod.info, nothing else + from(sourceSets.main.resources.srcDirs) { + include "mcmod.info" + + // replace version and mcversion + expand "version": project.version, "mcversion": project.minecraft.version + } + + // copy everything else, thats not the mcmod.info + from(sourceSets.main.resources.srcDirs) { + exclude "mcmod.info" + } +} diff --git a/minecraft/1.11/gradle.properties b/minecraft/1.11/gradle.properties new file mode 100644 index 0000000..160c5b2 --- /dev/null +++ b/minecraft/1.11/gradle.properties @@ -0,0 +1,8 @@ +minecraft.version = 1.11 +forge.version = 13.19.1.2189 +forgeGradleVersion = 2.2-SNAPSHOT + +packaging = jar +info.inceptionYear = 2016 +info.description = The NOVA-Worldgen Minecraft 1.11 wrapper. +info.organization.name = NOVA diff --git a/minecraft/1.11/src/main/java/nova/worldgen/wrapper/mc/forge/v1_11/launch/NovaWorldgenWrapper.java b/minecraft/1.11/src/main/java/nova/worldgen/wrapper/mc/forge/v1_11/launch/NovaWorldgenWrapper.java new file mode 100644 index 0000000..c21fd42 --- /dev/null +++ b/minecraft/1.11/src/main/java/nova/worldgen/wrapper/mc/forge/v1_11/launch/NovaWorldgenWrapper.java @@ -0,0 +1,54 @@ +/* + * 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_11.launch; + +import net.minecraftforge.fml.common.registry.GameRegistry; +import nova.core.loader.Loadable; +import nova.core.loader.Mod; +import nova.internal.worldgen.depmodules.WorldgenModule; +import nova.worldgen.WorldgenManager; +import nova.worldgen.wrapper.mc.forge.v1_11.wrapper.world.forward.FWWorldGenerator; + +/** + * + * @author ExE Boss + */ +@Mod(id = NovaWorldgenWrapper.id, name = NovaWorldgenWrapper.name, version = NovaWorldgenWrapper.version, modules = { WorldgenModule.class }, novaVersion = "0.0.1") +public class NovaWorldgenWrapper implements Loadable { + + 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; + this.worldGenerator = new FWWorldGenerator(this.worldgenManager); + } + + @Override + public void preInit() { + GameRegistry.registerWorldGenerator(this.worldGenerator, 0); + } +} diff --git a/minecraft/1.11/src/main/java/nova/worldgen/wrapper/mc/forge/v1_11/wrapper/world/forward/FWWorldGenerator.java b/minecraft/1.11/src/main/java/nova/worldgen/wrapper/mc/forge/v1_11/wrapper/world/forward/FWWorldGenerator.java new file mode 100644 index 0000000..295a851 --- /dev/null +++ b/minecraft/1.11/src/main/java/nova/worldgen/wrapper/mc/forge/v1_11/wrapper/world/forward/FWWorldGenerator.java @@ -0,0 +1,89 @@ +/* + * 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_11.wrapper.world.forward; + +import net.minecraft.block.Block; +import net.minecraft.util.math.BlockPos; +import net.minecraft.world.World; +import net.minecraft.world.chunk.IChunkGenerator; +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.ore.Ore; +import nova.worldgen.ore.OreHeight; + +import java.util.Arrays; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Random; +import java.util.stream.Collectors; + +/** + * + * @author ExE Boss + */ +public class FWWorldGenerator implements IWorldGenerator { + + private final Map oreGen; + private final WorldgenManager worldgenManager; + + public FWWorldGenerator(WorldgenManager worldgenManager) { + this.worldgenManager = worldgenManager; + this.oreGen = new HashMap<>(); + Game.events().on(WorldgenEvent.RegisterOre.class).bind(evt -> { + this.oreGen.put(evt.ore, new WorldGenMinable(((Block)Game.natives().toNative(evt.ore.block.build())).getDefaultState(), (int) Math.round(evt.ore.clusterSize * 5))); + }); + } + + @Override + public void generate(Random random, int chunkX, int chunkZ, World world, IChunkGenerator chunkGenerator, IChunkProvider chunkProvider) { + double worldScale = world.provider.getAverageGroundLevel(); + this.worldgenManager.registry.stream().forEachOrdered(ore -> { + double baseCount = 12 * ore.rarity * worldScale / 64; + int count = (int) Math.round(random.nextGaussian() * Math.sqrt(baseCount) + baseCount); + for(int i = 0; i < count; i++) { + // OreHeight Values: (when worldScale == 64, which is the default) + // 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 / 64) + (5 * worldScale / 64); + + int x = chunkX + random.nextInt(16); + int y = (int) Math.round(yAdd + (random.nextDouble() * 10 * worldScale / 64)); + int z = chunkZ + random.nextInt(16); + + oreGen.get(ore).generate(world, random, new BlockPos(x, y, z)); + } + }); + } +} 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/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..bd1e3b6 --- /dev/null +++ b/minecraft/1.7/src/main/java/nova/worldgen/wrapper/mc/forge/v1_7_10/launch/NovaWorldgenWrapper.java @@ -0,0 +1,54 @@ +/* + * 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.registry.GameRegistry; +import nova.core.loader.Loadable; +import nova.core.loader.Mod; +import nova.internal.worldgen.depmodules.WorldgenModule; +import nova.worldgen.WorldgenManager; +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 = { WorldgenModule.class }, novaVersion = "0.0.1") +public class NovaWorldgenWrapper implements Loadable { + + 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; + this.worldGenerator = new FWWorldGenerator(this.worldgenManager); + } + + @Override + public void preInit() { + GameRegistry.registerWorldGenerator(this.worldGenerator, 0); + } +} 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..071081e --- /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,87 @@ +/* + * 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.ore.Ore; +import nova.worldgen.ore.OreHeight; + +import java.util.Arrays; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Random; +import java.util.stream.Collectors; + +/** + * + * @author ExE Boss + */ +public class FWWorldGenerator implements IWorldGenerator { + + private final Map oreGen; + private final WorldgenManager worldgenManager; + + public FWWorldGenerator(WorldgenManager worldgenManager) { + this.worldgenManager = worldgenManager; + this.oreGen = new HashMap<>(); + Game.events().on(WorldgenEvent.RegisterOre.class).bind(evt -> { + this.oreGen.put(evt.ore, new WorldGenMinable(((Block)Game.natives().toNative(evt.ore.block.build())), (int) Math.round(evt.ore.clusterSize * 5))); + }); + } + + @Override + public void generate(Random random, int chunkX, int chunkZ, World world, IChunkProvider chunkGenerator, IChunkProvider chunkProvider) { + double worldScale = world.provider.getAverageGroundLevel(); + this.worldgenManager.registry.stream().forEachOrdered(ore -> { + double baseCount = 12 * ore.rarity * worldScale / 64; + int count = (int) Math.round(random.nextGaussian() * Math.sqrt(baseCount) + baseCount); + for(int i = 0; i < count; i++) { + // OreHeight Values: (when worldScale == 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 / 64) + (5 * worldScale / 64); + + int x = chunkX + random.nextInt(16); + int y = (int) Math.round(yAdd + (random.nextDouble() * 10 * worldScale / 64)); + int z = chunkZ + random.nextInt(16); + + oreGen.get(ore).generate(world, random, x, y, z); + } + }); + } +} 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/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..35e1cc4 --- /dev/null +++ b/minecraft/1.8/src/main/java/nova/worldgen/wrapper/mc/forge/v1_8/launch/NovaWorldgenWrapper.java @@ -0,0 +1,54 @@ +/* + * 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.registry.GameRegistry; +import nova.core.loader.Loadable; +import nova.core.loader.Mod; +import nova.internal.worldgen.depmodules.WorldgenModule; +import nova.worldgen.WorldgenManager; +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 = { WorldgenModule.class }, novaVersion = "0.0.1") +public class NovaWorldgenWrapper implements Loadable { + + 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; + this.worldGenerator = new FWWorldGenerator(this.worldgenManager); + } + + @Override + public void preInit() { + GameRegistry.registerWorldGenerator(this.worldGenerator, 0); + } +} 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..28603c3 --- /dev/null +++ b/minecraft/1.8/src/main/java/nova/worldgen/wrapper/mc/forge/v1_8/wrapper/world/forward/FWWorldGenerator.java @@ -0,0 +1,88 @@ +/* + * 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.ore.Ore; +import nova.worldgen.ore.OreHeight; + +import java.util.Arrays; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Random; +import java.util.stream.Collectors; + +/** + * + * @author ExE Boss + */ +public class FWWorldGenerator implements IWorldGenerator { + + private final Map oreGen; + private final WorldgenManager worldgenManager; + + public FWWorldGenerator(WorldgenManager worldgenManager) { + this.worldgenManager = worldgenManager; + this.oreGen = new HashMap<>(); + Game.events().on(WorldgenEvent.RegisterOre.class).bind(evt -> { + this.oreGen.put(evt.ore, new WorldGenMinable(((Block)Game.natives().toNative(evt.ore.block.build())).getDefaultState(), (int) Math.round(evt.ore.clusterSize * 5))); + }); + } + + @Override + public void generate(Random random, int chunkX, int chunkZ, World world, IChunkProvider chunkGenerator, IChunkProvider chunkProvider) { + double worldScale = world.provider.getAverageGroundLevel(); + this.worldgenManager.registry.stream().forEachOrdered(ore -> { + double baseCount = 12 * ore.rarity * worldScale / 64; + int count = (int) Math.round(random.nextGaussian() * Math.sqrt(baseCount) + baseCount); + for(int i = 0; i < count; i++) { + // OreHeight Values: (when worldScale == 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 / 64) + (5 * worldScale / 64); + + int x = chunkX + random.nextInt(16); + int y = (int) Math.round(yAdd + (random.nextDouble() * 10 * worldScale / 64)); + int z = chunkZ + random.nextInt(16); + + oreGen.get(ore).generate(world, random, new BlockPos(x, y, z)); + } + }); + } +} 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..aa20a86 100644 --- a/settings.gradle +++ b/settings.gradle @@ -1,3 +1,5 @@ -rootProject.name = "NOVA-WORLDGEN" +rootProject.name = "NOVA-Worldgen" -include "mc17", "mc18" \ No newline at end of file +include "minecraft:1.11" +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..dac85fe --- /dev/null +++ b/src/main/java/nova/internal/worldgen/depmodules/WorldgenModule.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.internal.worldgen.depmodules; + +import nova.worldgen.WorldgenManager; +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/Generable.java b/src/main/java/nova/worldgen/Generable.java new file mode 100644 index 0000000..789145b --- /dev/null +++ b/src/main/java/nova/worldgen/Generable.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; + +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 Generable implements Identifiable { + public final String id; + + public Generable(String id) { + this.id = id; + } + + @Override + public final String getID() { + return id; + } +} diff --git a/src/main/java/nova/worldgen/WorldgenManager.java b/src/main/java/nova/worldgen/WorldgenManager.java new file mode 100644 index 0000000..7f5c484 --- /dev/null +++ b/src/main/java/nova/worldgen/WorldgenManager.java @@ -0,0 +1,66 @@ +/* + * 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.event.bus.GlobalEvents; +import nova.core.util.registry.Manager; +import nova.core.util.registry.Registry; +import nova.worldgen.event.WorldgenEvent; +import nova.worldgen.ore.Ore; + +import java.util.Optional; + +/** + * + * @author ExE Boss + */ +public class WorldgenManager extends Manager { + public final Registry registry; + + private final GlobalEvents events; + + public WorldgenManager(GlobalEvents events) { + this.registry = new Registry<>(); + this.events = events; + } + + public Ore register(Ore ore) { + WorldgenEvent.RegisterOre event = new WorldgenEvent.RegisterOre(ore); + this.events.publish(event); + registry.register(event.ore); + return event.ore; + } + + public Optional get(String ID) { + return registry.get(ID); + } + + @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..5d1da28 --- /dev/null +++ b/src/main/java/nova/worldgen/event/WorldgenEvent.java @@ -0,0 +1,39 @@ +/* + * 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.ore.Ore; + +/** + * + * @author ExE Boss + */ +public abstract class WorldgenEvent extends CancelableEvent { + + public static class RegisterOre extends CancelableEvent { + public Ore ore; + + public RegisterOre(Ore ore) { + this.ore = ore; + } + } +} diff --git a/src/main/java/nova/worldgen/ore/Ore.java b/src/main/java/nova/worldgen/ore/Ore.java index b430b2f..8e86cf7 100644 --- a/src/main/java/nova/worldgen/ore/Ore.java +++ b/src/main/java/nova/worldgen/ore/Ore.java @@ -1,37 +1,51 @@ +/* + * 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.Generable; /** - * 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 Generable { 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 + * @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..90184f0 100644 --- a/src/main/java/nova/worldgen/world/WorldInfo.java +++ b/src/main/java/nova/worldgen/world/WorldInfo.java @@ -1,10 +1,31 @@ +/* + * 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 { /** @@ -18,7 +39,7 @@ public abstract class WorldInfo { 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(); }