1 furnace.Inventory = class extends dragonblocks.InventoryContainer
6 inventory: new dragonblocks.Inventory(4, 2),
15 this.input = new dragonblocks.ItemStack();
16 this.input.addEventListener("update", _ => {
20 this.fuel = new dragonblocks.ItemStack();
21 this.fuel.addEventListener("update", _ => {
25 this.burnProgressStack = new dragonblocks.ItemStack();
26 this.burnProgressStack.deserialize("furnace:burn_progress_0");
27 this.burnProgressStack.action = _ => {};
28 this.burnProgressStack.addEventListener("redraw", event => {
29 event.stack.display.style.backgroundColor = "";
30 event.stack.display.style.border = "none";
33 this.fuelProgressStack = new dragonblocks.ItemStack();
34 this.fuelProgressStack.deserialize("furnace:fuel_progress_0");
35 this.fuelProgressStack.action = _ => {};
36 this.fuelProgressStack.addEventListener("redraw", event => {
37 event.stack.display.style.backgroundColor = "";
38 event.stack.display.style.border = "none";
51 this.input.draw(this.display, 2 * dragonblocks.settings.inventory.scale * 1.1, 0.5 * dragonblocks.settings.inventory.scale * 1.1);
52 this.fuel.draw(this.display, 2 * dragonblocks.settings.inventory.scale * 1.1, 2.5 * dragonblocks.settings.inventory.scale * 1.1);
53 this.burnProgressStack.draw(this.display, 3 * dragonblocks.settings.inventory.scale * 1.1, 1.5 * dragonblocks.settings.inventory.scale * 1.1);
54 this.fuelProgressStack.draw(this.display, 2 * dragonblocks.settings.inventory.scale * 1.1, 1.5 * dragonblocks.settings.inventory.scale * 1.1);
59 return this.inventory.isEmpty() && ! this.fuel.item && ! this.input.item;
64 let data = JSON.parse(str);
66 this.inventory.deserialize(data.inventory);
67 this.input.deserialize(data.input);
68 this.fuel.deserialize(data.fuel);
73 return JSON.stringify({
74 inventory: this.inventory.serialize(),
75 input: this.input.serialize(),
76 fuel: this.fuel.serialize()
82 for (let recipe of furnace.recipes)
83 if (dragonblocks.itemMatch(recipe.input, this.input.item))
89 return this.getRecipe() && this.getRecipe().output;
94 return this.getRecipe() && this.getRecipe().time || 1;
99 this.burnProgress = 0;
100 clearInterval(this.burnInterval);
101 this.burning = false;
106 this.fuelPower = this.fullFuelPower = 0;
107 clearInterval(this.fuelInterval);
108 this.fuelBurning = false;
115 if (! this.getRecipeOutput()) {
117 } else if (this.burnProgress > this.getRecipeTime()) {
118 this.inventory.add(this.getRecipeOutput());
123 } else if (! this.burning) {
124 this.burnInterval = setInterval(_ => {
132 if (this.fuelBurning && this.fuelPower <= 0)
135 if (! this.fuelBurning && this.burning) {
136 if (this.fuel.toItem() && this.fuel.toItem().flammable) {
137 this.fuelBurning = true;
138 this.fullFuelPower = this.fuelPower = this.fuel.toItem().hardness;
140 this.fuelInterval = setInterval(_ => {
152 this.burnProgressStack.deserialize("furnace:burn_progress_" + parseInt(this.burnProgress / this.getRecipeTime() * 5));
153 this.fuelProgressStack.deserialize("furnace:fuel_progress_" + (parseInt(this.fuelPower / this.fullFuelPower * 5) || 0));