Theme

alex/beta-minecraft-rust

Minecraft Beta 1.7.3 Rewrite

BRANCH main
main
SNAPSHOT Draw terrain GPU-driven from packed per-section buffers with GPU occlusion culling, add a render distance slider (2-128) with a quad/disk shape, cut chunk bookkeeping at high render distances, and fix a light underflow at y=0
DOWNLOAD
Download file

root / crates / common / src / inventory / furnace.rs

use super::take;
use crate::item::{Item, ItemStack, burn_time};
use crate::world::{Block, TileEntity};

pub fn smelting_result(item: Item) -> Option<ItemStack> {
    let (item, damage) = match item {
        Item::RAW_PORKCHOP => (Item::COOKED_PORKCHOP, 0),
        Item::RAW_FISH => (Item::COOKED_FISH, 0),
        Item::CLAY_BALL => (Item::BRICK, 0),
        item => match item.block()? {
            Block::IRON_ORE => (Item::IRON_INGOT, 0),
            Block::GOLD_ORE => (Item::GOLD_INGOT, 0),
            Block::DIAMOND_ORE => (Item::DIAMOND, 0),
            Block::SAND => (Item::from_block(Block::GLASS), 0),
            Block::COBBLESTONE => (Item::from_block(Block::STONE), 0),
            Block::CACTUS => (Item::DYE, 2),
            Block::LOG => (Item::COAL, 1),
            _ => return None,
        },
    };
    Some(ItemStack::new(item, 1, damage))
}

pub fn tick_furnace(tile: &mut TileEntity) -> bool {
    let TileEntity::Furnace {
        items,
        burn_time: burning,
        cook_time,
        item_burn_time,
    } = tile
    else {
        return false;
    };
    let before = (*items, *burning, *cook_time, *item_burn_time);
    if *burning > 0 {
        *burning -= 1;
    }
    let output = items[0].and_then(|input| smelting_result(input.item));
    let can_smelt = output.is_some_and(|result| {
        items[2].is_none_or(|existing| {
            existing.same_item(&result)
                && existing.count + result.count <= existing.max_stack().min(64)
        })
    });
    if *burning == 0 && can_smelt {
        *item_burn_time = items[1].map_or(0, |fuel| burn_time(fuel.item));
        *burning = *item_burn_time;
        if *burning > 0 {
            take(&mut items[1], 1);
        }
    }
    if *burning > 0 && can_smelt {
        *cook_time += 1;
        if *cook_time >= 200 {
            *cook_time = 0;
            take(&mut items[0], 1);
            match &mut items[2] {
                Some(stack) => stack.count += output.expect("smeltable input").count,
                slot => *slot = output,
            }
        }
    } else {
        *cook_time = 0;
    }
    before != (*items, *burning, *cook_time, *item_burn_time)
}