mirror of
https://hub.spigotmc.org/stash/scm/spigot/spigot.git
synced 2025-09-18 21:33:01 +00:00
196 lines
10 KiB
Diff
196 lines
10 KiB
Diff
From 1d404d1cfd3cd23e3385d9f836080ac9ec2fe17b Mon Sep 17 00:00:00 2001
|
|
From: md_5 <git@md-5.net>
|
|
Date: Mon, 7 Mar 2016 22:14:13 +1100
|
|
Subject: [PATCH] Crop Growth Rates
|
|
|
|
Allows configuring the growth rates of crops as a percentage of their normal growth rate.
|
|
|
|
diff --git a/src/main/java/net/minecraft/server/Block.java b/src/main/java/net/minecraft/server/Block.java
|
|
index 1968c0e..288ca93 100644
|
|
--- a/src/main/java/net/minecraft/server/Block.java
|
|
+++ b/src/main/java/net/minecraft/server/Block.java
|
|
@@ -929,6 +929,18 @@ public class Block {
|
|
a(i, new MinecraftKey(s), block);
|
|
}
|
|
|
|
+ // 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
|
|
+
|
|
public static enum EnumRandomOffset {
|
|
|
|
NONE, XZ, XYZ;
|
|
diff --git a/src/main/java/net/minecraft/server/BlockCactus.java b/src/main/java/net/minecraft/server/BlockCactus.java
|
|
index 715da28..3f579fb 100644
|
|
--- a/src/main/java/net/minecraft/server/BlockCactus.java
|
|
+++ b/src/main/java/net/minecraft/server/BlockCactus.java
|
|
@@ -31,7 +31,7 @@ public class BlockCactus extends Block {
|
|
if (i < 3) {
|
|
int j = ((Integer) iblockdata.get(BlockCactus.AGE)).intValue();
|
|
|
|
- if (j == 15) {
|
|
+ if (j >= (byte) range(3, ((100.0F / world.spigotConfig.cactusModifier) * 15) + 0.5F, 15)) { // Spigot
|
|
// world.setTypeUpdate(blockposition1, this.getBlockData()); // CraftBukkit
|
|
IBlockData iblockdata1 = iblockdata.set(BlockCactus.AGE, Integer.valueOf(0));
|
|
|
|
diff --git a/src/main/java/net/minecraft/server/BlockCocoa.java b/src/main/java/net/minecraft/server/BlockCocoa.java
|
|
index fe2298a..82a9f19 100644
|
|
--- a/src/main/java/net/minecraft/server/BlockCocoa.java
|
|
+++ b/src/main/java/net/minecraft/server/BlockCocoa.java
|
|
@@ -21,7 +21,7 @@ public class BlockCocoa extends BlockFacingHorizontal implements IBlockFragilePl
|
|
public void b(World world, BlockPosition blockposition, IBlockData iblockdata, Random random) {
|
|
if (!this.e(world, blockposition, iblockdata)) {
|
|
this.f(world, blockposition, iblockdata);
|
|
- } else if (world.random.nextInt(5) == 0) {
|
|
+ } else if (world.random.nextInt(Math.max(1, (int) (100.0F / world.spigotConfig.cocoaModifier) * 5)) == 0) { // Spigot
|
|
int i = ((Integer) iblockdata.get(BlockCocoa.AGE)).intValue();
|
|
|
|
if (i < 2) {
|
|
diff --git a/src/main/java/net/minecraft/server/BlockCrops.java b/src/main/java/net/minecraft/server/BlockCrops.java
|
|
index 445cf03..e9c5d14 100644
|
|
--- a/src/main/java/net/minecraft/server/BlockCrops.java
|
|
+++ b/src/main/java/net/minecraft/server/BlockCrops.java
|
|
@@ -54,7 +54,7 @@ public class BlockCrops extends BlockPlant implements IBlockFragilePlantElement
|
|
if (i < this.g()) {
|
|
float f = a((Block) this, world, blockposition);
|
|
|
|
- if (random.nextInt((int) (25.0F / f) + 1) == 0) {
|
|
+ if (random.nextInt((int) ((100.0F / world.spigotConfig.wheatModifier) * (25.0F / f)) + 1) == 0) { // Spigot
|
|
// CraftBukkit start
|
|
IBlockData data = this.setAge(i + 1);
|
|
CraftEventFactory.handleBlockGrowEvent(world, blockposition.getX(), blockposition.getY(), blockposition.getZ(), this, toLegacyData(data));
|
|
diff --git a/src/main/java/net/minecraft/server/BlockMushroom.java b/src/main/java/net/minecraft/server/BlockMushroom.java
|
|
index 2e5cf99..4571344 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 b(World world, BlockPosition blockposition, IBlockData iblockdata, Random random) {
|
|
final int sourceX = blockposition.getX(), sourceY = blockposition.getY(), sourceZ = blockposition.getZ(); // CraftBukkit
|
|
- if (random.nextInt(25) == 0) {
|
|
+ if (random.nextInt(Math.max(1, (int) (100.0F / world.spigotConfig.mushroomModifier) * 25)) == 0) { // Spigot
|
|
int i = 5;
|
|
boolean flag = true;
|
|
Iterator iterator = BlockPosition.b(blockposition.a(-4, -1, -4), blockposition.a(4, 1, 4)).iterator();
|
|
diff --git a/src/main/java/net/minecraft/server/BlockNetherWart.java b/src/main/java/net/minecraft/server/BlockNetherWart.java
|
|
index 13f53bb..48bd617 100644
|
|
--- a/src/main/java/net/minecraft/server/BlockNetherWart.java
|
|
+++ b/src/main/java/net/minecraft/server/BlockNetherWart.java
|
|
@@ -29,7 +29,7 @@ public class BlockNetherWart extends BlockPlant {
|
|
public void b(World world, BlockPosition blockposition, IBlockData iblockdata, Random random) {
|
|
int i = ((Integer) iblockdata.get(BlockNetherWart.AGE)).intValue();
|
|
|
|
- if (i < 3 && random.nextInt(10) == 0) {
|
|
+ if (i < 3 && random.nextInt(Math.max(1, (int) (100.0F / world.spigotConfig.wartModifier) * 10)) == 0) { // Spigot
|
|
iblockdata = iblockdata.set(BlockNetherWart.AGE, Integer.valueOf(i + 1));
|
|
// world.setTypeAndData(blockposition, iblockdata, 2); // CraftBukkit
|
|
org.bukkit.craftbukkit.event.CraftEventFactory.handleBlockGrowEvent(world, blockposition.getX(), blockposition.getY(), blockposition.getZ(), this, toLegacyData(iblockdata)); // CraftBukkit
|
|
diff --git a/src/main/java/net/minecraft/server/BlockReed.java b/src/main/java/net/minecraft/server/BlockReed.java
|
|
index 11903ae..84014b1 100644
|
|
--- a/src/main/java/net/minecraft/server/BlockReed.java
|
|
+++ b/src/main/java/net/minecraft/server/BlockReed.java
|
|
@@ -31,7 +31,7 @@ public class BlockReed extends Block {
|
|
if (i < 3) {
|
|
int j = ((Integer) iblockdata.get(BlockReed.AGE)).intValue();
|
|
|
|
- if (j == 15) {
|
|
+ if (j >= (byte) range(3, ((100.0F / world.spigotConfig.caneModifier) * 15) + 0.5F, 15)) { // Spigot
|
|
// CraftBukkit start
|
|
// world.setTypeUpdate(blockposition.up(), this.getBlockData()); // CraftBukkit
|
|
BlockPosition upPos = blockposition.up();
|
|
diff --git a/src/main/java/net/minecraft/server/BlockSapling.java b/src/main/java/net/minecraft/server/BlockSapling.java
|
|
index 46a6b22..f463b71 100644
|
|
--- a/src/main/java/net/minecraft/server/BlockSapling.java
|
|
+++ b/src/main/java/net/minecraft/server/BlockSapling.java
|
|
@@ -34,7 +34,7 @@ public class BlockSapling extends BlockPlant implements IBlockFragilePlantElemen
|
|
public void b(World world, BlockPosition blockposition, IBlockData iblockdata, Random random) {
|
|
if (!world.isClientSide) {
|
|
super.b(world, blockposition, iblockdata, random);
|
|
- if (world.getLightLevel(blockposition.up()) >= 9 && random.nextInt(7) == 0) {
|
|
+ if (world.getLightLevel(blockposition.up()) >= 9 && random.nextInt(Math.max(2, (int) (((100.0F / world.spigotConfig.saplingModifier) * 7) + 0.5F))) == 0) { // Spigot
|
|
// 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
|
|
index 171dff5..c74b628 100644
|
|
--- a/src/main/java/net/minecraft/server/BlockStem.java
|
|
+++ b/src/main/java/net/minecraft/server/BlockStem.java
|
|
@@ -51,7 +51,7 @@ public class BlockStem extends BlockPlant implements IBlockFragilePlantElement {
|
|
if (world.getLightLevel(blockposition.up()) >= 9) {
|
|
float f = BlockCrops.a((Block) this, world, blockposition);
|
|
|
|
- if (random.nextInt((int) (25.0F / f) + 1) == 0) {
|
|
+ if (random.nextInt((int) ((100.0F / (this == Blocks.PUMPKIN_STEM ? world.spigotConfig.pumpkinModifier : world.spigotConfig.melonModifier)) * (25.0F / f)) + 1) == 0) { // Spigot
|
|
int i = ((Integer) iblockdata.get(BlockStem.AGE)).intValue();
|
|
|
|
if (i < 7) {
|
|
diff --git a/src/main/java/net/minecraft/server/BlockVine.java b/src/main/java/net/minecraft/server/BlockVine.java
|
|
index 83d4b75..da48082 100644
|
|
--- a/src/main/java/net/minecraft/server/BlockVine.java
|
|
+++ b/src/main/java/net/minecraft/server/BlockVine.java
|
|
@@ -139,7 +139,7 @@ public class BlockVine extends Block {
|
|
|
|
public void b(World world, BlockPosition blockposition, IBlockData iblockdata, Random random) {
|
|
if (!world.isClientSide) {
|
|
- if (world.random.nextInt(4) == 0) {
|
|
+ if (world.random.nextInt(Math.max(1, (int) (100.0F / world.spigotConfig.vineModifier) * 4)) == 0) { // Spigot
|
|
boolean flag = true;
|
|
int i = 5;
|
|
boolean flag1 = false;
|
|
diff --git a/src/main/java/org/spigotmc/SpigotWorldConfig.java b/src/main/java/org/spigotmc/SpigotWorldConfig.java
|
|
index 961ddb4..c62fa45 100644
|
|
--- a/src/main/java/org/spigotmc/SpigotWorldConfig.java
|
|
+++ b/src/main/java/org/spigotmc/SpigotWorldConfig.java
|
|
@@ -68,4 +68,41 @@ public class SpigotWorldConfig
|
|
config.addDefault( "world-settings.default." + path, def );
|
|
return config.getString( "world-settings." + worldName + "." + path, config.getString( "world-settings.default." + path ) );
|
|
}
|
|
+
|
|
+ // Crop growth rates
|
|
+ public int cactusModifier;
|
|
+ public int caneModifier;
|
|
+ public int melonModifier;
|
|
+ public int mushroomModifier;
|
|
+ public int pumpkinModifier;
|
|
+ public int saplingModifier;
|
|
+ public int wheatModifier;
|
|
+ public int wartModifier;
|
|
+ public int vineModifier;
|
|
+ public int cocoaModifier;
|
|
+ private int getAndValidateGrowth(String crop)
|
|
+ {
|
|
+ int modifier = getInt( "growth." + crop.toLowerCase(java.util.Locale.ENGLISH) + "-modifier", 100 );
|
|
+ if ( modifier == 0 )
|
|
+ {
|
|
+ log( "Cannot set " + crop + " growth to zero, defaulting to 100" );
|
|
+ modifier = 100;
|
|
+ }
|
|
+ log( crop + " Growth Modifier: " + modifier + "%" );
|
|
+
|
|
+ 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" );
|
|
+ wartModifier = getAndValidateGrowth( "NetherWart" );
|
|
+ vineModifier = getAndValidateGrowth( "Vine" );
|
|
+ cocoaModifier = getAndValidateGrowth( "Cocoa" );
|
|
+ }
|
|
}
|
|
--
|
|
2.9.3
|
|
|