1.18.2-pre
This commit is contained in:
1 parent
702022bce0
commit
c01ad9ce9d
20 files changed
+303
-422
No files matched your search
@@ -794,7 +794,7 @@ public class Auxiliary {
|
||||
|
||||
if (res == null)
|
||||
return;
|
||||
if (what.equalsIgnoreCase("boulder")) // there might be more of those
|
||||
if (what.equalsIgnoreCase("forest_rock")) // there might be more of those
|
||||
WorldTools.forceChunkUpdate(locator.block.getPos(), ((CarpetContext) c).s.getLevel());
|
||||
result[0] = BooleanValue.of(res);
|
||||
});
|
||||
|
||||
@@ -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());
|
||||
|
||||
@@ -16,6 +16,7 @@ import carpet.script.value.StringValue;
|
||||
import carpet.script.value.Value;
|
||||
import carpet.script.value.ValueConversions;
|
||||
import carpet.utils.CarpetProfiler;
|
||||
import com.mojang.datafixers.util.Either;
|
||||
import it.unimi.dsi.fastutil.ints.IntOpenHashSet;
|
||||
import it.unimi.dsi.fastutil.ints.IntSet;
|
||||
|
||||
@@ -72,6 +73,7 @@ import net.minecraft.commands.arguments.ObjectiveCriteriaArgument;
|
||||
import net.minecraft.commands.arguments.ParticleArgument;
|
||||
import net.minecraft.commands.arguments.RangeArgument;
|
||||
import net.minecraft.commands.arguments.ResourceLocationArgument;
|
||||
import net.minecraft.commands.arguments.ResourceOrTagLocationArgument;
|
||||
import net.minecraft.commands.arguments.ScoreHolderArgument;
|
||||
import net.minecraft.commands.arguments.ScoreboardSlotArgument;
|
||||
import net.minecraft.commands.arguments.TeamArgument;
|
||||
@@ -91,9 +93,12 @@ import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.core.Direction;
|
||||
import net.minecraft.core.Registry;
|
||||
import net.minecraft.network.chat.TextComponent;
|
||||
import net.minecraft.resources.ResourceKey;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.server.commands.BossBarCommands;
|
||||
import net.minecraft.tags.TagKey;
|
||||
import net.minecraft.world.entity.Entity;
|
||||
import net.minecraft.world.level.biome.Biome;
|
||||
import net.minecraft.world.phys.Vec2;
|
||||
import net.minecraft.world.scores.Scoreboard;
|
||||
|
||||
@@ -209,8 +214,20 @@ public abstract class CommandArgument
|
||||
new VanillaUnconfigurableArgument("boss", ResourceLocationArgument::id,
|
||||
(c, p) -> ValueConversions.of( ResourceLocationArgument.getId(c, p)), BossBarCommands.SUGGEST_BOSS_BAR
|
||||
),
|
||||
new VanillaUnconfigurableArgument("biome", ResourceLocationArgument::id,
|
||||
(c, p) -> ValueConversions.of( ResourceLocationArgument.getId(c, p)), SuggestionProviders.AVAILABLE_BIOMES
|
||||
new VanillaUnconfigurableArgument("biome", () -> ResourceOrTagLocationArgument.resourceOrTag(Registry.BIOME_REGISTRY),
|
||||
(c, p) -> {
|
||||
ResourceOrTagLocationArgument.Result<Biome> result = ResourceOrTagLocationArgument.getBiome(c, p);
|
||||
Either<ResourceKey<Biome>, TagKey<Biome>> res = result.unwrap();
|
||||
if (res.left().isPresent())
|
||||
{
|
||||
return ValueConversions.of(res.left().get());
|
||||
}
|
||||
if (res.right().isPresent())
|
||||
{
|
||||
return ValueConversions.of(res.right().get());
|
||||
}
|
||||
return Value.NULL;
|
||||
}, (ctx, builder) -> SharedSuggestionProvider.suggestResource(ctx.getSource().getServer().registryAccess().registryOrThrow(Registry.BIOME_REGISTRY).keySet(), builder)
|
||||
),
|
||||
new VanillaUnconfigurableArgument("sound", ResourceLocationArgument::id,
|
||||
(c, p) -> ValueConversions.of( ResourceLocationArgument.getId(c, p)), SuggestionProviders.AVAILABLE_SOUNDS
|
||||
|
||||
@@ -115,8 +115,8 @@ public class WorldTools
|
||||
//});
|
||||
|
||||
chunkGenerator2 = new NoiseBasedChunkGenerator(
|
||||
server.registryAccess().registryOrThrow(Registry.STRUCTURE_SET_REGISTRY),
|
||||
server.registryAccess().registryOrThrow(Registry.NOISE_REGISTRY),
|
||||
server.registryAccess().registryOrThrow(Registry.CONFIGURED_STRUCTURE_FEATURE_REGISTRY),
|
||||
MultiNoiseBiomeSource.Preset.OVERWORLD.biomeSource(server.registryAccess().registryOrThrow(Registry.BIOME_REGISTRY)), seed,
|
||||
Holder.direct(server.registryAccess().registryOrThrow(Registry.NOISE_GENERATOR_SETTINGS_REGISTRY).getOrThrow(NoiseGeneratorSettings.OVERWORLD))
|
||||
);
|
||||
|
||||
@@ -314,7 +314,7 @@ public class ValueConversions
|
||||
);
|
||||
}
|
||||
|
||||
public static Value of(StructureStart<?> structure)
|
||||
public static Value of(StructureStart structure)
|
||||
{
|
||||
if (structure == null || structure == StructureStart.INVALID_START) return Value.NULL;
|
||||
BoundingBox boundingBox = structure.getBoundingBox();
|
||||
|
||||
Reference in new issue
Block a user