From 4beb94befcb2f4257ba8c871b8174668995bfcd9 Mon Sep 17 00:00:00 2001 From: Alex4386 Date: Thu, 19 Dec 2024 02:48:44 +0900 Subject: [PATCH] fix: give volcano option to fight back succession with geothermal --- .../typhon/volcano/VolcanoGeoThermal.java | 22 +++++-- .../intrusions/VolcanoMetamorphism.java | 10 +++- .../volcano/lavaflow/VolcanoLavaFlow.java | 2 + .../volcano/succession/VolcanoSuccession.java | 57 +++++++++++++------ .../typhon/volcano/vent/VolcanoVent.java | 5 +- 5 files changed, 72 insertions(+), 24 deletions(-) diff --git a/src/main/java/me/alex4386/plugin/typhon/volcano/VolcanoGeoThermal.java b/src/main/java/me/alex4386/plugin/typhon/volcano/VolcanoGeoThermal.java index 0fc156c..70abd67 100644 --- a/src/main/java/me/alex4386/plugin/typhon/volcano/VolcanoGeoThermal.java +++ b/src/main/java/me/alex4386/plugin/typhon/volcano/VolcanoGeoThermal.java @@ -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; @@ -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; } @@ -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(); @@ -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) { @@ -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) { diff --git a/src/main/java/me/alex4386/plugin/typhon/volcano/intrusions/VolcanoMetamorphism.java b/src/main/java/me/alex4386/plugin/typhon/volcano/intrusions/VolcanoMetamorphism.java index 277cc2a..839148f 100644 --- a/src/main/java/me/alex4386/plugin/typhon/volcano/intrusions/VolcanoMetamorphism.java +++ b/src/main/java/me/alex4386/plugin/typhon/volcano/intrusions/VolcanoMetamorphism.java @@ -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); @@ -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; } diff --git a/src/main/java/me/alex4386/plugin/typhon/volcano/lavaflow/VolcanoLavaFlow.java b/src/main/java/me/alex4386/plugin/typhon/volcano/lavaflow/VolcanoLavaFlow.java index 163af57..036f8d4 100644 --- a/src/main/java/me/alex4386/plugin/typhon/volcano/lavaflow/VolcanoLavaFlow.java +++ b/src/main/java/me/alex4386/plugin/typhon/volcano/lavaflow/VolcanoLavaFlow.java @@ -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; @@ -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 = diff --git a/src/main/java/me/alex4386/plugin/typhon/volcano/succession/VolcanoSuccession.java b/src/main/java/me/alex4386/plugin/typhon/volcano/succession/VolcanoSuccession.java index 3e0eec0..0b2f9d1 100644 --- a/src/main/java/me/alex4386/plugin/typhon/volcano/succession/VolcanoSuccession.java +++ b/src/main/java/me/alex4386/plugin/typhon/volcano/succession/VolcanoSuccession.java @@ -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; } @@ -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; @@ -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; + } + } } } @@ -392,7 +409,6 @@ public boolean isConsideredErodedRockType(Material material) { case COBBLESTONE_STAIRS: case COBBLESTONE_WALL: case NETHERRACK: - case TUFF: case BLACKSTONE: return true; } @@ -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 treeRange = VolcanoMath.getCircle(block, spreadRange + extension); + returnToNormalBiome(block); + + VolcanoVent vent = this.volcano.manager.getNearestVent(block); for (Block rockRange : treeRange) { double distance = TyphonUtils.getTwoDimensionalDistance( @@ -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); } } diff --git a/src/main/java/me/alex4386/plugin/typhon/volcano/vent/VolcanoVent.java b/src/main/java/me/alex4386/plugin/typhon/volcano/vent/VolcanoVent.java index 6315154..090fcd7 100644 --- a/src/main/java/me/alex4386/plugin/typhon/volcano/vent/VolcanoVent.java +++ b/src/main/java/me/alex4386/plugin/typhon/volcano/vent/VolcanoVent.java @@ -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(); @@ -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() {