aboutsummaryrefslogtreecommitdiff
path: root/src/Java/gtPlusPlus/core/slots
diff options
context:
space:
mode:
Diffstat (limited to 'src/Java/gtPlusPlus/core/slots')
-rw-r--r--src/Java/gtPlusPlus/core/slots/SlotBlueprint.java30
-rw-r--r--src/Java/gtPlusPlus/core/slots/SlotGeneric.java24
-rw-r--r--src/Java/gtPlusPlus/core/slots/SlotGtToolElectric.java98
-rw-r--r--src/Java/gtPlusPlus/core/slots/SlotNoInput.java23
-rw-r--r--src/Java/gtPlusPlus/core/slots/SlotOutput.java101
5 files changed, 276 insertions, 0 deletions
diff --git a/src/Java/gtPlusPlus/core/slots/SlotBlueprint.java b/src/Java/gtPlusPlus/core/slots/SlotBlueprint.java
new file mode 100644
index 0000000000..3c5c30966e
--- /dev/null
+++ b/src/Java/gtPlusPlus/core/slots/SlotBlueprint.java
@@ -0,0 +1,30 @@
+package gtPlusPlus.core.slots;
+
+import gtPlusPlus.core.interfaces.IItemBlueprint;
+import gtPlusPlus.core.util.Utils;
+import net.minecraft.inventory.IInventory;
+import net.minecraft.inventory.Slot;
+import net.minecraft.item.ItemStack;
+
+public class SlotBlueprint extends Slot{
+
+ public SlotBlueprint(IInventory inventory, int x, int y, int z) {
+ super(inventory, x, y, z);
+ }
+
+ @Override
+ public boolean isItemValid(ItemStack itemstack) {
+ if (itemstack.getItem() instanceof IItemBlueprint){
+ Utils.LOG_WARNING(itemstack.getDisplayName()+" is a valid Blueprint.");
+ return true;
+ }
+ Utils.LOG_WARNING(itemstack.getDisplayName()+" is not a valid Blueprint.");
+ return false;
+ }
+
+ @Override
+ public int getSlotStackLimit() {
+ return 1;
+ }
+
+}
diff --git a/src/Java/gtPlusPlus/core/slots/SlotGeneric.java b/src/Java/gtPlusPlus/core/slots/SlotGeneric.java
new file mode 100644
index 0000000000..bf7dc1fff5
--- /dev/null
+++ b/src/Java/gtPlusPlus/core/slots/SlotGeneric.java
@@ -0,0 +1,24 @@
+package gtPlusPlus.core.slots;
+
+import net.minecraft.inventory.IInventory;
+import net.minecraft.inventory.Slot;
+import net.minecraft.item.ItemStack;
+
+public class SlotGeneric extends Slot{
+
+ public SlotGeneric(IInventory inventory, int x, int y, int z) {
+ super(inventory, x, y, z);
+
+ }
+
+ @Override
+ public boolean isItemValid(ItemStack itemstack) {
+ return true;
+ }
+
+ @Override
+ public int getSlotStackLimit() {
+ return 64;
+ }
+
+}
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;
+ }
+
+}
diff --git a/src/Java/gtPlusPlus/core/slots/SlotNoInput.java b/src/Java/gtPlusPlus/core/slots/SlotNoInput.java
new file mode 100644
index 0000000000..fe51631a5d
--- /dev/null
+++ b/src/Java/gtPlusPlus/core/slots/SlotNoInput.java
@@ -0,0 +1,23 @@
+package gtPlusPlus.core.slots;
+
+import net.minecraft.inventory.IInventory;
+import net.minecraft.inventory.Slot;
+import net.minecraft.item.ItemStack;
+
+public class SlotNoInput extends Slot{
+
+ public SlotNoInput(IInventory inventory, int x, int y, int z) {
+ super(inventory, x, y, z);
+ }
+
+ @Override
+ public boolean isItemValid(ItemStack itemstack) {
+ return false;
+ }
+
+ @Override
+ public int getSlotStackLimit() {
+ return 0;
+ }
+
+}
diff --git a/src/Java/gtPlusPlus/core/slots/SlotOutput.java b/src/Java/gtPlusPlus/core/slots/SlotOutput.java
new file mode 100644
index 0000000000..a0f895d554
--- /dev/null
+++ b/src/Java/gtPlusPlus/core/slots/SlotOutput.java
@@ -0,0 +1,101 @@
+package gtPlusPlus.core.slots;
+
+import net.minecraft.entity.player.EntityPlayer;
+import net.minecraft.inventory.IInventory;
+import net.minecraft.inventory.InventoryCrafting;
+import net.minecraft.item.ItemStack;
+import net.minecraftforge.common.MinecraftForge;
+import net.minecraftforge.event.entity.player.PlayerDestroyItemEvent;
+import cpw.mods.fml.common.FMLCommonHandler;
+
+public class SlotOutput extends SlotCrafting{
+
+ private final IInventory craftMatrix;
+ private final EntityPlayer thePlayer;
+ private int amountCrafted;
+
+
+ public SlotOutput(EntityPlayer player, InventoryCrafting craftingInventory, IInventory p_i45790_3_, int slotIndex, int xPosition, int yPosition)
+ {
+ super(player, craftingInventory, p_i45790_3_, slotIndex, xPosition, yPosition);
+ this.thePlayer = player;
+ this.craftMatrix = craftingInventory;
+ }
+ /**
+ * Check if the stack is a valid item for this slot. Always true beside for the armor slots.
+ */
+ @Override
+ public boolean isItemValid(ItemStack par1ItemStack)
+ {
+ return false;
+ }
+ /**
+ * Decrease the size of the stack in slot (first int arg) by the amount of the second int arg. Returns the new
+ * stack.
+ */
+ @Override
+ public ItemStack decrStackSize(int par1)
+ {
+ if (this.getHasStack())
+ {
+ this.amountCrafted += Math.min(par1, this.getStack().stackSize);
+ }
+ return super.decrStackSize(par1);
+ }
+ /**
+ * the itemStack passed in is the output - ie, iron ingots, and pickaxes, not ore and wood. Typically increases an
+ * internal count then calls onCrafting(item).
+ */
+ @Override
+ protected void onCrafting(ItemStack par1ItemStack, int par2)
+ {
+ this.amountCrafted += par2;
+ this.onCrafting(par1ItemStack);
+ }
+ /**
+ * the itemStack passed in is the output - ie, iron ingots, and pickaxes, not ore and wood.
+ */
+ @Override
+ protected void onCrafting(ItemStack stack)
+ {
+ stack.onCrafting(this.thePlayer.worldObj, this.thePlayer, this.amountCrafted);
+ this.amountCrafted = 0;
+ }
+
+ @Override
+ public void onPickupFromSlot(EntityPlayer playerIn, ItemStack stack)
+ {
+ {
+ FMLCommonHandler.instance().firePlayerCraftingEvent(playerIn, stack, craftMatrix);
+ this.onCrafting(stack);
+ for (int i = 0; i < this.craftMatrix.getSizeInventory(); ++i)
+ {
+ ItemStack itemstack1 = this.craftMatrix.getStackInSlot(i);
+ if (itemstack1 != null)
+ {
+ this.craftMatrix.decrStackSize(i, 1);
+ if (itemstack1.getItem().hasContainerItem(itemstack1))
+ {
+ ItemStack itemstack2 = itemstack1.getItem().getContainerItem(itemstack1);
+ if (itemstack2.isItemStackDamageable() && itemstack2.getItemDamage() > itemstack2.getMaxDamage())
+ {
+ MinecraftForge.EVENT_BUS.post(new PlayerDestroyItemEvent(thePlayer, itemstack2));
+ itemstack2 = null;
+ }
+ if (!this.thePlayer.inventory.addItemStackToInventory(itemstack2))
+ {
+ if (this.craftMatrix.getStackInSlot(i) == null)
+ {
+ this.craftMatrix.setInventorySlotContents(i, itemstack2);
+ }
+ else
+ {
+ this.thePlayer.dropPlayerItemWithRandomChoice(itemstack2, false);
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+} \ No newline at end of file