Skip to content

Instantly share code, notes, and snippets.

@yooksi yooksi/EventHandler.java
Last active Oct 27, 2016

Embed
What would you like to do?
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
You can’t perform that action at this time.