當前位置: 首頁>>代碼示例>>Java>>正文


Java PlayerInteractEvent.getPos方法代碼示例

本文整理匯總了Java中net.minecraftforge.event.entity.player.PlayerInteractEvent.getPos方法的典型用法代碼示例。如果您正苦於以下問題:Java PlayerInteractEvent.getPos方法的具體用法?Java PlayerInteractEvent.getPos怎麽用?Java PlayerInteractEvent.getPos使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在net.minecraftforge.event.entity.player.PlayerInteractEvent的用法示例。


在下文中一共展示了PlayerInteractEvent.getPos方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: onBlockInteract

import net.minecraftforge.event.entity.player.PlayerInteractEvent; //導入方法依賴的package包/類
@SubscribeEvent
public void onBlockInteract(PlayerInteractEvent event) {
	cachedItem = event.getItemStack();
	cachedBlockPos = event.getPos();
	IBlockState state = Minecraft.getMinecraft().theWorld.getBlockState(event.getPos());
	Material mat = state.getMaterial();
	cachedVariant = state.getBlock().getMetaFromState(state);
	// we use this to detect the material of a broken block, so we want to ignore air, because otherwise this would
	// always be set to air at the point we handle a block break
	if (mat != Material.AIR) {
		cachedMaterial = mat;
	}
}
 
開發者ID:Maxopoly,項目名稱:OreLogger,代碼行數:14,代碼來源:Listener.java

示例2: onBlockInteract

import net.minecraftforge.event.entity.player.PlayerInteractEvent; //導入方法依賴的package包/類
@SubscribeEvent
public void onBlockInteract(PlayerInteractEvent event) {
    World world = event.getWorld();
    BlockPos pos = event.getPos();
    IBlockState blockstate = world.getBlockState(pos);
    EntityPlayer player = event.getEntityPlayer();

    if (blockstate.getBlock() instanceof BlockBanner) {
        EnumHand hand = EnumHand.MAIN_HAND;
        ItemStack stack = player.getHeldItemMainhand();
        BlockBanner bannerblock = (BlockBanner) blockstate.getBlock();

        if (stack.isEmpty() && player.isSneaking() && player.getItemStackFromSlot(EntityEquipmentSlot.HEAD).isEmpty()) {
            ItemStack bannerstack = bannerblock.getItem(world, pos, blockstate);
            player.swingArm(hand);

            world.removeTileEntity(pos);
            world.setBlockToAir(pos);

            player.setItemStackToSlot(EntityEquipmentSlot.HEAD, bannerstack);

            if (!event.getWorld().isRemote) {
                event.setCanceled(true);
            }
        }
    }
}
 
開發者ID:DaedalusGame,項目名稱:BetterWithAddons,代碼行數:28,代碼來源:AssortedHandler.java

示例3: onPlayerInteract

import net.minecraftforge.event.entity.player.PlayerInteractEvent; //導入方法依賴的package包/類
@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);
    }
}
 
開發者ID:Microsoft,項目名稱:malmo,代碼行數:31,代碼來源:BuildBattleDecoratorImplementation.java

示例4: stopBedUse

import net.minecraftforge.event.entity.player.PlayerInteractEvent; //導入方法依賴的package包/類
@SubscribeEvent(priority = EventPriority.HIGHEST)
public void stopBedUse(PlayerInteractEvent e){
    if(!e.getWorld().isRemote) {
        if (e.getWorld().getBlockState(e.getPos()).getBlock() == Blocks.BED && ConfigurationFile.clickingBedSetsSpawnPoint) {
            e.getEntityPlayer().setSpawnPoint(e.getPos(), true);
            e.getEntityPlayer().bedLocation = e.getPos();
            e.getEntityPlayer().addChatComponentMessage(new TextComponentTranslation("Spawn point set!"));
            if (ConfigurationFile.stopBedUse && !e.getEntity().getEntityWorld().isDaytime()) {
                e.getEntityPlayer().addChatComponentMessage(new TextComponentTranslation("You don't feel tired enough to sleep.."));
                e.setCanceled(true);
            }
        }
    }
}
 
開發者ID:baileyholl,項目名稱:Event-Tweaks,代碼行數:15,代碼來源:InteractEventHandler.java

示例5: onPlayerInteract

