Paper/CraftBukkit-Patches/0007-Crop-Growth-Rates.patch

177 lines
8.7 KiB
Diff
Raw Normal View History

2014-04-24 08:27:12 +02:00
From 1e1bd1813fe7ea78783f98d772faa52ba59005f6 Mon Sep 17 00:00:00 2001
From: md_5 <md_5@live.com.au>
2013-06-21 09:30:13 +02:00
Date: Fri, 21 Jun 2013 17:17:20 +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
2014-03-23 01:06:43 +01:00
index 14c00c5..51f8279 100644
--- a/src/main/java/net/minecraft/server/Block.java
+++ b/src/main/java/net/minecraft/server/Block.java
2013-12-01 04:40:53 +01:00
@@ -804,4 +804,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
2014-03-23 01:06:43 +01:00
index 57eb59d..6778cae 100644
--- a/src/main/java/net/minecraft/server/BlockCactus.java
+++ b/src/main/java/net/minecraft/server/BlockCactus.java
2013-12-01 05:36:32 +01:00
@@ -23,7 +23,7 @@ public class BlockCactus extends Block {
if (l < 3) {
int i1 = world.getData(i, j, k);
- if (i1 == 15) {
2013-06-20 10:21:31 +02:00
+ if (i1 >= (byte) range(3, (world.growthOdds / world.spigotConfig.cactusModifier * 15) + 0.5F, 15)) { // Spigot
2013-12-01 05:36:32 +01:00
org.bukkit.craftbukkit.event.CraftEventFactory.handleBlockGrowEvent(world, i, j + 1, k, this, 0); // CraftBukkit
world.setData(i, j, k, 0, 4);
2013-12-01 04:40:53 +01:00
this.doPhysics(world, i, j + 1, k, this);
diff --git a/src/main/java/net/minecraft/server/BlockCrops.java b/src/main/java/net/minecraft/server/BlockCrops.java
2014-04-18 19:08:19 +02:00
index 875181f..fd28d85 100644
--- a/src/main/java/net/minecraft/server/BlockCrops.java
+++ b/src/main/java/net/minecraft/server/BlockCrops.java
2014-04-18 19:08:19 +02:00
@@ -29,7 +29,7 @@ public class BlockCrops extends BlockPlant implements IBlockFragilePlantElement
if (l < 7) {
2013-12-01 04:40:53 +01:00
float f = this.n(world, i, j, k);
- if (random.nextInt((int) (25.0F / f) + 1) == 0) {
2013-06-20 10:21:31 +02:00
+ if (random.nextInt((int) (world.growthOdds / world.spigotConfig.wheatModifier * (25.0F / f)) + 1) == 0) { // Spigot
2014-04-18 19:08:19 +02:00
++l;
CraftEventFactory.handleBlockGrowEvent(world, i, j, k, this, l); // CraftBukkit
}
diff --git a/src/main/java/net/minecraft/server/BlockGrass.java b/src/main/java/net/minecraft/server/BlockGrass.java
2014-04-18 19:08:19 +02:00
index abd991b..7c00158 100644
--- a/src/main/java/net/minecraft/server/BlockGrass.java
+++ b/src/main/java/net/minecraft/server/BlockGrass.java
2014-04-18 19:08:19 +02:00
@@ -39,7 +39,8 @@ public class BlockGrass extends Block implements IBlockFragilePlantElement {
}
// 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
2014-04-24 08:27:12 +02:00
index 5b90eb9..c720a7f 100644
--- a/src/main/java/net/minecraft/server/BlockMushroom.java
+++ b/src/main/java/net/minecraft/server/BlockMushroom.java
2014-04-24 08:27:12 +02:00
@@ -19,7 +19,7 @@ public class BlockMushroom extends BlockPlant implements IBlockFragilePlantEleme
public void a(World world, int i, int j, int k, Random random) {
2013-01-27 23:46:19 +01:00
final int sourceX = i, sourceY = j, sourceZ = k; // CraftBukkit
- if (random.nextInt(25) == 0) {
2013-06-20 10:21:31 +02:00
+ 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
2014-03-23 01:06:43 +01:00
index a01a6e6..2854bbc 100644
--- a/src/main/java/net/minecraft/server/BlockMycel.java
+++ b/src/main/java/net/minecraft/server/BlockMycel.java
2014-03-23 01:06:43 +01:00
@@ -33,7 +33,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
2013-12-01 05:36:32 +01:00
index a1350f6..6c04ad2 100644
--- a/src/main/java/net/minecraft/server/BlockReed.java
+++ b/src/main/java/net/minecraft/server/BlockReed.java
2013-12-01 05:36:32 +01:00
@@ -24,7 +24,7 @@ public class BlockReed extends Block {
2013-12-01 04:40:53 +01:00
if (l < 3) {
int i1 = world.getData(i, j, k);
2013-12-01 04:40:53 +01:00
- if (i1 == 15) {
2013-12-01 05:36:32 +01:00
+ 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, 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
2014-04-24 08:27:12 +02:00
index ab8b07c..348a00e 100644
--- a/src/main/java/net/minecraft/server/BlockSapling.java
+++ b/src/main/java/net/minecraft/server/BlockSapling.java
2014-04-24 08:27:12 +02:00
@@ -27,7 +27,7 @@ public class BlockSapling extends BlockPlant implements IBlockFragilePlantElemen
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
2014-04-24 08:27:12 +02:00
// CraftBukkit start
world.captureTreeGeneration = true;
// CraftBukkit end
diff --git a/src/main/java/net/minecraft/server/BlockStem.java b/src/main/java/net/minecraft/server/BlockStem.java
2014-04-18 19:08:19 +02:00
index 40ad1c6..b37b187 100644
--- a/src/main/java/net/minecraft/server/BlockStem.java
+++ b/src/main/java/net/minecraft/server/BlockStem.java
2013-12-01 04:40:53 +01:00
@@ -26,7 +26,7 @@ public class BlockStem extends BlockPlant implements IBlockFragilePlantElement {
if (world.getLightLevel(i, j + 1, k) >= 9) {
2013-12-01 04:40:53 +01:00
float f = this.n(world, i, j, k);
- if (random.nextInt((int) (25.0F / f) + 1) == 0) {
2013-12-01 05:36:32 +01:00
+ if (random.nextInt((int) (world.growthOdds / (this == Blocks.PUMPKIN_STEM? world.spigotConfig.pumpkinModifier : world.spigotConfig.melonModifier) * (25.0F / f)) + 1) == 0) { // Spigot
int l = world.getData(i, j, k);
if (l < 7) {
2013-06-20 10:21:31 +02:00
diff --git a/src/main/java/org/spigotmc/SpigotWorldConfig.java b/src/main/java/org/spigotmc/SpigotWorldConfig.java
2014-02-18 03:56:13 +01:00
index 90a227f..7e79ba5 100644
2013-06-20 10:21:31 +02:00
--- a/src/main/java/org/spigotmc/SpigotWorldConfig.java
+++ b/src/main/java/org/spigotmc/SpigotWorldConfig.java
@@ -79,4 +79,35 @@ public class SpigotWorldConfig
clearChunksOnTick = getBoolean( "clear-tick-list", false );
2014-02-18 03:56:13 +01:00
log( "Clear tick list: " + clearChunksOnTick );
2013-06-20 10:21:31 +02:00
}
+
+ // Crop growth rates
2013-06-21 09:00:01 +02:00
+ public int cactusModifier;
+ public int caneModifier;
+ public int melonModifier;
+ public int mushroomModifier;
+ public int pumpkinModifier;
+ public int saplingModifier;
+ public int wheatModifier;
2013-12-02 23:05:49 +01:00
+ private int getAndValidateGrowth(String crop)
2013-06-20 10:21:31 +02:00
+ {
2013-12-02 23:05:49 +01:00
+ int modifier = getInt( "growth." + crop.toLowerCase() + "-modifier", 100 );
+ if ( modifier == 0 )
+ {
+ log( "Cannot set " + crop + " growth to zero, defaulting to 100" );
+ modifier = 100;
+ }
+ log( crop + " Growth Modifier: " + modifier + "%" );
2013-06-20 10:21:31 +02:00
+
2013-12-02 23:05:49 +01:00
+ return modifier;
+ }
+ private void growthModifiers()
+ {
+ cactusModifier = getAndValidateGrowth( "Cactus" );
+ caneModifier = getAndValidateGrowth( "Cane" );
+ melonModifier = getAndValidateGrowth( "Melon" );
+ mushroomModifier = getAndValidateGrowth( "Mushroom" );
+ pumpkinModifier = getAndValidateGrowth( "Pumpkin" );
+ saplingModifier = getAndValidateGrowth( "Sapling" );
+ wheatModifier = getAndValidateGrowth( "Wheat" );
2013-06-20 10:21:31 +02:00
+ }
}
--
2014-04-18 19:08:19 +02:00
1.9.1