Search in sources :

Example 1 with IBaseRecipeType

use of reborncore.api.recipe.IBaseRecipeType in project TechReborn by TechReborn.

the class BehaviorDispenseScrapbox method dispenseStack.

@Override
protected ItemStack dispenseStack(IBlockSource source, ItemStack stack) {
    if (dispenseScrapboxes) {
        List<IBaseRecipeType> scrapboxRecipeList = RecipeHandler.getRecipeClassFromName(Reference.SCRAPBOX_RECIPE);
        int random = new Random().nextInt(scrapboxRecipeList.size());
        ItemStack out = scrapboxRecipeList.get(random).getOutput(0);
        stack.splitStack(1);
        TileEntityDispenser tile = source.getBlockTileEntity();
        EnumFacing enumfacing = tile.getWorld().getBlockState(new BlockPos(source.getX(), source.getY(), source.getZ())).getValue(BlockDispenser.FACING);
        IPosition iposition = BlockDispenser.getDispensePosition(source);
        doDispense(source.getWorld(), out, 6, enumfacing, iposition);
    }
    return stack;
}
Also used : IPosition(net.minecraft.dispenser.IPosition) Random(java.util.Random) EnumFacing(net.minecraft.util.EnumFacing) IBaseRecipeType(reborncore.api.recipe.IBaseRecipeType) TileEntityDispenser(net.minecraft.tileentity.TileEntityDispenser) BlockPos(net.minecraft.util.math.BlockPos) ItemStack(net.minecraft.item.ItemStack)

Example 2 with IBaseRecipeType

use of reborncore.api.recipe.IBaseRecipeType in project TechReborn by TechReborn.

the class TileIronAlloyFurnace method smeltItem.

/**
 * Turn one item from the furnace source stack into the appropriate smelted
 * item in the furnace result stack
 */
public void smeltItem() {
    if (this.canSmelt()) {
        ItemStack itemstack = ItemStack.EMPTY;
        for (final IBaseRecipeType recipeType : RecipeHandler.getRecipeClassFromName(Reference.ALLOY_SMELTER_RECIPE)) {
            if (this.hasAllInputs(recipeType)) {
                itemstack = recipeType.getOutput(0);
                break;
            }
            if (!itemstack.isEmpty()) {
                break;
            }
        }
        if (this.getStackInSlot(this.output) == ItemStack.EMPTY) {
            this.setInventorySlotContents(this.output, itemstack.copy());
        } else if (this.getStackInSlot(this.output).getItem() == itemstack.getItem()) {
            this.decrStackSize(this.output, -itemstack.getCount());
        }
        for (final IBaseRecipeType recipeType : RecipeHandler.getRecipeClassFromName(Reference.ALLOY_SMELTER_RECIPE)) {
            boolean hasAllRecipes = true;
            if (this.hasAllInputs(recipeType)) {
            } else {
                hasAllRecipes = false;
            }
            if (hasAllRecipes) {
                for (Object input : recipeType.getInputs()) {
                    boolean useOreDict = input instanceof String || recipeType.useOreDic();
                    for (int inputSlot = 0; inputSlot < 2; inputSlot++) {
                        if (ItemUtils.isInputEqual(input, this.inventory.getStackInSlot(inputSlot), true, true, useOreDict)) {
                            int count = 1;
                            if (input instanceof ItemStack) {
                                count = RecipeTranslator.getStackFromObject(input).getCount();
                            }
                            inventory.decrStackSize(inputSlot, count);
                            break;
                        }
                    }
                }
            }
        }
    }
}
Also used : IBaseRecipeType(reborncore.api.recipe.IBaseRecipeType)

Example 3 with IBaseRecipeType

use of reborncore.api.recipe.IBaseRecipeType in project TechReborn by TechReborn.

the class ItemScrapBox method onItemRightClick.

