summaryrefslogtreecommitdiff
path: root/src/main/java/darkknight/jewelrycraft/entities/EntityHalfHeart.java
blob: 4fad3096c59c4e99a47e2247676dba6543cd80c2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
/**
 * 
 */
package darkknight.jewelrycraft.entities;

import net.minecraft.entity.SharedMonsterAttributes;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.potion.Potion;
import net.minecraft.potion.PotionEffect;
import net.minecraft.world.World;
import darkknight.jewelrycraft.JewelrycraftMod;
import darkknight.jewelrycraft.network.PacketRequestPlayerInfo;
import darkknight.jewelrycraft.util.PlayerUtils;
import darkknight.jewelrycraft.util.Variables;

/**
 * @author Sorin
 */
public class EntityHalfHeart extends EntityHeart
{
    public EntityHalfHeart(World world)
    {
        super(world);
    }
    
    @Override
    public void onCollideWithPlayer(EntityPlayer player)
    {
        if (!player.worldObj.isRemote){
            NBTTagCompound playerInfo = PlayerUtils.getModPlayerPersistTag(player, Variables.MODID);
            if (getType().equals("Red") && player.getHealth() < player.getMaxHealth()){
                player.heal(1f);
                this.setDead();
            }else if (getType().equals("White") && playerInfo.getFloat("WhiteHeart") > 0.1F){
                playerInfo.setFloat(getType() + "Heart", 0F);
                player.getEntityAttribute(SharedMonsterAttributes.maxHealth).setBaseValue(player.getMaxHealth() + 2f);
                this.setDead();
            }else if (!getType().equals("Red")){
                playerInfo.setFloat(getType() + "Heart", playerInfo.getFloat(getType() + "Heart") + 1.0F);
                this.setDead();
            }
        }
        else JewelrycraftMod.netWrapper.sendToServer(new PacketRequestPlayerInfo());
    }
}