From 2c82e722cd515a49783f7f7aae50588a9879f09d Mon Sep 17 00:00:00 2001 From: ExE Boss Date: Thu, 22 Dec 2016 10:25:18 +0100 Subject: [PATCH] NOVA Worldgen Minecraft 1.7 Wrappers --- minecraft/.gitignore | 1 + minecraft/1.7/.gitignore | 17 ++++ {mc17 => minecraft/1.7}/build.gradle | 6 +- {mc17 => minecraft/1.7}/gradle.properties | 5 +- .../v1_7_10/depmodules/MCWorldgenModule.java | 37 +++++++ .../v1_7_10/launch/NovaWorldgenWrapper.java | 55 +++++++++++ .../v1_7_10/wrapper/world/MCWorldInfo.java | 55 +++++++++++ .../world/forward/FWWorldGenerator.java | 97 +++++++++++++++++++ 8 files changed, 266 insertions(+), 7 deletions(-) create mode 100644 minecraft/1.7/.gitignore rename {mc17 => minecraft/1.7}/build.gradle (84%) rename {mc17 => minecraft/1.7}/gradle.properties (68%) create mode 100644 minecraft/1.7/src/main/java/nova/worldgen/wrapper/mc/forge/v1_7_10/depmodules/MCWorldgenModule.java create mode 100644 minecraft/1.7/src/main/java/nova/worldgen/wrapper/mc/forge/v1_7_10/launch/NovaWorldgenWrapper.java create mode 100644 minecraft/1.7/src/main/java/nova/worldgen/wrapper/mc/forge/v1_7_10/wrapper/world/MCWorldInfo.java create mode 100644 minecraft/1.7/src/main/java/nova/worldgen/wrapper/mc/forge/v1_7_10/wrapper/world/forward/FWWorldGenerator.java diff --git a/minecraft/.gitignore b/minecraft/.gitignore index fd2f4da..a4c6e69 100644 --- a/minecraft/.gitignore +++ b/minecraft/.gitignore @@ -4,3 +4,4 @@ !/.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..8c2741b --- /dev/null +++ b/minecraft/1.7/src/main/java/nova/worldgen/wrapper/mc/forge/v1_7_10/launch/NovaWorldgenWrapper.java @@ -0,0 +1,55 @@ +/* + * 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.depmodules.MCWorldgenModule; +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 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/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..5bb6460 --- /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 final WorldgenManager worldgenManager; + + public MCWorldInfo(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())); + } +}