import net.minecraftforge.event.entity.player.PlayerInteractEvent; //導入方法依賴的package包/類
@SubscribeEvent
public void onPlayerInteract(PlayerInteractEvent event) {
  if (signSkullName) {
    EntityPlayer entityPlayer = event.getEntityPlayer();
    BlockPos pos = event.getPos();
    World worldObj = event.getWorld();
    if (pos == null) {
      return;
    }
    // event has no hand??
    // and no item stack. and right click rarely works. known bug
    // http://www.minecraftforge.net/forum/index.php?topic=37416.0
    ItemStack held = entityPlayer.getHeldItemMainhand();
    if (held == null) {
      held = entityPlayer.getHeldItemOffhand();
    }
    TileEntity container = worldObj.getTileEntity(pos);
    if (held != null && held.getItem() == Items.SKULL && held.getItemDamage() == Const.skull_player && container != null && container instanceof TileEntitySign) {
      TileEntitySign sign = (TileEntitySign) container;
      String firstLine = sign.signText[0].getUnformattedText();
      if (firstLine == null) {
        firstLine = "";
      }
      if (firstLine.isEmpty() || firstLine.split(" ").length == 0) {
        held.setTagCompound(null);
      }
      else {
        firstLine = firstLine.split(" ")[0];
        NBTTagCompound nbt = UtilNBT.getItemStackNBT(held);
        nbt.setString(Const.SkullOwner, firstLine);
      }
    }
  }
}
 
開發者ID:PrinceOfAmber,項目名稱:Cyclic,代碼行數:35,代碼來源:PlayerAbilitiesModule.java

示例6: onEvent

import net.minecraftforge.event.entity.player.PlayerInteractEvent; //導入方法依賴的package包/類
@SubscribeEvent(priority = EventPriority.LOWEST)
public void onEvent(PlayerInteractEvent event) {
    if (event.getPos() != null) {
        IBlockState state = event.getWorld().getBlockState(event.getPos());
        Block block = state.getBlock();
        int meta = block.getMetaFromState(state);

        if (ProgressionAPI.registry.fireTrigger(event.getEntityPlayer(), getProvider().getUnlocalisedName(), block, meta) == Result.DENY) {
            event.setCanceled(true);
        }
    }
}
 
開發者ID:joshiejack,項目名稱:Progression,代碼行數:13,代碼來源:TriggerClickBlock.java

示例7: onPlayerInteract

import net.minecraftforge.event.entity.player.PlayerInteractEvent; //導入方法依賴的package包/類
@SubscribeEvent
    public void onPlayerInteract(PlayerInteractEvent evt) {
        // only handle right clicks on blocks
        // TODO: port for 1.9
//        if (evt.action != PlayerInteractEvent.Action.RIGHT_CLICK_BLOCK) {
//            return;
//        }
        
        BlockPos pos = evt.getPos();
        World world = evt.getWorld();
        IBlockState state = world.getBlockState(pos);
        Block block = world.getBlockState(pos).getBlock();
        
        // don't interact with vanilla egg blocks if configured
        if (DragonMounts.instance.getConfig().isDisableBlockOverride() &&
                block == Blocks.DRAGON_EGG) {
            return;
        }
        
        // ignore non-egg blocks
        if (block != Blocks.DRAGON_EGG && block != BlockDragonBreedEgg.INSTANCE) {
            return;
        }
        
        // deny action
        evt.setResult(Event.Result.DENY);
        
        // clear dragon egg block
        world.setBlockToAir(pos);

        // create dragon egg entity on server
        if (!world.isRemote) { // this was inverted, i.e. evt.world.isRemote, but it should surely be this way
            EntityTameableDragon dragon = new EntityTameableDragon(world);
            dragon.setPosition(pos.getX() + 0.5, pos.getY() + 0.5, pos.getZ() + 0.5);
            dragon.getReproductionHelper().setBreeder(evt.getEntityPlayer());
            dragon.getLifeStageHelper().setLifeStage(EnumDragonLifeStage.EGG);
            
            // set breed type (custom dragon egg only, otherwise use default breed)
            if (block == BlockDragonBreedEgg.INSTANCE) {
                EnumDragonBreed breed = state.getValue(BlockDragonBreedEgg.BREED);
                dragon.getBreedHelper().setBreedType(breed);
            }
            
            world.spawnEntityInWorld(dragon);
        }
    }
 
開發者ID:ata4,項目名稱:dragon-mounts,代碼行數:47,代碼來源:DragonEggBlockHandler.java


注:本文中的net.minecraftforge.event.entity.player.PlayerInteractEvent.getPos方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。