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

项目:uniquecrops    文件:EmblemRainbow.java   
@SubscribeEvent
public void onSheared(EntityInteractSpecific event) {

    ItemStack rainbow = BaublesApi.getBaublesHandler((EntityPlayer)event.getEntityPlayer()).getStackInSlot(6);
    if (rainbow == null || (rainbow != null && rainbow.getItem() != this)) return;

    if (!(event.getTarget() instanceof IShearable)) return;
    if (!(event.getTarget() instanceof EntitySheep) || (event.getTarget() instanceof EntitySheep && ((EntitySheep)event.getTarget()).getSheared())) return;
    if (event.getItemStack() == null || (event.getItemStack() != null && !(event.getItemStack().getItem() instanceof ItemShears))) return;

    int fortune = EnchantmentHelper.getEnchantmentLevel(Enchantments.FORTUNE, event.getItemStack());
    if (!event.getWorld().isRemote) {
        List<ItemStack> wools = ((IShearable)event.getTarget()).onSheared(event.getItemStack(), event.getWorld(), event.getPos(), fortune);
        for (ItemStack is : wools) {
            Random rand = new Random();
            is.setItemDamage(rand.nextInt(15));
            EntityItem wool = new EntityItem(event.getWorld(), event.getTarget().posX, event.getTarget().posY, event.getTarget().posZ, is);
            event.getWorld().spawnEntityInWorld(wool);
        }
    }
}
项目:Aether-Legacy    文件:AetherEventHandler.java   
@SubscribeEvent
public void onMilkedCow(EntityInteractSpecific event)
{
    if (event.getTarget() instanceof EntityCow || event.getTarget() instanceof EntityFlyingCow)
    {
        EntityPlayer player = event.getEntityPlayer();
        ItemStack heldItem = player.getHeldItem(event.getHand());

        if (heldItem != null && heldItem.getItem() == ItemsAether.skyroot_bucket && EnumSkyrootBucketType.getType(heldItem.getMetadata()) == EnumSkyrootBucketType.Empty)
        {
            if (--heldItem.stackSize == 0)
            {
                player.setHeldItem(event.getHand(), new ItemStack(ItemsAether.skyroot_bucket, 1, EnumSkyrootBucketType.Milk.meta));
            }
            else if (!player.inventory.addItemStackToInventory(new ItemStack(ItemsAether.skyroot_bucket, 1, EnumSkyrootBucketType.Milk.meta)))
            {
                player.dropItem(new ItemStack(ItemsAether.skyroot_bucket, 1, EnumSkyrootBucketType.Milk.meta), false);
            }
        }
    }
}
项目:TaleCraft    文件:TaleCraftEventHandler.java   
@SubscribeEvent
public void villagerInteract(EntityInteractSpecific e){
    /* XXX: Commented out because disabling features is NOT okay.
    if(e.getTarget() instanceof EntityVillager){
        if(e.getSide() == Side.CLIENT){
            e.getEntityPlayer().addChatComponentMessage(new TextComponentString(TextFormatting.RED + "Villager trading is disabled in TaleCraft. Use the NPC instead."));
        }
        e.setCanceled(true);
    }
    //*/
}