3
0
Mirror von https://github.com/PaperMC/Paper.git synchronisiert 2024-11-16 21:10:17 +01:00
Paper/CraftBukkit-Patches/0006-Crop-Growth-Rates.patch

260 Zeilen
13 KiB
Diff

From bade146cff75a2d2fca7a80c11ce655816a7517c Mon Sep 17 00:00:00 2001
From: md_5 <md_5@live.com.au>
Date: Fri, 21 Jun 2013 17:17:20 +1000
Subject: [PATCH] Crop Growth Rates
diff --git a/CraftBukkit-Patches/0071-Growth-Rates-Divide-By-0-Prevention.patch b/CraftBukkit-Patches/0071-Growth-Rates-Divide-By-0-Prevention.patch
new file mode 100644
index 0000000..e7912f7
--- /dev/null
+++ b/CraftBukkit-Patches/0071-Growth-Rates-Divide-By-0-Prevention.patch
@@ -0,0 +1,73 @@
+From 5cf798e92bfc9c03460dffe32887940d27eaaf11 Mon Sep 17 00:00:00 2001
+From: Dmck2b <dmck2b+github@gmail.com>
+Date: Mon, 2 Dec 2013 18:52:59 +0000
+Subject: [PATCH] Growth Rates Divide By 0 Prevention
+
+
+diff --git a/src/main/java/org/spigotmc/SpigotWorldConfig.java b/src/main/java/org/spigotmc/SpigotWorldConfig.java
+index 300db67..95e3716 100644
+--- a/src/main/java/org/spigotmc/SpigotWorldConfig.java
++++ b/src/main/java/org/spigotmc/SpigotWorldConfig.java
+@@ -88,24 +88,59 @@ public class SpigotWorldConfig
+ private void growthModifiers()
+ {
+ cactusModifier = getInt( "growth.cactus-modifier", 100 );
++ if ( cactusModifier == 0 ) {
++ log( "***WARNING*** You have set your Cactus Growth Modifier for " + worldName + "to 0. Defaulting back to 100 to prevent a division by 0 crash." );
++ log( "***WARNING*** Please fix your Spigot.yml configuration to hide this message." );
++ cactusModifier = 100;
++ }
+ log( "Cactus Growth Modifier: " + cactusModifier + "%" );
+
+ caneModifier = getInt( "growth.cane-modifier", 100 );
++ if ( caneModifier == 0 ) {
++ log( "***WARNING*** You have set your Sugar Cane Growth Modifier for " + worldName + "to 0. Defaulting back to 100 to prevent a division by 0 crash." );
++ log( "***WARNING*** Please fix your Spigot.yml configuration to hide this message." );
++ caneModifier = 100;
++ }
+ log( "Cane Growth Modifier: " + caneModifier + "%" );
+
+ melonModifier = getInt( "growth.melon-modifier", 100 );
++ if ( melonModifier == 0 ) {
++ log( "***WARNING*** You have set your Melon Growth Modifier for " + worldName + "to 0. Defaulting back to 100 to prevent a division by 0 crash." );
++ log( "***WARNING*** Please fix your Spigot.yml configuration to hide this message." );
++ melonModifier = 100;
++ }
+ log( "Melon Growth Modifier: " + melonModifier + "%" );
+
+ mushroomModifier = getInt( "growth.mushroom-modifier", 100 );
++ if ( mushroomModifier == 0 ) {
++ log( "***WARNING*** You have set your Mushroom Growth Modifier for " + worldName + "to 0. Defaulting back to 100 to prevent a division by 0 crash." );
++ log( "***WARNING*** Please fix your Spigot.yml configuration to hide this message." );
++ mushroomModifier = 100;
++ }
+ log( "Mushroom Growth Modifier: " + mushroomModifier + "%" );
+
+ pumpkinModifier = getInt( "growth.pumpkin-modifier", 100 );
++ if ( pumpkinModifier == 0 ) {
++ log( "***WARNING*** You have set your Pumpkin Growth Modifier for " + worldName + "to 0. Defaulting back to 100 to prevent a division by 0 crash." );
++ log( "***WARNING*** Please fix your Spigot.yml configuration to hide this message." );
++ pumpkinModifier = 100;
++ }
+ log( "Pumpkin Growth Modifier: " + pumpkinModifier + "%" );
+
+ saplingModifier = getInt( "growth.sapling-modifier", 100 );
++ if ( saplingModifier == 0 ) {
++ log( "***WARNING*** You have set your Sapling Growth Modifier for " + worldName + "to 0. Defaulting back to 100 to prevent a division by 0 crash." );
++ log( "***WARNING*** Please fix your Spigot.yml configuration to hide this message." );
++ saplingModifier = 100;
++ }
+ log( "Sapling Growth Modifier: " + saplingModifier + "%" );
+
+ wheatModifier = getInt( "growth.wheat-modifier", 100 );
++ if ( wheatModifier == 0 ) {
++ log( "***WARNING*** You have set your Wheat Growth Modifier for " + worldName + "to 0. Defaulting back to 100 to prevent a division by 0 crash." );
++ log( "***WARNING*** Please fix your Spigot.yml configuration to hide this message." );
++ wheatModifier = 100;
++ }
+ log( "Wheat Growth Modifier: " + wheatModifier + "%" );
+ }
+
+--
+1.8.5
+
diff --git a/src/main/java/net/minecraft/server/Block.java b/src/main/java/net/minecraft/server/Block.java
index dca832f..ad4e3a2 100644
--- a/src/main/java/net/minecraft/server/Block.java
+++ b/src/main/java/net/minecraft/server/Block.java
@@ -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
index 421af04..183fb43 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, 0); // CraftBukkit
world.setData(i, j, k, 0, 4);
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
index 942d6ab..c46879c 100644
--- a/src/main/java/net/minecraft/server/BlockCrops.java
+++ b/src/main/java/net/minecraft/server/BlockCrops.java
@@ -27,9 +27,8 @@ public class BlockCrops extends BlockPlant implements IBlockFragilePlantElement
if (l < 7) {
float f = this.n(world, i, j, k);
- if (random.nextInt((int) (25.0F / f) + 1) == 0) {
- ++l;
- org.bukkit.craftbukkit.event.CraftEventFactory.handleBlockGrowEvent(world, i, j, k, this, l); // CraftBukkit
+ 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, ++l); // CraftBukkit
}
}
}
diff --git a/src/main/java/net/minecraft/server/BlockGrass.java b/src/main/java/net/minecraft/server/BlockGrass.java
index 7b78579..bdf3172 100644
--- a/src/main/java/net/minecraft/server/BlockGrass.java
+++ b/src/main/java/net/minecraft/server/BlockGrass.java
@@ -37,7 +37,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
index 54a399f..4cab3eb 100644
--- a/src/main/java/net/minecraft/server/BlockMushroom.java
+++ b/src/main/java/net/minecraft/server/BlockMushroom.java
@@ -23,7 +23,7 @@ public class BlockMushroom extends BlockPlant implements IBlockFragilePlantEleme
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 6ac6d94..a401f65 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 a1350f6..6c04ad2 100644
--- a/src/main/java/net/minecraft/server/BlockReed.java
+++ b/src/main/java/net/minecraft/server/BlockReed.java
@@ -24,7 +24,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, 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 830eb65..24c95ef 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 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
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 4fae805..a90fab1 100644
--- a/src/main/java/net/minecraft/server/BlockStem.java
+++ b/src/main/java/net/minecraft/server/BlockStem.java
@@ -26,7 +26,7 @@ public class BlockStem extends BlockPlant implements IBlockFragilePlantElement {
if (world.getLightLevel(i, j + 1, k) >= 9) {
float f = this.n(world, i, j, k);
- if (random.nextInt((int) (25.0F / f) + 1) == 0) {
+ 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) {
diff --git a/src/main/java/org/spigotmc/SpigotWorldConfig.java b/src/main/java/org/spigotmc/SpigotWorldConfig.java
index 478d9e6..1c598ed 100644
--- a/src/main/java/org/spigotmc/SpigotWorldConfig.java
+++ b/src/main/java/org/spigotmc/SpigotWorldConfig.java
@@ -75,4 +75,36 @@ public class SpigotWorldConfig
chunksPerTick = getInt( "chunks-per-tick", 650 );
log( "Chunks to Grow per Tick: " + chunksPerTick );
}
+
+ // Crop growth rates
+ public int cactusModifier;
+ public int caneModifier;
+ public int melonModifier;
+ public int mushroomModifier;
+ public int pumpkinModifier;
+ public int saplingModifier;
+ public int wheatModifier;
+ private void growthModifiers()
+ {
+ cactusModifier = getInt( "growth.cactus-modifier", 100 );
+ log( "Cactus Growth Modifier: " + cactusModifier + "%" );
+
+ caneModifier = getInt( "growth.cane-modifier", 100 );
+ log( "Cane Growth Modifier: " + caneModifier + "%" );
+
+ melonModifier = getInt( "growth.melon-modifier", 100 );
+ log( "Melon Growth Modifier: " + melonModifier + "%" );
+
+ mushroomModifier = getInt( "growth.mushroom-modifier", 100 );
+ log( "Mushroom Growth Modifier: " + mushroomModifier + "%" );
+
+ pumpkinModifier = getInt( "growth.pumpkin-modifier", 100 );
+ log( "Pumpkin Growth Modifier: " + pumpkinModifier + "%" );
+
+ saplingModifier = getInt( "growth.sapling-modifier", 100 );
+ log( "Sapling Growth Modifier: " + saplingModifier + "%" );
+
+ wheatModifier = getInt( "growth.wheat-modifier", 100 );
+ log( "Wheat Growth Modifier: " + wheatModifier + "%" );
+ }
}
--
1.8.3.2