Jump to content

[solved]WorldGenMinable - what am i doing wrong??


danners68

Recommended Posts

I've recently started coding java, following tutorials and renaming things, piecing together the puzzle of modding,

 

however i've stumbled upon a flaw that no amount of tutorials seem to help me with (maybe I'm not reading them properly),

 

Eclipse Tells Me Everything is fine and there's no little error marks anywhere that says class referencing is incorrect, the debug minecraft environment runs properly right up until it try's to generate the terrain with my new ore

 

 

Just to clarify this is using 1.7.10 with forge: 10.13.2.1230

 

[spoiler=code]package mg.Labyrinth;

 

import java.util.Random;

 

import net.minecraft.block.Block;

import net.minecraft.init.Blocks;

import net.minecraft.world.World;

import net.minecraft.world.chunk.IChunkProvider;

import net.minecraft.world.gen.feature.WorldGenMinable;

import cpw.mods.fml.common.IWorldGenerator;

 

public class worldGen implements IWorldGenerator

{

public void generate(Random random, int chunkX, int chunkZ, World world, IChunkProvider chunkGenerator, IChunkProvider chunkProvider)

{

switch (world.provider.dimensionId)

{

case -1:

generateNether(world, random, chunkX * 16, chunkZ * 16);

case 0:

generateSurface(world, random, chunkX * 16, chunkZ * 16);

case 1:

generateEnd(world, random, chunkX * 16, chunkZ * 16);

break;

}

}

 

private void generateEnd(World world, Random random, int x, int z)

{

 

}

 

private void generateSurface(World world, Random random, int x, int z)

{

this.addOreSpawn(minoriumOre.minoriumOre, world, random, x, z, 16, 16, 4 + random.nextInt(3), 5, 15, 50);

int Xcoord = x + random.nextInt(16);

    int Ycoord = 10 + random.nextInt(128);

    int Zcoord = z + random.nextInt(16);

    (new WorldGenMinable(minoriumOre.minoriumOre, 1, 15, Blocks.stone)).generate(world, random, Xcoord, Ycoord, Zcoord);

}

 

private void generateNether(World world, Random random, int x, int z)

{

 

}

 

/**

* Adds an Ore Spawn to Minecraft. Simply register all Ores to spawn with this method in your Generation method in your IWorldGeneration extending Class

*

* @param The Block to spawn

* @param The World to spawn in

* @param A Random object for retrieving random positions within the world to spawn the Block

* @param An int for passing the X-Coordinate for the Generation method

* @param An int for passing the Z-Coordinate for the Generation method

* @param An int for setting the maximum X-Coordinate values for spawning on the X-Axis on a Per-Chunk basis

* @param An int for setting the maximum Z-Coordinate values for spawning on the Z-Axis on a Per-Chunk basis

* @param An int for setting the maximum size of a vein

* @param An int for the Number of chances available for the Block to spawn per-chunk

* @param An int for the minimum Y-Coordinate height at which this block may spawn

* @param An int for the maximum Y-Coordinate height at which this block may spawn

**/

public void addOreSpawn(Block block, World world, Random random, int blockXPos, int blockZPos, int maxX, int maxZ, int maxVeinSize, int chancesToSpawn, int minY, int maxY)

{

assert maxY > minY : "The maximum Y must be greater than the Minimum Y";

assert maxX > 0 && maxX <= 16 : "addOreSpawn: The Maximum X must be greater than 0 and less than 16";

assert minY > 0 : "addOreSpawn: The Minimum Y must be greater than 0";

assert maxY < 256 && maxY > 0 : "addOreSpawn: The Maximum Y must be less than 256 but greater than 0";

assert maxZ > 0 && maxZ <= 16 : "addOreSpawn: The Maximum Z must be greater than 0 and less than 16";

 

int diffBtwnMinMaxY = maxY - minY;

for (int x = 5; x < chancesToSpawn; x++)

{

int posX = blockXPos + random.nextInt(maxX);

int posY = minY + random.nextInt(diffBtwnMinMaxY);

int posZ = blockZPos + random.nextInt(maxZ);

(new WorldGenMinable(block, maxVeinSize)).generate(world, random, posX, posY, posZ);

break;

}

}

}

 

 

 

I like to think I understand what the most of this is doing and that in theory with everything I've Googled says that this should work, however, minecraft says otherwise and gives me the following crash report:

 

[spoiler=crash]

---- Minecraft Crash Report ----

