mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2025-12-29 12:09:07 +00:00
Allow placing datapack structures in Iris worlds (#1225)
* Allow placing datapack structures in Iris worlds * command for generating configs for datapack structures * remove the sub dir from the snippet key
This commit is contained in:
@@ -83,6 +83,7 @@ dependencies {
|
||||
slim(libs.commons.io)
|
||||
slim(libs.commons.lang)
|
||||
slim(libs.commons.lang3)
|
||||
slim(libs.commons.math3)
|
||||
slim(libs.oshi)
|
||||
slim(libs.lz4)
|
||||
slim(libs.fastutil)
|
||||
|
||||
@@ -18,19 +18,29 @@
|
||||
|
||||
package com.volmit.iris.core.commands;
|
||||
|
||||
import com.google.gson.JsonArray;
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.volmit.iris.Iris;
|
||||
import com.volmit.iris.core.ServerConfigurator;
|
||||
import com.volmit.iris.core.loader.IrisData;
|
||||
import com.volmit.iris.core.nms.INMS;
|
||||
import com.volmit.iris.core.nms.datapack.DataVersion;
|
||||
import com.volmit.iris.core.service.IrisEngineSVC;
|
||||
import com.volmit.iris.core.tools.IrisPackBenchmarking;
|
||||
import com.volmit.iris.core.tools.IrisToolbelt;
|
||||
import com.volmit.iris.engine.framework.Engine;
|
||||
import com.volmit.iris.engine.object.IrisDimension;
|
||||
import com.volmit.iris.engine.object.annotations.Snippet;
|
||||
import com.volmit.iris.util.collection.KSet;
|
||||
import com.volmit.iris.util.context.IrisContext;
|
||||
import com.volmit.iris.engine.object.IrisJigsawStructurePlacement;
|
||||
import com.volmit.iris.util.collection.KList;
|
||||
import com.volmit.iris.util.decree.DecreeExecutor;
|
||||
import com.volmit.iris.util.decree.DecreeOrigin;
|
||||
import com.volmit.iris.util.decree.annotations.Decree;
|
||||
import com.volmit.iris.util.decree.annotations.Param;
|
||||
import com.volmit.iris.util.decree.specialhandlers.NullableDimensionHandler;
|
||||
import com.volmit.iris.util.format.C;
|
||||
import com.volmit.iris.util.format.Form;
|
||||
import com.volmit.iris.util.io.CountingDataInputStream;
|
||||
@@ -42,6 +52,7 @@ import com.volmit.iris.util.nbt.mca.MCAFile;
|
||||
import com.volmit.iris.util.nbt.mca.MCAUtil;
|
||||
import com.volmit.iris.util.parallel.MultiBurst;
|
||||
import com.volmit.iris.util.plugin.VolmitSender;
|
||||
import lombok.SneakyThrows;
|
||||
import net.jpountz.lz4.LZ4BlockInputStream;
|
||||
import net.jpountz.lz4.LZ4BlockOutputStream;
|
||||
import net.jpountz.lz4.LZ4FrameInputStream;
|
||||
@@ -59,6 +70,8 @@ import java.util.*;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
import java.util.zip.GZIPInputStream;
|
||||
import java.util.zip.GZIPOutputStream;
|
||||
|
||||
@@ -143,6 +156,130 @@ public class CommandDeveloper implements DecreeExecutor {
|
||||
}
|
||||
}
|
||||
|
||||
@SneakyThrows
|
||||
@Decree(description = "Generate Iris structures for all loaded datapack structures")
|
||||
public void generateStructures(
|
||||
@Param(description = "The pack to add the generated structures to", aliases = "pack", defaultValue = "---", customHandler = NullableDimensionHandler.class)
|
||||
IrisDimension dimension,
|
||||
@Param(description = "Ignore existing structures", defaultValue = "false")
|
||||
boolean force
|
||||
) {
|
||||
var map = INMS.get().collectStructures();
|
||||
if (map.isEmpty()) {
|
||||
sender().sendMessage(C.IRIS + "No structures found");
|
||||
return;
|
||||
}
|
||||
|
||||
sender().sendMessage(C.IRIS + "Found " + map.size() + " structures");
|
||||
|
||||
final File dataDir;
|
||||
final IrisData data;
|
||||
final Set<String> existingStructures;
|
||||
final Map<String, Set<String>> snippets;
|
||||
final File dimensionFile;
|
||||
final File structuresFolder;
|
||||
final File snippetsFolder;
|
||||
|
||||
var dimensionObj = new JsonObject();
|
||||
|
||||
if (dimension == null) {
|
||||
dataDir = Iris.instance.getDataFolder("structures");
|
||||
IO.delete(dataDir);
|
||||
data = IrisData.get(dataDir);
|
||||
existingStructures = Set.of();
|
||||
snippets = Map.of();
|
||||
dimensionFile = new File(dataDir, "structures.json");
|
||||
} else {
|
||||
data = dimension.getLoader();
|
||||
dataDir = data.getDataFolder();
|
||||
existingStructures = new KSet<>(data.getJigsawStructureLoader().getPossibleKeys());
|
||||
|
||||
dimensionObj = data.getGson().fromJson(IO.readAll(dimension.getLoadFile()), JsonObject.class);
|
||||
snippets = Optional.ofNullable(dimensionObj.getAsJsonArray("jigsawStructures"))
|
||||
.map(array -> array.asList()
|
||||
.stream()
|
||||
.filter(JsonElement::isJsonPrimitive)
|
||||
.collect(Collectors.toMap(element -> data.getGson()
|
||||
.fromJson(element, IrisJigsawStructurePlacement.class)
|
||||
.getStructure(),
|
||||
element -> Set.of(element.getAsString()),
|
||||
KSet::merge)))
|
||||
.orElse(Map.of());
|
||||
|
||||
dimensionFile = dimension.getLoadFile();
|
||||
}
|
||||
structuresFolder = new File(dataDir, "jigsaw-structures");
|
||||
snippetsFolder = new File(dataDir, "snippet" + "/" + IrisJigsawStructurePlacement.class.getAnnotation(Snippet.class).value());
|
||||
|
||||
var gson = data.getGson();
|
||||
var jigsawStructures = Optional.ofNullable(dimensionObj.getAsJsonArray("jigsawStructures"))
|
||||
.orElse(new JsonArray(map.size()));
|
||||
|
||||
map.forEach((key, placement) -> {
|
||||
String loadKey = "datapack/" + key.namespace() + "/" + key.key();
|
||||
if (existingStructures.contains(loadKey) && !force)
|
||||
return;
|
||||
|
||||
var structures = placement.structures();
|
||||
var obj = placement.toJson(loadKey);
|
||||
if (obj == null || structures.isEmpty()) {
|
||||
sender().sendMessage(C.RED + "Failed to generate hook for " + key);
|
||||
return;
|
||||
}
|
||||
File snippetFile = new File(snippetsFolder, loadKey + ".json");
|
||||
try {
|
||||
IO.writeAll(snippetFile, gson.toJson(obj));
|
||||
} catch (IOException e) {
|
||||
sender().sendMessage(C.RED + "Failed to generate snippet for " + key);
|
||||
e.printStackTrace();
|
||||
return;
|
||||
}
|
||||
|
||||
Set<String> loadKeys = snippets.getOrDefault(loadKey, Set.of(loadKey));
|
||||
jigsawStructures.asList().removeIf(e -> loadKeys.contains((e.isJsonObject() ? e.getAsJsonObject().get("structure") : e).getAsString()));
|
||||
jigsawStructures.add("snippet/" + loadKey);
|
||||
|
||||
String structureKey;
|
||||
if (structures.size() > 1) {
|
||||
KList<String> common = new KList<>();
|
||||
for (int i = 0; i < structures.size(); i++) {
|
||||
var tags = structures.get(i).tags();
|
||||
if (i == 0) common.addAll(tags);
|
||||
else common.removeIf(tag -> !tags.contains(tag));
|
||||
}
|
||||
structureKey = common.isNotEmpty() ? "#" + common.getFirst() : structures.getFirst().key();
|
||||
} else structureKey = structures.getFirst().key();
|
||||
|
||||
JsonArray array = new JsonArray();
|
||||
if (structures.size() > 1) {
|
||||
structures.stream()
|
||||
.flatMap(structure -> {
|
||||
String[] arr = new String[structure.weight()];
|
||||
Arrays.fill(arr, structure.key());
|
||||
return Arrays.stream(arr);
|
||||
})
|
||||
.forEach(array::add);
|
||||
} else array.add(structureKey);
|
||||
|
||||
obj = new JsonObject();
|
||||
obj.addProperty("structureKey", structureKey);
|
||||
obj.add("datapackStructures", array);
|
||||
|
||||
File out = new File(structuresFolder, loadKey + ".json");
|
||||
out.getParentFile().mkdirs();
|
||||
try {
|
||||
IO.writeAll(out, gson.toJson(obj));
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
});
|
||||
|
||||
dimensionObj.add("jigsawStructures", jigsawStructures);
|
||||
IO.writeAll(dimensionFile, gson.toJson(dimensionObj));
|
||||
|
||||
data.hotloaded();
|
||||
}
|
||||
|
||||
@Decree(description = "Test")
|
||||
public void packBenchmark(
|
||||
@Param(description = "The pack to bench", aliases = {"pack"}, defaultValue = "overworld")
|
||||
|
||||
@@ -425,6 +425,7 @@ public class IrisData implements ExclusionStrategy, TypeAdapterFactory {
|
||||
}
|
||||
|
||||
String snippetType = typeToken.getRawType().getDeclaredAnnotation(Snippet.class).value();
|
||||
String snippedBase = "snippet/" + snippetType + "/";
|
||||
|
||||
return new TypeAdapter<>() {
|
||||
@Override
|
||||
@@ -438,19 +439,20 @@ public class IrisData implements ExclusionStrategy, TypeAdapterFactory {
|
||||
|
||||
if (reader.peek().equals(JsonToken.STRING)) {
|
||||
String r = reader.nextString();
|
||||
if (!r.startsWith("snippet/"))
|
||||
return null;
|
||||
if (!r.startsWith(snippedBase))
|
||||
r = snippedBase + r.substring(8);
|
||||
|
||||
if (r.startsWith("snippet/" + snippetType + "/")) {
|
||||
File f = new File(getDataFolder(), r + ".json");
|
||||
|
||||
if (f.exists()) {
|
||||
try (JsonReader snippetReader = new JsonReader(new FileReader(f))){
|
||||
return adapter.read(snippetReader);
|
||||
} catch (Throwable e) {
|
||||
Iris.error("Couldn't read snippet " + r + " in " + reader.getPath() + " (" + e.getMessage() + ")");
|
||||
}
|
||||
} else {
|
||||
Iris.error("Couldn't find snippet " + r + " in " + reader.getPath());
|
||||
File f = new File(getDataFolder(), r + ".json");
|
||||
if (f.exists()) {
|
||||
try (JsonReader snippetReader = new JsonReader(new FileReader(f))){
|
||||
return adapter.read(snippetReader);
|
||||
} catch (Throwable e) {
|
||||
Iris.error("Couldn't read snippet " + r + " in " + reader.getPath() + " (" + e.getMessage() + ")");
|
||||
}
|
||||
} else {
|
||||
Iris.error("Couldn't find snippet " + r + " in " + reader.getPath());
|
||||
}
|
||||
|
||||
return null;
|
||||
@@ -488,7 +490,7 @@ public class IrisData implements ExclusionStrategy, TypeAdapterFactory {
|
||||
.map(s -> s.substring(absPath.length() + 1))
|
||||
.map(s -> s.replace("\\", "/"))
|
||||
.map(s -> s.split("\\Q.\\E")[0])
|
||||
.forEach(s -> l.add("snippet/" + f + "/" + s));
|
||||
.forEach(s -> l.add("snippet/" + s));
|
||||
} catch (Throwable e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
@@ -28,6 +28,7 @@ import com.volmit.iris.util.collection.KList;
|
||||
import com.volmit.iris.util.json.JSONObject;
|
||||
import com.volmit.iris.util.plugin.VolmitSender;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
import java.awt.*;
|
||||
import java.io.File;
|
||||
@@ -39,6 +40,7 @@ public abstract class IrisRegistrant {
|
||||
@ArrayType(min = 1, type = String.class)
|
||||
private KList<String> preprocessors = new KList<>();
|
||||
|
||||
@EqualsAndHashCode.Exclude
|
||||
private transient IrisData loader;
|
||||
|
||||
private transient String loadKey;
|
||||
|
||||
@@ -18,8 +18,12 @@
|
||||
|
||||
package com.volmit.iris.core.nms;
|
||||
|
||||
import com.volmit.iris.core.link.Identifier;
|
||||
import com.volmit.iris.core.nms.container.AutoClosing;
|
||||
import com.volmit.iris.core.nms.container.BiomeColor;
|
||||
import com.volmit.iris.core.nms.container.BlockProperty;
|
||||
import com.volmit.iris.core.nms.container.Pair;
|
||||
import com.volmit.iris.core.nms.container.StructurePlacement;
|
||||
import com.volmit.iris.core.nms.datapack.DataVersion;
|
||||
import com.volmit.iris.engine.framework.Engine;
|
||||
import com.volmit.iris.engine.platform.PlatformChunkGenerator;
|
||||
@@ -136,4 +140,8 @@ public interface INMSBinding {
|
||||
}
|
||||
|
||||
KMap<Material, List<BlockProperty>> getBlockProperties();
|
||||
|
||||
void placeStructures(Chunk chunk);
|
||||
|
||||
KMap<Identifier, StructurePlacement> collectStructures();
|
||||
}
|
||||
|
||||
@@ -0,0 +1,77 @@
|
||||
package com.volmit.iris.core.nms.container;
|
||||
|
||||
import com.google.gson.JsonObject;
|
||||
import com.volmit.iris.engine.object.IrisJigsawStructurePlacement.SpreadType;
|
||||
import lombok.*;
|
||||
import lombok.experimental.Accessors;
|
||||
import lombok.experimental.SuperBuilder;
|
||||
import org.apache.commons.math3.fraction.Fraction;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
@SuperBuilder
|
||||
@Accessors(fluent = true, chain = true)
|
||||
public abstract class StructurePlacement {
|
||||
private final int salt;
|
||||
private final float frequency;
|
||||
private final List<Structure> structures;
|
||||
|
||||
public abstract JsonObject toJson(String structure);
|
||||
|
||||
protected JsonObject createBase(String structure) {
|
||||
JsonObject object = new JsonObject();
|
||||
object.addProperty("structure", structure);
|
||||
object.addProperty("salt", salt);
|
||||
return object;
|
||||
}
|
||||
|
||||
public int frequencyToSpacing() {
|
||||
var frac = new Fraction(Math.max(Math.min(frequency, 1), 0.000000001f));
|
||||
return (int) Math.round(Math.sqrt((double) frac.getDenominator() / frac.getNumerator()));
|
||||
}
|
||||
|
||||
@Getter
|
||||
@Accessors(chain = true, fluent = true)
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@SuperBuilder
|
||||
public static class RandomSpread extends StructurePlacement {
|
||||
private final int spacing;
|
||||
private final int separation;
|
||||
private final SpreadType spreadType;
|
||||
|
||||
@Override
|
||||
public JsonObject toJson(String structure) {
|
||||
JsonObject object = createBase(structure);
|
||||
object.addProperty("spacing", Math.max(spacing, frequencyToSpacing()));
|
||||
object.addProperty("separation", separation);
|
||||
object.addProperty("spreadType", spreadType.name());
|
||||
return object;
|
||||
}
|
||||
}
|
||||
|
||||
@Getter
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@SuperBuilder
|
||||
public static class ConcentricRings extends StructurePlacement {
|
||||
private final int distance;
|
||||
private final int spread;
|
||||
private final int count;
|
||||
|
||||
@Override
|
||||
public JsonObject toJson(String structure) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public record Structure(
|
||||
int weight,
|
||||
String key,
|
||||
List<String> tags
|
||||
) {
|
||||
|
||||
public boolean isValid() {
|
||||
return weight > 0 && key != null;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -19,10 +19,13 @@
|
||||
package com.volmit.iris.core.nms.v1X;
|
||||
|
||||
import com.volmit.iris.Iris;
|
||||
import com.volmit.iris.core.link.Identifier;
|
||||
import com.volmit.iris.core.nms.INMSBinding;
|
||||
import com.volmit.iris.core.nms.container.BiomeColor;
|
||||
import com.volmit.iris.core.nms.container.BlockProperty;
|
||||
import com.volmit.iris.core.nms.datapack.DataVersion;
|
||||
import com.volmit.iris.core.nms.container.Pair;
|
||||
import com.volmit.iris.core.nms.container.StructurePlacement;
|
||||
import com.volmit.iris.engine.framework.Engine;
|
||||
import com.volmit.iris.util.collection.KList;
|
||||
import com.volmit.iris.util.collection.KMap;
|
||||
@@ -135,6 +138,16 @@ public class NMSBinding1X implements INMSBinding {
|
||||
return map;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void placeStructures(Chunk chunk) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public KMap<Identifier, StructurePlacement> collectStructures() {
|
||||
return new KMap<>();
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompoundTag serializeEntity(Entity location) {
|
||||
return null;
|
||||
|
||||
@@ -167,6 +167,7 @@ public class MantleJigsawComponent extends IrisMantleComponent {
|
||||
|
||||
@BlockCoordinates
|
||||
private boolean place(MantleWriter writer, IrisPosition position, IrisJigsawStructure structure, RNG rng, boolean forcePlace) {
|
||||
if (structure == null || structure.getDatapackStructures().isNotEmpty()) return false;
|
||||
return new PlannedStructure(structure, position, rng, forcePlace).place(writer, getMantle(), writer.getEngine());
|
||||
}
|
||||
|
||||
|
||||
@@ -1,43 +0,0 @@
|
||||
/*
|
||||
* Iris is a World Generator for Minecraft Bukkit Servers
|
||||
* Copyright (c) 2022 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.object;
|
||||
|
||||
import com.volmit.iris.engine.object.annotations.*;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
@Snippet("jigsaw-placer")
|
||||
@Accessors(chain = true)
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@Desc("Represents a jigsaw placement")
|
||||
@Data
|
||||
public class IrisJigsawPlacement {
|
||||
@RegistryListResource(IrisJigsawStructure.class)
|
||||
@Required
|
||||
@Desc("The jigsaw structure to use")
|
||||
private String structure = "";
|
||||
|
||||
@Required
|
||||
@MinNumber(1)
|
||||
@Desc("The rarity for this jigsaw structure to place on a per chunk basis")
|
||||
private int rarity = 29;
|
||||
}
|
||||
@@ -23,6 +23,7 @@ import com.volmit.iris.core.loader.IrisRegistrant;
|
||||
import com.volmit.iris.engine.data.cache.AtomicCache;
|
||||
import com.volmit.iris.engine.object.annotations.*;
|
||||
import com.volmit.iris.engine.object.annotations.functions.StructureKeyFunction;
|
||||
import com.volmit.iris.engine.object.annotations.functions.StructureKeyOrTagFunction;
|
||||
import com.volmit.iris.util.collection.KList;
|
||||
import com.volmit.iris.util.json.JSONObject;
|
||||
import com.volmit.iris.util.plugin.VolmitSender;
|
||||
@@ -40,6 +41,11 @@ import lombok.experimental.Accessors;
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
public class IrisJigsawStructure extends IrisRegistrant {
|
||||
@RegistryListFunction(StructureKeyFunction.class)
|
||||
@ArrayType(min = 1, type = String.class)
|
||||
@Desc("The datapack structures. Randomply chooses a structure to place\nIgnores every other setting")
|
||||
private KList<String> datapackStructures = new KList<>();
|
||||
|
||||
@RegistryListResource(IrisJigsawPiece.class)
|
||||
@Required
|
||||
@ArrayType(min = 1, type = String.class)
|
||||
@@ -70,7 +76,7 @@ public class IrisJigsawStructure extends IrisRegistrant {
|
||||
@Desc("Set to true to prevent rotating the initial structure piece")
|
||||
private boolean disableInitialRotation = false;
|
||||
|
||||
@RegistryListFunction(StructureKeyFunction.class)
|
||||
@RegistryListFunction(StructureKeyOrTagFunction.class)
|
||||
@Desc("The minecraft key to use when creating treasure maps")
|
||||
private String structureKey = null;
|
||||
|
||||
@@ -117,6 +123,10 @@ public class IrisJigsawStructure extends IrisRegistrant {
|
||||
|
||||
public int getMaxDimension() {
|
||||
return maxDimension.aquire(() -> {
|
||||
if (datapackStructures.isNotEmpty()) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (useMaxPieceSizeForParallaxRadius) {
|
||||
int max = 0;
|
||||
KList<String> pools = new KList<>();
|
||||
|
||||
@@ -0,0 +1,74 @@
|
||||
package com.volmit.iris.engine.object;
|
||||
|
||||
import com.volmit.iris.engine.framework.Engine;
|
||||
import com.volmit.iris.engine.framework.EngineAssignedComponent;
|
||||
import com.volmit.iris.util.collection.KList;
|
||||
import com.volmit.iris.util.documentation.ChunkCoordinates;
|
||||
import com.volmit.iris.util.math.Position2;
|
||||
import com.volmit.iris.util.math.RNG;
|
||||
import com.volmit.iris.util.noise.CNG;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.function.BiPredicate;
|
||||
|
||||
public class IrisStructurePopulator extends EngineAssignedComponent {
|
||||
private final CNG cng;
|
||||
private final long mantle;
|
||||
private final long jigsaw;
|
||||
|
||||
public IrisStructurePopulator(Engine engine) {
|
||||
super(engine, "Datapack Structures");
|
||||
mantle = engine.getSeedManager().getMantle();
|
||||
jigsaw = engine.getSeedManager().getJigsaw();
|
||||
cng = NoiseStyle.STATIC.create(new RNG(jigsaw));
|
||||
}
|
||||
|
||||
@ChunkCoordinates
|
||||
public void populateStructures(int x, int z, BiPredicate<String, Boolean> placer) {
|
||||
int bX = x << 4, bZ = z << 4;
|
||||
var dimension = getDimension();
|
||||
var region = getEngine().getRegion(bX + 8, bZ + 8);
|
||||
var biome = getEngine().getSurfaceBiome(bX + 8, bZ + 8);
|
||||
var loader = getData().getJigsawStructureLoader();
|
||||
|
||||
long seed = cng.fit(Integer.MIN_VALUE, Integer.MAX_VALUE, x, z);
|
||||
if (dimension.getStronghold() != null) {
|
||||
var list = getDimension().getStrongholds(mantle);
|
||||
if (list != null && list.contains(new Position2(bX, bZ))) {
|
||||
place(placer, loader.load(dimension.getStronghold()), new RNG(seed), true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
boolean placed = place(placer, biome.getJigsawStructures(), seed, x, z);
|
||||
if (!placed) placed = place(placer, region.getJigsawStructures(), seed, x, z);
|
||||
if (!placed) place(placer, dimension.getJigsawStructures(), seed, x, z);
|
||||
}
|
||||
|
||||
private boolean place(BiPredicate<String, Boolean> placer, KList<IrisJigsawStructurePlacement> placements, long seed, int x, int z) {
|
||||
var placement = pick(placements, seed, x, z);
|
||||
if (placement == null) return false;
|
||||
return place(placer, getData().getJigsawStructureLoader().load(placement.getStructure()), new RNG(seed), false);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@ChunkCoordinates
|
||||
private IrisJigsawStructurePlacement pick(List<IrisJigsawStructurePlacement> structures, long seed, int x, int z) {
|
||||
return IRare.pick(structures.stream()
|
||||
.filter(p -> p.shouldPlace(getData(), getDimension().getJigsawStructureDivisor(), jigsaw, x, z))
|
||||
.toList(), new RNG(seed).nextDouble());
|
||||
}
|
||||
|
||||
@ChunkCoordinates
|
||||
private boolean place(BiPredicate<String, Boolean> placer, IrisJigsawStructure structure, RNG rng, boolean ignoreBiomes) {
|
||||
if (structure == null || structure.getDatapackStructures().isEmpty()) return false;
|
||||
var keys = structure.getDatapackStructures().shuffleCopy(rng);
|
||||
while (keys.isNotEmpty()) {
|
||||
String key = keys.removeFirst();
|
||||
if (key != null && placer.test(key, ignoreBiomes || structure.isForcePlace()))
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -18,6 +18,6 @@ public class StructureKeyFunction implements ListFunction<KList<String>> {
|
||||
|
||||
@Override
|
||||
public KList<String> apply(IrisData irisData) {
|
||||
return INMS.get().getStructureKeys();
|
||||
return INMS.get().getStructureKeys().removeWhere(t -> t.startsWith("#"));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
package com.volmit.iris.engine.object.annotations.functions;
|
||||
|
||||
import com.volmit.iris.core.loader.IrisData;
|
||||
import com.volmit.iris.core.nms.INMS;
|
||||
import com.volmit.iris.engine.framework.ListFunction;
|
||||
import com.volmit.iris.util.collection.KList;
|
||||
|
||||
public class StructureKeyOrTagFunction implements ListFunction<KList<String>> {
|
||||
@Override
|
||||
public String key() {
|
||||
return "structure-key-or-tag";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String fancyName() {
|
||||
return "Structure Key or Tag";
|
||||
}
|
||||
|
||||
@Override
|
||||
public KList<String> apply(IrisData irisData) {
|
||||
return INMS.get().getStructureKeys();
|
||||
}
|
||||
}
|
||||
@@ -240,6 +240,7 @@ public class BukkitChunkGenerator extends ChunkGenerator implements PlatformChun
|
||||
}
|
||||
}, syncExecutor));
|
||||
}
|
||||
futures.add(CompletableFuture.runAsync(() -> INMS.get().placeStructures(c), syncExecutor));
|
||||
|
||||
CompletableFuture.allOf(futures.toArray(new CompletableFuture[0]))
|
||||
.thenRunAsync(() -> {
|
||||
|
||||
@@ -22,6 +22,7 @@ import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.AbstractSet;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Iterator;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
@@ -30,13 +31,15 @@ public class KSet<T> extends AbstractSet<T> implements Serializable {
|
||||
private static final long serialVersionUID = 1L;
|
||||
private final ConcurrentHashMap<T, Boolean> map;
|
||||
|
||||
public KSet() {
|
||||
map = new ConcurrentHashMap<>();
|
||||
public KSet(Collection<? extends T> c) {
|
||||
this(c.size());
|
||||
addAll(c);
|
||||
}
|
||||
|
||||
public KSet(Collection<? extends T> c) {
|
||||
this();
|
||||
addAll(c);
|
||||
@SafeVarargs
|
||||
public KSet(T... values) {
|
||||
this(values.length);
|
||||
addAll(Arrays.asList(values));
|
||||
}
|
||||
|
||||
public KSet(int initialCapacity, float loadFactor) {
|
||||
@@ -47,6 +50,13 @@ public class KSet<T> extends AbstractSet<T> implements Serializable {
|
||||
map = new ConcurrentHashMap<>(initialCapacity);
|
||||
}
|
||||
|
||||
public static <T> KSet<T> merge(Collection<? extends T> first, Collection<? extends T> second) {
|
||||
var set = new KSet<T>();
|
||||
set.addAll(first);
|
||||
set.addAll(second);
|
||||
return set;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int size() {
|
||||
return map.size();
|
||||
|
||||
@@ -0,0 +1,88 @@
|
||||
/*
|
||||
* Iris is a World Generator for Minecraft Bukkit Servers
|
||||
* Copyright (c) 2022 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.util.decree.specialhandlers;
|
||||
|
||||
import com.volmit.iris.Iris;
|
||||
import com.volmit.iris.core.IrisSettings;
|
||||
import com.volmit.iris.core.loader.IrisData;
|
||||
import com.volmit.iris.engine.object.IrisDimension;
|
||||
import com.volmit.iris.util.collection.KList;
|
||||
import com.volmit.iris.util.collection.KMap;
|
||||
import com.volmit.iris.util.decree.DecreeParameterHandler;
|
||||
import com.volmit.iris.util.decree.exceptions.DecreeParsingException;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
public class NullableDimensionHandler implements DecreeParameterHandler<IrisDimension> {
|
||||
@Override
|
||||
public KList<IrisDimension> getPossibilities() {
|
||||
KMap<String, IrisDimension> p = new KMap<>();
|
||||
|
||||
//noinspection ConstantConditions
|
||||
for (File i : Iris.instance.getDataFolder("packs").listFiles()) {
|
||||
if (i.isDirectory()) {
|
||||
IrisData data = IrisData.get(i);
|
||||
for (IrisDimension j : data.getDimensionLoader().loadAll(data.getDimensionLoader().getPossibleKeys())) {
|
||||
p.putIfAbsent(j.getLoadKey(), j);
|
||||
}
|
||||
|
||||
data.close();
|
||||
}
|
||||
}
|
||||
|
||||
return p.v();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString(IrisDimension dim) {
|
||||
return dim.getLoadKey();
|
||||
}
|
||||
|
||||
@Override
|
||||
public IrisDimension parse(String in, boolean force) throws DecreeParsingException {
|
||||
if (in.equalsIgnoreCase("---"))
|
||||
return null;
|
||||
|
||||
if (in.equalsIgnoreCase("default")) {
|
||||
return parse(IrisSettings.get().getGenerator().getDefaultWorldType());
|
||||
}
|
||||
|
||||
KList<IrisDimension> options = getPossibilities(in);
|
||||
|
||||
|
||||
if (options.isEmpty()) {
|
||||
throw new DecreeParsingException("Unable to find Dimension \"" + in + "\"");
|
||||
}
|
||||
try {
|
||||
return options.stream().filter((i) -> toString(i).equalsIgnoreCase(in)).toList().get(0);
|
||||
} catch (Throwable e) {
|
||||
throw new DecreeParsingException("Unable to filter which Dimension \"" + in + "\"");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean supports(Class<?> type) {
|
||||
return type.equals(IrisDimension.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getRandomDefault() {
|
||||
return "dimension";
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user