aboutsummaryrefslogtreecommitdiff
path: root/src/Java/gtPlusPlus/core/slots
diff options
context:
space:
mode:
authorDraknyte1 <Draknyte1@hotmail.com>2016-09-25 21:11:05 +1000
committerDraknyte1 <Draknyte1@hotmail.com>2016-09-25 21:11:05 +1000
commitd43694eb98a0968190c3dbaa4ab5121c39feaf1f (patch)
tree441d4ed0300d675382539b8a650abe8e7bdf67f9 /src/Java/gtPlusPlus/core/slots
parent6a95a11b16cfa38e7789418d93e70b1dc12b19c7 (diff)
downloadGT5-Unofficial-d43694eb98a0968190c3dbaa4ab5121c39feaf1f.tar.gz
GT5-Unofficial-d43694eb98a0968190c3dbaa4ab5121c39feaf1f.tar.bz2
GT5-Unofficial-d43694eb98a0968190c3dbaa4ab5121c39feaf1f.zip
+ Added the Work Bench, from Gregtech 4.
% Renamed a method that converted arrays to fixed sized lists. % Added a Util function to determine server or client easier.
Diffstat (limited to 'src/Java/gtPlusPlus/core/slots')
-rw-r--r--src/Java/gtPlusPlus/core/slots/SlotCrafting.java164
-rw-r--r--src/Java/gtPlusPlus/core/slots/SlotGtTool.java25
2 files changed, 189 insertions, 0 deletions
diff --git a/src/Java/gtPlusPlus/core/slots/SlotCrafting.java b/src/Java/gtPlusPlus/core/slots/SlotCrafting.java
new file mode 100644
index 0000000000..0c9989158d
--- /dev/null
+++ b/src/Java/gtPlusPlus/core/slots/SlotCrafting.java
@@ -0,0 +1,164 @@
+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 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(EntityPlayer p_i1823_1_, IInventory p_i1823_2_, IInventory p_i1823_3_, int p_i1823_4_, int p_i1823_5_, 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.
+ */
+ 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.
+ */
+ public ItemStack decrStackSize(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).
+ */
+ protected void onCrafting(ItemStack p_75210_1_, 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.
+ */
+ protected void onCrafting(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);
+ }
+ }
+
+ public void onPickupFromSlot(EntityPlayer p_82870_1_, ItemStack p_82870_2_)
+ {
+ FMLCommonHandler.instance().firePlayerCraftingEvent(p_82870_1_, p_82870_2_, craftMatrix);
+ this.onCrafting(p_82870_2_);
+
+ 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);
+ }
+ }
+ }
+ }
+ }
+ }
+} \ No newline at end of file
diff --git a/src/Java/gtPlusPlus/core/slots/SlotGtTool.java b/src/Java/gtPlusPlus/core/slots/SlotGtTool.java
new file mode 100644
index 0000000000..ec77aa10bd
--- /dev/null
+++ b/src/Java/gtPlusPlus/core/slots/SlotGtTool.java
@@ -0,0 +1,25 @@
+package gtPlusPlus.core.slots;
+
+import gregtech.api.interfaces.IToolStats;
+import net.minecraft.inventory.IInventory;
+import net.minecraft.inventory.Slot;
+import net.minecraft.item.ItemStack;
+
+public class SlotGtTool extends Slot{
+
+ public SlotGtTool(IInventory inventory, int x, int y, int z) {
+ super(inventory, x, y, z);
+
+ }
+
+ @Override
+ public boolean isItemValid(ItemStack itemstack) {
+ return itemstack.getItem() instanceof IToolStats;
+ }
+
+ @Override
+ public int getSlotStackLimit() {
+ return 1;
+ }
+
+}