Skip to content

Commit

Permalink
added render distance limit to most features
Browse files Browse the repository at this point in the history
  • Loading branch information
octarine-noise committed Apr 28, 2015
1 parent a2baba5 commit 68d50a0
Show file tree
Hide file tree
Showing 13 changed files with 46 additions and 13 deletions.
Expand Up @@ -13,6 +13,7 @@
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.RenderBlocks;
import net.minecraft.client.renderer.Tessellator;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.init.Blocks;
import net.minecraft.util.IIcon;
import net.minecraft.util.MathHelper;
Expand Down Expand Up @@ -620,5 +621,11 @@ public boolean renderStandardBlock(Block p_147784_1_, int p_147784_2_, int p_147
}
}


protected int getCameraDistance(int x, int y, int z) {
EntityLivingBase camera = Minecraft.getMinecraft().renderViewEntity;
int result = Math.abs(x - MathHelper.floor_double(camera.posX));
result += Math.abs(y - MathHelper.floor_double(camera.posY));
result += Math.abs(z - MathHelper.floor_double(camera.posZ));
return result;
}
}
Expand Up @@ -36,7 +36,7 @@ public RenderBlockCactus() {
}

public boolean isBlockAccepted(IBlockAccess blockAccess, int x, int y, int z, Block block, int original) {
return Config.cactusEnabled && block == Blocks.cactus;
return Config.cactusEnabled && block == Blocks.cactus && getCameraDistance(x, y, z) <= Config.cactusDistance;
}

