Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

By jove, I think I've done it #244

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions src/main/java/CustomOreGen/ModEventBusSubscriber.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import javax.annotation.Nonnull;

import CustomOreGen.Server.ServerState;
import CustomOreGen.Server.WorldConfig;
import CustomOreGen.Server.WorldGenFeature;
import net.minecraft.util.ResourceLocation;
import net.minecraft.world.World;
Expand All @@ -28,12 +29,13 @@ public class ModEventBusSubscriber {
* However, the population step falls outside of the system. There could be a populating Feature that runs after the rest.
* Better would be a Forge event when a chunk changes status. Population could run after FEATURES completion.
*/
@Deprecated
/*@Deprecated
@SuppressWarnings("rawtypes")
public void generate(Random random, int chunkX, int chunkZ, World world, ChunkGenerator chunkGenerator, AbstractChunkProvider chunkProvider) {
ServerState.checkIfServerChanged(world.getServer(), world.getWorldInfo());
ServerState.onPopulateChunk(world, chunkX, chunkZ, random);
}
WorldConfig cfg = ServerState.getWorldConfig(world);
ServerState.onPopulateChunk(cfg, chunkGenerator, chunkProvider, chunkX, chunkZ, random);
}*/

@SubscribeEvent
public static void onFMLPreInit(FMLCommonSetupEvent event) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -839,7 +839,7 @@ public boolean attemptPlaceBlock(IWorld world, Random random, int x, int y, int
else
{
BlockArrangement arrangement = new BlockArrangement(replaceableBlocks, aboveBlocks, belowBlocks, besideBlocks, touchingBlocks);
boolean matched = arrangement.matchesAt(world.getWorld(), random, pos);
boolean matched = arrangement.matchesAt(world, random, pos);
if (matched)
{
BlockInfo match = oreBlock.getMatchingBlock(random);
Expand Down
24 changes: 13 additions & 11 deletions src/main/java/CustomOreGen/Server/ServerState.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import net.minecraft.server.MinecraftServer;
import net.minecraft.util.math.ChunkPos;
import net.minecraft.world.server.ServerWorld;
import net.minecraft.world.IWorld;
import net.minecraft.world.World;
import net.minecraft.world.chunk.ChunkStatus;
import net.minecraft.world.dimension.DimensionType;
Expand Down Expand Up @@ -122,13 +123,14 @@ public static void validateOptions(Collection<ConfigOption> options, boolean cul
}

// TODO: add force option; if true then we will generate even when there is no version
public static void populateDistributions(Collection<IOreDistribution> distributions, World world, int chunkX, int chunkZ)
public static void populateDistributions(Collection<IOreDistribution> distributions, IWorld world, int chunkX, int chunkZ)
{
SimpleProfiler.globalProfiler.startSection("Populate");

// FIXME: Before 1.14, we were forcing instant block updates here. Not clear how to do that now.

for (IOreDistribution dist : distributions) {
System.out.println(dist.toString());
dist.generate(world, chunkX, chunkZ);
dist.populate(world, chunkX, chunkZ);
dist.cull();
Expand Down Expand Up @@ -176,22 +178,22 @@ else if (request.world == null)
}
}

public static void onPopulateChunk(World world, int chunkX, int chunkZ, Random rand) {
WorldConfig cfg = getWorldConfig(world);
public static void onPopulateChunk(WorldConfig cfg, IWorld world, int chunkX, int chunkZ, Random rand) {
int range = (cfg.deferredPopulationRange + 15) / 16;
//for (int iX = chunkX - range; iX <= chunkX + range; ++iX)
//{
{
//for (int iZ = chunkZ - range; iZ <= chunkZ + range; ++iZ)
//{
//if (allNeighborsPopulated(world, iX, iZ, range)) {
{
//if (allNeighborsPopulated(world, iX, iZ, range))
{
//CustomOreGenBase.log.info("[" + iX + "," + iZ + "]: POPULATING");
populateDistributions(cfg.getOreDistributions(), world, chunkX, chunkZ);
//}
//}
//}
}
}
}
}

private static boolean allNeighborsPopulated(World world, int chunkX, int chunkZ, int range) {
private static boolean allNeighborsPopulated(IWorld world, int chunkX, int chunkZ, int range) {
int area = 4 * range * (range + 1) + 1;
int neighborCount = 0;
for (int iX = chunkX - range; iX <= chunkX + range; ++iX)
Expand All @@ -208,7 +210,7 @@ private static boolean allNeighborsPopulated(World world, int chunkX, int chunkZ
return neighborCount == area;
}

private static boolean chunkHasBeenPopulated(World world, int chunkX, int chunkZ) {
private static boolean chunkHasBeenPopulated(IWorld world, int chunkX, int chunkZ) {
return world.getChunk(chunkX, chunkZ).getStatus().isAtLeast(ChunkStatus.FEATURES);
}

Expand Down
8 changes: 4 additions & 4 deletions src/main/java/CustomOreGen/Server/SubstitutionFeature.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
import net.minecraft.world.IWorld;
import net.minecraft.world.World;
import net.minecraft.world.biome.Biome;
import net.minecraft.world.chunk.Chunk;
import net.minecraft.world.chunk.ChunkStatus;
import net.minecraft.world.chunk.IChunk;
import net.minecraft.world.gen.ChunkGenerator;
import net.minecraft.world.gen.GenerationSettings;
import net.minecraft.world.gen.Heightmap;
Expand Down Expand Up @@ -307,7 +307,7 @@ public boolean generate(IWorld world, Random random, BlockPos position)
int chunkZ = depositCZ + dCZ;
int chunkX = depositCX + dCX;

Chunk chunk = (Chunk)world.getChunk(chunkX, chunkZ, ChunkStatus.FEATURES.getParent(), false);
IChunk chunk = world.getChunk(chunkX, chunkZ, ChunkStatus.FEATURES.getParent(), false);
if (chunk != null)
{
int minX = dCX < 0 && -dCX * 2 > hRange ? 8 : 0;
Expand Down Expand Up @@ -336,7 +336,7 @@ public boolean generate(IWorld world, Random random, BlockPos position)
int worldX = chunkX * 16 + x;
int worldZ = chunkZ * 16 + z;
BlockPos worldPos = new BlockPos(worldX, y, worldZ);
if (arrangement.matchesAt(world.getWorld(), random, worldPos)) {
if (arrangement.matchesAt(world, random, worldPos)) {
BlockInfo match = this.oreBlock.getMatchingBlock(random);
if (match == null)
{
Expand Down Expand Up @@ -365,7 +365,7 @@ public boolean generate(IWorld world, Random random, BlockPos position)
}
}

private int findSurfaceHeight(Chunk chunk, int x, int z) {
private int findSurfaceHeight(IChunk chunk, int x, int z) {
return chunk.getTopBlockY(Heightmap.Type.WORLD_SURFACE, x, z);
}

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/CustomOreGen/Server/WorldConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,7 @@ else if (chunkGenerator instanceof EndChunkGenerator)

properties.put("dimension.generator", genName);
properties.put("dimension.generator.class", genClass);
properties.put("dimension", world == null ? "" : world.getDimension().getType().getRegistryName());
properties.put("dimension", world == null ? "" : world.getDimension().getType().getRegistryName().getPath());
properties.put("dimension.id", world == null ? 0 : world.getDimension().getType().getId());
properties.put("dimension.isSurface", world == null ? false : world.getDimension().isSurfaceWorld());
properties.put("dimension.hasNoSky", world == null ? false : world.getDimension().hasSkyLight());
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/CustomOreGen/Server/WorldGenFeature.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ public WorldGenFeature(Function<Dynamic<?>, ? extends NoFeatureConfig> configFac
public boolean place(IWorld worldIn, ChunkGenerator<? extends GenerationSettings> generator, Random rand, BlockPos pos, NoFeatureConfig config) {
ServerState.checkIfServerChanged(worldIn.getWorld().getServer(), worldIn.getWorldInfo());
ChunkPos p = new ChunkPos(pos);
ServerState.onPopulateChunk(worldIn.getWorld(), p.x, p.z, worldIn.getRandom()); //TOOD: should use IWorld, not World
WorldConfig cfg = ServerState.getWorldConfig(worldIn.getWorld());
ServerState.onPopulateChunk(cfg, worldIn, p.x, p.z, worldIn.getRandom()); //TOOD: should use IWorld, not World
return false;
}
}
10 changes: 5 additions & 5 deletions src/main/java/CustomOreGen/Util/BlockArrangement.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

import net.minecraft.block.BlockState;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import net.minecraft.world.IWorld;

public class BlockArrangement {
private BlockDescriptor center, above, below, beside;
Expand All @@ -20,7 +20,7 @@ public BlockArrangement(BlockDescriptor center, BlockDescriptor above, BlockDesc
this.touching = touching;
}

public boolean matchesAt(World world, Random rand, BlockPos pos) {
public boolean matchesAt(IWorld world, Random rand, BlockPos pos) {
return
this.descriptorMatchesAt(center, world, rand, pos) &&
this.descriptorMatchesAt(above, world, rand, pos.up()) &&
Expand All @@ -34,15 +34,15 @@ public boolean matchesAt(World world, Random rand, BlockPos pos) {
this.touchesAt(world, rand, pos);
}

private boolean descriptorMatchesAt(BlockDescriptor descriptor, World world, Random rand, BlockPos pos) {
private boolean descriptorMatchesAt(BlockDescriptor descriptor, IWorld world, Random rand, BlockPos pos) {
if (descriptor.isEmpty()) {
return true;
}
BlockState blockState = world.getBlockState(pos);
return descriptor.matchesBlock(blockState, rand);
}

private boolean touchesAt(World world, Random rand, BlockPos pos) {
private boolean touchesAt(IWorld world, Random rand, BlockPos pos) {
if (this.touching.size() <= 0)
return true;

Expand Down Expand Up @@ -78,7 +78,7 @@ private boolean touchesAt(World world, Random rand, BlockPos pos) {
return false;
}

private boolean touchesAt(TouchingDescriptor descriptor, World world, Random rand, BlockPos pos) {
private boolean touchesAt(TouchingDescriptor descriptor, IWorld world, Random rand, BlockPos pos) {
int numberOfTouches = 0;

// search each required block position
Expand Down