mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2025-07-19 10:43:14 +00:00
ModXz in actuators
This commit is contained in:
parent
12e7c51c39
commit
3df741c4fc
@ -20,7 +20,7 @@ public class IrisBiomeActuator extends EngineAssignedActuator<Biome>
|
||||
{
|
||||
for(zf = 0; zf < h.getDepth(); zf++)
|
||||
{
|
||||
v = getComplex().getTrueBiomeDerivativeStream().get(xf+x, zf+z);
|
||||
v = getComplex().getTrueBiomeDerivativeStream().get(modX(xf+x), modZ(zf+z));
|
||||
|
||||
for(i = 0; i < h.getHeight(); i++)
|
||||
{
|
||||
|
@ -2,12 +2,18 @@ package com.volmit.iris.v2.generator.actuator;
|
||||
|
||||
import com.volmit.iris.util.B;
|
||||
import com.volmit.iris.util.KList;
|
||||
import com.volmit.iris.v2.generator.decorator.IrisCeilingDecorator;
|
||||
import com.volmit.iris.v2.generator.decorator.IrisSeaSurfaceDecorator;
|
||||
import com.volmit.iris.v2.generator.decorator.IrisShoreLineDecorator;
|
||||
import com.volmit.iris.v2.generator.decorator.IrisSurfaceDecorator;
|
||||
import com.volmit.iris.v2.scaffold.engine.Engine;
|
||||
import com.volmit.iris.v2.scaffold.engine.EngineAssignedActuator;
|
||||
import com.volmit.iris.v2.scaffold.engine.EngineDecorator;
|
||||
import com.volmit.iris.v2.scaffold.hunk.Hunk;
|
||||
import com.volmit.iris.object.IrisBiome;
|
||||
import com.volmit.iris.object.IrisDecorator;
|
||||
import com.volmit.iris.util.RNG;
|
||||
import lombok.Getter;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Biome;
|
||||
import org.bukkit.block.data.BlockData;
|
||||
@ -18,238 +24,98 @@ public class IrisDecorantActuator extends EngineAssignedActuator<BlockData>
|
||||
{
|
||||
private static final Predicate<BlockData> PREDICATE_SOLID = (b) -> b != null && !b.getMaterial().isAir() && !b.getMaterial().equals(Material.WATER) && !b.getMaterial().equals(Material.LAVA);
|
||||
private final RNG rng;
|
||||
@Getter
|
||||
private final EngineDecorator surfaceDecorator;
|
||||
@Getter
|
||||
private final EngineDecorator ceilingDecorator;
|
||||
@Getter
|
||||
private final EngineDecorator seaSurfaceDecorator;
|
||||
@Getter
|
||||
private final EngineDecorator shoreLineDecorator;
|
||||
private final boolean shouldRay;
|
||||
|
||||
public IrisDecorantActuator(Engine engine) {
|
||||
super(engine, "Decorant");
|
||||
shouldRay = shouldRayDecorate();
|
||||
this.rng = new RNG(engine.getTarget().getWorld().getSeed());
|
||||
surfaceDecorator = new IrisSurfaceDecorator(getEngine());
|
||||
ceilingDecorator = new IrisCeilingDecorator(getEngine());
|
||||
seaSurfaceDecorator = new IrisSeaSurfaceDecorator(getEngine());
|
||||
shoreLineDecorator = new IrisShoreLineDecorator(getEngine());
|
||||
}
|
||||
|
||||
private boolean shouldDecorate()
|
||||
{
|
||||
return getEngine().getDimension().isDecorate();
|
||||
@Override
|
||||
public void onActuate(int x, int z, Hunk<BlockData> output) {
|
||||
if(!getEngine().getDimension().isDecorate())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
boolean solid;
|
||||
int emptyFor = 0;
|
||||
int lastSolid = 0;
|
||||
int j, realX, realZ, height;
|
||||
IrisBiome biome, cave;
|
||||
|
||||
for(int i = 0; i < output.getWidth(); i++)
|
||||
{
|
||||
for(j = 0; j < output.getDepth(); j++)
|
||||
{
|
||||
realX = (int) Math.round(modX(x + i));
|
||||
realZ = (int) Math.round(modZ(z + j));
|
||||
height = (int) Math.round(getComplex().getHeightStream().get(realX, realZ));
|
||||
biome = getComplex().getTrueBiomeStream().get(realX, realZ);
|
||||
cave = shouldRay ? getComplex().getCaveBiomeStream().get(realX, realZ) : null;
|
||||
|
||||
if(biome.getDecorators().isEmpty() && (cave == null || cave.getDecorators().isEmpty()))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if(height == getDimension().getFluidHeight())
|
||||
{
|
||||
getShoreLineDecorator().decorate(i, j,
|
||||
realX, (int) Math.round(modX(x + i+1)), (int) Math.round(modX(x + i-1)),
|
||||
realZ, (int) Math.round(modZ(z + j+1)), (int) Math.round(modZ(z + j-1)),
|
||||
output, biome, height, getEngine().getHeight() - height);
|
||||
}
|
||||
|
||||
else if(height < getDimension().getFluidHeight())
|
||||
{
|
||||
getSeaSurfaceDecorator().decorate(i, j, realX, realZ, output, biome, getDimension().getFluidHeight(), getEngine().getHeight() - getDimension().getFluidHeight());
|
||||
}
|
||||
|
||||
getSurfaceDecorator().decorate(i, j, realX, realZ, output, biome, height, getEngine().getHeight() - height);
|
||||
|
||||
if(cave != null && cave.getDecorators().isNotEmpty())
|
||||
{
|
||||
for(int k = height; k > 0; k--)
|
||||
{
|
||||
solid = PREDICATE_SOLID.test(output.get(i, k, j));
|
||||
|
||||
if(solid)
|
||||
{
|
||||
lastSolid = k;
|
||||
}
|
||||
|
||||
else {
|
||||
emptyFor++;
|
||||
}
|
||||
|
||||
if(solid && emptyFor > 0)
|
||||
{
|
||||
getCeilingDecorator().decorate(i, j, realX, realZ, output, cave, lastSolid, emptyFor);
|
||||
getSurfaceDecorator().decorate(i, j, realX, realZ, output, cave, k, emptyFor);
|
||||
emptyFor = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private boolean shouldRayDecorate()
|
||||
{
|
||||
return getEngine().getDimension().isCarving() || getEngine().getDimension().isCaves() || getEngine().getDimension().isVanillaCaves() || getEngine().getDimension().isRavines();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onActuate(int x, int z, Hunk<BlockData> output) {
|
||||
if(!shouldDecorate())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if(shouldRayDecorate())
|
||||
{
|
||||
output.iterateSurfaces2D(0, PREDICATE_SOLID, (hunkRelativeX, hunkRelativeZ, hunkOffsetX, hunkOffsetZ, top, bottom, lastBottom, h) -> decorateLayer(x, z, hunkRelativeX, hunkRelativeZ, hunkOffsetX, hunkOffsetZ,top,bottom,lastBottom,h));
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
int he;
|
||||
for(int i = 0; i < output.getWidth(); i++)
|
||||
{
|
||||
for(int j = 0; j < output.getDepth(); j++)
|
||||
{
|
||||
he = getComplex().getHeightFluidStream().get(x + i, z + j).intValue();
|
||||
decorateLayer(x, z, i, j, 0, 0, he, 0, getEngine().getHeight(), output);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void decorateLayer(int x, int z, int hunkRelativeX, int hunkRelativeZ, int hunkOffsetX, int hunkOffsetZ, int top, int bottom,int lastBottom, Hunk<BlockData> h)
|
||||
{
|
||||
int realX = x + hunkOffsetX + hunkRelativeX;
|
||||
int realZ = z + hunkOffsetZ + hunkRelativeZ;
|
||||
IrisBiome b = getComplex().getTrueBiomeStream().get(realX, realZ);
|
||||
|
||||
if(b.getDecorators().isEmpty())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
RNG g = rng.nextParallelRNG(realX >> 4).nextParallelRNG(realZ >> 4);
|
||||
boolean surface = lastBottom == -1;
|
||||
int floor = top + 1;
|
||||
int ceiling = lastBottom == -1 ? floor < getDimension().getFluidHeight() ? getDimension().getFluidHeight() : getEngine().getHeight() : lastBottom - 1;
|
||||
int height = ceiling - floor;
|
||||
|
||||
if(height < 2)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if(b.isShore() && floor <= getDimension().getFluidHeight())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if(surface)
|
||||
{
|
||||
IrisDecorator deco = getComplex().getTerrainSurfaceDecoration().get(realX, realZ);
|
||||
|
||||
if(deco != null)
|
||||
{
|
||||
if(deco.isStacking())
|
||||
{
|
||||
int stack = Math.min(g.i(deco.getStackMin(), deco.getStackMax()), height);
|
||||
boolean fail = false;
|
||||
|
||||
for(int i = 0; i < stack; i++)
|
||||
{
|
||||
BlockData v = deco.getBlockData100(b, rng, realX - i, realZ + i, getData());
|
||||
if(i == 0 && (deco.isForcePlace() || canGoOn(h.get(hunkRelativeX, i+floor-1, hunkRelativeZ), v)))
|
||||
{
|
||||
h.set(hunkRelativeX, i+floor, hunkRelativeZ, v);
|
||||
continue;
|
||||
}
|
||||
|
||||
else if(i == 0)
|
||||
{
|
||||
fail = true;
|
||||
break;
|
||||
}
|
||||
|
||||
h.set(hunkRelativeX, i + floor, hunkRelativeZ, v);
|
||||
}
|
||||
|
||||
if(!fail && deco.getTopPalette().isNotEmpty())
|
||||
{
|
||||
h.set(hunkRelativeX, stack + floor - 1, hunkRelativeZ, deco.getBlockDataForTop(b, rng, realX - stack, realZ + stack, getData()));
|
||||
}
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
BlockData v = deco.getBlockData100(b, rng, realX, realZ, getData());
|
||||
if(deco.isForcePlace() || canGoOn(h.get(hunkRelativeX, floor-1, hunkRelativeZ), v))
|
||||
{
|
||||
h.set(hunkRelativeX, floor, hunkRelativeZ, v);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
IrisBiome cave = getComplex().getCaveBiomeStream().get(realX, realZ);
|
||||
IrisDecorator deco = getComplex().getTerrainCaveSurfaceDecoration().get(realX, realZ);
|
||||
|
||||
if(deco != null)
|
||||
{
|
||||
if(deco.isStacking())
|
||||
{
|
||||
int stack = Math.min(g.i(deco.getStackMin(), deco.getStackMax()), height);
|
||||
boolean fail = false;
|
||||
|
||||
for(int i = 0; i < stack; i++)
|
||||
{
|
||||
BlockData v = deco.getBlockData100(b, rng, realX - i, realZ + i, getData());
|
||||
if(i == 0 && (deco.isForcePlace() || canGoOn(h.get(hunkRelativeX, i+floor-1, hunkRelativeZ), v)))
|
||||
{
|
||||
h.set(hunkRelativeX, i+floor, hunkRelativeZ, v);
|
||||
continue;
|
||||
}
|
||||
|
||||
else if(i == 0)
|
||||
{
|
||||
fail = true;
|
||||
break;
|
||||
}
|
||||
|
||||
h.set(hunkRelativeX, i + floor, hunkRelativeZ, v);
|
||||
}
|
||||
|
||||
if(deco.getTopPalette().isNotEmpty())
|
||||
{
|
||||
h.set(hunkRelativeX, stack + floor - 1, hunkRelativeZ, deco.getBlockDataForTop(b, rng, realX - stack, realZ + stack, getData()));
|
||||
}
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
BlockData v = deco.getBlockData100(b, rng, realX, realZ, getData());
|
||||
if(deco.isForcePlace() || canGoOn(h.get(hunkRelativeX, floor-1, hunkRelativeZ), v))
|
||||
{
|
||||
h.set(hunkRelativeX, floor, hunkRelativeZ, v);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int maxCeiling = lastBottom - top - 1;
|
||||
|
||||
if(maxCeiling > 0)
|
||||
{
|
||||
KList<BlockData> v = cave.generateLayers(realX, realZ, rng, maxCeiling, top, getData());
|
||||
|
||||
if(!v.isEmpty())
|
||||
{
|
||||
for(int i = 0; i < v.size(); i++)
|
||||
{
|
||||
h.set(hunkRelativeX, top+i, hunkRelativeZ, v.get(i));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
IrisDecorator cdeco = getComplex().getTerrainCaveCeilingDecoration().get(realX, realZ);
|
||||
|
||||
if(cdeco != null)
|
||||
{
|
||||
if(cdeco.isStacking())
|
||||
{
|
||||
int stack = Math.min(g.i(cdeco.getStackMin(), cdeco.getStackMax()), height);
|
||||
|
||||
for(int i = 0; i < stack; i++)
|
||||
{
|
||||
h.set(hunkRelativeX, -i + ceiling, hunkRelativeZ, cdeco.getBlockData100(b, rng, realX - i, realZ + i, getData()));
|
||||
}
|
||||
|
||||
if(cdeco.getTopPalette().isNotEmpty())
|
||||
{
|
||||
h.set(hunkRelativeX, -stack + ceiling - 1, hunkRelativeZ, cdeco.getBlockDataForTop(b, rng, realX - stack, realZ + stack, getData()));
|
||||
}
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
h.set(hunkRelativeX, ceiling, hunkRelativeZ, cdeco.getBlockData100(b, rng, realX, realZ, getData()));
|
||||
}
|
||||
}
|
||||
|
||||
int maxFloor = Math.min(8, bottom-1);
|
||||
|
||||
KList<BlockData> v = cave.generateLayers(realX, realZ, rng, maxFloor, bottom, getData());
|
||||
|
||||
if(!v.isEmpty())
|
||||
{
|
||||
for(int i = 0; i < v.size(); i++)
|
||||
{
|
||||
if(bottom-i < 2)
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
BlockData bk = h.get(hunkRelativeX, bottom-i, hunkRelativeZ);
|
||||
|
||||
if(PREDICATE_SOLID.test(bk))
|
||||
{
|
||||
h.set(hunkRelativeX, bottom-i, hunkRelativeZ, v.get(i));
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private boolean canGoOn(BlockData decorant, BlockData atop)
|
||||
{
|
||||
return B.canPlaceOnto(decorant.getMaterial(), atop.getMaterial());
|
||||
}
|
||||
}
|
||||
|
@ -4,13 +4,13 @@ import com.volmit.iris.Iris;
|
||||
import com.volmit.iris.gen.scaffold.TerrainChunk;
|
||||
import com.volmit.iris.noise.CNG;
|
||||
import com.volmit.iris.object.*;
|
||||
import com.volmit.iris.util.CaveResult;
|
||||
import com.volmit.iris.util.KList;
|
||||
import com.volmit.iris.util.PrecisionStopwatch;
|
||||
import com.volmit.iris.util.RNG;
|
||||
import com.volmit.iris.v2.scaffold.engine.Engine;
|
||||
import com.volmit.iris.v2.scaffold.engine.EngineAssignedActuator;
|
||||
import com.volmit.iris.v2.scaffold.hunk.Hunk;
|
||||
import lombok.Getter;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.data.BlockData;
|
||||
|
||||
@ -19,6 +19,7 @@ public class IrisTerrainActuator extends EngineAssignedActuator<BlockData>
|
||||
private static final BlockData AIR = Material.AIR.createBlockData();
|
||||
private static final BlockData BEDROCK = Material.BEDROCK.createBlockData();
|
||||
private static final BlockData CAVE_AIR = Material.CAVE_AIR.createBlockData();
|
||||
@Getter
|
||||
private final RNG rng;
|
||||
private final boolean hasUnder;
|
||||
|
||||
@ -38,8 +39,8 @@ public class IrisTerrainActuator extends EngineAssignedActuator<BlockData>
|
||||
{
|
||||
for(zf = 0; zf < h.getDepth(); zf++)
|
||||
{
|
||||
realX = xf + x;
|
||||
realZ = zf + z;
|
||||
realX = (int) modX(xf + x);
|
||||
realZ = (int) modZ(zf + z);
|
||||
b = hasUnder ? (int) Math.round(getDimension().getUndercarriage().get(rng, realX, realZ)) : 0;
|
||||
he = (int) Math.round(Math.min(h.getHeight(), getComplex().getHeightStream().get(realX, realZ)));
|
||||
hf = (int) Math.round(Math.max(Math.min(h.getHeight(), getDimension().getFluidHeight()), he));
|
||||
|
Loading…
x
Reference in New Issue
Block a user