List of usage examples for net.minecraftforge.event.entity.player PlayerInteractEvent.RightClickBlock getHand
@Nonnull
public Hand getHand()
From source file:com.buuz135.industrial.proxy.event.CocoaBeanRightClickHarvesting.java
License:Open Source License
@SubscribeEvent public static void onPlayerRightClick(PlayerInteractEvent.RightClickBlock event) { if (!BlockRegistry.plantInteractorBlock.isRightClickCocoBeansEnabled()) return;/* ww w .j a v a2 s.com*/ if (event.getWorld().isRemote) return; if (event.getHand() != EnumHand.MAIN_HAND) return; if (event.getEntityPlayer() == null) return; IBlockState state = event.getWorld().getBlockState(event.getPos()); if (state.getBlock() instanceof BlockCocoa && state.getValue(BlockCocoa.AGE) == 2) { ItemStack main = event.getEntityPlayer().getHeldItemMainhand(); int fortune = EnchantmentHelper.getEnchantmentLevel(Enchantments.FORTUNE, main); NonNullList<ItemStack> drops = NonNullList.create(); state.getBlock().getDrops(drops, event.getWorld(), event.getPos(), state, fortune); if (drops.size() > 0) { drops.get(0).shrink(1); } ForgeEventFactory.fireBlockHarvesting(drops, event.getWorld(), event.getPos(), state, fortune, 1f, false, event.getEntityPlayer()); event.getWorld().setBlockState(event.getPos(), state.withProperty(BlockCocoa.AGE, 0)); for (ItemStack stack : drops) ItemHandlerHelper.giveItemToPlayer(event.getEntityPlayer(), stack); } }
From source file:com.lothrazar.cyclicmagic.playerupgrade.PlayerAbilitiesModule.java
License:Open Source License
@SubscribeEvent public void onInteract(PlayerInteractEvent.RightClickBlock event) { if (passThroughClick) { EntityPlayer entityPlayer = event.getEntityPlayer(); BlockPos pos = event.getPos();//w w w . ja v a 2s .c o m World worldObj = event.getWorld(); if (pos == null) { return; } if (entityPlayer.isSneaking()) { return; } // ItemStack held = event.getItemStack();// entityPlayer.getHeldItem(event.getHand()); IBlockState state = event.getWorld().getBlockState(pos); //removed && entityPlayer.isSneaking() == false if (state != null && (state.getBlock() == Blocks.WALL_SIGN || state.getBlock() == Blocks.WALL_BANNER)) { // but NOT standing sign or standing banner EnumFacing face = EnumFacing.byIndex(state.getBlock().getMetaFromState(state)); BlockPos posBehind = pos.offset(face.getOpposite()); IBlockState stuffBehind = worldObj.getBlockState(posBehind); if (stuffBehind != null && stuffBehind.getBlock() != null && worldObj.getTileEntity(posBehind) != null) { // then perform the action on that thing (chest/furnace/etc) // a function in base class of block // public boolean onBlockActivated(World worldIn, BlockPos pos, // IBlockState state, EntityPlayer playerIn, EnumHand hand, ItemStack // heldItem, EnumFacing side, float hitX, float hitY, float hitZ) stuffBehind.getBlock().onBlockActivated(worldObj, posBehind, stuffBehind, entityPlayer, event.getHand(), event.getFace(), 0, 0, 0); // stop the normal item thing happening event.setUseItem(net.minecraftforge.fml.common.eventhandler.Event.Result.DENY); } } } }
From source file:de.sanandrew.mods.sanlib.sanplayermodel.event.ItemClickEvent.java
License:Creative Commons License
@SubscribeEvent public void onItemUse(PlayerInteractEvent.RightClickBlock event) { if (event.getItemStack().getItem() instanceof ItemArmorStand && event.getEntity() instanceof EntityPlayer) { EntityPlayer player = (EntityPlayer) event.getEntity(); if (SanPlayerModel.isSanPlayer(player) && !player.isSneaking()) { EnumFacing facing = event.getFace(); if (facing != null && facing != EnumFacing.DOWN) { World world = event.getEntity().world; boolean replaceable = world.getBlockState(event.getPos()).getBlock().isReplaceable(world, event.getPos()); BlockPos pos1 = replaceable ? event.getPos() : event.getPos().offset(facing); ItemStack heldItem = player.getHeldItem(event.getHand()); if (player.canPlayerEdit(pos1, facing, heldItem)) { BlockPos pos2 = pos1.up(); boolean isOccupied = !world.isAirBlock(pos1) && !world.getBlockState(pos1).getBlock().isReplaceable(world, pos1); isOccupied = isOccupied | (!world.isAirBlock(pos2) && !world.getBlockState(pos2).getBlock().isReplaceable(world, pos2)); if (!isOccupied) { double posX = pos1.getX(); double posY = pos1.getY(); double posZ = pos1.getZ(); List<Entity> entities = world.getEntitiesWithinAABBExcludingEntity(null, new AxisAlignedBB(posX, posY, posZ, posX + 1.0D, posY + 2.0D, posZ + 1.0D)); if (entities.isEmpty()) { if (!world.isRemote) { world.setBlockToAir(pos1); world.setBlockToAir(pos2); EntitySanArmorStand stand = new EntitySanArmorStand(world, posX + 0.5D, posY, posZ + 0.5D); float rotation = (float) MathHelper.floor( (MathHelper.wrapDegrees(player.rotationYaw - 180.0F) + 22.5F) / 45.0F) * 45.0F; stand.setLocationAndAngles(posX + 0.5D, posY, posZ + 0.5D, rotation, 0.0F); doRandomRotations(stand); ItemMonsterPlacer.applyItemEntityDataToEntity(world, player, heldItem, stand); world.spawnEntity(stand); world.playSound(null, stand.posX, stand.posY, stand.posZ, SoundEvents.ENTITY_ARMORSTAND_PLACE, SoundCategory.BLOCKS, 0.75F, 0.8F); }//from w w w .jav a 2 s .c om heldItem.shrink(1); event.setCanceled(true); } } } } } } }
From source file:hellfirepvp.astralsorcery.common.event.listener.EventHandlerServer.java
License:Open Source License
@SubscribeEvent public void onRightClick(PlayerInteractEvent.RightClickBlock event) { ItemStack hand = event.getItemStack(); if (event.getHand() == EnumHand.OFF_HAND) { hand = event.getEntityPlayer().getHeldItem(EnumHand.MAIN_HAND); }/* w w w . ja va 2s . co m*/ if (hand.isEmpty()) return; if (hand.getItem() instanceof ISpecialInteractItem) { ISpecialInteractItem i = (ISpecialInteractItem) hand.getItem(); if (i.needsSpecialHandling(event.getWorld(), event.getPos(), event.getEntityPlayer(), hand)) { i.onRightClick(event.getWorld(), event.getPos(), event.getEntityPlayer(), event.getFace(), event.getHand(), hand); event.setCanceled(true); } } }
From source file:vazkii.quark.decoration.feature.FlatItemFrames.java
License:Creative Commons License
@SubscribeEvent public void onPlayerInteract(PlayerInteractEvent.RightClickBlock event) { if (event.getFace() == null) return;//from ww w . j a va2 s . co m ItemStack itemstack = event.getItemStack(); EnumFacing facing = event.getFace(); BlockPos blockpos = event.getPos().offset(facing); World world = event.getWorld(); EntityPlayer player = event.getEntityPlayer(); if (!player.canPlayerEdit(blockpos, facing, itemstack) || facing.getAxis() != EnumFacing.Axis.Y || itemstack.getItem() != Items.ITEM_FRAME) return; EntityHanging entityhanging = new EntityFlatItemFrame(world, blockpos, facing); if (entityhanging != null && entityhanging.onValidSurface()) { if (!event.getWorld().isRemote) { entityhanging.playPlaceSound(); world.spawnEntity(entityhanging); event.setCanceled(true); if (!player.capabilities.isCreativeMode) itemstack.shrink(1); } else player.swingArm(event.getHand()); } }
From source file:vazkii.quark.tweaks.feature.DeployLaddersDown.java
License:Creative Commons License
@SubscribeEvent public void onInteract(PlayerInteractEvent.RightClickBlock event) { EntityPlayer player = event.getEntityPlayer(); EnumHand hand = event.getHand(); ItemStack stack = player.getHeldItem(hand); List<Item> items = new ArrayList(); items.add(Item.getItemFromBlock(Blocks.LADDER)); if (ModuleLoader.isFeatureEnabled(IronLadders.class)) items.add(Item.getItemFromBlock(IronLadders.iron_ladder)); if (!stack.isEmpty() && items.contains(stack.getItem())) { Block block = Block.getBlockFromItem(stack.getItem()); World world = event.getWorld();/*from w ww . j a v a 2s . co m*/ BlockPos pos = event.getPos(); while (world.getBlockState(pos).getBlock() == block) { BlockPos posDown = pos.down(); IBlockState stateDown = world.getBlockState(posDown); if (stateDown.getBlock() == block) pos = posDown; else { if (stateDown.getBlock().isAir(stateDown, world, posDown)) { IBlockState copyState = world.getBlockState(pos); EnumFacing facing = copyState.getValue(BlockLadder.FACING); if (block.canPlaceBlockOnSide(world, posDown, facing)) { world.setBlockState(posDown, copyState); world.playSound(null, posDown.getX(), posDown.getY(), posDown.getZ(), Blocks.LADDER.getSoundType().getPlaceSound(), SoundCategory.BLOCKS, 1F, 1F); event.setCanceled(true); if (world.isRemote) player.swingArm(hand); if (!player.capabilities.isCreativeMode) { stack.shrink(1); if (stack.getCount() <= 0) player.setHeldItem(hand, ItemStack.EMPTY); } } } break; } } } }
From source file:vazkii.quark.tweaks.feature.RemoveSnowLayers.java
License:Creative Commons License
@SubscribeEvent public void onPlayerRightClick(PlayerInteractEvent.RightClickBlock event) { if (event.getFace() != EnumFacing.UP) return;//from w w w .j av a2s.co m World world = event.getWorld(); BlockPos pos = event.getPos(); EntityPlayer player = event.getEntityPlayer(); IBlockState state = world.getBlockState(pos); if (state.getBlock() != Blocks.SNOW_LAYER && state.getBlock() != Blocks.SNOW) return; ItemStack stack = event.getEntityPlayer().getHeldItem(event.getHand()); if (!stack.isEmpty() && stack.getItem() instanceof ItemSpade) { if (state.getBlock() == Blocks.SNOW) world.setBlockState(pos, Blocks.SNOW_LAYER.getDefaultState().withProperty(BlockSnow.LAYERS, 7)); else { int layers = state.getValue(BlockSnow.LAYERS); if (layers == 1) world.setBlockToAir(pos); else world.setBlockState(pos, state.withProperty(BlockSnow.LAYERS, layers - 1)); } world.playSound(event.getEntityPlayer(), pos, SoundEvents.ITEM_SHOVEL_FLATTEN, SoundCategory.BLOCKS, 1.0F, 1.0F); stack.damageItem(1, event.getEntityPlayer()); player.swingArm(event.getHand()); event.setCanceled(true); } }