Skip to content

Commit

Permalink
Add unloaded chunk meteor config
Browse files Browse the repository at this point in the history
  • Loading branch information
democat3457 committed Mar 17, 2021
1 parent 7def3e0 commit 406357b
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 2 deletions.
6 changes: 5 additions & 1 deletion src/main/java/de/ellpeck/nyx/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ public final class Config {
public static boolean meteors;
public static int meteorDisallowRadius;
public static int meteorDisallowTime;
public static boolean meteorKillUnloaded;
public static boolean meteorCacheUnloaded;
public static Set<String> enchantingWhitelistDimensions;
public static boolean eventNotifications;
public static int crystalDurability;
Expand Down Expand Up @@ -109,7 +111,9 @@ public static void load() {
meteorChanceEnd = instance.get("meteors", "meteorChanceEnd", 0.003, "The chance of a meteor spawning every second, in the end dimension").getDouble();
meteorSpawnRadius = instance.get("meteors", "meteorSpawnRadius", 1000, "The amount of blocks a meteor can spawn away from the nearest player").getInt();
meteorDisallowRadius = instance.get("meteors", "meteorDisallowRadius", 16, "The radius in chunks that should be marked as invalid for meteor spawning around each player").getInt();
meteorDisallowTime = instance.get("meteors", "meteorDisallowTime", 12000, "The amount of ticks that need to pass for each player until the chance of a meteor spawning in the area is halved (and then halved again, and so on)").getInt();
meteorDisallowTime = instance.get("meteors", "meteorDisallowTime", 12000, "The amount of ticks that need to pass for each player until the chance of a meteor spawning in the area is halved (and then halved again, and so on). This decreases the chance of a meteor hitting a base or player hub").getInt();
meteorKillUnloaded = instance.get("meteors", "meteorKillUnloaded", false, "If meteors passing through unloaded chunks should be removed. If the game is lagging because of the unloaded chunks, try enabling this").getBoolean();
meteorCacheUnloaded = instance.get("meteors", "meteorCacheUnloaded", false, "If meteors passing through unloaded chunks should be cached at that position until entering the unloaded chunk. This option is ignored if meteorKillUnloaded is true.").getBoolean();
crystalDurability = instance.get("meteors", "crystalDurability", 1000, "The amount of uses that a gleaning crystal should have for bone-mealing").getInt();
hammerDamage = instance.get("meteors", "hammerDamage", 15, "The amount of damage that the meteor hammer deals if the maximum flight time was used").getInt();
bowDamageMultiplier = instance.get("meteors", "bowDamageMult", 1.75, "The multiplier for the amount of damage inflicted by the meteor bow's arrows").getDouble();
Expand Down
21 changes: 20 additions & 1 deletion src/main/java/de/ellpeck/nyx/entities/FallingMeteor.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package de.ellpeck.nyx.entities;

import de.ellpeck.nyx.Config;
import de.ellpeck.nyx.Nyx;
import de.ellpeck.nyx.Registry;
import de.ellpeck.nyx.capabilities.NyxWorld;
Expand Down Expand Up @@ -70,8 +71,26 @@ public void setLocationAndAngles(double x, double y, double z, float yaw, float
protected void customUpdate() {
if (!this.world.isRemote) {
// falling into the void
if (this.posY <= -64)
if (this.posY <= -64) {
this.setDead();
return;
}

// Kill meteors that are in unloaded chunks?
if (Config.meteorKillUnloaded && !this.world.isBlockLoaded(this.getPosition(), false)) {
this.setDead();
return;
}

// Cache meteors that are in unloaded chunks?
if (Config.meteorCacheUnloaded && !this.world.isBlockLoaded(this.getPosition(), false)) {
NyxWorld data = NyxWorld.get(this.world);
data.cachedMeteorPositions.add(this.getPosition());
data.sendToClients();

this.setDead();
return;
}

// move towards the closest player if we're homing
if (this.homing) {
Expand Down
6 changes: 6 additions & 0 deletions src/main/java/de/ellpeck/nyx/events/Events.java
Original file line number Diff line number Diff line change
Expand Up @@ -214,20 +214,26 @@ public static void onWorldTick(TickEvent.WorldTickEvent event) {
// Meteors
meteors:
if (!event.world.isRemote && Config.meteors && event.world.getTotalWorldTime() % 20 == 0) {
// Get random player
if (event.world.playerEntities.size() <= 0)
break meteors;
EntityPlayer selectedPlayer = event.world.playerEntities.get(event.world.rand.nextInt(event.world.playerEntities.size()));
if (selectedPlayer == null)
break meteors;

// Find random spawn pos near player
double spawnX = selectedPlayer.posX + MathHelper.nextDouble(event.world.rand, -Config.meteorSpawnRadius, Config.meteorSpawnRadius);
double spawnZ = selectedPlayer.posZ + MathHelper.nextDouble(event.world.rand, -Config.meteorSpawnRadius, Config.meteorSpawnRadius);
BlockPos spawnPos = new BlockPos(spawnX, 0, spawnZ);

// Determine chance
double chance = Config.getMeteorChance(event.world, data);
MutableInt ticksInArea = data.playersPresentTicks.get(new ChunkPos(spawnPos));
if (ticksInArea != null && ticksInArea.intValue() >= Config.meteorDisallowTime)
chance /= Math.pow(2, ticksInArea.intValue() / (double) Config.meteorDisallowTime);
if (chance <= 0 || !(event.world.rand.nextFloat() <= chance))
break meteors;

if (!event.world.isBlockLoaded(spawnPos, false)) {
// add meteor information to cache
data.cachedMeteorPositions.add(spawnPos);
Expand Down

0 comments on commit 406357b

Please sign in to comment.