Skip to content

Commit

Permalink
chore: better scoria composition setup
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex4386 committed Jun 23, 2024
1 parent a99bcbb commit d092f29
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,16 @@ public static Material getBombRock(double silicateLevel, double distanceScale) {
Random random = new Random();

if (silicateLevel < 0.57) {
double redScoriaRatio = silicateLevel < 0.52 ?
1 - ((silicateLevel - 0.45) / (0.52 - 0.45)) : 0;

double scoriaPercentage = Math.pow(redScoriaRatio, 2) * 0.75;
double otherPercentage = 1 - scoriaPercentage;

double scaled = Math.pow(distanceScale, 2) * scoriaPercentage;
double threshold = otherPercentage + scaled;
double redScoriaRatio =
1 - ((silicateLevel - 0.45) / (0.57 - 0.45));

double redScoriaPercentage = Math.max(Math.pow(redScoriaRatio, 2), 0.99);
double scaled = distanceScale * redScoriaPercentage;
double s = random.nextDouble();

if (s < threshold) {
System.out.println("redScoriaPercentage: "+redScoriaPercentage+", distanceScale:"+distanceScale+", Scaled: " + scaled);

if (s < scaled) {
return Material.COBBLED_DEEPSLATE;
} else {
// purple-red scoria
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,12 @@ public VolcanoBomb(
}

public double getDistanceRatio() {
return this.getDistanceRatio(this.landingLocation);
}

public double getDistanceRatio(Location location) {
if (this.vent == null) return 1;
return this.vent.lavaFlow.getDistanceRatio(this.landingLocation);
return this.vent.lavaFlow.getDistanceRatio(location);
}

public void launch() {
Expand All @@ -81,7 +85,7 @@ public void launch() {
new MaterialData(
VolcanoComposition.getBombRock(
this.vent.lavaFlow.settings.silicateLevel,
this.getDistanceRatio())));
this.getDistanceRatio(null))));

this.block.setGlowing(true);

Expand Down Expand Up @@ -371,7 +375,7 @@ public void buildBomb(boolean flowLava) {
finalBlock.getWorld().createExplosion(finalBlock.getLocation(), 1, true, false);
} else {
for (Block bombBlock : bomb) {
Material material = VolcanoComposition.getBombRock(lavaFlow.settings.silicateLevel, this.getDistanceRatio());
Material material = VolcanoComposition.getBombRock(lavaFlow.settings.silicateLevel, this.getDistanceRatio(finalBlock.getLocation(bombBlock.getLocation())));
if (vent == null)
bombBlock.setType(material);
else
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,6 @@ public boolean onCommand(CommandSender sender, Command command, String label, St
msg.info("Builder type has been set to "+type.getName());
} else {
msg.error("Failed to set arguments for builder type "+type.getName());
vent.builder = null;
}
}
}
Expand Down Expand Up @@ -895,6 +894,12 @@ public boolean onCommand(CommandSender sender, Command command, String label, St
+ " @ "
+ String.format("%.2f", vent.longestFlowLength)
+ "m");
msg.info(
" Normal: "
+ String.format("%.2f", vent.longestNormalLavaFlowLength) + "m (now: "
+ String.format("%.2f", vent.currentNormalLavaFlowLength) + "m"
);

msg.info(
" - Bomb : "
+ vent.isExploding()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package me.alex4386.plugin.typhon.volcano.explosion;

import me.alex4386.plugin.typhon.TyphonPlugin;
import me.alex4386.plugin.typhon.TyphonScheduler;
import me.alex4386.plugin.typhon.TyphonSounds;
import me.alex4386.plugin.typhon.TyphonUtils;
import me.alex4386.plugin.typhon.volcano.erupt.VolcanoEruptStyle;
Expand Down Expand Up @@ -39,28 +40,22 @@ public void registerTask() {
this.vent.volcano.logger.log(
VolcanoLogClass.EXPLOSION,
"Registering VolcanoExplosion for vent " + vent.getName());
this.scheduleID = Bukkit.getScheduler()
.scheduleSyncRepeatingTask(
TyphonPlugin.plugin,
this.scheduleID = TyphonScheduler.registerGlobalTask(
() -> {
if (this.enabled) {
explodeQueued();
}
},
0l,
1l);
}

if (this.queueScheduleID < 0) {
this.queueScheduleID = Bukkit.getScheduler()
.scheduleSyncRepeatingTask(
TyphonPlugin.plugin,
this.queueScheduleID = TyphonScheduler.registerGlobalTask(
() -> {
if (this.enabled && this.running) {
if (!this.vent.erupt.getStyle().canFormCaldera) explode();
}
},
0l,
5l);
}
}
Expand All @@ -70,8 +65,8 @@ public void unregisterTask() {
this.vent.volcano.logger.log(
VolcanoLogClass.EXPLOSION,
"Unregistering VolcanoExplosion for vent " + vent.getName());
Bukkit.getScheduler().cancelTask(scheduleID);
Bukkit.getScheduler().cancelTask(queueScheduleID);
TyphonScheduler.unregisterTask(scheduleID);
TyphonScheduler.unregisterTask(queueScheduleID);
scheduleID = -1;
queueScheduleID = -1;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -520,7 +520,7 @@ public void onBlockFromTo(BlockFromToEvent event) {
}

if (distance > vent.currentFlowLength) {
vent.longestFlowLength = distance;
vent.currentFlowLength = distance;
trySave = true;
}

Expand Down Expand Up @@ -1201,17 +1201,23 @@ public void addRootlessCone(Location location) {
}

public double getDistanceRatio(Location dest) {
if (dest == null || this.vent == null) return 1;
double distance = TyphonUtils.getTwoDimensionalDistance(vent.location, dest);
int radius = 0;
if (vent != null) {
radius = vent.getRadius();
}

double maxRange = 100.0;
int distanceFromVent = (int) Math.max(0, Math.min(distance - radius, maxRange));
double scaledDistance = distanceFromVent / maxRange;
assert this.vent != null;

double coneHeight = Math.max(1, this.vent.getSummitBlock().getY() - this.vent.bombs.baseY);

double distanceFromVent = Math.max(0, Math.min(distance - radius, coneHeight));
double scaledDistance = distanceFromVent / coneHeight;

System.out.println("coneHeight: "+coneHeight+", distance: "+distance+", radius: "+radius+", distanceFromVent: "+distanceFromVent+", scaledDistance: "+scaledDistance);

return Math.pow(scaledDistance, 2);
return Math.min(Math.pow(scaledDistance, 2), 1);
}

public boolean extendLava() {
Expand Down

0 comments on commit d092f29

Please sign in to comment.