Search in sources :

Example 1 with HeatLevel

use of com.simibubi.create.content.contraptions.processing.burner.BlazeBurnerBlock.HeatLevel in project Create by Creators-of-Create.

the class BasinRecipe method apply.

private static boolean apply(BasinTileEntity basin, Recipe<?> recipe, boolean test) {
    boolean isBasinRecipe = recipe instanceof BasinRecipe;
    IItemHandler availableItems = basin.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY).orElse(null);
    IFluidHandler availableFluids = basin.getCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY).orElse(null);
    if (availableItems == null || availableFluids == null)
        return false;
    HeatLevel heat = BasinTileEntity.getHeatLevelOf(basin.getLevel().getBlockState(basin.getBlockPos().below(1)));
    if (isBasinRecipe && !((BasinRecipe) recipe).getRequiredHeat().testBlazeBurner(heat))
        return false;
    List<ItemStack> recipeOutputItems = new ArrayList<>();
    List<FluidStack> recipeOutputFluids = new ArrayList<>();
    List<Ingredient> ingredients = new LinkedList<>(recipe.getIngredients());
    ingredients.sort(Comparator.comparingInt(i -> i.getItems().length));
    List<FluidIngredient> fluidIngredients = isBasinRecipe ? ((BasinRecipe) recipe).getFluidIngredients() : Collections.emptyList();
    for (boolean simulate : Iterate.trueAndFalse) {
        if (!simulate && test)
            return true;
        int[] extractedItemsFromSlot = new int[availableItems.getSlots()];
        int[] extractedFluidsFromTank = new int[availableFluids.getTanks()];
        Ingredients: for (int i = 0; i < ingredients.size(); i++) {
            Ingredient ingredient = ingredients.get(i);
            for (int slot = 0; slot < availableItems.getSlots(); slot++) {
                if (simulate && availableItems.getStackInSlot(slot).getCount() <= extractedItemsFromSlot[slot])
                    continue;
                ItemStack extracted = availableItems.extractItem(slot, 1, true);
                if (!ingredient.test(extracted))
                    continue;
                // Catalyst items are never consumed
                if (extracted.hasContainerItem() && extracted.getContainerItem().sameItem(extracted))
                    continue Ingredients;
                if (!simulate)
                    availableItems.extractItem(slot, 1, false);
                else if (extracted.hasContainerItem())
                    recipeOutputItems.add(extracted.getContainerItem().copy());
                extractedItemsFromSlot[slot]++;
                continue Ingredients;
            }
            // something wasn't found
            return false;
        }
        boolean fluidsAffected = false;
        FluidIngredients: for (int i = 0; i < fluidIngredients.size(); i++) {
            FluidIngredient fluidIngredient = fluidIngredients.get(i);
            int amountRequired = fluidIngredient.getRequiredAmount();
            for (int tank = 0; tank < availableFluids.getTanks(); tank++) {
                FluidStack fluidStack = availableFluids.getFluidInTank(tank);
                if (simulate && fluidStack.getAmount() <= extractedFluidsFromTank[tank])
                    continue;
                if (!fluidIngredient.test(fluidStack))
                    continue;
                int drainedAmount = Math.min(amountRequired, fluidStack.getAmount());
                if (!simulate) {
                    fluidStack.shrink(drainedAmount);
                    fluidsAffected = true;
                }
                amountRequired -= drainedAmount;
                if (amountRequired != 0)
                    continue;
                extractedFluidsFromTank[tank] += drainedAmount;
                continue FluidIngredients;
            }
            // something wasn't found
            return false;
        }
        if (fluidsAffected) {
            basin.getBehaviour(SmartFluidTankBehaviour.INPUT).forEach(TankSegment::onFluidStackChanged);
            basin.getBehaviour(SmartFluidTankBehaviour.OUTPUT).forEach(TankSegment::onFluidStackChanged);
        }
        if (simulate) {
            if (recipe instanceof BasinRecipe) {
                recipeOutputItems.addAll(((BasinRecipe) recipe).rollResults());
                recipeOutputFluids.addAll(((BasinRecipe) recipe).getFluidResults());
            } else
                recipeOutputItems.add(recipe.getResultItem());
        }
        if (!basin.acceptOutputs(recipeOutputItems, recipeOutputFluids, simulate))
            return false;
    }
    return true;
}
Also used : SmartFluidTankBehaviour(com.simibubi.create.foundation.tileEntity.behaviour.fluid.SmartFluidTankBehaviour) IItemHandler(net.minecraftforge.items.IItemHandler) IFluidHandler(net.minecraftforge.fluids.capability.IFluidHandler) Iterate(com.simibubi.create.foundation.utility.Iterate) CapabilityFluidHandler(net.minecraftforge.fluids.capability.CapabilityFluidHandler) FilteringBehaviour(com.simibubi.create.foundation.tileEntity.behaviour.filtering.FilteringBehaviour) HeatLevel(com.simibubi.create.content.contraptions.processing.burner.BlazeBurnerBlock.HeatLevel) ArrayList(java.util.ArrayList) Ingredient(net.minecraft.world.item.crafting.Ingredient) List(java.util.List) FluidIngredient(com.simibubi.create.foundation.fluid.FluidIngredient) SmartInventory(com.simibubi.create.foundation.item.SmartInventory) Recipe(net.minecraft.world.item.crafting.Recipe) AllRecipeTypes(com.simibubi.create.AllRecipeTypes) CapabilityItemHandler(net.minecraftforge.items.CapabilityItemHandler) ProcessingRecipeParams(com.simibubi.create.content.contraptions.processing.ProcessingRecipeBuilder.ProcessingRecipeParams) TankSegment(com.simibubi.create.foundation.tileEntity.behaviour.fluid.SmartFluidTankBehaviour.TankSegment) FluidStack(net.minecraftforge.fluids.FluidStack) ItemStack(net.minecraft.world.item.ItemStack) Comparator(java.util.Comparator) LinkedList(java.util.LinkedList) Level(net.minecraft.world.level.Level) Collections(java.util.Collections) Nonnull(javax.annotation.Nonnull) IItemHandler(net.minecraftforge.items.IItemHandler) FluidStack(net.minecraftforge.fluids.FluidStack) ArrayList(java.util.ArrayList) TankSegment(com.simibubi.create.foundation.tileEntity.behaviour.fluid.SmartFluidTankBehaviour.TankSegment) IFluidHandler(net.minecraftforge.fluids.capability.IFluidHandler) LinkedList(java.util.LinkedList) FluidIngredient(com.simibubi.create.foundation.fluid.FluidIngredient) Ingredient(net.minecraft.world.item.crafting.Ingredient) FluidIngredient(com.simibubi.create.foundation.fluid.FluidIngredient) HeatLevel(com.simibubi.create.content.contraptions.processing.burner.BlazeBurnerBlock.HeatLevel) ItemStack(net.minecraft.world.item.ItemStack)

