当前位置: 首页>>代码示例>>Java>>正文


Java PlayerInteractEvent.RightClickBlock方法代码示例

本文整理汇总了Java中net.minecraftforge.event.entity.player.PlayerInteractEvent.RightClickBlock方法的典型用法代码示例。如果您正苦于以下问题:Java PlayerInteractEvent.RightClickBlock方法的具体用法?Java PlayerInteractEvent.RightClickBlock怎么用?Java PlayerInteractEvent.RightClickBlock使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在net.minecraftforge.event.entity.player.PlayerInteractEvent的用法示例。


在下文中一共展示了PlayerInteractEvent.RightClickBlock方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: handleBlockRightClick

import net.minecraftforge.event.entity.player.PlayerInteractEvent; //导入方法依赖的package包/类
@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);
		}
	}
}
 
开发者ID:astronautlabs,项目名称:rezolve,代码行数:25,代码来源:SecurityAccessController.java

示例2: onPlayerInteract

import net.minecraftforge.event.entity.player.PlayerInteractEvent; //导入方法依赖的package包/类
@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;
}
 
开发者ID:TeamPneumatic,项目名称:pnc-repressurized,代码行数:18,代码来源:CoordTrackUpgradeHandler.java

示例3: onInteraction

import net.minecraftforge.event.entity.player.PlayerInteractEvent; //导入方法依赖的package包/类
@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);
    }
}
 
开发者ID:TeamPneumatic,项目名称:pnc-repressurized,代码行数:19,代码来源:SemiBlockManager.java

示例4: placeKiln

import net.minecraftforge.event.entity.player.PlayerInteractEvent; //导入方法依赖的package包/类
@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);
		}
	}
}
 
开发者ID:EnderiumSmith,项目名称:CharcoalPit,代码行数:20,代码来源:PileIgnitr.java

示例5: onPlayerClickBlock

import net.minecraftforge.event.entity.player.PlayerInteractEvent; //导入方法依赖的package包/类
@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);
	}

}
 
开发者ID:the-realest-stu,项目名称:Adventurers-Toolbox,代码行数:27,代码来源:HammerHandler.java

示例6: onRightClick

import net.minecraftforge.event.entity.player.PlayerInteractEvent; //导入方法依赖的package包/类
@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);
            }
        }
    }
}
 
开发者ID:GamingsModding,项目名称:LittleThings-old,代码行数:17,代码来源:RightClickCrops.java

示例7: handleInteract

import net.minecraftforge.event.entity.player.PlayerInteractEvent; //导入方法依赖的package包/类
@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);
            }
        }
    }
}
 
开发者ID:BubbleTrouble14,项目名称:ARKCraft,代码行数:24,代码来源:Easter.java

示例8: onPlayerInteractEvent

import net.minecraftforge.event.entity.player.PlayerInteractEvent; //导入方法依赖的package包/类
@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);
}
 
开发者ID:legendblade,项目名称:CraftingHarmonics,代码行数:17,代码来源:EventHandler.java

示例9: handleInteraction

