Skip to content

Instantly share code, notes, and snippets.

@matshou
Last active October 27, 2016 07:43
Show Gist options
  • Save matshou/83217050a511e6689cbe9c43f52c1d1d to your computer and use it in GitHub Desktop.
Save matshou/83217050a511e6689cbe9c43f52c1d1d to your computer and use it in GitHub Desktop.
Iron Pickaxe of Inferno
@SubscribeEvent
public static void onBlockLeftClicked(PlayerInteractEvent.LeftClickBlock event)
{
/*
* Tips: Don't worry about World#getBlockState returning null,
* if it does not find anything valid it will just return the default state of AIR.
*/
Random rand = new Random();
ItemStack heldStack = event.getEntityPlayer().getHeldItem(EnumHand.MAIN_HAND);
Block block = event.getWorld().getBlockState(event.getPos()).getBlock();
Item heldItem = heldStack != null ? heldStack.getItem() : null;
if (!event.getWorld().isRemote && block == Blocks.STONE && heldItem == Items.IRON_PICKAXE && rand.nextInt(1) == 0)
{
BlockPos firePos = event.getPos().offset(EnumFacing.UP); // offset this BlockPos 1 block UP
final boolean shouldSetOnFire = rand.nextInt(9) == 0;
if (shouldSetOnFire && (event.getFace() == EnumFacing.UP || event.getWorld().isAirBlock(firePos)))
{
/*
* Use setCanceled as setting event result does nothing in this case.
*/
event.setCanceled(true);
event.getWorld().setBlockState(firePos, Blocks.FIRE.getDefaultState());
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment