Skip to content

Commit

Permalink
fix: give volcano option to fight back succession with geothermal
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex4386 committed Dec 18, 2024
1 parent 6590570 commit 4beb94b
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

import me.alex4386.plugin.typhon.volcano.vent.VolcanoVentType;
import org.bukkit.*;
import org.bukkit.block.Biome;
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
import org.bukkit.enchantments.Enchantment;
Expand Down Expand Up @@ -101,13 +102,15 @@ public void runCraterGeothermal(VolcanoVent vent, Block block, boolean onTop) {
}

letOffSteam = true;
runPoison = Math.random() < scaleFactor;
runPoison = Math.random() < Math.sqrt(scaleFactor);
}
} else if (scaleFactor >= 0.04) {
this.burnNearbyEntities(targetLoc, 1);

letOffSteam = (Math.random() < 0.5);
runPoison = (Math.random() < scaleFactor);
letOffSteam = (Math.random() < (scaleFactor * 10));
if (letOffSteam) {
runPoison = Math.random() < Math.pow(scaleFactor, 0.8);
}
} else if (vent.getStatus() == VolcanoVentStatus.EXTINCT) {
return;
}
Expand Down Expand Up @@ -181,7 +184,7 @@ public double getCraterCycleCount(VolcanoVent vent) {
}

public void runCraterGeoThermalCycle(VolcanoVent vent) {
double thermalScale = Math.pow(vent.getStatus().getScaleFactor(), 1.1);
double thermalScale = Math.pow(vent.getStatus().getScaleFactor(), 2);
double maxCount = this.getCraterCycleCount(vent);

double cycleCount = thermalScale * maxCount * Math.random();
Expand Down Expand Up @@ -359,12 +362,17 @@ public void runGeothermalActivity(VolcanoVent vent, Block block, boolean allowSt
boolean letOffSteam = false;
boolean runPoison = false;

boolean backToNormalBiome = false;

if (scaleFactor >= 0.1) {
letOffSteam = true;
runPoison = Math.random() < Math.max(scaleFactor, Math.sqrt(scaleFactor) * Math.pow(Math.min(1, heatValue / 0.85), 2));
} else if (scaleFactor >= 0.04) {
letOffSteam = (Math.random() < 0.5);
runPoison = (Math.random() < scaleFactor);
backToNormalBiome = true;
} else {
backToNormalBiome = true;
}

if (Math.random() < heatValue) {
Expand Down Expand Up @@ -417,6 +425,12 @@ public void runGeothermalActivity(VolcanoVent vent, Block block, boolean allowSt
}
}
}

if (backToNormalBiome) {
if (isTop) {
this.volcano.succession.returnToNormalBiome(block);
}
}
}

public void createTuffRing(Block block) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,11 @@ public void metamorphoseBlock(VolcanoVent vent, Block block, boolean isLavaConta
}

