Java Code Examples for net.minecraft.item.ItemStack#onCrafting()

The following examples show how to use net.minecraft.item.ItemStack#onCrafting() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CraftingRecipeResolver.java    From GregTech with GNU Lesser General Public License v3.0 6 votes vote down vote up
public void handleItemCraft(ItemStack itemStack, EntityPlayer player, boolean simulate) {
    itemStack.onCrafting(world, player, 1);
    itemStack.getItem().onCreated(itemStack, world, player);
    if (!simulate) {
        //if we're not simulated, fire the event, unlock recipe and add crafted items
        FMLCommonHandler.instance().firePlayerCraftingEvent(player, itemStack, inventoryCrafting);
        if (cachedRecipe != null && !cachedRecipe.isDynamic()) {
            player.unlockRecipes(Lists.newArrayList(cachedRecipe));
        }
        if (cachedRecipe != null) {
            ItemStack resultStack = cachedRecipe.getCraftingResult(inventoryCrafting);
            this.itemsCrafted += resultStack.getCount();
            recipeMemory.notifyRecipePerformed(craftingGrid, resultStack);
        }
    }
}
 
Example 2
Source File: SlotSpecialCraftingOutput.java    From TFC2 with GNU General Public License v3.0 6 votes vote down vote up
@Override
public ItemStack onTake(EntityPlayer player, ItemStack itemstack)
{
	itemstack.onCrafting(player.world, thePlayer, slotNumber);
	FMLCommonHandler.instance().firePlayerCraftingEvent(player, itemstack, player.inventory);

	for (int i = 0; i < craftMatrix.getSizeInventory(); i++)
	{
		// Clear out everything in the crafting matrix.
		craftMatrix.setInventorySlotContents(i, ItemStack.EMPTY);
		if (player.world.isRemote)
		{
			((GuiKnapping) Minecraft.getMinecraft().currentScreen).resetButton(i);
		}
	}

	// Reset decreasedStack flag so another item can be created if the clay forming is reset with NEI.
	((ContainerSpecialCrafting) container).setDecreasedStack(false);
	return itemstack;
}
 
Example 3
Source File: SlotItemHandlerCraftResult.java    From enderutilities with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
protected void onCrafting(ItemStack stack)
{
    if (this.amountCrafted > 0)
    {
        stack.onCrafting(this.player.getEntityWorld(), this.player, this.amountCrafted);
        net.minecraftforge.fml.common.FMLCommonHandler.instance().firePlayerCraftingEvent(this.player, stack, this.craftMatrix);
    }

    this.amountCrafted = 0;

    IRecipe recipe = this.craftResult.getRecipe();

    if (recipe != null && recipe.isDynamic() == false)
    {
        this.player.unlockRecipes(Lists.newArrayList(recipe));
        this.craftResult.setRecipe(null);
    }
}
 
Example 4
Source File: SlotItemHandlerFurnaceOutput.java    From enderutilities with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
protected void onCrafting(ItemStack stack)
{
    stack.onCrafting(this.player.getEntityWorld(), this.player, this.amountCrafted);

    if (this.player.getEntityWorld().isRemote == false)
    {
        int i = this.amountCrafted;
        float f = FurnaceRecipes.instance().getSmeltingExperience(stack);

        if (f == 0.0F)
        {
            i = 0;
        }
        else if (f < 1.0F)
        {
            int j = MathHelper.floor((float)i * f);

            if (j < MathHelper.ceil((float)i * f) && Math.random() < (double)((float)i * f - (float)j))
            {
                ++j;
            }

            i = j;
        }

        while (i > 0)
        {
            int k = EntityXPOrb.getXPSplit(i);
            i -= k;
            this.player.getEntityWorld().spawnEntity(new EntityXPOrb(this.player.getEntityWorld(), this.player.posX, this.player.posY + 0.5D, this.player.posZ + 0.5D, k));
        }
    }

    this.amountCrafted = 0;
    net.minecraftforge.fml.common.FMLCommonHandler.instance().firePlayerSmeltedEvent(player, stack);
}
 
Example 5
Source File: TileCraftingGrid.java    From Translocators with MIT License 5 votes vote down vote up
private void doCraft(ItemStack mresult, InventoryCrafting craftMatrix, EntityPlayer player) {
    giveOrDropItem(mresult, player);

    FMLCommonHandler.instance().firePlayerCraftingEvent(player, mresult, craftMatrix);
    mresult.onCrafting(worldObj, player, mresult.stackSize);

    for (int slot = 0; slot < 9; ++slot) {
        ItemStack stack = craftMatrix.getStackInSlot(slot);
        if (stack == null)
            continue;

        craftMatrix.decrStackSize(slot, 1);
        if (stack.getItem().hasContainerItem(stack)) {
            ItemStack container = stack.getItem().getContainerItem(stack);

            if (container != null) {
                if (container.isItemStackDamageable() && container.getItemDamage() > container.getMaxDamage())
                    container = null;

                craftMatrix.setInventorySlotContents(slot, container);
            }
        }
    }

    for (int i = 0; i < 9; i++)
        items[i] = craftMatrix.getStackInSlot(i);
}
 
