From 311ab89f93558233a40079f7cb16605b141b5346 Mon Sep 17 00:00:00 2001 From: Johann Bernhardt Date: Sun, 12 Dec 2021 19:38:06 +0100 Subject: Move sources and resources --- .../java/gtPlusPlus/core/slots/SlotAirFilter.java | 30 ++++ .../java/gtPlusPlus/core/slots/SlotBlueprint.java | 31 +++++ .../java/gtPlusPlus/core/slots/SlotBuzzSaw.java | 77 +++++++++++ .../core/slots/SlotChemicalPlantInput.java | 45 ++++++ .../java/gtPlusPlus/core/slots/SlotCrafting.java | 151 +++++++++++++++++++++ .../core/slots/SlotCraftingNoCollect.java | 147 ++++++++++++++++++++ .../java/gtPlusPlus/core/slots/SlotDataStick.java | 42 ++++++ .../java/gtPlusPlus/core/slots/SlotElectric.java | 45 ++++++ src/main/java/gtPlusPlus/core/slots/SlotFrame.java | 26 ++++ .../java/gtPlusPlus/core/slots/SlotFuelRod.java | 55 ++++++++ .../java/gtPlusPlus/core/slots/SlotGeneric.java | 23 ++++ .../java/gtPlusPlus/core/slots/SlotGtTool.java | 33 +++++ .../gtPlusPlus/core/slots/SlotGtToolElectric.java | 94 +++++++++++++ .../core/slots/SlotIntegratedCircuit.java | 105 ++++++++++++++ .../gtPlusPlus/core/slots/SlotItemBackpackInv.java | 26 ++++ .../java/gtPlusPlus/core/slots/SlotJukebox.java | 37 +++++ .../gtPlusPlus/core/slots/SlotLockedInput.java | 57 ++++++++ .../java/gtPlusPlus/core/slots/SlotLunchBox.java | 30 ++++ .../gtPlusPlus/core/slots/SlotMagicToolBag.java | 29 ++++ .../gtPlusPlus/core/slots/SlotModularBauble.java | 32 +++++ .../core/slots/SlotModularBaubleUpgrades.java | 56 ++++++++ .../java/gtPlusPlus/core/slots/SlotNoInput.java | 23 ++++ .../gtPlusPlus/core/slots/SlotNoInputLogging.java | 36 +++++ .../java/gtPlusPlus/core/slots/SlotOutput.java | 96 +++++++++++++ .../core/slots/SlotPollutionScrubber.java | 66 +++++++++ src/main/java/gtPlusPlus/core/slots/SlotRTG.java | 26 ++++ .../java/gtPlusPlus/core/slots/SlotToolBox.java | 113 +++++++++++++++ .../gtPlusPlus/core/slots/SlotVolumetricFlask.java | 30 ++++ 28 files changed, 1561 insertions(+) create mode 100644 src/main/java/gtPlusPlus/core/slots/SlotAirFilter.java create mode 100644 src/main/java/gtPlusPlus/core/slots/SlotBlueprint.java create mode 100644 src/main/java/gtPlusPlus/core/slots/SlotBuzzSaw.java create mode 100644 src/main/java/gtPlusPlus/core/slots/SlotChemicalPlantInput.java create mode 100644 src/main/java/gtPlusPlus/core/slots/SlotCrafting.java create mode 100644 src/main/java/gtPlusPlus/core/slots/SlotCraftingNoCollect.java create mode 100644 src/main/java/gtPlusPlus/core/slots/SlotDataStick.java create mode 100644 src/main/java/gtPlusPlus/core/slots/SlotElectric.java create mode 100644 src/main/java/gtPlusPlus/core/slots/SlotFrame.java create mode 100644 src/main/java/gtPlusPlus/core/slots/SlotFuelRod.java create mode 100644 src/main/java/gtPlusPlus/core/slots/SlotGeneric.java create mode 100644 src/main/java/gtPlusPlus/core/slots/SlotGtTool.java create mode 100644 src/main/java/gtPlusPlus/core/slots/SlotGtToolElectric.java create mode 100644 src/main/java/gtPlusPlus/core/slots/SlotIntegratedCircuit.java create mode 100644 src/main/java/gtPlusPlus/core/slots/SlotItemBackpackInv.java create mode 100644 src/main/java/gtPlusPlus/core/slots/SlotJukebox.java create mode 100644 src/main/java/gtPlusPlus/core/slots/SlotLockedInput.java create mode 100644 src/main/java/gtPlusPlus/core/slots/SlotLunchBox.java create mode 100644 src/main/java/gtPlusPlus/core/slots/SlotMagicToolBag.java create mode 100644 src/main/java/gtPlusPlus/core/slots/SlotModularBauble.java create mode 100644 src/main/java/gtPlusPlus/core/slots/SlotModularBaubleUpgrades.java create mode 100644 src/main/java/gtPlusPlus/core/slots/SlotNoInput.java create mode 100644 src/main/java/gtPlusPlus/core/slots/SlotNoInputLogging.java create mode 100644 src/main/java/gtPlusPlus/core/slots/SlotOutput.java create mode 100644 src/main/java/gtPlusPlus/core/slots/SlotPollutionScrubber.java create mode 100644 src/main/java/gtPlusPlus/core/slots/SlotRTG.java create mode 100644 src/main/java/gtPlusPlus/core/slots/SlotToolBox.java create mode 100644 src/main/java/gtPlusPlus/core/slots/SlotVolumetricFlask.java (limited to 'src/main/java/gtPlusPlus/core/slots') diff --git a/src/main/java/gtPlusPlus/core/slots/SlotAirFilter.java b/src/main/java/gtPlusPlus/core/slots/SlotAirFilter.java new file mode 100644 index 0000000000..92e9bebe21 --- /dev/null +++ b/src/main/java/gtPlusPlus/core/slots/SlotAirFilter.java @@ -0,0 +1,30 @@ +package gtPlusPlus.core.slots; + +import gtPlusPlus.core.item.general.ItemAirFilter; +import net.minecraft.inventory.IInventory; +import net.minecraft.inventory.Slot; +import net.minecraft.item.ItemStack; + +public class SlotAirFilter extends Slot { + + public SlotAirFilter(final IInventory inventory, final int slot, final int x, final int y) { + super(inventory, slot, x, y); + } + + @Override + public boolean isItemValid(final ItemStack itemstack) { + if (itemstack == null) { + return false; + } + if (itemstack.getItem() instanceof ItemAirFilter){ + return true; + } + return false; + } + + @Override + public int getSlotStackLimit() { + return 1; + } + +} diff --git a/src/main/java/gtPlusPlus/core/slots/SlotBlueprint.java b/src/main/java/gtPlusPlus/core/slots/SlotBlueprint.java new file mode 100644 index 0000000000..532f2f0822 --- /dev/null +++ b/src/main/java/gtPlusPlus/core/slots/SlotBlueprint.java @@ -0,0 +1,31 @@ +package gtPlusPlus.core.slots; + +import net.minecraft.inventory.IInventory; +import net.minecraft.inventory.Slot; +import net.minecraft.item.ItemStack; + +import gtPlusPlus.api.objects.Logger; +import gtPlusPlus.core.interfaces.IItemBlueprint; + +public class SlotBlueprint extends Slot { + + public SlotBlueprint(final IInventory inventory, final int x, final int y, final int z) { + super(inventory, x, y, z); + } + + @Override + public boolean isItemValid(final ItemStack itemstack) { + if (itemstack.getItem() instanceof IItemBlueprint) { + Logger.WARNING(itemstack.getDisplayName() + " is a valid Blueprint."); + return true; + } + Logger.WARNING(itemstack.getDisplayName() + " is not a valid Blueprint."); + return false; + } + + @Override + public int getSlotStackLimit() { + return 1; + } + +} diff --git a/src/main/java/gtPlusPlus/core/slots/SlotBuzzSaw.java b/src/main/java/gtPlusPlus/core/slots/SlotBuzzSaw.java new file mode 100644 index 0000000000..94b0b9ecc7 --- /dev/null +++ b/src/main/java/gtPlusPlus/core/slots/SlotBuzzSaw.java @@ -0,0 +1,77 @@ +package gtPlusPlus.core.slots; + +import net.minecraft.inventory.IInventory; +import net.minecraft.inventory.Slot; +import net.minecraft.item.ItemStack; + +import gregtech.api.enums.OrePrefixes; +import gregtech.api.items.GT_MetaGenerated_Tool; +import gregtech.common.items.GT_MetaGenerated_Item_02; + +public class SlotBuzzSaw extends Slot { + + public SAWTOOL currentTool = SAWTOOL.NONE; + + public SlotBuzzSaw(final IInventory inventory, final int slot, final int x, final int y) { + super(inventory, slot, x, y); + + } + + @Override + public boolean isItemValid(final ItemStack itemstack) { + boolean isValid = false; + + if (itemstack != null) { + if ((itemstack.getItem() instanceof GT_MetaGenerated_Item_02) + || (itemstack.getItem() instanceof GT_MetaGenerated_Tool)) { + // Buzzsaw Blade //TODO + /* + * if (OrePrefixes.toolHeadBuzzSaw.contains(itemstack)){ isValid + * = false; } + */ + if (OrePrefixes.craftingTool.contains(itemstack)) { + if (itemstack.getDisplayName().toLowerCase().contains("saw") + || itemstack.getDisplayName().toLowerCase().contains("gt.metatool.01.10") + || itemstack.getDisplayName().toLowerCase().contains("gt.metatool.01.110") + || itemstack.getDisplayName().toLowerCase().contains("gt.metatool.01.112") + || itemstack.getDisplayName().toLowerCase().contains("gt.metatool.01.114") + || itemstack.getDisplayName().toLowerCase().contains("gt.metatool.01.140")) { + if (itemstack.getItemDamage() == 10) { + isValid = true; + this.currentTool = SAWTOOL.SAW; + } + else if (itemstack.getItemDamage() == 110) { + isValid = true; + this.currentTool = SAWTOOL.CHAINSAW; + } + else if (itemstack.getItemDamage() == 112) { + isValid = true; + this.currentTool = SAWTOOL.CHAINSAW; + } + else if (itemstack.getItemDamage() == 114) { + isValid = true; + this.currentTool = SAWTOOL.CHAINSAW; + } + else if (itemstack.getItemDamage() == 140) { + isValid = true; + this.currentTool = SAWTOOL.BUZZSAW; + } + return isValid; + } + } + } + } + this.currentTool = SAWTOOL.NONE; + return isValid; + } + + @Override + public int getSlotStackLimit() { + return 1; + } + + public enum SAWTOOL { + NONE, SAW, BUZZSAW, CHAINSAW + } + +} diff --git a/src/main/java/gtPlusPlus/core/slots/SlotChemicalPlantInput.java b/src/main/java/gtPlusPlus/core/slots/SlotChemicalPlantInput.java new file mode 100644 index 0000000000..1029d37a78 --- /dev/null +++ b/src/main/java/gtPlusPlus/core/slots/SlotChemicalPlantInput.java @@ -0,0 +1,45 @@ +package gtPlusPlus.core.slots; + +import gregtech.api.util.GTPP_Recipe.GTPP_Recipe_Map; +import gregtech.api.util.GT_Recipe; +import net.minecraft.inventory.IInventory; +import net.minecraft.inventory.Slot; +import net.minecraft.item.ItemStack; +import net.minecraftforge.fluids.FluidContainerRegistry; +import net.minecraftforge.fluids.FluidStack; + +public class SlotChemicalPlantInput extends Slot { + + public SlotChemicalPlantInput(final IInventory inventory, final int index, final int x, final int y) { + super(inventory, index, x, y); + } + + @Override + public boolean isItemValid(final ItemStack itemstack) { + return isItemValidForChemicalPlantSlot(itemstack); + } + + public static boolean isItemValidForChemicalPlantSlot(ItemStack aStack) { + boolean validItem = GTPP_Recipe_Map.sChemicalPlantRecipes.containsInput(aStack); + if (!validItem) { + for (GT_Recipe f : GTPP_Recipe_Map.sChemicalPlantRecipes.mRecipeList) { + if (f.mFluidInputs.length > 0) { + for (FluidStack g : f.mFluidInputs) { + if (g != null) { + if (FluidContainerRegistry.containsFluid(aStack, g)) { + return true; + } + } + } + } + } + } + return validItem; + } + + @Override + public int getSlotStackLimit() { + return 64; + } + +} diff --git a/src/main/java/gtPlusPlus/core/slots/SlotCrafting.java b/src/main/java/gtPlusPlus/core/slots/SlotCrafting.java new file mode 100644 index 0000000000..42b7b585e2 --- /dev/null +++ b/src/main/java/gtPlusPlus/core/slots/SlotCrafting.java @@ -0,0 +1,151 @@ +package gtPlusPlus.core.slots; + +import cpw.mods.fml.common.FMLCommonHandler; + +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.init.Blocks; +import net.minecraft.init.Items; +import net.minecraft.inventory.IInventory; +import net.minecraft.inventory.Slot; +import net.minecraft.item.*; +import net.minecraft.stats.AchievementList; + +import net.minecraftforge.common.MinecraftForge; +import net.minecraftforge.event.entity.player.PlayerDestroyItemEvent; + +public class SlotCrafting extends Slot { + /** The craft matrix inventory linked to this result slot. */ + private final IInventory craftMatrix; + /** The player that is using the GUI where this slot resides. */ + private final EntityPlayer thePlayer; + /** + * The number of items that have been crafted so far. Gets passed to + * ItemStack.onCrafting before being reset. + */ + private int amountCrafted; + private static final String __OBFID = "CL_00001761"; + + public SlotCrafting(final EntityPlayer p_i1823_1_, final IInventory p_i1823_2_, final IInventory p_i1823_3_, + final int p_i1823_4_, final int p_i1823_5_, final int p_i1823_6_) { + super(p_i1823_3_, p_i1823_4_, p_i1823_5_, p_i1823_6_); + this.thePlayer = p_i1823_1_; + this.craftMatrix = p_i1823_2_; + } + + /** + * Check if the stack is a valid item for this slot. Always true beside for + * the armor slots. + */ + @Override + public boolean isItemValid(final ItemStack p_75214_1_) { + 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(final int p_75209_1_) { + if (this.getHasStack()) { + this.amountCrafted += Math.min(p_75209_1_, this.getStack().stackSize); + } + + return super.decrStackSize(p_75209_1_); + } + + /** + * 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(final ItemStack p_75210_1_, final int p_75210_2_) { + this.amountCrafted += p_75210_2_; + this.onCrafting(p_75210_1_); + } + + /** + * the itemStack passed in is the output - ie, iron ingots, and pickaxes, + * not ore and wood. + */ + @Override + protected void onCrafting(final ItemStack p_75208_1_) { + p_75208_1_.onCrafting(this.thePlayer.worldObj, this.thePlayer, this.amountCrafted); + this.amountCrafted = 0; + + if (p_75208_1_.getItem() == Item.getItemFromBlock(Blocks.crafting_table)) { + this.thePlayer.addStat(AchievementList.buildWorkBench, 1); + } + + if (p_75208_1_.getItem() instanceof ItemPickaxe) { + this.thePlayer.addStat(AchievementList.buildPickaxe, 1); + } + + if (p_75208_1_.getItem() == Item.getItemFromBlock(Blocks.furnace)) { + this.thePlayer.addStat(AchievementList.buildFurnace, 1); + } + + if (p_75208_1_.getItem() instanceof ItemHoe) { + this.thePlayer.addStat(AchievementList.buildHoe, 1); + } + + if (p_75208_1_.getItem() == Items.bread) { + this.thePlayer.addStat(AchievementList.makeBread, 1); + } + + if (p_75208_1_.getItem() == Items.cake) { + this.thePlayer.addStat(AchievementList.bakeCake, 1); + } + + if ((p_75208_1_.getItem() instanceof ItemPickaxe) + && (((ItemPickaxe) p_75208_1_.getItem()).func_150913_i() != Item.ToolMaterial.WOOD)) { + this.thePlayer.addStat(AchievementList.buildBetterPickaxe, 1); + } + + if (p_75208_1_.getItem() instanceof ItemSword) { + this.thePlayer.addStat(AchievementList.buildSword, 1); + } + + if (p_75208_1_.getItem() == Item.getItemFromBlock(Blocks.enchanting_table)) { + this.thePlayer.addStat(AchievementList.enchantments, 1); + } + + if (p_75208_1_.getItem() == Item.getItemFromBlock(Blocks.bookshelf)) { + this.thePlayer.addStat(AchievementList.bookcase, 1); + } + } + + @Override + public void onPickupFromSlot(final EntityPlayer p_82870_1_, final ItemStack p_82870_2_) { + FMLCommonHandler.instance().firePlayerCraftingEvent(p_82870_1_, p_82870_2_, this.craftMatrix); + this.onCrafting(p_82870_2_); + + for (int i = 0; i < this.craftMatrix.getSizeInventory(); ++i) { + final ItemStack itemstack1 = this.craftMatrix.getStackInSlot(i); + + if (itemstack1 != null) { + this.craftMatrix.decrStackSize(i, 1); + + if (itemstack1.getItem().hasContainerItem(itemstack1)) { + final ItemStack itemstack2 = itemstack1.getItem().getContainerItem(itemstack1); + + if ((itemstack2 != null) && itemstack2.isItemStackDamageable() + && (itemstack2.getItemDamage() > itemstack2.getMaxDamage())) { + MinecraftForge.EVENT_BUS.post(new PlayerDestroyItemEvent(this.thePlayer, itemstack2)); + continue; + } + + if (!itemstack1.getItem().doesContainerItemLeaveCraftingGrid(itemstack1) + || !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 diff --git a/src/main/java/gtPlusPlus/core/slots/SlotCraftingNoCollect.java b/src/main/java/gtPlusPlus/core/slots/SlotCraftingNoCollect.java new file mode 100644 index 0000000000..3608c3724c --- /dev/null +++ b/src/main/java/gtPlusPlus/core/slots/SlotCraftingNoCollect.java @@ -0,0 +1,147 @@ +package gtPlusPlus.core.slots; + +import cpw.mods.fml.common.FMLCommonHandler; + +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.init.Blocks; +import net.minecraft.init.Items; +import net.minecraft.inventory.IInventory; +import net.minecraft.item.*; +import net.minecraft.stats.AchievementList; + +public class SlotCraftingNoCollect extends SlotCrafting { + /** The craft matrix inventory linked to this result slot. */ + private final IInventory craftMatrix; + /** The player that is using the GUI where this slot resides. */ + private EntityPlayer thePlayer; + /** + * The number of items that have been crafted so far. Gets passed to + * ItemStack.onCrafting before being reset. + */ + private int amountCrafted; + + public SlotCraftingNoCollect(EntityPlayer player, IInventory inventory, IInventory inventory2, int x, int y, + int z) { + super(player, inventory, inventory2, x, y, z); + this.thePlayer = player; + this.craftMatrix = inventory; + } + + /** + * Check if the stack is a valid item for this slot. Always true beside for + * the armor slots. + */ + @Override + public boolean isItemValid(ItemStack p_75214_1_) { + 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 amount) { + if (this.getHasStack()) { + this.amountCrafted += Math.min(amount, this.getStack().stackSize); + } + + return super.decrStackSize(amount); + } + + /** + * 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 output, int amount) { + this.amountCrafted += amount; + this.onCrafting(output); + } + + /** + * the itemStack passed in is the output - ie, iron ingots, and pickaxes, + * not ore and wood. + */ + @Override + protected void onCrafting(ItemStack output) { + output.onCrafting(this.thePlayer.worldObj, this.thePlayer, this.amountCrafted); + this.amountCrafted = 0; + + if (output.getItem() == Item.getItemFromBlock(Blocks.crafting_table)) { + this.thePlayer.addStat(AchievementList.buildWorkBench, 1); + } + + if (output.getItem() instanceof ItemPickaxe) { + this.thePlayer.addStat(AchievementList.buildPickaxe, 1); + } + + if (output.getItem() == Item.getItemFromBlock(Blocks.furnace)) { + this.thePlayer.addStat(AchievementList.buildFurnace, 1); + } + + if (output.getItem() instanceof ItemHoe) { + this.thePlayer.addStat(AchievementList.buildHoe, 1); + } + + if (output.getItem() == Items.bread) { + this.thePlayer.addStat(AchievementList.makeBread, 1); + } + + if (output.getItem() == Items.cake) { + this.thePlayer.addStat(AchievementList.bakeCake, 1); + } + + if (output.getItem() instanceof ItemPickaxe + && ((ItemPickaxe) output.getItem()).func_150913_i() != Item.ToolMaterial.WOOD) { + this.thePlayer.addStat(AchievementList.buildBetterPickaxe, 1); + } + + if (output.getItem() instanceof ItemSword) { + this.thePlayer.addStat(AchievementList.buildSword, 1); + } + + if (output.getItem() == Item.getItemFromBlock(Blocks.enchanting_table)) { + this.thePlayer.addStat(AchievementList.enchantments, 1); + } + + if (output.getItem() == Item.getItemFromBlock(Blocks.bookshelf)) { + this.thePlayer.addStat(AchievementList.bookcase, 1); + } + } + + @Override + public void onPickupFromSlot(EntityPlayer player, ItemStack output) { + FMLCommonHandler.instance().firePlayerCraftingEvent(player, output, craftMatrix); + this.onCrafting(output); + + /* + * 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 != null && itemstack2.isItemStackDamageable() && + * itemstack2.getItemDamage() > itemstack2.getMaxDamage()) { + * MinecraftForge.EVENT_BUS.post(new PlayerDestroyItemEvent(thePlayer, + * itemstack2)); continue; } + * + * if + * (!itemstack1.getItem().doesContainerItemLeaveCraftingGrid(itemstack1) + * || !this.thePlayer.inventory.addItemStackToInventory(itemstack2)) { + * if (this.craftMatrix.getStackInSlot(i) == null) { + * this.craftMatrix.setInventorySlotContents(i, itemstack2); } else { + * this.thePlayer.dropPlayerItemWithRandomChoice(itemstack2, false); } } + * } } } + */ + } + + @Override + public boolean canTakeStack(EntityPlayer player) { + return false; + } +} \ No newline at end of file diff --git a/src/main/java/gtPlusPlus/core/slots/SlotDataStick.java b/src/main/java/gtPlusPlus/core/slots/SlotDataStick.java new file mode 100644 index 0000000000..ce97a2fdbf --- /dev/null +++ b/src/main/java/gtPlusPlus/core/slots/SlotDataStick.java @@ -0,0 +1,42 @@ +package gtPlusPlus.core.slots; + +import net.minecraft.inventory.IInventory; +import net.minecraft.inventory.Slot; +import net.minecraft.item.ItemStack; + +import gregtech.api.util.GT_Utility; +import gtPlusPlus.core.recipe.common.CI; + +public class SlotDataStick extends Slot { + + public SlotDataStick(final IInventory inventory, final int slot, final int x, final int y) { + super(inventory, slot, x, y); + + } + + public static ItemStack[] mDataItems = new ItemStack[2]; + + @Override + public synchronized boolean isItemValid(final ItemStack itemstack) { + boolean isValid = false; + if (itemstack != null) { + if (mDataItems[0] == null) { + mDataItems[0] = CI.getDataStick(); + } + if (mDataItems[1] == null) { + mDataItems[1] = CI.getDataOrb(); + } + if (mDataItems[0] != null && mDataItems[1] != null) { + if (GT_Utility.areStacksEqual(itemstack, mDataItems[0], true) || GT_Utility.areStacksEqual(itemstack, mDataItems[1], true) ) { + isValid = true; + } + } + } + return isValid; + } + + @Override + public int getSlotStackLimit() { + return 1; + } +} diff --git a/src/main/java/gtPlusPlus/core/slots/SlotElectric.java b/src/main/java/gtPlusPlus/core/slots/SlotElectric.java new file mode 100644 index 0000000000..a747432a74 --- /dev/null +++ b/src/main/java/gtPlusPlus/core/slots/SlotElectric.java @@ -0,0 +1,45 @@ +package gtPlusPlus.core.slots; + +import net.minecraft.inventory.IInventory; +import net.minecraft.inventory.Slot; +import net.minecraft.item.ItemStack; + +import gregtech.api.interfaces.tileentity.IGregTechTileEntity; +import gregtech.api.items.GT_MetaGenerated_Tool; + +import ic2.api.info.Info; +import ic2.api.item.ElectricItem; +import ic2.api.item.IElectricItem; + +public class SlotElectric extends Slot { + + public SlotElectric(final IInventory inventory, final int x, final int y, final int z) { + super(inventory, x, y, z); + } + + public SlotElectric(IGregTechTileEntity mTileEntity, int i, int j, int k) { + this(mTileEntity.getIInventory(mTileEntity.getXCoord(), mTileEntity.getYCoord(), mTileEntity.getZCoord()), i, j, k); + } + + @Override + public boolean isItemValid(final ItemStack itemstack) { + if ((accepts(itemstack)) || (itemstack.getItem() instanceof GT_MetaGenerated_Tool) || (itemstack.getItem() instanceof IElectricItem)) { + return true; + } + return false; + } + + public boolean accepts(final ItemStack stack) { + if (stack == null) { + return false; + } + return (Info.itemEnergy.getEnergyValue(stack) > 0.0D) + || (ElectricItem.manager.discharge(stack, (1.0D / 0.0D), 4, true, true, true) > 0.0D); + } + + @Override + public int getSlotStackLimit() { + return 1; + } + +} diff --git a/src/main/java/gtPlusPlus/core/slots/SlotFrame.java b/src/main/java/gtPlusPlus/core/slots/SlotFrame.java new file mode 100644 index 0000000000..4168ded5bc --- /dev/null +++ b/src/main/java/gtPlusPlus/core/slots/SlotFrame.java @@ -0,0 +1,26 @@ +package gtPlusPlus.core.slots; + +import net.minecraft.inventory.IInventory; +import net.minecraft.inventory.Slot; +import net.minecraft.item.ItemStack; + +import forestry.api.apiculture.IHiveFrame; + +public class SlotFrame extends Slot { + + public SlotFrame(final IInventory inventory, final int x, final int y, final int z) { + super(inventory, x, y, z); + + } + + @Override + public boolean isItemValid(final ItemStack itemstack) { + return itemstack.getItem() instanceof IHiveFrame; + } + + @Override + public int getSlotStackLimit() { + return 1; + } + +} diff --git a/src/main/java/gtPlusPlus/core/slots/SlotFuelRod.java b/src/main/java/gtPlusPlus/core/slots/SlotFuelRod.java new file mode 100644 index 0000000000..b50b679665 --- /dev/null +++ b/src/main/java/gtPlusPlus/core/slots/SlotFuelRod.java @@ -0,0 +1,55 @@ +package gtPlusPlus.core.slots; + +import net.minecraft.inventory.IInventory; +import net.minecraft.inventory.Slot; +import net.minecraft.item.ItemStack; + +import gregtech.api.enums.ItemList; + +import ic2.core.Ic2Items; + +public class SlotFuelRod extends Slot { + + public SlotFuelRod(final IInventory inventory, final int index, final int x, final int y) { + super(inventory, index, x, y); + + } + + @Override + public boolean isItemValid(final ItemStack itemstack) { + boolean returnValue = false; + // Uranium Rods + if (itemstack.getItem() == Ic2Items.reactorUraniumSimple.getItem()) { + returnValue = true; + } else if (itemstack.getItem() == Ic2Items.reactorUraniumDual.getItem()) { + returnValue = true; + } else if (itemstack.getItem() == Ic2Items.reactorUraniumQuad.getItem()) { + returnValue = true; + } + + // Mox Rods + if (itemstack.getItem() == Ic2Items.reactorMOXSimple.getItem()) { + returnValue = true; + } else if (itemstack.getItem() == Ic2Items.reactorMOXDual.getItem()) { + returnValue = true; + } else if (itemstack.getItem() == Ic2Items.reactorMOXQuad.getItem()) { + returnValue = true; + } + + // Thorium Rods + if (itemstack.getItem() == ItemList.ThoriumCell_1.getItem()) { + returnValue = true; + } else if (itemstack.getItem() == ItemList.ThoriumCell_2.getItem()) { + returnValue = true; + } else if (itemstack.getItem() == ItemList.ThoriumCell_4.getItem()) { + returnValue = true; + } + return returnValue; + } + + @Override + public int getSlotStackLimit() { + return 1; + } + +} diff --git a/src/main/java/gtPlusPlus/core/slots/SlotGeneric.java b/src/main/java/gtPlusPlus/core/slots/SlotGeneric.java new file mode 100644 index 0000000000..533539d914 --- /dev/null +++ b/src/main/java/gtPlusPlus/core/slots/SlotGeneric.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 SlotGeneric extends Slot { + + public SlotGeneric(final IInventory inventory, final int aSlotID, final int x, final int y) { + super(inventory, aSlotID, x, y); + } + + @Override + public boolean isItemValid(final ItemStack itemstack) { + return true; + } + + @Override + public int getSlotStackLimit() { + return 64; + } + +} diff --git a/src/main/java/gtPlusPlus/core/slots/SlotGtTool.java b/src/main/java/gtPlusPlus/core/slots/SlotGtTool.java new file mode 100644 index 0000000000..54e25362db --- /dev/null +++ b/src/main/java/gtPlusPlus/core/slots/SlotGtTool.java @@ -0,0 +1,33 @@ +package gtPlusPlus.core.slots; + +import net.minecraft.inventory.IInventory; +import net.minecraft.inventory.Slot; +import net.minecraft.item.ItemStack; + +import gregtech.api.items.GT_MetaGenerated_Tool; + +import gtPlusPlus.api.objects.Logger; + +public class SlotGtTool extends Slot { + + public SlotGtTool(final IInventory inventory, final int x, final int y, final int z) { + super(inventory, x, y, z); + + } + + @Override + public boolean isItemValid(final ItemStack itemstack) { + if (itemstack.getItem() instanceof GT_MetaGenerated_Tool) { + Logger.WARNING(itemstack.getDisplayName() + " is a valid Tool."); + return true; + } + Logger.WARNING(itemstack.getDisplayName() + " is not a valid Tool."); + return false; + } + + @Override + public int getSlotStackLimit() { + return 1; + } + +} diff --git a/src/main/java/gtPlusPlus/core/slots/SlotGtToolElectric.java b/src/main/java/gtPlusPlus/core/slots/SlotGtToolElectric.java new file mode 100644 index 0000000000..c0e3340769 --- /dev/null +++ b/src/main/java/gtPlusPlus/core/slots/SlotGtToolElectric.java @@ -0,0 +1,94 @@ +package gtPlusPlus.core.slots; + +import net.minecraft.init.Items; +import net.minecraft.inventory.IInventory; +import net.minecraft.item.ItemStack; + +import gregtech.api.items.GT_MetaGenerated_Tool; + +import gtPlusPlus.api.objects.Logger; +import ic2.api.info.Info; +import ic2.api.item.ElectricItem; +import ic2.api.item.IElectricItem; + +public class SlotGtToolElectric extends SlotGtTool { + public int tier; + private ItemStack content; + + public SlotGtToolElectric(final IInventory base, final int x, final int y, final int z, final int tier, + final boolean allowRedstoneDust) { + super(base, x, y, z); + this.tier = tier; + this.allowRedstoneDust = allowRedstoneDust; + } + + public boolean accepts(final 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(final double amount, final boolean ignoreLimit) { + if (amount <= 0.0D) { + throw new IllegalArgumentException("Amount must be > 0."); + } + final ItemStack stack = this.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) { + this.put(0, null); + } + } + return realAmount; + } + + public void setTier(final int tier1) { + this.tier = tier1; + } + + public boolean allowRedstoneDust = true; + + public ItemStack get() { + return this.get(0); + } + + public ItemStack get(final int index) { + return this.content; + } + + public void put(final ItemStack content) { + this.put(0, content); + } + + public void put(final int index, final ItemStack content) { + this.content = content; + this.onChanged(); + } + + public void onChanged() { + } + + @Override + public boolean isItemValid(final ItemStack itemstack) { + if ((itemstack.getItem() instanceof GT_MetaGenerated_Tool) || (itemstack.getItem() instanceof IElectricItem)) { + Logger.WARNING(itemstack.getDisplayName() + " is a valid Tool."); + return true; + } + Logger.WARNING(itemstack.getDisplayName() + " is not a valid Tool."); + return false; + } + +} diff --git a/src/main/java/gtPlusPlus/core/slots/SlotIntegratedCircuit.java b/src/main/java/gtPlusPlus/core/slots/SlotIntegratedCircuit.java new file mode 100644 index 0000000000..8c8a118abb --- /dev/null +++ b/src/main/java/gtPlusPlus/core/slots/SlotIntegratedCircuit.java @@ -0,0 +1,105 @@ +package gtPlusPlus.core.slots; + +import net.minecraft.inventory.IInventory; +import net.minecraft.inventory.Slot; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; + +import gtPlusPlus.core.recipe.common.CI; + +public class SlotIntegratedCircuit extends Slot { + + public static Item mCircuitItem; + public static Item mCircuitItem2; + public static Item mCircuitItem3; + private final short mCircuitLock; + + public SlotIntegratedCircuit(final IInventory inventory, final int slot, final int x, final int y) { + this(Short.MAX_VALUE+1, inventory, slot, x, y); + } + + public SlotIntegratedCircuit(int mTypeLock, final IInventory inventory, final int slot, final int x, final int y) { + super(inventory, slot, x, y); + if (mTypeLock > Short.MAX_VALUE || mTypeLock < Short.MIN_VALUE) { + mCircuitLock = -1; + } + else { + mCircuitLock = (short) mTypeLock; + } + } + + @Override + public synchronized boolean isItemValid(final ItemStack itemstack) { + return isItemValidForSlot(mCircuitLock, itemstack); + } + + public static synchronized boolean isItemValidForSlot(final ItemStack itemstack) { + return isItemValidForSlot(-1, itemstack); + } + + public static synchronized boolean isItemValidForSlot(int aLockedCircuitNumber, final ItemStack itemstack) { + boolean isValid = false; + if (mCircuitItem == null) { + mCircuitItem = CI.getNumberedCircuit(0).getItem(); + } + if (mCircuitItem2 == null) { + mCircuitItem2 = CI.getNumberedBioCircuit(0).getItem(); + } + if (mCircuitItem3 == null) { + mCircuitItem3 = CI.getNumberedAdvancedCircuit(0).getItem(); + } + if (mCircuitItem != null && mCircuitItem2 != null && mCircuitItem3 != null) { + if (itemstack != null) { + if (itemstack.getItem() == mCircuitItem || itemstack.getItem() == mCircuitItem2 || itemstack.getItem() == mCircuitItem3) { + if (aLockedCircuitNumber == -1) { + isValid = true; + } + else { + if (itemstack.getItemDamage() == aLockedCircuitNumber) { + isValid = true; + } + } + } + } + } + return isValid; + } + + /** + * Returns the circuit type. -1 is invalid, 0 is standard, 1 is GT++ bio. + * @param itemstack - the Circuit Stack. + * @return + */ + public static synchronized int isRegularProgrammableCircuit(final ItemStack itemstack) { + if (mCircuitItem == null) { + mCircuitItem = CI.getNumberedCircuit(0).getItem(); + } + if (mCircuitItem2 == null) { + mCircuitItem2 = CI.getNumberedBioCircuit(0).getItem(); + } + if (mCircuitItem3 == null) { + mCircuitItem3 = CI.getNumberedAdvancedCircuit(0).getItem(); + } + if (mCircuitItem != null && mCircuitItem2 != null && mCircuitItem3 != null) { + if (itemstack != null) { + if (itemstack.getItem() == mCircuitItem || itemstack.getItem() == mCircuitItem2 || itemstack.getItem() == mCircuitItem3) { + if (itemstack.getItem() == mCircuitItem) { + return 0; + } + else if (itemstack.getItem() == mCircuitItem2) { + return 1; + } + else if (itemstack.getItem() == mCircuitItem3) { + return 2; + } + } + } + } + return -1; + } + + @Override + public int getSlotStackLimit() { + return 64; + } +} diff --git a/src/main/java/gtPlusPlus/core/slots/SlotItemBackpackInv.java b/src/main/java/gtPlusPlus/core/slots/SlotItemBackpackInv.java new file mode 100644 index 0000000000..3aa551f966 --- /dev/null +++ b/src/main/java/gtPlusPlus/core/slots/SlotItemBackpackInv.java @@ -0,0 +1,26 @@ +package gtPlusPlus.core.slots; + +import net.minecraft.inventory.IInventory; +import net.minecraft.inventory.Slot; +import net.minecraft.item.ItemStack; + +import gtPlusPlus.core.item.base.BaseItemBackpack; + +public class SlotItemBackpackInv extends Slot { + public SlotItemBackpackInv(final IInventory inv, final int index, final int xPos, final int yPos) { + super(inv, index, xPos, yPos); + } + + // This is the only method we need to override so that + // we can't place our inventory-storing Item within + // its own inventory (thus making it permanently inaccessible) + // as well as preventing abuse of storing backpacks within backpacks + /** + * Check if the stack is a valid item for this slot. + */ + @Override + public boolean isItemValid(final ItemStack itemstack) { + // Everything returns true except an instance of our Item + return !(itemstack.getItem() instanceof BaseItemBackpack); + } +} \ No newline at end of file diff --git a/src/main/java/gtPlusPlus/core/slots/SlotJukebox.java b/src/main/java/gtPlusPlus/core/slots/SlotJukebox.java new file mode 100644 index 0000000000..0f8af988a1 --- /dev/null +++ b/src/main/java/gtPlusPlus/core/slots/SlotJukebox.java @@ -0,0 +1,37 @@ +package gtPlusPlus.core.slots; + +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.inventory.IInventory; +import net.minecraft.item.ItemRecord; +import net.minecraft.item.ItemStack; + +public class SlotJukebox extends SlotGeneric { + + private final boolean isDisplay; + + + public SlotJukebox(IInventory inventory, int x, int y, int z) { + this(inventory, x, y, z, false); + } + + public SlotJukebox(IInventory inventory, int x, int y, int z, boolean display) { + super(inventory, x, y, z); + isDisplay = display; + } + + @Override + public boolean isItemValid(ItemStack itemstack) { + return (itemstack != null && itemstack.getItem() instanceof ItemRecord); + } + + @Override + public int getSlotStackLimit() { + return 1; + } + + @Override + public boolean canTakeStack(EntityPlayer p_82869_1_) { + return !isDisplay; + } + +} diff --git a/src/main/java/gtPlusPlus/core/slots/SlotLockedInput.java b/src/main/java/gtPlusPlus/core/slots/SlotLockedInput.java new file mode 100644 index 0000000000..c67f8acfeb --- /dev/null +++ b/src/main/java/gtPlusPlus/core/slots/SlotLockedInput.java @@ -0,0 +1,57 @@ +package gtPlusPlus.core.slots; + +import net.minecraft.inventory.Slot; +import net.minecraft.item.ItemStack; + +import gregtech.api.interfaces.tileentity.IGregTechTileEntity; + +import gtPlusPlus.core.util.reflect.ReflectionUtils; +import gtPlusPlus.xmod.gregtech.common.tileentities.storage.GT_MetaTileEntity_TieredChest; + +public class SlotLockedInput extends Slot { + + private ItemStack mLockStack; + private final IGregTechTileEntity mEntity; + private boolean mChecked = false; + + public SlotLockedInput(final IGregTechTileEntity inventory, final int index, final int x, final int y, ItemStack lockStack) { + super(inventory, index, x, y); + mLockStack = lockStack; + mEntity = inventory; + } + + @Override + public boolean isItemValid(final ItemStack itemstack) { + if (mEntity == null) { + return false; + } + else { + if (!mChecked) { + try { + mLockStack = (ItemStack) ReflectionUtils.getField(this.mEntity.getMetaTileEntity().getClass(), "mItemStack").get(this.mEntity.getMetaTileEntity()); + } + catch (Throwable t) { + t.printStackTrace(); + mLockStack = null; + } + mChecked = true; + } + } + + if (mLockStack == null) { + return true; + } + else { + if (ItemStack.areItemStacksEqual(itemstack, mLockStack)) { + return true; + } + } + return false; + } + + @Override + public int getSlotStackLimit() { + return mLockStack == null ? 64 : mLockStack.getMaxStackSize(); + } + +} diff --git a/src/main/java/gtPlusPlus/core/slots/SlotLunchBox.java b/src/main/java/gtPlusPlus/core/slots/SlotLunchBox.java new file mode 100644 index 0000000000..bb82a28936 --- /dev/null +++ b/src/main/java/gtPlusPlus/core/slots/SlotLunchBox.java @@ -0,0 +1,30 @@ +package gtPlusPlus.core.slots; + +import net.minecraft.inventory.IInventory; +import net.minecraft.item.ItemFood; +import net.minecraft.item.ItemStack; + +import gtPlusPlus.api.objects.Logger; +import gtPlusPlus.core.util.minecraft.FoodUtils; + +public class SlotLunchBox extends SlotGtTool { + + public SlotLunchBox(final IInventory base, final int x, final int y, final int z) { + super(base, x, y, z); + } + + @Override + public boolean isItemValid(final ItemStack itemstack) { + return isItemValid_STATIC(itemstack); + } + + public static boolean isItemValid_STATIC(final ItemStack itemstack) { + if ((itemstack.getItem() instanceof ItemFood) || (FoodUtils.isFood(itemstack))) { + Logger.WARNING(itemstack.getDisplayName() + " is a valid food."); + return true; + } + Logger.WARNING(itemstack.getDisplayName() + " is not a valid food."); + return false; + } + +} diff --git a/src/main/java/gtPlusPlus/core/slots/SlotMagicToolBag.java b/src/main/java/gtPlusPlus/core/slots/SlotMagicToolBag.java new file mode 100644 index 0000000000..d555f10a44 --- /dev/null +++ b/src/main/java/gtPlusPlus/core/slots/SlotMagicToolBag.java @@ -0,0 +1,29 @@ +package gtPlusPlus.core.slots; + +import net.minecraft.inventory.IInventory; +import net.minecraft.item.ItemFood; +import net.minecraft.item.ItemStack; +import gtPlusPlus.api.objects.Logger; +import gtPlusPlus.core.util.minecraft.FoodUtils; + +public class SlotMagicToolBag extends SlotGtTool { + + public SlotMagicToolBag(final IInventory base, final int x, final int y, final int z) { + super(base, x, y, z); + } + + @Override + public boolean isItemValid(final ItemStack itemstack) { + return isItemValid_STATIC(itemstack); + } + + public static boolean isItemValid_STATIC(final ItemStack itemstack) { + if ((itemstack.getItem() instanceof ItemFood) || (FoodUtils.isFood(itemstack))) { + Logger.WARNING(itemstack.getDisplayName() + " is a valid food."); + return true; + } + Logger.WARNING(itemstack.getDisplayName() + " is not a valid food."); + return false; + } + +} diff --git a/src/main/java/gtPlusPlus/core/slots/SlotModularBauble.java b/src/main/java/gtPlusPlus/core/slots/SlotModularBauble.java new file mode 100644 index 0000000000..4aef5bc877 --- /dev/null +++ b/src/main/java/gtPlusPlus/core/slots/SlotModularBauble.java @@ -0,0 +1,32 @@ +package gtPlusPlus.core.slots; + +import net.minecraft.inventory.IInventory; +import net.minecraft.inventory.Slot; +import net.minecraft.item.ItemStack; + +import gtPlusPlus.core.item.bauble.ModularBauble; + +public class SlotModularBauble extends Slot { + + public SlotModularBauble(final IInventory inventory, final int slot, final int x, final int y) { + super(inventory, slot, x, y); + + } + + @Override + public boolean isItemValid(final ItemStack itemstack) { + boolean isValid = false; + + if (itemstack != null) { + if (itemstack.getItem() instanceof ModularBauble) { + isValid = true; + } + } + return isValid; + } + + @Override + public int getSlotStackLimit() { + return 1; + } +} diff --git a/src/main/java/gtPlusPlus/core/slots/SlotModularBaubleUpgrades.java b/src/main/java/gtPlusPlus/core/slots/SlotModularBaubleUpgrades.java new file mode 100644 index 0000000000..dae62f0415 --- /dev/null +++ b/src/main/java/gtPlusPlus/core/slots/SlotModularBaubleUpgrades.java @@ -0,0 +1,56 @@ +package gtPlusPlus.core.slots; + +import static gtPlusPlus.core.tileentities.machines.TileEntityModularityTable.*; + +import java.util.Iterator; +import java.util.Map.Entry; + +import net.minecraft.inventory.IInventory; +import net.minecraft.inventory.Slot; +import net.minecraft.item.ItemStack; + +import gtPlusPlus.api.objects.Logger; +import gtPlusPlus.api.objects.data.Pair; +import gtPlusPlus.core.util.minecraft.ModularArmourUtils.BT; +import gtPlusPlus.core.util.minecraft.ModularArmourUtils.Modifiers; + +public class SlotModularBaubleUpgrades extends Slot { + + public SlotModularBaubleUpgrades(final IInventory inventory, final int slot, final int x, final int y) { + super(inventory, slot, x, y); + + } + + @Override + public boolean isItemValid(final ItemStack itemstack) { + boolean isValid = false; + if (itemstack != null) { + Logger.INFO("trying to insert " + itemstack.getDisplayName()); + Logger.INFO("Valid Upgrade count: " + mValidUpgradeList.size()); + + Iterator> it = mValidUpgradeListFormChange.entrySet().iterator(); + while (it.hasNext()) { + Entry pair = it.next(); + if (pair.getKey().getItem() == itemstack.getItem() + && pair.getKey().getItemDamage() == itemstack.getItemDamage()) { + isValid = true; + } + } + + Iterator>> it2 = mValidUpgradeList.entrySet().iterator(); + while (it2.hasNext()) { + Entry> pair = it2.next(); + if (pair.getKey().getItem() == itemstack.getItem() + && pair.getKey().getItemDamage() == itemstack.getItemDamage()) { + isValid = true; + } + } + } + return isValid; + } + + @Override + public int getSlotStackLimit() { + return 64; + } +} diff --git a/src/main/java/gtPlusPlus/core/slots/SlotNoInput.java b/src/main/java/gtPlusPlus/core/slots/SlotNoInput.java new file mode 100644 index 0000000000..1a1cf62e2b --- /dev/null +++ b/src/main/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(final IInventory inventory, final int index, final int x, final int y) { + super(inventory, index, x, y); + } + + @Override + public boolean isItemValid(final ItemStack itemstack) { + return false; + } + + @Override + public int getSlotStackLimit() { + return 0; + } + +} diff --git a/src/main/java/gtPlusPlus/core/slots/SlotNoInputLogging.java b/src/main/java/gtPlusPlus/core/slots/SlotNoInputLogging.java new file mode 100644 index 0000000000..762714ac94 --- /dev/null +++ b/src/main/java/gtPlusPlus/core/slots/SlotNoInputLogging.java @@ -0,0 +1,36 @@ +package gtPlusPlus.core.slots; + +import gtPlusPlus.api.objects.Logger; +import gtPlusPlus.core.util.minecraft.ItemUtils; +import net.minecraft.block.Block; +import net.minecraft.inventory.IInventory; +import net.minecraft.item.ItemStack; + +public class SlotNoInputLogging extends SlotNoInput { + + private final int aSlotIndex; + + public SlotNoInputLogging(final IInventory inventory, final int index, final int x, final int y) { + super(inventory, index, x, y); + aSlotIndex = index; + Logger.INFO("Slot "+index+" is doing logging"); + } + + @Override + public boolean isItemValid(final ItemStack itemstack) { + if (ItemUtils.checkForInvalidItems(itemstack)) { + Logger.INFO("Tried Inserting "+ItemUtils.getItemName(itemstack)+" into slot "+aSlotIndex); + Block b = Block.getBlockFromItem(itemstack.getItem()); + Logger.INFO(""+itemstack.getUnlocalizedName()); + if (b != null) { + Logger.INFO(""+b.getLocalizedName()); + Logger.INFO(""+b.getUnlocalizedName()); + } + } + else { + Logger.INFO("Bad Itemstack"); + } + return false; + } + +} diff --git a/src/main/java/gtPlusPlus/core/slots/SlotOutput.java b/src/main/java/gtPlusPlus/core/slots/SlotOutput.java new file mode 100644 index 0000000000..f22e0645f5 --- /dev/null +++ b/src/main/java/gtPlusPlus/core/slots/SlotOutput.java @@ -0,0 +1,96 @@ +package gtPlusPlus.core.slots; + +import cpw.mods.fml.common.FMLCommonHandler; + +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; + +public class SlotOutput extends SlotCrafting { + + private final IInventory craftMatrix; + private final EntityPlayer thePlayer; + private int amountCrafted; + + public SlotOutput(final EntityPlayer player, final InventoryCrafting craftingInventory, + final IInventory p_i45790_3_, final int slotIndex, final int xPosition, final 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(final 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(final 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(final ItemStack par1ItemStack, final 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(final ItemStack stack) { + stack.onCrafting(this.thePlayer.worldObj, this.thePlayer, this.amountCrafted); + this.amountCrafted = 0; + } + + @Override + public void onPickupFromSlot(final EntityPlayer playerIn, final ItemStack stack) { + { + FMLCommonHandler.instance().firePlayerCraftingEvent(playerIn, stack, this.craftMatrix); + this.onCrafting(stack); + for (int i = 0; i < this.craftMatrix.getSizeInventory(); ++i) { + final 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(this.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 diff --git a/src/main/java/gtPlusPlus/core/slots/SlotPollutionScrubber.java b/src/main/java/gtPlusPlus/core/slots/SlotPollutionScrubber.java new file mode 100644 index 0000000000..6dd3745d09 --- /dev/null +++ b/src/main/java/gtPlusPlus/core/slots/SlotPollutionScrubber.java @@ -0,0 +1,66 @@ +package gtPlusPlus.core.slots; + +import java.util.HashMap; + +import gregtech.api.items.GT_MetaGenerated_Tool; +import gregtech.api.util.GT_Utility; +import gtPlusPlus.core.item.general.ItemAirFilter; +import gtPlusPlus.core.item.general.ItemBasicScrubberTurbine; +import gtPlusPlus.core.lib.CORE; +import gtPlusPlus.core.recipe.common.CI; +import net.minecraft.inventory.IInventory; +import net.minecraft.inventory.Slot; +import net.minecraft.item.ItemStack; + +public class SlotPollutionScrubber extends Slot { + + private final int mType; + private final int mTier; + + private static HashMap mConveyorMap = new HashMap(); + + static { + for (int i=0; i<(CORE.MAIN_GREGTECH_5U_EXPERIMENTAL_FORK ? 9 : 5); i++) { + mConveyorMap.put(i, CI.getConveyor(i, 1)); + } + } + + public SlotPollutionScrubber(final int aType, final int aTier, final IInventory inventory, final int slot, final int x, final int y) { + super(inventory, slot, x, y); + mType = aType; + mTier = aTier; + } + + @Override + public synchronized boolean isItemValid(final ItemStack itemstack) { + return isItemValidForSlot(this, itemstack); + } + + public static synchronized boolean isItemValidForSlot(final SlotPollutionScrubber aSlot, final ItemStack itemstack) { + if (aSlot.mType == 0) { + if (itemstack.getItem() instanceof ItemBasicScrubberTurbine) { + return true; + } + if (itemstack.getItem() instanceof GT_MetaGenerated_Tool && itemstack.getItemDamage() >= 170 && itemstack.getItemDamage() <= 179){ + return true; + } + } + else if (aSlot.mType == 1) { + if (itemstack.getItem() instanceof ItemAirFilter) { + return true; + } + } + else if (aSlot.mType == 2) { + ItemStack aConveyorStack = mConveyorMap.get(aSlot.mTier); + if (GT_Utility.areStacksEqual(itemstack, aConveyorStack, true)) { + return true; + } + } + return false; + } + + @Override + public int getSlotStackLimit() { + return 1; + } +} diff --git a/src/main/java/gtPlusPlus/core/slots/SlotRTG.java b/src/main/java/gtPlusPlus/core/slots/SlotRTG.java new file mode 100644 index 0000000000..181052cc57 --- /dev/null +++ b/src/main/java/gtPlusPlus/core/slots/SlotRTG.java @@ -0,0 +1,26 @@ +package gtPlusPlus.core.slots; + +import net.minecraft.inventory.IInventory; +import net.minecraft.inventory.Slot; +import net.minecraft.item.ItemStack; + +import ic2.core.Ic2Items; + +public class SlotRTG extends Slot { + + public SlotRTG(final IInventory inventory, final int x, final int y, final int z) { + super(inventory, x, y, z); + + } + + @Override + public boolean isItemValid(final ItemStack itemstack) { + return itemstack.getItem().getClass() == Ic2Items.RTGPellets.getItem().getClass(); + } + + @Override + public int getSlotStackLimit() { + return 1; + } + +} diff --git a/src/main/java/gtPlusPlus/core/slots/SlotToolBox.java b/src/main/java/gtPlusPlus/core/slots/SlotToolBox.java new file mode 100644 index 0000000000..87967b75b5 --- /dev/null +++ b/src/main/java/gtPlusPlus/core/slots/SlotToolBox.java @@ -0,0 +1,113 @@ +package gtPlusPlus.core.slots; + +import net.minecraft.inventory.IInventory; +import net.minecraft.item.ItemStack; +import net.minecraft.item.ItemTool; +import gregtech.api.items.GT_MetaGenerated_Tool; + +import gtPlusPlus.api.objects.Logger; +import gtPlusPlus.api.objects.data.AutoMap; +import gtPlusPlus.core.util.reflect.ReflectionUtils; + +public class SlotToolBox extends SlotGtTool { + + private static final AutoMap mSupportedCustomTools = new AutoMap(); + + static { + //Look for Supported custom tool types + Class temp; + + //IHL Pumps + temp = ReflectionUtils.getClass("ihl.handpump.IHLHandPump"); + if (temp != null) { + mSupportedCustomTools.put(temp); + temp = null; + } + + //IC2 Electrics + temp = ReflectionUtils.getClass("ic2.api.item.IElectricItem"); + if (temp != null) { + mSupportedCustomTools.put(temp); + temp = null; + } + + //IC2 Boxables + temp = ReflectionUtils.getClass(" ic2.api.item.IBoxable"); + if (temp != null) { + mSupportedCustomTools.put(temp); + temp = null; + } + + //Tinkers Tools + temp = ReflectionUtils.getClass("tconstruct.library.tools.Weapon"); + if (temp != null) { + mSupportedCustomTools.put(temp); + temp = null; + } + //BattleGear Weapons + temp = ReflectionUtils.getClass("mods.battlegear2.api.weapons.IBattlegearWeapon"); + if (temp != null) { + mSupportedCustomTools.put(temp); + temp = null; + } + + + //OpenMods + String[] OpenModsContent = new String[] {"openblocks.common.item.ItemDevNull", "openblocks.common.item.ItemHangGlider", "openblocks.common.item.ItemWrench", "openblocks.common.item.ItemSleepingBag"}; + for (String t : OpenModsContent) { + temp = ReflectionUtils.getClass(t); + if (temp != null) { + mSupportedCustomTools.put(temp); + temp = null; + } + } + + //GC Wrench + temp = ReflectionUtils.getClass("micdoodle8.mods.galacticraft.core.items.ItemUniversalWrench"); + if (temp != null) { + mSupportedCustomTools.put(temp); + temp = null; + } + + //EIO + String[] EioContent = new String[] {"crazypants.enderio.api.tool.ITool", "crazypants.enderio.item.ItemMagnet", "crazypants.enderio.item.ItemConduitProbe"}; + for (String t : EioContent) { + temp = ReflectionUtils.getClass(t); + if (temp != null) { + mSupportedCustomTools.put(temp); + temp = null; + } + } + + //Forestry + temp = ReflectionUtils.getClass("forestry.core.items.ItemForestryTool"); + if (temp != null) { + mSupportedCustomTools.put(temp); + temp = null; + } + } + + public SlotToolBox(final IInventory base, final int x, final int y, final int z) { + super(base, x, y, z); + } + + @Override + public boolean isItemValid(final ItemStack itemstack) { + return isItemValid_STATIC(itemstack); + } + + public static boolean isItemValid_STATIC(final ItemStack itemstack) { + if ((itemstack.getItem() instanceof GT_MetaGenerated_Tool) || (itemstack.getItem() instanceof ItemTool)) { + Logger.WARNING(itemstack.getDisplayName() + " is a valid Tool."); + return true; + } + for (Class C : mSupportedCustomTools) { + if (C.isInstance(itemstack.getItem())) { + return true; + } + } + Logger.WARNING(itemstack.getDisplayName() + " is not a valid Tool."); + return false; + } + +} diff --git a/src/main/java/gtPlusPlus/core/slots/SlotVolumetricFlask.java b/src/main/java/gtPlusPlus/core/slots/SlotVolumetricFlask.java new file mode 100644 index 0000000000..b8955f6dc8 --- /dev/null +++ b/src/main/java/gtPlusPlus/core/slots/SlotVolumetricFlask.java @@ -0,0 +1,30 @@ +package gtPlusPlus.core.slots; + +import gtPlusPlus.xmod.gregtech.common.helpers.VolumetricFlaskHelper; +import net.minecraft.inventory.IInventory; +import net.minecraft.inventory.Slot; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; + +public class SlotVolumetricFlask extends Slot { + + public static Item mFlask; + + public SlotVolumetricFlask(final IInventory inventory, final int slot, final int x, final int y) { + super(inventory, slot, x, y); + } + + @Override + public synchronized boolean isItemValid(final ItemStack itemstack) { + return isItemValidForSlot(itemstack); + } + + public static synchronized boolean isItemValidForSlot(final ItemStack itemstack) { + return VolumetricFlaskHelper.isVolumetricFlask(itemstack); + } + + @Override + public int getSlotStackLimit() { + return 16; + } +} -- cgit