1 furnace.Inventory = class extends dragonblocks.InventoryContainer{
4 inventory: new dragonblocks.Inventory(4, 2),
11 this.input = new dragonblocks.Itemstack();
12 this.input.addUpdateListener(_ => {
15 this.fuel = new dragonblocks.Itemstack();
16 this.fuel.addUpdateListener(_ => {
19 this.burnProgressDisplay = new dragonblocks.Itemstack();
20 this.burnProgressDisplay.parse("furnace:burn_progress_0");
21 this.burnProgressDisplay.action = _ => {};
22 this.burnProgressDisplay.onredraw = _ => {
23 dragonblocks.Inventory.getStackDisplay(self.burnProgressDisplay.id).style.backgroundColor = "";
24 dragonblocks.Inventory.getStackDisplay(self.burnProgressDisplay.id).style.border = "none";
26 this.fuelProgressDisplay = new dragonblocks.Itemstack();
27 this.fuelProgressDisplay.parse("furnace:fuel_progress_0");
28 this.fuelProgressDisplay.action = _ => {};
29 this.fuelProgressDisplay.onredraw = _ => {
30 dragonblocks.Inventory.getStackDisplay(self.fuelProgressDisplay.id).style.backgroundColor = "";
31 dragonblocks.Inventory.getStackDisplay(self.fuelProgressDisplay.id).style.border = "none";
38 if(! super.draw(parent, x, y))
40 dragonblocks.Inventory.drawStack(this.getDisplay(), 2 * dragonblocks.settings.inventory.scale * 1.1, 0.5 * dragonblocks.settings.inventory.scale * 1.1, this.input);
41 dragonblocks.Inventory.drawStack(this.getDisplay(), 3 * dragonblocks.settings.inventory.scale * 1.1, 1.5 * dragonblocks.settings.inventory.scale * 1.1, this.burnProgressDisplay);
42 dragonblocks.Inventory.drawStack(this.getDisplay(), 2 * dragonblocks.settings.inventory.scale * 1.1, 1.5 * dragonblocks.settings.inventory.scale * 1.1, this.fuelProgressDisplay);
43 dragonblocks.Inventory.drawStack(this.getDisplay(), 2 * dragonblocks.settings.inventory.scale * 1.1, 2.5 * dragonblocks.settings.inventory.scale * 1.1, this.fuel);
47 return this.inventory.isEmpty() && ! this.fuel.item && ! this.input.item;
50 let obj = JSON.parse(str);
51 this.inventory.parse(obj.inventory);
52 this.input.parse(obj.input);
53 this.fuel.parse(obj.fuel);
56 return JSON.stringify({
57 inventory: this.inventory.stringify(),
58 input: this.input.stringify(),
59 fuel: this.fuel.stringify()
63 for(let recipe of furnace.recipes)
64 if(dragonblocks.itemMatch(recipe.input, this.input.item))
68 return this.getRecipe() && this.getRecipe().output;
71 return this.getRecipe() && this.getRecipe().time || 1;
74 this.burnProgress = 0;
75 clearInterval(this.burnInterval);
79 this.fuelPower = this.fullFuelPower = 0;
80 clearInterval(this.fuelInterval);
81 this.fuelBurning = false;
86 if(! this.getRecipeOutput())
88 else if(this.burnProgress > this.getRecipeTime()){
89 this.inventory.add(this.getRecipeOutput())
94 else if(! this.burning){
95 this.burnInterval = setInterval(_ => {
101 if(this.fuelBurning && this.fuelPower <= 0)
103 if(! this.fuelBurning && this.burning){
104 if(this.fuel.toItem() && this.fuel.toItem().flammable){
105 this.fuelBurning = true;
106 this.fullFuelPower = this.fuelPower = this.fuel.toItem().hardness;
107 this.fuelInterval = setInterval(_ => {
117 this.burnProgressDisplay.parse("furnace:burn_progress_" + parseInt(this.burnProgress / this.getRecipeTime() * 5));
118 this.fuelProgressDisplay.parse("furnace:fuel_progress_" + (parseInt(this.fuelPower / this.fullFuelPower * 5) || 0));