Marker destruction

This commit is contained in:
cyberpwn 2021-09-13 16:33:24 -04:00
parent 93bcb8994f
commit 0b1d59e398
6 changed files with 40 additions and 1 deletions

View File

@ -398,6 +398,7 @@ public class IrisWorldManager extends EngineAssignedWorldManager {
private Stream<IrisEntitySpawn> stream(IrisSpawner s, boolean initial) {
for (IrisEntitySpawn i : initial ? s.getInitialSpawns() : s.getSpawns()) {
i.setReferenceSpawner(s);
i.setReferenceMarker(s.getReferenceMarker());
}
return (initial ? s.getInitialSpawns() : s.getSpawns()).stream();
@ -471,6 +472,7 @@ public class IrisWorldManager extends EngineAssignedWorldManager {
IrisEntitySpawn ss = spawnRandomly(s).getRandom();
ss.setReferenceSpawner(spawner);
ss.setReferenceMarker(spawner.getReferenceMarker());
spawn(block, ss);
}
@ -496,6 +498,7 @@ public class IrisWorldManager extends EngineAssignedWorldManager {
IrisPosition pos = new IrisPosition((c.getX() << 4) + x, y, (c.getZ() << 4) + z);
for (String i : mark.getSpawners()) {
IrisSpawner m = getData().getSpawnerLoader().load(i);
m.setReferenceMarker(mark);
if (m != null) {
p.computeIfAbsent(pos, (k) -> new KSet<>()).add(m);

View File

@ -243,6 +243,11 @@ public class PlannedPiece {
@Override
public Engine getEngine() {
if(IrisToolbelt.isIrisWorld(world))
{
return IrisToolbelt.access(world).getEngine();
}
return IrisContext.get().getEngine();
}
}, piece.getPlacementOptions(), rng, getData());

View File

@ -28,6 +28,7 @@ import com.volmit.iris.engine.object.annotations.Required;
import com.volmit.iris.engine.object.annotations.Snippet;
import com.volmit.iris.util.format.C;
import com.volmit.iris.util.math.RNG;
import com.volmit.iris.util.matter.MatterMarker;
import com.volmit.iris.util.matter.slices.MarkerMatter;
import lombok.AllArgsConstructor;
import lombok.Data;
@ -63,6 +64,7 @@ public class IrisEntitySpawn implements IRare {
@Desc("The max of this entity to spawn")
private int maxSpawns = 1;
private transient IrisSpawner referenceSpawner;
private transient IrisMarker referenceMarker;
public int spawn(Engine gen, Chunk c, RNG rng) {
int spawns = minSpawns == maxSpawns ? minSpawns : rng.i(Math.min(minSpawns, maxSpawns), Math.max(minSpawns, maxSpawns));
@ -110,6 +112,12 @@ public class IrisEntitySpawn implements IRare {
World world = gen.getWorld().realWorld();
if (spawns > 0) {
if(referenceMarker != null)
{
gen.getMantle().getMantle().remove(c.getX(), c.getY(), c.getZ(), MatterMarker.class);
}
for (int id = 0; id < spawns; id++) {
Location l = c.toLocation(world).add(0, 1, 0);

View File

@ -24,6 +24,7 @@ import com.volmit.iris.engine.object.annotations.Desc;
import com.volmit.iris.engine.object.annotations.RegistryListResource;
import com.volmit.iris.util.collection.KList;
import com.volmit.iris.util.json.JSONObject;
import com.volmit.iris.util.math.RNG;
import com.volmit.iris.util.plugin.VolmitSender;
import lombok.AllArgsConstructor;
import lombok.Data;
@ -46,6 +47,14 @@ public class IrisMarker extends IrisRegistrant {
@Desc("Remove this marker when the block it's assigned to is changed.")
private boolean removeOnChange = true;
@Desc("If this marker is used, what is the chance it removes itself. For example 25% (0.25) would mean that on average 4 uses will remove a specific marker. Set this below 0 (-1) to never exhaust & set this to 1 or higher to always exhaust on first use.")
private double exhaustionChance = 0.33;
public boolean shouldExhaust()
{
return RNG.r.chance(exhaustionChance);
}
@Override
public String getFolderName() {
return "markers";

View File

@ -504,7 +504,7 @@ public class IrisObject extends IrisRegistrant {
}
public int place(int x, int yv, int z, IObjectPlacer oplacer, IrisObjectPlacement config, RNG rng, Consumer<BlockPosition> listener, CarveResult c, IrisData rdata) {
IObjectPlacer placer = (config.getHeightmap() != null) ? new HeightmapObjectPlacer(IrisContext.get().getEngine(), rng, x, yv, z, config, oplacer) : oplacer;
IObjectPlacer placer = (config.getHeightmap() != null) ? new HeightmapObjectPlacer(oplacer.getEngine() == null ? IrisContext.get().getEngine() : oplacer.getEngine(), rng, x, yv, z, config, oplacer) : oplacer;
if (config.isSmartBore()) {
ensureSmartBored(placer.isDebugSmartBore());
@ -667,9 +667,19 @@ public class IrisObject extends IrisRegistrant {
for(BlockVector i : getBlocks().k().shuffle())
{
if(max <= 0)
{
break;
}
BlockData data = getBlocks().get(i);
for (BlockData k : j.getMark(rdata)) {
if(max <= 0)
{
break;
}
if (j.isExact() ? k.matches(data) : k.getMaterial().equals(data.getMaterial())) {
boolean a = !blocks.containsKey(new BlockVector(i.clone().add(new BlockVector(0, 1, 0))));
boolean fff = !blocks.containsKey(new BlockVector(i.clone().add(new BlockVector(0, 2, 0))));
@ -677,6 +687,7 @@ public class IrisObject extends IrisRegistrant {
if((j.isEmptyAbove() && a && fff) || !j.isEmptyAbove())
{
markers.put(i, j.getMarker());
max--;
}
}
}

View File

@ -38,6 +38,9 @@ import org.bukkit.World;
@Desc("Represents an entity spawn during initial chunk generation")
@Data
public class IrisSpawner extends IrisRegistrant {
private transient IrisMarker referenceMarker;
@ArrayType(min = 1, type = IrisEntitySpawn.class)
@Desc("The entity spawns to add")
private KList<IrisEntitySpawn> spawns = new KList<>();