UseHoeEventの利用
UseHoeEventを使ったModの作成
UseHoeEventはプレイヤーがクワを使ったときに呼ばれるEvent. 利用方法がだいぶ限定されている気はするが, やはりアイデア次第.
ダイヤクワのみ範囲耕作になるMod
今回はForgeSubscribe以下のメソッドのみ. 前回のPlayerSleepInBedEventに張り付ければ動く.
@ForgeSubscribe public void doMultiCultivate(UseHoeEvent event) { EntityPlayer player = event.entityPlayer; World world = player.worldObj; int x = event.x; int y = event.y; int z = event.z; if (event.current.itemID == Item.hoeDiamond.itemID) { for (int i = -1; i <= 1; ++i) { for (int j = -1; j <= 1; ++j) { if (world.getBlockId(x + i, y, z + j) == Block.dirt.blockID || world.getBlockId(x + i, y, z + j) == Block.grass.blockID) { world.setBlockWithNotify(x + i, y, z + j, Block.tilledField.blockID); } } } event.setResult(Event.Result.ALLOW); } }
単純に, クワで右クリックしたブロックの周囲8マスが土/草ブロックの場合, 農地に置換してるだけ.