Java 类net.minecraftforge.event.entity.player.PlayerInteractEvent.EntityInteract 实例源码

项目:Cyclic    文件:ItemAppleLapis.java   
@SubscribeEvent
public void onEntityInteractEvent(EntityInteract event) {
  if (event.getEntity() instanceof EntityPlayer == false) {
    return;
  }
  EntityPlayer player = (EntityPlayer) event.getEntity();
  //    ItemStack held = player.getHeldItemMainhand();
  ItemStack itemstack = event.getItemStack();
  if (itemstack != null && itemstack.getItem() instanceof ItemAppleLapis && itemstack.getCount() > 0) {
    if (event.getTarget() instanceof EntityZombieHorse || event.getTarget() instanceof EntitySkeletonHorse) {
      AbstractHorse h = (AbstractHorse) event.getTarget();
      if (h.isTame() == false) {
        h.setTamedBy(player);
        h.setEatingHaystack(true);
        //        UtilChat.addChatMessage(player, UtilChat.lang("item.apple_emerald.merchant"));
        itemstack.shrink(1);
        if (itemstack.getCount() == 0) {
          itemstack = ItemStack.EMPTY;
        }
        event.setCanceled(true);// stop the GUI inventory opening && horse mounting
      }
    }
  }
}
项目:MineCamera    文件:EventLoader.java   
@SubscribeEvent
public void entityInteract(EntityInteract event) {
    if (event.getEntityPlayer().getEntityData().hasKey("renderViewCamera")) {
        event.setCanceled(true);
        if (event.getSide().isClient() && event.getHand().equals(EnumHand.MAIN_HAND)
                && event.getItemStack() == null) {
            System.out.println("EntityInteract,HandType=" + event.getHand());
            ActiveTripod(Minecraft.getMinecraft().thePlayer.getName(),
                    ((EntityTripod) event.getWorld()
                            .getEntityByID(event.getEntityPlayer().getEntityData().getInteger("renderViewCamera")))
                                    .getDelay());
        }
        return;
    }
    if (event.getTarget() instanceof EntityTripod) {
        Entity target = ((PlayerInteractEvent.EntityInteract) event).getTarget();
        EntityPlayer player = event.getEntityPlayer();
        if (!player.isSneaking()) {
            if (player.inventory.armorInventory[3] != null
                    && player.inventory.armorInventory[3].getItem() instanceof ItemGlassesHelmet) {
                if (player.getEntityWorld().isRemote) {
                    // System.out.println("123");
                    Minecraft.getMinecraft().setRenderViewEntity(target);
                    Minecraft.getMinecraft().ingameGUI.setRecordPlaying(new TextComponentTranslation("chat.tripod.info"), false);
                }
                player.getEntityData().setInteger("renderViewCamera", target.getEntityId());
            }else if(!event.getWorld().isRemote&&event.getHand().equals(EnumHand.MAIN_HAND)){
                player.addChatComponentMessage(new TextComponentTranslation("chat.tripod.mustuseglass"));
            }
        } else {
            player.getEntityData().setInteger("usingGui", target.getEntityId());
            player.openGui(MineCamera.instance, GuiElementLoader.GUI_TRIPOD_CAMERA, target.getEntityWorld(),
                    (int) target.posX, (int) target.posY, (int) target.posZ);
        }
    }
}
项目:ShearMadness    文件:CommonForgeEventProxy.java   
@SuppressWarnings({"ConstantConditions", "MethodWithMoreThanThreeNegations"})
@SubscribeEvent(priority = EventPriority.LOWEST)
public void onPlayerInteractionWithEntity(EntityInteract event)
{
    //Process for shearing a sheep
    if (event.getWorld().isRemote) return;
    if (event.getHand() != EnumHand.MAIN_HAND) return;
    if (!(event.getTarget() instanceof EntitySheep)) return;
    final ItemStack itemStack = event.getItemStack();
    if (itemStack == null) {
        checkSpecialSheepInteraction(event);
        return;
    }
    if (!(itemStack.getItem() instanceof ItemShears)) return;

    final EntitySheep sheep = (EntitySheep) event.getTarget();
    if (!sheep.isShearable(itemStack, event.getWorld(), event.getPos())) return;

    final IChiseledSheepCapability capability = sheep.getCapability(Capability.CHISELED_SHEEP, null);
    if (capability == null) return;
    if (!capability.isChiseled()) return;

    //Ok, we have a chiseled sheep, cancel vanilla.
    event.setCanceled(true);

    Shearing.shearSheep(itemStack, sheep, capability);
}
项目:ShearMadness    文件:CommonForgeEventProxy.java   
private void checkSpecialSheepInteraction(EntityInteract event)
{
    final EntitySheep sheep = (EntitySheep) event.getTarget();
    final IChiseledSheepCapability capability = sheep.getCapability(Capability.CHISELED_SHEEP, null);
    if (capability == null) return;
    if (!capability.isChiseled()) return;

    final EntityPlayer entityPlayer = event.getEntityPlayer();

    MinecraftForge.EVENT_BUS.post(new ShearMadnessSpecialInteractionEvent(event.getWorld(), entityPlayer, sheep, capability));
}
项目:Inhuman-Resources    文件:EventHandler.java   
@SubscribeEvent
public void onEntityRightClicked(EntityInteract event)
{
    if (event.getTarget() instanceof MobBase)
    {
        MobBase mob = (MobBase) event.getTarget();
        if (mob.getOwnerId() == null) mob.setOwner(event.getEntityPlayer());
    }
}
项目:Dark-Utilities    文件:FeatureShulkerPearlItem.java   
@SubscribeEvent
public void onEntityInteract (EntityInteract event) {

    if (event.getSide().equals(Side.SERVER) && this.harvestablePearls && event.getTarget() instanceof EntityShulker) {

        final ICustomData data = ShulkerDataHandler.getData(event.getTarget());

        if (data != null && data.getCooldown() <= 0) {

            event.getTarget().entityDropItem(new ItemStack(itemShulkerPearl), 0.5f);
            data.setCooldown(this.maxCooldown);
        }
    }
}
项目:SimpleCorn    文件:GenericBreedHandler.java   
@SubscribeEvent
public void breed(EntityInteract event)
{
    if (event.getEntityPlayer().inventory.getCurrentItem() != null && event.getEntityPlayer().inventory.getCurrentItem().getItem() == breedItem)
    {
        if (animal.isInstance(event.getTarget()))
        {
            ItemStack itemstack = event.getEntityPlayer().inventory.getCurrentItem();

            if (((EntityAgeable) event.getTarget()).getGrowingAge() == 0 && !((EntityAnimal)event.getTarget()).isInLove())
            {
                if (!event.getEntityPlayer().capabilities.isCreativeMode)
                {
                    itemstack.shrink(1);;

                    if (itemstack.isEmpty())
                    {
                        event.getEntityPlayer().inventory.setInventorySlotContents(event.getEntityPlayer().inventory.currentItem, (ItemStack)null);
                    }
                }

                ((EntityAnimal)event.getTarget()).setInLove(event.getEntityPlayer());
                Random rand = new Random();

                for (int i = 0; i < 7; ++i)
                {
                    double d0 = event.getWorld().rand.nextGaussian() * 0.02D;
                    double d1 = event.getWorld().rand.nextGaussian() * 0.02D;
                    double d2 = event.getWorld().rand.nextGaussian() * 0.02D;

                    if (event.getWorld().isRemote){
                        event.getTarget().world.spawnParticle(EnumParticleTypes.HEART, event.getTarget().posX + rand.nextFloat() * event.getTarget().width * 2.0F - event.getTarget().width, event.getTarget().posY + 0.5D + rand.nextFloat() * event.getTarget().height, event.getTarget().posZ + rand.nextFloat() * event.getTarget().width * 2.0F - event.getTarget().width, d0, d1, d2);    
                    }
                }
            }
        }
    }
}
项目:Cyclic    文件:ItemAppleEmerald.java   
@SubscribeEvent
public void onEntityInteractEvent(EntityInteract event) {
  if (event.getEntity() instanceof EntityPlayer == false) {
    return;
  }
  EntityPlayer player = (EntityPlayer) event.getEntity();
  //    ItemStack held = player.getHeldItemMainhand();
  ItemStack itemstack = event.getItemStack();
  if (itemstack != null && itemstack.getItem() instanceof ItemAppleEmerald && itemstack.getCount() > 0) {
    if (event.getTarget() instanceof EntityVillager) {
      EntityVillager villager = ((EntityVillager) event.getTarget());
      int count = 0;
      for (MerchantRecipe merchantrecipe : villager.getRecipes(player)) {
        if (merchantrecipe.isRecipeDisabled()) {
          //vanilla code as of 1.9.4 odes this (2d6+2) 
          merchantrecipe.increaseMaxTradeUses(villager.getEntityWorld().rand.nextInt(6) + villager.getEntityWorld().rand.nextInt(6) + 2);
          count++;
        }
      }
      if (count > 0) {
        UtilChat.addChatMessage(player, UtilChat.lang("item.apple_emerald.merchant") + count);
        consumeSelf(itemstack);
      }
      event.setCanceled(true);// stop the GUI inventory opening && horse mounting
    }
  }
}
项目:Cyclic    文件:EventHorseFeed.java   
@SubscribeEvent
public void onEntityInteractEvent(EntityInteract event) {
  if (event.getEntity() instanceof EntityPlayer == false) {
    return;
  }
  EntityPlayer entityPlayer = (EntityPlayer) event.getEntity();
  ItemStack held = entityPlayer.getHeldItemMainhand();
  if (held != null && held.getItem() instanceof ItemHorseUpgrade && held.getCount() > 0
      && event.getTarget() instanceof AbstractHorse) {
    ItemHorseUpgrade.onHorseInteract((AbstractHorse) event.getTarget(), entityPlayer, held, (ItemHorseUpgrade) held.getItem());
    event.setCanceled(true);// stop the GUI inventory opening && horse mounting
  }
}
项目:CrystalMod    文件:EventHandler.java   
@SubscribeEvent
public void onEntityLivingInteract(EntityInteract event)
{
    if(event.getTarget() == null)return;

    EntityPlayer player = event.getEntityPlayer();
    ItemStack held = event.getItemStack();
    Entity entity = event.getTarget();
    if(entity instanceof AbstractHorse){
      AbstractHorse horse = (AbstractHorse)entity;
      if(HorseAccessories.handleHorseInteract(player, held, event.getHand(), horse)){
          event.setCanceled(true);
      }
    }
    if(entity instanceof EntityWolf){
        if(WolfAccessories.handleWolfInteract(player, held, event.getHand(), (EntityWolf)entity)){
            event.setCanceled(true);
        }
    }
    if(entity instanceof EntityPolarBear){
        EntityPolarBear bear = (EntityPolarBear)entity;
        if(ItemStackTools.isValid(held)){
            if(held.getItem() == ModItems.miscFood && held.getMetadata() == FoodType.WHITE_FISH_RAW.getMetadata()){
                if (!player.capabilities.isCreativeMode)
                {
                    held.shrink(1);
                }
                if (!player.getEntityWorld().isRemote){
                    if (EntityUtil.rand.nextInt(3) == 0 && !net.minecraftforge.event.ForgeEventFactory.onAnimalTame(bear, player))
                    {
                        EntityTamedPolarBear.convertToTamed(player.getEntityWorld(), bear, player);
                    }   
                }
                event.setCanceled(true);
            }
        }
    }
    if(entity instanceof EntityShulkerBullet){
        if(ItemStackTools.isValid(held)){
            if(held.getItem() == Item.getItemFromBlock(ModBlocks.jar)){
                NBTTagCompound nbt = new NBTTagCompound();
                if(held.hasTagCompound() && held.getTagCompound().hasKey(BlockJar.TILE_NBT_STACK)){
                    nbt = ItemNBTHelper.getCompound(held).getCompoundTag(BlockJar.TILE_NBT_STACK);
                }
                if((!nbt.hasKey("IsShulker") || !nbt.getBoolean("IsShulker")) && (!nbt.hasKey("Count") || nbt.getInteger("Count") <=0)){
                    nbt.setBoolean("IsShulker", true);
                    if(ItemStackTools.getStackSize(held) == 1){
                        ItemNBTHelper.getCompound(held).setTag(BlockJar.TILE_NBT_STACK, nbt);
                    } else {
                        ItemStack newStack = ItemUtil.copy(held, 1);
                        ItemNBTHelper.getCompound(newStack).setTag(BlockJar.TILE_NBT_STACK, nbt);
                        player.setHeldItem(event.getHand(), ItemUtil.consumeItem(held));
                        if(!player.inventory.addItemStackToInventory(newStack)){
                            ItemUtil.dropFromPlayer(player, newStack, false);
                        }
                    }
                    entity.setDead();
                }
            }
        }
    }
}
项目:rtap    文件:ModEvents.java   
@SubscribeEvent
public static void interact(EntityInteract event) {

    ItemStack itemstack = event.getItemStack();
    EntityPlayer player = event.getEntityPlayer();
    Entity entity = event.getTarget();
    World world = event.getWorld();

    if (world.isRemote || itemstack.equals(ItemStack.EMPTY)) {

        return;

    }

    if ( entity instanceof EntityOcelot && ((EntityOcelot) entity).isSitting() && !entity.isDead && itemstack.getItem() instanceof ItemShears) {

        if (itemstack.getItemDamage() > 1) {

            itemstack.damageItem(2, player);
            world.spawnEntity(new EntityItem(world, entity.posX, entity.posY, entity.lastTickPosZ, new ItemStack(ModItems.itemcathair)));

        } else {

            itemstack.damageItem(1, player);
            if (Math.random() > .5) {

                world.spawnEntity(new EntityItem(world, entity.posX, entity.posY, entity.lastTickPosZ, new ItemStack(ModItems.itemcathair)));

            }

        }

        if (itemstack.getMaxDamage() <= -1) {

            entity.onKillCommand();

        } else {

            if (100 / (((itemstack.getMaxDamage() + 1) / (itemstack.getItemDamage() + 1))) * Math.random() * 2 >= Math.random() * 50) {

                DamageSource killedByShears = new ModDeath("killedByShears", player);

                entity.attackEntityFrom(killedByShears, 1);

            }

        }

        event.setCanceled(true);

    }

}