9
0
mirror of https://github.com/VolmitSoftware/Iris.git synced 2026-01-06 15:51:30 +00:00

Custom entity spawns

This commit is contained in:
Daniel Mills
2020-09-02 16:46:11 -04:00
parent 8bb01a2412
commit a478428721
16 changed files with 680 additions and 4 deletions

View File

@@ -16,6 +16,7 @@ import org.bukkit.event.Listener;
import org.bukkit.event.block.BlockBreakEvent;
import org.bukkit.event.block.BlockDropItemEvent;
import org.bukkit.event.block.BlockPlaceEvent;
import org.bukkit.event.entity.EntitySpawnEvent;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.player.PlayerQuitEvent;
import org.bukkit.event.player.PlayerTeleportEvent;
@@ -205,6 +206,14 @@ public abstract class ContextualChunkGenerator extends ChunkGenerator implements
onTick(ticks++);
}
@EventHandler(priority = EventPriority.MONITOR)
public void on(EntitySpawnEvent e)
{
onSpawn(e);
}
protected abstract void onSpawn(EntitySpawnEvent e);
@EventHandler(priority = EventPriority.MONITOR)
public void on(BlockBreakEvent e)
{

View File

@@ -12,6 +12,7 @@ import org.bukkit.World;
import org.bukkit.block.data.BlockData;
import org.bukkit.entity.Player;
import org.bukkit.event.block.BlockDropItemEvent;
import org.bukkit.event.entity.EntitySpawnEvent;
import org.bukkit.inventory.ItemStack;
import com.volmit.iris.Iris;
@@ -24,8 +25,10 @@ import com.volmit.iris.object.IrisBiome;
import com.volmit.iris.object.IrisBlockDrops;
import com.volmit.iris.object.IrisDimension;
import com.volmit.iris.object.IrisEffect;
import com.volmit.iris.object.IrisEntitySpawn;
import com.volmit.iris.object.IrisRegion;
import com.volmit.iris.util.Form;
import com.volmit.iris.util.IrisStructureResult;
import com.volmit.iris.util.KList;
import com.volmit.iris.util.KMap;
import com.volmit.iris.util.PrecisionStopwatch;
@@ -42,6 +45,7 @@ public class IrisChunkGenerator extends PostBlockChunkGenerator implements IrisC
private IrisBiome hb = null;
private IrisRegion hr = null;
private KMap<Player, IrisBiome> b = new KMap<>();
private boolean spawnable = false;
public IrisChunkGenerator(String dimensionName, int threads)
{
@@ -122,6 +126,7 @@ public class IrisChunkGenerator extends PostBlockChunkGenerator implements IrisC
@Override
public void onTick(int ticks)
{
spawnable = true;
super.onTick(ticks);
for(Player i : getWorld().getPlayers())
{
@@ -429,4 +434,87 @@ public class IrisChunkGenerator extends PostBlockChunkGenerator implements IrisC
}
}
}
@Override
protected void onSpawn(EntitySpawnEvent e)
{
if(spawnable)
{
int x = e.getEntity().getLocation().getBlockX();
int y = e.getEntity().getLocation().getBlockY();
int z = e.getEntity().getLocation().getBlockZ();
IrisDimension dim = getDimension();
IrisRegion region = sampleRegion(x, z);
IrisBiome above = sampleTrueBiome(x, z);
IrisBiome below = sampleTrueBiome(x, y, z);
if(above.getLoadKey().equals(below.getLoadKey()))
{
below = null;
}
IrisStructureResult res = getStructure(x, y, z);
if(res != null && res.getTile() != null)
{
if(trySpawn(res.getTile().getEntitySpawns(), e))
{
return;
}
}
if(res != null && res.getStructure() != null)
{
if(trySpawn(res.getStructure().getEntitySpawns(), e))
{
return;
}
}
if(below != null)
{
if(trySpawn(below.getEntitySpawns(), e))
{
return;
}
}
if(trySpawn(above.getEntitySpawns(), e))
{
return;
}
if(trySpawn(region.getEntitySpawns(), e))
{
return;
}
if(trySpawn(dim.getEntitySpawns(), e))
{
return;
}
}
}
private boolean trySpawn(KList<IrisEntitySpawn> s, EntitySpawnEvent e)
{
for(IrisEntitySpawn i : s)
{
spawnable = false;
if(i.on(this, e.getLocation(), e.getEntityType(), e) != null)
{
e.setCancelled(true);
e.getEntity().remove();
return true;
}
else
{
spawnable = true;
}
}
return false;
}
}

View File

@@ -184,7 +184,7 @@ public class GenLayerUpdate extends BlockPopulator
}
}
private void scramble(Inventory inventory, RNG rng)
public void scramble(Inventory inventory, RNG rng)
{
KList<ItemStack> v = new KList<>();