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


Java PlayerInteractEvent.EntityInteract方法代码示例

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


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

示例1: animalsSheared

import net.minecraftforge.event.entity.player.PlayerInteractEvent; //导入方法依赖的package包/类
@SubscribeEvent
public static void animalsSheared(PlayerInteractEvent.EntityInteract event)
{
	Entity target = event.getTarget();
	if (target instanceof EntityMooshroom && !target.isDead && ((EntityMooshroom) target).hurtTime == 0)
	{
		if (isUsingShears(event.getEntityPlayer()))
		{
			World world = event.getWorld();
			if (!world.isRemote)
			{
				EntityItem item = new EntityItem(event.getEntity().getEntityWorld(), target.posX, target.posY, target.posZ, new ItemStack(ModItems.meatshroom));
				world.spawnEntity(item);
			}
		}
	}
}
 
开发者ID:DarkMorford,项目名称:BetterThanWeagles,代码行数:18,代码来源:EventHandlerShears.java

示例2: onEntityInteract

import net.minecraftforge.event.entity.player.PlayerInteractEvent; //导入方法依赖的package包/类
@SubscribeEvent
public void onEntityInteract(PlayerInteractEvent.EntityInteract event) {
    EntityPlayer player = event.getEntityPlayer();
    if (!player.worldObj.isRemote && event.getHand() == EnumHand.MAIN_HAND) {
        if (event.getTarget() instanceof EntityLivingBase && !(event.getTarget() instanceof EntityPlayer) && player.isSneaking()) {
            ItemStack head = player.getItemStackFromSlot(EntityEquipmentSlot.HEAD);
            if ((head != null && head.getItem() instanceof ItemPossessiveHelmet) || PossessHandler.isPossessing(player)) {
                EntityLivingBase target = (EntityLivingBase) event.getTarget();
                if (!(target instanceof EntityLiving && ((EntityLiving) target).isAIDisabled())) {
                    PossessHandler.possess(player, target);
                }
            }
        } else if (event.getTarget() instanceof EntityPlayer) {
            PossessivePlayer possessivePlayer = PossessHandler.get((EntityPlayer) event.getTarget());
            if (possessivePlayer != null) {
                ItemStack stack = event.getItemStack();
                EntityLivingBase possessing = possessivePlayer.getPossessing();
                EnumHand hand = event.getHand();
                if ((stack != null && stack.getItem().itemInteractionForEntity(stack, player, possessing, hand)) || (possessing.processInitialInteract(player, stack, hand))) {
                    event.setCanceled(true);
                }
            }
        }
    }
}
 
开发者ID:Fararise,项目名称:Possessed,代码行数:26,代码来源:ServerEventHandler.java

示例3: playerInteract

import net.minecraftforge.event.entity.player.PlayerInteractEvent; //导入方法依赖的package包/类
@SubscribeEvent
public void playerInteract(PlayerInteractEvent.EntityInteract event){
	Entity target = event.getTarget();
	EntityPlayer player = event.getEntityPlayer();
	if(target !=null && player !=null && !player.getEntityWorld().isRemote){
		if(target instanceof EntityPlayer){
		   EntityPlayer tPlayer = (EntityPlayer) target;
              tagPlayer(tPlayer.getName(), player.getName());
		}
		else if(target instanceof EntityLiving){
			   EntityLiving tEnt = (EntityLiving) target;
			   if(tEnt.hasCustomName()){
				  if(getData(tEnt.getCustomNameTag()) !=null)
                  tagPlayer(tEnt.getCustomNameTag(), player.getName());
			   }
		}
	}
}
 
开发者ID:Alec-WAM,项目名称:CrystalMod,代码行数:19,代码来源:TagManager.java

示例4: onRightclickEntity