Example 2 with HeatLevel

use of com.simibubi.create.content.contraptions.processing.burner.BlazeBurnerBlock.HeatLevel in project Create by Creators-of-Create.

the class BlazeBurnerTileEntity method getHeatLevelFromFuelType.

protected HeatLevel getHeatLevelFromFuelType(FuelType fuel) {
    HeatLevel level = HeatLevel.SMOULDERING;
    switch(activeFuel) {
        case SPECIAL:
            level = HeatLevel.SEETHING;
            break;
        case NORMAL:
            boolean lowPercent = (double) remainingBurnTime / MAX_HEAT_CAPACITY < 0.1;
            level = lowPercent ? HeatLevel.FADING : HeatLevel.KINDLED;
            break;
        default:
        case NONE:
            break;
    }
    return level;
}
Also used : HeatLevel(com.simibubi.create.content.contraptions.processing.burner.BlazeBurnerBlock.HeatLevel)

Example 3 with HeatLevel

use of com.simibubi.create.content.contraptions.processing.burner.BlazeBurnerBlock.HeatLevel in project Create by Creators-of-Create.

the class BlazeBurnerRenderer method renderSafe.

@Override
protected void renderSafe(BlazeBurnerTileEntity te, float partialTicks, PoseStack ms, MultiBufferSource buffer, int light, int overlay) {
    HeatLevel heatLevel = te.getHeatLevelFromBlock();
    if (heatLevel == HeatLevel.NONE)
        return;
    float renderTick = AnimationTickHolder.getRenderTime(te.getLevel()) + (te.hashCode() % 13) * 16f;
    float offset = (Mth.sin((float) ((renderTick / 16f) % (2 * Math.PI))) + .5f) / 16f;
    PartialModel blazeModel = AllBlockPartials.BLAZES.get(heatLevel);
    SuperByteBuffer blazeBuffer = CachedBufferer.partial(blazeModel, te.getBlockState());
    blazeBuffer.rotateCentered(Direction.UP, AngleHelper.rad(te.headAngle.getValue(partialTicks)));
    blazeBuffer.translate(0, offset, 0);
    blazeBuffer.light(LightTexture.FULL_BRIGHT).renderInto(ms, buffer.getBuffer(RenderType.solid()));
}
Also used : SuperByteBuffer(com.simibubi.create.foundation.render.SuperByteBuffer) HeatLevel(com.simibubi.create.content.contraptions.processing.burner.BlazeBurnerBlock.HeatLevel) PartialModel(com.jozufozu.flywheel.core.PartialModel)

