Skip to content

Commit

Permalink
Adds configurable bonemeal reduction modifier
Browse files Browse the repository at this point in the history
  • Loading branch information
nsporillo committed May 17, 2019
1 parent ecaaa05 commit 93f9790
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 5 deletions.
4 changes: 4 additions & 0 deletions src/main/java/net/porillo/config/WorldConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ public class WorldConfig extends ConfigLoader {
@Getter private CarbonSensitivity sensitivity;
@Getter private double blastFurnaceMultiplier;
@Getter private double methaneTicksLivedModifier;
@Getter private boolean bonemealReductionAllowed;
@Getter private double bonemealReductionModifier;

public WorldConfig(UUID worldId) {
super(String.format("%s.yml", Bukkit.getWorld(worldId).getName()), "world.yml");
Expand Down Expand Up @@ -54,6 +56,8 @@ protected void loadKeys() {
this.enabledEffects = new HashSet<>();
this.blastFurnaceMultiplier = this.conf.getDouble("blastFurnaceMultiplier", 1.2);
this.methaneTicksLivedModifier = this.conf.getDouble("methaneTicksLivedModifier", 0.01);
this.bonemealReductionAllowed = this.conf.getBoolean("bonemealReductionAllowed", true);
this.bonemealReductionModifier = this.conf.getDouble("bonemealReductionModifier", 0.5);

for (String effect : this.conf.getStringList("enabledEffects")) {
try {
Expand Down
15 changes: 11 additions & 4 deletions src/main/java/net/porillo/engine/api/WorldClimateEngine.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import net.porillo.objects.*;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.TreeType;
import org.bukkit.World;
import org.bukkit.block.BlockState;
import org.bukkit.inventory.ItemStack;
Expand Down Expand Up @@ -49,10 +48,18 @@ public WorldClimateEngine(WorldConfig config) {

}

public Reduction treeGrow(Tree tree, TreeType treeType, List<BlockState> blocks) {
public Reduction treeGrow(Tree tree, List<BlockState> blocks, boolean bonemealUsed) {
int reductionValue = 0;
for (BlockState bs : blocks) {
reductionValue += reductionModel.getReduction(bs.getType());
if (bonemealUsed && !config.isBonemealReductionAllowed()) {
return null;
} else if (bonemealUsed) {
for (BlockState bs : blocks) {
reductionValue += (config.getBonemealReductionModifier() * reductionModel.getReduction(bs.getType()));
}
} else {
for (BlockState bs : blocks) {
reductionValue += reductionModel.getReduction(bs.getType());
}
}

Integer uniqueId = GlobalWarming.getInstance().getRandom().nextInt(Integer.MAX_VALUE);
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/net/porillo/listeners/CO2Listener.java
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ public void onStructureGrow(StructureGrowEvent event) {
WorldClimateEngine affectedClimateEngine = ClimateEngine.getInstance().getClimateEngine(affectedWorldId);
if (affectedClimateEngine != null && affectedClimateEngine.isEnabled()) {
//Carbon reduction record:
Reduction reduction = eventClimateEngine.treeGrow(tree, event.getSpecies(), event.getBlocks());
Reduction reduction = eventClimateEngine.treeGrow(tree, event.getBlocks(), event.isFromBonemeal());

//Queue an insert into the contributions table:
ReductionInsertQuery insertQuery = new ReductionInsertQuery(reduction);
Expand Down
2 changes: 2 additions & 0 deletions src/main/resources/world.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ association: world
carbonSensitivity: LOW
blastFurnaceMultiplier: 1.2
methaneTicksLivedModifier: 0.001
bonemealReductionAllowed: true
bonemealReductionModifier: 0.5
enabledEffects:
- SEA_LEVEL_RISE
- ICE_MELT
Expand Down

0 comments on commit 93f9790

Please sign in to comment.