From 37ffe3459556d2b73dce77a5d4d8ea210bb8e806 Mon Sep 17 00:00:00 2001 From: younggam Date: Sat, 5 Sep 2020 00:19:36 +0900 Subject: [PATCH] stat info cleanup --- bundles/bundle.properties | 2 + bundles/bundle_ko.properties | 2 + mod.json | 2 +- scripts/blocks/production/advanced-furnace.js | 430 ++++++++-------- scripts/blocks/production/blast-furnace.js | 458 +++++++++--------- scripts/blocks/production/metal-smelter.js | 386 ++++++++------- 6 files changed, 616 insertions(+), 664 deletions(-) diff --git a/bundles/bundle.properties b/bundles/bundle.properties index 750e783..d773c55 100644 --- a/bundles/bundle.properties +++ b/bundles/bundle.properties @@ -1,5 +1,7 @@ steam-power-heat-per-sec={0}heat/sec steam-power-heat-cond=above {0} heat +steam-power-heatUse=Heat Use +steam-power-heatRange=Heat Range steam-power-matter-disintegrator-dialog-0=Current State steam-power-matter-disintegrator-dialog-1=Values steam-power-matter-disintegrator-title-0=Container Requirement diff --git a/bundles/bundle_ko.properties b/bundles/bundle_ko.properties index c1a3607..f464d1a 100644 --- a/bundles/bundle_ko.properties +++ b/bundles/bundle_ko.properties @@ -1,5 +1,7 @@ steam-power-heat-per-sec={0}열/초 steam-power-heat-cond={0}열 이상 +steam-power-heatUse=열 사용 +steam-power-heatRange=열 범위 steam-power-matter-disintegrator-dialog-0=현황 steam-power-matter-disintegrator-dialog-1=값들 steam-power-matter-disintegrator-title-0=용기 요구량 diff --git a/mod.json b/mod.json index bd56fa2..23ffb75 100644 --- a/mod.json +++ b/mod.json @@ -2,6 +2,6 @@ name:steam-power displayName:Steam Power description:"[orange]Realistic power generation. \n\n[cyan]Developer : [green]younggam\n[yellow]Thanks to : sirius, 우파루파, Lily, sk7725\n\n[red]Need younggam/multi-lib2" author: younggam -version: 2.0.0 +version: 2.0.1 minGameVersion: 104 dependencies:["multi-lib2"] diff --git a/scripts/blocks/production/advanced-furnace.js b/scripts/blocks/production/advanced-furnace.js index 28d3420..1852b6f 100644 --- a/scripts/blocks/production/advanced-furnace.js +++ b/scripts/blocks/production/advanced-furnace.js @@ -1,228 +1,204 @@ -const multiLib=require("multi-lib2/wrapper"); -const furnaces=this.global.furnaces; -const advancedFurnace=multiLib.extend(GenericCrafter,"advanced-furnace", -[ - { - input:{ - items:["steam-power-copper-ore/1"], - power:0.6 - }, - output:{ - items:["copper/1"], - liquids:["slag/1"] - }, - craftTime:50 - }, - { - input:{ - items:["steam-power-lead-ore/1"], - power:0.6 - }, - output:{ - items:["lead/1"], - liquids:["slag/1"] - }, - craftTime:50 - }, - { - input:{ - items:["steam-power-iron-ore/1"], - }, - output:{ - items:["steam-power-iron/1"], - liquids:["slag/1"] - }, - craftTime:100 - }, - { - input:{ - items:["steam-power-titanium-ore/1"], - power:0.6 - }, - output:{ - items:["titanium/1"], - liquids:["slag/1"] - }, - craftTime:50 - }, - { - input:{ - items:["sand/1"], - power:0.6 - }, - output:{ - items:["steam-power-glass/1"], - liquids:[] - }, - craftTime:50 - }, - { - input:{ - items:["scrap/1"], - power:0.6 - }, - output:{ - liquids:["slag/2"] - }, - craftTime:25 - }, -], -{ - setBars(){ - this.super$setBars(); - //initialize - this.bars.remove("liquid"); - this.bars.remove("items"); - //display every Liquids that can contain - var i=0; - if(!this.liquidSet.isEmpty()){ - this.liquidSet.each(cons(k=>{ - this.bars.add("liquid"+i,func(entity=> - new Bar(prov(()=>k.localizedName),prov(()=>k.barColor()),floatp(()=>entity.liquids.get(k)/this.liquidCapacity)) - )); - i++; - })); - } - this.bars.add("multiplier",func(entity=> - new Bar(prov(()=>Core.bundle.formatFloat("bar.efficiency",entity.warmup*100*(entity.items.get(Items.coal)>0?2.5:1),1)),prov(()=>Pal.ammo),floatp(()=>entity.warmup*(entity.items.get(Items.coal)>0?2.5:1))) - )); - }, - //for dislpying info - setStats(){ - this.super$setStats(); - this.stats.remove(BlockStat.powerUse); - this.stats.remove(BlockStat.productionTime); - this.stats.add(BlockStat.booster,new ItemListValue(ItemStack(Items.coal,1))) - this.stats.add(BlockStat.boostEffect,2.5,StatUnit.timesSpeed); - var recLen=this.recs.length; - //crafTimes - for(var i=0;i0) this.stats.add(BlockStat.powerUse,this.recs[i].input.power*60,StatUnit.powerSecond); - else this.stats.add(BlockStat.powerUse,0,StatUnit.powerSecond); - } - } - }, - //custom function for consumeing items and liquids - customCons(tile,i){ - const entity=tile.ent(); - var excute=this.checkCond(tile,i); - entity.saveCond(excute); - if(excute){ - //do produce - if(entity.getProgress(i)!=0&&entity.getProgress(i)!=null){ - entity.progress=entity.getProgress(i); - entity.saveProgress(i,0); - } - entity.progress+=(entity.items.get(Items.coal)>0?2.5:1)*entity.warmup*this.getProgressIncreaseA(entity,i,this.recs[i].craftTime); - if(entity.items.get(Items.coal)>0){ - var oldProgress=entity.totalProgress; - var prog=Time.delta() - entity.totalProgress+=prog; - if(entity.totalProgress>=120) { - entity.items.remove(Items.coal,1); - entity.totalProgress=0; +const multiLib = require("multi-lib2/wrapper"); +const furnaces = this.global.furnaces; +const advancedFurnace = multiLib.extend(GenericCrafter, "advanced-furnace", + [{ + input: { + items: ["steam-power-copper-ore/1"], + power: 0.6 + }, + output: { + items: ["copper/1"], + liquids: ["slag/1"] + }, + craftTime: 50 + }, + { + input: { + items: ["steam-power-lead-ore/1"], + power: 0.6 + }, + output: { + items: ["lead/1"], + liquids: ["slag/1"] + }, + craftTime: 50 + }, + { + input: { + items: ["steam-power-iron-ore/1"], + power: 0.6 + }, + output: { + items: ["steam-power-iron/1"], + liquids: ["slag/1"] + }, + craftTime: 100 + }, + { + input: { + items: ["steam-power-titanium-ore/1"], + power: 0.6 + }, + output: { + items: ["titanium/1"], + liquids: ["slag/1"] + }, + craftTime: 50 + }, + { + input: { + items: ["sand/1"], + power: 0.6 + }, + output: { + items: ["steam-power-glass/1"], + liquids: [] + }, + craftTime: 50 + }, + { + input: { + items: ["scrap/1"], + power: 0.6 + }, + output: { + liquids: ["slag/2"] + }, + craftTime: 25 + }, + ], { + setBars() { + this.super$setBars(); + //initialize + this.bars.remove("liquid"); + this.bars.remove("items"); + //display every Liquids that can contain + var i = 0; + if (!this.liquidSet.isEmpty()) { + this.liquidSet.each(cons(k => { + this.bars.add("liquid" + i, func(entity => + new Bar(prov(() => k.localizedName), prov(() => k.barColor()), floatp(() => entity.liquids.get(k) / this.liquidCapacity)) + )); + i++; + })); + } + this.bars.add("multiplier", func(entity => + new Bar(prov(() => Core.bundle.formatFloat("bar.efficiency", entity.warmup * 100 * (entity.items.get(Items.coal) > 0 ? 2.5 : 1), 1)), prov(() => Pal.ammo), floatp(() => entity.warmup * (entity.items.get(Items.coal) > 0 ? 2.5 : 1))) + )); + }, + //for dislpying info + setStats() { + this.super$setStats(); + this.stats.remove(BlockStat.powerUse); + this.stats.remove(BlockStat.productionTime); + this.stats.add(BlockStat.booster, new ItemListValue(ItemStack(Items.coal, 1))) + this.stats.add(BlockStat.boostEffect, 2.5, StatUnit.timesSpeed); + }, + //custom function for consumeing items and liquids + customCons(tile, i) { + const entity = tile.ent(); + var excute = this.checkCond(tile, i); + entity.saveCond(excute); + if (excute) { + //do produce + if (entity.getProgress(i) != 0 && entity.getProgress(i) != null) { + entity.progress = entity.getProgress(i); + entity.saveProgress(i, 0); + } + entity.progress += (entity.items.get(Items.coal) > 0 ? 2.5 : 1) * entity.warmup * this.getProgressIncreaseA(entity, i, this.recs[i].craftTime); + if (entity.items.get(Items.coal) > 0) { + var oldProgress = entity.totalProgress; + var prog = Time.delta() + entity.totalProgress += prog; + if (entity.totalProgress >= 120) { + entity.items.remove(Items.coal, 1); + entity.totalProgress = 0; + } + if (entity.totalProgress % 120 <= prog && entity.totalProgress != 0 && !(oldProgress <= prog)) entity.items.remove(Items.coal, 1); + } + entity.warmup = Mathf.lerpDelta(entity.warmup, 1, 0.02); + if (Mathf.equal(entity.warmup, 1, 0.02)) { + entity.warmup = 1; + } + if (Mathf.chance(Time.delta() * this.updateEffectChance)) { + Effects.effect(this.updateEffect, entity.x + Mathf.range(this.size * 4), entity.y + Mathf.range(this.size * 4)); + } + } else entity.warmup = Mathf.lerp(entity.warmup, 0, 0.02); + }, + //decides which item to accept + acceptItem(item, tile, source) { + const entity = tile.ent(); + if (entity == null) return false; + if (entity.items.get(item) >= this.itemCapacity) return false; + return item == Items.coal || this.inputItemSet.contains(item); + }, + placed(tile) { + this.super$placed(tile); + this.register(tile.entity, 1); + }, + register(entity, value) { + if (entity != null) furnaces.update(entity, value); + }, + removed(tile) { + this.register(tile.entity, 1); + this.register(tile.entity, 0); + this.invFrag.hide(); + }, + customUpdate(tile) { + const entity = tile.ent(); + if (entity == null) return; + if (entity.getToggle() == -1) entity.warmup = Mathf.lerp(entity.warmup, 0, 0.02); + if (Time.time() % 60 < Time.delta()) this.register(entity, 1); + }, + //custom function that checks space for item and liquid + checkoutput(tile, i) { + const entity = tile.ent(); + //items + var items = this.recs[i].output.items; + for (var j = 0, len = items.length; j < len; j++) { + if (entity.items.get(items[j].item) + items[j].amount > this.itemCapacity) return true; + } + return false; + }, + configured(tile, player, value) { + const entity = tile.ent(); + const old = entity.getToggle(); + if ((old == 1 || old == 0) && value != 1 && value != 0) furnaces.sizes[tile.getTeam()]--; + if ((value == 1 || value == 0) && old != 1 && old != 0) furnaces.sizes[tile.getTeam()]++; + if (old >= 0) entity.saveProgress(old, entity.progress); + if (value == -1) entity.saveCond(false); + entity.progress = 0; + entity.setToggle(value); + }, + random: new Rand(0), + draw(tile) { + const entity = tile.ent(); + Draw.rect(this.region, tile.drawx(), tile.drawy()); + if (entity.warmup > 0.01) { + Draw.color(Color.salmon); + Draw.alpha(entity.warmup); + Draw.rect(this.topRegion, tile.drawx(), tile.drawy()); + if (entity.warmup > 0.4) { + var seeds = Math.round(entity.warmup * 12); + Draw.color(Color.valueOf("474747"), Color.gold, entity.warmup); + this.random.setSeed(tile.pos()); + for (var i = 0; i < seeds; i++) { + var offset = this.random.nextFloat() * 999999; + var x = this.random.range(6), + y = this.random.range(6); + var life = 1 - (((Time.time() + offset) / 50) % 6); + if (life > 0) { + Lines.stroke(entity.warmup * (life * 1 + 0.2)); + Lines.poly(tile.drawx() + x, tile.drawy() + y, 8, (1 - life) * 3); + } + } + } + Draw.color(); + } + }, + load() { + this.super$load(); + this.topRegion = Core.atlas.find(this.name + "-top") } - if(entity.totalProgress%120<=prog&&entity.totalProgress!=0&&!(oldProgress<=prog)) entity.items.remove(Items.coal,1); - } - entity.warmup=Mathf.lerpDelta(entity.warmup,1,0.02); - if(Mathf.equal(entity.warmup,1,0.02)){ - entity.warmup=1; - } - if(Mathf.chance(Time.delta()*this.updateEffectChance)){ - Effects.effect(this.updateEffect,entity.x+Mathf.range(this.size*4),entity.y+Mathf.range(this.size*4)); - } - }else entity.warmup=Mathf.lerp(entity.warmup,0,0.02); - }, - //decides which item to accept - acceptItem(item,tile,source){ - const entity=tile.ent(); - if(entity==null) return false; - if(entity.items.get(item)>=this.itemCapacity) return false; - return item==Items.coal||this.inputItemSet.contains(item); - }, - placed(tile){ - this.super$placed(tile); - this.register(tile.entity,1); - }, - register(entity,value){ - if(entity!=null)furnaces.update(entity,value); - }, - removed(tile){ - this.register(tile.entity,1); - this.register(tile.entity,0); - this.invFrag.hide(); - }, - customUpdate(tile){ - const entity=tile.ent(); - if(entity==null) return; - if(entity.getToggle()==-1)entity.warmup=Mathf.lerp(entity.warmup,0,0.02); - if(Time.time()%60this.itemCapacity) return true; - } - return false; - }, - configured(tile,player,value){ - const entity=tile.ent(); - const old=entity.getToggle(); - if((old==1||old==0)&&value!=1&&value!=0) furnaces.sizes[tile.getTeam()]--; - if((value==1||value==0)&&old!=1&&old!=0) furnaces.sizes[tile.getTeam()]++; - if(old>=0) entity.saveProgress(old,entity.progress); - if(value==-1) entity.saveCond(false); - entity.progress=0; - entity.setToggle(value); - }, - random:new Rand(0), - draw(tile){ - const entity=tile.ent(); - Draw.rect(this.region,tile.drawx(),tile.drawy()); - if(entity.warmup>0.01) { - Draw.color(Color.salmon); - Draw.alpha(entity.warmup); - Draw.rect(this.topRegion,tile.drawx(),tile.drawy()); - if(entity.warmup>0.4) { - var seeds=Math.round(entity.warmup*12); - Draw.color(Color.valueOf("474747"),Color.gold,entity.warmup); - this.random.setSeed(tile.pos()); - for(var i=0;i0){ - Lines.stroke(entity.warmup*(life*1+0.2)); - Lines.poly(tile.drawx()+x,tile.drawy()+y,8,(1-life)*3); - } - } - } - Draw.color(); - } - }, - load(){ - this.super$load(); - this.topRegion=Core.atlas.find(this.name+"-top") - } -},{}); -advancedFurnace.dumpToggle=false; + }, {}); +advancedFurnace.dumpToggle = false; diff --git a/scripts/blocks/production/blast-furnace.js b/scripts/blocks/production/blast-furnace.js index c496d67..77479b7 100644 --- a/scripts/blocks/production/blast-furnace.js +++ b/scripts/blocks/production/blast-furnace.js @@ -1,244 +1,224 @@ -const multiLib=require("multi-lib2/wrapper"); -const furnaces=this.global.furnaces; -const blastFurnace=multiLib.extend(GenericCrafter,"blast-furnace",[ - { - input:{ - items:["steam-power-copper-ore/1"], - }, - output:{ - items:["copper/1"], - liquids:["slag/1"] - }, - craftTime:100 - }, - { - input:{ - items:["steam-power-lead-ore/1"], - }, - output:{ - items:["lead/1"], - liquids:["slag/1"] - }, - craftTime:100 - }, - { - input:{ - items:["steam-power-iron-ore/1"], - }, - output:{ - items:["steam-power-iron/1"], - liquids:["slag/1"] - }, - craftTime:100 - }, - { - input:{ - items:["steam-power-titanium-ore/1"], - }, - output:{ - items:["titanium/1"], - liquids:["slag/1"] - }, - craftTime:100 - }, - { - input:{ - items:["sand/1"], - }, - output:{ - items:["steam-power-glass/1"], - liquids:[] - }, - craftTime:100 - }, - { - input:{ - items:["scrap/1"], - }, - output:{ - liquids:["slag/2"] - }, - craftTime:50 - }, -], -{ - setBars(){ - this.super$setBars(); - //initialize - this.bars.remove("liquid"); - this.bars.remove("power") - //display every Liquids that can contain - var i=0; - if(!this.liquidSet.isEmpty()){ - this.liquidSet.each(cons(k=>{ - this.bars.add("liquid"+i,func(entity=> - new Bar(prov(()=>k.localizedName),prov(()=>k.barColor()),floatp(()=>entity.liquids.get(k)/this.liquidCapacity)) +const multiLib = require("multi-lib2/wrapper"); +const furnaces = this.global.furnaces; +const blastFurnace = multiLib.extend(GenericCrafter, "blast-furnace", [{ + input: { + items: ["steam-power-copper-ore/1"], + }, + output: { + items: ["copper/1"], + liquids: ["slag/1"] + }, + craftTime: 100 + }, + { + input: { + items: ["steam-power-lead-ore/1"], + }, + output: { + items: ["lead/1"], + liquids: ["slag/1"] + }, + craftTime: 100 + }, + { + input: { + items: ["steam-power-iron-ore/1"], + }, + output: { + items: ["steam-power-iron/1"], + liquids: ["slag/1"] + }, + craftTime: 100 + }, + { + input: { + items: ["steam-power-titanium-ore/1"], + }, + output: { + items: ["titanium/1"], + liquids: ["slag/1"] + }, + craftTime: 100 + }, + { + input: { + items: ["sand/1"], + }, + output: { + items: ["steam-power-glass/1"], + liquids: [] + }, + craftTime: 100 + }, + { + input: { + items: ["scrap/1"], + }, + output: { + liquids: ["slag/2"] + }, + craftTime: 50 + }, +], { + setBars() { + this.super$setBars(); + //initialize + this.bars.remove("liquid"); + this.bars.remove("power") + //display every Liquids that can contain + var i = 0; + if (!this.liquidSet.isEmpty()) { + this.liquidSet.each(cons(k => { + this.bars.add("liquid" + i, func(entity => + new Bar(prov(() => k.localizedName), prov(() => k.barColor()), floatp(() => entity.liquids.get(k) / this.liquidCapacity)) + )); + i++; + })); + } + this.bars.add("multiplier", func(entity => + new Bar(prov(() => Core.bundle.formatFloat("bar.efficiency", entity.warmup * 100 * (entity.items.get(Items.coal) > 0 ? 2.5 : 1), 1)), prov(() => Pal.ammo), floatp(() => entity.warmup * (entity.items.get(Items.coal) > 0 ? 2.5 : 1))) )); - i++; - })); - } - this.bars.add("multiplier",func(entity=> - new Bar(prov(()=>Core.bundle.formatFloat("bar.efficiency",entity.warmup*100*(entity.items.get(Items.coal)>0?2.5:1),1)),prov(()=>Pal.ammo),floatp(()=>entity.warmup*(entity.items.get(Items.coal)>0?2.5:1))) - )); - }, - //for dislpying info - setStats(){ - this.super$setStats(); - this.stats.remove(BlockStat.powerUse); - this.stats.remove(BlockStat.productionTime); - this.stats.add(BlockStat.booster,new ItemListValue(ItemStack(Items.coal,1))) - this.stats.add(BlockStat.boostEffect,2.5,StatUnit.timesSpeed); - var recLen=this.recs.length; - //crafTimes - for(var i=0;i0?2.5:1)*entity.warmup*this.getProgressIncreaseA(entity,i,this.recs[i].craftTime); - if(entity.items.get(Items.coal)>0){ - var oldProgress=entity.totalProgress; - var prog=Time.delta() - entity.totalProgress+=prog; - if(entity.totalProgress>=120) { - entity.items.remove(Items.coal,1); - entity.totalProgress=0; - } - if(entity.totalProgress%120<=prog&&entity.totalProgress!=0&&!(oldProgress<=prog)) entity.items.remove(Items.coal,1); - } - entity.warmup=Mathf.lerpDelta(entity.warmup,1,0.002); - if(Mathf.equal(entity.warmup,1,0.002)){ - entity.warmup=1; - } - if(Mathf.chance(Time.delta()*this.updateEffectChance)){ - Effects.effect(this.updateEffect,entity.x+Mathf.range(this.size*4),entity.y+Mathf.range(this.size*4)); - } - }, - //decides which item to accept - acceptItem(item,tile,source){ - const entity=tile.ent(); - if(entity==null) return false; - if(entity.items.get(item)>=this.itemCapacity) return false; - return item==Items.coal||this.inputItemSet.contains(item); - }, - placed(tile){ - this.super$placed(tile); - this.register(tile.entity,1); - }, - register(entity,value){ - if(entity!=null)furnaces.update(entity,value); - }, - removed(tile){ - this.register(tile.entity,1); - this.register(tile.entity,0); - this.invFrag.hide(); - }, - customUpdate(tile){ - const entity=tile.ent(); - if(entity==null) return; - if(entity.getToggle()==-1)entity.warmup=Mathf.lerp(entity.warmup,0,0.02); - if(Time.time()%60=1) this.customProd(tile,i); - break; - } - } - if(i==recLen) { - entity.warmup=Mathf.lerp(entity.warmup,0,0.02); - entity.saveCond(false) - } - //TODO 반복문 줄이기 - if(entity.timer.get(this.timerDump,this.dumpTime)&&eItems.total()>0){ - var itemIter=this.outputItemSet.iterator(); - while(itemIter.hasNext()){ - var item=itemIter.next(); - if(eItems.has(item)){ - this.tryDump(tile,item); - break; + }, + //for dislpying info + setStats() { + this.super$setStats(); + this.stats.remove(BlockStat.powerUse); + this.stats.remove(BlockStat.productionTime); + this.stats.add(BlockStat.booster, new ItemListValue(ItemStack(Items.coal, 1))) + this.stats.add(BlockStat.boostEffect, 2.5, StatUnit.timesSpeed); + }, + //custom function for consumeing items and liquids + customCons(tile, i) { + const entity = tile.ent(); + //do produce + entity.saveCond(true); + if (entity.getProgress(i) != 0 && entity.getProgress(i) != null) { + entity.progress = entity.getProgress(i); + entity.saveProgress(i, 0); } - } - } - if(eLiquids.total()>0.001){ - var liquidIter=this.outputLiquidSet.iterator(); - while(liquidIter.hasNext()){ - var liquid=liquidIter.next(); - if(eLiquids.get(liquid)>0.001){ - this.tryDumpLiquid(tile,liquid); - break; + entity.progress += (entity.items.get(Items.coal) > 0 ? 2.5 : 1) * entity.warmup * this.getProgressIncreaseA(entity, i, this.recs[i].craftTime); + if (entity.items.get(Items.coal) > 0) { + var oldProgress = entity.totalProgress; + var prog = Time.delta() + entity.totalProgress += prog; + if (entity.totalProgress >= 120) { + entity.items.remove(Items.coal, 1); + entity.totalProgress = 0; + } + if (entity.totalProgress % 120 <= prog && entity.totalProgress != 0 && !(oldProgress <= prog)) entity.items.remove(Items.coal, 1); } - } - } - }, - _configure(entity,value){ - const i=entity.getToggle(); - if(i>=0) entity.saveProgress(i,entity.progress); - entity.progress=0; - entity.setToggle(value); - }, - random:new Rand(0), - draw(tile){ - const entity=tile.ent(); - Draw.rect(this.region,tile.drawx(),tile.drawy()); - if(entity.warmup>0.01) { - Draw.color(Color.salmon); - Draw.alpha(entity.warmup); - Draw.rect(this.topRegion,tile.drawx(),tile.drawy()); - if(entity.warmup>0.4) { - var seeds=Math.round(entity.warmup*12); - Draw.color(Color.valueOf("474747"),Color.gold,entity.warmup); - this.random.setSeed(tile.pos()); - for(var i=0;i0){ - Lines.stroke(entity.warmup*(life*1+0.2)); - Lines.poly(tile.drawx()+x,tile.drawy()+y,8,(1-life)*3); - } + entity.warmup = Mathf.lerpDelta(entity.warmup, 1, 0.002); + if (Mathf.equal(entity.warmup, 1, 0.002)) { + entity.warmup = 1; + } + if (Mathf.chance(Time.delta() * this.updateEffectChance)) { + Effects.effect(this.updateEffect, entity.x + Mathf.range(this.size * 4), entity.y + Mathf.range(this.size * 4)); } - } - Draw.color(); + }, + //decides which item to accept + acceptItem(item, tile, source) { + const entity = tile.ent(); + if (entity == null) return false; + if (entity.items.get(item) >= this.itemCapacity) return false; + return item == Items.coal || this.inputItemSet.contains(item); + }, + placed(tile) { + this.super$placed(tile); + this.register(tile.entity, 1); + }, + register(entity, value) { + if (entity != null) furnaces.update(entity, value); + }, + removed(tile) { + this.register(tile.entity, 1); + this.register(tile.entity, 0); + this.invFrag.hide(); + }, + customUpdate(tile) { + const entity = tile.ent(); + if (entity == null) return; + if (entity.getToggle() == -1) entity.warmup = Mathf.lerp(entity.warmup, 0, 0.02); + if (Time.time() % 60 < Time.delta()) this.register(entity, 1); + }, + update(tile) { + const entity = tile.ent(); + var recLen = this.recs.length; + var eItems = entity.items; + var eLiquids = entity.liquids; + //to not rewrite whole update + if (typeof this["customUpdate"] === "function") this.customUpdate(tile); + for (var i = 0; i < recLen; i++) { + var input = this.recs[i].input.items[0].item; + var output = this.recs[i].output.items[0]; + if ((output == null || eItems.get(output.item) < this.itemCapacity) && eItems.has(input)) { + this._configure(entity, i); + this.customCons(tile, i); + if (entity.getToggle() == i && entity.progress >= 1) this.customProd(tile, i); + break; + } + } + if (i == recLen) { + entity.warmup = Mathf.lerp(entity.warmup, 0, 0.02); + entity.saveCond(false) + } + //TODO 반복문 줄이기 + if (entity.timer.get(this.timerDump, this.dumpTime) && eItems.total() > 0) { + var itemIter = this.outputItemSet.iterator(); + while (itemIter.hasNext()) { + var item = itemIter.next(); + if (eItems.has(item)) { + this.tryDump(tile, item); + break; + } + } + } + if (eLiquids.total() > 0.001) { + var liquidIter = this.outputLiquidSet.iterator(); + while (liquidIter.hasNext()) { + var liquid = liquidIter.next(); + if (eLiquids.get(liquid) > 0.001) { + this.tryDumpLiquid(tile, liquid); + break; + } + } + } + }, + _configure(entity, value) { + const i = entity.getToggle(); + if (i >= 0) entity.saveProgress(i, entity.progress); + entity.progress = 0; + entity.setToggle(value); + }, + random: new Rand(0), + draw(tile) { + const entity = tile.ent(); + Draw.rect(this.region, tile.drawx(), tile.drawy()); + if (entity.warmup > 0.01) { + Draw.color(Color.salmon); + Draw.alpha(entity.warmup); + Draw.rect(this.topRegion, tile.drawx(), tile.drawy()); + if (entity.warmup > 0.4) { + var seeds = Math.round(entity.warmup * 12); + Draw.color(Color.valueOf("474747"), Color.gold, entity.warmup); + this.random.setSeed(tile.pos()); + for (var i = 0; i < seeds; i++) { + var offset = this.random.nextFloat() * 999999; + var x = this.random.range(6), + y = this.random.range(6); + var life = 1 - (((Time.time() + offset) / 50) % 6); + if (life > 0) { + Lines.stroke(entity.warmup * (life * 1 + 0.2)); + Lines.poly(tile.drawx() + x, tile.drawy() + y, 8, (1 - life) * 3); + } + } + } + Draw.color(); + } + }, + load() { + this.super$load(); + this.topRegion = Core.atlas.find(this.name + "-top") } - }, - load(){ - this.super$load(); - this.topRegion=Core.atlas.find(this.name+"-top") - } -},{}); -blastFurnace.dumpToggle=false; -blastFurnace.configurable=false; +}, {}); +blastFurnace.dumpToggle = false; +blastFurnace.configurable = false; diff --git a/scripts/blocks/production/metal-smelter.js b/scripts/blocks/production/metal-smelter.js index 9c33c5f..2422269 100644 --- a/scripts/blocks/production/metal-smelter.js +++ b/scripts/blocks/production/metal-smelter.js @@ -1,203 +1,195 @@ -const multiLib=require("multi-lib2/wrapper"); -const metalSmelter=multiLib.extend(GenericSmelter,"metal-smelter",[ - { - input:{ - items:["copper/3","lead/4","titanium/2","steam-power-iron/3"], - power:5 - }, - output:{ - items:["surge-alloy/1"] - }, - craftTime:75 - }, - { - input:{ - items:["steam-power-iron/2","graphite/1"], - power:8 - }, - output:{ - items:["steam-power-steel/1"] - }, - craftTime:90 - }, - { - input:{ - items:["steam-power-steel/2","steam-power-depleted-uranium/1","plastanium/1"], - power:11 - }, - output:{ - items:["steam-power-dense-alloy/1"] - }, - craftTime:90 - }, - { - input:{ - items:["steam-power-quantum-mass/1","plastanium/2","graphite/1"], - power:20 - }, - output:{ - items:["steam-power-dimension-armour/1"] - }, - craftTime:150 - }, -], -{ - heatCons:[0,0.15,0.2,0.25], - heatCond:[0,100,360,840], - heatCapacity:1500, - update(tile){ - const entity=tile.ent(); - if(!this.invFrag.isShown()&&Vars.control.input.frag.config.isShown()&&Vars.control.input.frag.config.getSelectedTile()==tile){ this.invFrag.showFor(tile);} - var recLen=this.recs.length; - var current=entity.getToggle(); - entity.coolDownHeat(); - //calls customCons and customProd - if(current>=0) { - this.customCons(tile,current); - if(entity.progress>=1) this.customProd(tile,current); - } - var eItems=entity.items; - var eLiquids=entity.liquids; - //dump - var itemTimer=entity.timer.get(this.timerDump,this.dumpTime); - if(this.dumpToggle&¤t>-1){ - var items=this.recs[current].output.items; - var liquids=this.recs[current].output.liquids; - if(itemTimer){ - for(var i=0,len=items.length;i0.001){ - this.tryDumpLiquid(tile,liquids[i].liquid); - break; + var recLen = this.recs.length; + var current = entity.getToggle(); + entity.coolDownHeat(); + //calls customCons and customProd + if (current >= 0) { + this.customCons(tile, current); + if (entity.progress >= 1) this.customProd(tile, current); } - } - }else{ - //TODO 반복문 줄이기 - if(itemTimer&&eItems.total()>0){ - var itemIter=this.outputItemSet.iterator(); - while(itemIter.hasNext()){ - var item=itemIter.next(); - if(eItems.has(item)){ - this.tryDump(tile,item); - break; - } + var eItems = entity.items; + var eLiquids = entity.liquids; + //dump + var itemTimer = entity.timer.get(this.timerDump, this.dumpTime); + if (this.dumpToggle && current > -1) { + var items = this.recs[current].output.items; + var liquids = this.recs[current].output.liquids; + if (itemTimer) { + for (var i = 0, len = items.length; i < len; i++) { + if (eItems.has(items[i].item)) { + this.tryDump(tile, items[i].item); + break; + } + } + } + for (var i = 0, len = liquids.length; i < len; i++) { + if (eLiquids.get(liquids[i].liquid) > 0.001) { + this.tryDumpLiquid(tile, liquids[i].liquid); + break; + } + } + } else { + //TODO 반복문 줄이기 + if (itemTimer && eItems.total() > 0) { + var itemIter = this.outputItemSet.iterator(); + while (itemIter.hasNext()) { + var item = itemIter.next(); + if (eItems.has(item)) { + this.tryDump(tile, item); + break; + } + } + } + if (eLiquids.total() > 0.001) { + var liquidIter = this.outputLiquidSet.iterator(); + while (liquidIter.hasNext()) { + var liquid = liquidIter.next(); + if (eLiquids.get(liquid) > 0.001) { + this.tryDumpLiquid(tile, liquid); + break; + } + } + } } - } - if(eLiquids.total()>0.001){ - var liquidIter=this.outputLiquidSet.iterator(); - while(liquidIter.hasNext()){ - var liquid=liquidIter.next(); - if(eLiquids.get(liquid)>0.001){ - this.tryDumpLiquid(tile,liquid); - break; - } + if (entity.getHeat() >= this.heatCapacity) entity.kill(); + }, + setStats() { + this.super$setStats(); + this.heatPSec = Core.bundle.get("steam-power-heat-per-sec"); + this.heatC = Core.bundle.get("steam-power-heat-cond"); + this.heatUse = Core.bundle.get("steam-power-heatUse"); + this.heatRange = Core.bundle.get("steam-power-heatRange"); + this.stats.remove(BlockStat.powerUse); + this.stats.remove(BlockStat.productionTime); + }, + customDisplay(table, i) { + if (this.heatCons[i] > 0) { + table.table(cons(row => { + row.add("[lightgray]" + this.heatUse + ":[]").padRight(4); + (new StringValue(this.heatPSec, String(this.heatCons[i] * 60))).display(row); + })).left().row(); } - } - } - if(entity.getHeat()>=this.heatCapacity) entity.kill(); - }, - setStats(){ - this.super$setStats(); - var heatPSec=Core.bundle.get("steam-power-heat-per-sec"); - var heatC=Core.bundle.get("steam-power-heat-cond"); - this.stats.remove(BlockStat.powerUse); - this.stats.remove(BlockStat.productionTime); - var recLen=this.recs.length; - for(var i=0;i - new Bar(prov(()=>Core.bundle.format("bar.heat")+": "+(typeof(entity["getHeat"])!=="function"?0.0:entity.getHeat()).toFixed(1)),prov(()=>Pal.lightFlame),floatp(()=>typeof(entity["getHeat"])!=="function"?0:entity.getHeat()/this.heatCapacity)) - )); - }, - inputsHeat(tile){ - return true; - }, - onDestroyed(tile){ - this.super$onDestroyed(tile); - Sounds.explosionbig.at(tile); - const entity=tile.ent(); - if(entity.getHeat()entity.getHeat(); - }, -},{ - _heat:25, - getHeat(){ - return this._heat; - }, - setHeat(a){ - this._heat=a; - }, - addHeat(b){ - this._heat+=b; - }, - coolDownHeat(){ - if(this._heat>25){ - this._heat-=Time.delta()*this._heat/1200; - }else if(this._heat<25){ - this._heat=25; + if (this.heatCond[i] > 0) { + table.table(cons(row => { + row.add("[lightgray]" + this.heatRange + ":[]").padRight(4); + (new StringValue(this.heatC, String(this.heatCond[i]))).display(row); + })).left().row(); + } + }, + setBars() { + this.super$setBars(); + //initialize + this.bars.remove("liquid"); + this.bars.remove("items"); + this.outputsPower = false; + this.bars.add("heat", func(entity => + new Bar(prov(() => Core.bundle.format("bar.heat") + ": " + (typeof(entity["getHeat"]) !== "function" ? 0.0 : entity.getHeat()).toFixed(1)), prov(() => Pal.lightFlame), floatp(() => typeof(entity["getHeat"]) !== "function" ? 0 : entity.getHeat() / this.heatCapacity)) + )); + }, + inputsHeat(tile) { + return true; + }, + onDestroyed(tile) { + this.super$onDestroyed(tile); + Sounds.explosionbig.at(tile); + const entity = tile.ent(); + if (entity.getHeat() < this.heatCapacity / 2) return; + Effects.effect(Fx.pulverize, tile.worldx(), tile.worldy()); + Damage.damage(tile.worldx(), tile.worldy(), 16 * this.size, 50); + }, + drawLight(tile) { + Vars.renderer.lights.add(tile.drawx(), tile.drawy(), (10 + tile.entity.getHeat() / 20 + Mathf.absin(10, 0.5)) * this.size, Color.scarlet, 0.4); + }, + checkinput(tile, i) { + const entity = tile.ent(); + //items + var items = this.recs[i].input.items; + var liquids = this.recs[i].input.liquids; + for (var j = 0, len = items.length; j < len; j++) { + if (entity.items.get(items[j].item) < items[j].amount) return true; + } + //liquids + for (var j = 0, len = liquids.length; j < len; j++) { + if (entity.liquids.get(liquids[j].liquid) < liquids[j].amount) return true; + } + return this.heatCond[i] > entity.getHeat(); + }, +}, { + _heat: 25, + getHeat() { + return this._heat; + }, + setHeat(a) { + this._heat = a; + }, + addHeat(b) { + this._heat += b; + }, + coolDownHeat() { + if (this._heat > 25) { + this._heat -= Time.delta() * this._heat / 1200; + } else if (this._heat < 25) { + this._heat = 25; + } + }, + write(stream) { + this.super$write(stream); + stream.writeShort(this._toggle); + stream.writeFloat(this._heat); + }, + read(stream, revision) { + this.super$read(stream, revision); + this._toggle = stream.readShort(); + this._heat = stream.readFloat(); } - }, - write(stream){ - this.super$write(stream); - stream.writeShort(this._toggle); - stream.writeFloat(this._heat); - }, - read(stream,revision){ - this.super$read(stream,revision); - this._toggle=stream.readShort(); - this._heat=stream.readFloat(); - } }); -metalSmelter.dumpToggle=true; +metalSmelter.dumpToggle = true;