aboutsummaryrefslogtreecommitdiff
path: root/src/Java/gtPlusPlus/core/slots/SlotGtToolElectric.java
diff options
context:
space:
mode:
authordraknyte1 <draknyte1@hotmail.com>2016-11-02 15:49:00 +1000
committerdraknyte1 <draknyte1@hotmail.com>2016-11-02 15:49:00 +1000
commitd594987b2cfdefa447ee585a68d4a4bef4ece3a5 (patch)
tree814813fc14ce5dcd8dfa7aeaecd939ac42d12877 /src/Java/gtPlusPlus/core/slots/SlotGtToolElectric.java
parent26292158575a0f0acb51ae50715887f871d2b5a0 (diff)
parent49a520da5da01594b5c42652d9db5c7c04e49ad8 (diff)
downloadGT5-Unofficial-d594987b2cfdefa447ee585a68d4a4bef4ece3a5.tar.gz
GT5-Unofficial-d594987b2cfdefa447ee585a68d4a4bef4ece3a5.tar.bz2
GT5-Unofficial-d594987b2cfdefa447ee585a68d4a4bef4ece3a5.zip
Merge branch 'master' of https://github.com/draknyte1/GTplusplus
Diffstat (limited to 'src/Java/gtPlusPlus/core/slots/SlotGtToolElectric.java')
-rw-r--r--src/Java/gtPlusPlus/core/slots/SlotGtToolElectric.java98
1 files changed, 98 insertions, 0 deletions
diff --git a/src/Java/gtPlusPlus/core/slots/SlotGtToolElectric.java b/src/Java/gtPlusPlus/core/slots/SlotGtToolElectric.java
new file mode 100644
index 0000000000..461fa6ff04
--- /dev/null
+++ b/src/Java/gtPlusPlus/core/slots/SlotGtToolElectric.java
@@ -0,0 +1,98 @@
+package gtPlusPlus.core.slots;
+
+import gregtech.api.items.GT_MetaGenerated_Tool;
+import gtPlusPlus.core.util.Utils;
+import ic2.api.info.Info;
+import ic2.api.item.ElectricItem;
+import ic2.api.item.IElectricItem;
+import net.minecraft.init.Items;
+import net.minecraft.inventory.IInventory;
+import net.minecraft.item.ItemStack;
+
+public class SlotGtToolElectric extends SlotGtTool {
+ public int tier;
+ private ItemStack content;
+
+ public SlotGtToolElectric(IInventory base, int x, int y, int z, int tier, boolean allowRedstoneDust)
+ {
+ super(base, x, y, z);
+ this.tier = tier;
+ this.allowRedstoneDust = allowRedstoneDust;
+ }
+
+ public boolean accepts(ItemStack stack)
+ {
+ if (stack == null) {
+ return false;
+ }
+ if ((stack.getItem() == Items.redstone) && (!this.allowRedstoneDust)) {
+ return false;
+ }
+ return (Info.itemEnergy.getEnergyValue(stack) > 0.0D) || (ElectricItem.manager.discharge(stack, (1.0D / 0.0D), this.tier, true, true, true) > 0.0D);
+ }
+
+ public double discharge(double amount, boolean ignoreLimit)
+ {
+ if (amount <= 0.0D) {
+ throw new IllegalArgumentException("Amount must be > 0.");
+ }
+ ItemStack stack = get(0);
+ if (stack == null) {
+ return 0.0D;
+ }
+ double realAmount = ElectricItem.manager.discharge(stack, amount, this.tier, ignoreLimit, true, false);
+ if (realAmount <= 0.0D)
+ {
+ realAmount = Info.itemEnergy.getEnergyValue(stack);
+ if (realAmount <= 0.0D) {
+ return 0.0D;
+ }
+ stack.stackSize -= 1;
+ if (stack.stackSize <= 0) {
+ put(0, null);
+ }
+ }
+ return realAmount;
+ }
+
+ public void setTier(int tier1)
+ {
+ this.tier = tier1;
+ }
+
+ public boolean allowRedstoneDust = true;
+
+ public ItemStack get()
+ {
+ return get(0);
+ }
+
+ public ItemStack get(int index)
+ {
+ return this.content;
+ }
+
+ public void put(ItemStack content)
+ {
+ put(0, content);
+ }
+
+ public void put(int index, ItemStack content)
+ {
+ this.content = content;
+ onChanged();
+ }
+
+ public void onChanged() {}
+
+ @Override
+ public boolean isItemValid(ItemStack itemstack) {
+ if (itemstack.getItem() instanceof GT_MetaGenerated_Tool || itemstack.getItem() instanceof IElectricItem){
+ Utils.LOG_WARNING(itemstack.getDisplayName()+" is a valid Tool.");
+ return true;
+ }
+ Utils.LOG_WARNING(itemstack.getDisplayName()+" is not a valid Tool.");
+ return false;
+ }
+
+}