Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.ignatio.wilsonsanity;
- import net.minecraft.entity.Entity;
- import net.minecraft.entity.player.EntityPlayer;
- import net.minecraft.nbt.NBTTagCompound;
- import net.minecraft.world.World;
- import net.minecraftforge.common.IExtendedEntityProperties;
- public class ExtendedPlayer implements IExtendedEntityProperties
- {
- public final static String EXT_PROP_NAME = "PlayerSanity";
- private final EntityPlayer player;
- private double playerSanity;
- public ExtendedPlayer(EntityPlayer player)
- {
- System.out.println("ExtendedPlayer instantiated. Current sanity is " + this.playerSanity + ". About to be set to 50.");
- this.player = player;
- this.playerSanity = 50.00;
- }
- public static final void register(EntityPlayer player)
- {
- player.registerExtendedProperties(ExtendedPlayer.EXT_PROP_NAME, new ExtendedPlayer(player));
- }
- public static final ExtendedPlayer get(EntityPlayer player)
- {
- return (ExtendedPlayer) player.getExtendedProperties(EXT_PROP_NAME);
- }
- //save NBT
- @Override
- public void saveNBTData(NBTTagCompound compound)
- {
- System.out.println("Wilson > (pre) saveNBTData Sanity from NBT: " + this.playerSanity);
- compound.setDouble("PlayerSanity", 25);
- System.out.println("Saved sanity: " + compound.getDouble("PlayerSanity"));
- }
- // Load NBT
- @Override
- public void loadNBTData(NBTTagCompound compound)
- {
- System.out.println("Sanity in compound at load: " + compound.getDouble("PlayerSanity"));
- this.playerSanity = compound.getDouble("PlayerSanity");
- System.out.println("Wilson > loadNBTData Sanity from NBT: " + this.playerSanity);
- }
- //from the tutorial, not sure what it does
- @Override
- public void init(Entity entity, World world)
- {
- }
- // consume some sanity
- public boolean consumeSanity(Double amount)
- {
- boolean sufficient = amount <= this.playerSanity;
- this.playerSanity -= (amount < this.playerSanity ? amount : this.playerSanity);
- return sufficient;
- }
- //add some sanity
- public void replenishSanity(Double amount)
- {
- this.playerSanity += amount;
- }
- //set the sanity directly
- public void resetSanity(Double amount)
- {
- this.playerSanity = amount;
- }
- //get the current sanity
- public double getCurrentSanity()
- {
- return this.playerSanity;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement