Skip to content

Commit

Permalink
Merge pull request #904 from Team-RTG/1.10.2/tweaks
Browse files Browse the repository at this point in the history
Gradle stuff & ported tweaks from 1.8.9.
  • Loading branch information
whichonespink44 authored Aug 19, 2016
2 parents 4716ca4 + 8f04bf3 commit 05ddcf4
Show file tree
Hide file tree
Showing 12 changed files with 138 additions and 69 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ ext.ref = parseprops(file('build.properties'))
ext.ref.mod_deps = parseprops(file('mod_deps.properties'))

group = ref.package_base + '.' + ref.mod_id
archivesBaseName = ref.mod_id
archivesBaseName = ref.mod_abbr
// remove travis stuff from version for now because we aren't using it and it was a mess. -srs
version = ref.mc_version + '-' + ref.mod_version

Expand Down
3 changes: 2 additions & 1 deletion build.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# TODO: should maybe find a way to update mod_version automatically in the future (perhaps from git), but not neccessary.
# mod_author has to be in ""'s (and comma-separated, ie: "","",""), because array[]
mod_id=RTG
mod_id=rtg
mod_abbr=RTG
mod_name=Realistic Terrain Generation
mod_desc=Adds a new world type which generates realistic terrain for Overworld biomes.
mod_version=4.1.1.2-snapshot-1
Expand Down
39 changes: 27 additions & 12 deletions etc/config/RTG/rtg.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -214,31 +214,46 @@ mineshafts {


plateaus {
# Comma-separated list of meta values for the clay blocks used in the Mesa Bryce biome.
# -1 = Hardened Clay; 0-15 = Stained Clay
# The block to use for Mesa & Savanna plateau gradients. Defaults to stained hardened clay.
# This can be any block, but it works best with blocks that have multiple colours, such as stained hardened clay.
# The various 'meta' options in this section will use this block to configure the plateau gradients.
# [default: minecraft:stained_hardened_clay]
S:"Gradient Plateau Block ID"=minecraft:stained_hardened_clay

# Comma-separated list of meta values for the gradient plateau blocks used in the Mesa Bryce biome.
# -1 = Plateau block; 0-15 = Plateau gradient block
# 0 = White; 1 = Orange; 2 = Magenta; 3 = Light Blue; 4 = Yellow; 5 = Lime; 6 = Pink; 7 = Gray
# 8 = Light Gray; 9 = Cyan; 10 = Purple; 11 = Blue; 12 = Brown; 13 = Green; 14 = Red; 15 = Black
# [default: -1,-1,0,1,0,0,0,14,0,8,0,1,8,0,-1,0,14,0,0,14,0,0,8]
S:"Mesa Bryce Clay Colours"=-1,-1,0,1,0,0,0,14,0,8,0,1,8,0,-1,0,14,0,0,14,0,0,8
S:"Gradient Plateau Block Meta Values (Mesa Bryce)"=-1,-1,0,1,0,0,0,14,0,8,0,1,8,0,-1,0,14,0,0,14,0,0,8

# Comma-separated list of meta values for the clay blocks used in the Mesa biome variants (doesn't include Mesa Bryce).
# -1 = Hardened Clay; 0-15 = Stained Clay
# Comma-separated list of meta values for the gradient plateau blocks used in the Mesa biome variants (doesn't include Mesa Bryce).
# -1 = Plateau block; 0-15 = Plateau gradient block
# 0 = White; 1 = Orange; 2 = Magenta; 3 = Light Blue; 4 = Yellow; 5 = Lime; 6 = Pink; 7 = Gray
# 8 = Light Gray; 9 = Cyan; 10 = Purple; 11 = Blue; 12 = Brown; 13 = Green; 14 = Red; 15 = Black
# [default: 0,1,8,14,1,8]
S:"Mesa Clay Colours"=0,1,8,14,1,8
S:"Gradient Plateau Block Meta Values (Mesa)"=0,1,8,14,1,8

# Comma-separated list of meta values for the clay blocks used in the Savanna biome variants.
# -1 = Hardened Clay; 0-15 = Stained Clay
# Comma-separated list of meta values for the gradient plateau blocks used in the Savanna biome variants.
# -1 = Plateau block; 0-15 = Plateau gradient block
# 0 = White; 1 = Orange; 2 = Magenta; 3 = Light Blue; 4 = Yellow; 5 = Lime; 6 = Pink; 7 = Gray
# 8 = Light Gray; 9 = Cyan; 10 = Purple; 11 = Blue; 12 = Brown; 13 = Green; 14 = Red; 15 = Black
# [default: 0,0,0,0,8,8,12,12,8,0,8,12,12,8,12,8,0,0,8,12,12]
S:"Savanna Clay Colours"=0,0,0,0,8,8,12,12,8,0,8,12,12,8,12,8,0,0,8,12,12
S:"Gradient Plateau Block Meta Values (Savanna)"=0,0,0,0,8,8,12,12,8,0,8,12,12,8,12,8,0,0,8,12,12

# An extra block to use for Mesa & Savanna plateau gradients. Defaults to hardened clay.
# When configuring the various 'meta' options in this section, use a value of '-1' to reference this block.
# [default: minecraft:hardened_clay]
S:"Plateau Block ID"=minecraft:hardened_clay

# The meta value of the plateau block.
# [range: 0 ~ 15, default: 0]
I:"Plateau Block Meta Value"=0

# If set to TRUE, Savanna biome variants will mostly use stone/cobblestone instead of stained hardened clay for cliffs and plateaus.
# Savanna Plateau M will always use stained hardened clay.
# If set to TRUE, Savanna biome variants will mostly use stone/cobblestone instead of gradient blocks for cliffs and plateaus.
# Savanna Plateau M will always use gradient blocks.
# [default: true]
B:"Use stone instead of clay for most Savanna biome variants"=true
B:"Use stone for most Savanna biome variants"=true
}


Expand Down
5 changes: 3 additions & 2 deletions src/main/java/rtg/RTG.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package rtg;

import java.io.File;
import java.util.ArrayList;

import net.minecraft.world.gen.structure.MapGenStructureIO;
Expand Down Expand Up @@ -61,7 +62,7 @@ public void fmlLifeCycleEvent(FMLPreInitializationEvent event) {

instance = this;

worldtype = new WorldTypeRTG("RTG");
worldtype = new WorldTypeRTG(ModInfo.WORLD_TYPE);

this.registerStructures();

Expand All @@ -76,7 +77,7 @@ public void fmlLifeCycleEvent(FMLPreInitializationEvent event) {
BiomeConfigManager.initBiomeConfigs();
MinecraftForge.EVENT_BUS.post(new BiomeConfigEvent.Post());

configPath = event.getModConfigurationDirectory() + "/RTG/";
configPath = event.getModConfigurationDirectory() + File.separator + ModInfo.CONFIG_DIRECTORY + File.separator;
ConfigManager.init(configPath);
}

Expand Down
79 changes: 54 additions & 25 deletions src/main/java/rtg/config/rtg/ConfigRTG.java
Original file line number Diff line number Diff line change
Expand Up @@ -134,13 +134,18 @@ public class ConfigRTG {
// Plateaus
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

public static String mesaClayColourString = "0,1,8,14,1,8";
public static String mesaBryceClayColourString = "-1,-1,0,1,0,0,0,14,0,8,0,1,8,0,-1,0,14,0,0,14,0,0,8";
public static String savannaClayColourString = "0,0,0,0,8,8,12,12,8,0,8,12,12,8,12,8,0,0,8,12,12";
public static String plateauGradientBlockId = "minecraft:stained_hardened_clay";

public static byte[] mesaClayColours = getClayColourMetasFromConfigString(mesaClayColourString);
public static byte[] mesaBryceClayColours = getClayColourMetasFromConfigString(mesaBryceClayColourString);
public static byte[] savannaClayColours = getClayColourMetasFromConfigString(savannaClayColourString);
public static String plateauBlockId = "minecraft:hardened_clay";
public static int plateauBlockByte = 0;

public static String mesaGradientString = "0,1,8,14,1,8";
public static String mesaBryceGradientString = "-1,-1,0,1,0,0,0,14,0,8,0,1,8,0,-1,0,14,0,0,14,0,0,8";
public static String savannaGradientString = "0,0,0,0,8,8,12,12,8,0,8,12,12,8,12,8,0,0,8,12,12";

public static byte[] mesaPlateauBlockMetas = getPlateauGradientBlockMetasFromConfigString(mesaGradientString);
public static byte[] mesaBrycePlateauBlockMetas = getPlateauGradientBlockMetasFromConfigString(mesaBryceGradientString);
public static byte[] savannaPlateauBlockMetas = getPlateauGradientBlockMetasFromConfigString(savannaGradientString);

public static boolean stoneSavannas = true;

Expand Down Expand Up @@ -489,34 +494,58 @@ public static void init(File configFile) {
// Plateaus
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

mesaClayColours = getClayColourMetasFromConfigString(config.getString(
"Mesa Clay Colours",
plateauGradientBlockId = config.getString(
"Gradient Plateau Block ID",
"Plateaus",
plateauGradientBlockId,
"The block to use for Mesa & Savanna plateau gradients. Defaults to stained hardened clay." +
Configuration.NEW_LINE +
"This can be any block, but it works best with blocks that have multiple colours, such as stained hardened clay." +
Configuration.NEW_LINE +
"The various 'meta' options in this section will use this block to configure the plateau gradients." +
Configuration.NEW_LINE
);

mesaBrycePlateauBlockMetas = getPlateauGradientBlockMetasFromConfigString(config.getString(
"Gradient Plateau Block Meta Values (Mesa Bryce)",
"Plateaus",
mesaClayColourString,
getPlateauClayColourComment("Mesa biome variants (doesn't include Mesa Bryce)")
mesaBryceGradientString,
getPlateauGradientBlockMetasComment("Mesa Bryce biome")
));

mesaBryceClayColours = getClayColourMetasFromConfigString(config.getString(
"Mesa Bryce Clay Colours",
mesaPlateauBlockMetas = getPlateauGradientBlockMetasFromConfigString(config.getString(
"Gradient Plateau Block Meta Values (Mesa)",
"Plateaus",
mesaBryceClayColourString,
getPlateauClayColourComment("Mesa Bryce biome")
mesaGradientString,
getPlateauGradientBlockMetasComment("Mesa biome variants (doesn't include Mesa Bryce)")
));

savannaClayColours = getClayColourMetasFromConfigString(config.getString(
"Savanna Clay Colours",
savannaPlateauBlockMetas = getPlateauGradientBlockMetasFromConfigString(config.getString(
"Gradient Plateau Block Meta Values (Savanna)",
"Plateaus",
savannaClayColourString,
getPlateauClayColourComment("Savanna biome variants")
savannaGradientString,
getPlateauGradientBlockMetasComment("Savanna biome variants")
));

plateauBlockId = config.getString(
"Plateau Block ID",
"Plateaus",
plateauBlockId,
"An extra block to use for Mesa & Savanna plateau gradients. Defaults to hardened clay." +
Configuration.NEW_LINE +
"When configuring the various 'meta' options in this section, use a value of '-1' to reference this block." +
Configuration.NEW_LINE
);

plateauBlockByte = config.getInt("Plateau Block Meta Value", "Plateaus", plateauBlockByte, 0, 15, "The meta value of the plateau block." + Configuration.NEW_LINE);

stoneSavannas = config.getBoolean(
"Use stone instead of clay for most Savanna biome variants",
"Use stone for most Savanna biome variants",
"Plateaus",
stoneSavannas,
"If set to TRUE, Savanna biome variants will mostly use stone/cobblestone instead of stained hardened clay for cliffs and plateaus."
"If set to TRUE, Savanna biome variants will mostly use stone/cobblestone instead of gradient blocks for cliffs and plateaus."
+ Configuration.NEW_LINE +
"Savanna Plateau M will always use stained hardened clay."
"Savanna Plateau M will always use gradient blocks."
+ Configuration.NEW_LINE
);

Expand Down Expand Up @@ -865,7 +894,7 @@ private static boolean enableVillageTweaks() {
return enableVillageModifications;
}

private static byte[] getClayColourMetasFromConfigString(String configString)
private static byte[] getPlateauGradientBlockMetasFromConfigString(String configString)
{
String[] strings = configString.split(",");
ArrayList<Byte> byteList = new ArrayList<Byte>(){};
Expand All @@ -881,12 +910,12 @@ private static byte[] getClayColourMetasFromConfigString(String configString)
return ArrayUtils.toPrimitive(bytes);
}

private static String getPlateauClayColourComment(String biomeName)
private static String getPlateauGradientBlockMetasComment(String biomeName)
{
String comment =
"Comma-separated list of meta values for the clay blocks used in the " + biomeName + "."
"Comma-separated list of meta values for the gradient plateau blocks used in the " + biomeName + "."
+ Configuration.NEW_LINE +
"-1 = Hardened Clay; 0-15 = Stained Clay"
"-1 = Plateau block; 0-15 = Plateau gradient block"
+ Configuration.NEW_LINE +
"0 = White; 1 = Orange; 2 = Magenta; 3 = Light Blue; 4 = Yellow; 5 = Lime; 6 = Pink; 7 = Gray"
+ Configuration.NEW_LINE +
Expand Down
33 changes: 17 additions & 16 deletions src/main/java/rtg/event/EventManagerRTG.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
package rtg.event;

import java.util.ArrayList;
import java.util.Random;
import java.util.WeakHashMap;

import net.minecraft.block.BlockSapling;
import net.minecraft.block.state.IBlockState;
import net.minecraft.init.Blocks;
import net.minecraft.world.World;
import net.minecraft.world.biome.Biome;

import net.minecraftforge.common.MinecraftForge;
Expand Down Expand Up @@ -239,25 +238,27 @@ public void saplingGrowTreeRTG(SaplingGrowTreeEvent event) {
return;
}

Random rand = event.getRand();

// Should we generate a vanilla tree instead?
if (rand.nextInt(ConfigRTG.rtgTreeChance) != 0) {
if (event.getRand().nextInt(ConfigRTG.rtgTreeChance) != 0) {

Logger.debug("Skipping RTG tree generation.");
return;
}

World world = event.getWorld();
IBlockState saplingBlock = event.getWorld().getBlockState(event.getPos());

IBlockState saplingBlock = world.getBlockState(event.getPos());
int saplingMeta = SaplingUtil.getMetaFromState(saplingBlock);
// Are we dealing with a sapling? Sounds like a silly question, but apparently it's one that needs to be asked.
if (!(saplingBlock.getBlock() instanceof BlockSapling)) {
Logger.warn("Could not get sapling meta from non-sapling BlockState (%s).", saplingBlock.getBlock().getLocalizedName());
return;
}

WorldChunkManagerRTG cmr = (WorldChunkManagerRTG) world.getBiomeProvider();
WorldChunkManagerRTG cmr = (WorldChunkManagerRTG) event.getWorld().getBiomeProvider();
//Biome bgg = cmr.getBiomeGenAt(x, z);
Biome bgg = world.getBiome(event.getPos());
Biome bgg = event.getWorld().getBiome(event.getPos());
RealisticBiomeBase rb = RealisticBiomeBase.getBiome(BiomeUtils.getId(bgg));
ArrayList<TreeRTG> biomeTrees = rb.rtgTrees;
int saplingMeta = SaplingUtil.getMetaFromState(saplingBlock);

Logger.debug("Biome = %s", BiomeUtils.getName(rb.baseBiome));
Logger.debug("Ground Sapling Block = %s", saplingBlock.getBlock().getLocalizedName());
Expand Down Expand Up @@ -288,20 +289,20 @@ public void saplingGrowTreeRTG(SaplingGrowTreeEvent event) {
if (validTrees.size() > 0) {

// Get a random tree from the list of valid trees.
TreeRTG tree = validTrees.get(rand.nextInt(validTrees.size()));
TreeRTG tree = validTrees.get(event.getRand().nextInt(validTrees.size()));

Logger.debug("Tree = %s", tree.getClass().getName());

// Set the trunk size if min/max values have been set.
if (tree.minTrunkSize > 0 && tree.maxTrunkSize > tree.minTrunkSize) {

tree.trunkSize = RandomUtil.getRandomInt(rand, tree.minTrunkSize, tree.maxTrunkSize);
tree.trunkSize = RandomUtil.getRandomInt(event.getRand(), tree.minTrunkSize, tree.maxTrunkSize);
}

// Set the crown size if min/max values have been set.
if (tree.minCrownSize > 0 && tree.maxCrownSize > tree.minCrownSize) {

tree.crownSize = RandomUtil.getRandomInt(rand, tree.minCrownSize, tree.maxCrownSize);
tree.crownSize = RandomUtil.getRandomInt(event.getRand(), tree.minCrownSize, tree.maxCrownSize);
}

/*
Expand All @@ -312,7 +313,7 @@ public void saplingGrowTreeRTG(SaplingGrowTreeEvent event) {
*/
int oldFlag = tree.generateFlag;
tree.generateFlag = 3;
boolean generated = tree.generate(world, rand, event.getPos());
boolean generated = tree.generate(event.getWorld(), event.getRand(), event.getPos());
tree.generateFlag = oldFlag;

if (generated) {
Expand All @@ -321,8 +322,8 @@ public void saplingGrowTreeRTG(SaplingGrowTreeEvent event) {
event.setResult(Event.Result.DENY);

// Sometimes we have to remove the sapling manually because some trees grow around it, leaving the original sapling.
if (world.getBlockState(event.getPos()) == saplingBlock) {
world.setBlockState(event.getPos(), Blocks.AIR.getDefaultState(), 2);
if (event.getWorld().getBlockState(event.getPos()) == saplingBlock) {
event.getWorld().setBlockState(event.getPos(), Blocks.AIR.getDefaultState(), 2);
}
}
}
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/rtg/reference/ModInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,6 @@ public class ModInfo {
public static final String MOD_DEPS = "";
public static final String PROXY_COMMON = "rtg.proxy.CommonProxy";
public static final String PROXY_CLIENT = "rtg.proxy.ClientProxy";
public static final String WORLD_TYPE = "RTG"; // Let's keep this uppercase. - Pink
public static final String CONFIG_DIRECTORY = "RTG"; // Let's keep this uppercase too. - Pink
}
13 changes: 8 additions & 5 deletions src/main/java/rtg/util/CanyonColour.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
import java.util.HashMap;
import java.util.Map;

import net.minecraft.block.Block;
import net.minecraft.block.state.IBlockState;
import net.minecraft.init.Blocks;

import rtg.config.rtg.ConfigRTG;

Expand All @@ -15,14 +15,17 @@
*/
public enum CanyonColour {

MESA(ConfigRTG.mesaClayColours),
MESA_BRYCE(ConfigRTG.mesaBryceClayColours),
SAVANNA(ConfigRTG.savannaClayColours);
MESA(ConfigRTG.mesaPlateauBlockMetas),
MESA_BRYCE(ConfigRTG.mesaBrycePlateauBlockMetas),
SAVANNA(ConfigRTG.savannaPlateauBlockMetas);

private static Map<CanyonColour, IBlockState[]> colourBlocks = new HashMap<CanyonColour, IBlockState[]>();
private static OpenSimplexNoise simplex;
private byte[] bytes;

private static IBlockState plateauBlock = Block.getBlockFromName(ConfigRTG.plateauBlockId).getStateFromMeta(ConfigRTG.plateauBlockByte);
private static Block plateauGradientBlock = Block.getBlockFromName(ConfigRTG.plateauGradientBlockId);

CanyonColour(byte[] bytes) {
this.bytes = bytes;
}
Expand All @@ -39,7 +42,7 @@ public static void init(long l) {
for (int i = 0; i < 256; i++) {

byte b = colour.bytes[i % colour.bytes.length];
c[i] = (b == -1) ? Blocks.HARDENED_CLAY.getDefaultState() : Blocks.STAINED_HARDENED_CLAY.getStateFromMeta(b);
c[i] = (b == -1) ? plateauBlock : plateauGradientBlock.getStateFromMeta(b);
}

colourBlocks.put(colour, c);
Expand Down
16 changes: 14 additions & 2 deletions src/main/java/rtg/util/SaplingUtil.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package rtg.util;

import net.minecraft.block.BlockPlanks;
import net.minecraft.block.BlockSapling;
import net.minecraft.block.state.IBlockState;
import net.minecraft.init.Blocks;
Expand All @@ -9,7 +8,20 @@ public class SaplingUtil {

public static int getMetaFromState(IBlockState state) {

return ((BlockPlanks.EnumType)state.getValue(BlockSapling.TYPE)).getMetadata();
try {

if (!(state.getBlock() instanceof BlockSapling)) {
Logger.warn("Could not get sapling meta from non-sapling BlockState (%s).", state.getBlock().getLocalizedName());
return 0;
}

return state.getValue(BlockSapling.TYPE).getMetadata();
}
catch (Exception e) {

Logger.warn("Could not get sapling meta from state. Reason: " + e.getMessage());
return 0;
}
}

public static IBlockState getSaplingFromLeaves(IBlockState leavesBlock) {
Expand Down
Loading

0 comments on commit 05ddcf4

Please sign in to comment.