Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,4 @@ addon.local.gradle
addon.local.gradle.kts
addon.late.local.gradle
addon.late.local.gradle.kts
layout.json
layout.json
1 change: 1 addition & 0 deletions dependencies.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

dependencies {
compileOnly("thaumcraft:Thaumcraft:1.7.10-4.2.3.5:dev") {transitive = false}
compileOnly("com.github.GTNewHorizons:GT5-Unofficial:5.09.45.53:dev")
compileOnly("curse.maven:skinport-234948:3212017")

// For Thaumcraft runtime
Expand Down
19 changes: 16 additions & 3 deletions src/main/java/twilightforest/TFFeature.java
Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,18 @@ public static TFFeature generateFeatureForOldMapGen(int chunkX, int chunkZ, Worl
}

public static TFFeature generateFeatureFor1Point7(int chunkX, int chunkZ, World world) {
Copy link

@YannickMG YannickMG Jan 31, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It appears this function isn't only used when generating a feature (as its name would suggest) but also when looking up which feature should exist in a given region.

Changing the configurated change post-worldgen affects functionality that check against existing features such as the magic map.

Is this intended? If so you might want to document the caveat that this config isn't meant to be modified on an existing world.
image

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, definitely need a warning, I was worried that this would happen


// get random value
Random hillRNG = new Random(world.getSeed() + chunkX * 25117L + chunkZ * 151121L);

// Modify major features (Bosses) generation rate
// 100% = default
// 50% = only 50% generation chance from default chance

if (!getRandom(hillRNG, TwilightForestMod.majorFeatureGenChance)) {
return nothing;
}

if (TwilightForestMod.oldMapGen) {
return generateFeatureForOldMapGen(chunkX, chunkZ, world);
}
Expand All @@ -390,8 +402,6 @@ public static TFFeature generateFeatureFor1Point7(int chunkX, int chunkZ, World
// what biome is at the center of the chunk?
BiomeGenBase biomeAt = world.getBiomeGenForCoords((chunkX << 4) + 8, (chunkZ << 4) + 8);

// get random value
Random hillRNG = new Random(world.getSeed() + chunkX * 25117L + chunkZ * 151121L);
int randnum = hillRNG.nextInt(16);

// glaciers have ice towers
Expand Down Expand Up @@ -548,7 +558,6 @@ public static TFFeature getFeatureForRegion(int chunkX, int chunkZ, World world)
*
* @param cx
* @param cz
* @param seed
* @return
*/
public static int[] getNearestCenter(int cx, int cz, World world) {
Expand Down Expand Up @@ -839,4 +848,8 @@ public ItemStack createHintBook() {
return book;
}

public static boolean getRandom(Random r, double chanceMul) {
return ((r.nextDouble() * 100d) < chanceMul);

}
}
81 changes: 81 additions & 0 deletions src/main/java/twilightforest/TwilightForestMod.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import net.minecraftforge.common.DimensionManager;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.common.config.Configuration;
import net.minecraftforge.common.config.Property;

import baubles.api.BaubleType;
import cpw.mods.fml.common.FMLCommonHandler;
Expand All @@ -29,6 +30,7 @@
import twilightforest.biomes.TFBiomeBase;
import twilightforest.block.TFBlocks;
import twilightforest.entity.TFCreatures;
import twilightforest.gt_integration.GT_Integration_Utils;
import twilightforest.item.BehaviorTFMobEggDispense;
import twilightforest.item.ItemTFMagicMap;
import twilightforest.item.ItemTFMazeMap;
Expand Down Expand Up @@ -57,6 +59,7 @@
import twilightforest.tileentity.TileEntityTFTowerBossSpawner;
import twilightforest.tileentity.TileEntityTFTowerBuilder;
import twilightforest.tileentity.TileEntityTFTrophy;
import twilightforest.world.TFGenCaveStalactite;
import twilightforest.world.WorldProviderTwilightForest;

@Mod(modid = TwilightForestMod.ID, name = "The Twilight Forest", version = TwilightForestMod.VERSION)
Expand Down Expand Up @@ -97,6 +100,34 @@ public class TwilightForestMod {
public static float canopyCoverage;
public static int twilightOakChance;

// Ore Balance

public static double stalactiteOrePopulationDensity = 75;
public static boolean gregifyStalactiteOres;

public static boolean diamondOreStal;
public static boolean lapisOreStal;
public static boolean emeraldOreStal;
public static boolean goldOreStal;
public static boolean redstoneOreStal;
public static boolean ironOreStal;
public static boolean coalOreStal;
public static boolean glowstoneStal;

public static boolean GT_useSmallOres;

public static int GT_diamondOreMeta;
public static int GT_lapisOreMeta;
public static int GT_emeraldOreMeta;
public static int GT_goldOreMeta;
public static int GT_redstoneOreMeta;
public static int GT_ironOreMeta;
public static int GT_coalOreMeta;

// Major feature spawn chance
public static double majorFeatureGenChance = 100;
public static double minorFeatureGenChance = 14;

public static int idMobWildBoar;
public static int idMobBighornSheep;
public static int idMobWildDeer;
Expand Down Expand Up @@ -336,6 +367,16 @@ public void postInit(FMLPostInitializationEvent evt) {
FMLLog.info("[TwilightForest] Did not find Thaumcraft, did not load ThaumcraftApi integration.");
}

// GT Ore
if (Loader.isModLoaded("gregtech") && gregifyStalactiteOres) {
// Doing
GT_Integration_Utils.init();
} else {
FMLLog.warning("[TwilightForest] Did not load Gregtech integration.");
// Disable
gregifyStalactiteOres = false;
}

// final check for biome ID conflicts
TwilightForestMod.hasBiomeIdConflicts = TFBiomeBase.areThereBiomeIdConflicts();
}
Expand Down Expand Up @@ -945,6 +986,46 @@ private void loadConfiguration(Configuration configFile) {
"TwilightOakChance",
48).comment = "Chance that a chunk in the Twilight Forest will contain a twilight oak tree. Higher numbers reduce the number of trees, increasing performance.";

// Ore in Stalactites
// Toggle gen

diamondOreStal = configFile.get("Stalactites", "Diamond Ore Stalactites", true).getBoolean(true);
lapisOreStal = configFile.get("Stalactites", "Lapis Ore Stalactites", true).getBoolean(true);
emeraldOreStal = configFile.get("Stalactites", "Emerald Ore Stalactites", true).getBoolean(true);
goldOreStal = configFile.get("Stalactites", "Gold Ore Stalactites", true).getBoolean(true);
redstoneOreStal = configFile.get("Stalactites", "Redstone Ore Stalactites", true).getBoolean(true);
ironOreStal = configFile.get("Stalactites", "Iron Ore Stalactites", true).getBoolean(true);
coalOreStal = configFile.get("Stalactites", "Coal Ore Stalactites", true).getBoolean(true);
glowstoneStal = configFile.get("Stalactites", "Glowstone Stalactites", true).getBoolean(true);

// Toggle ore
TFGenCaveStalactite.configStalactites();

gregifyStalactiteOres = configFile.get("Stalactites", "Use Gregified ores", false).getBoolean(false);

if (gregifyStalactiteOres) {
// GT Ore Mapping
// Show More config
GT_useSmallOres = configFile.get("GT_OreMapping", "GT_UseSmallOres", false).getBoolean(false);
GT_coalOreMeta = configFile.get("GT_OreMapping", "GT_coalOreMeta", 535).getInt();
GT_lapisOreMeta = configFile.get("GT_OreMapping", "GT_lapisOreMeta", 526).getInt();
GT_redstoneOreMeta = configFile.get("GT_OreMapping", "GT_redstoneOreMeta", 810).getInt();
GT_emeraldOreMeta = configFile.get("GT_OreMapping", "GT_emeraldOreMeta", 501).getInt();
GT_diamondOreMeta = configFile.get("GT_OreMapping", "GT_diamondOreMeta", 500).getInt();
GT_ironOreMeta = configFile.get("GT_OreMapping", "GT_ironOreMeta", 32).getInt();
GT_goldOreMeta = configFile.get("GT_OreMapping", "GT_goldOreMeta", 86).getInt();

}

// Gen chance
Property majorGenChance = configFile.get("WorldGen", "Major Feature Generation Chance", 100);
majorGenChance.comment = "IT IS NOT RECOMMENDED TO CHANGE ON AN ALREADY CREATED WORLD! Since old dungeons can change/don't showing the icon on the magic map or will not be generated completely";
majorFeatureGenChance = majorGenChance.getDouble();

minorFeatureGenChance = configFile.get("WorldGen", "Minor Feature Generation Chance", 14).getDouble(14);

stalactiteOrePopulationDensity = configFile.get("WorldGen", "Ore density in stalactites", 100).getDouble(100);

// fixed values, don't even read the config
idMobWildBoar = 177;
idMobBighornSheep = 178;
Expand Down
4 changes: 3 additions & 1 deletion src/main/java/twilightforest/biomes/TFBiomeDecorator.java
Original file line number Diff line number Diff line change
Expand Up @@ -158,14 +158,16 @@ protected void genDecorations(BiomeGenBase biome) {
}

// random features!
if (randomGenerator.nextInt(6) == 0) {
// now with chance

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The "now" part of "now with chance" isn't going to be very helpful to future readers of the code, for which that comment will always have been there.

If the intent of the comment is to indicate that there's a chance of the feature not happening then you might want to encode that knowledge about the code's intent into a well named function instead.

if (TFFeature.getRandom(randomGenerator, TwilightForestMod.minorFeatureGenChance)) {
int rx = chunk_X + randomGenerator.nextInt(16) + 8;
int rz = chunk_Z + randomGenerator.nextInt(16) + 8;
int ry = currentWorld.getHeightValue(rx, rz);
if (ry < 75) {
TFGenerator rf = randomFeature(randomGenerator);
rf.generate(currentWorld, randomGenerator, rx, ry, rz);
}

}

// add canopy trees
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package twilightforest.gt_integration;

import net.minecraft.block.Block;
import net.minecraft.world.World;

public class GT_Integration_Utils {

private static GT_OrePlacer orePlacer;

public static void init() {
// Create worker obj
orePlacer = new GT_OrePlacer();

}

public static boolean isInit() {
return orePlacer != null;
}

public static boolean doPlaceGTOre(World aWorld, int aX, int aY, int aZ, Block mcOreBlock) {
if (!isInit()) {
return false;
}
return orePlacer.placeGTOre(aWorld, aX, aY, aZ, mcOreBlock);
}

}
54 changes: 54 additions & 0 deletions src/main/java/twilightforest/gt_integration/GT_OrePlacer.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package twilightforest.gt_integration;

import net.minecraft.block.Block;
import net.minecraft.init.Blocks;
import net.minecraft.world.World;

import gregtech.common.blocks.GT_TileEntity_Ores;
import twilightforest.TwilightForestMod;

public class GT_OrePlacer {

public int getMappedGTMetaForOre(Block mOre) {
Comment on lines +1 to +12

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

getMappedGTMetaForOre should be private, and if you remove GT_Integration_Utils::getOrePlacer then all of GT_OrePlacer can be package private instead of public to hide your implementation details.


if (mOre == Blocks.coal_ore) {
return TwilightForestMod.GT_coalOreMeta;
}

if (mOre == Blocks.iron_ore) {
return TwilightForestMod.GT_ironOreMeta;

}
if (mOre == Blocks.gold_ore) {
return TwilightForestMod.GT_goldOreMeta;
}

if (mOre == Blocks.redstone_ore) {
return TwilightForestMod.GT_redstoneOreMeta;
}

if (mOre == Blocks.lapis_ore) {
return TwilightForestMod.GT_lapisOreMeta;
}

if (mOre == Blocks.emerald_ore) {
return TwilightForestMod.GT_emeraldOreMeta;
}
if (mOre == Blocks.diamond_ore) {
return TwilightForestMod.GT_diamondOreMeta;
}

return -1;
}

public boolean placeGTOre(World aWorld, int aX, int aY, int aZ, Block mcOreBlock) {

int mappedMeta = getMappedGTMetaForOre(mcOreBlock);
if (mappedMeta <= 0) {
return false;
}
return GT_TileEntity_Ores.setOreBlock(aWorld, aX, aY, aZ, mappedMeta, TwilightForestMod.GT_useSmallOres, true);

}

}
58 changes: 57 additions & 1 deletion src/main/java/twilightforest/world/TFGenCaveStalactite.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@
import net.minecraft.init.Blocks;
import net.minecraft.world.World;

import twilightforest.TFFeature;
import twilightforest.TwilightForestMod;
import twilightforest.gt_integration.GT_Integration_Utils;

public class TFGenCaveStalactite extends TFGenerator {

public static TFGenCaveStalactite diamond = new TFGenCaveStalactite(Blocks.diamond_ore, 0.5F, 4, 16);
Expand All @@ -24,6 +28,8 @@ public class TFGenCaveStalactite extends TFGenerator {
public int maxLength;
public int minHeight;

public boolean doOreGen;

/**
* Initializes a stalactite builder. Actually also makes stalagmites
*
Expand Down Expand Up @@ -153,6 +159,11 @@ public boolean generate(World world, Random random, int x, int y, int z) {

public boolean makeSpike(World world, Random random, int x, int y, int z, int maxLength) {

// Disable ore gen
if (!doOreGen) {
blockID = Blocks.stone;
}

int diameter = (int) (maxLength / 4.5); // diameter of the base

// let's see...
Expand Down Expand Up @@ -180,12 +191,57 @@ public boolean makeSpike(World world, Random random, int x, int y, int z, int ma
}

for (int dy = 0; dy != (spikeLength * dir); dy += dir) {
setBlock(world, x + dx, y + dy, z + dz, blockID);

// Density
if (TFFeature.getRandom(random, TwilightForestMod.stalactiteOrePopulationDensity)) {

// Just set mcOre
if (TwilightForestMod.gregifyStalactiteOres && doOreGen) {
// Stone block before place gtOre

// Glowstone Stalactite
if (this.blockID == Blocks.glowstone) {
setBlock(world, x + dx, y + dy, z + dz, Blocks.glowstone);

} else {
setBlock(world, x + dx, y + dy, z + dz, Blocks.stone);
// Slap GT ore over
GT_Integration_Utils.doPlaceGTOre(world, x + dx, y + dy, z + dz, blockID);

}

} else {
// Place MC Ore
setBlock(world, x + dx, y + dy, z + dz, blockID);
}

} else {
// No ore just place stone
setBlock(world, x + dx, y + dy, z + dz, Blocks.stone);
}

}
}
}

return true;
}

public static void configStalactites() {

diamond.setDoOreGen(TwilightForestMod.diamondOreStal);
lapis.setDoOreGen(TwilightForestMod.lapisOreStal);
emerald.setDoOreGen(TwilightForestMod.emeraldOreStal);
gold.setDoOreGen(TwilightForestMod.goldOreStal);
redstone.setDoOreGen(TwilightForestMod.redstoneOreStal);
iron.setDoOreGen(TwilightForestMod.ironOreStal);
coal.setDoOreGen(TwilightForestMod.coalOreStal);
glowstone.setDoOreGen(TwilightForestMod.glowstoneStal);

}

public void setDoOreGen(boolean doGenOre) {
this.doOreGen = doGenOre;
}

}