-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
110 additions
and
99 deletions.
There are no files selected for viewing
83 changes: 83 additions & 0 deletions
83
src/main/java/elucent/rootsclassic/capability/ManaCapabilityProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
package elucent.rootsclassic.capability; | ||
|
||
import net.minecraft.nbt.NBTBase; | ||
import net.minecraft.nbt.NBTTagCompound; | ||
import net.minecraft.util.EnumFacing; | ||
import net.minecraftforge.common.capabilities.Capability; | ||
import net.minecraftforge.common.capabilities.ICapabilityProvider; | ||
import net.minecraftforge.common.util.INBTSerializable; | ||
|
||
public class ManaCapabilityProvider implements ICapabilityProvider, INBTSerializable, IManaCapability { | ||
|
||
// private EntityPlayer player; | ||
float mana; | ||
float maxMana; | ||
|
||
ManaCapabilityProvider(boolean isNew) { | ||
if (isNew) { | ||
mana = 40; | ||
maxMana = 40; | ||
} | ||
} | ||
|
||
@Override | ||
public boolean hasCapability(Capability<?> capability, EnumFacing facing) { | ||
return RootsCapabilityManager.manaCapability != null && capability == RootsCapabilityManager.manaCapability; | ||
} | ||
|
||
@Override | ||
public <T> T getCapability(Capability<T> capability, EnumFacing facing) { | ||
if (capability == RootsCapabilityManager.manaCapability) { | ||
return RootsCapabilityManager.manaCapability.cast(this); | ||
} | ||
return null; | ||
} | ||
|
||
@Override | ||
public float getMana() { | ||
return mana; | ||
} | ||
|
||
@Override | ||
public float getMaxMana() { | ||
return maxMana; | ||
} | ||
|
||
@Override | ||
public void setMana(float mana) { | ||
this.mana = mana; | ||
if (mana < 0) { | ||
this.mana = 0; | ||
} | ||
if (mana > getMaxMana()) { | ||
this.mana = getMaxMana(); | ||
} | ||
} | ||
|
||
@Override | ||
public void setMaxMana(float maxMana) { | ||
this.maxMana = maxMana; | ||
} | ||
|
||
@Override | ||
public NBTBase serializeNBT() { | ||
NBTTagCompound tag = new NBTTagCompound(); | ||
tag.setFloat("maxMana", getMaxMana()); | ||
tag.setFloat("mana", getMana()); | ||
return tag; | ||
} | ||
|
||
@Override | ||
public void deserializeNBT(NBTBase nbt) { | ||
if (nbt instanceof NBTTagCompound) { | ||
NBTTagCompound tag = (NBTTagCompound) nbt; | ||
//System.out.println("Loading NBT! Mana=" + tag.getFloat("mana") + "/" + tag.getFloat("maxMana")); | ||
if (tag.hasKey("maxMana")) { | ||
setMaxMana(tag.getFloat("maxMana")); | ||
} | ||
if (tag.hasKey("mana")) { | ||
setMana(tag.getFloat("mana")); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters