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

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

Introduction

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

Prototype

@Nullable
public Direction getFace() 

Source Link

Usage

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();/*from  w ww.  j  av  a  2  s  . co  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 .  ja va 2s  .  co  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);
    }/*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:vazkii.quark.decoration.feature.FlatItemFrames.java

License:Creative Commons License

@SubscribeEvent
public void onPlayerInteract(PlayerInteractEvent.RightClickBlock event) {
    if (event.getFace() == null)
        return;/*ww  w  .  ja v  a  2s  .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.RemoveSnowLayers.java

License:Creative Commons License

@SubscribeEvent
public void onPlayerRightClick(PlayerInteractEvent.RightClickBlock event) {
    if (event.getFace() != EnumFacing.UP)
        return;//  ww  w. j  a  v 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);
    }
}

From source file:vazkii.quark.vanity.feature.SitInStairs.java

License:Creative Commons License

@SubscribeEvent
public void onInteract(PlayerInteractEvent.RightClickBlock event) {
    EntityPlayer player = event.getEntityPlayer();
    if (player.getRidingEntity() != null)
        return;//from w  w  w  . ja va2 s.co  m

    World world = event.getWorld();
    BlockPos pos = event.getPos();

    Vec3d vec = new Vec3d(pos.getX() + 0.5, pos.getY(), pos.getZ() + 0.5);
    double maxDist = 2;
    if ((vec.x - player.posX) * (vec.x - player.posX) + (vec.y - player.posY) * (vec.y - player.posY)
            + (vec.z - player.posZ) * (vec.z - player.posZ) > maxDist * maxDist)
        return;

    IBlockState state = world.getBlockState(pos);

    ItemStack stack1 = player.getHeldItemMainhand();
    ItemStack stack2 = player.getHeldItemOffhand();
    if (!stack1.isEmpty() || !stack2.isEmpty())
        return;

    if (state.getBlock() instanceof BlockStairs && state.getValue(BlockStairs.HALF) == EnumHalf.BOTTOM
            && !state.getBlock().isSideSolid(state, world, pos, event.getFace()) && canBeAbove(world, pos)) {
        List<Seat> seats = world.getEntitiesWithinAABB(Seat.class, new AxisAlignedBB(pos, pos.add(1, 1, 1)));

        if (seats.isEmpty()) {
            Seat seat = new Seat(world, pos);
            world.spawnEntity(seat);
            event.getEntityPlayer().startRiding(seat);
        }
    }
}