Skip to content

Commit

Permalink
chore: miscellaneous patches
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex4386 committed Dec 17, 2023
1 parent 918e8ce commit a17a94c
Show file tree
Hide file tree
Showing 9 changed files with 109 additions and 27 deletions.
3 changes: 2 additions & 1 deletion src/main/java/me/alex4386/plugin/typhon/TyphonCache.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@

public class TyphonCache<T> {
T target;
long lastUpdate = System.currentTimeMillis();
long lastUpdate;

public long cacheValidity = 20;

public TyphonCache(T target) {
this.target = target;
this.lastUpdate = System.currentTimeMillis();
}

public TyphonCache(T target, long cacheValidity) {
Expand Down
1 change: 1 addition & 0 deletions src/main/java/me/alex4386/plugin/typhon/TyphonUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,7 @@ public static long getBlockUpdatesPerSecond() {

public static boolean isMaterialTree(org.bukkit.Material material) {
String materialType = TyphonUtils.toLowerCaseDumbEdition(material.name());

return (materialType.contains("leaves")
|| materialType.contains("log")
|| materialType.contains("plank")
Expand Down
20 changes: 10 additions & 10 deletions src/main/java/me/alex4386/plugin/typhon/volcano/ash/VolcanoAsh.java
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,11 @@ public void shutdownPyroclasticFlows() {
}
}
public int getTargetHeight(Location location) {
double distance = vent.getTwoDimensionalDistance(location);
double distance = Math.max(vent.getTwoDimensionalDistance(location) - vent.getRadius(), 0);
if (vent.isInVent(location)) {
return vent.getSummitBlock().getY() - (int) (vent.getRadius() - vent.getTwoDimensionalDistance(location));
}

double height = Math.max(0, vent.getSummitBlock().getY() - vent.bombs.getBaseY());
if (distance > (4 * Math.sqrt(3) * height / 3)) return 0;

Expand Down Expand Up @@ -189,14 +193,6 @@ public void processAshClouds() {
if (Math.random() < 0.1 * bd.multiplier) {
bd.fallAsh();
}

if (bd.multiplier > 2) {
if (Math.random() < 0.02 * bd.multiplier) {
if (vent.isInVent(bd.bd.getLocation())) {
bd.lightning();
}
}
}
}

this.clearOrphanedAshClouds(false);
Expand Down Expand Up @@ -248,7 +244,11 @@ public void triggerPyroclasticFlow() {
this.triggerPyroclasticFlow(this.vent.selectFlowVentBlock(Math.random() < 0.6));
}

public void triggerPyroclasticFlow(Block block) {
public void triggerPyroclasticFlow(Block srcblock) {
Location target = srcblock.getLocation();
target.setY(srcblock.getWorld().getMaxHeight());
Block block = TyphonUtils.getHighestRocklikes(target);

this.vent.getVolcano().logger.log(VolcanoLogClass.ASH, "Triggering Pyroclastic Flows @ "+TyphonUtils.blockLocationTostring(block));
VolcanoPyroclasticFlow flow = new VolcanoPyroclasticFlow(TyphonUtils.getHighestRocklikes(block).getLocation().add(0, 1, 0), this);
this.pyroclasticFlows.add(flow);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,7 @@ public void land() {
}

if (TyphonPlugin.isShuttingdown) return;

Block targetBlock = TyphonUtils.getHighestRocklikes(nearestVent.getNearestVentBlock(this.landingLocation));
boolean isAllowedToGrowUp = nearestVent.averageVentHeight() == nearestVent.getSummitBlock().getY();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ public double getAdequateHeightFromDistance(double distance) {
}

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

int baseYHeight = this.getEffectiveConeHeight();
double coneRadius = (baseYHeight * this.distanceHeightRatio());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,24 +17,24 @@ public enum VolcanoEruptStyle {
// lessly used in
// here
STROMBOLIAN(
"strombolian", new String[] { "stromboli" }, VolcanoEruptCauseType.MAGMATIC, 1, 1, 1),
"strombolian", new String[] { "stromboli" }, VolcanoEruptCauseType.MAGMATIC, 0, 1, 1),

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

// 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, 4, 1.7),
PELEAN("pelean", new String[] { "pelèan" }, VolcanoEruptCauseType.MAGMATIC, 8, 4, 4),

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

String rawType;
Expand Down Expand Up @@ -78,8 +78,9 @@ public enum VolcanoEruptStyle {
}

public double getPyroclasticFlowMultiplier() {
if (this == VolcanoEruptStyle.VULCANIAN || this == VolcanoEruptStyle.PLINIAN) return 0.2;
else if (this == VolcanoEruptStyle.PELEAN) return 0.6;
if (this.ashMultiplier > 1) {
return this.ashMultiplier - 1;
}

return 0;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -193,9 +193,11 @@ public void runQueueComplete(Location targetVent) {
if (this.vent != null) {
double pyroclast = this.vent.erupt.getStyle().getPyroclasticFlowMultiplier();
if (pyroclast > 0) {
if (Math.random() < pyroclast) {
this.vent.ash.createAshPlume(targetVent);
this.vent.ash.triggerPyroclasticFlow();
for (int i = 0; i < pyroclast; i++) {
if (Math.random() < 0.4) {
this.vent.ash.createAshPlume(targetVent);
this.vent.ash.triggerPyroclasticFlow();
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,14 +105,27 @@ public void removeTree(Block baseBlock) {
public void removeTree(Block baseBlock, int maxRecursion) {
if (maxRecursion < 0 || !TyphonUtils.isMaterialTree(baseBlock.getType())) return;

BlockFace[] facesToSearch = {BlockFace.UP, BlockFace.WEST, BlockFace.DOWN, BlockFace.EAST, BlockFace.NORTH, BlockFace.SOUTH, BlockFace.DOWN};
BlockFace[] facesToSearch = {BlockFace.UP, BlockFace.DOWN, BlockFace.WEST, BlockFace.DOWN, BlockFace.EAST, BlockFace.NORTH, BlockFace.SOUTH, BlockFace.DOWN};

for (BlockFace face : facesToSearch) {
Block block = baseBlock.getRelative(face);
if (TyphonUtils.isMaterialTree(block.getType())) {
removeTree(block, maxRecursion - 1);
}
}

// improvise cherry log detection algorithm
if (baseBlock.getType() == Material.CHERRY_LOG) {
// extra search
Block upBlock = baseBlock.getRelative(BlockFace.UP);
for (BlockFace face : facesToSearch) {
Block block = upBlock.getRelative(face);
if (TyphonUtils.isMaterialTree(block.getType())) {
removeTree(block, maxRecursion - 1);
}
}
}

String name = TyphonUtils.toLowerCaseDumbEdition(baseBlock.getType().name());

if (name.contains("log")) {
Expand All @@ -122,6 +135,49 @@ public void removeTree(Block baseBlock, int maxRecursion) {
}
}

public boolean isFlower(Material material) {
return material == Material.DANDELION ||
material == Material.POPPY ||
material == Material.BLUE_ORCHID ||
material == Material.ALLIUM ||
material == Material.AZURE_BLUET ||
material == Material.RED_TULIP ||
material == Material.ORANGE_TULIP ||
material == Material.WHITE_TULIP ||
material == Material.PINK_TULIP ||
material == Material.OXEYE_DAISY ||
material == Material.CORNFLOWER ||
material == Material.LILY_OF_THE_VALLEY ||
material == Material.TORCHFLOWER ||
material == Material.WITHER_ROSE ||
material == Material.SUNFLOWER ||
material == Material.LILAC ||
material == Material.ROSE_BUSH ||
material == Material.PEONY ||
material == Material.PITCHER_PLANT ||
material == Material.PITCHER_POD;
}

public boolean isPlantlike(Material material) {
return isFlower(material) ||
material == Material.SMALL_DRIPLEAF ||
material == Material.BIG_DRIPLEAF ||
material == Material.BIG_DRIPLEAF_STEM ||
material == Material.GLOW_LICHEN ||
material == Material.HANGING_ROOTS ||
material == Material.ROOTED_DIRT ||
material == Material.MANGROVE_ROOTS ||
material == Material.MUDDY_MANGROVE_ROOTS ||
material == Material.SPORE_BLOSSOM;
}

public boolean isPlaceableAnimalEgg(Material material) {
return material == Material.DRAGON_EGG ||
material == Material.TURTLE_EGG ||
material == Material.SNIFFER_EGG ||
material == Material.FROGSPAWN;
}

public void evaporateBlock(Block block) {
Material material = block.getType();
String blockTypeName = TyphonUtils.toLowerCaseDumbEdition(material.name());
Expand All @@ -144,20 +200,36 @@ public void evaporateBlock(Block block) {
block.setType(Material.AIR);
} else if (blockTypeName.contains("coral")) {
block.setType(Material.SAND);
} else if (material == Material.GRASS) {
} else if (material == Material.GRASS || material == Material.PINK_PETALS) {
block.setType(Material.AIR);
} else if (material == Material.GRASS_BLOCK) {
} else if (material == Material.GRASS_BLOCK || material == Material.ROOTED_DIRT || material == Material.MUDDY_MANGROVE_ROOTS) {
block.setType(Material.DIRT);
} else if (material == Material.TALL_GRASS || material == Material.GRASS) {
} else if (material == Material.TALL_GRASS || material == Material.LARGE_FERN || material == Material.BAMBOO) {
// check under block is not the same type
Block underBlock = block.getRelative(BlockFace.DOWN);
if (underBlock.getType() == material) {
block.setType(Material.AIR);
} else {
block.setType(Material.DEAD_BUSH);
}
} else if (blockTypeName.contains("sapling") || material == Material.MANGROVE_PROPAGULE) {
block.setType(Material.DEAD_BUSH);
} else if (material == Material.SEAGRASS || material == Material.WATER) {
} else if (isFlower(material)) {
block.setType(Material.DEAD_BUSH);
} else if (isPlantlike(material)) {
block.setType(Material.AIR);
} else if (isPlaceableAnimalEgg(material)) {
block.setType(Material.AIR);
} else if (material == Material.SEAGRASS || material == Material.TALL_SEAGRASS) {
block.setType(Material.AIR);
} else if (material == Material.WATER_CAULDRON) {
block.setType(Material.CAULDRON);
} else if (material == Material.MOSS_BLOCK) {
block.setType(Material.DIRT);
} else if (blockTypeName.contains("infested")) {
block.setType(VolcanoComposition.getExtrusiveRock(silicateLevel));
} else if (material == Material.SEA_PICKLE) {
block.setType(Material.AIR);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -445,7 +445,11 @@ public void setType(VolcanoVentType type) {
public double averageVentHeight() {
int totalY = 0;
for (Block block : this.cachedVentBlocks) {
totalY += block.getY();
Location loc = block.getLocation();
loc.setY(block.getWorld().getMaxHeight());

int highestY = TyphonUtils.getHighestRocklikes(loc.getBlock()).getY();
totalY += highestY;
}

return (double) totalY / this.cachedVentBlocks.size();
Expand Down

0 comments on commit a17a94c

Please sign in to comment.