Skip to content

Commit

Permalink
Removed IslandsChunkGenerator in favor of CustomChunkGenerator
Browse files Browse the repository at this point in the history
  • Loading branch information
OmerBenGera committed Jan 8, 2022
1 parent a3fa389 commit d6b5773
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 271 deletions.
Expand Up @@ -9,7 +9,6 @@
import com.bgsoftware.superiorskyblock.key.dataset.KeyMap;
import com.bgsoftware.superiorskyblock.nms.NMSChunks;
import com.bgsoftware.superiorskyblock.nms.v1_17_R1.chunks.CropsTickingTileEntity;
import com.bgsoftware.superiorskyblock.nms.v1_17_R1.chunks.IslandsChunkGenerator;
import com.bgsoftware.superiorskyblock.threads.Executor;
import com.bgsoftware.superiorskyblock.world.blocks.BlockData;
import com.bgsoftware.superiorskyblock.world.chunks.CalculatedChunk;
Expand All @@ -26,6 +25,7 @@
import net.minecraft.network.protocol.game.PacketPlayOutUnloadChunk;
import net.minecraft.server.level.ChunkProviderServer;
import net.minecraft.server.level.LightEngineThreaded;
import net.minecraft.server.level.RegionLimitedWorldAccess;
import net.minecraft.server.level.WorldServer;
import net.minecraft.server.network.PlayerConnection;
import net.minecraft.tags.TagsBlock;
Expand All @@ -42,6 +42,7 @@
import net.minecraft.world.level.chunk.BiomeStorage;
import net.minecraft.world.level.chunk.Chunk;
import net.minecraft.world.level.chunk.ChunkSection;
import net.minecraft.world.level.chunk.ChunkStatus;
import net.minecraft.world.level.chunk.NibbleArray;
import net.minecraft.world.level.chunk.ProtoChunk;
import net.minecraft.world.level.lighting.LightEngine;
Expand Down Expand Up @@ -149,19 +150,17 @@ private static void removeEntities(Chunk chunk) {
}

private static void removeBlocks(Chunk chunk) {
ChunkCoordIntPair chunkCoords = chunk.getPos();
WorldServer worldServer = (WorldServer) chunk.getWorld();

if (!(worldServer.generator instanceof IslandsGenerator)) {
IslandsChunkGenerator chunkGenerator = new IslandsChunkGenerator(worldServer);
ProtoChunk protoChunk = NMSUtils.createProtoChunk(chunkCoords, worldServer);
//noinspection ConstantConditions
chunkGenerator.buildBase(null, protoChunk);
CustomChunkGenerator chunkGenerator = new CustomChunkGenerator(worldServer,
worldServer.getChunkProvider().getChunkGenerator(),
worldServer.generator);

for (int i = 0; i < 16; i++)
chunk.getSections()[i] = protoChunk.getSections()[i];
RegionLimitedWorldAccess region = new RegionLimitedWorldAccess(worldServer,
Collections.singletonList(chunk), ChunkStatus.f, 0);

protoChunk.y().values().forEach(worldServer::setTileEntity);
chunkGenerator.buildBase(region, chunk);
}
}

Expand Down

This file was deleted.

Expand Up @@ -6,7 +6,6 @@
import com.bgsoftware.superiorskyblock.key.dataset.KeyMap;
import com.bgsoftware.superiorskyblock.nms.NMSChunks;
import com.bgsoftware.superiorskyblock.nms.v1_18_R1.chunks.CropsTickingTileEntity;
import com.bgsoftware.superiorskyblock.nms.v1_18_R1.chunks.IslandsChunkGenerator;
import com.bgsoftware.superiorskyblock.nms.v1_18_R1.mapping.BlockPosition;
import com.bgsoftware.superiorskyblock.nms.v1_18_R1.mapping.ChunkCoordIntPair;
import com.bgsoftware.superiorskyblock.nms.v1_18_R1.mapping.SectionPosition;
Expand Down Expand Up @@ -34,6 +33,7 @@
import net.minecraft.nbt.NBTBase;
import net.minecraft.network.protocol.game.ClientboundLevelChunkWithLightPacket;
import net.minecraft.network.protocol.game.PacketPlayOutUnloadChunk;
import net.minecraft.server.level.RegionLimitedWorldAccess;
import net.minecraft.world.entity.player.EntityHuman;
import net.minecraft.world.level.EnumSkyBlock;
import net.minecraft.world.level.biome.BiomeBase;
Expand All @@ -43,6 +43,7 @@
import net.minecraft.world.level.block.state.IBlockData;
import net.minecraft.world.level.block.state.properties.BlockPropertySlabType;
import net.minecraft.world.level.chunk.Chunk;
import net.minecraft.world.level.chunk.ChunkStatus;
import net.minecraft.world.level.chunk.DataPaletteBlock;
import net.minecraft.world.level.chunk.NibbleArray;
import org.bukkit.Location;
Expand All @@ -59,6 +60,7 @@
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
Expand Down Expand Up @@ -136,18 +138,19 @@ private static void removeEntities(ChunkAccess chunk) {
}

private static void removeBlocks(ChunkAccess chunk) {
ChunkCoordIntPair chunkCoords = chunk.getPos();
WorldServer worldServer = chunk.getWorld();

if (!(worldServer.getBukkitGenerator() instanceof IslandsGenerator)) {
IslandsChunkGenerator chunkGenerator = new IslandsChunkGenerator(worldServer);
ChunkAccess protoChunk = NMSUtils.createProtoChunk(chunkCoords, worldServer);
chunkGenerator.a(null, null, protoChunk.getHandle());
CustomChunkGenerator chunkGenerator = new CustomChunkGenerator(worldServer.getHandle(),
worldServer.getChunkProvider().getGenerator(),
worldServer.getBukkitGenerator());

net.minecraft.world.level.chunk.ChunkSection[] chunkSections = protoChunk.getSections();
System.arraycopy(chunkSections, 0, chunk.getSections(), 0, chunkSections.length);
RegionLimitedWorldAccess region = new RegionLimitedWorldAccess(worldServer.getHandle(),
Collections.singletonList(chunk.getHandle()), ChunkStatus.h, 0);

protoChunk.getTileEntities().values().forEach(worldServer::setTileEntity);
chunkGenerator.a(region,
worldServer.getStructureManager().getStructureManager(region).getHandle(),
chunk.getHandle());
}
}

Expand Down

This file was deleted.

@@ -0,0 +1,16 @@
package com.bgsoftware.superiorskyblock.nms.v1_18_R1.mapping.level;

import com.bgsoftware.superiorskyblock.nms.v1_18_R1.mapping.MappedObject;
import net.minecraft.server.level.RegionLimitedWorldAccess;

public final class StructureManager extends MappedObject<net.minecraft.world.level.StructureManager> {

public StructureManager(net.minecraft.world.level.StructureManager handle) {
super(handle);
}

public StructureManager getStructureManager(RegionLimitedWorldAccess region) {
return new StructureManager(this.handle.a(region));
}

}
Expand Up @@ -217,4 +217,8 @@ public Entity getNearestPlayer(PathfinderTargetCondition targetCondition, int x,
return Entity.ofNullable(handle.a(targetCondition, x, y, z));
}

public StructureManager getStructureManager() {
return new StructureManager(handle.a());
}

}

0 comments on commit d6b5773

Please sign in to comment.