Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

Posted

Hi.

 

Not too long ago I made a thread about my WorldGen system's odd behaviour.

I am not porting, but entirely rewriting my mod for 1.10.2. This is to ensure better code quality.

 

Anyways, I now need to remake the WorldGen system. I have a few problems and questions about this.

 

The main issues/questions I have are these:

 

  • My ores spawn very far away from the spawn. How are chunk coordinates chosen? Completely randomly, or based on player's position?
  • Can't keep up! Did the system time change... 

    is my system not efficient?

  • The main issue. To spawn my copper ore, I practically use iron's settings (count, vein size, min/max Y coords), but my ore is basically extremely common. It spawns in exponentially larger veins than iron does. Of course, I could just tune the settings down, but why does this happen, if I mostly use adapted vanilla code, and iron ore generation settings?

 

Now, explained what my issues are, here is the code.

 

[spoiler=ModWorldGen.java]

public class ModWorldGen {

private final static int NETHER = -1, OVERWORLD = 0, END = 1;

public static void register() {
	registerFeature(new FeatureOre(ModOres.Ore.COPPER, Blocks.STONE, 20, 8, 8, 0, 64), OVERWORLD);
	//registerFeature(new FeatureOre(ModOres.Ore.TIN, Blocks.STONE, 16, 6, 6, 0, 64), OVERWORLD);
}

private static void registerFeature(Feature feature, int... dimensions) {
	GameRegistry.registerWorldGenerator(new WorldGenFeature(feature, dimensions), 0);
}
}

 

 

 

[spoiler=WorldGenFeature.java]

public class WorldGenFeature implements IWorldGenerator {

private final Feature feature;
private final int[] dimensions;

public WorldGenFeature(Feature feature, int... dimensions) {
	this.feature = feature;
	this.dimensions = dimensions;
}

@Override
public void generate(Random random, int chunkX, int chunkZ, World world, IChunkGenerator chunkGenerator, IChunkProvider chunkProvider) {
	if (ArrayUtils.contains(dimensions, world.provider.getDimension())) {
		feature.generate(new Random(), world, chunkZ, chunkZ);
	}
}
}

 

 

 

[spoiler=Feature.java]

public abstract class Feature {

protected int count, minY, maxY;

public Feature(int count, int minY, int maxY) {
	this.count = count;
	this.minY = minY;
	this.maxY = maxY;
}

public abstract void generate(Random random, World world, int chunkX, int chunkZ);
}

 

 

 

[spoiler=FeatureOre.java]

public class FeatureOre extends Feature {

private IBlockState blockOre, blockStone;
private int minSize, maxSize;

public FeatureOre(IVariant ore, IBlockState blockStone, int count, int minSize, int maxSize, int minY, int maxY) {
	super(count, minY, maxY);
	this.blockOre = Block.getBlockFromItem(ore.toItemStack(1).getItem()).getStateFromMeta(ore.getMetadata());
	this.blockStone = blockStone;
	this.minSize = minSize;
	this.maxSize = maxSize;
}

public FeatureOre(IVariant ore, Block blockStone, int count, int minSize, int maxSize, int minY, int maxY) {
	this(ore, blockStone.getDefaultState(), count, minSize, maxSize, minY, maxY);
}

@Override
public void generate(Random random, World world, int chunkX, int chunkZ) {
	final BlockPos chunkPos = new BlockPos(chunkX * 16, minY, chunkZ * 16);
	//Copper's size is 8 (both min and max being , like iron.
	int oreVeinSize = minSize + random.nextInt(Math.max(maxSize - minSize, 1));

	//Copper's count is 20, like iron.
	for (int i = 0; i < count; i++) {
		new WorldGenMinable(blockOre, oreVeinSize, BlockMatcher.forBlock(blockStone.getBlock())).generate(world, random, chunkPos.add(random.nextInt(16), random.nextInt(Math.max(maxY - minY, 0)), random.nextInt(16)));
	}	        
}
}

 

 

 

Edit: Something went wrong. Adding the code now.

Here you go.

I try my best, so apologies if I said something obviously stupid!

  • Author

I seem to have solved my issues with some random seed trickery; I still have a question for you.

 

The only "problem" left is the slight lag that my (?) world gen causes.

Even though I am just generating one ore, it sometimes says

Can't keep up! Did the system time change ...

in the console. The amount of ticks skipped is not too large, but still quite substantial (peaking at 173 ticks skipped).

 

Does this happen even on vanilla worlds? I could understand if the whole minecraft world generation would be causing this, not just my mod's. (as such errors are prompted when flying through the sky, and on world creation)

I try my best, so apologies if I said something obviously stupid!

this might just be your PC and all the running stuff behind Minecraft (like your IDE), AFAIK it shouldn't be a problem.

  • Author

That was my best guess anyways.

Aah, alright, no point in this thread anymore!  ;)

I try my best, so apologies if I said something obviously stupid!

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

Important Information

By using this site, you agree to our Terms of Use.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.