Java Code Examples for net.minecraftforge.event.entity.player.PlayerInteractEvent#LeftClickBlock

The following examples show how to use net.minecraftforge.event.entity.player.PlayerInteractEvent#LeftClickBlock . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ModGenuinePeoplePersonalities.java    From CommunityMod with GNU Lesser General Public License v2.1 5 votes vote down vote up
@SubscribeEvent(priority = EventPriority.HIGHEST)
public static void onBlockHit(PlayerInteractEvent.LeftClickBlock event) {
    EventData data = new EventData(event);
    if (data.getPlayer() == null || data.getPlayer().world.isRemote) return;
    if (data.getHand() != EnumHand.MAIN_HAND) return;
    if (!testCooldown(data.getPlayer())) return;
    if (generateComplaint(StringType.ATTACK, data.getPlayer(), data.getBlock(), data)) {
        resetCooldown(data.getPlayer());
    }
}
 
Example 2
Source File: NukerHack.java    From ForgeWurst with GNU General Public License v3.0 5 votes vote down vote up
@SubscribeEvent
public void onLeftClickBlock(PlayerInteractEvent.LeftClickBlock event)
{
	EntityPlayer player = event.getEntityPlayer();
	if(!WPlayer.getWorld(player).isRemote)
		return;
	
	if(mode.getSelected() == Mode.ID)
		id = BlockUtils.getId(event.getPos());
}
 
Example 3
Source File: EssentialsMissingHandler.java    From Cyberware with MIT License 5 votes vote down vote up
@SubscribeEvent
public void handleLeftClickBlock(PlayerInteractEvent.LeftClickBlock event)
{
	EntityLivingBase e = event.getEntityLiving();
	
	if (CyberwareAPI.hasCapability(e))
	{
		ICyberwareUserData cyberware = CyberwareAPI.getCapability(e);
		processEvent(event, event.getHand(), event.getEntityPlayer(), cyberware);
	}
}
 
Example 4
Source File: BuildBattleDecoratorImplementation.java    From malmo with MIT License 5 votes vote down vote up
@SubscribeEvent
public void onPlayerInteract(PlayerInteractEvent event)
{
    // Disallow creating or destroying events in the player structure:
    if (event instanceof PlayerInteractEvent.LeftClickBlock)
    {
        // Destroy block
        if (blockInBounds(event.getPos(), this.sourceBounds))
            event.setCanceled(true);
    }
    else if (event instanceof PlayerInteractEvent.RightClickBlock)
    {
        // Place block - need to work out *where* the block would be placed.
        // This code was cribbed from ItemBlock.onItemUse()
        IBlockState iblockstate = event.getWorld().getBlockState(event.getPos());
        Block block = iblockstate.getBlock();
        EnumFacing side = event.getFace();
        BlockPos pos = event.getPos();
        if (block == Blocks.SNOW_LAYER && ((Integer)iblockstate.getValue(BlockSnow.LAYERS)).intValue() < 1)
        {
            side = EnumFacing.UP;
        }
        else if (!block.isReplaceable(event.getWorld(), pos))
        {
            pos = pos.offset(side);
        }
        if (blockInBounds(pos, this.sourceBounds))
            event.setCanceled(true);
    }
}
 
Example 5
Source File: ChoppingBlock.java    From Survivalist with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@SubscribeEvent
public static void interactEvent(PlayerInteractEvent.LeftClickBlock event)
{
    PlayerEntity player = event.getPlayer();
    World world = player.world;
    BlockPos pos = event.getPos();
    BlockState state = world.getBlockState(pos);
    Block block = state.getBlock();
    if (block instanceof ChoppingBlock)
    {
        if (((ChoppingBlock) block).interceptClick(world, pos, state, player))
            event.setCanceled(true);
    }
}
 
Example 6
Source File: PlayerEventHandler.java    From enderutilities with GNU Lesser General Public License v3.0 4 votes vote down vote up
@SubscribeEvent
public void onLeftClickBlock(PlayerInteractEvent.LeftClickBlock event)
{
    EntityPlayer player = event.getEntityPlayer();
    // You can only left click with the main hand, so this is fine here
    ItemStack stack = player.getHeldItemMainhand();
    World world = event.getWorld();
    BlockPos pos = event.getPos();
    EnumFacing face = event.getFace();

    if (stack.isEmpty() == false)
    {
        if (stack.getItem() == EnderUtilitiesItems.BUILDERS_WAND)
        {
            ((ItemBuildersWand) stack.getItem()).onLeftClickBlock(player, world, stack, pos, world.provider.getDimension(), face);
            event.setCanceled(true);
            return;
        }
        else if (stack.getItem() == EnderUtilitiesItems.RULER)
        {
            ((ItemRuler) stack.getItem()).onLeftClickBlock(player, world, stack, pos, world.provider.getDimension(), face);
            event.setCanceled(true);
            return;
        }
        else if (player.capabilities.isCreativeMode == false && stack.getItem() == EnderUtilitiesItems.ENDER_TOOL)
        {
            if (player.getCooldownTracker().hasCooldown(stack.getItem()))
            {
                event.setCanceled(true);
                return;
            }
        }
    }

    if (world.getBlockState(pos).getBlock() == EnderUtilitiesBlocks.BARREL)
    {
        boolean takeItems = stack.isEmpty() || stack.getItem().getToolClasses(stack).contains("pickaxe") == false;

        if (player.capabilities.isCreativeMode)
        {
            TileEntityBarrel te = BlockEnderUtilities.getTileEntitySafely(world, pos, TileEntityBarrel.class);

            if (te == null || te.getLabeledFaces().contains(face) == false)
            {
                takeItems = false;
            }
        }

        if (takeItems)
        {
            if (world.isRemote)
            {
                int dim = world.provider.getDimension();
                int guiId = ReferenceGuiIds.GUI_ID_TILE_ENTITY_GENERIC;
                int fullStacks = Configs.barrelInversedSneak == player.isSneaking() ? 1 : 0;

                PacketHandler.INSTANCE.sendToServer(new MessageGuiAction(dim, pos, guiId, TileEntityBarrel.GUI_ACTION_TAKE_ITEMS, fullStacks));
            }

            event.setCanceled(true);
        }
    }
}