2014-11-14 12:02:52 +01:00
|
|
|
/*
|
|
|
|
* This file is part of Applied Energistics 2.
|
|
|
|
* Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved.
|
|
|
|
*
|
|
|
|
* Applied Energistics 2 is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Lesser General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* Applied Energistics 2 is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public License
|
|
|
|
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
|
|
|
|
*/
|
|
|
|
|
2013-12-27 23:59:59 +01:00
|
|
|
package appeng.container.slot;
|
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
|
2013-12-27 23:59:59 +01:00
|
|
|
import net.minecraft.entity.player.EntityPlayer;
|
2014-02-09 02:34:52 +01:00
|
|
|
import net.minecraft.init.Blocks;
|
|
|
|
import net.minecraft.init.Items;
|
2013-12-27 23:59:59 +01:00
|
|
|
import net.minecraft.inventory.IInventory;
|
2014-02-05 08:25:44 +01:00
|
|
|
import net.minecraft.item.Item;
|
2014-02-09 02:34:52 +01:00
|
|
|
import net.minecraft.item.ItemHoe;
|
|
|
|
import net.minecraft.item.ItemPickaxe;
|
2014-02-05 08:25:44 +01:00
|
|
|
import net.minecraft.item.ItemStack;
|
2014-02-09 02:34:52 +01:00
|
|
|
import net.minecraft.item.ItemSword;
|
2015-05-09 00:00:52 +02:00
|
|
|
import net.minecraft.item.ItemTool;
|
2014-02-05 08:25:44 +01:00
|
|
|
import net.minecraft.stats.AchievementList;
|
|
|
|
import net.minecraftforge.common.MinecraftForge;
|
|
|
|
import net.minecraftforge.event.entity.player.PlayerDestroyItemEvent;
|
2014-12-29 21:59:05 +01:00
|
|
|
|
2014-02-09 02:34:52 +01:00
|
|
|
import cpw.mods.fml.common.FMLCommonHandler;
|
2013-12-27 23:59:59 +01:00
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
|
2014-02-05 08:25:44 +01:00
|
|
|
public class AppEngCraftingSlot extends AppEngSlot
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
/**
|
|
|
|
* The craft matrix inventory linked to this result slot.
|
|
|
|
*/
|
2014-02-05 08:25:44 +01:00
|
|
|
private final IInventory craftMatrix;
|
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
/**
|
|
|
|
* The player that is using the GUI where this slot resides.
|
|
|
|
*/
|
2014-09-29 09:54:34 +02:00
|
|
|
private final EntityPlayer thePlayer;
|
2014-02-05 08:25:44 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The number of items that have been crafted so far. Gets passed to ItemStack.onCrafting before being reset.
|
|
|
|
*/
|
|
|
|
private int amountCrafted;
|
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
public AppEngCraftingSlot( EntityPlayer par1EntityPlayer, IInventory par2IInventory, IInventory par3IInventory, int par4, int par5, int par6 )
|
|
|
|
{
|
2014-02-05 08:25:44 +01:00
|
|
|
super( par3IInventory, par4, par5, par6 );
|
|
|
|
this.thePlayer = par1EntityPlayer;
|
|
|
|
this.craftMatrix = par2IInventory;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Check if the stack is a valid item for this slot. Always true beside for the armor slots.
|
|
|
|
*/
|
2014-09-28 20:34:00 +02:00
|
|
|
@Override
|
2015-04-03 08:54:31 +02:00
|
|
|
public boolean isItemValid( ItemStack par1ItemStack )
|
2014-02-05 08:25:44 +01:00
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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).
|
|
|
|
*/
|
2014-09-28 20:34:00 +02:00
|
|
|
@Override
|
2015-04-03 08:54:31 +02:00
|
|
|
protected void onCrafting( ItemStack par1ItemStack, int par2 )
|
2014-02-05 08:25:44 +01:00
|
|
|
{
|
|
|
|
this.amountCrafted += par2;
|
|
|
|
this.onCrafting( par1ItemStack );
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|
|
|
|
|
2014-02-05 08:25:44 +01:00
|
|
|
/**
|
|
|
|
* the itemStack passed in is the output - ie, iron ingots, and pickaxes, not ore and wood.
|
|
|
|
*/
|
2014-09-28 20:34:00 +02:00
|
|
|
@Override
|
2015-04-03 08:54:31 +02:00
|
|
|
protected void onCrafting( ItemStack par1ItemStack )
|
2014-02-05 08:25:44 +01:00
|
|
|
{
|
|
|
|
par1ItemStack.onCrafting( this.thePlayer.worldObj, this.thePlayer, this.amountCrafted );
|
|
|
|
this.amountCrafted = 0;
|
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
if( par1ItemStack.getItem() == Item.getItemFromBlock( Blocks.crafting_table ) )
|
2014-02-05 08:25:44 +01:00
|
|
|
{
|
|
|
|
this.thePlayer.addStat( AchievementList.buildWorkBench, 1 );
|
|
|
|
}
|
2014-02-09 02:34:52 +01:00
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
if( par1ItemStack.getItem() instanceof ItemPickaxe )
|
2014-02-05 08:25:44 +01:00
|
|
|
{
|
|
|
|
this.thePlayer.addStat( AchievementList.buildPickaxe, 1 );
|
|
|
|
}
|
2014-02-09 02:34:52 +01:00
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
if( par1ItemStack.getItem() == Item.getItemFromBlock( Blocks.furnace ) )
|
2014-02-05 08:25:44 +01:00
|
|
|
{
|
|
|
|
this.thePlayer.addStat( AchievementList.buildFurnace, 1 );
|
|
|
|
}
|
2014-02-09 02:34:52 +01:00
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
if( par1ItemStack.getItem() instanceof ItemHoe )
|
2014-02-05 08:25:44 +01:00
|
|
|
{
|
|
|
|
this.thePlayer.addStat( AchievementList.buildHoe, 1 );
|
|
|
|
}
|
2014-02-09 02:34:52 +01:00
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
if( par1ItemStack.getItem() == Items.bread )
|
2014-02-05 08:25:44 +01:00
|
|
|
{
|
|
|
|
this.thePlayer.addStat( AchievementList.makeBread, 1 );
|
|
|
|
}
|
2014-02-09 02:34:52 +01:00
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
if( par1ItemStack.getItem() == Items.cake )
|
2014-02-05 08:25:44 +01:00
|
|
|
{
|
|
|
|
this.thePlayer.addStat( AchievementList.bakeCake, 1 );
|
|
|
|
}
|
2014-02-09 02:34:52 +01:00
|
|
|
|
2015-05-09 00:00:52 +02:00
|
|
|
if( par1ItemStack.getItem() instanceof ItemPickaxe && ( (ItemTool) par1ItemStack.getItem() ).func_150913_i() != Item.ToolMaterial.WOOD )
|
2014-02-05 08:25:44 +01:00
|
|
|
{
|
|
|
|
this.thePlayer.addStat( AchievementList.buildBetterPickaxe, 1 );
|
|
|
|
}
|
2014-02-09 02:34:52 +01:00
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
if( par1ItemStack.getItem() instanceof ItemSword )
|
2014-02-05 08:25:44 +01:00
|
|
|
{
|
|
|
|
this.thePlayer.addStat( AchievementList.buildSword, 1 );
|
|
|
|
}
|
2014-02-09 02:34:52 +01:00
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
if( par1ItemStack.getItem() == Item.getItemFromBlock( Blocks.enchanting_table ) )
|
2014-02-05 08:25:44 +01:00
|
|
|
{
|
|
|
|
this.thePlayer.addStat( AchievementList.enchantments, 1 );
|
|
|
|
}
|
2014-02-09 02:34:52 +01:00
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
if( par1ItemStack.getItem() == Item.getItemFromBlock( Blocks.bookshelf ) )
|
2014-02-05 08:25:44 +01:00
|
|
|
{
|
|
|
|
this.thePlayer.addStat( AchievementList.bookcase, 1 );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-09-28 20:34:00 +02:00
|
|
|
@Override
|
2015-04-03 08:54:31 +02:00
|
|
|
public void onPickupFromSlot( EntityPlayer par1EntityPlayer, ItemStack par2ItemStack )
|
2014-02-05 08:25:44 +01:00
|
|
|
{
|
2014-12-29 15:13:47 +01:00
|
|
|
FMLCommonHandler.instance().firePlayerCraftingEvent( par1EntityPlayer, par2ItemStack, this.craftMatrix );
|
2014-02-05 08:25:44 +01:00
|
|
|
this.onCrafting( par2ItemStack );
|
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
for( int i = 0; i < this.craftMatrix.getSizeInventory(); ++i )
|
2014-02-05 08:25:44 +01:00
|
|
|
{
|
|
|
|
ItemStack itemstack1 = this.craftMatrix.getStackInSlot( i );
|
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
if( itemstack1 != null )
|
2014-02-05 08:25:44 +01:00
|
|
|
{
|
|
|
|
this.craftMatrix.decrStackSize( i, 1 );
|
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
if( itemstack1.getItem().hasContainerItem( itemstack1 ) )
|
2014-02-05 08:25:44 +01:00
|
|
|
{
|
2014-02-09 02:34:52 +01:00
|
|
|
ItemStack itemstack2 = itemstack1.getItem().getContainerItem( itemstack1 );
|
2014-02-05 08:25:44 +01:00
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
if( itemstack2 != null && itemstack2.isItemStackDamageable() && itemstack2.getItemDamage() > itemstack2.getMaxDamage() )
|
2014-02-05 08:25:44 +01:00
|
|
|
{
|
2014-12-29 15:13:47 +01:00
|
|
|
MinecraftForge.EVENT_BUS.post( new PlayerDestroyItemEvent( this.thePlayer, itemstack2 ) );
|
2014-02-09 02:34:52 +01:00
|
|
|
continue;
|
2014-02-05 08:25:44 +01:00
|
|
|
}
|
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
if( !itemstack1.getItem().doesContainerItemLeaveCraftingGrid( itemstack1 ) || !this.thePlayer.inventory.addItemStackToInventory( itemstack2 ) )
|
2014-02-05 08:25:44 +01:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
if( this.craftMatrix.getStackInSlot( i ) == null )
|
2014-02-05 08:25:44 +01:00
|
|
|
{
|
|
|
|
this.craftMatrix.setInventorySlotContents( i, itemstack2 );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-02-09 02:34:52 +01:00
|
|
|
this.thePlayer.dropPlayerItemWithRandomChoice( itemstack2, false );
|
2014-02-05 08:25:44 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-04-03 08:54:31 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* 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 );
|
|
|
|
}
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|