mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2026-04-07 16:26:14 +00:00
Entity spawns
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package com.volmit.iris.generator;
|
||||
|
||||
import com.volmit.iris.Iris;
|
||||
import com.volmit.iris.IrisSettings;
|
||||
import com.volmit.iris.generator.actuator.IrisTerrainActuator;
|
||||
import com.volmit.iris.generator.modifier.IrisCaveModifier;
|
||||
import com.volmit.iris.generator.noise.CNG;
|
||||
@@ -74,7 +75,7 @@ public class IrisComplex implements DataProvider
|
||||
|
||||
public IrisComplex(Engine engine)
|
||||
{
|
||||
int cacheSize = 8192;
|
||||
int cacheSize = IrisSettings.get().getStreamingCacheSize();
|
||||
this.rng = new RNG(engine.getWorld().getSeed());
|
||||
this.data = engine.getData();
|
||||
double height = engine.getHeight();
|
||||
|
||||
@@ -99,7 +99,6 @@ public class IrisEngine extends BlockPopulator implements Engine
|
||||
() -> getFramework().getPostModifier().modify(x, z, blocks),
|
||||
() -> getFramework().getDecorantActuator().actuate(x, z, blocks)
|
||||
);
|
||||
;
|
||||
|
||||
getFramework().getEngineParallax().insertParallax(x, z, blocks);
|
||||
getFramework().recycle();
|
||||
|
||||
@@ -4,7 +4,6 @@ import com.volmit.iris.Iris;
|
||||
import com.volmit.iris.manager.IrisDataManager;
|
||||
import com.volmit.iris.object.IrisDimension;
|
||||
import com.volmit.iris.object.IrisDimensionIndex;
|
||||
import com.volmit.iris.util.KList;
|
||||
import com.volmit.iris.scaffold.engine.Engine;
|
||||
import com.volmit.iris.scaffold.engine.EngineCompound;
|
||||
import com.volmit.iris.scaffold.engine.EngineData;
|
||||
@@ -12,7 +11,9 @@ import com.volmit.iris.scaffold.engine.EngineTarget;
|
||||
import com.volmit.iris.scaffold.hunk.Hunk;
|
||||
import com.volmit.iris.scaffold.parallel.BurstExecutor;
|
||||
import com.volmit.iris.scaffold.parallel.MultiBurst;
|
||||
import com.volmit.iris.util.KList;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.block.Biome;
|
||||
import org.bukkit.block.data.BlockData;
|
||||
@@ -45,6 +46,10 @@ public class IrisEngineCompound implements EngineCompound {
|
||||
@Getter
|
||||
private int threadCount;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
private boolean studio;
|
||||
|
||||
public IrisEngineCompound(World world, IrisDimension rootDimension, IrisDataManager data, int maximumThreads)
|
||||
{
|
||||
this.rootDimension = rootDimension;
|
||||
|
||||
@@ -1,20 +1,24 @@
|
||||
package com.volmit.iris.generator;
|
||||
|
||||
import com.volmit.iris.IrisSettings;
|
||||
import com.volmit.iris.object.*;
|
||||
import com.volmit.iris.scaffold.cache.Cache;
|
||||
import com.volmit.iris.scaffold.engine.Engine;
|
||||
import com.volmit.iris.scaffold.engine.EngineAssignedWorldManager;
|
||||
import com.volmit.iris.util.J;
|
||||
import com.volmit.iris.util.KList;
|
||||
import com.volmit.iris.util.RNG;
|
||||
import org.bukkit.Chunk;
|
||||
import org.bukkit.event.block.BlockBreakEvent;
|
||||
import org.bukkit.event.block.BlockPlaceEvent;
|
||||
import org.bukkit.event.entity.EntitySpawnEvent;
|
||||
|
||||
public class IrisWorldManager extends EngineAssignedWorldManager {
|
||||
private boolean spawnable;
|
||||
|
||||
public IrisWorldManager(Engine engine) {
|
||||
super(engine);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onEntitySpawn(EntitySpawnEvent e) {
|
||||
|
||||
spawnable = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -28,8 +32,116 @@ public class IrisWorldManager extends EngineAssignedWorldManager {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void spawnInitialEntities(Chunk chunk) {
|
||||
public void spawnInitialEntities(Chunk c) {
|
||||
RNG rng = new RNG(Cache.key(c));
|
||||
int x = (c.getX() * 16) + rng.nextInt(15);
|
||||
int z = (c.getZ() * 16) + rng.nextInt(15);
|
||||
int y = getEngine().getHeight(x, z) + 1;
|
||||
IrisDimension dim = getDimension();
|
||||
IrisRegion region = getEngine().getRegion(x, z);
|
||||
IrisBiome above = getEngine().getSurfaceBiome(x, z);
|
||||
trySpawn(above.getEntityInitialSpawns(), c, rng);
|
||||
trySpawn(region.getEntityInitialSpawns(), c, rng);
|
||||
trySpawn(dim.getEntityInitialSpawns(), c, rng);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onEntitySpawn(EntitySpawnEvent e)
|
||||
{
|
||||
if(getTarget().getWorld() == null || !getTarget().getWorld().equals(e.getEntity().getWorld()))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
if(!IrisSettings.get().isSystemEntitySpawnOverrides())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
int x = e.getEntity().getLocation().getBlockX();
|
||||
int y = e.getEntity().getLocation().getBlockY();
|
||||
int z = e.getEntity().getLocation().getBlockZ();
|
||||
|
||||
J.a(() ->
|
||||
{
|
||||
if(spawnable)
|
||||
{
|
||||
IrisDimension dim = getDimension();
|
||||
IrisRegion region = getEngine().getRegion(x, z);
|
||||
IrisBiome above = getEngine().getSurfaceBiome(x, z);
|
||||
IrisBiome bbelow = getEngine().getBiome(x, y, z);
|
||||
if(above.getLoadKey().equals(bbelow.getLoadKey()))
|
||||
{
|
||||
bbelow = null;
|
||||
}
|
||||
|
||||
IrisBiome below = bbelow;
|
||||
|
||||
J.s(() ->
|
||||
{
|
||||
if(below != null)
|
||||
{
|
||||
if(trySpawn(below.getEntitySpawnOverrides(), e))
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if(trySpawn(above.getEntitySpawnOverrides(), e))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if(trySpawn(region.getEntitySpawnOverrides(), e))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if(trySpawn(dim.getEntitySpawnOverrides(), e))
|
||||
{
|
||||
return;
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
catch(Throwable xe)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
private boolean trySpawn(KList<IrisEntitySpawnOverride> s, EntitySpawnEvent e)
|
||||
{
|
||||
for(IrisEntitySpawnOverride i : s)
|
||||
{
|
||||
spawnable = false;
|
||||
|
||||
if(i.on(getEngine(), e.getLocation(), e.getEntityType(), e) != null)
|
||||
{
|
||||
e.setCancelled(true);
|
||||
e.getEntity().remove();
|
||||
return true;
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
spawnable = true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private void trySpawn(KList<IrisEntityInitialSpawn> s, Chunk c, RNG rng)
|
||||
{
|
||||
for(IrisEntityInitialSpawn i : s)
|
||||
{
|
||||
i.spawn(getEngine(), c, rng);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user