fixes for 22w11a

This commit is contained in:
gnembon committed 2022-03-17 20:21:55 +01:00
1 parent 3e419d1557
commit 302a7b4817
39 files changed
+410 -305

No files matched your search

@@ -46,6 +46,8 @@ import net.minecraft.core.QuartPos;
import net.minecraft.core.Registry;
import net.minecraft.resources.ResourceKey;
import net.minecraft.tags.TagKey;
import net.minecraft.world.level.levelgen.structure.Structure;
import net.minecraft.world.level.levelgen.structure.StructureType;
import org.jetbrains.annotations.Nullable;
import java.util.ArrayList;
@@ -111,13 +113,10 @@ import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.block.state.StateDefinition;
import net.minecraft.world.level.block.state.properties.Property;
import net.minecraft.world.level.chunk.ChunkAccess;
import net.minecraft.world.level.chunk.ChunkGenerator;
import net.minecraft.world.level.chunk.ChunkStatus;
import net.minecraft.world.level.chunk.LevelChunk;
import net.minecraft.world.level.levelgen.Heightmap;
import net.minecraft.world.level.levelgen.WorldgenRandom;
import net.minecraft.world.level.levelgen.feature.ConfiguredStructureFeature;
import net.minecraft.world.level.levelgen.feature.StructureFeature;
import net.minecraft.world.level.levelgen.structure.BoundingBox;
import net.minecraft.world.level.levelgen.structure.StructureStart;
import net.minecraft.world.level.pathfinder.PathComputationType;
@@ -237,11 +236,11 @@ public class WorldAccess {
return (float) num;
}
private static void BooYah(ChunkGenerator generator)
private static void BooYah(final ServerLevel level)
{
synchronized (generator)
synchronized (level)
{
((ChunkGeneratorInterface)generator).initStrongholds();
((ChunkGeneratorInterface)level.getChunkSource().getGenerator()).initStrongholds(level);
}
}
@@ -1285,15 +1284,15 @@ public class WorldAccess {
BlockArgument locator = BlockArgument.findIn(cc, lv, 0);
ServerLevel world = cc.s.getLevel();
BlockPos pos = locator.block.getPos();
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);
Map<Structure, LongSet> references = world.getChunk(pos.getX() >> 4, pos.getZ() >> 4, ChunkStatus.STRUCTURE_REFERENCES).getAllReferences();
Registry<Structure> reg = cc.s.getServer().registryAccess().registryOrThrow(Registry.STRUCTURE_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(reg.getKey(e.getKey())))).collect(Collectors.toList())
);
String simpleStructureName = lv.get(locator.offset).getString().toLowerCase(Locale.ROOT);
ConfiguredStructureFeature<?,?> structureName = reg.get(InputValidator.identifierOf(simpleStructureName));
Structure 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();
@@ -1311,13 +1310,13 @@ public class WorldAccess {
ServerLevel world = cc.s.getLevel();
// well, because
BooYah(world.getChunkSource().getGenerator());
BooYah(world);
BlockPos pos = locator.block.getPos();
final List<ConfiguredStructureFeature<?, ?>> structure = new ArrayList<>();
final List<Structure> structure = new ArrayList<>();
boolean needSize = false;
boolean singleOutput = false;
Registry<ConfiguredStructureFeature<?, ?>> reg = cc.s.getServer().registryAccess().registryOrThrow(Registry.CONFIGURED_STRUCTURE_FEATURE_REGISTRY);
Registry<Structure> reg = cc.s.getServer().registryAccess().registryOrThrow(Registry.STRUCTURE_REGISTRY);
if (lv.size() > locator.offset)
{
Value requested = lv.get(locator.offset+0);
@@ -1325,7 +1324,7 @@ public class WorldAccess {
{
String reqString = requested.getString();
var id = InputValidator.identifierOf(reqString);
ConfiguredStructureFeature<?, ?> requestedStructure = reg.get(id);
Structure requestedStructure = reg.get(id);
if (requestedStructure != null)
{
singleOutput = true;
@@ -1333,10 +1332,8 @@ public class WorldAccess {
}
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()));
StructureType<?> sss = Registry.STRUCTURE_TYPES.get(id);
reg.entrySet().stream().filter(e -> e.getValue().type() ==sss).forEach(e -> structure.add(e.getValue()));
}
if (structure.isEmpty())
{
@@ -1365,7 +1362,7 @@ public class WorldAccess {
return ValueConversions.of(start);
}
Map<Value, Value> ret = new HashMap<>();
for(ConfiguredStructureFeature<?, ?> str: structure)
for(Structure str: structure)
{
StructureStart start;
try
@@ -1392,12 +1389,12 @@ public class WorldAccess {
ServerLevel world = cc.s.getLevel();
BlockPos pos = locator.block.getPos();
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);
Map<Structure, StructureStart> structures = world.getChunk(pos.getX() >> 4, pos.getZ() >> 4, ChunkStatus.STRUCTURE_STARTS).getAllStarts();
Registry<Structure> reg = cc.s.getServer().registryAccess().registryOrThrow(Registry.STRUCTURE_REGISTRY);
if (lv.size() == locator.offset)
{
Map<Value, Value> structureList = new HashMap<>();
for (Map.Entry<ConfiguredStructureFeature<?, ?>, StructureStart> entry : structures.entrySet())
for (Map.Entry<Structure, StructureStart> entry : structures.entrySet())
{
StructureStart start = entry.getValue();
if (start == StructureStart.INVALID_START)
@@ -1425,14 +1422,14 @@ public class WorldAccess {
if (lv.size() == locator.offset)
throw new InternalExpressionException("'set_structure requires at least position and a structure name");
String structureName = lv.get(locator.offset).getString().toLowerCase(Locale.ROOT);
ConfiguredStructureFeature<?, ?> configuredStructure = FeatureGenerator.resolveConfiguredStructure(structureName, world, pos);
Structure configuredStructure = FeatureGenerator.resolveConfiguredStructure(structureName, world, pos);
if (configuredStructure == null) throw new ThrowStatement(structureName, Throwables.UNKNOWN_STRUCTURE);
// good 'ol pointer
Value[] result = new Value[]{Value.NULL};
// technically a world modification. Even if we could let it slide, we will still park it
((CarpetContext) c).s.getServer().executeBlocking(() ->
{
Map<ConfiguredStructureFeature<?, ?>, StructureStart> structures = world.getChunk(pos).getAllStarts();
Map<Structure, StructureStart> structures = world.getChunk(pos).getAllStarts();
if (lv.size() == locator.offset + 1)
{
Boolean res = FeatureGenerator.plopGrid(configuredStructure, ((CarpetContext) c).s.getLevel(), locator.block.getPos());
@@ -1443,7 +1440,7 @@ public class WorldAccess {
Value newValue = lv.get(locator.offset+1);
if (newValue.isNull()) // remove structure
{
ConfiguredStructureFeature<?,?> structure = configuredStructure;
Structure structure = configuredStructure;
if (!structures.containsKey(structure))
{
return;
@@ -1457,7 +1454,7 @@ public class WorldAccess {
{
ChunkPos chpos = new ChunkPos(chx, chz);
// getting a chunk will convert it to full, allowing to modify references
Map<ConfiguredStructureFeature<?,?>, LongSet> references =
Map<Structure, LongSet> references =
world.getChunk(chpos.getWorldPosition()).getAllReferences();
if (references.containsKey(structure) && references.get(structure) != null)
references.get(structure).remove(structureChunkPos.toLong());
@@ -1469,7 +1466,7 @@ public class WorldAccess {
});
return result[0]; // preventing from lazy evaluating of the result in case a future completes later
});
/*
expression.addContextFunction("custom_dimension", -1, (c, t, lv) ->
{
if (lv.size() == 0) throw new InternalExpressionException("'custom_dimension' requires at least one argument");
@@ -1496,7 +1493,7 @@ public class WorldAccess {
CarpetServer.settingsManager.notifyPlayersCommandsChanged();
return Value.TRUE;
});
*/
// todo maybe enable chunk blending?
expression.addContextFunction("reset_chunk", -1, (c, t, lv) ->
{