diff options
author | Draknyte1 <Draknyte1@hotmail.com> | 2016-12-28 16:00:53 +1000 |
---|---|---|
committer | Draknyte1 <Draknyte1@hotmail.com> | 2016-12-28 16:00:53 +1000 |
commit | f66fb1526fa85554842db425652545448495a2a0 (patch) | |
tree | a90cf67cd0f240e73f2d3ab2aa2c4b363b14b5bf /src/Java/api/cofh/energy/ItemEnergyContainer.java | |
parent | d41a850da5a9bcfe7dda85dba2aad08387833d04 (diff) | |
download | GT5-Unofficial-f66fb1526fa85554842db425652545448495a2a0.tar.gz GT5-Unofficial-f66fb1526fa85554842db425652545448495a2a0.tar.bz2 GT5-Unofficial-f66fb1526fa85554842db425652545448495a2a0.zip |
+ Added framework based on opensource works for player movement modification.
+ Added support for the builders ring to toggle Sneak on and Sprinting off while worn.
+ Added PlayerAPI.
% Moved COFH api files into the same package as PlayerAPI.
Diffstat (limited to 'src/Java/api/cofh/energy/ItemEnergyContainer.java')
-rw-r--r-- | src/Java/api/cofh/energy/ItemEnergyContainer.java | 98 |
1 files changed, 98 insertions, 0 deletions
diff --git a/src/Java/api/cofh/energy/ItemEnergyContainer.java b/src/Java/api/cofh/energy/ItemEnergyContainer.java new file mode 100644 index 0000000000..f4da898919 --- /dev/null +++ b/src/Java/api/cofh/energy/ItemEnergyContainer.java @@ -0,0 +1,98 @@ +package api.cofh.energy; + +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; + +public class ItemEnergyContainer + extends Item + implements IEnergyContainerItem +{ + protected int capacity; + protected int maxReceive; + protected int maxExtract; + + public ItemEnergyContainer() {} + + public ItemEnergyContainer(int capacity) + { + this(capacity, capacity, capacity); + } + + public ItemEnergyContainer(int capacity, int maxTransfer) + { + this(capacity, maxTransfer, maxTransfer); + } + + public ItemEnergyContainer(int capacity, int maxReceive, int maxExtract) + { + this.capacity = capacity; + this.maxReceive = maxReceive; + this.maxExtract = maxExtract; + } + + public ItemEnergyContainer setCapacity(int capacity) + { + this.capacity = capacity; + return this; + } + + public void setMaxTransfer(int maxTransfer) + { + setMaxReceive(maxTransfer); + setMaxExtract(maxTransfer); + } + + public void setMaxReceive(int maxReceive) + { + this.maxReceive = maxReceive; + } + + public void setMaxExtract(int maxExtract) + { + this.maxExtract = maxExtract; + } + + public int receiveEnergy(ItemStack container, int maxReceive, boolean simulate) + { + if (container.stackTagCompound == null) { + container.stackTagCompound = new NBTTagCompound(); + } + int energy = container.stackTagCompound.getInteger("Energy"); + int energyReceived = Math.min(this.capacity - energy, Math.min(this.maxReceive, maxReceive)); + if (!simulate) + { + energy += energyReceived; + container.stackTagCompound.setInteger("Energy", energy); + } + return energyReceived; + } + + public int extractEnergy(ItemStack container, int maxExtract, boolean simulate) + { + if ((container.stackTagCompound == null) || (!container.stackTagCompound.hasKey("Energy"))) { + return 0; + } + int energy = container.stackTagCompound.getInteger("Energy"); + int energyExtracted = Math.min(energy, Math.min(this.maxExtract, maxExtract)); + if (!simulate) + { + energy -= energyExtracted; + container.stackTagCompound.setInteger("Energy", energy); + } + return energyExtracted; + } + + public int getEnergyStored(ItemStack container) + { + if ((container.stackTagCompound == null) || (!container.stackTagCompound.hasKey("Energy"))) { + return 0; + } + return container.stackTagCompound.getInteger("Energy"); + } + + public int getMaxEnergyStored(ItemStack container) + { + return this.capacity; + } +} |