if (typeOfDirt) {
material = Material.COARSE_DIRT;
if (block.getType() == Material.COARSE_DIRT) {
material = Material.STONE;
} else {
material = Material.COARSE_DIRT;
}
} else if (blockTypeName.contains("cobblestone") || blockTypeName.contains("gravel") || blockTypeName.contains("infested")) {
if (blockTypeName.contains("infested")) {
block.getWorld().playSound(block.getLocation(), Sound.ENTITY_SILVERFISH_DEATH, 1f, 0f);
Expand All @@ -82,6 +86,10 @@ public void metamorphoseBlock(VolcanoVent vent, Block block, boolean isLavaConta
}
}

if (material == Material.STONE) {
material = VolcanoComposition.getExtrusiveRock(vent.lavaFlow.settings.silicateLevel);
}

vent.lavaFlow.queueBlockUpdate(block, material);
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import me.alex4386.plugin.typhon.volcano.vent.VolcanoVentType;

import org.bukkit.*;
import org.bukkit.block.Biome;
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
import org.bukkit.block.data.BlockData;
Expand Down Expand Up @@ -556,6 +557,7 @@ public void onBlockFromTo(BlockFromToEvent event) {
this.tryRootlessCone();
}

toBlock.getWorld().setBiome(event.getToBlock().getLocation(), Biome.BASALT_DELTAS);
if (this.vent != null && !data.isBomb && data.source != null) {
double distance;
distance =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@ public class VolcanoSuccession {
boolean isEnabled = true;

double cyclesPerTick = 1;

public int snowYAxis = 170;
public int peakThreshold = 220;

public VolcanoSuccession(Volcano volcano) {
this.volcano = volcano;
}
Expand Down Expand Up @@ -182,6 +184,17 @@ public boolean shouldCheckHeat(Block block) {
return shouldCheckHeat;
}

public void returnToNormalBiome(Block block) {

if (block.getY() > snowYAxis) {
block.getWorld().setBiome(block.getLocation(), Biome.GROVE);
} else if (block.getY() > peakThreshold) {
block.getWorld().setBiome(block.getLocation(), Biome.JAGGED_PEAKS);
} else {
block.getWorld().setBiome(block.getLocation(), Biome.MEADOW);
}
}

public void runSuccession(Block block) {
boolean isDebug = false;

Expand Down Expand Up @@ -223,23 +236,27 @@ public void runSuccession(Block block) {
if (!block.getWorld().isClearWeather()) growProbability += 0.3;

if (Math.random() < growProbability) {
boolean treeGenerated = createTree(targetBlock);
if (isDebug) this.volcano.logger.log(
VolcanoLogClass.SUCCESSION,
"Creating Tree on block "+TyphonUtils.blockLocationTostring(block)+" / result: "+treeGenerated);

if (treeGenerated) {
return;
}

// tree can not grow if heatValue is high enough,
// in that case, grass should be generated instead.
if (shouldCheckHeat(block)) {
if (heatValue > 0.6) {
targetBlock.applyBoneMeal(BlockFace.UP);
spreadSoil(targetBlock);
int yAxis = targetBlock.getY();
if (yAxis < snowYAxis) {
boolean treeGenerated = createTree(targetBlock);
if (isDebug) this.volcano.logger.log(
VolcanoLogClass.SUCCESSION,
"Creating Tree on block "+TyphonUtils.blockLocationTostring(block)+" / result: "+treeGenerated);

if (treeGenerated) {
return;
}
} else if (yAxis < peakThreshold) {

// tree can not grow if heatValue is high enough,
// in that case, grass should be generated instead.
if (shouldCheckHeat(block)) {
if (heatValue > 0.6) {
targetBlock.applyBoneMeal(BlockFace.UP);
spreadSoil(targetBlock);
return;
}
}
}
}

Expand Down Expand Up @@ -392,7 +409,6 @@ public boolean isConsideredErodedRockType(Material material) {
case COBBLESTONE_STAIRS:
case COBBLESTONE_WALL:
case NETHERRACK:
case TUFF:
case BLACKSTONE:
return true;
}
Expand All @@ -413,6 +429,9 @@ public void spreadSoil(Block block) {
public void spreadSoil(Block block, int spreadRange, boolean withExtension) {
int extension = (withExtension ? spreadRange / 3 : 0);
List<Block> treeRange = VolcanoMath.getCircle(block, spreadRange + extension);
returnToNormalBiome(block);

VolcanoVent vent = this.volcano.manager.getNearestVent(block);

for (Block rockRange : treeRange) {
double distance = TyphonUtils.getTwoDimensionalDistance(
Expand All @@ -426,6 +445,10 @@ public void spreadSoil(Block block, int spreadRange, boolean withExtension) {
}

if (probability == 1.0 || Math.random() < probability) {
if (vent.isInVent(rockRange.getLocation())) {
continue;
}

runSoilGeneration(rockRange);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -446,8 +446,9 @@ public double getHeatValue(Location loc) {
double killZone = this.getRadius();
double pillowRatio = 0.2;

double multiplier = this.status.getScaleFactor() <= VolcanoVentStatus.DORMANT.getScaleFactor() ? Math.sqrt(this.status.getScaleFactor()) : 1;
if (distance <= killZone) {
return 1;
return multiplier;
}

double basinLength = this.getBasinLength();
Expand All @@ -466,7 +467,7 @@ public double getHeatValue(Location loc) {
if (converted >= 1) return 0;
double reversed = Math.max(1 - converted, 0);

return Math.pow(reversed, 1.5);
return Math.pow(reversed, 1.5) * multiplier;
}

public int getRadius() {
Expand Down

0 comments on commit 4beb94b

Please sign in to comment.