Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for non-persistent crops growing too fast #16

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion plugin.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: RealisticBiomes
main: com.untamedears.realisticbiomes.RealisticBiomes
load: STARTUP
version: 0.6.4.1
version: 0.6.4.3
19 changes: 15 additions & 4 deletions src/com/untamedears/realisticbiomes/RealisticBiomes.java
Original file line number Diff line number Diff line change
Expand Up @@ -400,6 +400,11 @@ public double growAndPersistBlock(Block block, boolean naturalGrowEvent) {
return 0.0;
}

// Only persistent crops should be grown in this manner
if (!growthConfig.isPersistent()) {
return 0.0;
}

RealisticBiomes.doLog(Level.FINER, "Realisticbiomes.growAndPersistBlock(): plantManager.get() returned: " + plant + " for coords: " + blockCoords);

if (plant == null) {
Expand Down Expand Up @@ -441,16 +446,22 @@ public GrowthConfig getGrowthConfig(TreeType species) {
return materialGrowth.get(treeTypeMap.get(species));
}

public GrowthConfig getGrowthConfig(Block block) {
Material m = block.getType();
public GrowthConfig getGrowthConfig(Material m) {
return materialGrowth.get(m);
}

public boolean hasGrowthConfig(Block block) {
Material m = block.getType();
public GrowthConfig getGrowthConfig(Block b) {
return materialGrowth.get(b.getType());
}

public boolean hasGrowthConfig(Material m) {
return materialGrowth.containsKey(m);
}

public boolean hasGrowthConfig(Block b) {
return materialGrowth.containsKey(b.getType());
}

public boolean hasGrowthConfig(TreeType species) {
return materialGrowth.containsKey(treeTypeMap.get(species));
}
Expand Down
19 changes: 12 additions & 7 deletions src/com/untamedears/realisticbiomes/listener/GrowListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ public GrowListener(RealisticBiomes plugin) {
*/
@EventHandler(ignoreCancelled = true)
public void onBlockGrow(BlockGrowEvent event) {
Material m = event.getNewState().getType();
Block b = event.getBlock();

GrowthConfig growthConfig = plugin.getGrowthConfig(b);
Expand All @@ -57,7 +58,7 @@ public void onBlockGrow(BlockGrowEvent event) {

event.setCancelled(true);
}
else if (!willGrow(b)) {
else if (!willGrow(m, b)) {
event.setCancelled(true);
}
}
Expand Down Expand Up @@ -155,14 +156,18 @@ public void onBlockDispense(BlockDispenseEvent event) {
* Determines if a plant {@link Material | @link TreeType} will grow, given the current conditions
* @param m The material type of the plant
* @param b The block that the plant is on
* @return Whether the plant will grow this tick
* @return true if the block should grow this material, otherwise false
*/
private boolean willGrow(Block b) {
if(plugin.hasGrowthConfig(b)) {
boolean willGrow = Math.random() < plugin.getGrowthConfig(b).getRate(b);
return willGrow;
private boolean willGrow(Material m, Block b) {
GrowthConfig config = plugin.getGrowthConfig(m);

// Returns true if the random value is within the growth rate
if (config != null) {
return Math.random() < config.getRate(b);
}
return true;

// Default to no growth
return false;
}


Expand Down