Search in sources :

Example 41 with EnumHand

use of net.minecraft.util.EnumHand in project ElementalSorcery by Yuzunyannn.

the class ItemAncientPaper method doUnscramble.

/**
 * 进行一次解读
 */
protected void doUnscramble(AncientPaper ap, World world, EntityPlayer player, EnumHand handIn) {
    if (world.isRemote)
        return;
    NBTTagCompound playerData = EventServer.getPlayerNBT(player);
    // 上次的时间
    long nextTime = playerData.getLong("unsNext");
    if (nextTime > world.getWorldTime() && !player.isCreative()) {
        player.sendMessage(new TextComponentTranslation("info.want.not.unscramble").setStyle(new Style().setColor(TextFormatting.GRAY).setBold(true)));
        return;
    }
    Random rand = world.rand;
    // 一些前置处理
    EnumHand offHand = handIn == EnumHand.MAIN_HAND ? EnumHand.OFF_HAND : EnumHand.MAIN_HAND;
    int noteEnergy = ItemUnscrambleNote.getNoteEnergy(player.getHeldItem(offHand), player);
    float energy = Math.max(playerData.getFloat("unsEnergy"), 1);
    boolean setTired = rand.nextFloat() < 0.5f / energy;
    if (setTired)
        playerData.setLong("unsNext", world.getWorldTime() + 12000);
    // 增加研究力
    playerData.setFloat("unsEnergy", Math.min(energy + 0.1f, 3));
    ItemUnscrambleNote.growNoteEnergy(player.getHeldItem(offHand), player, rand.nextInt(3), false);
    // 增加进度
    float originProgress = ap.getProgress();
    float grow = rand.nextFloat() * 0.04f + 0.01f + rand.nextFloat() * noteEnergy / 1000;
    ap.setProgress(originProgress + grow);
    if (player instanceof EntityPlayerMP)
        ESCriteriaTriggers.ES_TRING.trigger((EntityPlayerMP) player, "unscramble:once");
    if (!ap.hasType())
        return;
    // 增加研究点数
    KnowledgeType type = ap.getType();
    List<Entry<String, Integer>> topics = type.getTopics();
    if (topics == null)
        return;
    Entry<String, Integer> topic = topics.get(rand.nextInt(topics.size()));
    float rCount = topic.getValue() * grow * (ap.getEnd() - ap.getStart()) / 100.0f;
    int count = MathHelper.floor(rCount);
    float expect = (rCount) - MathHelper.floor(rCount);
    count += rand.nextFloat() <= expect ? 1 : 0;
    if (count > 0)
        Researcher.research(player, topic.getKey(), count);
}
Also used : TextComponentTranslation(net.minecraft.util.text.TextComponentTranslation) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) TextComponentString(net.minecraft.util.text.TextComponentString) Entry(java.util.Map.Entry) Random(java.util.Random) EnumHand(net.minecraft.util.EnumHand) Style(net.minecraft.util.text.Style) EntityPlayerMP(net.minecraft.entity.player.EntityPlayerMP) KnowledgeType(yuzunyannn.elementalsorcery.elf.research.KnowledgeType)

Example 42 with EnumHand

use of net.minecraft.util.EnumHand in project ElementalSorcery by Yuzunyannn.

the class ItemDejectedTear method onUpdate.

@Override
public void onUpdate(ItemStack stack, World worldIn, Entity entityIn, int itemSlot, boolean isSelected) {
    if (worldIn.isRemote)
        return;
    EnumHand hand = ItemVortex.inEntityHand(entityIn, stack, itemSlot, isSelected);
    if (hand == null)
        return;
    if (entityIn.ticksExisted % 200 == 0) {
        ((EntityLivingBase) entityIn).addPotionEffect(new PotionEffect(MobEffects.SLOWNESS, 220, 2));
        ((EntityLivingBase) entityIn).addPotionEffect(new PotionEffect(MobEffects.ABSORPTION, 220, 1));
        ((EntityLivingBase) entityIn).addPotionEffect(new PotionEffect(MobEffects.RESISTANCE, 220, 2));
    }
}
Also used : PotionEffect(net.minecraft.potion.PotionEffect) EnumHand(net.minecraft.util.EnumHand) EntityLivingBase(net.minecraft.entity.EntityLivingBase)

Example 43 with EnumHand

use of net.minecraft.util.EnumHand in project ElementalSorcery by Yuzunyannn.

the class ItemDreadGem method onUpdate.

