Try fixing ChunkGenerator

This commit is contained in:
SD 2021-02-12 10:06:37 +05:30
parent 3561e9a7b6
commit c707d78ef0
No known key found for this signature in database
GPG key ID: E36B57EE08544BC5
5 changed files with 15 additions and 21 deletions

View file

@ -9,11 +9,13 @@ import net.minecraft.nbt.CompoundTag;
import net.minecraft.server.world.ServerLightingProvider; import net.minecraft.server.world.ServerLightingProvider;
import net.minecraft.server.world.ServerWorld; import net.minecraft.server.world.ServerWorld;
import net.minecraft.util.Identifier; import net.minecraft.util.Identifier;
import net.minecraft.util.Util;
import net.minecraft.util.math.*; import net.minecraft.util.math.*;
import net.minecraft.util.registry.BuiltinRegistries; import net.minecraft.util.registry.BuiltinRegistries;
import net.minecraft.util.registry.Registry; import net.minecraft.util.registry.Registry;
import net.minecraft.util.registry.RegistryKey; import net.minecraft.util.registry.RegistryKey;
import net.minecraft.world.ChunkRegion; import net.minecraft.world.ChunkRegion;
import net.minecraft.world.HeightLimitView;
import net.minecraft.world.Heightmap; import net.minecraft.world.Heightmap;
import net.minecraft.world.chunk.*; import net.minecraft.world.chunk.*;
import net.minecraft.world.gen.GenerationStep; import net.minecraft.world.gen.GenerationStep;
@ -32,6 +34,7 @@ import org.dimdev.dimdoors.world.pocket.VirtualLocation;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.concurrent.ExecutionException;
import java.util.stream.Collectors; import java.util.stream.Collectors;
public class ChunkGenerator extends PocketGenerator { public class ChunkGenerator extends PocketGenerator {
@ -95,7 +98,7 @@ public class ChunkGenerator extends PocketGenerator {
ArrayList<Chunk> protoChunks = new ArrayList<>(); ArrayList<Chunk> protoChunks = new ArrayList<>();
for (int z = 0; z < chunkSizeZ; z++) { for (int z = 0; z < chunkSizeZ; z++) {
for (int x = 0; x < chunkSizeX; x++) { 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); ProtoChunk protoChunk = new ProtoChunk(new ChunkPos(pocket.getOrigin().add(x * 16, 0, z * 16)), UpgradeData.NO_UPGRADE_DATA, world);
protoChunk.setLightingProvider(genWorld.getLightingProvider()); protoChunk.setLightingProvider(genWorld.getLightingProvider());
protoChunks.add(protoChunk); protoChunks.add(protoChunk);
} }
@ -114,7 +117,11 @@ public class ChunkGenerator extends PocketGenerator {
((ProtoChunk) protoChunk).setStatus(ChunkStatus.BIOMES); ((ProtoChunk) protoChunk).setStatus(ChunkStatus.BIOMES);
} }
for (Chunk protoChunk : protoChunks) { for (Chunk protoChunk : protoChunks) {
genWorldChunkGenerator.populateNoise(genWorld, genWorld.getStructureAccessor().forRegion(protoRegion), protoChunk); try {
genWorldChunkGenerator.populateNoise(Util.getMainWorkerExecutor(), genWorld.getStructureAccessor().forRegion(protoRegion), protoChunk).get();
} catch (InterruptedException | ExecutionException e) {
e.printStackTrace();
}
((ProtoChunk) protoChunk).setStatus(ChunkStatus.NOISE); ((ProtoChunk) protoChunk).setStatus(ChunkStatus.NOISE);
} }
for (Chunk protoChunk : protoChunks) { for (Chunk protoChunk : protoChunks) {
@ -199,15 +206,15 @@ public class ChunkGenerator extends PocketGenerator {
@Override @Override
public Chunk getChunk(int chunkX, int chunkZ, ChunkStatus leastStatus, boolean create) { public Chunk getChunk(int chunkX, int chunkZ, ChunkStatus leastStatus, boolean create) {
Chunk chunk = super.getChunk(chunkX, chunkZ, leastStatus, false); Chunk chunk = super.getChunk(chunkX, chunkZ, leastStatus, false);
return chunk == null ? new ProtoChunkHack(new ChunkPos(chunkX, chunkZ), UpgradeData.NO_UPGRADE_DATA) : chunk; return chunk == null ? new ProtoChunkHack(new ChunkPos(chunkX, chunkZ), UpgradeData.NO_UPGRADE_DATA, this) : chunk;
} }
// TODO: Override getSeed() // TODO: Override getSeed()
} }
private static class ProtoChunkHack extends ProtoChunk { // exists solely to make some calls in the non utilized chunks faster private static class ProtoChunkHack extends ProtoChunk { // exists solely to make some calls in the non utilized chunks faster
public ProtoChunkHack(ChunkPos pos, UpgradeData upgradeData) { public ProtoChunkHack(ChunkPos pos, UpgradeData upgradeData, HeightLimitView world) {
super(pos, upgradeData); super(pos, upgradeData, world);
} }
@Override @Override

View file

@ -11,18 +11,6 @@ import net.minecraft.util.registry.RegistryKey;
import net.minecraft.world.World; import net.minecraft.world.World;
public class PocketEntrancePointer extends RegistryVertex { // TODO: PocketRiftPointer superclass? public class PocketEntrancePointer extends RegistryVertex { // TODO: PocketRiftPointer superclass?
public static final Codec<PocketEntrancePointer> CODEC = RecordCodecBuilder.create(instance -> {
return instance.group(
DynamicSerializableUuid.CODEC.fieldOf("id").forGetter(a -> a.id),
World.CODEC.fieldOf("pocketDim").forGetter(a -> a.world),
Codec.INT.fieldOf("pocketId").forGetter(a -> a.pocketId)
).apply(instance, (id, pocketDim, pocketId) -> {
PocketEntrancePointer pointer = new PocketEntrancePointer(pocketDim, pocketId);
pointer.id = id;
return pointer;
});
});
public int pocketId; public int pocketId;
public PocketEntrancePointer(RegistryKey<World> pocketDim, int pocketId) { public PocketEntrancePointer(RegistryKey<World> pocketDim, int pocketId) {

View file

@ -16,7 +16,6 @@ public class LimboTarget extends VirtualTarget implements EntityTarget {
@Override @Override
public boolean receiveEntity(Entity entity, float yawOffset) { public boolean receiveEntity(Entity entity, float yawOffset) {
TeleportUtil.teleport(entity, ModDimensions.LIMBO_DIMENSION, entity.getPos(), yawOffset); TeleportUtil.teleport(entity, ModDimensions.LIMBO_DIMENSION, entity.getPos(), yawOffset);
//FabricDimensions.teleport(entity, entity.getServer().getWorld(LIMBO));
return true; return true;
} }

View file

@ -52,9 +52,9 @@ public class PrivatePocketExitTarget extends VirtualTarget implements EntityTarg
@Override @Override
public void register() { public void register() {
super.register(); super.register();
PocketDirectory privatePocketRegistry = DimensionalRegistry.instance().getPocketDirectory(this.location.world); PocketDirectory privatePocketRegistry = DimensionalRegistry.getPocketDirectory(this.location.world);
Pocket pocket = privatePocketRegistry.getPocketAt(this.location.pos); Pocket pocket = privatePocketRegistry.getPocketAt(this.location.pos);
DimensionalRegistry.instance().getRiftRegistry().addPocketEntrance(pocket, this.location); DimensionalRegistry.getRiftRegistry().addPocketEntrance(pocket, this.location);
} }
@Override @Override

View file

@ -66,7 +66,7 @@ public class PrivatePocketTarget extends VirtualTarget implements EntityTarget {
if (item instanceof DyeItem) { if (item instanceof DyeItem) {
if (pocket.addDye(EntityUtils.getOwner(entity), ((DyeItem) item).getColor())) { if (pocket.addDye(EntityUtils.getOwner(entity), ((DyeItem) item).getColor())) {
entity.remove(); entity.remove(Entity.RemovalReason.DISCARDED);
} else { } else {
((EntityTarget) blockEntity).receiveEntity(entity, relativeYaw); ((EntityTarget) blockEntity).receiveEntity(entity, relativeYaw);
} }