diff options
Diffstat (limited to 'src/Java/gtPlusPlus')
-rw-r--r-- | src/Java/gtPlusPlus/core/container/Container_ProjectTable.java | 44 | ||||
-rw-r--r-- | src/Java/gtPlusPlus/core/slots/SlotCraftingNoCollect.java | 165 |
2 files changed, 203 insertions, 6 deletions
diff --git a/src/Java/gtPlusPlus/core/container/Container_ProjectTable.java b/src/Java/gtPlusPlus/core/container/Container_ProjectTable.java index 6d26c50041..0100a422c1 100644 --- a/src/Java/gtPlusPlus/core/container/Container_ProjectTable.java +++ b/src/Java/gtPlusPlus/core/container/Container_ProjectTable.java @@ -9,11 +9,17 @@ import gtPlusPlus.core.util.Utils; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.InventoryPlayer; import net.minecraft.inventory.*; +import net.minecraft.inventory.SlotCrafting; import net.minecraft.item.ItemStack; +import net.minecraft.item.crafting.CraftingManager; import net.minecraft.world.World; public class Container_ProjectTable extends Container { + /** The crafting matrix inventory (3x3). */ + public InventoryCrafting craftMatrix = new InventoryCrafting(this, 3, 3); + public IInventory craftResult = new InventoryCraftResult(); + protected TileEntityProjectTable tile_entity; public final InventoryProjectMain inventoryGrid; public final InventoryProjectOutput inventoryOutputs; @@ -46,7 +52,9 @@ public class Container_ProjectTable extends Container { this.addSlotToContainer(new SlotDataStick(this.inventoryOutputs, 0, 26+(18*4), 7)); this.addSlotToContainer(new SlotNoInput(this.inventoryOutputs, 1, 26+(18*4), 43)); - + this.addSlotToContainer(new SlotCraftingNoCollect(inventory.player, this.craftMatrix, this.craftResult, 0, 26+(18*3), 25)); + + int o = 0; //Storage Side for (var6 = 0; var6 < 3; ++var6) @@ -54,7 +62,7 @@ public class Container_ProjectTable extends Container { for (var7 = 0; var7 < 3; ++var7) { //Utils.LOG_WARNING("Adding slots at var:"+(var7 + var6 * 4)+" x:"+(8 + var7 * 18)+" y:"+(7 + var6 * 18)); - this.addSlotToContainer(new Slot(this.inventoryGrid, nextFreeSlot, 8 + (var7 * 18), 7 + (var6 * 18))); + this.addSlotToContainer(new Slot(this.craftMatrix, nextFreeSlot, 8 + (var7 * 18), 7 + (var6 * 18))); this.slotGrid[o] = nextFreeSlot; nextFreeSlot++; o++; @@ -76,8 +84,33 @@ public class Container_ProjectTable extends Container { { this.addSlotToContainer(new Slot(inventory, var6, 8 + (var6 * 18), 142)); } + + this.onCraftMatrixChanged(this.craftMatrix); } + + /** + * Callback for when the crafting matrix is changed. + */ + public void onCraftMatrixChanged(IInventory p_75130_1_) + { + this.craftResult.setInventorySlotContents(0, CraftingManager.getInstance().findMatchingRecipe(this.craftMatrix, this.worldObj)); + } + + /** + * Called when the container is closed. + */ + public void onContainerClosed(EntityPlayer p_75134_1_){ + super.onContainerClosed(p_75134_1_); + if (!this.worldObj.isRemote){ + for (int i = 0; i < 9; ++i){ + ItemStack itemstack = this.craftMatrix.getStackInSlotOnClosing(i); + /* if (itemstack != null){ + p_75134_1_.dropPlayerItemWithRandomChoice(itemstack, false); + }*/ + } + } + } @Override public ItemStack slotClick(final int aSlotIndex, final int aMouseclick, final int aShifthold, final EntityPlayer aPlayer){ @@ -178,10 +211,9 @@ public class Container_ProjectTable extends Container { } //Can merge Slot - @Override - public boolean func_94530_a(final ItemStack p_94530_1_, final Slot p_94530_2_) { - return super.func_94530_a(p_94530_1_, p_94530_2_); - } + public boolean func_94530_a(ItemStack p_94530_1_, Slot p_94530_2_){ + return p_94530_2_.inventory != this.craftResult && super.func_94530_a(p_94530_1_, p_94530_2_); + } }
\ No newline at end of file diff --git a/src/Java/gtPlusPlus/core/slots/SlotCraftingNoCollect.java b/src/Java/gtPlusPlus/core/slots/SlotCraftingNoCollect.java new file mode 100644 index 0000000000..8ab1a48277 --- /dev/null +++ b/src/Java/gtPlusPlus/core/slots/SlotCraftingNoCollect.java @@ -0,0 +1,165 @@ +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.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; + +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. + */ + 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 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). + */ + 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. + */ + 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); + } + } + + 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 |