Stronkholds

This commit is contained in:
Daniel Mills 2021-08-04 02:07:55 -04:00
parent 8c4a74179d
commit 1155789a75
2 changed files with 64 additions and 0 deletions

View File

@ -19,12 +19,19 @@
package com.volmit.iris.engine.framework; package com.volmit.iris.engine.framework;
import com.volmit.iris.Iris; import com.volmit.iris.Iris;
import com.volmit.iris.engine.object.IrisPosition;
import com.volmit.iris.util.collection.KList;
import com.volmit.iris.util.math.Position2;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.Chunk; import org.bukkit.Chunk;
import org.bukkit.Location;
import org.bukkit.entity.EnderSignal;
import org.bukkit.entity.EntityType;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener; import org.bukkit.event.Listener;
import org.bukkit.event.block.BlockBreakEvent; import org.bukkit.event.block.BlockBreakEvent;
import org.bukkit.event.block.BlockPlaceEvent; import org.bukkit.event.block.BlockPlaceEvent;
import org.bukkit.event.entity.ProjectileLaunchEvent;
import org.bukkit.event.world.ChunkLoadEvent; import org.bukkit.event.world.ChunkLoadEvent;
import org.bukkit.event.world.WorldSaveEvent; import org.bukkit.event.world.WorldSaveEvent;
import org.bukkit.event.world.WorldUnloadEvent; import org.bukkit.event.world.WorldUnloadEvent;
@ -50,6 +57,35 @@ public abstract class EngineAssignedWorldManager extends EngineAssignedComponent
} }
} }
@EventHandler
public void on(ProjectileLaunchEvent e) {
if (e.getEntity().getWorld().equals(getTarget().getWorld().realWorld())) {
if(e.getEntityType().equals(EntityType.ENDER_SIGNAL))
{
KList<Position2> p = getEngine().getDimension().getStrongholds(getEngine().getWorld().seed());
Position2 px = new Position2(e.getEntity().getLocation().getBlockX(), e.getEntity().getLocation().getBlockZ());
Position2 pr = null;
double d = Double.MAX_VALUE;
for(Position2 i : p)
{
double dx = i.distance(px);
if(dx < d)
{
d = dx;
pr = i;
}
}
if(pr != null)
{
Iris.info("Taking you to " + pr.getX() + " " + pr.getZ());
((EnderSignal) e.getEntity()).setTargetLocation(new Location(e.getEntity().getWorld(), pr.getX(), 40, pr.getZ()));
}
}
}
}
@EventHandler @EventHandler
public void on(WorldUnloadEvent e) { public void on(WorldUnloadEvent e) {
if (e.getWorld().equals(getTarget().getWorld().realWorld())) { if (e.getWorld().equals(getTarget().getWorld().realWorld())) {

View File

@ -26,6 +26,7 @@ import com.volmit.iris.engine.noise.CNG;
import com.volmit.iris.engine.object.annotations.*; import com.volmit.iris.engine.object.annotations.*;
import com.volmit.iris.util.collection.KList; import com.volmit.iris.util.collection.KList;
import com.volmit.iris.util.io.IO; import com.volmit.iris.util.io.IO;
import com.volmit.iris.util.math.BlockPosition;
import com.volmit.iris.util.math.Position2; import com.volmit.iris.util.math.Position2;
import com.volmit.iris.util.math.RNG; import com.volmit.iris.util.math.RNG;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
@ -67,6 +68,12 @@ public class IrisDimension extends IrisRegistrant {
@Desc("If defined, Iris will place the given jigsaw structure where minecraft should place the overworld stronghold.") @Desc("If defined, Iris will place the given jigsaw structure where minecraft should place the overworld stronghold.")
private String stronghold; private String stronghold;
@Desc("The average distance between strongholds")
private int strongholdJumpDistance = 1280;
@Desc("Define the maximum strongholds to place")
private int maxStrongholds = 14;
@Desc("Improves the biome grid variation by shuffling the cell grid more depending on the seed. This makes biomes across multiple seeds look far different than before.") @Desc("Improves the biome grid variation by shuffling the cell grid more depending on the seed. This makes biomes across multiple seeds look far different than before.")
private boolean aggressiveBiomeReshuffle = false; private boolean aggressiveBiomeReshuffle = false;
@ -308,6 +315,27 @@ public class IrisDimension extends IrisRegistrant {
private final transient AtomicCache<Double> cosr = new AtomicCache<>(); private final transient AtomicCache<Double> cosr = new AtomicCache<>();
private final transient AtomicCache<Double> rad = new AtomicCache<>(); private final transient AtomicCache<Double> rad = new AtomicCache<>();
private final transient AtomicCache<Boolean> featuresUsed = new AtomicCache<>(); private final transient AtomicCache<Boolean> featuresUsed = new AtomicCache<>();
private final transient AtomicCache<KList<Position2>> strongholdsCache = new AtomicCache<>();
public KList<Position2> getStrongholds(long seed)
{
return strongholdsCache.aquire(() -> {
KList<Position2> pos = new KList<>();
int jump = strongholdJumpDistance;
RNG rng = new RNG((seed * 223) + 12945);
for(int i = 0; i < maxStrongholds; i++)
{
int m = i + 1;
pos.add(new Position2(
(int) ((rng.i( jump * i) + (jump * i)) * (rng.b() ? -1D : 1D)),
(int) ((rng.i( jump * i) + (jump * i)) * (rng.b() ? -1D : 1D))
));
}
return pos;
});
}
public boolean hasSky() { public boolean hasSky() {
return getSky() != null; return getSky() != null;