Java 类net.minecraftforge.event.entity.player.PlayerInteractEvent 实例源码

项目:rezolve    文件:SecurityAccessController.java   
@SubscribeEvent
public void handleBlockRightClick(PlayerInteractEvent.RightClickBlock evt) {

    TileEntity entity = evt.getEntityPlayer().getEntityWorld().getTileEntity(evt.getPos());
    SecurityServerEntity securityServer;

    if (entity instanceof SecurityServerEntity) {
        securityServer = (SecurityServerEntity)entity;
        if (!securityServer.canPlayerOpen(evt.getEntityPlayer())) {
            evt.setCanceled(true);
        }

        return;
    }

    CableNetwork network = new CableNetwork(evt.getEntityPlayer().getEntityWorld(), evt.getPos(), RezolveMod.ETHERNET_CABLE_BLOCK);
    securityServer = network.getSecurityServer();

    if (securityServer != null) {
        if (!securityServer.canPlayerUse(evt.getEntityPlayer(), evt.getPos())) {
            evt.setCanceled(true);
        }
    }
}
项目:MineCamera    文件:EventLoader.java   
@SubscribeEvent
public void playerInteract(PlayerInteractEvent event) {
    // System.out.println(event.toString());
    // System.out.println("PlayerInteractEvent,HandType="+event.getHand()+",PlayerAciveHand="+event.getEntityPlayer().getActiveHand());
    if (event.isCancelable() && event.getEntityPlayer().getEntityData().hasKey("renderViewCamera")) {
        event.setCanceled(true);
        return;
    }
    /*
     * if(event instanceof
     * PlayerInteractEvent.EntityInteract&&((PlayerInteractEvent.
     * EntityInteract) event).getTarget() instanceof EntityTripod){ Entity
     * target=((PlayerInteractEvent.EntityInteract) event).getTarget();
     * EntityPlayer player =event.getEntityPlayer(); if
     * (!player.isSneaking()) { if (player.getEntityWorld().isRemote) {
     * System.out.println("123");
     * Minecraft.getMinecraft().setRenderViewEntity(target); }
     * player.getEntityData().setInteger("renderViewCamera",
     * target.getEntityId()); }else{
     * player.getEntityData().setInteger("usingGui", target.getEntityId());
     * player.openGui(MineCamera.instance,
     * GuiElementLoader.GUI_TRIPOD_CAMERA, target.getEntityWorld(),
     * (int)target.posX, (int)target.posY, (int)target.posZ); } }
     */
}
项目:pnc-repressurized    文件:CoordTrackUpgradeHandler.java   
@SubscribeEvent
public boolean onPlayerInteract(PlayerInteractEvent.RightClickBlock event) {
    if (isListeningToCoordTrackerSetting) {
        isListeningToCoordTrackerSetting = false;
        EnumFacing dir = event.getFace();
        reset();
        ItemStack stack = event.getEntityPlayer().getItemStackFromSlot(EntityEquipmentSlot.HEAD);
        if (!stack.isEmpty()) {
            NBTTagCompound tag = NBTUtil.getCompoundTag(stack, "CoordTracker");
            tag.setInteger("dimID", event.getEntity().world.provider.getDimension());
            NBTUtil.setPos(tag, event.getPos().offset(dir));
        }
        assert dir != null;
        NetworkHandler.sendToServer(new PacketCoordTrackUpdate(event.getEntity().world, event.getPos().offset(dir)));
    }
    return false;
}
项目:pnc-repressurized    文件:TileEntityUniversalSensor.java   
public void onEvent(Event event) {
    ISensorSetting sensor = SensorHandler.getInstance().getSensorFromPath(sensorSetting);
    if (sensor != null && sensor instanceof IEventSensorSetting && getPressure() > PneumaticValues.MIN_PRESSURE_UNIVERSAL_SENSOR) {
        int newRedstoneStrength = ((IEventSensorSetting) sensor).emitRedstoneOnEvent(event, this, getRange(), sensorGuiText);
        if (newRedstoneStrength != 0) eventTimer = ((IEventSensorSetting) sensor).getRedstonePulseLength();
        if (invertedRedstone) newRedstoneStrength = 15 - newRedstoneStrength;
        if (eventTimer > 0 && ThirdPartyManager.computerCraftLoaded) {
            if (event instanceof PlayerInteractEvent) {
                PlayerInteractEvent e = (PlayerInteractEvent) event;
                notifyComputers(newRedstoneStrength, e.getPos().getX(), e.getPos().getY(), e.getPos().getZ());
            } else {
                notifyComputers(newRedstoneStrength);
            }
        }
        if (newRedstoneStrength != redstoneStrength) {
            redstoneStrength = newRedstoneStrength;
            updateNeighbours();
        }
    }
}
项目:pnc-repressurized    文件:SemiBlockManager.java   
@SubscribeEvent
public void onInteraction(PlayerInteractEvent.RightClickBlock event) {
    ItemStack curItem = event.getEntityPlayer().getHeldItemMainhand();
    if (!event.getWorld().isRemote && event.getHand() == EnumHand.MAIN_HAND) {
        if (curItem.getItem() instanceof ISemiBlockItem) {
            boolean success = interact(event, curItem, event.getPos());

            //If the block can't be placed in the pos, then try to place it next to the block.
            if(!success && event.getFace() != null)
                success = interact(event, curItem, event.getPos().offset(event.getFace()));

            if(success) event.setCanceled(true);
        }
    } else if (event.getWorld().isRemote && curItem.getItem() instanceof ISemiBlockItem) {
        event.setCancellationResult(EnumActionResult.SUCCESS);
        event.setCanceled(true);
    }
}
项目:HardVox    文件:SelectionListener.java   
private void dueProcess(PlayerInteractEvent event, BiFunction<RegionSelector<?, ?>, Vector3i, String> selector) {
    if (event.getWorld().isRemote) {
        // don't process on client
        // perhaps we can cancel on client if we do config sync
        return;
    }

    if (event.getItemStack().getItem() == HardVoxConfig.getSelectionWand()) {
        // cancel event, fire selection
        event.setCanceled(true);

        WorldServer ws = (WorldServer) event.getWorld();
        SessionManager.getInstance()
                .getSession(ws.getMinecraftServer(), event.getEntityPlayer())
                .performRegionCommand(sel -> selector.apply(sel, VecBridge.toFlow(event.getPos())));
        // send an update to the player so the block re-appears?
        ws.getPlayerChunkMap().markBlockForUpdate(event.getPos());
    }
}
项目:RunicArcana    文件:ScriptActivationEventHandler.java   
@SubscribeEvent
public void rightClickEvent(PlayerInteractEvent.RightClickItem e)
{
    EntityPlayer player = e.getEntityPlayer();
    ItemStack RunicItem = null;
    if(EnchantmentHelper.getEnchantmentLevel(ModEnchantment.runicenchantment, player.getHeldItem(EnumHand.MAIN_HAND) )>0)
        RunicItem = player.getHeldItem(EnumHand.MAIN_HAND);
    else if(EnchantmentHelper.getEnchantmentLevel(ModEnchantment.runicenchantment, player.getHeldItem(EnumHand.OFF_HAND) )>0)
        RunicItem = player.getHeldItem(EnumHand.OFF_HAND);
    else return;

    CompiledSymbol[] script = ModDust.getScriptFromItem(RunicItem);
    if(script==null)return;

    if(player.isSneaking())
        new ScriptExecutor(script, player, RunicItem, ScriptExecutor.StartPoint.SNEAK_RIGHT);
    else
        new ScriptExecutor(script, player, RunicItem, ScriptExecutor.StartPoint.RIGHT_CLICK);

}
项目:BetterThanWeagles    文件:EventHandlerShears.java   
@SubscribeEvent
public static void animalsSheared(PlayerInteractEvent.EntityInteract event)
{
    Entity target = event.getTarget();
    if (target instanceof EntityMooshroom && !target.isDead && ((EntityMooshroom) target).hurtTime == 0)
    {
        if (isUsingShears(event.getEntityPlayer()))
        {
            World world = event.getWorld();
            if (!world.isRemote)
            {
                EntityItem item = new EntityItem(event.getEntity().getEntityWorld(), target.posX, target.posY, target.posZ, new ItemStack(ModItems.meatshroom));
                world.spawnEntity(item);
            }
        }
    }
}
项目:CharcoalPit    文件:PileIgnitr.java   
@SubscribeEvent(priority=EventPriority.HIGH)
public void placeKiln(PlayerInteractEvent.RightClickBlock event){
    if(event.getWorld().getBlockState(event.getPos()).getBlock()==BlocksRegistry.potteryKiln){
        event.setUseBlock(Result.ALLOW);
    }else if(!event.isCanceled()&&event.getEntityPlayer().isSneaking()&&PotteryKilnRecipe.isValidInput(event.getItemStack())){
        if(event.getFace()==EnumFacing.UP&&event.getWorld().getBlockState(event.getPos()).isSideSolid(event.getWorld(), event.getPos(), EnumFacing.UP)&&
                event.getWorld().getBlockState(event.getPos().offset(EnumFacing.UP)).getBlock().isReplaceable(event.getWorld(), event.getPos().offset(EnumFacing.UP))){
            if(!event.getWorld().isRemote){
                event.getWorld().setBlockState(event.getPos().offset(EnumFacing.UP), BlocksRegistry.potteryKiln.getDefaultState());
                TilePotteryKiln tile=((TilePotteryKiln)event.getWorld().getTileEntity(event.getPos().offset(EnumFacing.UP)));
                event.getEntityPlayer().setHeldItem(event.getHand(), tile.pottery.insertItem(0, event.getItemStack(), false));
                event.getWorld().playSound(null, event.getPos(), SoundEvents.BLOCK_GRAVEL_PLACE, SoundCategory.BLOCKS, 1F, 1F);
                event.getWorld().notifyBlockUpdate(event.getPos().offset(EnumFacing.UP), BlocksRegistry.potteryKiln.getDefaultState(), BlocksRegistry.potteryKiln.getDefaultState(), 2);
            }
            event.setUseBlock(Result.DENY);
            event.setUseItem(Result.DENY);
        }
    }
}
项目:Adventurers-Toolbox    文件:HammerHandler.java   
@SubscribeEvent
public void onPlayerClickBlock(PlayerInteractEvent.RightClickBlock event) {

    if (event.getEntityPlayer() == null || !event.getEntityPlayer().isSneaking()) {
        return;
    }

    if (event.getItemStack().getItem() == ModItems.hammer && !event.getEntityPlayer().getCooldownTracker().hasCooldown(ModItems.hammer)) {

        if (!event.getWorld().isRemote) {
            BlockPos pos = event.getPos().offset(event.getFace());
            event.getWorld().createExplosion(event.getEntityPlayer(), pos.getX() + 0.5, pos.getY() + 0.5,
                    pos.getZ() + 0.5, 3, false);
        }

        event.getEntityPlayer().swingArm(event.getHand());
        event.getEntityPlayer().setActiveHand(event.getHand());
        event.getEntityPlayer().getCooldownTracker().setCooldown(ModItems.hammer, 200);
        ModItems.hammer.setDamage(event.getItemStack(), ModItems.hammer.getDamage(event.getItemStack()) - 10);

        event.setCancellationResult(EnumActionResult.SUCCESS);
        event.setResult(Event.Result.ALLOW);
        event.setCanceled(true);
    }

}
项目:connor41-etfuturum2    文件:GrassPath.java   
public static void onPlayerInteract(PlayerInteractEvent event) {
    if (EtFuturum.enableGrassPath)
        if (event.entityPlayer != null) {
            World world = event.entityPlayer.worldObj;
            if (event.action == Action.RIGHT_CLICK_BLOCK)
                if (world.getBlock(event.x, event.y, event.z) == Blocks.grass) {
                    ItemStack stack = event.entityPlayer.getCurrentEquippedItem();
                    if (stack != null && (stack.getItem() instanceof ItemSpade || isTinkersShovel(stack))) {
                        world.setBlock(event.x, event.y, event.z, ModBlocks.grass_path);
                        event.entityPlayer.swingItem();
                        stack.damageItem(1, event.entityPlayer);
                        world.playSoundEffect(event.x + 0.5F, event.y + 0.5F, event.z + 0.5F, Block.soundTypeGravel.getStepResourcePath(), 1.0F, 0.8F);
                    }
                }
        }
}
项目:Possessed    文件:ServerEventHandler.java   
@SubscribeEvent
public void onEntityInteract(PlayerInteractEvent.EntityInteract event) {
    EntityPlayer player = event.getEntityPlayer();
    if (!player.worldObj.isRemote && event.getHand() == EnumHand.MAIN_HAND) {
        if (event.getTarget() instanceof EntityLivingBase && !(event.getTarget() instanceof EntityPlayer) && player.isSneaking()) {
            ItemStack head = player.getItemStackFromSlot(EntityEquipmentSlot.HEAD);
            if ((head != null && head.getItem() instanceof ItemPossessiveHelmet) || PossessHandler.isPossessing(player)) {
                EntityLivingBase target = (EntityLivingBase) event.getTarget();
                if (!(target instanceof EntityLiving && ((EntityLiving) target).isAIDisabled())) {
                    PossessHandler.possess(player, target);
                }
            }
        } else if (event.getTarget() instanceof EntityPlayer) {
            PossessivePlayer possessivePlayer = PossessHandler.get((EntityPlayer) event.getTarget());
            if (possessivePlayer != null) {
                ItemStack stack = event.getItemStack();
                EntityLivingBase possessing = possessivePlayer.getPossessing();
                EnumHand hand = event.getHand();
                if ((stack != null && stack.getItem().itemInteractionForEntity(stack, player, possessing, hand)) || (possessing.processInitialInteract(player, stack, hand))) {
                    event.setCanceled(true);
                }
            }
        }
    }
}
项目:LittleThings-old    文件:GetExpBottles.java   
@SubscribeEvent
public void onRightClick(PlayerInteractEvent.RightClickItem e)
{
    if (e.getItemStack() != null && e.getItemStack().getItem() instanceof ItemGlassBottle && e.getEntityPlayer().isSneaking() && (e.getEntityPlayer().experienceLevel >= 1 || e.getEntityPlayer().isCreative())) {
        EntityPlayer player = e.getEntityPlayer();

        Vector3 origin = Vector3.fromEntity(player).add(0, player.getEyeHeight(), 0);
        Vector3 look = new Vector3(player.getLookVec());
        Vector3 end = origin.copy().add(look.copy().normalize().multiply(5));

        RayTraceResult rtr = player.worldObj.rayTraceBlocks(origin.toVec3D(), end.toVec3D(), true);
        IBlockState hitBlockState = null;
        if (rtr != null) hitBlockState = e.getWorld().getBlockState(rtr.getBlockPos());

        if (hitBlockState == null || hitBlockState.getBlock() != Blocks.water) {
            e.getItemStack().stackSize--;
            if (e.getItemStack().stackSize <= 0)
                e.getEntityPlayer().inventory.deleteStack(e.getItemStack());
            e.getEntityPlayer().inventory.addItemStackToInventory(new ItemStack(Items.experience_bottle));
            e.getEntityPlayer().removeExperienceLevel(1);
        }
    }
}
项目:LittleThings-old    文件:RightClickCrops.java   
@SubscribeEvent
public void onRightClick(PlayerInteractEvent.RightClickBlock e)
{
    if (!e.getWorld().isRemote) {
        BlockPos pos = e.getPos();
        IBlockState state = e.getWorld().getBlockState(pos);
        if (state.getBlock() instanceof BlockCrops) {
            BlockCrops block = (BlockCrops) state.getBlock();
            if ((block == Blocks.wheat || block == Blocks.carrots || block == Blocks.potatoes) && state.getValue(BlockCrops.AGE) == 7) {
                performAction(e.getWorld(), e.getPos(), state, BlockCrops.AGE);
            } else if (block == Blocks.beetroots && state.getValue(BlockBeetroot.BEETROOT_AGE) == 3) {
                performAction(e.getWorld(), e.getPos(), state, BlockBeetroot.BEETROOT_AGE);
            }
        }
    }
}
项目:LittleThings-old    文件:ReplaceArmor.java   
@SubscribeEvent
public void onRightClick(PlayerInteractEvent.RightClickItem e)
{
    if (e.getItemStack() != null) {
        EntityPlayer player = e.getEntityPlayer();
        ItemStack stack = e.getItemStack();

        if (stack.getItem() instanceof ItemArmor) {
            EntityEquipmentSlot slot = EntityLiving.getSlotForItemStack(stack);
            ItemStack old = player.getItemStackFromSlot(slot);
            if (old != null) {
                old = old.copy();
                player.setItemStackToSlot(slot, stack.copy());
                stack.stackSize = 0;
                player.setHeldItem(e.getHand(), old);
            }
        }
    }
}
项目:CrystalMod    文件:TagManager.java   
@SubscribeEvent
public void playerInteract(PlayerInteractEvent.EntityInteract event){
    Entity target = event.getTarget();
    EntityPlayer player = event.getEntityPlayer();
    if(target !=null && player !=null && !player.getEntityWorld().isRemote){
        if(target instanceof EntityPlayer){
           EntityPlayer tPlayer = (EntityPlayer) target;
              tagPlayer(tPlayer.getName(), player.getName());
        }
        else if(target instanceof EntityLiving){
               EntityLiving tEnt = (EntityLiving) target;
               if(tEnt.hasCustomName()){
                  if(getData(tEnt.getCustomNameTag()) !=null)
                  tagPlayer(tEnt.getCustomNameTag(), player.getName());
               }
        }
    }
}
项目:Microcosm    文件:PlayerHandler.java   
@SubscribeEvent
public void onRightclickEntity(PlayerInteractEvent.EntityInteract event)
{
    EntityPlayer player = event.getEntityPlayer();
    ItemStack heldItem = player.inventory.getCurrentItem();
    if(!event.getEntity().worldObj.isRemote && heldItem != null && heldItem.getItem() instanceof ItemMobCapsule)
    {
        if(heldItem.hasCapability(CapabilityEntityContainer.ENTITY_CONTAINER_CAPABILITY, EnumFacing.DOWN))
        {
            Entity e = event.getTarget();
            if(e != null && !e.isDead)
            {
                IEntityContainer cap = heldItem.getCapability(CapabilityEntityContainer.ENTITY_CONTAINER_CAPABILITY, EnumFacing.DOWN);
                if(cap.addEntity(new EntityStack(event.getTarget().serializeNBT())))
                    event.getTarget().setDead();
            }
        }
    }
}
项目:TAIGA    文件:TraitTantrum.java   
@SubscribeEvent
public void RightClickItem(PlayerInteractEvent.RightClickItem event) {
    World w = event.getWorld();
    BlockPos pos = event.getPos();
    ItemStack tool = event.getEntityPlayer().getHeldItemMainhand();
    if (!w.isRemote && TinkerUtil.hasTrait(TagUtil.getTagSafe(tool), identifier)) {
        NBTTagCompound tag = TagUtil.getExtraTag(tool);
        Data data = Data.read(tag);
        if (data.amount > 1f) {
            double d = Math.min(Utils.round2(random.nextDouble() * data.amount), max_power);
            w.newExplosion(event.getEntityPlayer(), pos.getX(), pos.getY(), pos.getZ(), (float) Math.pow((double) 1.2f, d), false, true);
            data.amount -= d;
            data.write(tag);
            TagUtil.setExtraTag(tool, tag);
            TagUtil.setEnchantEffect(tool, false);
        }
    }
}
项目:How-Bout-That-Furniture    文件:FurnitureEventHandler.java   
@SubscribeEvent
public void playerLeftClick(PlayerInteractEvent.LeftClickBlock event) {
    if (!event.getEntityPlayer().capabilities.isCreativeMode && event.getWorld().getBlockState(event.getPos()).getBlock() instanceof BlockDoor && event.getWorld().getBlockState(event.getPos()).getMaterial() == Material.WOOD) {
        event.getWorld().playSound(null, event.getPos(), SoundEvents.BLOCK_METAL_PLACE, SoundCategory.BLOCKS, 1, 1);
        event.getWorld().playSound(null, event.getPos(), SoundEvents.BLOCK_WOOD_PLACE, SoundCategory.BLOCKS, 1, 1);
        event.getWorld().playSound(null, event.getPos(), SoundEvents.BLOCK_WOOD_PLACE, SoundCategory.BLOCKS, 1, 1);
        event.getWorld().playSound(null, event.getPos(), SoundEvents.BLOCK_WOOD_PLACE, SoundCategory.BLOCKS, 1, 1);
    }

    if (!event.getEntityPlayer().capabilities.isCreativeMode && event.getWorld().getBlockState(event.getPos()).getBlock() instanceof BlockDoor && event.getWorld().getBlockState(event.getPos()).getMaterial() == Material.IRON) {
        event.getWorld().playSound(null, event.getPos(), SoundEvents.BLOCK_METAL_PLACE, SoundCategory.BLOCKS, 1, 1);
        event.getWorld().playSound(null, event.getPos(), SoundEvents.BLOCK_METAL_PLACE, SoundCategory.BLOCKS, 1, 1);
        event.getWorld().playSound(null, event.getPos(), SoundEvents.BLOCK_METAL_PLACE, SoundCategory.BLOCKS, 1, 1);
        event.getWorld().playSound(null, event.getPos(), SoundEvents.BLOCK_METAL_PLACE, SoundCategory.BLOCKS, 1, 1);
        event.getWorld().playSound(null, event.getPos(), SoundEvents.BLOCK_METAL_PLACE, SoundCategory.BLOCKS, 1, 1);
        event.getWorld().playSound(null, event.getPos(), SoundEvents.BLOCK_METAL_PLACE, SoundCategory.BLOCKS, 1, 1);
    }
}
项目:ARKCraft    文件:Easter.java   
@SuppressWarnings("static-access")
@SubscribeEvent
public static void handleInteract(PlayerInteractEvent.RightClickBlock event) throws NullPointerException
{
    ItemStack item = event.getEntityPlayer().getActiveItemStack();
    AchievementPage page = ARKCraftAchievements.page;
    Achievement achievement = ARKCraftAchievements.achievementMichaelBay;

    EntityPlayer player = event.getEntityPlayer();
    if (!AchievementHelper.containsAchievement(page, achievement)) {
        if (item != null && item.getItem() == ARKCraftRangedWeapons.rocket_propelled_grenade) {
            if (item.getDisplayName().equals("Michael_Bay") && player.isSneaking()) {

                double x = player.posX;
                double y = player.posY;
                double z = player.posZ;

                Easter.MICHAEL_BAY.createExplosionNoDamage(player, event.getWorld(), 5.0F, x, y, z, 0, 1, 0);
                AchievementHelper.registerAndDisplay(player, achievement);
            }
        }
    }
}
项目:Ambidextrous    文件:EventPlayerInteract.java   
private void handleClick(
        final PlayerInteractEvent e )
{
    final SupressionState current = getState( e.getEntityPlayer() ).get( e.getEntityPlayer() );

    if ( current == null || current.suppress == false )
    {
        // if nothing is set, or supression isn't on, then we don't care.
        return;
    }

    if ( current.hand == e.getHand() )
    {
        // if we here suppression is on, was it the correct hand?
        e.setCanceled( true );
    }
}
项目:CraftingHarmonics    文件:EventHandler.java   
@SubscribeEvent(priority = EventPriority.LOWEST)
public void onPlayerInteractEvent(PlayerInteractEvent.RightClickBlock evt) {
    // Called when right clicking on a block (potentially with something...)
    if(evt.isCanceled()) return;

    // Check if we're cancelling, or if our interaction handler says we should cancel:
    if (!ItemRegistry.instance.shouldCancelUse(evt) && BlockRegistry.instance.handleInteraction(evt)) return;

    evt.setUseItem(Event.Result.DENY);
    evt.setUseBlock(Event.Result.ALLOW);
    evt.setCanceled(true);

    // The game ends up firing the RightClickItem event as well; we set this here to make sure
    // we don't end up doing all the checks/callbacks a second time in that event:
    debounceItemRightClick.set(true);
}
项目:CraftingHarmonics    文件:EventHandler.java   
@SubscribeEvent(priority = EventPriority.LOWEST)
public void onPlayerInteract(PlayerInteractEvent.EntityInteract evt) {
    if(evt.isCanceled()) return;

    // If we're cancelling on this thread...
    Boolean debounce = debounceEntityInteract.get();
    if(debounce != null && debounce) {
        debounceEntityInteract.set(false);
        evt.setCanceled(true);
        return;
    }

    // We don't care about offhands if we're not cancelling them...
    if(evt.getHand() == EnumHand.OFF_HAND) return;

    // If we pass the check, then we can allow the event to go through...
    if(EntityRegistry.allowInteractionBetween(evt.getTarget(), evt.getEntityPlayer())) return;

    // Otherwise, cancel, and debounce our off-hand click:
    evt.setCanceled(true);
    debounceEntityInteract.set(true);
}
项目:CraftingHarmonics    文件:BlockRegistry.java   
/**
 * Handles checking for any interactions we need to run for the given block.
 * @param evt    The event to handle
 * @return       True if the interaction should continue, false otherwise.
 */
