This commit is contained in:
cyberpwn 2021-08-26 06:12:32 -04:00
parent 3b61b87501
commit 44d75d9955
17 changed files with 117 additions and 182 deletions

View File

@ -24,14 +24,11 @@ import com.volmit.iris.engine.framework.Engine;
import com.volmit.iris.engine.platform.PlatformChunkGenerator;
import com.volmit.iris.util.collection.KList;
import com.volmit.iris.util.format.Form;
import com.volmit.iris.util.math.RNG;
import com.volmit.iris.util.parallel.BurstExecutor;
import com.volmit.iris.util.parallel.MultiBurst;
import com.volmit.iris.util.plugin.MortarCommand;
import com.volmit.iris.util.plugin.VolmitSender;
import com.volmit.iris.util.scheduling.J;
import com.volmit.iris.util.scheduling.jobs.Job;
import com.volmit.iris.util.scheduling.jobs.JobCollection;
import com.volmit.iris.util.scheduling.jobs.QueueJob;
import org.bukkit.Chunk;
@ -53,18 +50,15 @@ public class CommandIrisRegen extends MortarCommand {
@Override
public boolean handle(VolmitSender sender, String[] args) {
if (!sender.isPlayer())
{
if (!sender.isPlayer()) {
sender.sendMessage("Must be in an iris world.");
}
if(IrisToolbelt.isIrisWorld(sender.player().getWorld()))
{
if (IrisToolbelt.isIrisWorld(sender.player().getWorld())) {
J.a(() -> {
PlatformChunkGenerator plat = IrisToolbelt.access(sender.player().getWorld());
Engine engine = plat.getEngine();
try
{
try {
int vd = Integer.parseInt(args[0]);
int rg = 0;
Chunk cx = sender.player().getLocation().getChunk();
@ -72,21 +66,18 @@ public class CommandIrisRegen extends MortarCommand {
BurstExecutor b = MultiBurst.burst.burst();
b.setMulticore(false);
int rad = engine.getMantle().getRealRadius();
for(int i = -(vd+rad); i <= vd+rad; i++) {
for (int j = -(vd+rad); j <= vd+rad; j++) {
for (int i = -(vd + rad); i <= vd + rad; i++) {
for (int j = -(vd + rad); j <= vd + rad; j++) {
engine.getMantle().getMantle().deleteChunk(i + cx.getX(), j + cx.getZ());
}
}
for(int i = -vd; i <= vd; i++)
{
for(int j = -vd; j <= vd; j++)
{
for (int i = -vd; i <= vd; i++) {
for (int j = -vd; j <= vd; j++) {
int finalJ = j;
int finalI = i;
b.queue(() -> plat.injectChunkReplacement(sender.player().getWorld(), finalI + cx.getX(), finalJ + cx.getZ(), (f) -> {
synchronized (js)
{
synchronized (js) {
js.add(f);
}
}));
@ -102,10 +93,8 @@ public class CommandIrisRegen extends MortarCommand {
public void execute(Runnable runnable) {
futures.add(J.sfut(runnable));
if(futures.size() > 64)
{
while(futures.isNotEmpty())
{
if (futures.size() > 64) {
while (futures.isNotEmpty()) {
try {
futures.remove(0).get();
} catch (InterruptedException e) {
@ -124,10 +113,7 @@ public class CommandIrisRegen extends MortarCommand {
};
r.queue(js);
r.execute(sender);
}
catch(Throwable e)
{
} catch (Throwable e) {
sender.sendMessage("Unable to parse view-distance");
}
});

View File

@ -58,7 +58,17 @@ import java.util.function.BiFunction;
public class VisionGUI extends JPanel implements MouseWheelListener, KeyListener, MouseMotionListener, MouseInputListener {
private static final long serialVersionUID = 2094606939770332040L;
private final KList<LivingEntity> lastEntities = new KList<>();
private final KMap<String, Long> notifications = new KMap<>();
private final ChronoLatch centities = new ChronoLatch(1000);
private final RollingSequence rs = new RollingSequence(512);
private final O<Integer> m = new O<>();
private final KMap<BlockPosition, BufferedImage> positions = new KMap<>();
private final KMap<BlockPosition, BufferedImage> fastpositions = new KMap<>();
private final KSet<BlockPosition> working = new KSet<>();
private final KSet<BlockPosition> workingfast = new KSet<>();
double tfps = 240D;
int ltc = 3;
private RenderType currentType = RenderType.BIOME;
private boolean help = true;
private boolean helpIgnored = false;
@ -82,7 +92,6 @@ public class VisionGUI extends JPanel implements MouseWheelListener, KeyListener
private int h = 0;
private double lx = 0;
private double lz = 0;
private final KList<LivingEntity> lastEntities = new KList<>();
private double ox = 0;
private double oz = 0;
private double hx = 0;
@ -90,17 +99,7 @@ public class VisionGUI extends JPanel implements MouseWheelListener, KeyListener
private double oxp = 0;
private double ozp = 0;
private Engine engine;
private final KMap<String, Long> notifications = new KMap<>();
double tfps = 240D;
int ltc = 3;
private final ChronoLatch centities = new ChronoLatch(1000);
private final RollingSequence rs = new RollingSequence(512);
private final O<Integer> m = new O<>();
private int tid = 0;
private final KMap<BlockPosition, BufferedImage> positions = new KMap<>();
private final KMap<BlockPosition, BufferedImage> fastpositions = new KMap<>();
private final KSet<BlockPosition> working = new KSet<>();
private final KSet<BlockPosition> workingfast = new KSet<>();
private final ExecutorService e = Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors(), r -> {
tid++;
Thread t = new Thread(r);
@ -153,6 +152,33 @@ public class VisionGUI extends JPanel implements MouseWheelListener, KeyListener
});
}
private static void createAndShowGUI(Engine r, int s, IrisWorld world) {
JFrame frame = new JFrame("Vision");
VisionGUI nv = new VisionGUI(frame);
nv.world = world;
nv.engine = r;
nv.renderer = new IrisRenderer(r);
frame.add(nv);
frame.setSize(1440, 820);
frame.setVisible(true);
File file = Iris.getCached("Iris Icon", "https://raw.githubusercontent.com/VolmitSoftware/Iris/master/icon.png");
if (file != null) {
try {
nv.texture = ImageIO.read(file);
frame.setIconImage(ImageIO.read(file));
} catch (IOException e) {
Iris.reportError(e);
}
}
}
public static void launch(Engine g, int i) {
J.a(() ->
createAndShowGUI(g, i, g.getWorld()));
}
public boolean updateEngine() {
if (engine.isClosed()) {
if (world.hasRealWorld()) {
@ -755,33 +781,6 @@ public class VisionGUI extends JPanel implements MouseWheelListener, KeyListener
}
}
private static void createAndShowGUI(Engine r, int s, IrisWorld world) {
JFrame frame = new JFrame("Vision");
VisionGUI nv = new VisionGUI(frame);
nv.world = world;
nv.engine = r;
nv.renderer = new IrisRenderer(r);
frame.add(nv);
frame.setSize(1440, 820);
frame.setVisible(true);
File file = Iris.getCached("Iris Icon", "https://raw.githubusercontent.com/VolmitSoftware/Iris/master/icon.png");
if (file != null) {
try {
nv.texture = ImageIO.read(file);
frame.setIconImage(ImageIO.read(file));
} catch (IOException e) {
Iris.reportError(e);
}
}
}
public static void launch(Engine g, int i) {
J.a(() ->
createAndShowGUI(g, i, g.getWorld()));
}
public void mouseWheelMoved(MouseWheelEvent e) {
int notches = e.getWheelRotation();
if (e.isControlDown()) {

View File

@ -49,8 +49,7 @@ public class AsyncPregenMethod implements PregeneratorMethod {
private void unloadAndSaveAllChunks() {
try {
J.sfut(() -> {
if(world == null)
{
if (world == null) {
Iris.warn("World was null somehow...");
return;
}

View File

@ -223,8 +223,7 @@ public class IrisWorldManager extends EngineAssignedWorldManager {
}
private void spawnIn(Chunk c, boolean initial) {
if(initial)
{
if (initial) {
energy += 1.2;
}
@ -370,13 +369,12 @@ public class IrisWorldManager extends EngineAssignedWorldManager {
@Override
public void onChunkLoad(Chunk e, boolean generated) {
J.a(() -> getMantle().raiseFlag(e.getX(), e.getZ(), MantleFlag.INITIAL_SPAWNED,
() -> J.a(() -> spawnIn(e, true), RNG.r.i(5, 200))));
() -> J.a(() -> spawnIn(e, true), RNG.r.i(5, 200))));
energy += 0.3;
fixEnergy();
}
public Mantle getMantle()
{
public Mantle getMantle() {
return getEngine().getMantle().getMantle();
}
@ -392,36 +390,14 @@ public class IrisWorldManager extends EngineAssignedWorldManager {
Runnable drop = () -> J.s(() -> d.forEach((i) -> e.getBlock().getWorld().dropItemNaturally(e.getBlock().getLocation().clone().add(0.5, 0.5, 0.5), i)));
IrisBiome b = getEngine().getBiome(e.getBlock().getLocation());
for (IrisBlockDrops i : b.getBlockDrops()) {
if (i.shouldDropFor(e.getBlock().getBlockData(), getData())) {
if (i.isReplaceVanillaDrops()) {
e.setDropItems(false);
}
i.fillDrops(false, d);
if (i.isSkipParents()) {
drop.run();
return;
}
}
if (dropItems(e, d, drop, b.getBlockDrops(), b)) {
return;
}
IrisRegion r = getEngine().getRegion(e.getBlock().getLocation());
for (IrisBlockDrops i : r.getBlockDrops()) {
if (i.shouldDropFor(e.getBlock().getBlockData(), getData())) {
if (i.isReplaceVanillaDrops()) {
e.setDropItems(false);
}
i.fillDrops(false, d);
if (i.isSkipParents()) {
drop.run();
return;
}
}
if (dropItems(e, d, drop, r.getBlockDrops(), b)) {
return;
}
for (IrisBlockDrops i : getEngine().getDimension().getBlockDrops()) {
@ -441,6 +417,24 @@ public class IrisWorldManager extends EngineAssignedWorldManager {
}
}
private boolean dropItems(BlockBreakEvent e, KList<ItemStack> d, Runnable drop, KList<IrisBlockDrops> blockDrops, IrisBiome b) {
for (IrisBlockDrops i : blockDrops) {
if (i.shouldDropFor(e.getBlock().getBlockData(), getData())) {
if (i.isReplaceVanillaDrops()) {
e.setDropItems(false);
}
i.fillDrops(false, d);
if (i.isSkipParents()) {
drop.run();
return true;
}
}
}
return false;
}
@Override
public void onBlockPlace(BlockPlaceEvent e) {

View File

@ -56,9 +56,9 @@ public class LinkedTerrainChunk implements TerrainChunk {
@Override
public BiomeBaseInjector getBiomeBaseInjector() {
if(unsafe)
{
return (a,b,c,d) -> {};
if (unsafe) {
return (a, b, c, d) -> {
};
}
return (x, y, z, bb) -> INMS.get().forceBiomeInto(x, y, z, bb, storage);

View File

@ -147,8 +147,7 @@ public interface Engine extends DataProvider, Fallible, LootProvider, BlockUpdat
double modifyZ(double z);
@BlockCoordinates
default void generate(int x, int z, TerrainChunk tc, boolean multicore) throws WrongEngineBroException
{
default void generate(int x, int z, TerrainChunk tc, boolean multicore) throws WrongEngineBroException {
generate(x, z, Hunk.view((ChunkGenerator.ChunkData) tc), Hunk.view((ChunkGenerator.BiomeGrid) tc), multicore);
}

View File

@ -34,7 +34,6 @@ import com.volmit.iris.util.documentation.ChunkCoordinates;
import com.volmit.iris.util.hunk.Hunk;
import com.volmit.iris.util.mantle.Mantle;
import com.volmit.iris.util.mantle.MantleChunk;
import com.volmit.iris.util.mantle.MantleFlag;
import com.volmit.iris.util.parallel.BurstExecutor;
import com.volmit.iris.util.parallel.MultiBurst;
import org.bukkit.Chunk;
@ -193,8 +192,7 @@ public interface EngineMantle extends IObjectPlacer {
burst.queue(() -> {
MantleChunk mc = getMantle().getChunk(xx, zz);
for(MantleComponent k : getComponents())
{
for (MantleComponent k : getComponents()) {
generateMantleComponent(writer, xx, zz, k, c, mc);
}
});
@ -282,13 +280,11 @@ public interface EngineMantle extends IObjectPlacer {
return pos;
}
default boolean queueRegenerate(int x, int z)
{
return false; // TODO:
default boolean queueRegenerate(int x, int z) {
return false; // TODO:
}
default boolean dequeueRegenerate(int x, int z)
{
default boolean dequeueRegenerate(int x, int z) {
return false;// TODO:
}
}

View File

@ -40,13 +40,11 @@ public enum StudioMode {
private final Consumer<BukkitChunkGenerator> injector;
StudioMode(Consumer<BukkitChunkGenerator> injector)
{
StudioMode(Consumer<BukkitChunkGenerator> injector) {
this.injector = injector;
}
public void inject(BukkitChunkGenerator c)
{
public void inject(BukkitChunkGenerator c) {
injector.accept(c);
}
}

View File

@ -20,7 +20,6 @@ package com.volmit.iris.engine.object.entity;
import com.volmit.iris.Iris;
import com.volmit.iris.core.project.loader.IrisRegistrant;
import com.volmit.iris.core.service.WandSVC;
import com.volmit.iris.engine.framework.Engine;
import com.volmit.iris.engine.object.annotations.*;
import com.volmit.iris.engine.object.common.IrisScript;
@ -46,10 +45,8 @@ import lombok.NoArgsConstructor;
import lombok.experimental.Accessors;
import org.bukkit.*;
import org.bukkit.attribute.Attributable;
import org.bukkit.block.data.BlockData;
import org.bukkit.entity.*;
import org.bukkit.entity.Panda.Gene;
import org.bukkit.event.player.PlayerTeleportEvent;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
import org.bukkit.loot.LootContext;
@ -176,7 +173,7 @@ public class IrisEntity extends IrisRegistrant {
}
public Entity spawn(Engine gen, Location at, RNG rng) {
if(isSpawnEffectRiseOutOfGround()) {
if (isSpawnEffectRiseOutOfGround()) {
Location b = at.clone();
double sy = b.getY() - 5;
Location start = new Location(b.getWorld(), b.getX(), sy, b.getZ());
@ -334,8 +331,7 @@ public class IrisEntity extends IrisRegistrant {
}
}
if(isSpawnEffectRiseOutOfGround() && e instanceof LivingEntity)
{
if (isSpawnEffectRiseOutOfGround() && e instanceof LivingEntity) {
Location start = at.clone();
e.setInvulnerable(true);
((LivingEntity) e).setAI(false);
@ -344,19 +340,14 @@ public class IrisEntity extends IrisRegistrant {
AtomicInteger v = new AtomicInteger(0);
v.set(J.sr(() -> {
if(e.getLocation().getBlock().getType().isSolid() || ((LivingEntity) e).getEyeLocation().getBlock().getType().isSolid())
{
if (e.getLocation().getBlock().getType().isSolid() || ((LivingEntity) e).getEyeLocation().getBlock().getType().isSolid()) {
e.teleport(start.add(new Vector(0, 0.1, 0)));
ItemStack itemCrackData = new ItemStack(((LivingEntity) e).getEyeLocation().clone().subtract(0, 2, 0).getBlock().getBlockData().getMaterial());
e.getWorld().spawnParticle(Particle.ITEM_CRACK, ((LivingEntity) e).getEyeLocation(), 6, 0.2, 0.4, 0.2, 0.06f, itemCrackData);
if(M.r(0.2))
{
if (M.r(0.2)) {
e.getWorld().playSound(e.getLocation(), Sound.BLOCK_CHORUS_FLOWER_GROW, 0.8f, 0.1f);
}
}
else
{
} else {
J.csr(v.get());
((LivingEntity) e).setNoDamageTicks(0);
((LivingEntity) e).setCollidable(true);
@ -369,17 +360,14 @@ public class IrisEntity extends IrisRegistrant {
return e;
}
private int surfaceY(Location l)
{
private int surfaceY(Location l) {
int m = l.getBlockY();
while(m-- > 0)
{
while (m-- > 0) {
Location ll = l.clone();
ll.setY(m);
if(ll.getBlock().getType().isSolid())
{
if (ll.getBlock().getType().isSolid()) {
return m;
}
}

View File

@ -34,7 +34,6 @@ import com.volmit.iris.util.collection.KList;
import com.volmit.iris.util.data.IrisBiomeStorage;
import com.volmit.iris.util.hunk.Hunk;
import com.volmit.iris.util.io.ReactiveFolder;
import com.volmit.iris.util.math.RNG;
import com.volmit.iris.util.scheduling.ChronoLatch;
import com.volmit.iris.util.scheduling.J;
import com.volmit.iris.util.scheduling.Looper;
@ -168,18 +167,14 @@ public class BukkitChunkGenerator extends ChunkGenerator implements PlatformChun
getEngine().generate(x << 4, z << 4, blocks, biomes, true);
Iris.debug("Regenerated " + x + " " + z);
int t = 0;
for(int i = getEngine().getHeight() >> 4; i >= 0; i--)
{
if(!world.isChunkLoaded(x, z))
{
for (int i = getEngine().getHeight() >> 4; i >= 0; i--) {
if (!world.isChunkLoaded(x, z)) {
continue;
}
Chunk c = world.getChunkAt(x, z);
for(Entity ee : c.getEntities())
{
if(ee instanceof Player)
{
for (Entity ee : c.getEntities()) {
if (ee instanceof Player) {
continue;
}
@ -191,18 +186,14 @@ public class BukkitChunkGenerator extends ChunkGenerator implements PlatformChun
int finalI = i;
jobs.accept(() -> {
for(int xx = 0; xx < 16; xx++)
{
for(int yy = 0; yy < 16; yy++)
{
for(int zz = 0; zz < 16; zz++)
{
if(yy + (finalI << 4) >= engine.getHeight() || yy + (finalI << 4) < 0)
{
for (int xx = 0; xx < 16; xx++) {
for (int yy = 0; yy < 16; yy++) {
for (int zz = 0; zz < 16; zz++) {
if (yy + (finalI << 4) >= engine.getHeight() || yy + (finalI << 4) < 0) {
continue;
}
c.getBlock(xx,yy + (finalI << 4),zz).setBlockData(tc.getBlockData(xx,yy + (finalI << 4),zz), false);
c.getBlock(xx, yy + (finalI << 4), zz).setBlockData(tc.getBlockData(xx, yy + (finalI << 4), zz), false);
}
}
}
@ -284,13 +275,9 @@ public class BukkitChunkGenerator extends ChunkGenerator implements PlatformChun
TerrainChunk tc = TerrainChunk.create(world, biome);
this.world.bind(world);
if(studioGenerator != null)
{
if (studioGenerator != null) {
studioGenerator.generateChunk(getEngine(), tc, x, z);
}
else
{
} else {
Hunk<BlockData> blocks = Hunk.view((ChunkData) tc);
Hunk<Biome> biomes = Hunk.view((BiomeGrid) tc);
getEngine().generate(x << 4, z << 4, blocks, biomes, true);
@ -333,8 +320,7 @@ public class BukkitChunkGenerator extends ChunkGenerator implements PlatformChun
}
private void computeStudioGenerator() {
if(!getEngine().getDimension().getStudioMode().equals(lastMode))
{
if (!getEngine().getDimension().getStudioMode().equals(lastMode)) {
lastMode = getEngine().getDimension().getStudioMode();
getEngine().getDimension().getStudioMode().inject(this);
}

View File

@ -24,7 +24,7 @@ import com.volmit.iris.engine.framework.WrongEngineBroException;
import lombok.RequiredArgsConstructor;
@RequiredArgsConstructor
public abstract class EnginedStudioGenerator implements StudioGenerator{
public abstract class EnginedStudioGenerator implements StudioGenerator {
private final Engine engine;
@Override

View File

@ -44,24 +44,20 @@ public class BiomeBuffetGenerator extends EnginedStudioGenerator {
@Override
public void generateChunk(Engine engine, TerrainChunk tc, int x, int z) throws WrongEngineBroException {
int id = Cache.to1D(x/biomeSize, 0, z/biomeSize, width, 1);
int id = Cache.to1D(x / biomeSize, 0, z / biomeSize, width, 1);
if(id >= 0 && id < biomes.length)
{
if (id >= 0 && id < biomes.length) {
IrisBiome biome = biomes[id];
String foc = engine.getDimension().getFocus();
if(!Objects.equals(foc, biome.getLoadKey()))
{
if (!Objects.equals(foc, biome.getLoadKey())) {
engine.getDimension().setFocus(biome.getLoadKey());
engine.hotloadComplex();
}
engine.generate(x << 4, z << 4, tc, true);
}
else {
tc.setRegion(0,0,0,16, 1, 16, FLOOR);
} else {
tc.setRegion(0, 0, 0, 16, 1, 16, FLOOR);
}
}
}

View File

@ -23,7 +23,7 @@ import org.bukkit.block.Biome;
import org.bukkit.generator.ChunkGenerator.BiomeGrid;
import org.jetbrains.annotations.NotNull;
public class IrisBiomeStorage implements BiomeGrid{
public class IrisBiomeStorage implements BiomeGrid {
private static final int e;
private static final int f;
public static final int a;

View File

@ -432,8 +432,7 @@ public class Mantle {
try {
region = TectonicPlate.read(worldHeight, file);
if(region.getX() != x || region.getZ() != z)
{
if (region.getX() != x || region.getZ() != z) {
Iris.warn("Loaded Tectonic Plate " + x + "," + z + " but read it as " + region.getX() + "," + region.getZ() + "... Assuming " + x + "," + z);
}

View File

@ -140,7 +140,7 @@ public class TectonicPlate {
MantleChunk chunk = get(x, z);
if (chunk == null) {
chunk = new MantleChunk(sectionHeight, x&31, z&31);
chunk = new MantleChunk(sectionHeight, x & 31, z & 31);
chunks.set(index(x, z), chunk);
}

View File

@ -42,8 +42,7 @@ public class BurstExecutor {
@SuppressWarnings("UnusedReturnValue")
public Future<?> queue(Runnable r) {
if(!multicore)
{
if (!multicore) {
r.run();
return CompletableFuture.completedFuture(null);
}

View File

@ -256,13 +256,9 @@ public class J {
* @param delay the delay to wait in ticks before running
*/
public static void s(Runnable r, int delay) {
try
{
try {
Bukkit.getScheduler().scheduleSyncDelayedTask(Iris.instance, r, delay);
}
catch(Throwable e)
{
} catch (Throwable e) {
Iris.reportError(e);
}
}