1.18.2-pre

This commit is contained in:
gnembon committed 2022-02-20 01:50:46 +01:00
1 parent 702022bce0
commit c01ad9ce9d
20 files changed
+303 -422

No files matched your search

@@ -4,7 +4,6 @@ import carpet.CarpetServer;
import carpet.CarpetSettings;
import carpet.fakes.ChunkGeneratorInterface;
import carpet.fakes.ChunkTicketManagerInterface;
import carpet.fakes.NoiseColumnSamplerInterface;
import carpet.fakes.ServerChunkManagerInterface;
import carpet.fakes.ServerWorldInterface;
import carpet.fakes.SpawnHelperInnerInterface;
@@ -31,7 +30,6 @@ import carpet.script.value.EntityValue;
import carpet.script.value.ListValue;
import carpet.script.value.MapValue;
import carpet.script.value.NBTSerializableValue;
import carpet.script.value.NullValue;
import carpet.script.value.NumericValue;
import carpet.script.value.StringValue;
import carpet.script.value.Value;
@@ -241,10 +239,10 @@ public class WorldAccess {
private static void BooYah(ChunkGenerator generator)
{
//synchronized (generator)
//{
// ((ChunkGeneratorInterface)generator).initStrongholds();
//}
synchronized (generator)
{
((ChunkGeneratorInterface)generator).initStrongholds();
}
}
public static void apply(Expression expression)
@@ -1287,16 +1285,15 @@ public class WorldAccess {
BlockArgument locator = BlockArgument.findIn(cc, lv, 0);
ServerLevel world = cc.s.getLevel();
BlockPos pos = locator.block.getPos();
Map<StructureFeature<?>, LongSet> references = world.getChunk(pos.getX() >> 4, pos.getZ() >> 4, ChunkStatus.STRUCTURE_REFERENCES).getAllReferences();
Map<ConfiguredStructureFeature<?,?>, LongSet> references = world.getChunk(pos.getX() >> 4, pos.getZ() >> 4, ChunkStatus.STRUCTURE_REFERENCES).getAllReferences();
Registry<ConfiguredStructureFeature<?, ?>> reg = cc.s.getServer().registryAccess().registryOrThrow(Registry.CONFIGURED_STRUCTURE_FEATURE_REGISTRY);
if (lv.size() == locator.offset)
return ListValue.wrap(references.entrySet().stream().
filter(e -> e.getValue()!= null && !e.getValue().isEmpty()).
map(e -> new StringValue(NBTSerializableValue.nameFromRegistryId(Registry.STRUCTURE_FEATURE.getKey(e.getKey())))).collect(Collectors.toList())
map(e -> new StringValue(NBTSerializableValue.nameFromRegistryId(reg.getKey(e.getKey())))).collect(Collectors.toList())
);
String simpleStructureName = lv.get(locator.offset).getString().toLowerCase(Locale.ROOT);
//CarpetSettings.LOG.error(FeatureGenerator.featureToStructure.keySet().stream().collect(Collectors.joining(",")));
//CarpetSettings.LOG.error(FeatureGenerator.featureToStructure.values().stream().collect(Collectors.joining(",")));
StructureFeature<?> structureName = Registry.STRUCTURE_FEATURE.get(InputValidator.identifierOf(simpleStructureName));
ConfiguredStructureFeature<?,?> structureName = reg.get(InputValidator.identifierOf(simpleStructureName));
if (structureName == null) return Value.NULL;
LongSet structureReferences = references.get(structureName);
if (structureReferences == null || structureReferences.isEmpty()) return ListValue.of();
@@ -1317,46 +1314,73 @@ public class WorldAccess {
BooYah(world.getChunkSource().getGenerator());
BlockPos pos = locator.block.getPos();
StructureFeature<?> structure = null;
final List<ConfiguredStructureFeature<?, ?>> structure = new ArrayList<>();
boolean needSize = false;
boolean singleOutput = false;
Registry<ConfiguredStructureFeature<?, ?>> reg = cc.s.getServer().registryAccess().registryOrThrow(Registry.CONFIGURED_STRUCTURE_FEATURE_REGISTRY);
if (lv.size() > locator.offset)
{
Value requested = lv.get(locator.offset+0);
if (!requested.isNull())
{
String reqString = requested.getString();
structure = Registry.STRUCTURE_FEATURE.getOptional(InputValidator.identifierOf(reqString))
.orElseThrow(() -> new ThrowStatement(reqString, Throwables.UNKNOWN_STRUCTURE));
var id = InputValidator.identifierOf(reqString);
ConfiguredStructureFeature<?, ?> requestedStructure = reg.get(id);
if (requestedStructure != null)
{
singleOutput = true;
structure.add(requestedStructure);
}
else
{
Registry<StructureFeature<?>> reg1 = cc.s.getServer().registryAccess().registryOrThrow(Registry.STRUCTURE_FEATURE_REGISTRY);
StructureFeature<?> sss = reg1.get(id);
// bad
reg.entrySet().stream().filter(e -> e.getValue().feature==sss).forEach(e -> structure.add(e.getValue()));
}
if (structure.isEmpty())
{
throw new ThrowStatement(reqString, Throwables.UNKNOWN_STRUCTURE);
}
}
else
{
structure.addAll(reg.entrySet().stream().map(Map.Entry::getValue).toList());
}
if (lv.size() > locator.offset+1)
{
needSize = lv.get(locator.offset+1).getBoolean();
}
}
if (structure != null)
else
{
StructureStart<?> start = FeatureGenerator.shouldStructureStartAt(world, pos, structure, needSize);
structure.addAll(reg.entrySet().stream().map(Map.Entry::getValue).toList());
}
if (singleOutput)
{
StructureStart start = FeatureGenerator.shouldStructureStartAt(world, pos, structure.get(0), needSize);
if (start == null) return Value.NULL;
if (!needSize) return Value.TRUE;
return ValueConversions.of(start);
}
Map<Value, Value> ret = new HashMap<>();
for(StructureFeature<?> str : StructureFeature.STRUCTURES_REGISTRY.values())
for(ConfiguredStructureFeature<?, ?> str: structure)
{
StructureStart<?> start;
StructureStart start;
try
{
start = FeatureGenerator.shouldStructureStartAt(world, pos, str, needSize);
}
catch (NullPointerException npe)
{
CarpetSettings.LOG.error("Failed to detect structure: "+str.getFeatureName());
CarpetSettings.LOG.error("Failed to detect structure: "+ reg.getKey(str));
start = null;
}
if (start == null) continue;
Value key = new StringValue(NBTSerializableValue.nameFromRegistryId(Registry.STRUCTURE_FEATURE.getKey(str)));
Value key = new StringValue(NBTSerializableValue.nameFromRegistryId(reg.getKey(str)));
ret.put(key, (!needSize)?Value.NULL: ValueConversions.of(start));
}
return MapValue.wrap(ret);
@@ -1368,25 +1392,26 @@ public class WorldAccess {
ServerLevel world = cc.s.getLevel();
BlockPos pos = locator.block.getPos();
Map<StructureFeature<?>, StructureStart<?>> structures = world.getChunk(pos.getX() >> 4, pos.getZ() >> 4, ChunkStatus.STRUCTURE_STARTS).getAllStarts();
Map<ConfiguredStructureFeature<?,?>, StructureStart> structures = world.getChunk(pos.getX() >> 4, pos.getZ() >> 4, ChunkStatus.STRUCTURE_STARTS).getAllStarts();
Registry<ConfiguredStructureFeature<?, ?>> reg = cc.s.getServer().registryAccess().registryOrThrow(Registry.CONFIGURED_STRUCTURE_FEATURE_REGISTRY);
if (lv.size() == locator.offset)
{
Map<Value, Value> structureList = new HashMap<>();
for (Map.Entry<StructureFeature<?>, StructureStart<?>> entry : structures.entrySet())
for (Map.Entry<ConfiguredStructureFeature<?, ?>, StructureStart> entry : structures.entrySet())
{
StructureStart<?> start = entry.getValue();
StructureStart start = entry.getValue();
if (start == StructureStart.INVALID_START)
continue;
BoundingBox box = start.getBoundingBox();
structureList.put(
new StringValue(NBTSerializableValue.nameFromRegistryId(Registry.STRUCTURE_FEATURE.getKey(entry.getKey()))),
new StringValue(NBTSerializableValue.nameFromRegistryId(reg.getKey(entry.getKey()))),
ListValue.of(ListValue.fromTriple(box.minX(), box.minY(), box.minZ()), ListValue.fromTriple(box.maxX(), box.maxY(), box.maxZ()))
);
}
return MapValue.wrap(structureList);
}
String structureName = lv.get(locator.offset).getString().toLowerCase(Locale.ROOT);
return ValueConversions.of(structures.get(Registry.STRUCTURE_FEATURE.get(InputValidator.identifierOf(structureName))));
return ValueConversions.of(structures.get(reg.get(InputValidator.identifierOf(structureName))));
});
expression.addContextFunction("set_structure", -1, (c, t, lv) ->
@@ -1407,11 +1432,10 @@ public class WorldAccess {
// technically a world modification. Even if we could let it slide, we will still park it
((CarpetContext) c).s.getServer().executeBlocking(() ->
{
Map<StructureFeature<?>, StructureStart<?>> structures = world.getChunk(pos).getAllStarts();
Map<ConfiguredStructureFeature<?, ?>, StructureStart> structures = world.getChunk(pos).getAllStarts();
if (lv.size() == locator.offset + 1)
{
Boolean res = FeatureGenerator.plopGrid(configuredStructure, ((CarpetContext) c).s.getLevel(), locator.block.getPos());
//Boolean res = FeatureGenerator.gridStructure(structureName, ((CarpetContext) c).s.getWorld(), locator.block.getPos());
if (res == null) return;
result[0] = res?Value.TRUE:Value.FALSE;
return;
@@ -1419,13 +1443,13 @@ public class WorldAccess {
Value newValue = lv.get(locator.offset+1);
if (newValue.isNull()) // remove structure
{
StructureFeature<?> structure = configuredStructure.feature;
ConfiguredStructureFeature<?,?> structure = configuredStructure;
if (!structures.containsKey(structure))
{
return;
}
StructureStart<?> start = structures.get(structure);
ChunkPos structureChunkPos = start.getChunkPos(); // new ChunkPos(start.getChunkX(), start.getChunkZ());
StructureStart start = structures.get(structure);
ChunkPos structureChunkPos = start.getChunkPos();
BoundingBox box = start.getBoundingBox();
for (int chx = box.minX() / 16; chx <= box.maxX() / 16; chx++) // minx maxx
{
@@ -1433,7 +1457,7 @@ public class WorldAccess {
{
ChunkPos chpos = new ChunkPos(chx, chz);
// getting a chunk will convert it to full, allowing to modify references
Map<StructureFeature<?>, LongSet> references =
Map<ConfiguredStructureFeature<?,?>, LongSet> references =
world.getChunk(chpos.getWorldPosition()).getAllReferences();
if (references.containsKey(structure) && references.get(structure) != null)
references.get(structure).remove(structureChunkPos.toLong());