Skip to content

Commit

Permalink
chore: realistic pillow lava and more
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex4386 committed Oct 7, 2023
1 parent bd7576c commit 535d461
Show file tree
Hide file tree
Showing 8 changed files with 227 additions and 218 deletions.
281 changes: 95 additions & 186 deletions src/main/java/me/alex4386/plugin/typhon/volcano/ash/VolcanoAsh.java

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,7 @@ public void buildBomb(boolean flowLava) {
public void explode() {
Volcano volcano = this.vent.getVolcano();

if (bombRadius >= 2) {
if (bombRadius >= 1) {
Block bombCenter = landingLocation.add(0, bombRadius, 0).getBlock();

volcano.logger.debug(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import me.alex4386.plugin.typhon.TyphonPlugin;
import me.alex4386.plugin.typhon.TyphonUtils;
import me.alex4386.plugin.typhon.volcano.log.VolcanoLogClass;
import me.alex4386.plugin.typhon.volcano.utils.VolcanoCircleOffsetXZ;
import me.alex4386.plugin.typhon.volcano.utils.VolcanoMath;
import me.alex4386.plugin.typhon.volcano.vent.VolcanoVent;
import me.alex4386.plugin.typhon.volcano.vent.VolcanoVentType;
Expand Down Expand Up @@ -159,7 +158,7 @@ public VolcanoBomb generateRandomBomb(Location hostLocation) {
if (multiplier < 0)
return null;

double maxRadius = (1.25 + (Math.random() * 1.0))
double maxRadius = (1.25 + Math.random())
* hostLocation.getWorld().getHighestBlockYAt(hostLocation)
* Math.pow(1.1, multiplier);

Expand Down Expand Up @@ -201,18 +200,29 @@ public double distanceHeightRatio() {
return ((Math.sqrt(3) - 1) * (1 - ratio)) + 1;
}

public VolcanoBomb generateConeBuildingBomb() {
int minRadius = (int) (this.vent.craterRadius * 0.7);
public double getEffectiveConeY() {
int baseY = this.getBaseY();

int minimumScaffoldBombRadius = this.vent.craterRadius * 2;
double minimumScaffoldConeHeight = (minimumScaffoldBombRadius / this.distanceHeightRatio());
double minimumRequiredSummitHeight = baseY + minimumScaffoldConeHeight;
double summitBlockTargetHeight = this.vent.getSummitBlock().getY() + minimumScaffoldConeHeight;

double effectiveSummitHeight = Math.max(minimumRequiredSummitHeight, summitBlockTargetHeight);
int baseYHeight = (int) (effectiveSummitHeight - baseY);
return Math.max(minimumRequiredSummitHeight, summitBlockTargetHeight);
}

public int getEffectiveConeHeight() {
return (int) (this.getEffectiveConeY() - this.getBaseY());
}

public double getAdequateHeightFromDistance(double distance) {
return this.getEffectiveConeY() - (distance / this.distanceHeightRatio());
}

public VolcanoBomb generateConeBuildingBomb() {
int minRadius = (int) (this.vent.craterRadius * 0.7);

int baseYHeight = this.getEffectiveConeHeight();
double coneRadius = (baseYHeight * this.distanceHeightRatio());
int maxRadius = (int) Math.max(coneRadius * 1.5, minRadius);
int defaultRadius = maxRadius;
Expand All @@ -228,8 +238,8 @@ public VolcanoBomb generateConeBuildingBomb() {
distance = (int) (Math.pow(Math.random(), 2) * (maxRadius - defaultRadius) + defaultRadius);
}

double adequateHeight = effectiveSummitHeight - (distance / this.distanceHeightRatio());
double distanceFromCore = distance;
double adequateHeight = this.getAdequateHeightFromDistance(distanceFromCore);

Block randomBlock = TyphonUtils.getHighestRocklikes(
TyphonUtils.getFairRandomBlockInRange(
Expand Down Expand Up @@ -257,13 +267,19 @@ else if (distanceFromCore < this.vent.craterRadius * 2) {
int radius = 0;
if (diff < 1) radius = 0;
else if (diff <= 3) radius = 1;
else radius = (int) Math.min(maxBombRadius, (diff - 1) / 2);
else radius = 2;

// upper limiting
if (radius >= 4) radius = 4;
double height = this.vent.averageVentHeight() - this.vent.location.getBlockY();
if ((height / 3) < radius) {
radius = Math.max(1, Math.min((int) (height / 3), radius));
}

this.vent.volcano.logger.log(VolcanoLogClass.BOMB_LAUNCHER, distanceFromCore+" distance. radius: "+radius);
int willGrowUpTo = randomBlock.getY() + radius;
if (willGrowUpTo > this.vent.averageVentHeight() + 2) {
radius -= (willGrowUpTo - (int) (this.vent.averageVentHeight() + 2));
}

if (radius < 0) return null;
return this.generateBombToDestination(randomBlock.getLocation(), radius);
} else if (diff < 0) {
if (Math.random() < 0.25) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

public enum VolcanoEruptStyle {
// lava lake + lava fountain (minimal), lava flow is everything of this.
HAWAIIAN("hawaiian", new String[] { "effusive" }, VolcanoEruptCauseType.MAGMATIC, 5, 1, 0.2),
HAWAIIAN("hawaiian", new String[] { "effusive" }, VolcanoEruptCauseType.MAGMATIC, 5, 0.2, 0.4),

// Lava fountain (with volcanic bombs) + can have lava flows, but minimal.
// Usually goes into
Expand All @@ -17,24 +17,24 @@ public enum VolcanoEruptStyle {
// lessly used in
// here
STROMBOLIAN(
"strombolian", new String[] { "stromboli" }, VolcanoEruptCauseType.MAGMATIC, 1, 1, 0.7),
"strombolian", new String[] { "stromboli" }, VolcanoEruptCauseType.MAGMATIC, 1, 1, 1),

// stromboli but, range longer + with ash
// rocks: andestic volcanic bombs (+ tuff)
VULCANIAN("vulcanian", new String[] {}, VolcanoEruptCauseType.MAGMATIC, 8, 5, 1),
VULCANIAN("vulcanian", new String[] {}, VolcanoEruptCauseType.MAGMATIC, 8, 2, 1.3),

// BUILD Lava dome first.
// andesite lava dome -> explode it. + lava overflow + pyroclastic flows +
// volcanic bombs (+
// tuff)
// less volume but range is plinian or vulcanian
// tuff pyroclastic flows
PELEAN("pelean", new String[] { "pelèan" }, VolcanoEruptCauseType.MAGMATIC, 8, 5, 1.4),
PELEAN("pelean", new String[] { "pelèan" }, VolcanoEruptCauseType.MAGMATIC, 8, 4, 1.7),

// no lava overflow + caldera + top collapse + (granite) rhyolite volcano bombs
// (A LOT)
// **RAINING TUFF**
PLINIAN("plinian", new String[] { "vesuvian" }, VolcanoEruptCauseType.MAGMATIC, 0, 0, 1.7),
PLINIAN("plinian", new String[] { "vesuvian" }, VolcanoEruptCauseType.MAGMATIC, 0, 0, 2.5),
;

String rawType;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ public void explodeQueued() {

queuedBombs -= bombCount;

boolean queueComplete = queuedBombs == 0;
boolean queueComplete = queuedBombs <= 0;

Location targetVent = this.selectEruptionVent();

Expand Down Expand Up @@ -185,12 +185,7 @@ public void explodeQueued() {
VolcanoLogClass.EXPLOSION,
bombCount+" bombs thrown. Currently Queued: "+queuedBombs
);

Location plumeSrc = TyphonUtils.getHighestLocation(
TyphonUtils.getRandomBlockInRange(targetVent.getBlock(),
0, (int) (this.vent.getRadius() * 0.7)).getLocation()
).getBlock().getRelative(BlockFace.UP).getLocation();
this.vent.ash.createAshPlume(plumeSrc);
this.vent.ash.createAshPlume();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,38 @@ public void onBlockFromTo(BlockFromToEvent event) {
}
}
*/
// calculate flow direction
boolean isPrimary = true;
if (data.fromBlock != null) {
BlockFace fromFace = data.fromBlock.getFace(block);
if (fromFace != BlockFace.DOWN) {
if (fromFace != null) {
isPrimary = face.getDirection().equals(fromFace.getDirection());
}
}
}

if (face == BlockFace.DOWN) {
isPrimary = true;
}

int decrementAmount = block.getWorld().isUltraWarm() ? 1 : 2;
int levelConverted = level >= 8 ? 8 : (8 - level);

int levelT = isPrimary ? levelConverted : levelConverted - decrementAmount;
double ratio = Math.min(1, Math.max(0, levelT / (8.0 - decrementAmount)));

double levelProbability = Math.pow(ratio, 2);
if (isPrimary) {
levelProbability = Math.pow(ratio, 1.25);
}

if (Math.random() < this.getLavaStickiness()) {
if (Math.random() > levelProbability) {
event.setCancelled(true);
return;
}
}

if (this.vent != null && !data.isBomb && data.source != null) {
double distance;
Expand Down Expand Up @@ -917,6 +949,10 @@ public void extendLava(Block block) {
flowLava(fromVent, block);
}

public double getLavaStickiness() {
return (this.settings.silicateLevel - 0.48 / 0.63 - 0.48);
}

public boolean extensionCapable(Location location) {
if (this.vent != null) {
if (this.vent.getType() == VolcanoVentType.CRATER) {
Expand Down Expand Up @@ -995,7 +1031,23 @@ public void runPillowLavaTick() {


if (underBlock.getType() == Material.MAGMA_BLOCK) {
underBlock.setType(material);
VolcanoPillowLavaData underLavaData = pillowLavaMap.get(underBlock);
if (underLavaData != null) {
int underFluidlevel = underLavaData.fluidLevel;
int level = lavaData.fluidLevel;
int levelSum = underFluidlevel + level;
if (levelSum > 8) {
flowedBlocks.add(underBlock);
lavaData.fluidLevel = levelSum - 8;
} else {
underLavaData.fluidLevel += level;
underLavaData.extensionCount += lavaData.extensionCount;
flowedBlocks.add(block);
continue;
}
} else {
underBlock.setType(material);
}
} else if (underBlock.isEmpty() || TyphonUtils.containsLiquidWater(underBlock)) {
if (!isPillowLavaRegistered(underBlock)) {
registerLavaCoolData(
Expand All @@ -1015,7 +1067,11 @@ public void runPillowLavaTick() {
// flow on surface
int extension = lavaData.extensionCount;
int level = lavaData.fluidLevel;
level -= Math.min((int) (Math.random() * 4) + 1, 1);

int levelDeductionRate = (this.settings.silicateLevel < 0.63) ? (
(Math.random() > this.getLavaStickiness()) ? 1 : 2
) : 2;
level -= levelDeductionRate;

if (!this.extensionCapable(block.getLocation())) {
extension = 0;
Expand All @@ -1036,6 +1092,14 @@ public void runPillowLavaTick() {
level = 8;
}

BlockFace primaryFlow = null;
if (lavaData.fromBlock != null) {
primaryFlow = lavaData.fromBlock.getFace(block);
if (primaryFlow != BlockFace.DOWN) {
primaryFlow = null;
}
}

BlockFace[] flowableFaces = {
BlockFace.NORTH,
BlockFace.WEST,
Expand All @@ -1045,10 +1109,26 @@ public void runPillowLavaTick() {

for (BlockFace flowableFace : flowableFaces) {
Block flowTarget = block.getRelative(flowableFace);
if (level <= 4) {
if (Math.random() > 0.2 * level) {
continue;
}

boolean isPrimary = false;
int levelT = (primaryFlow != null) ?
level - levelDeductionRate : level;

if (primaryFlow != null) {
isPrimary = primaryFlow.getDirection().equals(flowableFace.getDirection());
levelT = isPrimary ? level : levelT;
}
if (level <= 0) continue;

double ratio = Math.min(1, Math.max(0, levelT / 6.0));

double levelProbability = Math.pow(ratio, 2);
if (isPrimary) {
levelProbability = Math.pow(ratio, 1.25);
}

if (Math.random() > levelProbability) {
continue;
}

if (flowTarget.getType().isAir()
Expand All @@ -1069,7 +1149,7 @@ public void runPillowLavaTick() {
} else {
VolcanoPillowLavaData pillowData = cachedPillowLavaMap.get(flowTarget);
if (pillowData != null) {
pillowData.fluidLevel = level;
pillowData.fluidLevel = levelT;
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
public class VolcanoSuccession {
// Implements Primary Succession
Volcano volcano;
boolean isEnabled = true;
boolean isEnabled = false;

double cyclesPerTick = 1;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -679,6 +679,15 @@ public Block getSummitBlock() {
highestBlock = cachedVentBlocks.get(0);
}

// update base, since it is now an island.
int seaLevel = highestBlock.getWorld().getSeaLevel();
if (bombs.getBaseY() < seaLevel) {
if (highestBlock.getY() > seaLevel + 2) {
bombs.baseY = seaLevel;
volcano.trySave();
}
}

this.cachedSummitBlock = highestBlock;
this.cachedSummitBlockLastSync = System.currentTimeMillis();
return highestBlock;
Expand Down

0 comments on commit 535d461

Please sign in to comment.