import net.minecraftforge.event.entity.player.PlayerInteractEvent; //导入方法依赖的package包/类
/**
 * 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;
}
 
开发者ID:legendblade,项目名称:CraftingHarmonics,代码行数:30,代码来源:BlockRegistry.java

示例10: handle

import net.minecraftforge.event.entity.player.PlayerInteractEvent; //导入方法依赖的package包/类
/**
 * 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;
}
 
开发者ID:legendblade,项目名称:CraftingHarmonics,代码行数:31,代码来源:BlockInteractionHandler.java

示例11: onPlayerTryToSleep

import net.minecraftforge.event.entity.player.PlayerInteractEvent; //导入方法依赖的package包/类
@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"));
    }
}
 
开发者ID:InfinityRaider,项目名称:SettlerCraft,代码行数:17,代码来源:SleepHandler.java

示例12: vanillaRightClickCropsHarvesting

import net.minecraftforge.event.entity.player.PlayerInteractEvent; //导入方法依赖的package包/类
@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);
        }
    }
}
 
开发者ID:GirafiStudios,项目名称:Culinary-Cultivation,代码行数:22,代码来源:InteractEvents.java

示例13: interact

import net.minecraftforge.event.entity.player.PlayerInteractEvent; //导入方法依赖的package包/类
private boolean interact(PlayerInteractEvent.RightClickBlock event, ItemStack curItem, BlockPos pos){
    ISemiBlock newBlock = ((ISemiBlockItem) curItem.getItem()).getSemiBlock(event.getWorld(), pos, curItem);
    newBlock.initialize(event.getWorld(), pos);
    newBlock.prePlacement(event.getEntityPlayer(), curItem, event.getFace());
    
    Stream<ISemiBlock> existingSemiblocks = getSemiBlocks(event.getWorld(), pos);
    List<ISemiBlock> collidingBlocks = existingSemiblocks.filter(s -> !s.canCoexistInSameBlock(newBlock)).collect(Collectors.toList());
    
    if (!collidingBlocks.isEmpty()) {
        for(ISemiBlock collidingBlock : collidingBlocks){
            if (event.getEntityPlayer().capabilities.isCreativeMode) {
                removeSemiBlock(collidingBlock);
            } else {
                breakSemiBlock(collidingBlock, event.getEntityPlayer());
            }
        }
        
        return true;
    } else {            
        if (newBlock.canPlace(event.getFace())) {
            addSemiBlock(event.getWorld(), pos, newBlock);
            newBlock.onPlaced(event.getEntityPlayer(), curItem, event.getFace());
            event.getWorld().playSound(pos.getX() + 0.5, pos.getY() + 0.5, pos.getZ() + 0.5,
                    SoundType.GLASS.getPlaceSound(), SoundCategory.BLOCKS,
                    (SoundType.GLASS.getVolume() + 1.0F) / 2.0F, SoundType.GLASS.getPitch() * 0.8F,
                    false);
            if (!event.getEntityPlayer().capabilities.isCreativeMode) {
                curItem.shrink(1);
                if (curItem.getCount() <= 0) event.getEntityPlayer().setHeldItem(event.getHand(), ItemStack.EMPTY);
            }
            return true;
        }
    }
    return false;
}
 
开发者ID:TeamPneumatic,项目名称:pnc-repressurized,代码行数:36,代码来源:SemiBlockManager.java

示例14: onInteract

import net.minecraftforge.event.entity.player.PlayerInteractEvent; //导入方法依赖的package包/类
@SubscribeEvent
public static void onInteract(PlayerInteractEvent.RightClickBlock e)
{
    if(e.getEntityPlayer() instanceof EntityPlayerMP)
    {
        EntityPlayerMP mp = (EntityPlayerMP) e.getEntityPlayer();
        for (Pair<IfEntry, IRSBlockInteract> pair : PurMag.INSTANCE.getIfRegistry().getAllResearchableSteps(IRSBlockInteract.class, mp))
        {
            if(pair.getRight().apply(mp, e.getHand(), e.getPos(), e.getFace(), e.getHitVec(), e.getWorld()))
            {
                mp.getCapability(CapabilityRegistry.ENTRY_STORE_CAP, null).unlockStepAndSync(pair.getLeft().getId(), mp);
            }
        }
    }
}
 
开发者ID:PearXTeam,项目名称:PurificatiMagicae,代码行数:16,代码来源:IfEvents.java

示例15: onRightClickBlock

import net.minecraftforge.event.entity.player.PlayerInteractEvent; //导入方法依赖的package包/类
@SubscribeEvent
public static void onRightClickBlock(PlayerInteractEvent.RightClickBlock event) {
    EntityPlayer player = event.getEntityPlayer();
    World world = event.getWorld();
    BlockPos pos = event.getPos();
    EnumFacing face = event.getFace();
    ItemStack stack = event.getItemStack();
    Item item = stack.getItem();

    if (item instanceof ItemSpade) {
        if (player.canPlayerEdit(pos.offset(face), face, stack)) {
            IBlockState state = world.getBlockState(pos);
            Block block = state.getBlock();

            if (face != EnumFacing.DOWN && world.isAirBlock(pos.up()) && block == GenesisBlocks.HUMUS) {
                world.playSound(player, pos, SoundEvents.ITEM_SHOVEL_FLATTEN, SoundCategory.BLOCKS, 1.0F, 1.0F);

                if (!world.isRemote) {
                    IBlockState path = GenesisBlocks.HUMUS_PATH.getDefaultState();
                    world.setBlockState(pos, path, WorldFlags.UPDATE_BLOCK_AND_CLIENT_AND_RERENDER_ON_MAIN);
                    stack.damageItem(1, player);
                }

                event.setCanceled(true);
            }
        }
    }
}
 
开发者ID:Boethie,项目名称:Genesis,代码行数:29,代码来源:GenesisEventHandler.java


注:本文中的net.minecraftforge.event.entity.player.PlayerInteractEvent.RightClickBlock方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。