@Override
public ActionResult<ItemStack> onItemRightClick(World world, EntityPlayer player, EnumHand hand) {
    ItemStack stack = player.getHeldItemMainhand();
    if (!world.isRemote) {
        List<IBaseRecipeType> scrapboxRecipeList = RecipeHandler.getRecipeClassFromName(Reference.SCRAPBOX_RECIPE);
        int random = world.rand.nextInt(scrapboxRecipeList.size());
        ItemStack out = scrapboxRecipeList.get(random).getOutput(0);
        WorldUtils.dropItem(out, world, player.getPosition());
        stack.shrink(1);
    }
    return new ActionResult<>(EnumActionResult.SUCCESS, stack);
}
Also used : EnumActionResult(net.minecraft.util.EnumActionResult) ActionResult(net.minecraft.util.ActionResult) IBaseRecipeType(reborncore.api.recipe.IBaseRecipeType) ItemStack(net.minecraft.item.ItemStack)

Example 4 with IBaseRecipeType

use of reborncore.api.recipe.IBaseRecipeType in project RebornCore by TechReborn.

the class RecipeCrafter method updateCurrentRecipe.

public void updateCurrentRecipe() {
    currentTickTime = 0;
    for (IBaseRecipeType recipe : RecipeHandler.getRecipeClassFromName(recipeName)) {
        // This checks to see if it has all of the inputs
        if (recipe.canCraft(parentTile) && hasAllInputs(recipe)) {
            // This checks to see if it can fit all of the outputs
            for (int i = 0; i < recipe.getOutputsSize(); i++) {
                if (!canFitStack(recipe.getOutput(i), outputSlots[i], recipe.useOreDic())) {
                    currentRecipe = null;
                    this.currentTickTime = 0;
                    setIsActive();
                    return;
                }
            }
            // Sets the current recipe then syncs
            setCurrentRecipe(recipe);
            this.currentNeededTicks = Math.max((int) (currentRecipe.tickTime() * (1.0 - getSpeedMultiplier())), 1);
            this.currentTickTime = 0;
            setIsActive();
            return;
        }
    }
}
Also used : IBaseRecipeType(reborncore.api.recipe.IBaseRecipeType)

Example 5 with IBaseRecipeType

use of reborncore.api.recipe.IBaseRecipeType in project TechReborn by TechReborn.

the class TileIronAlloyFurnace method canSmelt.

private boolean canSmelt() {
    if (this.getStackInSlot(this.input1) == ItemStack.EMPTY || this.getStackInSlot(this.input2) == ItemStack.EMPTY) {
        return false;
    } else {
        ItemStack itemstack = null;
        for (final IBaseRecipeType recipeType : RecipeHandler.getRecipeClassFromName(Reference.ALLOY_SMELTER_RECIPE)) {
            if (this.hasAllInputs(recipeType)) {
                itemstack = recipeType.getOutput(0);
                break;
            }
        }
        if (itemstack == null)
            return false;
        if (this.getStackInSlot(this.output) == ItemStack.EMPTY)
            return true;
        if (!this.getStackInSlot(this.output).isItemEqual(itemstack))
            return false;
        final int result = this.getStackInSlot(this.output).getCount() + itemstack.getCount();
        // Forge
        return result <= this.getInventoryStackLimit() && result <= this.getStackInSlot(this.output).getMaxStackSize();
    // BugFix:
    // Make
    // it
    // respect
    // stack
    // sizes
    // properly.
    }
}
Also used : IBaseRecipeType(reborncore.api.recipe.IBaseRecipeType)

Aggregations

IBaseRecipeType (reborncore.api.recipe.IBaseRecipeType)5 ItemStack (net.minecraft.item.ItemStack)2 Random (java.util.Random)1 IPosition (net.minecraft.dispenser.IPosition)1 TileEntityDispenser (net.minecraft.tileentity.TileEntityDispenser)1 ActionResult (net.minecraft.util.ActionResult)1 EnumActionResult (net.minecraft.util.EnumActionResult)1 EnumFacing (net.minecraft.util.EnumFacing)1 BlockPos (net.minecraft.util.math.BlockPos)1