mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2025-12-30 20:39:21 +00:00
Goto Object
This commit is contained in:
@@ -49,7 +49,7 @@ public class IrisWorlds
|
||||
{
|
||||
for(Player j : world.getPlayers())
|
||||
{
|
||||
new MortarSender(j, Iris.instance.getTag()).sendMessage("You have been evacuated from this world due to a close request.");
|
||||
new MortarSender(j, Iris.instance.getTag()).sendMessage("You have been evacuated from this world.");
|
||||
j.teleport(i.getSpawnLocation());
|
||||
}
|
||||
|
||||
|
||||
@@ -134,6 +134,19 @@ public interface EngineParallaxManager extends DataProvider, IObjectPlacer
|
||||
generateStructures(rng, x>>4, z>>4, region, biome);
|
||||
}
|
||||
|
||||
default KList<PlacedObject> generateParallaxLayerObjects(int x, int z)
|
||||
{
|
||||
KList<PlacedObject> placedObjects = new KList<>();
|
||||
RNG rng = new RNG(Cache.key(x, z)).nextParallelRNG(getEngine().getTarget().getWorld().getSeed());
|
||||
IrisRegion region = getComplex().getRegionStream().get(x+8, z+8);
|
||||
IrisBiome biome = getComplex().getTrueBiomeStream().get(x+8, z+8);
|
||||
generateParallaxSurface(rng, x, z, biome, placedObjects);
|
||||
generateParallaxMutations(rng, x, z, placedObjects);
|
||||
generateStructures(rng, x>>4, z>>4, region, biome, placedObjects);
|
||||
|
||||
return placedObjects;
|
||||
}
|
||||
|
||||
default void generateStructures(RNG rng, int x, int z, IrisRegion region, IrisBiome biome)
|
||||
{
|
||||
int g = 30265;
|
||||
@@ -158,6 +171,30 @@ public interface EngineParallaxManager extends DataProvider, IObjectPlacer
|
||||
}
|
||||
}
|
||||
|
||||
default void generateStructures(RNG rng, int x, int z, IrisRegion region, IrisBiome biome, KList<PlacedObject> objects)
|
||||
{
|
||||
int g = 30265;
|
||||
for(IrisStructurePlacement k : region.getStructures())
|
||||
{
|
||||
if(k == null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
getStructureManager().placeStructure(k, rng.nextParallelRNG(2228 * 2 * g++), x, z, objects);
|
||||
}
|
||||
|
||||
for(IrisStructurePlacement k : biome.getStructures())
|
||||
{
|
||||
if(k == null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
getStructureManager().placeStructure(k, rng.nextParallelRNG(-22228 * 4 * g++), x, z, objects);
|
||||
}
|
||||
}
|
||||
|
||||
default void generateParallaxSurface(RNG rng, int x, int z, IrisBiome biome) {
|
||||
for (IrisObjectPlacement i : biome.getSurfaceObjects())
|
||||
{
|
||||
@@ -168,6 +205,16 @@ public interface EngineParallaxManager extends DataProvider, IObjectPlacer
|
||||
}
|
||||
}
|
||||
|
||||
default void generateParallaxSurface(RNG rng, int x, int z, IrisBiome biome, KList<PlacedObject> objects) {
|
||||
for (IrisObjectPlacement i : biome.getSurfaceObjects())
|
||||
{
|
||||
if(rng.chance(i.getChance()))
|
||||
{
|
||||
place(rng, x, z, i, objects);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
default void generateParallaxMutations(RNG rng, int x, int z) {
|
||||
if(getEngine().getDimension().getMutations().isEmpty())
|
||||
{
|
||||
@@ -199,11 +246,59 @@ public interface EngineParallaxManager extends DataProvider, IObjectPlacer
|
||||
}
|
||||
}
|
||||
|
||||
default void generateParallaxMutations(RNG rng, int x, int z, KList<PlacedObject> o) {
|
||||
if(getEngine().getDimension().getMutations().isEmpty())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
searching: for(IrisBiomeMutation k : getEngine().getDimension().getMutations())
|
||||
{
|
||||
for(int l = 0; l < k.getChecks(); l++)
|
||||
{
|
||||
IrisBiome sa = getComplex().getTrueBiomeStream().get(((x * 16) + rng.nextInt(16)) + rng.i(-k.getRadius(), k.getRadius()), ((z * 16) + rng.nextInt(16)) + rng.i(-k.getRadius(), k.getRadius()));
|
||||
IrisBiome sb = getComplex().getTrueBiomeStream().get(((x * 16) + rng.nextInt(16)) + rng.i(-k.getRadius(), k.getRadius()), ((z * 16) + rng.nextInt(16)) + rng.i(-k.getRadius(), k.getRadius()));
|
||||
|
||||
if(sa.getLoadKey().equals(sb.getLoadKey()))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if(k.getRealSideA(this).contains(sa.getLoadKey()) && k.getRealSideB(this).contains(sb.getLoadKey()))
|
||||
{
|
||||
for(IrisObjectPlacement m : k.getObjects())
|
||||
{
|
||||
place(rng.nextParallelRNG((34 * ((x * 30) + (z * 30)) * x * z) + x - z + 1569962), x, z, m, o);
|
||||
}
|
||||
|
||||
continue searching;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
default void place(RNG rng, int x, int z, IrisObjectPlacement objectPlacement)
|
||||
{
|
||||
place(rng, x,-1, z, objectPlacement);
|
||||
}
|
||||
|
||||
default void place(RNG rng, int x, int z, IrisObjectPlacement objectPlacement, KList<PlacedObject> objects)
|
||||
{
|
||||
place(rng, x,-1, z, objectPlacement, objects);
|
||||
}
|
||||
|
||||
default void place(RNG rng, int x, int forceY, int z, IrisObjectPlacement objectPlacement, KList<PlacedObject> objects)
|
||||
{
|
||||
for(int i = 0; i < objectPlacement.getDensity(); i++)
|
||||
{
|
||||
IrisObject v = objectPlacement.getSchematic(getComplex(), rng);
|
||||
int xx = rng.i(x, x+16);
|
||||
int zz = rng.i(z, z+16);
|
||||
int id = rng.i(0, Integer.MAX_VALUE);
|
||||
objects.add(new PlacedObject(objectPlacement, v, id, xx, zz));
|
||||
}
|
||||
}
|
||||
|
||||
default void place(RNG rng, int x, int forceY, int z, IrisObjectPlacement objectPlacement)
|
||||
{
|
||||
for(int i = 0; i < objectPlacement.getDensity(); i++)
|
||||
|
||||
@@ -4,10 +4,11 @@ import com.volmit.iris.object.IrisObject;
|
||||
import com.volmit.iris.object.IrisRareObject;
|
||||
import com.volmit.iris.object.IrisStructurePlacement;
|
||||
import com.volmit.iris.object.TileResult;
|
||||
import com.volmit.iris.scaffold.parallax.ParallaxChunkMeta;
|
||||
import com.volmit.iris.util.ChunkPosition;
|
||||
import com.volmit.iris.util.KList;
|
||||
import com.volmit.iris.util.KSet;
|
||||
import com.volmit.iris.util.RNG;
|
||||
import com.volmit.iris.scaffold.parallax.ParallaxChunkMeta;
|
||||
|
||||
public interface EngineStructureManager extends EngineComponent
|
||||
{
|
||||
@@ -56,6 +57,51 @@ public interface EngineStructureManager extends EngineComponent
|
||||
}
|
||||
}
|
||||
|
||||
default void placeStructure(IrisStructurePlacement structure, RNG rngno, int cx, int cz, KList<PlacedObject> objects)
|
||||
{
|
||||
RNG rng = new RNG(getEngine().getWorld().getSeed()).nextParallelRNG(-88738456 + rngno.nextInt());
|
||||
RNG rnp = rng.nextParallelRNG(cx - (cz * cz << 3) + rngno.nextInt());
|
||||
int s = structure.gridSize(getEngine()) - (structure.getStructure(getEngine()).isMergeEdges() ? 1 : 0);
|
||||
int sh = structure.gridHeight(getEngine()) - (structure.getStructure(getEngine()).isMergeEdges() ? 1 : 0);
|
||||
KSet<ChunkPosition> m = new KSet<>();
|
||||
|
||||
for(int i = cx << 4; i <= (cx << 4) + 15; i += 1)
|
||||
{
|
||||
if(Math.floorDiv(i, s) * s >> 4 < cx)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
for(int j = cz << 4; j <= (cz << 4) + 15; j += 1)
|
||||
{
|
||||
if(Math.floorDiv(j, s) * s >> 4 < cz)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
ChunkPosition p = new ChunkPosition(Math.floorDiv(i, s) * s, Math.floorDiv(j, s) * s);
|
||||
|
||||
if(m.contains(p))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
m.add(p);
|
||||
|
||||
if(structure.getStructure(getEngine()).getMaxLayers() <= 1)
|
||||
{
|
||||
placeLayer(structure, rng, rnp, i, 0, j, s, sh, objects);
|
||||
continue;
|
||||
}
|
||||
|
||||
for(int k = 0; k < s * structure.getStructure(getEngine()).getMaxLayers(); k += Math.max(sh, 1))
|
||||
{
|
||||
placeLayer(structure, rng, rnp, i, k, j, s, sh, objects);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
default void placeLayer(IrisStructurePlacement structure, RNG rng, RNG rnp, int i, int k, int j, int s, int sh)
|
||||
{
|
||||
if(!hasStructure(structure, rng, i, k, j))
|
||||
@@ -102,6 +148,35 @@ public interface EngineStructureManager extends EngineComponent
|
||||
}
|
||||
}
|
||||
|
||||
default void placeLayer(IrisStructurePlacement structure, RNG rng, RNG rnp, int i, int k, int j, int s, int sh, KList<PlacedObject> objects)
|
||||
{
|
||||
if(!hasStructure(structure, rng, i, k, j))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
int h = (structure.getHeight() == -1 ? 0 : structure.getHeight()) + (Math.floorDiv(k, sh) * sh);
|
||||
TileResult t = structure.getStructure(getEngine()).getTile(rng, Math.floorDiv(i, s) * s, h, Math.floorDiv(j, s) * s);
|
||||
|
||||
if(t != null)
|
||||
{
|
||||
IrisObject o = null;
|
||||
|
||||
for(IrisRareObject l : t.getTile().getRareObjects())
|
||||
{
|
||||
if(rnp.i(1, l.getRarity()) == 1)
|
||||
{
|
||||
o = structure.load(getEngine(), l.getObject());
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
o = o != null ? o : structure.load(getEngine(), t.getTile().getObjects().get(rnp.nextInt(t.getTile().getObjects().size())));
|
||||
int id = rng.i(0, Integer.MAX_VALUE);
|
||||
objects.add(new PlacedObject(null, o, id, Math.floorDiv(i, s) * s, Math.floorDiv(j, s) * s));
|
||||
}
|
||||
}
|
||||
|
||||
default boolean hasStructure(IrisStructurePlacement structure, RNG random, double x, double y, double z)
|
||||
{
|
||||
if(structure.getChanceGenerator(new RNG(getEngine().getWorld().getSeed())).getIndex(x / structure.getZoom(), y / structure.getZoom(), z / structure.getZoom(), structure.getRarity()) == structure.getRarity() / 2)
|
||||
|
||||
@@ -48,7 +48,7 @@ public interface GeneratorAccess extends DataProvider
|
||||
{
|
||||
if(i.getPlace().contains(object))
|
||||
{
|
||||
return new PlacedObject(i, getData().getObjectLoader().load(object), id);
|
||||
return new PlacedObject(i, getData().getObjectLoader().load(object), id, x, z);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -58,10 +58,10 @@ public interface GeneratorAccess extends DataProvider
|
||||
{
|
||||
if(i.getPlace().contains(object))
|
||||
{
|
||||
return new PlacedObject(i, getData().getObjectLoader().load(object), id);
|
||||
return new PlacedObject(i, getData().getObjectLoader().load(object), id, x, z);
|
||||
}
|
||||
}
|
||||
|
||||
return new PlacedObject(null, getData().getObjectLoader().load(object), id);
|
||||
return new PlacedObject(null, getData().getObjectLoader().load(object), id, x, z);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
package com.volmit.iris.scaffold.engine;
|
||||
|
||||
import com.volmit.iris.manager.IrisDataManager;
|
||||
import com.volmit.iris.object.IrisBiome;
|
||||
import com.volmit.iris.object.IrisRegion;
|
||||
import com.volmit.iris.object.*;
|
||||
import com.volmit.iris.scaffold.data.DataProvider;
|
||||
import com.volmit.iris.util.*;
|
||||
import org.bukkit.Location;
|
||||
@@ -48,6 +47,177 @@ public interface IrisAccess extends Hotloadable, DataProvider {
|
||||
|
||||
public boolean isStudio();
|
||||
|
||||
public default Location lookForObject(IrisObject object, long timeout, Consumer<Integer> triesc)
|
||||
{
|
||||
ChronoLatch cl = new ChronoLatch(250, false);
|
||||
long s = M.ms();
|
||||
int cpus = 2+(Runtime.getRuntime().availableProcessors()/2);
|
||||
KList<Engine> engines = new KList<>();
|
||||
String key = object.getLoadKey();
|
||||
|
||||
looking: for(int i = 0; i < getCompound().getSize(); i++)
|
||||
{
|
||||
Engine e = getCompound().getEngine(i);
|
||||
|
||||
for(IrisBiome j : e.getDimension().getAllBiomes(e))
|
||||
{
|
||||
for(IrisObjectPlacement k : j.getObjects())
|
||||
{
|
||||
if(k.getPlace().contains(key))
|
||||
{
|
||||
engines.add(e);
|
||||
continue looking;
|
||||
}
|
||||
}
|
||||
|
||||
for(IrisStructurePlacement k : j.getStructures())
|
||||
{
|
||||
for(IrisStructureTile l : k.getStructure(this).getTiles())
|
||||
{
|
||||
for(IrisRareObject m : l.getRareObjects())
|
||||
{
|
||||
if(m.getObject().equals(key))
|
||||
{
|
||||
engines.add(e);
|
||||
continue looking;
|
||||
}
|
||||
}
|
||||
|
||||
if(l.getObjects().contains(key))
|
||||
{
|
||||
engines.add(e);
|
||||
continue looking;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for(IrisRegion j : e.getDimension().getAllRegions(e))
|
||||
{
|
||||
for(IrisObjectPlacement k : j.getObjects())
|
||||
{
|
||||
if(k.getPlace().contains(key))
|
||||
{
|
||||
engines.add(e);
|
||||
continue looking;
|
||||
}
|
||||
}
|
||||
|
||||
for(IrisStructurePlacement k : j.getStructures())
|
||||
{
|
||||
for(IrisStructureTile l : k.getStructure(this).getTiles())
|
||||
{
|
||||
for(IrisRareObject m : l.getRareObjects())
|
||||
{
|
||||
if(m.getObject().equals(key))
|
||||
{
|
||||
engines.add(e);
|
||||
continue looking;
|
||||
}
|
||||
}
|
||||
|
||||
if(l.getObjects().contains(key))
|
||||
{
|
||||
engines.add(e);
|
||||
continue looking;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for(IrisBiomeMutation k : e.getDimension().getMutations())
|
||||
{
|
||||
for(IrisObjectPlacement l : k.getObjects())
|
||||
{
|
||||
if(l.getPlace().contains(key))
|
||||
{
|
||||
engines.add(e);
|
||||
continue looking;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(engines.isEmpty())
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
AtomicInteger tries = new AtomicInteger(0);
|
||||
AtomicBoolean found = new AtomicBoolean(false);
|
||||
AtomicReference<Location> location = new AtomicReference<>();
|
||||
|
||||
for(int i = 0; i < cpus; i++)
|
||||
{
|
||||
J.a(() -> {
|
||||
try
|
||||
{
|
||||
Engine e;
|
||||
IrisBiome b;
|
||||
int x,y,z;
|
||||
String sf;
|
||||
|
||||
while(!found.get())
|
||||
{
|
||||
try {
|
||||
synchronized (engines) {
|
||||
e = engines.getRandom();
|
||||
}
|
||||
|
||||
tries.getAndIncrement();
|
||||
x = RNG.r.i(-29999970, 29999970);
|
||||
y = RNG.r.i(0, e.getHeight()-1);
|
||||
z = RNG.r.i(-29999970, 29999970);
|
||||
KList<PlacedObject> p = e.getFramework().getEngineParallax().generateParallaxLayerObjects(Math.floorDiv(x, 16), Math.floorDiv(z, 16));
|
||||
|
||||
if(p == null || p.isEmpty())
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
for(PlacedObject j : p)
|
||||
{
|
||||
if(j.getObject().getLoadKey().equals(object.getLoadKey()))
|
||||
{
|
||||
found.lazySet(true);
|
||||
location.lazySet(new Location(e.getWorld(), j.getXx(), e.getMinHeight() + e.getHeight(j.getXx(), j.getZz()), j.getZz(), 0f, -90f));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
catch(Throwable ex)
|
||||
{
|
||||
ex.printStackTrace();
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
catch(Throwable e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
while(!found.get() || location.get() == null)
|
||||
{
|
||||
J.sleep(50);
|
||||
|
||||
if(cl.flip())
|
||||
{
|
||||
triesc.accept(tries.get());
|
||||
}
|
||||
|
||||
if(M.ms() - s > timeout)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
return location.get();
|
||||
}
|
||||
|
||||
public default Location lookForBiome(IrisBiome biome, long timeout, Consumer<Integer> triesc)
|
||||
{
|
||||
ChronoLatch cl = new ChronoLatch(250, false);
|
||||
@@ -150,6 +320,11 @@ public interface IrisAccess extends Hotloadable, DataProvider {
|
||||
}
|
||||
}
|
||||
|
||||
if(engines.isEmpty())
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
AtomicInteger tries = new AtomicInteger(0);
|
||||
AtomicBoolean found = new AtomicBoolean(false);
|
||||
AtomicReference<Location> location = new AtomicReference<>();
|
||||
@@ -169,7 +344,7 @@ public interface IrisAccess extends Hotloadable, DataProvider {
|
||||
z = RNG.r.i(-29999970, 29999970);
|
||||
b = e.getRegion(x, z);
|
||||
|
||||
if(b != null && b.getLoadKey().equals(reg.getLoadKey()))
|
||||
if(b != null && b.getLoadKey() != null && b.getLoadKey().equals(reg.getLoadKey()))
|
||||
{
|
||||
found.lazySet(true);
|
||||
location.lazySet(new Location(e.getWorld(), x, e.getHeight(x, z) + e.getMinHeight() ,z));
|
||||
|
||||
@@ -15,4 +15,6 @@ public class PlacedObject {
|
||||
@Nullable
|
||||
private IrisObject object;
|
||||
private int id;
|
||||
private int xx;
|
||||
private int zz;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user