Example usage for net.minecraftforge.event.entity.player PlayerInteractEvent.RightClickBlock getWorld

List of usage examples for net.minecraftforge.event.entity.player PlayerInteractEvent.RightClickBlock getWorld

Introduction

In this page you can find the example usage for net.minecraftforge.event.entity.player PlayerInteractEvent.RightClickBlock getWorld.

Prototype

public World getWorld() 

Source Link

Usage

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 w w w .  jav  a 2 s  . c om
    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();/*  ww w.  j  a  v  a 2 s . c om*/
        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.ellpeck.actuallyadditions.mod.blocks.BlockLaserRelay.java

@SubscribeEvent
public void onBlockRightClick(PlayerInteractEvent.RightClickBlock event) {
    EntityPlayer player = event.getEntityPlayer();
    World world = event.getWorld();
    ItemStack stack = event.getItemStack();
    BlockPos pos = event.getPos();//  w ww.j ava  2  s . c  o m

    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();
    ItemStack stack = event.getItemStack();
    BlockPos pos = event.getPos();/*  ww  w .ja  v a 2s.  com*/

    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: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);
    }//from www . ja  v a 2 s . c  o  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: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());
        }/*from  ww w.jav  a 2  s.  c o  m*/
    }
}

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;/*from   www .  ja  va 2  s .c  om*/
    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());//from   w w w  .j  a  v a 2 s .  co  m
        if (physObj != null) {
            if (ValkyrienWarfareMod.runAirshipPermissions
                    && !(physObj.wrapping.creator.equals(event.getEntityPlayer().entityUniqueID.toString())
                            || physObj.wrapping.allowedUsers
                                    .contains(event.getEntityPlayer().entityUniqueID.toString()))) {
                event.getEntityPlayer()
                        .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;/* w w  w.  j a  v 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());
    }
}

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();//from   w  ww  .jav a 2s.c  o  m
    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();
        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;
            }
        }
    }
}