Example 6
Source File: SlotCompostOutput.java    From GardenCollection with MIT License 5 votes vote down vote up
@Override
protected void onCrafting (ItemStack itemStack) {
    itemStack.onCrafting(player.worldObj, player, amountCrafted);
    amountCrafted = 0;

    //FMLCommonHandler.instance().firePlayerCraftingEvent(player, itemStack, inputInventory);
}
 
Example 7
Source File: SlotSaltFurnace.java    From TofuCraftReload with MIT License 4 votes vote down vote up
/**
 * the itemStack passed in is the output - ie, iron ingots, and pickaxes, not ore and wood.
 */
@Override
protected void onCrafting(ItemStack par1ItemStack)
{
    par1ItemStack.onCrafting(this.thePlayer.world, this.thePlayer, this.field_75228_b);

    if (!this.thePlayer.world.isRemote)
    {
        int i = this.field_75228_b;
        float f = par1ItemStack.getItem() == ItemLoader.material ? 0.2f : par1ItemStack.getItem() == ItemLoader.nigari ? 0.3f : 0.0f;
        int j;

        if (f == 0.0F)
        {
            i = 0;
        }
        else if (f < 1.0F)
        {
            j = MathHelper.floor(i * f);

            if (j < MathHelper.ceil(i * f) && (float)Math.random() < i * f - j)
            {
                ++j;
            }

            i = j;
        }

        while (i > 0)
        {
            j = EntityXPOrb.getXPSplit(i);
            i -= j;
            this.thePlayer.world.spawnEntity(new EntityXPOrb(this.thePlayer.world, this.thePlayer.posX, this.thePlayer.posY + 0.5D, this.thePlayer.posZ + 0.5D, j));
        }
    }

    this.field_75228_b = 0;


    if (par1ItemStack.getItem() == ItemLoader.material)
    {
        TofuAdvancements.grantAdvancement(this.thePlayer, "getsalt");
    }
    else if (par1ItemStack.getItem() == ItemLoader.nigari)
    {
        TofuAdvancements.grantAdvancement(this.thePlayer, "getnigari");
    }
}
 
Example 8
Source File: SlotFirepitOutput.java    From TFC2 with GNU General Public License v3.0 4 votes vote down vote up
/**
 * the itemStack passed in is the output - ie, iron ingots, and pickaxes, not ore and wood.
 */
@Override
protected void onCrafting(ItemStack stack)
{
	stack.onCrafting(this.player.world, this.player, this.removeCount);

	if (!this.player.world.isRemote)
	{
		int i = this.removeCount;
		float f = FurnaceRecipes.instance().getSmeltingExperience(stack);

		if (f == 0.0F)
		{
			i = 0;
		}
		else if (f < 1.0F)
		{
			int j = MathHelper.floor((float)i * f);

			if (j < MathHelper.ceil((float)i * f) && Math.random() < (double)((float)i * f - (float)j))
			{
				++j;
			}

			i = j;
		}

		while (i > 0)
		{
			int k = EntityXPOrb.getXPSplit(i);
			i -= k;
			this.player.world.spawnEntity(new EntityXPOrb(this.player.world, this.player.posX, this.player.posY + 0.5D, this.player.posZ + 0.5D, k));
		}
	}

	this.removeCount = 0;

	net.minecraftforge.fml.common.FMLCommonHandler.instance().firePlayerSmeltedEvent(player, stack);

	if (stack.getItem() == Items.IRON_INGOT)
	{
		this.player.addStat(AchievementList.ACQUIRE_IRON);
	}

	if (stack.getItem() == Items.COOKED_FISH)
	{
		this.player.addStat(AchievementList.COOK_FISH);
	}
}
 
Example 9
Source File: SlotPottery.java    From GardenCollection with MIT License 4 votes vote down vote up
@Override
protected void onCrafting (ItemStack itemStack) {
    itemStack.onCrafting(player.worldObj, player, amountCrafted);
    amountCrafted = 0;
}
 
Example 10
Source File: SlotBloomeryOutput.java    From GardenCollection with MIT License 4 votes vote down vote up
@Override
protected void onCrafting (ItemStack itemStack) {
    itemStack.onCrafting(player.worldObj, player, amountCrafted);
    amountCrafted = 0;
}