Search in sources :

Example 1 with CentrifugeRecipe

use of com.teamresourceful.resourcefulbees.recipe.CentrifugeRecipe in project ResourcefulBees by Resourceful-Bees.

the class CentrifugeTileEntity method getRecipe.

public CentrifugeRecipe getRecipe(int i) {
    ItemStack input = itemStackHandler.getStackInSlot(honeycombSlots[i]);
    SimpleContainer recipeInv = new SimpleContainer(input, itemStackHandler.getStackInSlot(BOTTLE_SLOT));
    if (input.isEmpty() || input == failedMatch)
        return null;
    if (level != null) {
        boolean matches = this.recipes.get(i) == null;
        if (!matches)
            matches = !this.recipes.get(i).matches(recipeInv, level);
        if (matches) {
            CentrifugeRecipe rec = level.getRecipeManager().getRecipeFor(CentrifugeRecipe.CENTRIFUGE_RECIPE_TYPE, recipeInv, this.level).orElse(null);
            if (rec == null)
                failedMatch = input;
            else
                failedMatch = ItemStack.EMPTY;
            this.recipes.set(i, rec);
        }
        return this.recipes.get(i);
    }
    return null;
}
Also used : SimpleContainer(net.minecraft.world.SimpleContainer) ItemStack(net.minecraft.world.item.ItemStack) CentrifugeRecipe(com.teamresourceful.resourcefulbees.recipe.CentrifugeRecipe)

Example 2 with CentrifugeRecipe

use of com.teamresourceful.resourcefulbees.recipe.CentrifugeRecipe in project ResourcefulBees by Resourceful-Bees.

the class MechanicalCentrifugeTileEntity method getRecipe.

public CentrifugeRecipe getRecipe() {
    ItemStack input = getItemStackHandler().getStackInSlot(HONEYCOMB_SLOT);
    if (input.isEmpty() || input == getFailedMatch() || level == null) {
        return null;
    }
    if (recipe == null || !recipe.matches(new RecipeWrapper(getItemStackHandler()), level)) {
        CentrifugeRecipe rec = level.getRecipeManager().getRecipeFor(CentrifugeRecipe.CENTRIFUGE_RECIPE_TYPE, new RecipeWrapper(getItemStackHandler()), this.level).orElse(null);
        setFailedMatch(rec == null ? input : ItemStack.EMPTY);
        recipe = rec;
    }
    return recipe;
}
Also used : ItemStack(net.minecraft.world.item.ItemStack) CentrifugeRecipe(com.teamresourceful.resourcefulbees.recipe.CentrifugeRecipe) RecipeWrapper(net.minecraftforge.items.wrapper.RecipeWrapper)

Example 3 with CentrifugeRecipe

use of com.teamresourceful.resourcefulbees.recipe.CentrifugeRecipe in project ResourcefulBees by Resourceful-Bees.

the class CentrifugeTileEntity method completeProcess.

protected void completeProcess(int i) {
    if (recipes.get(i) == null) {
        resetProcess(i);
        return;
    }
    if (!inventoryHasSpace(recipes.get(i))) {
        return;
    }
    if (!tanksHasSpace(recipes.get(i))) {
        return;
    }
    consumeInput(i);
    List<ItemStack> depositStacks = new ArrayList<>();
    if (level == null) {
        resetProcess(i);
        return;
    }
    CentrifugeRecipe recipe = recipes.get(i);
    recipe.getItemOutputs().stream().limit(3).forEach(centrifugeItemOutput -> {
        double chance = centrifugeItemOutput.getChance();
        if (chance >= level.random.nextFloat()) {
            depositStacks.add(centrifugeItemOutput.getPool().next().getItemStack());
        }
    });
    recipe.getFluidOutputs().stream().limit(3).forEach(centrifugeFluidOutput -> {
        double chance = centrifugeFluidOutput.getChance();
        if (chance >= level.random.nextFloat()) {
            FluidStack fluid = centrifugeFluidOutput.getPool().next().getFluidStack();
            int tank = getValidTank(fluid);
            if (tank != -1)
                fluidTanks.fill(tank, fluid, IFluidHandler.FluidAction.EXECUTE);
        }
    });
    if (!depositStacks.isEmpty()) {
        depositItemStacks(depositStacks);
    }
    resetProcess(i);
}
Also used : FluidStack(net.minecraftforge.fluids.FluidStack) ArrayList(java.util.ArrayList) ItemStack(net.minecraft.world.item.ItemStack) CentrifugeRecipe(com.teamresourceful.resourcefulbees.recipe.CentrifugeRecipe)

