Hacky village generation is broken. Help!

Discussion in 'Plugin Development' started by rymate1234, Feb 13, 2012.

Thread Status:
Not open for further replies.
  1. Offline

    rymate1234

    Ok, I've been working on my custom wgen, and I've been trying to generate NPC villages. My problem is that the WorldGenVillage requires a net.minecraft.server.world. I've tried to do casting, but i got this error:
    Here is my code
    Code:
    /*
    * To change this template, choose Tools | Templates
    * and open the template in the editor.
    */
    package me.rymate.WorldGen;
     
    import java.util.Random;
    import net.minecraft.server.WorldGenVillage;
    import org.bukkit.*;
    import org.bukkit.block.Biome;
    import org.bukkit.craftbukkit.CraftWorld;
    import org.bukkit.generator.BlockPopulator;
     
    /**
    *
    * @author rymate
    */
    public class VillagePopulator extends BlockPopulator {
     
        @Override
        public void populate(World world, Random random, Chunk chunk) {
            int centerX = (chunk.getX() << 4) + random.nextInt(16);
            int centerZ = (chunk.getZ() << 4) + random.nextInt(16);
     
            Biome b = world.getBlockAt(centerX, 0, centerZ).getBiome();
     
            for (int i = 0; i < 8; i++) {
                int r = random.nextInt(1000);
                int x = random.nextInt(16) + chunk.getX() * 16;
                int z = random.nextInt(16) + chunk.getZ() * 16;
     
                if (r < 5) {
                    World worldcraft = (CraftWorld) world;
                    net.minecraft.server.World worldy = (net.minecraft.server.World) worldcraft;
                   
                    WorldGenVillage a = new WorldGenVillage(10);
                    a.a(worldy, random, centerX, centerZ);
                }
            }
        }
    }
    
    Any help appreciated :)
     
  2. Offline

    nisovin

    Use .getHandle() on a CraftWorld.
     
  3. Offline

    rymate1234

    Thanks :D

    This is probably gonna generate a lot of npc villages XD
     
  4. Offline

    user_43347

    Hey, if you ever finish this plugin, mind sending me the source? :p
     
  5. Offline

    rymate1234

    Ok, no more errors, but no villages generated either :(

    Here is my code as it stands :)
    Code:
    /*
    * To change this template, choose Tools | Templates
    * and open the template in the editor.
    */
    package me.rymate.WorldGen;
     
    import java.util.Random;
    import net.minecraft.server.WorldGenVillage;
    import org.bukkit.*;
    import org.bukkit.block.Biome;
    import org.bukkit.craftbukkit.CraftWorld;
    import org.bukkit.generator.BlockPopulator;
     
    /**
    *
    * @author rymate
    */
    public class VillagePopulator extends BlockPopulator {
     
        @Override
        public void populate(World world, Random random, Chunk chunk) {
            for (int i = 0; i < 8; i++) {
                int r = random.nextInt(1000);
                int x = random.nextInt(16) + chunk.getX() * 16;
                int z = random.nextInt(16) + chunk.getZ() * 16;
     
                if (r < 500) {
                    CraftWorld worldcraft = (CraftWorld) world;
                    net.minecraft.server.World worldy = (net.minecraft.server.World) worldcraft.getHandle();
                   
                    WorldGenVillage a = new WorldGenVillage(10);
                    a.a(worldy, random, x, z);
                }
            }
        }
    }
    
     
  6. WorldGenVillage.a is an protected methode
    You need to do something whit WorldGenVillage.b to generate it, WorldGenVillage.a is the code to check if it can be placed.
     
  7. Offline

    rymate1234

    Can you give me an example? Not too good with this obfuscated code (mainly the figuring out what to do bit :))

    Edit - It seems there are 3 a methods, but no b method, seen by netbeans. GAH D:
     
  8. Offline

    BloodShura

  9. I decompiled WorldGenVillage whit me netbans (bukkit recommend build r4) and saw 2 methodes, and 1 constructor
     
Thread Status:
Not open for further replies.

Share This Page