Example 4 with HeatLevel

use of com.simibubi.create.content.contraptions.processing.burner.BlazeBurnerBlock.HeatLevel in project Create by Creators-of-Create.

the class BlazeBurnerTileEntity method setBlockHeat.

protected void setBlockHeat(HeatLevel heat) {
    HeatLevel inBlockState = getHeatLevelFromBlock();
    if (inBlockState == heat)
        return;
    level.setBlockAndUpdate(worldPosition, getBlockState().setValue(BlazeBurnerBlock.HEAT_LEVEL, heat));
    notifyUpdate();
}
Also used : HeatLevel(com.simibubi.create.content.contraptions.processing.burner.BlazeBurnerBlock.HeatLevel)

Example 5 with HeatLevel

use of com.simibubi.create.content.contraptions.processing.burner.BlazeBurnerBlock.HeatLevel in project Create by Creators-of-Create.

the class BlazeBurnerTileEntity method tryUpdateFuel.

/**
 * @return true if the heater updated its burn time and an item should be
 *         consumed
 */
protected boolean tryUpdateFuel(ItemStack itemStack, boolean forceOverflow, boolean simulate) {
    if (isCreative)
        return false;
    FuelType newFuel = FuelType.NONE;
    int newBurnTime;
    if (AllItemTags.BLAZE_BURNER_FUEL_SPECIAL.matches(itemStack)) {
        newBurnTime = 1000;
        newFuel = FuelType.SPECIAL;
    } else {
        newBurnTime = ForgeHooks.getBurnTime(itemStack, null);
        if (newBurnTime > 0)
            newFuel = FuelType.NORMAL;
        else if (AllItemTags.BLAZE_BURNER_FUEL_REGULAR.matches(itemStack)) {
            // Same as coal
            newBurnTime = 1600;
            newFuel = FuelType.NORMAL;
        }
    }
    if (newFuel == FuelType.NONE)
        return false;
    if (newFuel.ordinal() < activeFuel.ordinal())
        return false;
    if (activeFuel == FuelType.SPECIAL && remainingBurnTime > 20)
        return false;
    if (newFuel == activeFuel) {
        if (remainingBurnTime + newBurnTime > MAX_HEAT_CAPACITY && !forceOverflow)
            return false;
        newBurnTime = Mth.clamp(remainingBurnTime + newBurnTime, 0, MAX_HEAT_CAPACITY);
    }
    if (simulate)
        return true;
    activeFuel = newFuel;
    remainingBurnTime = newBurnTime;
    if (level.isClientSide) {
        HeatLevel level = getHeatLevelFromFuelType(activeFuel);
        for (int i = 0; i < 20; i++) spawnParticles(level, 1 + (.25 * (i / 4)));
    } else {
        playSound();
        updateBlockState();
    }
    return true;
}
Also used : HeatLevel(com.simibubi.create.content.contraptions.processing.burner.BlazeBurnerBlock.HeatLevel)

Aggregations

HeatLevel (com.simibubi.create.content.contraptions.processing.burner.BlazeBurnerBlock.HeatLevel)5 PartialModel (com.jozufozu.flywheel.core.PartialModel)1 AllRecipeTypes (com.simibubi.create.AllRecipeTypes)1 ProcessingRecipeParams (com.simibubi.create.content.contraptions.processing.ProcessingRecipeBuilder.ProcessingRecipeParams)1 FluidIngredient (com.simibubi.create.foundation.fluid.FluidIngredient)1 SmartInventory (com.simibubi.create.foundation.item.SmartInventory)1 SuperByteBuffer (com.simibubi.create.foundation.render.SuperByteBuffer)1 FilteringBehaviour (com.simibubi.create.foundation.tileEntity.behaviour.filtering.FilteringBehaviour)1 SmartFluidTankBehaviour (com.simibubi.create.foundation.tileEntity.behaviour.fluid.SmartFluidTankBehaviour)1 TankSegment (com.simibubi.create.foundation.tileEntity.behaviour.fluid.SmartFluidTankBehaviour.TankSegment)1 Iterate (com.simibubi.create.foundation.utility.Iterate)1 ArrayList (java.util.ArrayList)1 Collections (java.util.Collections)1 Comparator (java.util.Comparator)1 LinkedList (java.util.LinkedList)1 List (java.util.List)1 Nonnull (javax.annotation.Nonnull)1 ItemStack (net.minecraft.world.item.ItemStack)1 Ingredient (net.minecraft.world.item.crafting.Ingredient)1 Recipe (net.minecraft.world.item.crafting.Recipe)1