public boolean renderWorldBlock(IBlockAccess world, int x, int y, int z, Block block, int modelId, RenderBlocks renderer) {
Expand Down
Expand Up @@ -31,6 +31,7 @@ public class RenderBlockDirtWithAlgae extends RenderBlockAOBase implements IRend

public boolean isBlockAccepted(IBlockAccess blockAccess, int x, int y, int z, Block block, int original) {
if (!Config.algaeEnabled) return false;
if (getCameraDistance(x, y, z) > Config.algaeDistance) return false;
if (!Config.dirt.matchesID(block)) return false;
if (!Config.algaeBiomeList.contains(blockAccess.getBiomeGenForCoords(x, z).biomeID)) return false;
if (blockAccess.getBlock(x, y + 1, z).getMaterial() != Material.water) return false;
Expand Down
Expand Up @@ -40,7 +40,7 @@ public enum RenderMode { DEFAULT, TFC };


public boolean isBlockAccepted(IBlockAccess blockAccess, int x, int y, int z, Block block, int original) {
return Config.grass.matchesID(block);
return Config.grass.matchesID(block) && getCameraDistance(x, y, z) <= Config.grassDistance;
}

public boolean renderWorldBlock(IBlockAccess world, int x, int y, int z, Block block, int modelId, RenderBlocks renderer) {
Expand Down
Expand Up @@ -30,6 +30,7 @@ public class RenderBlockLeaves extends RenderBlockAOBase implements IRenderBlock
public boolean isBlockAccepted(IBlockAccess blockAccess, int x, int y, int z, Block block, int original) {
if (!Config.leavesEnabled) return false;
if (original > 0 && original < 42) return false;
if (getCameraDistance(x, y, z) > Config.leavesDistance) return false;
return Config.leaves.matchesID(block) && !isBlockSurrounded(blockAccess, x, y, z);
}

Expand Down
Expand Up @@ -28,7 +28,7 @@ public RenderBlockLilypad() {
}

public boolean isBlockAccepted(IBlockAccess blockAccess, int x, int y, int z, Block block, int original) {
return Config.lilypadEnabled && block == Blocks.waterlily;
return Config.lilypadEnabled && block == Blocks.waterlily && getCameraDistance(x, y, z) <= Config.lilypadDistance;
}

public boolean renderWorldBlock(IBlockAccess world, int x, int y, int z, Block block, int modelId, RenderBlocks renderer) {
Expand Down
Expand Up @@ -24,7 +24,7 @@ public RenderBlockLogs() {
}

public boolean isBlockAccepted(IBlockAccess blockAccess, int x, int y, int z, Block block, int original) {
return Config.logsEnabled && Config.logs.matchesID(block);
return Config.logsEnabled && Config.logs.matchesID(block) && getCameraDistance(x, y, z) <= Config.logsDistance;
}

public boolean renderWorldBlock(IBlockAccess world, int x, int y, int z, Block block, int modelId, RenderBlocks renderer) {
Expand Down
Expand Up @@ -27,6 +27,7 @@ public class RenderBlockMycelium extends RenderBlockAOBase implements IRenderBlo
public boolean isBlockAccepted(IBlockAccess blockAccess, int x, int y, int z, Block block, int original) {
if (!Config.myceliumEnabled) return false;
if (block != Blocks.mycelium) return false;
if (getCameraDistance(x, y, z) > Config.grassDistance) return false;
if (!blockAccess.isAirBlock(x, y + 1, z)) return false;
return true;
}
Expand Down
Expand Up @@ -27,6 +27,7 @@ public class RenderBlockNetherrack extends RenderBlockAOBase implements IRenderB
public boolean isBlockAccepted(IBlockAccess blockAccess, int x, int y, int z, Block block, int original) {
if (!Config.netherrackEnabled) return false;
if (block != Blocks.netherrack) return false;
if (getCameraDistance(x, y, z) > Config.netherrackDistance) return false;
if (!blockAccess.isAirBlock(x, y - 1, z)) return false;
return true;
}
Expand Down
Expand Up @@ -33,6 +33,7 @@ public class RenderBlockReed extends RenderBlockAOBase implements IRenderBlockDe

public boolean isBlockAccepted(IBlockAccess blockAccess, int x, int y, int z, Block block, int original) {
if (!Config.reedEnabled) return false;
if (getCameraDistance(x, y, z) > Config.reedDistance) return false;
if (!(Config.dirt.matchesID(block))) return false;
if (!Config.reedBiomeList.contains(blockAccess.getBiomeGenForCoords(x, z).biomeID)) return false;
if (blockAccess.getBlock(x, y + 1, z).getMaterial() != Material.water) return false;
Expand Down
Expand Up @@ -32,6 +32,7 @@ public class RenderBlockSandWithCoral extends RenderBlockAOBase implements IRend
public boolean isBlockAccepted(IBlockAccess blockAccess, int x, int y, int z, Block block, int original) {
if (!Config.coralEnabled) return false;
if (block != Blocks.sand) return false;
if (getCameraDistance(x, y, z) > Config.coralDistance) return false;
if (!Config.coralBiomeList.contains(blockAccess.getBiomeGenForCoords(x, z).biomeID)) return false;
int terrainVariation = MathHelper.floor_double((noise.func_151605_a(x * 0.1, z * 0.1) + 1.0) * 32.0);
return terrainVariation < Config.coralPopulation;
Expand Down
34 changes: 26 additions & 8 deletions src/main/java/mods/betterfoliage/common/config/Config.java
Expand Up @@ -41,13 +41,15 @@ public enum Category {

// extracted config values
public static boolean leavesEnabled;
public static int leavesDistance;
public static boolean leavesSkew;
public static boolean leavesDense;
public static double leavesHOffset;
public static double leavesVOffset;
public static double leavesSize;

public static boolean grassEnabled;
public static int grassDistance;
public static boolean grassUseGenerated;
public static double grassHOffset;
public static double grassHeightMin;
Expand All @@ -58,26 +60,31 @@ public enum Category {
public static boolean grassSnowEnabled;

public static boolean cactusEnabled;
public static int cactusDistance;

public static boolean lilypadEnabled;
public static int lilypadDistance;
public static double lilypadHOffset;
public static int lilypadChance;

public static boolean reedEnabled;
public static int reedDistance;
public static double reedHOffset;
public static double reedHeightMin;
public static double reedHeightMax;
public static int reedPopulation;
public static boolean reedShaderWind;

public static boolean algaeEnabled;
public static int algaeDistance;
public static double algaeHOffset;
public static double algaeSize;
public static double algaeHeightMin;
public static double algaeHeightMax;
public static int algaePopulation;

public static boolean coralEnabled;
public static int coralDistance;
public static boolean coralShallowWater;
public static int coralPopulation;
public static int coralChance;
Expand Down Expand Up @@ -110,6 +117,7 @@ public enum Category {
public static int soulFXTrailDensity;

public static boolean netherrackEnabled;
public static int netherrackDistance;
public static double netherrackHOffset;
public static double netherrackHeightMin;
public static double netherrackHeightMax;
Expand All @@ -119,6 +127,7 @@ public enum Category {
public static boolean ctxGrassAggressiveEnabled;

public static boolean logsEnabled;
public static int logsDistance;
public static double logsSmallRadius;
public static double logsLargeRadius;
public static boolean logsConnect;
Expand All @@ -140,13 +149,15 @@ public static void readConfig(File configFile) {
/** Extract the config properties to static value fields for quick access */
public static void updateValues() {
leavesEnabled = getBoolean(Category.extraLeaves, "enabled", true, "betterfoliage.enabled");
leavesDistance = getInt(Category.extraLeaves, "distance", 1000, 1, 1000, "betterfoliage.distance");
leavesSkew = getBoolean(Category.extraLeaves, "skewMode", false, "betterfoliage.leavesMode");
leavesHOffset = getDouble(Category.extraLeaves, "hOffset", 0.2, 0.0, 0.4, "betterfoliage.hOffset");
leavesVOffset = getDouble(Category.extraLeaves, "vOffset", 0.1, 0.0, 0.4, "betterfoliage.vOffset");
leavesSize = getDouble(Category.extraLeaves, "size", 1.4, 0.75, 2.5, "betterfoliage.size");
leavesDense = getBoolean(Category.extraLeaves, "dense", false, "betterfoliage.leaves.dense");

grassEnabled = getBoolean(Category.shortGrass, "enabled", true, "betterfoliage.shortGrass.grassEnabled");
grassDistance = getInt(Category.shortGrass, "distance", 1000, 1, 1000, "betterfoliage.distance");
grassHOffset = getDouble(Category.shortGrass, "hOffset", 0.2, 0.0, 0.4, "betterfoliage.hOffset");
grassHeightMin = getDouble(Category.shortGrass, "heightMin", 0.6, 0.1, 2.5, "betterfoliage.minHeight");
grassHeightMax = getDouble(Category.shortGrass, "heightMax", 0.8, 0.1, 2.5, "betterfoliage.maxHeight");
Expand All @@ -158,12 +169,15 @@ public static void updateValues() {
grassSnowEnabled = getBoolean(Category.shortGrass, "snowEnabled", true, "betterfoliage.shortGrass.grassSnowEnabled");

cactusEnabled = getBoolean(Category.cactus, "enabled", true, "betterfoliage.enabled");
cactusDistance = getInt(Category.cactus, "distance", 1000, 1, 1000, "betterfoliage.distance");

lilypadEnabled = getBoolean(Category.lilypad, "enabled", true, "betterfoliage.enabled");
lilypadDistance = getInt(Category.lilypad, "distance", 1000, 1, 1000, "betterfoliage.distance");
lilypadHOffset = getDouble(Category.lilypad, "hOffset", 0.1, 0.0, 0.25, "betterfoliage.hOffset");
lilypadChance = getInt(Category.lilypad, "flowerChance", 16, 0, 64, "betterfoliage.lilypad.flowerChance");

reedEnabled = getBoolean(Category.reed, "enabled", true, "betterfoliage.enabled");
reedDistance = getInt(Category.reed, "distance", 1000, 1, 1000, "betterfoliage.distance");
reedHOffset = getDouble(Category.reed, "hOffset", 0.2, 0.0, 0.4, "betterfoliage.hOffset");
reedHeightMin = getDouble(Category.reed, "heightMin", 2.0, 1.5, 3.5, "betterfoliage.minHeight");
reedHeightMax = getDouble(Category.reed, "heightMax", 2.5, 1.5, 3.5, "betterfoliage.maxHeight");
Expand All @@ -173,6 +187,7 @@ public static void updateValues() {
reedShaderWind = getBoolean(Category.reed, "shaderWind", true, "betterfoliage.shaderWind");

algaeEnabled = getBoolean(Category.algae, "enabled", true, "betterfoliage.enabled");
algaeDistance = getInt(Category.algae, "distance", 1000, 1, 1000, "betterfoliage.distance");
algaeHOffset = getDouble(Category.algae, "hOffset", 0.1, 0.0, 0.25, "betterfoliage.hOffset");
algaeSize = getDouble(Category.algae, "size", 1.0, 0.5, 1.5, "betterfoliage.size");
algaeHeightMin = getDouble(Category.algae, "heightMin", 0.5, 0.1, 1.5, "betterfoliage.minHeight");
Expand All @@ -182,6 +197,7 @@ public static void updateValues() {
algaeBiomeList = getIntList(Category.algae, "algaeBiomeList", algaeBiomeList, "betterfoliage.algae.biomeList");

coralEnabled = getBoolean(Category.coral, "enabled", true, "betterfoliage.enabled");
coralDistance = getInt(Category.coral, "distance", 1000, 1, 1000, "betterfoliage.distance");
coralShallowWater = getBoolean(Category.coral, "shallowWater", false, "betterfoliage.coral.shallowWater");
coralHOffset = getDouble(Category.coral, "hOffset", 0.2, 0.0, 0.4, "betterfoliage.hOffset");
coralVOffset = getDouble(Category.coral, "vOffset", 0.1, 0.0, 0.4, "betterfoliage.vOffset");
Expand Down Expand Up @@ -215,6 +231,7 @@ public static void updateValues() {
soulFXTrailDensity = getInt(Category.risingSoul, "trailDensity", 3, 1, 16, "betterfoliage.risingSoul.trailDensity");

netherrackEnabled = getBoolean(Category.netherrack, "enabled", true, "betterfoliage.enabled");
netherrackDistance = getInt(Category.netherrack, "distance", 1000, 1, 1000, "betterfoliage.distance");
netherrackHOffset = getDouble(Category.netherrack, "hOffset", 0.2, 0.0, 0.4, "betterfoliage.hOffset");
netherrackHeightMin = getDouble(Category.netherrack, "heightMin", 0.6, 0.1, 1.5, "betterfoliage.minHeight");
netherrackHeightMax = getDouble(Category.netherrack, "heightMax", 0.8, 0.1, 1.5, "betterfoliage.maxHeight");
Expand All @@ -225,6 +242,7 @@ public static void updateValues() {
ctxGrassAggressiveEnabled= getBoolean(Category.connectedGrass, "aggressive", true, "betterfoliage.connectedGrass.aggressive");

logsEnabled = getBoolean(Category.roundLogs, "enabled", true, "betterfoliage.enabled");
logsDistance = getInt(Category.roundLogs, "distance", 1000, 1, 1000, "betterfoliage.distance");
logsSmallRadius = getDouble(Category.roundLogs, "smallRadius", 0.25, 0.0, 0.5, "betterfoliage.roundLogs.smallRadius");
logsLargeRadius = getDouble(Category.roundLogs, "largeRadius", 0.45, 0.0, 0.5, "betterfoliage.roundLogs.largeRadius");
logsConnect = getBoolean(Category.roundLogs, "connect", true, "betterfoliage.roundLogs.connect");
Expand All @@ -244,17 +262,17 @@ public static void updateValues() {

for (Category category : Category.values()) rawConfig.setCategoryLanguageKey(category.toString(), String.format("betterfoliage.%s", category.toString()));

setOrder(Category.extraLeaves, "enabled", "dense", "skewMode", "hOffset", "vOffset", "size");
setOrder(Category.shortGrass, "enabled", "myceliumEnabled", "snowEnabled", "useGenerated", "hOffset", "heightMin", "heightMax", "size", "shaderWind");
setOrder(Category.lilypad, "enabled", "hOffset", "flowerChance");
setOrder(Category.reed, "enabled", "hOffset", "heightMin", "heightMax", "population", "biomeList", "shaderWind");
setOrder(Category.algae, "enabled", "hOffset", "heightMin", "heightMax", "size", "population", "biomeList");
setOrder(Category.coral, "enabled", "shallowWater", "hOffset", "vOffset", "size", "crustSize", "population", "chance", "biomeList");
setOrder(Category.netherrack, "enabled", "hOffset", "heightMin", "heightMax", "size");
setOrder(Category.extraLeaves, "enabled", "distance", "dense", "skewMode", "hOffset", "vOffset", "size");
setOrder(Category.shortGrass, "enabled", "distance", "myceliumEnabled", "snowEnabled", "useGenerated", "hOffset", "heightMin", "heightMax", "size", "shaderWind");
setOrder(Category.lilypad, "enabled", "distance", "hOffset", "flowerChance");
setOrder(Category.reed, "enabled", "distance", "hOffset", "heightMin", "heightMax", "population", "biomeList", "shaderWind");
setOrder(Category.algae, "enabled", "distance", "hOffset", "heightMin", "heightMax", "size", "population", "biomeList");
setOrder(Category.coral, "enabled", "distance", "shallowWater", "hOffset", "vOffset", "size", "crustSize", "population", "chance", "biomeList");
setOrder(Category.netherrack, "enabled", "distance", "hOffset", "heightMin", "heightMax", "size");
setOrder(Category.fallingLeaves, "enabled", "chance", "size", "lifetime", "speed", "windStrength", "stormStrength", "perturb", "opacityHack");
setOrder(Category.risingSoul, "enabled", "chance", "speed", "perturb", "headSize", "trailSize", "sizeDecay", "opacity", "opacityDecay", "lifetime", "trailLength", "trailDensity");
setOrder(Category.connectedGrass, "classic", "aggressive");
setOrder(Category.roundLogs, "enabled", "connect", "connectGrass", "smallRadius", "largeRadius");
setOrder(Category.roundLogs, "enabled", "distance", "connect", "connectGrass", "smallRadius", "largeRadius");
}

public static void getDefaultBiomes() {
Expand Down
2 changes: 2 additions & 0 deletions src/main/resources/assets/betterfoliage/lang/en_US.lang
Expand Up @@ -17,6 +17,8 @@ betterfoliage.population=Population
betterfoliage.population.tooltip=Chance (N in 64) that an eligible block will have this feature
betterfoliage.shaderWind=Shader wind effects
betterfoliage.shaderWind.tooltip=Apply wind effects from ShaderMod shaders to this element?
betterfoliage.distance=Distance limit
betterfoliage.distance.tooltip=Maximum distance from player at which to render this feature

betterfoliage.blockTypes=Block Types
betterfoliage.blockTypes.tooltip=Configure lists of block classes that will have specific features applied to them
Expand Down

0 comments on commit 68d50a0

Please sign in to comment.