diff options
| author | Raven Szewczyk <git@eigenraven.me> | 2024-05-24 19:50:35 +0100 |
|---|---|---|
| committer | Raven Szewczyk <git@eigenraven.me> | 2024-05-24 19:50:35 +0100 |
| commit | 6d1b2216464d4dad449ac6fcfec476832224a55e (patch) | |
| tree | 526a0c15f7056313c80e6c0386e025e9b3f61781 /src/main/java/gtPlusPlus/core/slots | |
| parent | b5d35f40afa606ed1b07061dad82e0521a59c186 (diff) | |
| download | GT5-Unofficial-6d1b2216464d4dad449ac6fcfec476832224a55e.tar.gz GT5-Unofficial-6d1b2216464d4dad449ac6fcfec476832224a55e.tar.bz2 GT5-Unofficial-6d1b2216464d4dad449ac6fcfec476832224a55e.zip | |
Merge addon sources
Diffstat (limited to 'src/main/java/gtPlusPlus/core/slots')
8 files changed, 552 insertions, 0 deletions
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..323943b950 --- /dev/null +++ b/src/main/java/gtPlusPlus/core/slots/SlotCrafting.java @@ -0,0 +1,154 @@ +package gtPlusPlus.core.slots; + +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.Item; +import net.minecraft.item.ItemHoe; +import net.minecraft.item.ItemPickaxe; +import net.minecraft.item.ItemStack; +import net.minecraft.item.ItemSword; +import net.minecraft.stats.AchievementList; +import net.minecraftforge.common.MinecraftForge; +import net.minecraftforge.event.entity.player.PlayerDestroyItemEvent; + +import cpw.mods.fml.common.FMLCommonHandler; + +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; + + 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); + } + } + } + } + } + } +} 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..03581ef705 --- /dev/null +++ b/src/main/java/gtPlusPlus/core/slots/SlotCraftingNoCollect.java @@ -0,0 +1,139 @@ +package gtPlusPlus.core.slots; + +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.Item; +import net.minecraft.item.ItemHoe; +import net.minecraft.item.ItemPickaxe; +import net.minecraft.item.ItemStack; +import net.minecraft.item.ItemSword; +import net.minecraft.stats.AchievementList; + +import cpw.mods.fml.common.FMLCommonHandler; + +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; + } +} 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..3b39da877a --- /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/SlotGeneric.java b/src/main/java/gtPlusPlus/core/slots/SlotGeneric.java new file mode 100644 index 0000000000..bfb384efe8 --- /dev/null +++ b/src/main/java/gtPlusPlus/core/slots/SlotGeneric.java @@ -0,0 +1,22 @@ +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/SlotIntegratedCircuit.java b/src/main/java/gtPlusPlus/core/slots/SlotIntegratedCircuit.java new file mode 100644 index 0000000000..dc75c88369 --- /dev/null +++ b/src/main/java/gtPlusPlus/core/slots/SlotIntegratedCircuit.java @@ -0,0 +1,110 @@ +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/SlotJukebox.java b/src/main/java/gtPlusPlus/core/slots/SlotJukebox.java new file mode 100644 index 0000000000..1351e5c188 --- /dev/null +++ b/src/main/java/gtPlusPlus/core/slots/SlotJukebox.java @@ -0,0 +1,35 @@ +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/SlotNoInput.java b/src/main/java/gtPlusPlus/core/slots/SlotNoInput.java new file mode 100644 index 0000000000..d4e8696075 --- /dev/null +++ b/src/main/java/gtPlusPlus/core/slots/SlotNoInput.java @@ -0,0 +1,22 @@ +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/SlotVolumetricFlask.java b/src/main/java/gtPlusPlus/core/slots/SlotVolumetricFlask.java new file mode 100644 index 0000000000..c84c88a0b5 --- /dev/null +++ b/src/main/java/gtPlusPlus/core/slots/SlotVolumetricFlask.java @@ -0,0 +1,28 @@ +package gtPlusPlus.core.slots; + +import net.minecraft.inventory.IInventory; +import net.minecraft.inventory.Slot; +import net.minecraft.item.ItemStack; + +import gtPlusPlus.xmod.gregtech.common.helpers.VolumetricFlaskHelper; + +public class SlotVolumetricFlask extends Slot { + + 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; + } +} |
