Jump to content

Recommended Posts

Posted

Hey, It's me again and I have another question about storing things. Since my generated structure is spawned rarely, I want to make a command that will print out known locations of the structure. I figured out I have to save the coordinates when generating the structure. I think the MapStorage would be best to use, but I can't figure out how it works. These are my classes:

Data I'm Saving

 

public class CollectiblesWorldData extends WorldSavedData{

    private static final String identifier = Constants.MODID;

    public static int[] x;
    public static int[] y;
    public static int[] z;


    public  int getX(int i) {
        return x[i];
    }

    public  int getY(int i) {
        return y[i];
    }

    public  int getZ(int i) {
        return z[i];
    }

    public CollectiblesWorldData() {
        super(identifier);
    }

    public CollectiblesWorldData(String IDENTIFIER) {
        super(IDENTIFIER);
    }


    public void setBaseStructureCoords(int newx,int newy,int newz,int structureNumber){
        x[structureNumber-1] = newx;
        y[structureNumber-1] = newy;
        z[structureNumber-1] = newz;
        markDirty();
    }

    @Override
    public void readFromNBT(NBTTagCompound nbt) {
        x=nbt.getIntArray("x");
        y=nbt.getIntArray("y");
        z=nbt.getIntArray("z");
    }

    @Override
    public void writeToNBT(NBTTagCompound nbt) {
        nbt.setIntArray("x",x);
        nbt.setIntArray("y",y);
        nbt.setIntArray("z",z);
    }
}

 

Part of the code where I edit the data and the save it:

 