public boolean handleInteraction(PlayerInteractEvent.RightClickBlock evt) {
    // Figure out what we clicked...
    IBlockState targetBlock = evt.getWorld().getBlockState(evt.getPos());

    // Get our handlers...
    Collection<BlockInteractionHandler> handlers = interactionHandlers.get(targetBlock);

    // Bail early if we can:
    if(handlers.size() <= 0) return true;

    // Simulate the harvest drops event:
    // TODO: Abstract block drops from general block matchers so we don't have to do this...
    BlockEvent.HarvestDropsEvent simulatedEvt = new BlockEvent.HarvestDropsEvent(evt.getWorld(), evt.getPos(),
            targetBlock, 0, 0.0f, new ArrayList<>(), evt.getEntityPlayer(), false);

    // ... and process them
    for (BlockInteractionHandler handler : handlers) {
        // Check if we should cancel:
        if(!handler.handle(evt, simulatedEvt)) return false;
    }

    // If we made it here, we can tell the parent handler it can continue:
    return true;
}
项目:CraftingHarmonics    文件:BlockInteractionHandler.java   
/**
 * Handle the event, returning if processing should continue
 *
 * @param evt          The event to handle
 * @param simulatedEvt A simulated drop event to pass on to the matchers
 * @return True if processing should continue; false to cancel the underlying event.
 */
