From 77958016c76679e58d9475984109f0ec9830ceee Mon Sep 17 00:00:00 2001 From: md_5 Date: Fri, 21 Jun 2013 16:44:14 +1000 Subject: [PATCH] Crop Growth Rates diff --git a/src/main/java/net/minecraft/server/Block.java b/src/main/java/net/minecraft/server/Block.java index 4392cb2..8e041c2 100644 --- a/src/main/java/net/minecraft/server/Block.java +++ b/src/main/java/net/minecraft/server/Block.java @@ -768,4 +768,16 @@ public class Block { return 0; } // CraftBukkit end + + // Spigot start + public static float range(float min, float value, float max) { + if (value < min) { + return min; + } + if (value > max) { + return max; + } + return value; + } + // Spigot end } diff --git a/src/main/java/net/minecraft/server/BlockCactus.java b/src/main/java/net/minecraft/server/BlockCactus.java index 83cc09d..4376051 100644 --- a/src/main/java/net/minecraft/server/BlockCactus.java +++ b/src/main/java/net/minecraft/server/BlockCactus.java @@ -23,7 +23,7 @@ public class BlockCactus extends Block { if (l < 3) { int i1 = world.getData(i, j, k); - if (i1 == 15) { + if (i1 >= (byte) range(3, (world.growthOdds / world.spigotConfig.cactusModifier * 15) + 0.5F, 15)) { // Spigot org.bukkit.craftbukkit.event.CraftEventFactory.handleBlockGrowEvent(world, i, j + 1, k, this.id, 0); // CraftBukkit world.setData(i, j, k, 0, 4); this.doPhysics(world, i, j + 1, k, this.id); diff --git a/src/main/java/net/minecraft/server/BlockCrops.java b/src/main/java/net/minecraft/server/BlockCrops.java index 14a1c3b..d3b6095 100644 --- a/src/main/java/net/minecraft/server/BlockCrops.java +++ b/src/main/java/net/minecraft/server/BlockCrops.java @@ -28,7 +28,7 @@ public class BlockCrops extends BlockFlower { if (l < 7) { float f = this.k(world, i, j, k); - if (random.nextInt((int) (25.0F / f) + 1) == 0) { + if (random.nextInt((int) (world.growthOdds / world.spigotConfig.wheatModifier * (25.0F / f)) + 1) == 0) { // Spigot org.bukkit.craftbukkit.event.CraftEventFactory.handleBlockGrowEvent(world, i, j, k, this.id, ++l); // CraftBukkit } } diff --git a/src/main/java/net/minecraft/server/BlockGrass.java b/src/main/java/net/minecraft/server/BlockGrass.java index 6f9301d..2ccc0b8 100644 --- a/src/main/java/net/minecraft/server/BlockGrass.java +++ b/src/main/java/net/minecraft/server/BlockGrass.java @@ -32,7 +32,8 @@ public class BlockGrass extends Block { } // CraftBukkit end } else if (world.getLightLevel(i, j + 1, k) >= 9) { - for (int l = 0; l < 4; ++l) { + int numGrowth = Math.min(4, Math.max(20, (int) (4 * 100F / world.growthOdds))); // Spigot + for (int l = 0; l < numGrowth; ++l) { // Spigot int i1 = i + random.nextInt(3) - 1; int j1 = j + random.nextInt(5) - 3; int k1 = k + random.nextInt(3) - 1; diff --git a/src/main/java/net/minecraft/server/BlockMushroom.java b/src/main/java/net/minecraft/server/BlockMushroom.java index 872ad00..abc31ac 100644 --- a/src/main/java/net/minecraft/server/BlockMushroom.java +++ b/src/main/java/net/minecraft/server/BlockMushroom.java @@ -27,7 +27,7 @@ public class BlockMushroom extends BlockFlower { public void a(World world, int i, int j, int k, Random random) { final int sourceX = i, sourceY = j, sourceZ = k; // CraftBukkit - if (random.nextInt(25) == 0) { + if (random.nextInt(Math.max(1, (int) world.growthOdds / world.spigotConfig.mushroomModifier * 25)) == 0) { // Spigot byte b0 = 4; int l = 5; diff --git a/src/main/java/net/minecraft/server/BlockMycel.java b/src/main/java/net/minecraft/server/BlockMycel.java index 1de8c83..fa11d1c 100644 --- a/src/main/java/net/minecraft/server/BlockMycel.java +++ b/src/main/java/net/minecraft/server/BlockMycel.java @@ -32,7 +32,8 @@ public class BlockMycel extends Block { } // CraftBukkit end } else if (world.getLightLevel(i, j + 1, k) >= 9) { - for (int l = 0; l < 4; ++l) { + int numGrowth = Math.min(4, Math.max(20, (int) (4 * 100F / world.growthOdds))); // Spigot + for (int l = 0; l < numGrowth; ++l) { // Spigot int i1 = i + random.nextInt(3) - 1; int j1 = j + random.nextInt(5) - 3; int k1 = k + random.nextInt(3) - 1; diff --git a/src/main/java/net/minecraft/server/BlockReed.java b/src/main/java/net/minecraft/server/BlockReed.java index 8657860..cf52501 100644 --- a/src/main/java/net/minecraft/server/BlockReed.java +++ b/src/main/java/net/minecraft/server/BlockReed.java @@ -23,7 +23,7 @@ public class BlockReed extends Block { if (l < 3) { int i1 = world.getData(i, j, k); - if (i1 == 15) { + if (i1 >= (byte) range(3, (world.growthOdds / world.spigotConfig.caneModifier * 15) + 0.5F, 15)) { // Spigot org.bukkit.craftbukkit.event.CraftEventFactory.handleBlockGrowEvent(world, i, j + 1, k, this.id, 0); // CraftBukkit world.setData(i, j, k, 0, 4); } else { diff --git a/src/main/java/net/minecraft/server/BlockSapling.java b/src/main/java/net/minecraft/server/BlockSapling.java index 3b00939..ea34899 100644 --- a/src/main/java/net/minecraft/server/BlockSapling.java +++ b/src/main/java/net/minecraft/server/BlockSapling.java @@ -26,7 +26,7 @@ public class BlockSapling extends BlockFlower { public void a(World world, int i, int j, int k, Random random) { if (!world.isStatic) { super.a(world, i, j, k, random); - if (world.getLightLevel(i, j + 1, k) >= 9 && random.nextInt(7) == 0) { + if (world.getLightLevel(i, j + 1, k) >= 9 && (random.nextInt(Math.max(2, (int) ((world.growthOdds / world.spigotConfig.saplingModifier * 7) + 0.5F))) == 0)) { // Spigot this.grow(world, i, j, k, random, false, null, null); // CraftBukkit - added bonemeal, player and itemstack } } diff --git a/src/main/java/net/minecraft/server/BlockStem.java b/src/main/java/net/minecraft/server/BlockStem.java index 8339a35..c7e2344 100644 --- a/src/main/java/net/minecraft/server/BlockStem.java +++ b/src/main/java/net/minecraft/server/BlockStem.java @@ -27,7 +27,7 @@ public class BlockStem extends BlockFlower { if (world.getLightLevel(i, j + 1, k) >= 9) { float f = this.m(world, i, j, k); - if (random.nextInt((int) (25.0F / f) + 1) == 0) { + if (random.nextInt((int) (world.growthOdds / (this.id == Block.PUMPKIN_STEM.id ? world.spigotConfig.pumpkinModifier : world.spigotConfig.melonModifier) * (25.0F / f)) + 1) == 0) { // Spigot int l = world.getData(i, j, k); if (l < 7) { diff --git a/src/main/java/org/spigotmc/SpigotConfig.java b/src/main/java/org/spigotmc/SpigotConfig.java index bf297bc..38bd7ba 100644 --- a/src/main/java/org/spigotmc/SpigotConfig.java +++ b/src/main/java/org/spigotmc/SpigotConfig.java @@ -6,7 +6,6 @@ import java.io.IOException; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.lang.reflect.Modifier; -import java.util.List; import java.util.logging.Level; import org.bukkit.Bukkit; import org.bukkit.configuration.file.YamlConfiguration; @@ -84,15 +83,21 @@ public class SpigotConfig return config.getInt( path, config.getInt( path ) ); } - private List getList(String path, T def) + private static String getString(String path, String def) { config.addDefault( path, def ); - return (List) config.getList( path, config.getList( path ) ); + return config.getString( path, config.getString( path ) ); } - private static String getString(String path, String def) + public static boolean tabComplete = true; + private static void tabComplete() { - config.addDefault( path, def ); - return config.getString( path, config.getString( path ) ); + tabComplete = getBoolean( "commands.tab-complete", tabComplete ); + } + + public static boolean logCommands = true; + private static void logCommands() + { + logCommands = getBoolean( "commands.log", logCommands ); } } diff --git a/src/main/java/org/spigotmc/SpigotWorldConfig.java b/src/main/java/org/spigotmc/SpigotWorldConfig.java index 4e1bdcf..8954c99 100644 --- a/src/main/java/org/spigotmc/SpigotWorldConfig.java +++ b/src/main/java/org/spigotmc/SpigotWorldConfig.java @@ -61,4 +61,36 @@ public class SpigotWorldConfig chunksPerTick = getInt( "chunks-per-tick", chunksPerTick ); log( "Chunks to Grow per Tick: " + chunksPerTick ); } + + // Crop growth rates + public int cactusModifier = 100; + public int caneModifier = 100; + public int melonModifier = 100; + public int mushroomModifier = 100; + public int pumpkinModifier = 100; + public int saplingModifier = 100; + public int wheatModifier = 100; + private void growthModifiers() + { + cactusModifier = getInt( "growth.cactus-modifier", cactusModifier ); + log( "Cactus Growth Modifier: " + cactusModifier + "%" ); + + caneModifier = getInt( "growth.cane-modifier", caneModifier ); + log( "Cactus Growth Modifier: " + cactusModifier + "%" ); + + melonModifier = getInt( "growth.melon-modifier", melonModifier ); + log( "Cactus Growth Modifier: " + cactusModifier + "%" ); + + mushroomModifier = getInt( "growth.mushroom-modifier", mushroomModifier ); + log( "Cactus Growth Modifier: " + cactusModifier + "%" ); + + pumpkinModifier = getInt( "growth.pumpkin-modifier", pumpkinModifier ); + log( "Cactus Growth Modifier: " + cactusModifier + "%" ); + + saplingModifier = getInt( "growth.sapling-modifier", saplingModifier ); + log( "Cactus Growth Modifier: " + cactusModifier + "%" ); + + wheatModifier = getInt( "growth.wheat-modifier", wheatModifier ); + log( "Cactus Growth Modifier: " + cactusModifier + "%" ); + } } -- 1.8.1.2