Minecraft forge:生成块时的事件

Minecraft forge: event when block is generated

1.7.10 中是否有一个块生成时的事件,所以我可以在上面放置一些东西。还是我必须在一代人之内这样做?

我已经在网上看过了,但找不到

onBlockGenerated

事件或类似的事情。

您需要扩展 WorldGenerator

class Foo extends WorldGenerator {
     protected Block[] GetValidSpawnBlocks() {
      return new Block[] { Blocks.quartz };
   }
    public boolean generate(final World world, final Random rand, final int x, final int y, final int z) {
        world.setBlock(x,y+1,z,FooModBlocks.yourFancyBlock,0,2);
    }
}

并在您的 iworldgenerator 中注册它

public class MagicCookieWorldGen implements IWorldGenerator {
   private Foo myGenerator;
   public MagicCookieWorldGen() {
       super();
       myGenerator = new Foo();
   }
   @Override
    public void generate(Random random, int chunkX, int chunkZ, World world,
            IChunkProvider chunkGenerator, IChunkProvider chunkProvider) {
          this.worldGeneration(random, chunkX, chunkZ, world, true);
    }

    public void worldGeneration(final Random random, final int chunkX, final int chunkZ, final World world, final boolean newGen) {
         switch (world.provider.dimensionId) {
             case -1: {
                 this.generateNether(world, random, chunkX, chunkZ, newGen);
                 break;
             }
             case 1: {
                 break;
             }
             default: {
                 break;
             }
         }

    }
    private void generateNether(final World world, final Random random, final int chunkX, final int chunkZ, final boolean newGen) {
         int startX = chunkX * 16;
         int startZ = chunkZ * 16;
         int startY = 5;
         int endX = startX + 16;
         int endZ = startZ + 16;
         int endY = 65;

         for(int x=startX;x<endX;x++)for(int z=startZ;z<endZ;z++)for(int y = startY;y<endY;y++) {
              Block block = world.getBlock(x,y,z);
              for(Block match : Foo.GetValidSpawnBlocks()) {
                  if(match == block) {
                      Foo.generate(world, final Random random, x, y, z);
                      break;
                  }
              }
         }
    }

}

然后在初始化阶段的commonproxy中

GameRegistry.registerWorldGenerator((IWorldGenerator)(StuffLoader.worldGenerator = new MagicCookieWorldGen()), 0);
        MagicCookie.log.info("Registered worldgenerator" + StuffLoader.worldGenerator);