mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2026-11-28 00:34:19 +00:00
Structure placement markers move into the exposed package; the blocks stage looks up spawn markers itself
This commit is contained in:
1 parent
c3ed24364f
commit
b630efb818
5 files changed
+7
-7
No files matched your search
@@ -1,95 +0,0 @@
|
||||
package art.arcane.iris.engine.framework;
|
||||
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.Base64;
|
||||
import java.util.Objects;
|
||||
|
||||
public final class StructurePlacementMarker {
|
||||
private static final String FAMILY_PREFIX = "@iris-structure:";
|
||||
private static final String VERSION_PREFIX = FAMILY_PREFIX + "v1:";
|
||||
|
||||
private StructurePlacementMarker() {
|
||||
}
|
||||
|
||||
public static String encodeStructure(String objectKey, int placementId, String structureKey) {
|
||||
String normalizedObjectKey = requireKey(objectKey, "objectKey");
|
||||
String normalizedStructureKey = requireKey(structureKey, "structureKey");
|
||||
return VERSION_PREFIX
|
||||
+ encodeKey(normalizedObjectKey)
|
||||
+ ":" + placementId
|
||||
+ ":" + encodeKey(normalizedStructureKey);
|
||||
}
|
||||
|
||||
public static Decoded decode(String marker) {
|
||||
if (marker == null || marker.isBlank()) {
|
||||
return null;
|
||||
}
|
||||
if (marker.startsWith(FAMILY_PREFIX)) {
|
||||
return decodeStructure(marker);
|
||||
}
|
||||
return decodeLegacy(marker);
|
||||
}
|
||||
|
||||
private static Decoded decodeStructure(String marker) {
|
||||
if (!marker.startsWith(VERSION_PREFIX)) {
|
||||
return null;
|
||||
}
|
||||
String[] fields = marker.split(":", -1);
|
||||
if (fields.length != 5 || !fields[0].equals("@iris-structure") || !fields[1].equals("v1")) {
|
||||
return null;
|
||||
}
|
||||
try {
|
||||
String objectKey = decodeCanonicalKey(fields[2]);
|
||||
int placementId = Integer.parseInt(fields[3]);
|
||||
String structureKey = decodeCanonicalKey(fields[4]);
|
||||
if (objectKey.isBlank() || structureKey.isBlank()) {
|
||||
return null;
|
||||
}
|
||||
return new Decoded(objectKey, placementId, structureKey);
|
||||
} catch (IllegalArgumentException exception) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private static Decoded decodeLegacy(String marker) {
|
||||
int separator = marker.indexOf('@');
|
||||
if (separator <= 0 || separator != marker.lastIndexOf('@') || separator == marker.length() - 1) {
|
||||
return null;
|
||||
}
|
||||
String objectKey = marker.substring(0, separator);
|
||||
if (objectKey.isEmpty() || objectKey.equals("null")) {
|
||||
return null;
|
||||
}
|
||||
try {
|
||||
return new Decoded(objectKey, Integer.parseInt(marker.substring(separator + 1)), null);
|
||||
} catch (NumberFormatException exception) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private static String requireKey(String key, String name) {
|
||||
String required = Objects.requireNonNull(key, name);
|
||||
if (required.isBlank()) {
|
||||
throw new IllegalArgumentException(name + " must not be blank");
|
||||
}
|
||||
return required;
|
||||
}
|
||||
|
||||
private static String encodeKey(String key) {
|
||||
return Base64.getUrlEncoder().withoutPadding().encodeToString(key.getBytes(StandardCharsets.UTF_8));
|
||||
}
|
||||
|
||||
private static String decodeCanonicalKey(String key) {
|
||||
String decoded = new String(Base64.getUrlDecoder().decode(key), StandardCharsets.UTF_8);
|
||||
if (!encodeKey(decoded).equals(key)) {
|
||||
throw new IllegalArgumentException("Non-canonical marker key");
|
||||
}
|
||||
return decoded;
|
||||
}
|
||||
|
||||
public record Decoded(String objectKey, int placementId, String structureKey) {
|
||||
public boolean structureAware() {
|
||||
return structureKey != null;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -27,7 +27,7 @@ import art.arcane.volmlib.util.cache.CacheKey;
|
||||
import art.arcane.iris.engine.framework.IrisStructureLocator;
|
||||
import art.arcane.iris.engine.framework.PlacedStructurePiece;
|
||||
import art.arcane.iris.engine.framework.StructurePlacementScope;
|
||||
import art.arcane.iris.engine.framework.StructurePlacementMarker;
|
||||
import art.arcane.iris.builtin.structure.StructurePlacementMarker;
|
||||
import art.arcane.iris.engine.framework.TreeBlockMaterial;
|
||||
import art.arcane.iris.engine.framework.Engine;
|
||||
import art.arcane.iris.engine.mantle.MantleWriter;
|
||||
|
||||
@@ -29,6 +29,7 @@ import art.arcane.iris.builtin.placement.PlacementSettings;
|
||||
import art.arcane.iris.builtin.placement.PlacementTerrain;
|
||||
import art.arcane.iris.builtin.prepare.PreparedPlacement;
|
||||
import art.arcane.iris.builtin.spawn.SpawnMarker;
|
||||
import art.arcane.iris.engine.spawn.SpawnResources;
|
||||
import art.arcane.volmlib.util.collection.KList;
|
||||
import art.arcane.volmlib.util.math.RNG;
|
||||
import com.volmit.IrisModule;
|
||||
@@ -205,7 +206,7 @@ public final class BlocksModule implements IrisModule {
|
||||
RNG markerRandom = new RNG(context.random().nextLong());
|
||||
int salt = 0;
|
||||
for (MarkerRule rule : settings.markers()) {
|
||||
Optional<SpawnMarker> marker = placement.marker(rule.marker());
|
||||
Optional<SpawnMarker> marker = Optional.ofNullable(SpawnResources.marker(placement.resources(), rule.marker()));
|
||||
int markerSalt = salt++;
|
||||
if (marker.isEmpty()) {
|
||||
continue;
|
||||
|
||||
Reference in new issue
Block a user