public class WorldGenBaseStructure {
    static Configuration config = new Configuration(Collectibles.configfile);
    private static int i = 1;
    static CollectiblesWorldData cwd = new CollectiblesWorldData();                            //<------HERE
    public static void generate(World world, Random random, int x, int y, int z) {

        config.load();
        if (world.getBlock(x, y, z) == Blocks.grass || world.getBlock(x, y, z) == Blocks.sand || world.getBlock(x, y, z) == Blocks.dirt || world.getBlock(x, y, z) == Blocks.gravel) {
            if (world.getBlock(x, y, z + 9) == Blocks.grass || world.getBlock(x, y, z + 9) == Blocks.sand || world.getBlock(x, y, z + 9) == Blocks.dirt || world.getBlock(x, y, z + 9) == Blocks.gravel) {
                if (world.getBlock(x + 9, y, z) == Blocks.grass || world.getBlock(x + 9, y, z) == Blocks.sand || world.getBlock(x + 9, y, z) == Blocks.dirt || world.getBlock(x + 9, y, z) == Blocks.gravel) {
                    if (world.getBlock(x + 9, y, z + 9) == Blocks.grass || world.getBlock(x + 9, y, z + 9) == Blocks.sand || world.getBlock(x + 9, y, z + 9) == Blocks.dirt || world.getBlock(x + 9, y, z + 9) == Blocks.gravel) {
                    }
                }
                //System.out.println("Found suitable space on " + x + ", " + y + ", " + z);
                if ((!config.hasKey(config.CATEGORY_GENERAL, "generated3In_" + world.getWorldInfo().getWorldName()))) {         //||(world.getBlock(x+3,y+1,z) != Blocks.stonebrick)
                    System.out.println("Generating on " + x + ", " + y + ", " + z);
                    cwd.setBaseStructureCoords(x, y, z, i);                                                //<------HERE
                    world.mapStorage.setData(Constants.MODID,cwd);                            //<------HERE
                    config.get(config.CATEGORY_GENERAL, "generated" + i + "In_" + world.getWorldInfo().getWorldName(), true);
                    config.save();
                    i++;

 

My processCommand method:

 

@Override
    public void processCommand(ICommandSender sender, String[] args) {
    if (args.length == 1){
        if (sender instanceof EntityPlayer){

                CollectiblesWorldData savedData = new CollectiblesWorldData();
                savedData = (CollectiblesWorldData) sender.getEntityWorld().mapStorage.loadData(CollectiblesWorldData.class, Constants.MODID);
                EntityPlayer player = (EntityPlayer) sender;
                int x = (int)savedData.getX(Integer.parseInt(args[0]));
                int y = (int)savedData.getY(Integer.parseInt(args[0]));
                int z = (int)savedData.getZ(Integer.parseInt(args[0]));
                player.addChatMessage(new ChatComponentText(Integer.toString(x)));

                player.addChatMessage(new ChatComponentText(Integer.toString(y)));

                player.addChatMessage(new ChatComponentText(Integer.toString(z)));
            }
        }
        else{
        sender.addChatMessage(new ChatComponentText("§cYou have typed this command wrong! Use §2/help srl"));
    }
    }

 

 

And This is the error I get (It crashes always when the structure should be generated):

 

[23:27:55] [Client thread/INFO]: [CHAT] ForgeDevName has just earned the achievement [Taking Inventory]
Generating on 1988, 63, -324
[23:28:49] [server thread/ERROR]: Encountered an unexpected exception
net.minecraft.util.ReportedException: Exception ticking world
at net.minecraft.server.MinecraftServer.updateTimeLightAndEntities(MinecraftServer.java:708) ~[MinecraftServer.class:?]
at net.minecraft.server.MinecraftServer.tick(MinecraftServer.java:624) ~[MinecraftServer.class:?]
at net.minecraft.server.integrated.IntegratedServer.tick(IntegratedServer.java:118) ~[integratedServer.class:?]
at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:495) [MinecraftServer.class:?]
at net.minecraft.server.MinecraftServer$2.run(MinecraftServer.java:762) [MinecraftServer$2.class:?]
Caused by: java.lang.NullPointerException
at com.xenonlabs.collectibles.lib.CollectiblesWorldData.setBaseStructureCoords(CollectiblesWorldData.java:56) ~[CollectiblesWorldData.class:?]
at com.xenonlabs.collectibles.generation.WorldGenBaseStructure.generate(WorldGenBaseStructure.java:35) ~[WorldGenBaseStructure.class:?]
at com.xenonlabs.collectibles.generation.CollWorldGenerator.generateInOverworld(CollWorldGenerator.java:48) ~[CollWorldGenerator.class:?]
at com.xenonlabs.collectibles.generation.CollWorldGenerator.generate(CollWorldGenerator.java:27) ~[CollWorldGenerator.class:?]
at cpw.mods.fml.common.registry.GameRegistry.generateWorld(GameRegistry.java:106) ~[GameRegistry.class:?]
at net.minecraft.world.gen.ChunkProviderServer.populate(ChunkProviderServer.java:316) ~[ChunkProviderServer.class:?]
at net.minecraft.world.chunk.Chunk.populateChunk(Chunk.java:1153) ~[Chunk.class:?]
at net.minecraft.world.gen.ChunkProviderServer.originalLoadChunk(ChunkProviderServer.java:210) ~[ChunkProviderServer.class:?]
at net.minecraft.world.gen.ChunkProviderServer.loadChunk(ChunkProviderServer.java:151) ~[ChunkProviderServer.class:?]
at net.minecraft.world.gen.ChunkProviderServer.loadChunk(ChunkProviderServer.java:121) ~[ChunkProviderServer.class:?]
at net.minecraft.world.gen.ChunkProviderServer.provideChunk(ChunkProviderServer.java:223) ~[ChunkProviderServer.class:?]
at net.minecraft.world.World.getChunkFromChunkCoords(World.java:485) ~[World.class:?]
at net.minecraft.world.SpawnerAnimals.func_151350_a(SpawnerAnimals.java:33) ~[spawnerAnimals.class:?]
at net.minecraft.world.SpawnerAnimals.findChunksForSpawning(SpawnerAnimals.java:105) ~[spawnerAnimals.class:?]
at net.minecraft.world.WorldServer.tick(WorldServer.java:171) ~[WorldServer.class:?]
at net.minecraft.server.MinecraftServer.updateTimeLightAndEntities(MinecraftServer.java:702) ~[MinecraftServer.class:?]
... 4 more
[23:28:49] [server thread/ERROR]: This crash report has been saved to: C:\MCModding\TheCollectibles - 1.7.10\eclipse\.\crash-reports\crash-2014-08-30_23.28.49-server.txt
[23:28:49] [server thread/INFO]: Stopping server
[23:28:49] [server thread/INFO]: Saving players
---- Minecraft Crash Report ----
// You're mean.

Time: 30.8.14 23:28
Description: Exception ticking world

java.lang.NullPointerException: Exception ticking world
at com.xenonlabs.collectibles.lib.CollectiblesWorldData.setBaseStructureCoords(CollectiblesWorldData.java:56)
at com.xenonlabs.collectibles.generation.WorldGenBaseStructure.generate(WorldGenBaseStructure.java:35)
at com.xenonlabs.collectibles.generation.CollWorldGenerator.generateInOverworld(CollWorldGenerator.java:48)
at com.xenonlabs.collectibles.generation.CollWorldGenerator.generate(CollWorldGenerator.java:27)
at cpw.mods.fml.common.registry.GameRegistry.generateWorld(GameRegistry.java:106)
at net.minecraft.world.gen.ChunkProviderServer.populate(ChunkProviderServer.java:316)
at net.minecraft.world.chunk.Chunk.populateChunk(Chunk.java:1153)
at net.minecraft.world.gen.ChunkProviderServer.originalLoadChunk(ChunkProviderServer.java:210)
at net.minecraft.world.gen.ChunkProviderServer.loadChunk(ChunkProviderServer.java:151)
at net.minecraft.world.gen.ChunkProviderServer.loadChunk(ChunkProviderServer.java:121)
at net.minecraft.world.gen.ChunkProviderServer.provideChunk(ChunkProviderServer.java:223)
at net.minecraft.world.World.getChunkFromChunkCoords(World.java:485)
at net.minecraft.world.SpawnerAnimals.func_151350_a(SpawnerAnimals.java:33)
at net.minecraft.world.SpawnerAnimals.findChunksForSpawning(SpawnerAnimals.java:105)
at net.minecraft.world.WorldServer.tick(WorldServer.java:171)
at net.minecraft.server.MinecraftServer.updateTimeLightAndEntities(MinecraftServer.java:702)
at net.minecraft.server.MinecraftServer.tick(MinecraftServer.java:624)
at net.minecraft.server.integrated.IntegratedServer.tick(IntegratedServer.java:118)
at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:495)
at net.minecraft.server.MinecraftServer$2.run(MinecraftServer.java:762)


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

-- Head --
Stacktrace:
at com.xenonlabs.collectibles.lib.CollectiblesWorldData.setBaseStructureCoords(CollectiblesWorldData.java:56)
at com.xenonlabs.collectibles.generation.WorldGenBaseStructure.generate(WorldGenBaseStructure.java:35)
at com.xenonlabs.collectibles.generation.CollWorldGenerator.generateInOverworld(CollWorldGenerator.java:48)
at com.xenonlabs.collectibles.generation.CollWorldGenerator.generate(CollWorldGenerator.java:27)
at cpw.mods.fml.common.registry.GameRegistry.generateWorld(GameRegistry.java:106)
at net.minecraft.world.gen.ChunkProviderServer.populate(ChunkProviderServer.java:316)
at net.minecraft.world.chunk.Chunk.populateChunk(Chunk.java:1153)
at net.minecraft.world.gen.ChunkProviderServer.originalLoadChunk(ChunkProviderServer.java:210)
at net.minecraft.world.gen.ChunkProviderServer.loadChunk(ChunkProviderServer.java:151)
at net.minecraft.world.gen.ChunkProviderServer.loadChunk(ChunkProviderServer.java:121)
at net.minecraft.world.gen.ChunkProviderServer.provideChunk(ChunkProviderServer.java:223)
at net.minecraft.world.World.getChunkFromChunkCoords(World.java:485)
at net.minecraft.world.SpawnerAnimals.func_151350_a(SpawnerAnimals.java:33)
at net.minecraft.world.SpawnerAnimals.findChunksForSpawning(SpawnerAnimals.java:105)
at net.minecraft.world.WorldServer.tick(WorldServer.java:171)

-- Affected level --
Details:
Level name: WorldGen11
All players: 1 total; [EntityPlayerMP['ForgeDevName'/43707, l='WorldGen11', x=1907,84, y=80,51, z=-233,93]]
Chunk stats: ServerChunkCache: 629 Drop: 0
Level seed: 7081004375242392805
Level generator: ID 00 - default, ver 1. Features enabled: true
Level generator options: 
Level spawn location: World: (1259,64,-233), Chunk: (at 11,4,7 in 78,-15; contains blocks 1248,0,-240 to 1263,255,-225), Region: (2,-1; contains chunks 64,-32 to 95,-1, blocks 1024,0,-512 to 1535,255,-1)
Level time: 1600 game time, 1600 day time
Level dimension: 0
Level storage version: 0x04ABD - Anvil
Level weather: Rain time: 141751 (now: false), thunder time: 70467 (now: false)
Level game mode: Game mode: creative (ID 1). Hardcore: false. Cheats: true
Stacktrace:
at net.minecraft.server.MinecraftServer.updateTimeLightAndEntities(MinecraftServer.java:702)
at net.minecraft.server.MinecraftServer.tick(MinecraftServer.java:624)
at net.minecraft.server.integrated.IntegratedServer.tick(IntegratedServer.java:118)
at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:495)
at net.minecraft.server.MinecraftServer$2.run(MinecraftServer.java:762)

-- System Details --
Details:
Minecraft Version: 1.7.10
Operating System: Windows 7 (amd64) version 6.1
Java Version: 1.7.0_45, Oracle Corporation
Java VM Version: Java HotSpot(TM) 64-Bit Server VM (mixed mode), Oracle Corporation
Memory: 537474264 bytes (512 MB) / 1038876672 bytes (990 MB) up to 1038876672 bytes (990 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.18.1180 Minecraft Forge 10.13.0.1180 4 mods loaded, 4 mods active
mcp{9.05} [Minecraft Coder Pack] (minecraft.jar) Unloaded->Constructed->Pre-initialized->Initialized->Post-initialized->Available->Available->Available->Available->Available->Available->Available->Available->Available
FML{7.10.18.1180} [Forge Mod Loader] (forgeSrc-1.7.10-10.13.0.1180.jar) Unloaded->Constructed->Pre-initialized->Initialized->Post-initialized->Available->Available->Available->Available->Available->Available->Available->Available->Available
Forge{10.13.0.1180} [Minecraft Forge] (forgeSrc-1.7.10-10.13.0.1180.jar) Unloaded->Constructed->Pre-initialized->Initialized->Post-initialized->Available->Available->Available->Available->Available->Available->Available->Available->Available
collectibles{0.1.0} [The Collectibles] (main) Unloaded->Constructed->Pre-initialized->Initialized->Post-initialized->Available->Available->Available->Available->Available->Available->Available->Available->Available
Profiler Position: N/A (disabled)
Vec3 Pool Size: 0 (0 bytes; 0 MB) allocated, 0 (0 bytes; 0 MB) used
Player Count: 1 / 8; [EntityPlayerMP['ForgeDevName'/43707, l='WorldGen11', x=1907,84, y=80,51, z=-233,93]]
Type: Integrated Server (map_client.txt)
Is Modded: Definitely; Client brand changed to 'fml,forge'
#@!@# Game crashed! Crash report saved to: #@!@# .\crash-reports\crash-2014-08-30_23.28.49-server.txt
[23:28:49] [Client thread/INFO] [FML]: Waiting for the server to terminate/save.
[23:28:49] [server thread/INFO]: Saving worlds
[23:28:49] [server thread/INFO]: Saving chunks for level 'WorldGen11'/Overworld
[23:28:50] [server thread/INFO]: Saving chunks for level 'WorldGen11'/Nether
[23:28:50] [server thread/INFO]: Saving chunks for level 'WorldGen11'/The End
[23:28:50] [server thread/INFO] [FML]: Unloading dimension 0
[23:28:50] [server thread/INFO] [FML]: Unloading dimension -1
[23:28:50] [server thread/INFO] [FML]: Unloading dimension 1
[23:28:50] [server thread/INFO] [FML]: Applying holder lookups
[23:28:50] [server thread/INFO] [FML]: Holder lookups applied
[23:28:50] [server thread/INFO] [FML]: The state engine was in incorrect state SERVER_STOPPING and forced into state SERVER_STOPPED. Errors may have been discarded.
[23:28:50] [Client thread/INFO] [FML]: Server terminated.
AL lib: (EE) alc_cleanup: 1 device not closed

Process finished with exit code -1

 

Guest
This topic is now closed to further replies.

Announcements



×
×
  • Create New...

Important Information

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