Mantle Feature Components

This commit is contained in:
Daniel Mills 2021-08-09 09:07:42 -04:00
parent 252d289a8d
commit 9ed3c8a6bb

View File

@ -0,0 +1,88 @@
/*
* Iris is a World Generator for Minecraft Bukkit Servers
* Copyright (c) 2021 Arcane Arts (Volmit Software)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.volmit.iris.engine.mantle.components;
import com.volmit.iris.engine.data.cache.Cache;
import com.volmit.iris.engine.mantle.EngineMantle;
import com.volmit.iris.engine.mantle.IrisMantleComponent;
import com.volmit.iris.engine.object.biome.IrisBiome;
import com.volmit.iris.engine.object.feature.IrisFeaturePositional;
import com.volmit.iris.engine.object.feature.IrisFeaturePotential;
import com.volmit.iris.engine.object.regional.IrisRegion;
import com.volmit.iris.util.collection.KList;
import com.volmit.iris.util.documentation.ChunkCoordinates;
import com.volmit.iris.util.mantle.MantleFlag;
import com.volmit.iris.util.math.RNG;
import com.volmit.iris.util.parallel.BurstExecutor;
import java.util.function.Consumer;
public class MantleFeatureComponent extends IrisMantleComponent {
public MantleFeatureComponent(EngineMantle engineMantle) {
super(engineMantle, MantleFlag.FEATURE);
}
@Override
public void generateLayer(int x, int z, Consumer<Runnable> post) {
int s = getRadius();
BurstExecutor burst = burst();
for (int i = -s; i <= s; i++) {
int xx = i + x;
int xxx = 8 + (xx << 4);
for (int j = -s; j <= s; j++) {
int zz = j + z;
int zzz = 8 + (zz << 4);
burst.queue(() -> {
RNG rng = new RNG(Cache.key(xx, zz) + seed());
IrisRegion region = getComplex().getRegionStream().get(xxx, zzz);
IrisBiome biome = getComplex().getTrueBiomeStreamNoFeatures().get(xxx, zzz);
generateFeatures(rng, xx, zz, region, biome);
});
}
}
burst.complete();
}
@ChunkCoordinates
private void generateFeatures(RNG rng, int cx, int cz, IrisRegion region, IrisBiome biome) {
for (IrisFeaturePotential i : getFeatures()) {
placeZone(rng, cx, cz, i);
}
for (IrisFeaturePotential i : region.getFeatures()) {
placeZone(rng, cx, cz, i);
}
for (IrisFeaturePotential i : biome.getFeatures()) {
placeZone(rng, cx, cz, i);
}
}
private void placeZone(RNG rng, int cx, int cz, IrisFeaturePotential i) {
int x = (cx << 4) + rng.nextInt(16);
int z = (cz << 4) + rng.nextInt(16);
getMantle().set(x, 0, z, new IrisFeaturePositional(x, z, i.getZone()));
}
private KList<IrisFeaturePotential> getFeatures() {
return getEngineMantle().getEngine().getDimension().getFeatures();
}
}