hogepiyo

かつてはマイクラのModを作っていたがひざに矢を受けた

BonemealEventの利用

BonemealEventを使ったModの作成

BonemealEventは追加した苗木を木に成長させたり, 追加した作物を成長させるのに使えるEventである.

土ブロックを草ブロックにするMod

@ForgeSubscribe
public void dirtToGrass(BonemealEvent event) {
    EntityPlayer player = event.entityPlayer;
    World         world = event.world;
    int               x = event.X;
    int               y = event.Y;
    int               z = event.Z;

    if (world.getBlockId(x, y, z) == Block.dirt.blockID) {
        for (int i = -2; i <= 2; ++i) {
            for (int j = -2; j <= 2; ++j) {
                if (world.getBlockId(x + i, y, z + j) == Block.dirt.blockID) {
                    world.setBlockWithNotify(x + i, y, z + j, Block.grass.blockID);
                }
            }
        }
        event.setResult(Event.Result.ALLOW);
    }
    else {
        event.setResult(Event.Result.DENY);
    }
}

骨粉で土ブロックを右クリックすると, 周囲5*5マスの土ブロックも草ブロックにする. 意外と便利かもしれない.