Example 4 with CentrifugeRecipe

use of com.teamresourceful.resourcefulbees.recipe.CentrifugeRecipe in project ResourcefulBees by Resourceful-Bees.

the class RecipeBuilder method centrifugeRecipe.

private Recipe<?> centrifugeRecipe(String beeType, CentrifugeData centrifugeData, HoneycombData honeycombData, int multiplier) {
    boolean isBlockRecipe = multiplier != 1;
    ResourceLocation recipeLoc = new ResourceLocation(ResourcefulBees.MOD_ID, beeType + (isBlockRecipe ? "_honeycomb_block" : "_honeycomb") + "_centrifuge");
    Ingredient ingredient = Ingredient.of(new ItemStack(isBlockRecipe ? honeycombData.getHoneycombBlock() : honeycombData.getHoneycomb(), centrifugeData.getInputCount()));
    return new CentrifugeRecipe(recipeLoc, ingredient, centrifugeData.getItemOutputs(), centrifugeData.getFluidOutputs(), centrifugeData.getRecipeTime(), (centrifugeData.getRecipeTime() - Config.MULTIBLOCK_RECIPE_TIME_REDUCTION.get()) * (isBlockRecipe ? 3 : 1), isBlockRecipe);
}
Also used : ResourceLocation(net.minecraft.resources.ResourceLocation) ItemStack(net.minecraft.world.item.ItemStack) CentrifugeRecipe(com.teamresourceful.resourcefulbees.recipe.CentrifugeRecipe)

Example 5 with CentrifugeRecipe

use of com.teamresourceful.resourcefulbees.recipe.CentrifugeRecipe in project ResourcefulBees by Resourceful-Bees.

the class MechanicalCentrifugeTileEntity method tick.

@Override
public void tick() {
    if (level != null && !level.isClientSide) {
        boolean dirty = false;
        CentrifugeRecipe irecipe = getRecipe();
        if (!getItemStackHandler().getStackInSlot(HONEYCOMB_SLOT).isEmpty()) {
            if (this.canProcess(irecipe)) {
                if (this.getClicks() > 0)
                    level.setBlockAndUpdate(worldPosition, getBlockState().setValue(MechanicalCentrifugeBlock.PROPERTY_ON, true));
                if (this.getClicks() >= 8) {
                    this.setClicks(0);
                    this.processItem(irecipe);
                    dirty = true;
                    level.setBlockAndUpdate(worldPosition, getBlockState().setValue(MechanicalCentrifugeBlock.PROPERTY_ON, false));
                }
            }
        } else {
            setClicks(0);
            level.setBlockAndUpdate(worldPosition, getBlockState().setValue(MechanicalCentrifugeBlock.PROPERTY_ON, false));
        }
        if (dirty) {
            this.setChanged();
        }
    }
}
Also used : CentrifugeRecipe(com.teamresourceful.resourcefulbees.recipe.CentrifugeRecipe)

Aggregations

CentrifugeRecipe (com.teamresourceful.resourcefulbees.recipe.CentrifugeRecipe)5 ItemStack (net.minecraft.world.item.ItemStack)4 ArrayList (java.util.ArrayList)1 ResourceLocation (net.minecraft.resources.ResourceLocation)1 SimpleContainer (net.minecraft.world.SimpleContainer)1 FluidStack (net.minecraftforge.fluids.FluidStack)1 RecipeWrapper (net.minecraftforge.items.wrapper.RecipeWrapper)1