1.7.10中是否存在生成块的事件,因此我可以在其上面放置一些东西。或者我必须在这一代内做到这一点?
我已经在网上看了但是我找不到
onBlockGenerated
事件或类似事件。
答案 0 :(得分:1)
您需要扩展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;
}
}
}
}
}
然后在init阶段的commonproxy中
GameRegistry.registerWorldGenerator((IWorldGenerator)(StuffLoader.worldGenerator = new MagicCookieWorldGen()), 0);
MagicCookie.log.info("Registered worldgenerator" + StuffLoader.worldGenerator);