import net.minecraftforge.event.entity.player.PlayerInteractEvent; //导入方法依赖的package包/类
@SubscribeEvent
public void onRightclickEntity(PlayerInteractEvent.EntityInteract event)
{
    EntityPlayer player = event.getEntityPlayer();
    ItemStack heldItem = player.inventory.getCurrentItem();
    if(!event.getEntity().worldObj.isRemote && heldItem != null && heldItem.getItem() instanceof ItemMobCapsule)
    {
        if(heldItem.hasCapability(CapabilityEntityContainer.ENTITY_CONTAINER_CAPABILITY, EnumFacing.DOWN))
        {
            Entity e = event.getTarget();
            if(e != null && !e.isDead)
            {
                IEntityContainer cap = heldItem.getCapability(CapabilityEntityContainer.ENTITY_CONTAINER_CAPABILITY, EnumFacing.DOWN);
                if(cap.addEntity(new EntityStack(event.getTarget().serializeNBT())))
                    event.getTarget().setDead();
            }
        }
    }
}
 
开发者ID:Lumaceon,项目名称:Microcosm,代码行数:20,代码来源:PlayerHandler.java

示例5: onPlayerInteract

import net.minecraftforge.event.entity.player.PlayerInteractEvent; //导入方法依赖的package包/类
@SubscribeEvent(priority = EventPriority.LOWEST)
public void onPlayerInteract(PlayerInteractEvent.EntityInteract evt) {
    if(evt.isCanceled()) return;

    // If we're cancelling on this thread...
    Boolean debounce = debounceEntityInteract.get();
    if(debounce != null && debounce) {
        debounceEntityInteract.set(false);
        evt.setCanceled(true);
        return;
    }

    // We don't care about offhands if we're not cancelling them...
    if(evt.getHand() == EnumHand.OFF_HAND) return;

    // If we pass the check, then we can allow the event to go through...
    if(EntityRegistry.allowInteractionBetween(evt.getTarget(), evt.getEntityPlayer())) return;

    // Otherwise, cancel, and debounce our off-hand click:
    evt.setCanceled(true);
    debounceEntityInteract.set(true);
}
 
开发者ID:legendblade,项目名称:CraftingHarmonics,代码行数:23,代码来源:EventHandler.java

示例6: onRightclickEntity

import net.minecraftforge.event.entity.player.PlayerInteractEvent; //导入方法依赖的package包/类
@SubscribeEvent
public void onRightclickEntity(PlayerInteractEvent.EntityInteract event)
{
    EntityPlayer player = event.getEntityPlayer();
    ItemStack heldItem = player.inventory.getCurrentItem();
    if(!event.getWorld().isRemote && heldItem != null && heldItem.getItem().equals(ModItems.mobCapsule))
    {
        if(heldItem.hasCapability(ENTITY_CONTAINER, EnumFacing.DOWN))
        {
            Entity e = event.getTarget();
            if(e != null && !e.isDead)
            {
                IEntityContainer cap = heldItem.getCapability(ENTITY_CONTAINER, EnumFacing.DOWN);
                if(cap != null)
                {
                    if(cap.addEntity(new EntityStack(event.getTarget().serializeNBT())))
                    {
                        event.getTarget().setDead();
                    }
                }
            }
        }
    }
}
 
开发者ID:Lumaceon,项目名称:ClockworkPhase2,代码行数:25,代码来源:PlayerHandler.java

示例7: interactWith

import net.minecraftforge.event.entity.player.PlayerInteractEvent; //导入方法依赖的package包/类
/**TODO
 * Patch over {@link EntityPlayer#interactOn(Entity,EnumHand)}, adapted for the dual wielding
 * In battlemode, try to interact with {@link Entity#processInitialInteract(EntityPlayer, EnumHand)} in right hand, then left hand if no success
 * then try to interact with {@link ItemStack#interactWithEntity(EntityPlayer, EntityLivingBase, EnumHand)} in the same order
 * When necessary, hotswap the "current item" value to the offhand, then refresh the player attributes according to the newly selected item
 * @return SUCCESS if any interaction happened, actually bypassing subsequent PlayerInteractEvent.Action.RIGHT_CLICK_AIR and PlayerControllerMP#sendUseItem on client side
 */