// Daisy, daisy...

 

Time: 15/01/15 18:05

Description: Exception in server tick loop

 

java.lang.NullPointerException: Exception in server tick loop

at net.minecraft.world.chunk.storage.ExtendedBlockStorage.func_150818_a(SourceFile:57)

at net.minecraft.world.chunk.Chunk.func_150807_a(Chunk.java:595)

at net.minecraft.world.World.setBlock(World.java:451)

at net.minecraft.world.gen.feature.WorldGenMinable.generate(WorldGenMinable.java:78)

at mg.Labyrinth.worldGen.generateSurface(worldGen.java:39)

at mg.Labyrinth.worldGen.generate(worldGen.java:21)

at cpw.mods.fml.common.registry.GameRegistry.generateWorld(GameRegistry.java:106)

at net.minecraft.world.gen.ChunkProviderServer.populate(ChunkProviderServer.java:280)

at net.minecraft.world.chunk.Chunk.populateChunk(Chunk.java:1055)

at net.minecraft.world.gen.ChunkProviderServer.originalLoadChunk(ChunkProviderServer.java:190)

at net.minecraft.world.gen.ChunkProviderServer.loadChunk(ChunkProviderServer.java:131)

at net.minecraft.world.gen.ChunkProviderServer.loadChunk(ChunkProviderServer.java:101)

at net.minecraft.server.MinecraftServer.initialWorldChunkLoad(MinecraftServer.java:265)

at net.minecraft.server.integrated.IntegratedServer.loadAllWorlds(IntegratedServer.java:78)

at net.minecraft.server.integrated.IntegratedServer.startServer(IntegratedServer.java:92)

at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:387)

at net.minecraft.server.MinecraftServer$2.run(MinecraftServer.java:685)

 

 

A detailed walkthrough of the error, its code path and all known details is as follows:

---------------------------------------------------------------------------------------

 

-- System Details --

Details:

Minecraft Version: 1.7.10

Operating System: Windows 7 (amd64) version 6.1

Java Version: 1.8.0_25, Oracle Corporation

Java VM Version: Java HotSpot 64-Bit Server VM (mixed mode), Oracle Corporation

Memory: 923312960 bytes (880 MB) / 1037959168 bytes (989 MB) up to 1037959168 bytes (989 MB)

JVM Flags: 3 total; -Xincgc -Xmx1024M -Xms1024M

AABB Pool Size: 0 (0 bytes; 0 MB) allocated, 0 (0 bytes; 0 MB) used

IntCache: cache: 0, tcache: 0, allocated: 13, tallocated: 95

FML: MCP v9.05 FML v7.10.85.1230 Minecraft Forge 10.13.2.1230 7 mods loaded, 7 mods active

mcp{9.05} [Minecraft Coder Pack] (minecraft.jar) Unloaded->Constructed->Pre-initialized->Initialized->Post-initialized->Available->Available

FML{7.10.85.1230} [Forge Mod Loader] (forgeBin-1.7.10-10.13.2.1230.jar) Unloaded->Constructed->Pre-initialized->Initialized->Post-initialized->Available->Available

Forge{10.13.2.1230} [Minecraft Forge] (forgeBin-1.7.10-10.13.2.1230.jar) Unloaded->Constructed->Pre-initialized->Initialized->Post-initialized->Available->Available

CodeChickenCore{1.0.4.29} [CodeChicken Core] (minecraft.jar) Unloaded->Constructed->Pre-initialized->Initialized->Post-initialized->Available->Available

NotEnoughItems{1.0.4.83} [Not Enough Items] (NotEnoughItems-1.7.10-1.0.4.83-universal.jar) Unloaded->Constructed->Pre-initialized->Initialized->Post-initialized->Available->Available

mg.Labyrinth{0.0.01A} [Labyrinth] (bin) Unloaded->Constructed->Pre-initialized->Initialized->Post-initialized->Available->Available

ComputerCraft{1.64} [ComputerCraft] (ComputerCraft1.64.jar) Unloaded->Constructed->Pre-initialized->Initialized->Post-initialized->Available->Available

Profiler Position: N/A (disabled)

Vec3 Pool Size: 0 (0 bytes; 0 MB) allocated, 0 (0 bytes; 0 MB) used

Player Count: 0 / 8; []

Type: Integrated Server (map_client.txt)

Is Modded: Definitely; Client brand changed to 'fml,forge'

 

 

