Pockets and rifts

This commit is contained in:
SD 2022-01-14 13:55:15 +05:30
parent 491ce05f06
commit 13b764b764
15 changed files with 61 additions and 136 deletions

View file

@ -5,13 +5,7 @@ import net.minecraft.block.Block;
import net.minecraft.util.Identifier;
import org.dimdev.dimdoors.block.door.DimensionalDoorBlockRegistrar;
public class BlockRegistryEntryAddedListener implements RegistryEntryAddedCallback<Block> {
private final DimensionalDoorBlockRegistrar registrar;
public BlockRegistryEntryAddedListener(DimensionalDoorBlockRegistrar registrar) {
this.registrar = registrar;
}
public record BlockRegistryEntryAddedListener(DimensionalDoorBlockRegistrar registrar) implements RegistryEntryAddedCallback<Block> {
@Override
public void onEntryAdded(int rawId, Identifier id, Block object) {
registrar.handleEntry(id, object);

View file

@ -5,12 +5,7 @@ import net.minecraft.item.Item;
import net.minecraft.util.Identifier;
import org.dimdev.dimdoors.item.DimensionalDoorItemRegistrar;
public class ItemRegistryEntryAddedListener implements RegistryEntryAddedCallback<Item> {
private final DimensionalDoorItemRegistrar registrar;
public ItemRegistryEntryAddedListener(DimensionalDoorItemRegistrar registrar) {
this.registrar = registrar;
}
public record ItemRegistryEntryAddedListener(DimensionalDoorItemRegistrar registrar) implements RegistryEntryAddedCallback<Item> {
@Override
public void onEntryAdded(int rawId, Identifier id, Item object) {

View file

@ -1,6 +1,10 @@
package org.dimdev.dimdoors.listener;
import net.fabricmc.fabric.api.event.player.UseBlockCallback;
import org.dimdev.dimdoors.DimensionalDoorsInitializer;
import org.dimdev.dimdoors.api.event.UseItemOnBlockCallback;
import org.dimdev.dimdoors.block.ModBlocks;
import org.dimdev.dimdoors.item.DimensionalDoorItemRegistrar;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.Item;
import net.minecraft.item.ItemPlacementContext;
@ -9,10 +13,6 @@ import net.minecraft.util.ActionResult;
import net.minecraft.util.Hand;
import net.minecraft.util.hit.BlockHitResult;
import net.minecraft.world.World;
import org.dimdev.dimdoors.DimensionalDoorsInitializer;
import org.dimdev.dimdoors.api.event.UseItemOnBlockCallback;
import org.dimdev.dimdoors.block.ModBlocks;
import org.dimdev.dimdoors.item.DimensionalDoorItemRegistrar;
public class UseDoorItemOnBlockCallbackListener implements UseItemOnBlockCallback {
@Override

View file

@ -1,17 +0,0 @@
package org.dimdev.dimdoors.mixin.accessor;
import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.gen.Accessor;
import net.minecraft.util.registry.RegistryKey;
import net.minecraft.world.biome.Biome;
import net.minecraft.world.biome.BuiltinBiomes;
@Mixin(BuiltinBiomes.class)
public interface BuiltinBiomesAccessor {
@Accessor("BY_RAW_ID")
static Int2ObjectMap<RegistryKey<Biome>> getIdMap() {
throw new AssertionError();
}
}

View file

@ -9,35 +9,7 @@ import org.dimdev.dimdoors.world.pocket.VirtualLocation;
import java.util.Map;
public class PocketGenerationContext {
private final ServerWorld world;
private final VirtualLocation sourceVirtualLocation;
private final VirtualTarget linkTo;
private final LinkProperties linkProperties;
public PocketGenerationContext(ServerWorld world, VirtualLocation sourceVirtualLocation, VirtualTarget linkTo, LinkProperties linkProperties) {
this.world = world;
this.sourceVirtualLocation = sourceVirtualLocation;
this.linkTo = linkTo;
this.linkProperties = linkProperties;
}
public ServerWorld getWorld() {
return this.world;
}
public VirtualLocation getSourceVirtualLocation() {
return this.sourceVirtualLocation;
}
public VirtualTarget getLinkTo() {
return this.linkTo;
}
public LinkProperties getLinkProperties() {
return this.linkProperties;
}
public record PocketGenerationContext(ServerWorld world, VirtualLocation sourceVirtualLocation, VirtualTarget linkTo, LinkProperties linkProperties) {
public Map<String, Double> toVariableMap(Map<String, Double> stringDoubleMap) {
stringDoubleMap.put("depth", (double) this.sourceVirtualLocation.getDepth());
stringDoubleMap.put("public_size", (double) DimensionalDoorsInitializer.getConfig().getPocketsConfig().publicPocketSize);

View file

@ -10,14 +10,16 @@ import net.minecraft.server.world.ServerWorld;
import net.minecraft.util.Identifier;
import net.minecraft.util.Util;
import net.minecraft.util.math.*;
import net.minecraft.util.registry.BuiltinRegistries;
import net.minecraft.util.registry.Registry;
import net.minecraft.util.registry.RegistryKey;
import net.minecraft.world.ChunkRegion;
import net.minecraft.world.HeightLimitView;
import net.minecraft.world.Heightmap;
import net.minecraft.world.biome.Biome;
import net.minecraft.world.chunk.*;
import net.minecraft.world.gen.GenerationStep;
import net.minecraft.world.gen.chunk.Blender;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.dimdev.dimdoors.DimensionalDoorsInitializer;
@ -71,8 +73,8 @@ public class ChunkGenerator extends PocketGenerator {
@Override
public Pocket prepareAndPlacePocket(PocketGenerationContext parameters, Pocket.PocketBuilder<?, ?> builder) {
ServerWorld world = parameters.getWorld();
VirtualLocation sourceVirtualLocation = parameters.getSourceVirtualLocation();
ServerWorld world = parameters.world();
VirtualLocation sourceVirtualLocation = parameters.sourceVirtualLocation();
int chunkSizeX = ((this.size.getX() >> 4) + (this.size.getX() % 16 == 0 ? 0 : 1));
int chunkSizeZ = ((this.size.getZ() >> 4) + (this.size.getZ() % 16 == 0 ? 0 : 1));
@ -87,7 +89,7 @@ public class ChunkGenerator extends PocketGenerator {
ArrayList<Chunk> protoChunks = new ArrayList<>();
for (int z = 0; z < chunkSizeZ; z++) {
for (int x = 0; x < chunkSizeX; x++) {
ProtoChunk protoChunk = new ProtoChunk(new ChunkPos(pocket.getOrigin().add(x * 16, 0, z * 16)), UpgradeData.NO_UPGRADE_DATA, world);
ProtoChunk protoChunk = new ProtoChunk(new ChunkPos(pocket.getOrigin().add(x * 16, 0, z * 16)), UpgradeData.NO_UPGRADE_DATA, world, genWorld.getRegistryManager().get(Registry.BIOME_KEY), null);
protoChunk.setLightingProvider(genWorld.getLightingProvider());
protoChunks.add(protoChunk);
}
@ -102,24 +104,24 @@ public class ChunkGenerator extends PocketGenerator {
((ProtoChunk) protoChunk).setStatus(ChunkStatus.STRUCTURE_REFERENCES);
}
for (Chunk protoChunk : protoChunks) {
genWorldChunkGenerator.populateBiomes(BuiltinRegistries.BIOME, protoChunk);
genWorldChunkGenerator.populateBiomes(genWorld.getRegistryManager().get(Registry.BIOME_KEY), Util.getMainWorkerExecutor(), Blender.getNoBlending(), genWorld.getStructureAccessor(), protoChunk);
((ProtoChunk) protoChunk).setStatus(ChunkStatus.BIOMES);
}
for (Chunk protoChunk : protoChunks) {
try {
genWorldChunkGenerator.populateNoise(Util.getMainWorkerExecutor(), genWorld.getStructureAccessor().forRegion(protoRegion), protoChunk).get();
genWorldChunkGenerator.populateNoise(Util.getMainWorkerExecutor(), Blender.getNoBlending(), genWorld.getStructureAccessor().forRegion(protoRegion), protoChunk).get();
} catch (InterruptedException | ExecutionException e) {
e.printStackTrace();
}
((ProtoChunk) protoChunk).setStatus(ChunkStatus.NOISE);
}
for (Chunk protoChunk : protoChunks) {
genWorldChunkGenerator.buildSurface(protoRegion, protoChunk);
genWorldChunkGenerator.buildSurface(protoRegion, genWorld.getStructureAccessor(), protoChunk);
((ProtoChunk) protoChunk).setStatus(ChunkStatus.SURFACE);
}
for (GenerationStep.Carver carver : GenerationStep.Carver.values()) {
for (Chunk protoChunk : protoChunks) {
genWorldChunkGenerator.carve(genWorld.getSeed(), genWorld.getBiomeAccess(), protoChunk, carver);
genWorldChunkGenerator.carve(protoRegion, genWorld.getSeed(), genWorld.getBiomeAccess(), genWorld.getStructureAccessor(), protoChunk, carver);
ProtoChunk pChunk = ((ProtoChunk) protoChunk);
if (pChunk.getStatus() == ChunkStatus.SURFACE) pChunk.setStatus(ChunkStatus.CARVERS);
else pChunk.setStatus(ChunkStatus.LIQUID_CARVERS);
@ -127,7 +129,7 @@ public class ChunkGenerator extends PocketGenerator {
}
for (Chunk protoChunk : protoChunks) {
ChunkRegion tempRegion = new ChunkRegionHack(genWorld, ChunkPos.stream(protoChunk.getPos(), 10).map(chunkPos -> protoRegion.getChunk(chunkPos.x, chunkPos.z)).collect(Collectors.toList()));
genWorldChunkGenerator.generateFeatures(tempRegion, genWorld.getStructureAccessor().forRegion(tempRegion));
genWorldChunkGenerator.generateFeatures(tempRegion, protoChunk, genWorld.getStructureAccessor().forRegion(tempRegion));
((ProtoChunk) protoChunk).setStatus(ChunkStatus.FEATURES);
}
for (Chunk protoChunk : protoChunks) { // likely only necessary for spawn step since we copy over anyways
@ -201,15 +203,15 @@ public class ChunkGenerator extends PocketGenerator {
@Override
public Chunk getChunk(int chunkX, int chunkZ, ChunkStatus leastStatus, boolean create) {
Chunk chunk = super.getChunk(chunkX, chunkZ, leastStatus, false);
return chunk == null ? new ProtoChunkHack(new ChunkPos(chunkX, chunkZ), UpgradeData.NO_UPGRADE_DATA, this) : chunk;
return chunk == null ? new ProtoChunkHack(new ChunkPos(chunkX, chunkZ), UpgradeData.NO_UPGRADE_DATA, this, this.getRegistryManager().get(Registry.BIOME_KEY)) : chunk;
}
// TODO: Override getSeed()
}
private static class ProtoChunkHack extends ProtoChunk { // exists solely to make some calls in the non utilized chunks faster
public ProtoChunkHack(ChunkPos pos, UpgradeData upgradeData, HeightLimitView world) {
super(pos, upgradeData, world);
public ProtoChunkHack(ChunkPos pos, UpgradeData upgradeData, HeightLimitView world, Registry<Biome> biomeRegistry) {
super(pos, upgradeData, world, biomeRegistry, null);
}
@Override

View file

@ -162,7 +162,7 @@ public abstract class PocketGenerator implements Weighted<PocketGenerationContex
}
public void setup(Pocket pocket, RiftManager manager, PocketGenerationContext parameters, boolean setupLootTables) {
ServerWorld world = parameters.getWorld();
ServerWorld world = parameters.world();
if (!(pocket instanceof LazyGenerationPocket)) { // should not iterate over that which does not exist & area may be massive, getBlockEntities() might force generation
if (setupLootTables) // temp
@ -181,7 +181,7 @@ public abstract class PocketGenerator implements Weighted<PocketGenerationContex
});
}
manager.getRifts().forEach(rift -> rift.getDestination().setLocation(new Location(world, rift.getPos())));
TemplateUtils.registerRifts(manager.getRifts(), parameters.getLinkTo(), parameters.getLinkProperties(), pocket);
TemplateUtils.registerRifts(manager.getRifts(), parameters.linkTo(), parameters.linkProperties(), pocket);
}
public RiftManager getRiftManager(Pocket pocket) {

View file

@ -1,56 +1,40 @@
package org.dimdev.dimdoors.pockets.generator;
import net.fabricmc.fabric.api.networking.v1.ServerPlayNetworking;
import net.fabricmc.fabric.api.util.NbtType;
import net.fabricmc.loader.api.FabricLoader;
import net.minecraft.client.network.PlayerListEntry;
import net.minecraft.client.network.ServerInfo;
import net.minecraft.nbt.NbtCompound;
import net.minecraft.server.MinecraftServer;
import net.minecraft.server.PlayerManager;
import net.minecraft.server.network.ServerPlayNetworkHandler;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.server.network.ServerPlayerInteractionManager;
import net.minecraft.server.world.ServerEntityManager;
import net.minecraft.server.world.ServerWorld;
import net.minecraft.text.TranslatableText;
import net.minecraft.util.Identifier;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Vec3i;
import net.minecraft.world.chunk.Chunk;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.dimdev.dimdoors.api.util.Path;
import org.dimdev.dimdoors.block.entity.RiftBlockEntity;
import org.dimdev.dimdoors.command.PocketCommand;
import org.dimdev.dimdoors.pockets.PocketLoader;
import org.dimdev.dimdoors.pockets.PocketTemplate;
import org.dimdev.dimdoors.pockets.modifier.AbsoluteRiftBlockEntityModifier;
import org.dimdev.dimdoors.pockets.modifier.RiftManager;
import org.dimdev.dimdoors.api.util.BlockPlacementType;
import org.dimdev.dimdoors.pockets.PocketGenerationContext;
import org.dimdev.dimdoors.util.schematic.Schematic;
import org.dimdev.dimdoors.world.level.registry.DimensionalRegistry;
import org.dimdev.dimdoors.world.pocket.type.LazyGenerationPocket;
import org.dimdev.dimdoors.world.pocket.type.Pocket;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.dimdev.dimdoors.api.util.BlockPlacementType;
import org.dimdev.dimdoors.api.util.Path;
import org.dimdev.dimdoors.block.entity.RiftBlockEntity;
import org.dimdev.dimdoors.command.PocketCommand;
import org.dimdev.dimdoors.pockets.PocketGenerationContext;
import org.dimdev.dimdoors.pockets.PocketLoader;
import org.dimdev.dimdoors.pockets.PocketTemplate;
import org.dimdev.dimdoors.pockets.modifier.AbsoluteRiftBlockEntityModifier;
import org.dimdev.dimdoors.pockets.modifier.RiftManager;
import org.dimdev.dimdoors.util.schematic.Schematic;
import org.dimdev.dimdoors.world.level.registry.DimensionalRegistry;
import org.dimdev.dimdoors.world.pocket.type.LazyGenerationPocket;
import org.dimdev.dimdoors.world.pocket.type.Pocket;
import net.minecraft.nbt.NbtCompound;
import net.minecraft.server.world.ServerWorld;
import net.minecraft.text.TranslatableText;
import net.minecraft.util.Identifier;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Vec3i;
import net.minecraft.world.chunk.Chunk;
import net.fabricmc.fabric.api.util.NbtType;
public class SchematicGenerator extends LazyPocketGenerator{
private static final Logger LOGGER = LogManager.getLogger();
public static final String KEY = "schematic";
/*
public static final Codec<SchematicGenerator> CODEC = RecordCodecBuilder.create(instance -> instance.group(
Codec.INT.fieldOf("size").forGetter(SchematicGenerator::getSize),
Codec.STRING.fieldOf("id").forGetter(SchematicGenerator::getName),
Codec.INT.optionalFieldOf("weight", 5).forGetter(schematicGenerator -> schematicGenerator.getWeight(null))
).apply(instance, SchematicGenerator::new));
*/
private String id;
private Identifier templateID;
private BlockPlacementType placementType = BlockPlacementType.SECTION_NO_UPDATE;
@ -149,7 +133,7 @@ public class SchematicGenerator extends LazyPocketGenerator{
@Override
public Pocket prepareAndPlacePocket(PocketGenerationContext parameters, Pocket.PocketBuilder<?, ?> builder) {
ServerWorld world = parameters.getWorld();
ServerWorld world = parameters.world();
Map<String, Double> variableMap = parameters.toVariableMap(new HashMap<>());
PocketTemplate template = PocketLoader.getInstance().getTemplates().get(Path.stringPath(templateID));

View file

@ -26,7 +26,7 @@ public class VoidGenerator extends LazyPocketGenerator {
@Override
public Pocket prepareAndPlacePocket(PocketGenerationContext parameters, Pocket.PocketBuilder<?, ?> builder) {
Pocket pocket = DimensionalRegistry.getPocketDirectory(parameters.getWorld().getRegistryKey()).newPocket(builder);
Pocket pocket = DimensionalRegistry.getPocketDirectory(parameters.world().getRegistryKey()).newPocket(builder);
Map<String, Double> variableMap = parameters.toVariableMap(new HashMap<>());
pocket.setSize((int) widthEquation.apply(variableMap), (int) heightEquation.apply(variableMap), (int) lengthEquation.apply(variableMap));

View file

@ -59,7 +59,11 @@ public class AbsoluteRiftBlockEntityModifier implements LazyModifier {
NbtList riftsNbt;
if (rifts != null) {
riftsNbt = rifts.values().parallelStream().unordered().map(rift -> rift.writeNbt(new NbtCompound())).collect(Collectors.toCollection(NbtList::new));
riftsNbt = rifts.values().parallelStream().unordered().map(rift -> {
NbtCompound e = new NbtCompound();
rift.writeNbt(e);
return e;
}).collect(Collectors.toCollection(NbtList::new));
} else {
riftsNbt = new NbtList();
riftsNbt.addAll(serializedRifts.values());

View file

@ -156,7 +156,7 @@ public class DimensionalDoorModifier implements LazyCompatibleModifier {
chunk.setBlockState(pos.up(), upper, false);
});
} else {
ServerWorld world = parameters.getWorld();
ServerWorld world = parameters.world();
world.setBlockState(pos, lower);
world.setBlockState(pos.up(), upper);

View file

@ -162,7 +162,7 @@ public class ShellModifier implements LazyModifier {
boxToDrawAround = BlockBox.create(new Vec3i(pocketBox.getMinX(), pocketBox.getMinY(), pocketBox.getMinZ()), new Vec3i(pocketBox.getMaxX(), pocketBox.getMaxY(), pocketBox.getMaxZ()));
layers.forEach(layer -> pocket.expand(layer.getThickness(variableMap)));
} else {
layers.forEach(layer -> drawLayer(layer, manager.getPocket(), parameters.getWorld()));
layers.forEach(layer -> drawLayer(layer, manager.getPocket(), parameters.world()));
}
}

View file

@ -130,14 +130,14 @@ public abstract class PocketGeneratorReference implements ImplementedVirtualPock
Pocket.PocketBuilder<?, ?> builder = generator.pocketBuilder(parameters)
.virtualLocation(parameters.getSourceVirtualLocation()); // TODO: virtualLocation thing still makes little sense
.virtualLocation(parameters.sourceVirtualLocation()); // TODO: virtualLocation thing still makes little sense
generator.applyModifiers(parameters, builder);
this.applyModifiers(parameters, builder);
LazyPocketGenerator.currentlyGenerating = true;
// ensure we aren't missing any chunks that were already loaded previously
// for lazy gen
Set<Chunk> alreadyLoadedChunks = StreamSupport.stream(parameters.getWorld().getChunkManager().threadedAnvilChunkStorage.entryIterator().spliterator(), false).map(ChunkHolder::getWorldChunk).filter(Objects::nonNull).collect(Collectors.toSet());
Set<Chunk> alreadyLoadedChunks = StreamSupport.stream(parameters.world().getChunkManager().threadedAnvilChunkStorage.entryIterator().spliterator(), false).map(ChunkHolder::getWorldChunk).filter(Objects::nonNull).collect(Collectors.toSet());
Pocket pocket = generator.prepareAndPlacePocket(parameters, builder);
BlockPos originalOrigin = pocket.getOrigin();

View file

@ -12,7 +12,6 @@ public abstract class AbstractVirtualPocketList extends WeightedList<VirtualPock
public NbtCompound toNbt(NbtCompound nbt) {
ImplementedVirtualPocket.super.toNbt(nbt);
return nbt;
}

View file

@ -1,16 +1,8 @@
package org.dimdev.dimdoors.world.feature.gateway.schematic;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;
import org.dimdev.dimdoors.mixin.accessor.BuiltinBiomesAccessor;
import net.minecraft.block.Blocks;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.registry.RegistryKey;
import net.minecraft.world.StructureWorldAccess;
import net.minecraft.world.biome.Biome;
public class TwoPillarsGateway extends SchematicGateway {
private static final int GATEWAY_RADIUS = 4;