List of usage examples for net.minecraftforge.event.entity.player PlayerInteractEvent.RightClickBlock getPos
@Nonnull
public BlockPos getPos()
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;/*from ww w. j a va2s .c o m*/ 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(); World worldObj = event.getWorld(); if (pos == null) { return; }/*from w ww .ja va 2 s . c o m*/ 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.ellpeck.actuallyadditions.mod.blocks.BlockLaserRelay.java
@SubscribeEvent public void onBlockRightClick(PlayerInteractEvent.RightClickBlock event) { EntityPlayer player = event.getEntityPlayer(); World world = event.getWorld();/* ww w.j av a 2 s . com*/ ItemStack stack = event.getItemStack(); BlockPos pos = event.getPos(); if (player != null && world != null && StackUtil.isValid(stack) && pos != null) { IBlockState state = event.getWorld().getBlockState(pos); if (state != null && state.getBlock() instanceof BlockLaserRelay) { if (stack.getItem() instanceof ItemCompass && player.isSneaking()) { event.setUseBlock(Event.Result.ALLOW); } } } }
From source file:de.kitsunealex.projectx.event.BlockEventHandler.java
License:Open Source License
@SubscribeEvent public void handleRightClickBlockEvent(PlayerInteractEvent.RightClickBlock event) { EntityPlayer player = event.getEntityPlayer(); World world = event.getWorld();//from www . j a v a 2 s . c o m ItemStack stack = event.getItemStack(); BlockPos pos = event.getPos(); if (player != null && world != null && !stack.isEmpty()) { IBlockState state = world.getBlockState(pos); for (Block block : BYPASSED_BLOCKS) { if (state.getBlock() == block) { event.setUseBlock(Event.Result.ALLOW); } } } }
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 ww w . java 2s . c o m*/ 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.j a v a 2 s . com*/ 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:hellfirepvp.astralsorcery.common.event.listener.EventHandlerServer.java
License:Open Source License
@SubscribeEvent(priority = EventPriority.LOWEST) public void onRightClickLast(PlayerInteractEvent.RightClickBlock event) { if (!event.getWorld().isRemote) { IBlockState interacted = event.getWorld().getBlockState(event.getPos()); if (interacted.getBlock() instanceof BlockWorkbench) { PktCraftingTableFix fix = new PktCraftingTableFix(event.getPos()); PacketChannel.CHANNEL.sendTo(fix, (EntityPlayerMP) event.getEntityPlayer()); }//w w w . j a v a2 s . com } }
From source file:net.doubledoordev.inventorylock.server.ServerEventHandler.java
License:Open Source License
@SubscribeEvent public void onPlayerInteractRightClickBlock(PlayerInteractEvent.RightClickBlock event) { EntityPlayer player = event.getEntityPlayer(); if (player == null || player instanceof FakePlayer || player.world.isRemote) return;/*w w w .j a va 2s .c o m*/ ItemStack stack = event.getItemStack(); if (stack.isEmpty()) return; NBTTagCompound nbt = stack.getSubCompound(MOD_ID); if (nbt == null) return; event.setCanceled(true); Action action = Action.values()[nbt.getByte(ACTION)]; TileEntity te = event.getWorld().getTileEntity(event.getPos()); if (te == null) return; if (!(te instanceof ILockableContainer)) { Helper.chat(player, "This block is not lockable :(", RED); return; } ILockableContainer lc = ((ILockableContainer) te); Block block = event.getWorld().getBlockState(event.getPos()).getBlock(); if (block instanceof BlockChest) { lc = ((BlockChest) block).getLockableContainer(event.getWorld(), event.getPos()); if (lc == null) lc = (ILockableContainer) te; } LockCode existingLc = lc.getLockCode(); if (action == Action.LOCK) // We want to lock { //noinspection ConstantConditions if (existingLc == null || existingLc.isEmpty()) // There is no lock yet, OK { lc.setLockCode(new BetterLockCode().add(player.getUniqueID())); Helper.chat(player, "Locked!", GREEN); } else Helper.chat(player, "This block is already locked.", RED); return; // End of any LOCK case } // Beyond here the block needs to already be locked, via OUR lock, and the player needs to have access. //noinspection ConstantConditions if (existingLc == null || existingLc.isEmpty()) { Helper.chat(player, "This block is not locked.", RED); return; } if (!(existingLc instanceof BetterLockCode)) { Helper.chat(player, "This block is not locked via " + MOD_ID + ".", RED); return; } BetterLockCode blc = ((BetterLockCode) existingLc); if (action == Action.INSPECT) { printList(player, blc); // Bypass contains check return; } if (!blc.canEdit(player)) { Helper.chat(player, "You do not have access to this block.", RED); return; } // LOCK is already handled. if (action == Action.UNLOCK) // We want to unlock (set back to the EMPTY_CODE singleton) { lc.setLockCode(LockCode.EMPTY_CODE); Helper.chat(player, "Unlocked!", GREEN); return; } else if (action == Action.PUBLIC) // We want to make public (set back to the EMPTY_CODE singleton) { blc.setPublic(!blc.isPublic()); Helper.chat(player, "Chest now " + (blc.isPublic() ? "public!" : "private!"), GREEN); return; } else if (action == Action.ADD) // We want to add uuids { NBTTagList list = nbt.getTagList(UUIDS, TAG_STRING); for (int i = 0; i < list.tagCount(); i++) blc.add(UUID.fromString(list.getStringTagAt(i))); } else if (action == Action.REMOVE) // We want to remove uuids { NBTTagList list = nbt.getTagList(UUIDS, TAG_STRING); for (int i = 0; i < list.tagCount(); i++) { UUID uuid = UUID.fromString(list.getStringTagAt(i)); if (!player.getUniqueID().equals(uuid)) blc.remove(uuid); // Anti self lockout } } // Print this for ADD, REMOVE (LOCK, INSPECT & UNLOCK return early) printList(player, blc); }
From source file:valkyrienwarfare.mod.event.EventsCommon.java
License:Open Source License
@SubscribeEvent public void onRightClick(PlayerInteractEvent.RightClickBlock event) { if (!event.getWorld().isRemote) { PhysicsWrapperEntity physObj = ValkyrienWarfareMod.physicsManager.getObjectManagingPos(event.getWorld(), event.getPos()); if (physObj != null) { if (ValkyrienWarfareMod.runAirshipPermissions && !(physObj.wrapping.creator.equals(event.getEntityPlayer().entityUniqueID.toString()) || physObj.wrapping.allowedUsers .contains(event.getEntityPlayer().entityUniqueID.toString()))) { event.getEntityPlayer()//from w ww. j a va 2s.c om .sendMessage(new TextComponentString("You need to be added to the airship to do that!" + (physObj.wrapping.creator == null || physObj.wrapping.creator.trim().isEmpty() ? " Try using \"/airshipSettings claim\"!" : ""))); event.setCanceled(true); return; } else { event.setResult(Result.ALLOW); event.setCanceled(false); } } } }
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 w w w .j av a2 s. c o 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()); } }