@Override
public void onUpdate(ItemStack stack, World worldIn, Entity entityIn, int itemSlot, boolean isSelected) {
    if (worldIn.isRemote)
        return;
    EnumHand hand = ItemVortex.inEntityHand(entityIn, stack, itemSlot, isSelected);
    if (hand == null)
        return;
    if (entityIn.ticksExisted % 100 == 0) {
        AxisAlignedBB aabb = WorldHelper.createAABB(entityIn.getPositionVector(), 5, 2, 1);
        List<EntityLiving> mobs = worldIn.getEntitiesWithinAABB(EntityLiving.class, aabb, (e) -> {
            return e instanceof IMob;
        });
        for (EntityLiving mob : mobs) {
            EntityLivingBase player = (EntityLivingBase) entityIn;
            if (mob.getRevengeTarget() != null)
                mob.setRevengeTarget(player);
            else
                mob.setAttackTarget(player);
        }
    }
}
Also used : AxisAlignedBB(net.minecraft.util.math.AxisAlignedBB) EntityLiving(net.minecraft.entity.EntityLiving) IMob(net.minecraft.entity.monster.IMob) EnumHand(net.minecraft.util.EnumHand) EntityLivingBase(net.minecraft.entity.EntityLivingBase)

Example 44 with EnumHand

use of net.minecraft.util.EnumHand in project ElementalSorcery by Yuzunyannn.

the class ItemFusionCrystal method onUpdate.

@Override
public void onUpdate(ItemStack stack, World worldIn, Entity entityIn, int itemSlot, boolean isSelected) {
    if (entityIn.ticksExisted % (60 * 20) != 0)
        return;
    if (worldIn.isRemote)
        return;
    EnumHand hand = ItemVortex.inEntityHand(entityIn, stack, itemSlot, isSelected);
    if (hand == null)
        return;
    Random rand = worldIn.rand;
    EntityEquipmentSlot slot = hand == EnumHand.MAIN_HAND ? EntityEquipmentSlot.MAINHAND : EntityEquipmentSlot.OFFHAND;
    stack.setTagCompound(null);
    float at = 0.01f + rand.nextFloat() * 0.19f;
    ItemLifeLeather.addAttributeModifier(stack, SharedMonsterAttributes.MAX_HEALTH, slot, at, 1);
    ItemLifeLeather.addAttributeModifier(stack, SharedMonsterAttributes.ATTACK_SPEED, slot, at, 1);
    ItemLifeLeather.addAttributeModifier(stack, SharedMonsterAttributes.MOVEMENT_SPEED, slot, at, 1);
    ItemLifeLeather.addAttributeModifier(stack, SharedMonsterAttributes.LUCK, slot, at, 1);
}
Also used : Random(java.util.Random) EntityEquipmentSlot(net.minecraft.inventory.EntityEquipmentSlot) EnumHand(net.minecraft.util.EnumHand)

Example 45 with EnumHand

use of net.minecraft.util.EnumHand in project ElementalSorcery by Yuzunyannn.

the class ItemCalamityGem method onUpdate.

@Override
public void onUpdate(ItemStack stack, World worldIn, Entity entityIn, int itemSlot, boolean isSelected) {
    if (worldIn.isRemote)
        return;
    if (entityIn.ticksExisted % 100 == 0) {
        EnumHand hand = ItemVortex.inEntityHand(entityIn, stack, itemSlot, isSelected);
        if (hand == null)
            return;
        calamityEntity((EntityLivingBase) entityIn, 100);
    }
}
Also used : EnumHand(net.minecraft.util.EnumHand)

Aggregations

EnumHand (net.minecraft.util.EnumHand)117 ItemStack (net.minecraft.item.ItemStack)62 EntityPlayer (net.minecraft.entity.player.EntityPlayer)55 BlockPos (net.minecraft.util.math.BlockPos)45 EnumFacing (net.minecraft.util.EnumFacing)32 Vec3d (net.minecraft.util.math.Vec3d)24 World (net.minecraft.world.World)24 Entity (net.minecraft.entity.Entity)23 RayTraceResult (net.minecraft.util.math.RayTraceResult)21 EntityLivingBase (net.minecraft.entity.EntityLivingBase)19 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)19 Item (net.minecraft.item.Item)18 CPacketPlayerTryUseItemOnBlock (net.minecraft.network.play.client.CPacketPlayerTryUseItemOnBlock)18 IBlockState (net.minecraft.block.state.IBlockState)17 TileEntity (net.minecraft.tileentity.TileEntity)16 EntityPlayerMP (net.minecraft.entity.player.EntityPlayerMP)15 AxisAlignedBB (net.minecraft.util.math.AxisAlignedBB)14 SideOnly (net.minecraftforge.fml.relauncher.SideOnly)13 List (java.util.List)12 Block (net.minecraft.block.Block)11