what i pull from this is that lines 39 & 21 are erroring on world load.

 

[spoiler=line 21] generateSurface(world, random, chunkX * 16, chunkZ * 16);

 

 

[spoiler=line 39] (new WorldGenMinable(minoriumOre.minoriumOre, 1, 15, Blocks.stone)).generate(world, random, Xcoord, Ycoord, Zcoord);

 

 

The Above Code is borrowed from Wuppy's tutorial for upgrading 1.6 code to 1.7 and has been slightly rejigged, a link to the original can be gathered on request,

 

Again, please don't hurt me

Link to comment
Share on other sites

I'm not 100% sure what's meant by

the line where minoriumOre.minoriumOre is

 

so heres the class, thanks for the pointer with the class files, I'll get to work on changing them

 

[spoiler=minorium ore class]

package mg.Labyrinth;

 

import cpw.mods.fml.common.registry.LanguageRegistry;

import net.minecraft.block.Block;

import net.minecraft.block.material.Material;

import net.minecraft.creativetab.CreativeTabs;

 

public class minoriumOre extends Block {

 

public static final Block minoriumOre = null;

 

protected minoriumOre() {

super(Material.rock);

setHardness(4.0F);

setStepSound(Block.soundTypeStone); // sounds got renamed, look in Block class for what blocks have what sounds

setBlockName("Minorium Ore"); // changed in 1.7

setBlockTextureName("mg:minoriumOre");

setHarvestLevel("pickaxe",2);

setCreativeTab(base.tabLabyrinth);

 

}

}

 

 

 

Link to comment
Share on other sites

Found it.

 

The exception is saying that you are attempting to do SOMETHING (this one was very vague...) on a null variable.

 

public static final Block minoriumOre = null;

 

To fix it you just need to make sure that this variable is initialized. For example:

minoriumOre = new MinoriumOre();

Is this happening somewhere or is this variable remaining null?

Link to comment
Share on other sites

that's happening in the base class file at line 44

 

[spoiler=base]

[...]

   

    @EventHandler

    public void preinit(FMLPreInitializationEvent event)

    {

   

   

    // Blocks

    minoriumOre = new MinoriumOre();

    labyrinthiumOre = new LabyrinthiumOre();

    minoriumBlock = new MinoriumBlock();

    labyrinthiumBlock = new LabyrinthiumBlock();

   

    GameRegistry.registerBlock(minoriumOre, "Minorium Ore");

    GameRegistry.registerBlock(labyrinthiumOre, "Labyrinthium Ore");

    GameRegistry.registerBlock(minoriumBlock,"Minorium Block");

    GameRegistry.registerBlock(labyrinthiumBlock, "Labyrinthium Block");

    [...]

 

 

 

 

the pessimist in me is now saying "You're going to tell me i need to do this in the ore class somewhere"

 

Link to comment
Share on other sites

i take out the static and eclipse gives me error flags in the worldgen class asking me to create a field or constant in MinoriumOre on the following lines

 

[spoiler=error lines]

this.addOreSpawn(MinoriumOre.minoriumOre, world, random, x, z, 16, 16, 4 + random.nextInt(3), 5, 15, 50);

[...]

(new WorldGenMinable(MinoriumOre.minoriumOre, 1, 15, Blocks.stone)).generate(world, random, Xcoord, Ycoord, Zcoord);

 

 

 

when I make either they create static fields in the block class

Link to comment
Share on other sites

In theory the static field can be anywhere. Most often it serves organizational purposes to put them all in the same location.

 

What you need to do is put that static field back in, it shouldn't matter where you put it, and just instantiate the variable. Inside your preInit, init, or postInit you need to make sure you set it to be an instance of itself. For example:

ClassReference.staticVariable = new MinoriumOre()

 

For example, I usually put all my static references in the root class for the mod, as it makes more sense for me to go Labyrinth.minoriumOre rather than MinoriumOre.minoriumOre.

 

Link to comment
Share on other sites

Thank you both for your help

 

There were actually 2 faults which between you, you helped me see,

 

The Static Thing was piggybacked because i was telling world gen to look at the class folder where theres no init details, what i've done to rectify this is point them to the base class

 

Where i had MinoriumOre.MinoriumOre it should have been Base.MinoriumOre,

 

it would also help if I had thethe important "Oregen ore_gen = new Oregen();" style line in there,

 

Thank you both for putting up with me and showing me the light

Link to comment
Share on other sites

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...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

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