public static EnumActionResult interactWith(EntityPlayer entityPlayer, Entity entity, EnumHand hand){
    if(hand == EnumHand.OFF_HAND && isPlayerInBattlemode(entityPlayer)){//No interaction with left hand item
        PlayerInteractEvent.EntityInteract event = new PlayerInteractEvent.EntityInteract(entityPlayer, hand, entity);
        PlayerEventChild.OffhandAttackEvent offAttackEvent = new PlayerEventChild.OffhandAttackEvent(event);
        if(!MinecraftForge.EVENT_BUS.post(offAttackEvent)){
            if (offAttackEvent.swingOffhand){
                sendOffSwingEvent(event);
            }
            if (offAttackEvent.shouldAttack) {
                ((IBattlePlayer) entityPlayer).attackTargetEntityWithCurrentOffItem(offAttackEvent.getTarget());
            }
            if(offAttackEvent.cancelParent){
                return EnumActionResult.SUCCESS;
            }
        }
    }
    return EnumActionResult.PASS;
}
 
开发者ID:Mine-and-blade-admin,项目名称:Battlegear2,代码行数:26,代码来源:BattlegearUtils.java

示例8: onEntityRightClick

import net.minecraftforge.event.entity.player.PlayerInteractEvent; //导入方法依赖的package包/类
@SubscribeEvent
public void onEntityRightClick(PlayerInteractEvent.EntityInteract event)
{
	if(event.getEntityPlayer().getHeldItemMainhand().isItemEqual(new ItemStack(HarshenItems.GLASS_CONTAINER)) && event.getTarget().getClass() == EntityCow.class)
		event.getEntityPlayer().setHeldItem(EnumHand.MAIN_HAND, GlassContainerValues.MILK.getStack());

}
 
开发者ID:kenijey,项目名称:harshencastle,代码行数:8,代码来源:HandlerGlassContainer.java

示例9: onInteract

import net.minecraftforge.event.entity.player.PlayerInteractEvent; //导入方法依赖的package包/类
@SubscribeEvent
public void onInteract(PlayerInteractEvent.EntityInteract event)
{
    if(event.getEntityPlayer().getActiveItemStack().getItem() instanceof ItemTorchGun)
    {
        event.setCanceled(true);
    }
}
 
开发者ID:iChun,项目名称:Torched,代码行数:9,代码来源:EventHandlerServer.java

示例10: onPlayerEntityInteract

import net.minecraftforge.event.entity.player.PlayerInteractEvent; //导入方法依赖的package包/类
@SubscribeEvent
public static void onPlayerEntityInteract(PlayerInteractEvent.EntityInteract event)
{
	// if the villager inventory gui is enabled, if the entity being interacted with is a villager, and if the player is sneaking...
	if ((ModConfiguration.enableInventoryGui) && (event.getTarget() instanceof EntityVillager) && (EntityUtils.getFlag(event.getEntityPlayer(), 2)))
	{
		// if opening the gui requires the player to not be holding anything, check to ensure that the player isn't holding anything
		if (!ModConfiguration.requireEmptyHand || (ModConfiguration.requireEmptyHand && event.getEntityPlayer().inventory.getCurrentItem().isEmpty()))
		{
			// if the event is running on the server
			if (!event.getWorld().isRemote)
			{
				// cast the entity to type EntityVillager
				EntityVillager villager = (EntityVillager)event.getTarget();

				// get the entity id of the villager
				int entityId = villager.getEntityId();

				// and read it's profession and career from it's nbt data
				NBTTagCompound compound = new NBTTagCompound();
				villager.writeEntityToNBT(compound);
				int professionId = compound.getInteger("Profession");
				int careerId = compound.getInteger("Career");

				// send a message to the client to tell it what the villager's career is
				NETWORK.sendTo(new VillagerCareerMessage(entityId, careerId), (EntityPlayerMP)event.getEntityPlayer());

				// open the inventory gui
				FMLNetworkHandler.openGui(event.getEntityPlayer(), VillagerInventoryMod.INSTANCE, ModGuiHandler.GUI_VILLAGER_INVENTORY, event.getWorld(), entityId, professionId, careerId);
			}

			// cancel the event which would show the trading gui
			event.setCanceled(true);
		}
	}
}
 
开发者ID:crazysnailboy,项目名称:VillagerInventory,代码行数:37,代码来源:VillagerInventoryMod.java

示例11: baconInteract

