Search in sources :

Example 1 with AbstractFurnaceAccessor

use of net.sistr.littlemaidrebirth.util.AbstractFurnaceAccessor in project LittleMaidReBirth-Fabric by SistrScarlet.

the class CookingMode method tick.

@Override
public void tick() {
    AbstractFurnaceBlockEntity furnace = getFurnace(furnacePos).orElse(getFurnace(findFurnacePos().orElse(null)).orElse(null));
    if (furnace == null) {
        furnacePos = null;
        return;
    }
    this.mob.getLookControl().lookAt(furnacePos.getX() + 0.5, furnacePos.getY() + 0.5, furnacePos.getZ() + 0.5);
    if (!this.mob.getBlockPos().isWithinDistance(furnacePos, 2)) {
        if (this.mob.isSneaking()) {
            this.mob.setSneaking(false);
        }
        if (--this.timeToRecalcPath <= 0) {
            this.timeToRecalcPath = 10;
            this.mob.getNavigation().startMovingTo(furnacePos.getX() + 0.5D, furnacePos.getY() + 0.5D, furnacePos.getZ() + 0.5D, 1);
        }
        return;
    }
    this.mob.getNavigation().stop();
    if (!this.mob.isSneaking()) {
        this.mob.setSneaking(true);
    }
    Inventory inventory = this.mob.getInventory();
    RecipeType<? extends AbstractCookingRecipe> recipeType = ((AbstractFurnaceAccessor) furnace).getRecipeType_LM();
    getCookable(recipeType).ifPresent(cookableIndex -> tryInsertCookable(furnace, inventory, cookableIndex));
    getFuel().ifPresent(fuelIndex -> tryInsertFuel(furnace, inventory, fuelIndex));
    tryExtractItem(furnace, inventory);
}
Also used : AbstractFurnaceBlockEntity(net.minecraft.block.entity.AbstractFurnaceBlockEntity) AbstractFurnaceAccessor(net.sistr.littlemaidrebirth.util.AbstractFurnaceAccessor) Inventory(net.minecraft.inventory.Inventory) SimpleInventory(net.minecraft.inventory.SimpleInventory)

Example 2 with AbstractFurnaceAccessor

use of net.sistr.littlemaidrebirth.util.AbstractFurnaceAccessor in project LittleMaidReBirth-Fabric by SistrScarlet.

the class CookingMode method canUseFurnace.

public boolean canUseFurnace(AbstractFurnaceBlockEntity tile) {
    if (tile == null) {
        return false;
    }
    for (int slot : tile.getAvailableSlots(Direction.UP)) {
        ItemStack stack = tile.getStack(slot);
        if (!stack.isEmpty())
            continue;
        RecipeType<? extends AbstractCookingRecipe> recipeType = ((AbstractFurnaceAccessor) tile).getRecipeType_LM();
        if (getAllCoockable(recipeType).anyMatch(cookable -> tile.canInsert(slot, cookable, Direction.UP))) {
            return true;
        }
    }
    return false;
}
Also used : AbstractFurnaceAccessor(net.sistr.littlemaidrebirth.util.AbstractFurnaceAccessor) ItemStack(net.minecraft.item.ItemStack)

Aggregations

AbstractFurnaceAccessor (net.sistr.littlemaidrebirth.util.AbstractFurnaceAccessor)2 AbstractFurnaceBlockEntity (net.minecraft.block.entity.AbstractFurnaceBlockEntity)1 Inventory (net.minecraft.inventory.Inventory)1 SimpleInventory (net.minecraft.inventory.SimpleInventory)1 ItemStack (net.minecraft.item.ItemStack)1