mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2026-10-22 08:07:42 +00:00
Patching Cleanup
This commit is contained in:
1 parent
bf12f30d26
commit
29a31a69e0
44 files changed
+1340
-970
No files matched your search
@@ -18,13 +18,13 @@
|
||||
|
||||
package art.arcane.iris.modded;
|
||||
|
||||
import art.arcane.iris.platform.BlockStateKey;
|
||||
import art.arcane.iris.spi.PlatformBlockState;
|
||||
import net.minecraft.core.registries.BuiltInRegistries;
|
||||
import net.minecraft.tags.BlockTags;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import net.minecraft.world.level.block.state.properties.Property;
|
||||
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
@@ -52,7 +52,7 @@ public final class ModdedBlockState implements PlatformBlockState {
|
||||
this.state = state;
|
||||
this.parsedProperties = parsedProperties;
|
||||
this.key = key;
|
||||
this.namespace = parseNamespace(key);
|
||||
this.namespace = BlockStateKey.namespace(key);
|
||||
this.deferredPlacementKey = deferredPlacementKey;
|
||||
}
|
||||
|
||||
@@ -101,44 +101,6 @@ public final class ModdedBlockState implements PlatformBlockState {
|
||||
return Objects.hash(state, deferredPlacementKey);
|
||||
}
|
||||
|
||||
private static String parseNamespace(String key) {
|
||||
String base = key;
|
||||
int bracket = base.indexOf('[');
|
||||
if (bracket >= 0) {
|
||||
base = base.substring(0, bracket);
|
||||
}
|
||||
int colon = base.indexOf(':');
|
||||
return colon >= 0 ? base.substring(0, colon) : "minecraft";
|
||||
}
|
||||
|
||||
private static String mergeProperty(String key, String name, String value) {
|
||||
int bracket = key.indexOf('[');
|
||||
if (bracket < 0) {
|
||||
return key + "[" + name + "=" + value + "]";
|
||||
}
|
||||
String base = key.substring(0, bracket);
|
||||
String body = key.substring(bracket + 1, key.lastIndexOf(']'));
|
||||
LinkedHashMap<String, String> properties = new LinkedHashMap<>();
|
||||
for (String entry : body.split(",")) {
|
||||
int equals = entry.indexOf('=');
|
||||
if (equals < 0) {
|
||||
continue;
|
||||
}
|
||||
properties.put(entry.substring(0, equals).trim(), entry.substring(equals + 1).trim());
|
||||
}
|
||||
properties.put(name, value);
|
||||
StringBuilder merged = new StringBuilder(base).append('[');
|
||||
boolean first = true;
|
||||
for (Map.Entry<String, String> property : properties.entrySet()) {
|
||||
if (!first) {
|
||||
merged.append(',');
|
||||
}
|
||||
merged.append(property.getKey()).append('=').append(property.getValue());
|
||||
first = false;
|
||||
}
|
||||
return merged.append(']').toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String key() {
|
||||
return key;
|
||||
@@ -338,7 +300,7 @@ public final class ModdedBlockState implements PlatformBlockState {
|
||||
|
||||
@Override
|
||||
public PlatformBlockState withProperty(String name, String value) {
|
||||
String merged = mergeProperty(key, name, value);
|
||||
String merged = BlockStateKey.withProperty(key, name, value);
|
||||
ModdedBlockState resolved = ModdedBlockResolution.strictParse(merged);
|
||||
return withHandle(resolved.handle(), resolved.parsedProperties());
|
||||
}
|
||||
|
||||
+2
-26
@@ -20,6 +20,7 @@ package art.arcane.iris.modded;
|
||||
|
||||
import art.arcane.iris.engine.DimensionStackContext;
|
||||
import art.arcane.iris.engine.DimensionStackLayout;
|
||||
import art.arcane.iris.nativegen.NativeGenerationWriteGuard;
|
||||
import art.arcane.iris.engine.framework.Engine;
|
||||
import art.arcane.iris.engine.framework.GenerationSessionLease;
|
||||
import art.arcane.iris.engine.framework.NativeFeatureGenerationPolicy;
|
||||
@@ -62,7 +63,6 @@ import java.util.Set;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.locks.ReentrantLock;
|
||||
import java.util.function.IntBinaryOperator;
|
||||
import java.util.function.Predicate;
|
||||
|
||||
/**
|
||||
* Native placed-feature passthrough for one Iris dimension, gated on {@code importedFeatures.enabled}.
|
||||
@@ -353,7 +353,7 @@ final class ModdedImportedFeatureStage {
|
||||
surfaceFirstFreeY,
|
||||
floorFirstFreeY,
|
||||
stackContext != null,
|
||||
importedFeatureProtection(staticObjects, stackContext, staticMinY));
|
||||
NativeGenerationWriteGuard.protectedPositions(staticObjects, stackContext, staticMinY));
|
||||
|
||||
try {
|
||||
for (int stepIndex = 0; stepIndex < steps.size(); stepIndex++) {
|
||||
@@ -401,30 +401,6 @@ final class ModdedImportedFeatureStage {
|
||||
}
|
||||
}
|
||||
|
||||
private static Predicate<BlockPos> importedFeatureProtection(
|
||||
IrisStaticObjectLayer staticObjects,
|
||||
DimensionStackContext stackContext,
|
||||
int minimumY
|
||||
) {
|
||||
Map<Long, DimensionStackLayout> layouts = new ConcurrentHashMap<>();
|
||||
return position -> {
|
||||
if (!staticObjects.isEmpty() && staticObjects.contains(
|
||||
position.getX(), position.getY() - minimumY, position.getZ())) {
|
||||
return true;
|
||||
}
|
||||
if (stackContext == null) {
|
||||
return false;
|
||||
}
|
||||
long columnKey = ((long) position.getX() << 32)
|
||||
^ (position.getZ() & 0xFFFFFFFFL);
|
||||
DimensionStackLayout layout = layouts.computeIfAbsent(
|
||||
columnKey,
|
||||
ignored -> stackContext.sample(position.getX(), position.getZ())
|
||||
);
|
||||
return layout.isHostFeatureProtectedY(position.getY() - minimumY);
|
||||
};
|
||||
}
|
||||
|
||||
void evictRuntime(int runtimeIdentity) {
|
||||
featureTables.remove(runtimeIdentity);
|
||||
inertGenerations.remove(runtimeIdentity);
|
||||
|
||||
+5
-30
@@ -23,7 +23,6 @@ import net.minecraft.world.level.chunk.status.ChunkStatus;
|
||||
import art.arcane.iris.nativegen.NativeGenerationWriteGuard;
|
||||
|
||||
import art.arcane.iris.engine.DimensionStackContext;
|
||||
import art.arcane.iris.engine.DimensionStackLayout;
|
||||
import art.arcane.iris.engine.framework.Engine;
|
||||
import art.arcane.iris.engine.framework.IrisStructureLocator;
|
||||
import art.arcane.iris.engine.framework.NativeStructureGenerationPolicy;
|
||||
@@ -397,7 +396,8 @@ final class ModdedNativeStructureStage {
|
||||
chunkPos.x(), chunkPos.z(), error);
|
||||
}
|
||||
IrisStaticObjectLayer staticObjects = current.getDimension().getStaticObjectLayer(current.getData());
|
||||
Predicate<BlockPos> protectedPosition = nativeStructureProtection(current, staticObjects);
|
||||
Predicate<BlockPos> protectedPosition = NativeGenerationWriteGuard.protectedPositions(
|
||||
staticObjects, current.getDimensionStackContext(), current.getMinHeight());
|
||||
WorldGenLevel boundedWorld = ModdedNativeStructureWorldgenAccess.create(
|
||||
world, chunkPos, worldgenSurfaceHeight(current, world.getMinY()), worldgenFloorHeight(current, world.getMinY()),
|
||||
current.getDimensionStackContext() != null,
|
||||
@@ -480,9 +480,9 @@ final class ModdedNativeStructureStage {
|
||||
worldgenSurfaceHeight(current, world.getMinY()),
|
||||
worldgenFloorHeight(current, world.getMinY()),
|
||||
current.getDimensionStackContext() != null,
|
||||
nativeStructureProtection(
|
||||
current,
|
||||
current.getDimension().getStaticObjectLayer(current.getData())));
|
||||
NativeGenerationWriteGuard.protectedPositions(
|
||||
current.getDimension().getStaticObjectLayer(current.getData()),
|
||||
current.getDimensionStackContext(), current.getMinHeight()));
|
||||
world.setCurrentlyGenerating(() -> "Iris native structure " + structureId);
|
||||
try {
|
||||
NativeStructurePostProcessor.place(
|
||||
@@ -494,31 +494,6 @@ final class ModdedNativeStructureStage {
|
||||
}
|
||||
}
|
||||
|
||||
private static Predicate<BlockPos> nativeStructureProtection(
|
||||
Engine engine,
|
||||
IrisStaticObjectLayer staticObjects
|
||||
) {
|
||||
DimensionStackContext stackContext = engine.getDimensionStackContext();
|
||||
int minimumY = engine.getMinHeight();
|
||||
Map<Long, DimensionStackLayout> layouts = new ConcurrentHashMap<>();
|
||||
return position -> {
|
||||
if (!staticObjects.isEmpty() && staticObjects.contains(
|
||||
position.getX(), position.getY() - minimumY, position.getZ())) {
|
||||
return true;
|
||||
}
|
||||
if (stackContext == null) {
|
||||
return false;
|
||||
}
|
||||
long columnKey = ((long) position.getX() << 32)
|
||||
^ (position.getZ() & 0xFFFFFFFFL);
|
||||
DimensionStackLayout layout = layouts.computeIfAbsent(
|
||||
columnKey,
|
||||
ignored -> stackContext.sample(position.getX(), position.getZ())
|
||||
);
|
||||
return layout.isHostFeatureProtectedY(position.getY() - minimumY);
|
||||
};
|
||||
}
|
||||
|
||||
private List<List<Structure>> structuresByStep(Registry<Structure> registry) {
|
||||
StructureStepCache cached = structureStepCache;
|
||||
if (cached != null && cached.registry() == registry) {
|
||||
|
||||
@@ -3,6 +3,7 @@ package art.arcane.iris.modded;
|
||||
import art.arcane.iris.engine.framework.Engine;
|
||||
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.HexFormat;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Optional;
|
||||
@@ -91,13 +92,7 @@ public final class ModdedWorldgenIds {
|
||||
}
|
||||
|
||||
private static String encode(String value) {
|
||||
byte[] bytes = value.getBytes(StandardCharsets.UTF_8);
|
||||
StringBuilder encoded = new StringBuilder(bytes.length * 2);
|
||||
for (byte current : bytes) {
|
||||
encoded.append(Character.forDigit((current >>> 4) & 0xF, 16));
|
||||
encoded.append(Character.forDigit(current & 0xF, 16));
|
||||
}
|
||||
return encoded.toString();
|
||||
return HexFormat.of().formatHex(value.getBytes(StandardCharsets.UTF_8));
|
||||
}
|
||||
|
||||
private static String decode(String value) {
|
||||
|
||||
+30
@@ -0,0 +1,30 @@
|
||||
package art.arcane.iris.modded;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertThrows;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
public class ModdedWorldgenIdsTest {
|
||||
@Test
|
||||
public void scopedIdsRetainExactUtf8HexEncoding() {
|
||||
assertEquals("irisworldgen:packs/5061636b2f412d5f/dimensions/c389e5b1b1/preset",
|
||||
ModdedWorldgenIds.presetRef("Pack/A-_", "É山"));
|
||||
assertEquals("irisworldgen:packs//dimensions//preset", ModdedWorldgenIds.presetRef("", ""));
|
||||
assertEquals("irisworldgen:packs/3f/dimensions/f0a08080/dimension_type",
|
||||
ModdedWorldgenIds.dimensionTypeRef("\uD800", "\uD840\uDC00"));
|
||||
assertEquals(new ModdedWorldgenIds.ScopedDimension("Pack/A-_", "É山"),
|
||||
ModdedWorldgenIds.scopedDimensionType(
|
||||
ModdedWorldgenIds.dimensionTypeRef("Pack/A-_", "É山")).orElseThrow());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void malformedIdentifiersRetainRejectionBehavior() {
|
||||
assertTrue(ModdedWorldgenIds.scopedDimensionType(
|
||||
"irisworldgen:packs/7/dimensions/61/dimension_type").isEmpty());
|
||||
assertTrue(ModdedWorldgenIds.scopedDimensionType(
|
||||
"irisworldgen:packs/gg/dimensions/61/dimension_type").isEmpty());
|
||||
assertThrows(NullPointerException.class, () -> ModdedWorldgenIds.presetRef(null, "dimension"));
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user