import net.minecraftforge.event.entity.player.PlayerInteractEvent; //导入方法依赖的package包/类
@SubscribeEvent
public static void baconInteract(PlayerInteractEvent.EntityInteract e) {
    EntityPlayer player = e.getEntityPlayer();
    if (!player.world.isRemote) {
        if (e.getTarget() instanceof OinkBacon) {
            if (player.getItemStackFromSlot(EntityEquipmentSlot.MAINHAND).isEmpty() && player.isSneaking() && e.getHand() == EnumHand.MAIN_HAND && baconGlow) {
                baconGlow = false;
            } else if (player.getItemStackFromSlot(EntityEquipmentSlot.MAINHAND).isEmpty() && player.isSneaking() && e.getHand() == EnumHand.MAIN_HAND && !baconGlow) {
                baconGlow = true;
            }
        }
    }
}
 
开发者ID:OCDiary,项目名称:TheOink,代码行数:14,代码来源:OinkEntityEvents.java

示例12: sausageInteract

import net.minecraftforge.event.entity.player.PlayerInteractEvent; //导入方法依赖的package包/类
@SubscribeEvent
public static void sausageInteract(PlayerInteractEvent.EntityInteract e) {
    EntityPlayer player = e.getEntityPlayer();
    if (!player.world.isRemote) {
        if (e.getTarget() instanceof OinkSausage) {
            if (player.getItemStackFromSlot(EntityEquipmentSlot.MAINHAND).isEmpty() && player.isSneaking() && e.getHand() == EnumHand.MAIN_HAND && sausageGlow) {
                sausageGlow = false;
            } else if (player.getItemStackFromSlot(EntityEquipmentSlot.MAINHAND).isEmpty() && player.isSneaking() && e.getHand() == EnumHand.MAIN_HAND && !sausageGlow) {
                sausageGlow = true;
            }
        }
    } else {
        player.swingArm(EnumHand.MAIN_HAND);
    }
}
 
开发者ID:OCDiary,项目名称:TheOink,代码行数:16,代码来源:OinkEntityEvents.java

示例13: stopUsing

import net.minecraftforge.event.entity.player.PlayerInteractEvent; //导入方法依赖的package包/类
@SubscribeEvent
public void stopUsing(PlayerInteractEvent.EntityInteract event) {
	
	if (!TF2Util.canInteract(event.getEntityLiving())) {
		event.setCanceled(true);
		return;
	}
	if (WeaponsCapability.get(event.getEntity()).isDisguised() && !(event.getEntityPlayer().getHeldItem(event.getHand()).getItem() instanceof ItemFood)) {
		disguise(event.getEntityPlayer(), false);
	}
	event.getEntityPlayer().removePotionEffect(TF2weapons.charging);
}
 
开发者ID:rafradek,项目名称:Mods,代码行数:13,代码来源:TF2EventsCommon.java

示例14: onInteractEntity

import net.minecraftforge.event.entity.player.PlayerInteractEvent; //导入方法依赖的package包/类
@SubscribeEvent
public void onInteractEntity(PlayerInteractEvent.EntityInteract event)
{
	if (event.getEntityPlayer() != null)
	{
		if (event.getEntityPlayer().isPotionActive(ExPPotions.stunned))
		{
			event.setCanceled(true);
		}
	}
}
 
开发者ID:V0idWa1k3r,项目名称:ExPetrum,代码行数:12,代码来源:ExPHandlerServer.java

示例15: onPlayerInteract

import net.minecraftforge.event.entity.player.PlayerInteractEvent; //导入方法依赖的package包/类
@SubscribeEvent(priority = EventPriority.HIGHEST)
public void onPlayerInteract(PlayerInteractEvent.EntityInteract event) {
    if (event.getTarget() instanceof EntityWolf) {
        @Nullable IWolfArmorCapability wolfArmorCapability = event.getTarget().getCapability(CapabilityWolfArmor.WOLF_ARMOR_CAPABILITY, null);
        if (wolfArmorCapability != null) {
            EntityPlayer player = event.getEntityPlayer();
            EnumHand hand = event.getHand();
            if (wolfArmorCapability.processInteract(player, hand)) {
                event.setCanceled(true);
            }
        }
    }
}
 
开发者ID:CenturionFox,项目名称:wolfarmor,代码行数:14,代码来源:CapabilityWolfArmor.java


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