001package net.minecraft.entity.player;
002
003import cpw.mods.fml.relauncher.Side;
004import cpw.mods.fml.relauncher.SideOnly;
005import net.minecraft.nbt.NBTTagCompound;
006
007public class PlayerCapabilities
008{
009    /** Disables player damage. */
010    public boolean disableDamage = false;
011
012    /** Sets/indicates whether the player is flying. */
013    public boolean isFlying = false;
014
015    /** whether or not to allow the player to fly when they double jump. */
016    public boolean allowFlying = false;
017
018    /**
019     * Used to determine if creative mode is enabled, and therefore if items should be depleted on usage
020     */
021    public boolean isCreativeMode = false;
022
023    /** Indicates whether the player is allowed to modify the surroundings */
024    public boolean allowEdit = true;
025    private float flySpeed = 0.05F;
026    private float walkSpeed = 0.1F;
027
028    public void writeCapabilitiesToNBT(NBTTagCompound par1NBTTagCompound)
029    {
030        NBTTagCompound nbttagcompound1 = new NBTTagCompound();
031        nbttagcompound1.setBoolean("invulnerable", this.disableDamage);
032        nbttagcompound1.setBoolean("flying", this.isFlying);
033        nbttagcompound1.setBoolean("mayfly", this.allowFlying);
034        nbttagcompound1.setBoolean("instabuild", this.isCreativeMode);
035        nbttagcompound1.setBoolean("mayBuild", this.allowEdit);
036        nbttagcompound1.setFloat("flySpeed", this.flySpeed);
037        nbttagcompound1.setFloat("walkSpeed", this.walkSpeed);
038        par1NBTTagCompound.setTag("abilities", nbttagcompound1);
039    }
040
041    public void readCapabilitiesFromNBT(NBTTagCompound par1NBTTagCompound)
042    {
043        if (par1NBTTagCompound.hasKey("abilities"))
044        {
045            NBTTagCompound nbttagcompound1 = par1NBTTagCompound.getCompoundTag("abilities");
046            this.disableDamage = nbttagcompound1.getBoolean("invulnerable");
047            this.isFlying = nbttagcompound1.getBoolean("flying");
048            this.allowFlying = nbttagcompound1.getBoolean("mayfly");
049            this.isCreativeMode = nbttagcompound1.getBoolean("instabuild");
050
051            if (nbttagcompound1.hasKey("flySpeed"))
052            {
053                this.flySpeed = nbttagcompound1.getFloat("flySpeed");
054                this.walkSpeed = nbttagcompound1.getFloat("walkSpeed");
055            }
056
057            if (nbttagcompound1.hasKey("mayBuild"))
058            {
059                this.allowEdit = nbttagcompound1.getBoolean("mayBuild");
060            }
061        }
062    }
063
064    public float getFlySpeed()
065    {
066        return this.flySpeed;
067    }
068
069    @SideOnly(Side.CLIENT)
070    public void setFlySpeed(float par1)
071    {
072        this.flySpeed = par1;
073    }
074
075    public float getWalkSpeed()
076    {
077        return this.walkSpeed;
078    }
079
080    @SideOnly(Side.CLIENT)
081    public void setPlayerWalkSpeed(float par1)
082    {
083        this.walkSpeed = par1;
084    }
085}