public boolean handle(PlayerInteractEvent.RightClickBlock evt, BlockEvent.HarvestDropsEvent simulatedEvt) {
    List<Runnable> matcherCallbacks = new ArrayList<>();

    // Check our matchers:
    for (IBlockDropMatcher matcher : matchers) {
        BaseMatchResult result = matcher.isMatch(simulatedEvt, dummy);
        if (!result.isMatch()) return true;
        if (result.getCallback() != null) matcherCallbacks.add(result.getCallback());
    }

    // Run our matcher callbacks:
    for (Runnable matcherCallback : matcherCallbacks) {
        matcherCallback.run();
    }

    // Run our callbacks, only for the main hand:
    // TODO: Consider moving this to the event handler to prevent going through everything else...
    if(evt.getHand() == EnumHand.MAIN_HAND) {
        MobTickRegistry.addCallbackSet(evt.getEntity(), callbacks, new BaseEntityMatcherData(evt.getEntity()));
    }

    return !cancelAfterMatch;
}
项目:Factorization    文件:ItemMatrixProgrammer.java   
@SubscribeEvent(priority = EventPriority.LOW)
public void removeMask(PlayerInteractEvent event) {
    if (event.action == PlayerInteractEvent.Action.LEFT_CLICK_BLOCK) return;
    final EntityPlayer player = event.entityPlayer;
    if (player.worldObj.isRemote) return;
    if (!player.isSneaking()) return;
    if (player.getHeldItem() != null) return;
    final ItemStack helmet = player.getCurrentArmor(3);
    if (helmet == null || !(helmet.getItem() == this)) return;
    if (!isBowed(player)) return;

    player.setCurrentItemOrArmor(4, null);
    player.setCurrentItemOrArmor(0, helmet);
    event.setCanceled(true);
    Core.proxy.updatePlayerInventory(player); // Only seems necessary for removal specifically.
}
项目:SettlerCraft    文件:SleepHandler.java   
@SubscribeEvent
@SuppressWarnings("unused")
public void onPlayerTryToSleep(PlayerInteractEvent.RightClickBlock event) {
    World world = event.getWorld();
    BlockPos pos = event.getPos();
    IBlockState state = world.getBlockState(pos);
    if(!(state.getBlock() instanceof BlockBed)) {
        return;
    }
    if(isBedOccupied(world, pos, state)) {
        event.setCanceled(true);
        event.setUseBlock(Event.Result.DENY);
        event.setUseItem(Event.Result.DENY);
        event.getEntityPlayer().sendMessage(new TextComponentString("Occupied"));
    }
}
项目:DrawersBits    文件:PlayerEventHandler.java   
@SubscribeEvent(priority = EventPriority.HIGH)
public void interaction(
        final PlayerInteractEvent.LeftClickBlock event )
{
    if (BitDrawers.config.debugTrace) {
        Vec3d vec = event.getHitVec();
        BDLogger.info("Left Click %s %s %f %f %f", resultToString(event.getUseItem()), resultToString(event.getUseBlock()), vec.xCoord, vec.yCoord, vec.zCoord);
    }
    if ( event.getEntityPlayer() != null && event.getUseItem() != Event.Result.DENY )
    {
        final ItemStack is = event.getItemStack();
        if ( is != null && (is.getItem() instanceof ItemChiseledBit) && event.getWorld().isRemote)
        {
            Block target = event.getWorld().getBlockState(event.getPos()).getBlock();
            if (target instanceof BlockBitDrawers) {
                target.onBlockClicked(event.getWorld(), event.getPos(), event.getEntityPlayer());
            }
            if (BitDrawers.config.debugTrace)
                BDLogger.info("Bit Left Click");
        }
    }
}
项目:DualCraft    文件:WorldEventHandler.java   
@SubscribeEvent
public void onPlayerInteract(PlayerInteractEvent event)
{
    EntityPlayer player = event.entityPlayer;
    World world = event.world;
    int x = event.x;
    int y = event.y;
    int z = event.z;

    if ((event.action == PlayerInteractEvent.Action.RIGHT_CLICK_BLOCK) && (!player.isSneaking()))
    {
        Block clickedBlock = world.getBlock(x, y, z);
        if (clickedBlock == Blocks.crafting_table)
            if (validMultiblock(world, x, y, z))
            {
                event.useBlock = Event.Result.DENY;
                player.openGui(DualCraft.instance, GUIs.DUAL_WORKBENCH.ordinal(), world, x, y, z);
            }
    }
}
项目:notenoughwands1.8.8    文件:ForgeEventHandlers.java   
@SubscribeEvent
public void onPlayerInteractEvent(PlayerInteractEvent event) {
    ItemStack heldItem = event.entityPlayer.getHeldItem();
    if (heldItem == null || heldItem.getItem() == null) {
        return;
    }
    if (event.entityPlayer.isSneaking() && WrenchChecker.isAWrench(heldItem.getItem())) {
        // If the block is protected we prevent sneak-wrenching it.
        ProtectedBlocks protectedBlocks = ProtectedBlocks.getProtectedBlocks(event.world);
        BlockPos pos = event.pos;
        if (protectedBlocks != null && protectedBlocks.isProtected(event.world, pos)) {
            event.setCanceled(true);
        }
    }

}
项目:EnderCore    文件:RightClickCropHandler.java   
@SubscribeEvent
public void handleCropRightClick(PlayerInteractEvent event) {
  int x = event.x, y = event.y, z = event.z;
  Block block = event.world.getBlock(x, y, z);
  int meta = event.world.getBlockMetadata(x, y, z);
  if (ConfigHandler.allowCropRC && event.action == Action.RIGHT_CLICK_BLOCK && (event.entityPlayer.getHeldItem() == null || !event.entityPlayer.isSneaking())) {
    for (PlantInfo info : plants) {
      if (info.blockInst == block && meta == info.meta) {
        if (event.world.isRemote) {
          event.entityPlayer.swingItem();
        } else {
          currentPlant = info;
          block.dropBlockAsItem(event.world, x, y, z, meta, 0);
          currentPlant = null;
          event.world.setBlockMetadataWithNotify(x, y, z, info.resetMeta, 3);
          event.setCanceled(true);
        }
        break;
      }
    }
  }
}
项目:Culinary-Cultivation    文件:InteractEvents.java   
@SubscribeEvent
public void vanillaRightClickCropsHarvesting(PlayerInteractEvent.RightClickBlock event) {
    World world = event.getWorld();
    BlockPos pos = event.getPos();
    IBlockState state = event.getWorld().getBlockState(pos);
    Block block = world.getBlockState(pos).getBlock();

    if (block instanceof BlockCrops && !(block instanceof BlockCrop) && !(block instanceof BlockBeetroot)) {
        int age = state.getValue(BlockCrops.AGE);
        if (age >= 7) {
            block.dropBlockAsItem(world, pos, state, 0);
            world.setBlockState(pos, state.withProperty(BlockCrop.AGE, 0), 2);
        }
    } else if (block instanceof BlockNetherWart || block instanceof BlockBeetroot) {
        int age3 = state.getValue(BlockNetherWart.AGE);
        if (age3 >= 3) {
            block.dropBlockAsItem(world, pos, state, 0);
            world.setBlockState(pos, state.withProperty(BlockNetherWart.AGE, 0), 2);
        }
    }
}
项目:NOVA-Core    文件:ForgeEventHandler.java   
@SubscribeEvent
public void playerInteractEvent(PlayerInteractEvent event) {
    if (event.world != null && event.pos != null) {
        nova.core.event.PlayerEvent.Interact evt = new nova.core.event.PlayerEvent.Interact(
            WorldConverter.instance().toNova(event.world),
            VectorConverter.instance().toNova(event.pos),
            EntityConverter.instance().toNova(event.entityPlayer),
            nova.core.event.PlayerEvent.Interact.Action.values()[event.action.ordinal()]
        );

        Game.events().publish(evt);

        event.useBlock = Event.Result.values()[evt.useBlock.ordinal()];
        event.useItem = Event.Result.values()[evt.useItem.ordinal()];
        event.setCanceled(evt.isCanceled());
    }
}
项目:Cyclic    文件:BaseItemChargeScepter.java   
@SubscribeEvent
public void onHit(PlayerInteractEvent.LeftClickBlock event) {
  EntityPlayer player = event.getEntityPlayer();
  ItemStack held = player.getHeldItem(event.getHand());
  if (held.getItem() == this) {
    //did we turn it off? is the visible timer still going?
    if (ActionType.getTimeout(held) > 0) {
      return;
    }
    ActionType.setTimeout(held);
    event.setCanceled(true);
    UtilSound.playSound(player, player.getPosition(), SoundRegistry.dcoin, SoundCategory.PLAYERS, 0.1F);
    if (!player.getEntityWorld().isRemote) { // server side
      ActionType.toggle(held);
      UtilChat.addChatMessage(player, UtilChat.lang(ActionType.getName(held)));
    }
  }
}
项目:Cyclic    文件:ItemRandomizer.java   
@SubscribeEvent
public void onHit(PlayerInteractEvent.LeftClickBlock event) {
  EntityPlayer player = event.getEntityPlayer();
  ItemStack held = player.getHeldItem(event.getHand());
  if (held != null && held.getItem() == this) {
    if (ActionType.getTimeout(held) > 0) {
      //without a timeout, this fires every tick. so you 'hit once' and get this happening 6 times
      return;
    }
    ActionType.setTimeout(held);
    event.setCanceled(true);
    UtilSound.playSound(player, player.getPosition(), SoundRegistry.dcoin, SoundCategory.PLAYERS);
    if (!player.getEntityWorld().isRemote) { // server side
      ActionType.toggle(held);
      UtilChat.addChatMessage(player, UtilChat.lang(ActionType.getName(held)));
    }
  }
}
项目:Cyclic    文件:ItemPistonWand.java   
@SubscribeEvent
public void onHit(PlayerInteractEvent.LeftClickBlock event) {
  EntityPlayer player = event.getEntityPlayer();
  ItemStack held = player.getHeldItem(event.getHand());
  if (held != null && held.getItem() == this) {
    if (ActionType.getTimeout(held) > 0) {
      //without a timeout, this fires every tick. so you 'hit once' and get this happening 6 times
      return;
    }
    ActionType.setTimeout(held);
    event.setCanceled(true);
    UtilSound.playSound(player, player.getPosition(), SoundRegistry.dcoin, SoundCategory.PLAYERS);
    if (!player.getEntityWorld().isRemote) { // server side
      ActionType.toggle(held);
      UtilChat.addChatMessage(player, UtilChat.lang(ActionType.getName(held)));
    }
  }
}
项目:Cyclic    文件:ItemPlayerLauncher.java   
@SubscribeEvent
public void onHit(PlayerInteractEvent.LeftClickBlock event) {
  EntityPlayer player = event.getEntityPlayer();
  ItemStack held = player.getHeldItem(event.getHand());
  if (held != null && held.getItem() == this) {
    //did we turn it off? is the visible timer still going?
    if (ActionType.getTimeout(held) > 0) {
      return;
    }
    ActionType.setTimeout(held);
    event.setCanceled(true);
    UtilSound.playSound(player, player.getPosition(), SoundRegistry.dcoin, SoundCategory.PLAYERS, 0.3F);
    if (!player.getEntityWorld().isRemote) { // server side
      ActionType.toggle(held);
      UtilChat.addChatMessage(player, UtilChat.lang(ActionType.getName(held)));
    }
  }
}
项目:Cyclic    文件:ItemWaterRemoval.java   
@SubscribeEvent
public void onHit(PlayerInteractEvent.LeftClickBlock event) {
  EntityPlayer player = event.getEntityPlayer();
  ItemStack held = player.getHeldItem(event.getHand());
  if (held.getItem() == this) {
    //did we turn it off? is the visible timer still going?
    if (ActionType.getTimeout(held) > 0) {
      return;
    }
    ActionType.setTimeout(held);
    event.setCanceled(true);
    UtilSound.playSound(player, player.getPosition(), SoundRegistry.dcoin, SoundCategory.PLAYERS, 0.1F);
    if (!player.getEntityWorld().isRemote) { // server side
      ActionType.toggle(held);
      UtilChat.addChatMessage(player, UtilChat.lang(ActionType.getName(held)));
    }
  }
}
项目:Cyclic    文件:ItemBuildSwapper.java   
@SubscribeEvent
public void onHit(PlayerInteractEvent.LeftClickBlock event) {
  EntityPlayer player = event.getEntityPlayer();
  ItemStack held = player.getHeldItem(event.getHand());
  if (!held.isEmpty() && held.getItem() == this) {
    if (ActionType.getTimeout(held) > 0) {
      //without a timeout, this fires every tick. so you 'hit once' and get this happening 6 times
      return;
    }
    ActionType.setTimeout(held);
    event.setCanceled(true);
    UtilSound.playSound(player, player.getPosition(), SoundRegistry.dcoin, SoundCategory.PLAYERS);
    if (!player.getEntityWorld().isRemote) { // server side
      ActionType.toggle(held);
      UtilChat.addChatMessage(player, UtilChat.lang(ActionType.getName(held)));
    }
  }
}
项目:Cyclic    文件:PlayerAbilitiesModule.java   
@SubscribeEvent
public void onEntityInteractSpecific(PlayerInteractEvent.EntityInteractSpecific event) {
  if (armorStandSwap) {
    //added for https://www.twitch.tv/darkphan
    if (event.getWorld().isRemote) {
      return;
    } //server side only
    if (event.getTarget() == null || event.getTarget() instanceof EntityArmorStand == false) {
      return;
    }
    EntityArmorStand entityStand = (EntityArmorStand) event.getTarget();
    EntityPlayer player = event.getEntityPlayer();
    if (player.isSneaking() == false) {
      return;
    } //bc when not sneaking, we do the normal single item version
    event.setCanceled(true);//which means we need to now cancel that normal version and do our own
    for (EntityEquipmentSlot slot : armorStandEquipment) {
      ItemStack itemPlayer = player.getItemStackFromSlot(slot);
      ItemStack itemArmorstand = entityStand.getItemStackFromSlot(slot);
      player.setItemStackToSlot(slot, itemArmorstand);
      entityStand.setItemStackToSlot(slot, itemPlayer);
    }
  }
}