mirror of
https://github.com/Anuken/Mindustry.git
synced 2025-01-11 07:39:39 +07:00
Broke all crafting
This commit is contained in:
parent
50959317e9
commit
855957b099
@ -367,7 +367,7 @@ blocks.outputitemcapacity = Output Item Capacity
|
||||
blocks.itemcapacity = Item Capacity
|
||||
blocks.basepowergeneration = Base Power Generation
|
||||
blocks.powertransferspeed = Power Transfer
|
||||
blocks.craftspeed = Production Speed
|
||||
blocks.productiontime = Production Time:
|
||||
blocks.repairtime = Block Full Repair Time
|
||||
blocks.range = Range
|
||||
blocks.inputliquid = Input Liquid
|
||||
|
@ -370,7 +370,7 @@ public class Blocks implements ContentList{
|
||||
requirements(Category.crafting, ItemStack.with(Items.copper, 150, Items.lead, 60));
|
||||
|
||||
craftEffect = Fx.pulverizeMedium;
|
||||
output = Items.graphite;
|
||||
outputItem = Items.graphite;
|
||||
craftTime = 90f;
|
||||
size = 2;
|
||||
hasItems = true;
|
||||
@ -382,7 +382,7 @@ public class Blocks implements ContentList{
|
||||
requirements(Category.crafting, ItemStack.with(Items.titanium, 200, Items.silicon, 50, Items.lead, 200, Items.graphite, 100));
|
||||
|
||||
craftEffect = Fx.pulverizeMedium;
|
||||
output = Items.graphite;
|
||||
outputItem = Items.graphite;
|
||||
craftTime = 30f;
|
||||
size = 3;
|
||||
hasItems = true;
|
||||
@ -425,7 +425,7 @@ public class Blocks implements ContentList{
|
||||
hasItems = true;
|
||||
liquidCapacity = 60f;
|
||||
craftTime = 60f;
|
||||
output = Items.plastanium;
|
||||
outputItem = Items.plastanium;
|
||||
size = 2;
|
||||
health = 320;
|
||||
hasPower = hasLiquids = true;
|
||||
@ -475,7 +475,7 @@ public class Blocks implements ContentList{
|
||||
requirements(Category.crafting, ItemStack.with(Items.lead, 60, Items.titanium, 40));
|
||||
hasItems = true;
|
||||
hasPower = true;
|
||||
output = Items.blastCompound;
|
||||
outputItem = Items.blastCompound;
|
||||
size = 2;
|
||||
|
||||
consumes.items(new ItemStack(Items.pyratite, 1), new ItemStack(Items.sporePod, 1));
|
||||
@ -529,7 +529,7 @@ public class Blocks implements ContentList{
|
||||
|
||||
cultivator = new Cultivator("cultivator"){{
|
||||
requirements(Category.crafting, ItemStack.with(Items.copper, 20, Items.lead, 50, Items.silicon, 20));
|
||||
output = Items.sporePod;
|
||||
outputItem = Items.sporePod;
|
||||
craftTime = 160;
|
||||
size = 2;
|
||||
hasLiquids = true;
|
||||
@ -556,7 +556,7 @@ public class Blocks implements ContentList{
|
||||
|
||||
pulverizer = new Pulverizer("pulverizer"){{
|
||||
requirements(Category.crafting, ItemStack.with(Items.copper, 60, Items.lead, 50));
|
||||
output = Items.sand;
|
||||
outputItem = Items.sand;
|
||||
craftEffect = Fx.pulverize;
|
||||
craftTime = 40f;
|
||||
updateEffect = Fx.pulverizeSmall;
|
||||
|
19
core/src/io/anuke/mindustry/type/LiquidStack.java
Normal file
19
core/src/io/anuke/mindustry/type/LiquidStack.java
Normal file
@ -0,0 +1,19 @@
|
||||
package io.anuke.mindustry.type;
|
||||
|
||||
public class LiquidStack{
|
||||
public Liquid liquid;
|
||||
public float amount;
|
||||
|
||||
public LiquidStack(Liquid liquid, float amount){
|
||||
this.liquid = liquid;
|
||||
this.amount = amount;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString(){
|
||||
return "LiquidStack{" +
|
||||
"liquid=" + liquid +
|
||||
", amount=" + amount +
|
||||
'}';
|
||||
}
|
||||
}
|
@ -1,8 +1,10 @@
|
||||
package io.anuke.mindustry.ui;
|
||||
|
||||
import io.anuke.mindustry.type.Liquid;
|
||||
import io.anuke.arc.scene.ui.Image;
|
||||
import io.anuke.arc.scene.ui.layout.Stack;
|
||||
import io.anuke.arc.scene.ui.layout.Table;
|
||||
import io.anuke.arc.util.Strings;
|
||||
import io.anuke.mindustry.type.Liquid;
|
||||
|
||||
/**An ItemDisplay, but for liquids.*/
|
||||
public class LiquidDisplay extends Table{
|
||||
@ -11,4 +13,17 @@ public class LiquidDisplay extends Table{
|
||||
add(new Image(liquid.getContentIcon())).size(8*3);
|
||||
add(liquid.localizedName()).padLeft(3);
|
||||
}
|
||||
|
||||
public LiquidDisplay(Liquid liquid, float amount){
|
||||
add(new Stack(){{
|
||||
add(new Image(liquid.getContentIcon()));
|
||||
|
||||
if(amount != 0){
|
||||
Table t = new Table().left().bottom();
|
||||
t.add(Strings.toFixed(amount, 2));
|
||||
add(t);
|
||||
}
|
||||
}}).size(8*3);
|
||||
add(liquid.localizedName()).padLeft(3);
|
||||
}
|
||||
}
|
||||
|
@ -20,7 +20,6 @@ import io.anuke.mindustry.world.consumers.ConsumeLiquid;
|
||||
import io.anuke.mindustry.world.consumers.Consumers;
|
||||
import io.anuke.mindustry.world.meta.BlockBars;
|
||||
import io.anuke.mindustry.world.meta.BlockStats;
|
||||
import io.anuke.mindustry.world.meta.Producers;
|
||||
|
||||
public abstract class BlockStorage extends UnlockableContent{
|
||||
public boolean hasItems;
|
||||
@ -39,7 +38,7 @@ public abstract class BlockStorage extends UnlockableContent{
|
||||
public final BlockStats stats = new BlockStats();
|
||||
public final BlockBars bars = new BlockBars();
|
||||
public final Consumers consumes = new Consumers();
|
||||
public final Producers produces = new Producers();
|
||||
//public final Producers produces = new Producers();
|
||||
|
||||
public BlockStorage(String name){
|
||||
super(name);
|
||||
|
@ -8,6 +8,8 @@ import io.anuke.mindustry.entities.Effects;
|
||||
import io.anuke.mindustry.entities.Effects.Effect;
|
||||
import io.anuke.mindustry.entities.type.TileEntity;
|
||||
import io.anuke.mindustry.type.Item;
|
||||
import io.anuke.mindustry.type.ItemStack;
|
||||
import io.anuke.mindustry.type.LiquidStack;
|
||||
import io.anuke.mindustry.world.Block;
|
||||
import io.anuke.mindustry.world.Tile;
|
||||
import io.anuke.mindustry.world.meta.BlockStat;
|
||||
@ -20,7 +22,8 @@ import java.io.IOException;
|
||||
public class GenericCrafter extends Block{
|
||||
protected final int timerDump = timers++;
|
||||
|
||||
protected Item output;
|
||||
protected ItemStack outputItem;
|
||||
protected LiquidStack outputLiquid;
|
||||
|
||||
protected float craftTime = 80;
|
||||
protected Effect craftEffect = Fx.purify;
|
||||
@ -34,18 +37,18 @@ public class GenericCrafter extends Block{
|
||||
health = 60;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void init(){
|
||||
super.init();
|
||||
|
||||
produces.set(output);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setStats(){
|
||||
super.setStats();
|
||||
stats.add(BlockStat.craftSpeed, 60f / craftTime, StatUnit.itemsSecond);
|
||||
stats.add(BlockStat.outputItem, output);
|
||||
stats.add(BlockStat.productionTime, craftTime / 60f, StatUnit.itemsSecond);
|
||||
|
||||
if(outputItem != null){
|
||||
stats.add(BlockStat.output, outputItem);
|
||||
}
|
||||
|
||||
if(outputLiquid != null){
|
||||
stats.add(BlockStat.output, outputLiquid);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -64,14 +67,15 @@ public class GenericCrafter extends Block{
|
||||
public void update(Tile tile){
|
||||
GenericCrafterEntity entity = tile.entity();
|
||||
|
||||
if(entity.cons.valid() && tile.entity.items.get(output) < itemCapacity){
|
||||
if(entity.cons.valid()){
|
||||
|
||||
entity.progress += getProgressIncrease(entity, craftTime);
|
||||
entity.totalProgress += entity.delta();
|
||||
entity.warmup = Mathf.lerpDelta(entity.warmup, 1f, 0.02f);
|
||||
|
||||
if(Mathf.chance(Time.delta() * updateEffectChance))
|
||||
if(Mathf.chance(Time.delta() * updateEffectChance)){
|
||||
Effects.effect(updateEffect, entity.x + Mathf.range(size * 4f), entity.y + Mathf.range(size * 4));
|
||||
}
|
||||
}else{
|
||||
entity.warmup = Mathf.lerp(entity.warmup, 0f, 0.02f);
|
||||
}
|
||||
@ -79,14 +83,28 @@ public class GenericCrafter extends Block{
|
||||
if(entity.progress >= 1f){
|
||||
entity.cons.trigger();
|
||||
|
||||
useContent(tile, output);
|
||||
offloadNear(tile, output);
|
||||
if(outputItem != null){
|
||||
useContent(tile, outputItem.item);
|
||||
for(int i = 0; i < outputItem.amount; i++){
|
||||
offloadNear(tile, outputItem.item);
|
||||
}
|
||||
}
|
||||
|
||||
if(outputLiquid != null){
|
||||
useContent(tile, outputLiquid.liquid);
|
||||
handleLiquid(tile, tile, outputLiquid.liquid, outputLiquid.amount);
|
||||
}
|
||||
|
||||
Effects.effect(craftEffect, tile.drawx(), tile.drawy());
|
||||
entity.progress = 0f;
|
||||
}
|
||||
|
||||
if(tile.entity.timer.get(timerDump, 5)){
|
||||
tryDump(tile, output);
|
||||
if(outputItem != null && tile.entity.timer.get(timerDump, 5)){
|
||||
tryDump(tile, outputItem.item);
|
||||
}
|
||||
|
||||
if(outputLiquid != null){
|
||||
tryDumpLiquid(tile, outputLiquid.liquid);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,111 +0,0 @@
|
||||
package io.anuke.mindustry.world.blocks.production;
|
||||
|
||||
import io.anuke.mindustry.entities.type.TileEntity;
|
||||
import io.anuke.mindustry.type.Item;
|
||||
import io.anuke.mindustry.type.Liquid;
|
||||
import io.anuke.mindustry.world.Block;
|
||||
import io.anuke.mindustry.world.Tile;
|
||||
import io.anuke.mindustry.world.blocks.production.GenericCrafter.GenericCrafterEntity;
|
||||
import io.anuke.mindustry.world.meta.BlockStat;
|
||||
|
||||
/**Similar to GenericCrafter, but also optionally outputs liquids.
|
||||
* TODO consolidate into one class*/
|
||||
public class PowerCrafter extends Block{
|
||||
protected final int timerDump = timers++;
|
||||
protected final int timerContentCheck = timers++;
|
||||
|
||||
/**Optional.*/
|
||||
protected Item outputItem;
|
||||
/**Optional. Set hasLiquids to true when using.*/
|
||||
protected Liquid outputLiquid;
|
||||
protected float outputLiquidAmount;
|
||||
protected float craftTime;
|
||||
|
||||
public PowerCrafter(String name){
|
||||
super(name);
|
||||
solid = true;
|
||||
update = true;
|
||||
hasPower = true;
|
||||
hasItems = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean acceptLiquid(Tile tile, Tile source, Liquid liquid, float amount){
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void init(){
|
||||
super.init();
|
||||
|
||||
if(outputLiquid != null){
|
||||
outputsLiquid = true;
|
||||
}
|
||||
|
||||
if(outputLiquid != null){
|
||||
produces.set(outputLiquid);
|
||||
}else if(outputItem != null){
|
||||
produces.set(outputItem);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setStats(){
|
||||
super.setStats();
|
||||
|
||||
if(outputItem != null){
|
||||
stats.add(BlockStat.outputItem, outputItem);
|
||||
}
|
||||
|
||||
if(outputLiquid != null){
|
||||
stats.add(BlockStat.liquidOutput, outputLiquid);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canProduce(Tile tile){
|
||||
if(outputItem != null && tile.entity.items.get(outputItem) >= itemCapacity){
|
||||
return false;
|
||||
}
|
||||
return outputLiquid == null || !(tile.entity.liquids.get(outputLiquid) >= liquidCapacity - 0.01f);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update(Tile tile){
|
||||
GenericCrafterEntity entity = tile.entity();
|
||||
|
||||
if(entity.cons.valid()){
|
||||
entity.progress += getProgressIncrease(entity, craftTime);
|
||||
entity.totalProgress += entity.delta();
|
||||
}
|
||||
|
||||
if(entity.progress >= 1f){
|
||||
entity.items.remove(consumes.item(), consumes.itemAmount());
|
||||
if(outputItem != null){
|
||||
offloadNear(tile, outputItem);
|
||||
useContent(tile, outputItem);
|
||||
}
|
||||
|
||||
if(outputLiquid != null){
|
||||
handleLiquid(tile, tile, outputLiquid, outputLiquidAmount);
|
||||
if(tile.entity.liquids.currentAmount() > 0f && tile.entity.timer.get(timerContentCheck, 10)){
|
||||
useContent(tile, outputLiquid);
|
||||
}
|
||||
}
|
||||
entity.progress = 0f;
|
||||
}
|
||||
|
||||
if(outputItem != null && entity.timer.get(timerDump, 5)){
|
||||
tryDump(tile, outputItem);
|
||||
}
|
||||
|
||||
if(outputLiquid != null){
|
||||
tryDumpLiquid(tile, entity.liquids.current());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public TileEntity newEntity(){
|
||||
return new GenericCrafterEntity();
|
||||
}
|
||||
}
|
@ -1,55 +1,21 @@
|
||||
package io.anuke.mindustry.world.blocks.production;
|
||||
|
||||
import io.anuke.arc.Core;
|
||||
import io.anuke.mindustry.entities.Effects;
|
||||
import io.anuke.mindustry.entities.Effects.Effect;
|
||||
import io.anuke.arc.graphics.Color;
|
||||
import io.anuke.arc.graphics.g2d.Draw;
|
||||
import io.anuke.arc.graphics.g2d.Fill;
|
||||
import io.anuke.arc.graphics.g2d.TextureRegion;
|
||||
import io.anuke.arc.math.Mathf;
|
||||
import io.anuke.arc.util.Time;
|
||||
import io.anuke.mindustry.content.Fx;
|
||||
import io.anuke.mindustry.entities.type.TileEntity;
|
||||
import io.anuke.mindustry.type.Item;
|
||||
import io.anuke.mindustry.type.ItemStack;
|
||||
import io.anuke.mindustry.world.Tile;
|
||||
import io.anuke.mindustry.world.blocks.PowerBlock;
|
||||
import io.anuke.mindustry.world.meta.BlockStat;
|
||||
import io.anuke.mindustry.world.meta.StatUnit;
|
||||
|
||||
import java.io.DataInput;
|
||||
import java.io.DataOutput;
|
||||
import java.io.IOException;
|
||||
|
||||
public class PowerSmelter extends PowerBlock{
|
||||
protected final int timerDump = timers++;
|
||||
|
||||
protected Item output;
|
||||
|
||||
protected float heatUpTime = 80f;
|
||||
protected float minHeat = 0.5f;
|
||||
|
||||
protected float craftTime = 20f; //time to craft one item, so max 3 items per second by default
|
||||
protected float burnEffectChance = 0.01f;
|
||||
protected Effect craftEffect = Fx.smelt,
|
||||
burnEffect = Fx.fuelburn;
|
||||
/**A GenericCrafter with a new glowing region drawn on top.*/
|
||||
public class PowerSmelter extends GenericCrafter{
|
||||
protected Color flameColor = Color.valueOf("ffc999");
|
||||
|
||||
protected TextureRegion topRegion;
|
||||
|
||||
public PowerSmelter(String name){
|
||||
super(name);
|
||||
hasItems = true;
|
||||
update = true;
|
||||
solid = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void init(){
|
||||
super.init();
|
||||
|
||||
produces.set(output);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -58,118 +24,27 @@ public class PowerSmelter extends PowerBlock{
|
||||
topRegion = Core.atlas.find(name + "-top");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setStats(){
|
||||
super.setStats();
|
||||
|
||||
stats.add(BlockStat.outputItem, output);
|
||||
stats.add(BlockStat.craftSpeed, 60f / craftTime, StatUnit.itemsSecond);
|
||||
stats.add(BlockStat.inputItemCapacity, itemCapacity, StatUnit.items);
|
||||
stats.add(BlockStat.outputItemCapacity, itemCapacity, StatUnit.items);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update(Tile tile){
|
||||
|
||||
PowerSmelterEntity entity = tile.entity();
|
||||
|
||||
if(entity.timer.get(timerDump, 5) && entity.items.has(output)){
|
||||
tryDump(tile, output);
|
||||
}
|
||||
|
||||
//heat it up if there's enough power
|
||||
if(entity.cons.valid()){
|
||||
entity.heat += 1f / heatUpTime * entity.delta();
|
||||
if(Mathf.chance(entity.delta() * burnEffectChance))
|
||||
Effects.effect(burnEffect, entity.x + Mathf.range(size * 4f), entity.y + Mathf.range(size * 4));
|
||||
}else{
|
||||
entity.heat -= 1f / heatUpTime * Time.delta();
|
||||
}
|
||||
|
||||
entity.heat = Mathf.clamp(entity.heat);
|
||||
entity.time += entity.heat * entity.delta();
|
||||
|
||||
if(!entity.cons.valid()){
|
||||
return;
|
||||
}
|
||||
|
||||
entity.craftTime += entity.delta() * entity.power.satisfaction;
|
||||
|
||||
if(entity.items.get(output) >= itemCapacity //output full
|
||||
|| entity.heat <= minHeat //not burning
|
||||
|| entity.craftTime < craftTime){ //not yet time
|
||||
return;
|
||||
}
|
||||
|
||||
entity.craftTime = 0f;
|
||||
|
||||
for(ItemStack item : consumes.items()){
|
||||
entity.items.remove(item.item, item.amount);
|
||||
}
|
||||
|
||||
offloadNear(tile, output);
|
||||
Effects.effect(craftEffect, flameColor, tile.drawx(), tile.drawy());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean acceptItem(Item item, Tile tile, Tile source){
|
||||
|
||||
for(ItemStack stack : consumes.items()){
|
||||
if(stack.item == item){
|
||||
return tile.entity.items.get(item) < itemCapacity;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMaximumAccepted(Tile tile, Item item){
|
||||
return itemCapacity;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void draw(Tile tile){
|
||||
super.draw(tile);
|
||||
|
||||
PowerSmelterEntity entity = tile.entity();
|
||||
GenericCrafterEntity entity = tile.entity();
|
||||
|
||||
//draw glowing center
|
||||
if(entity.heat > 0f && flameColor.a > 0.001f){
|
||||
if(entity.warmup > 0f && flameColor.a > 0.001f){
|
||||
float g = 0.3f;
|
||||
float r = 0.06f;
|
||||
float cr = Mathf.random(0.1f);
|
||||
|
||||
Draw.alpha(((1f - g) + Mathf.absin(Time.time(), 8f, g) + Mathf.random(r) - r) * entity.heat);
|
||||
Draw.alpha(((1f - g) + Mathf.absin(Time.time(), 8f, g) + Mathf.random(r) - r) * entity.warmup);
|
||||
|
||||
Draw.tint(flameColor);
|
||||
Fill.circle(tile.drawx(), tile.drawy(), 3f + Mathf.absin(Time.time(), 5f, 2f) + cr);
|
||||
Draw.color(1f, 1f, 1f, entity.heat);
|
||||
Draw.color(1f, 1f, 1f, entity.warmup);
|
||||
Draw.rect(topRegion, tile.drawx(), tile.drawy());
|
||||
Fill.circle(tile.drawx(), tile.drawy(), 1.9f + Mathf.absin(Time.time(), 5f, 1f) + cr);
|
||||
|
||||
Draw.color();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public TileEntity newEntity(){
|
||||
return new PowerSmelterEntity();
|
||||
}
|
||||
|
||||
class PowerSmelterEntity extends TileEntity{
|
||||
public float heat;
|
||||
public float time;
|
||||
public float craftTime;
|
||||
|
||||
@Override
|
||||
public void write(DataOutput stream) throws IOException{
|
||||
stream.writeFloat(heat);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void read(DataInput stream) throws IOException{
|
||||
heat = stream.readFloat();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,148 +0,0 @@
|
||||
package io.anuke.mindustry.world.blocks.production;
|
||||
|
||||
import io.anuke.mindustry.entities.Effects;
|
||||
import io.anuke.mindustry.entities.Effects.Effect;
|
||||
import io.anuke.arc.graphics.Color;
|
||||
import io.anuke.arc.graphics.g2d.Draw;
|
||||
import io.anuke.arc.graphics.g2d.Fill;
|
||||
import io.anuke.arc.math.Mathf;
|
||||
import io.anuke.arc.util.Time;
|
||||
import io.anuke.mindustry.content.Fx;
|
||||
import io.anuke.mindustry.entities.type.TileEntity;
|
||||
import io.anuke.mindustry.type.Item;
|
||||
import io.anuke.mindustry.type.ItemStack;
|
||||
import io.anuke.mindustry.world.Block;
|
||||
import io.anuke.mindustry.world.Tile;
|
||||
import io.anuke.mindustry.world.consumers.ConsumeItem;
|
||||
import io.anuke.mindustry.world.consumers.ConsumeItems;
|
||||
import io.anuke.mindustry.world.meta.BlockStat;
|
||||
import io.anuke.mindustry.world.meta.StatUnit;
|
||||
|
||||
public class Smelter extends Block{
|
||||
protected final int timerDump = timers++;
|
||||
|
||||
protected Item result;
|
||||
|
||||
protected float craftTime = 20f;
|
||||
protected float burnDuration = 50f;
|
||||
protected Effect craftEffect = Fx.smelt, burnEffect = Fx.fuelburn;
|
||||
protected Color flameColor = Color.valueOf("ffb879");
|
||||
|
||||
public Smelter(String name){
|
||||
super(name);
|
||||
update = true;
|
||||
hasItems = true;
|
||||
solid = true;
|
||||
|
||||
consumes.require(ConsumeItems.class);
|
||||
consumes.require(ConsumeItem.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setStats(){
|
||||
super.setStats();
|
||||
|
||||
stats.add(BlockStat.fuelBurnTime, burnDuration / 60f, StatUnit.seconds);
|
||||
stats.add(BlockStat.outputItem, result);
|
||||
stats.add(BlockStat.craftSpeed, 60f / craftTime, StatUnit.itemsSecond);
|
||||
stats.add(BlockStat.inputItemCapacity, itemCapacity, StatUnit.items);
|
||||
stats.add(BlockStat.outputItemCapacity, itemCapacity, StatUnit.items);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void init(){
|
||||
super.init();
|
||||
produces.set(result);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update(Tile tile){
|
||||
SmelterEntity entity = tile.entity();
|
||||
|
||||
if(entity.timer.get(timerDump, 5) && entity.items.has(result)){
|
||||
tryDump(tile, result);
|
||||
}
|
||||
|
||||
//add fuel
|
||||
if(entity.consumed(ConsumeItem.class) && entity.burnTime <= 0f){
|
||||
entity.items.remove(consumes.item(), 1);
|
||||
entity.burnTime += burnDuration;
|
||||
Effects.effect(burnEffect, entity.x + Mathf.range(2f), entity.y + Mathf.range(2f));
|
||||
}
|
||||
|
||||
//decrement burntime
|
||||
if(entity.burnTime > 0){
|
||||
entity.burnTime -= entity.delta();
|
||||
entity.heat = Mathf.lerpDelta(entity.heat, 1f, 0.02f);
|
||||
}else{
|
||||
entity.heat = Mathf.lerpDelta(entity.heat, 0f, 0.02f);
|
||||
}
|
||||
|
||||
//make sure it has all the items
|
||||
if(!entity.cons.valid()){
|
||||
return;
|
||||
}
|
||||
|
||||
entity.craftTime += entity.delta();
|
||||
|
||||
if(entity.items.get(result) >= itemCapacity //output full
|
||||
|| entity.burnTime <= 0 //not burning
|
||||
|| entity.craftTime < craftTime){ //not yet time
|
||||
return;
|
||||
}
|
||||
|
||||
entity.craftTime = 0f;
|
||||
for(ItemStack item : consumes.items()){
|
||||
entity.items.remove(item.item, item.amount);
|
||||
}
|
||||
|
||||
offloadNear(tile, result);
|
||||
Effects.effect(craftEffect, flameColor, tile.drawx(), tile.drawy());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean acceptItem(Item item, Tile tile, Tile source){
|
||||
boolean isInput = false;
|
||||
|
||||
for(ItemStack req : consumes.items()){
|
||||
if(req.item == item){
|
||||
isInput = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return (isInput && tile.entity.items.get(item) < itemCapacity) || (item == consumes.item() && tile.entity.items.get(consumes.item()) < itemCapacity);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void draw(Tile tile){
|
||||
super.draw(tile);
|
||||
|
||||
SmelterEntity entity = tile.entity();
|
||||
|
||||
//draw glowing center
|
||||
if(entity.heat > 0f){
|
||||
float g = 0.1f;
|
||||
|
||||
Draw.alpha(((1f - g) + Mathf.absin(Time.time(), 8f, g)) * entity.heat);
|
||||
|
||||
Draw.tint(flameColor);
|
||||
Fill.circle(tile.drawx(), tile.drawy(), 2f + Mathf.absin(Time.time(), 5f, 0.8f));
|
||||
Draw.color(1f, 1f, 1f, entity.heat);
|
||||
Fill.circle(tile.drawx(), tile.drawy(), 1f + Mathf.absin(Time.time(), 5f, 0.7f));
|
||||
|
||||
Draw.color();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public TileEntity newEntity(){
|
||||
return new SmelterEntity();
|
||||
}
|
||||
|
||||
public class SmelterEntity extends TileEntity{
|
||||
public float burnTime;
|
||||
public float heat;
|
||||
public float craftTime;
|
||||
}
|
||||
}
|
@ -16,8 +16,6 @@ public enum BlockStat{
|
||||
launchTime(StatCategory.items),
|
||||
|
||||
liquidCapacity(StatCategory.liquids),
|
||||
liquidOutput(StatCategory.liquids),
|
||||
liquidOutputSpeed(StatCategory.liquids),
|
||||
coolant(StatCategory.liquids),
|
||||
coolantUse(StatCategory.liquids),
|
||||
|
||||
@ -32,12 +30,9 @@ public enum BlockStat{
|
||||
|
||||
inputLiquid(StatCategory.crafting),
|
||||
liquidUse(StatCategory.crafting),
|
||||
inputItem(StatCategory.crafting),
|
||||
inputItems(StatCategory.crafting),
|
||||
inputFuel(StatCategory.crafting),
|
||||
fuelBurnTime(StatCategory.crafting),
|
||||
craftSpeed(StatCategory.crafting),
|
||||
outputItem(StatCategory.crafting),
|
||||
input(StatCategory.crafting),
|
||||
output(StatCategory.crafting),
|
||||
productionTime(StatCategory.crafting),
|
||||
drillTier(StatCategory.crafting),
|
||||
drillSpeed(StatCategory.crafting),
|
||||
maxUnits(StatCategory.crafting),
|
||||
@ -53,8 +48,7 @@ public enum BlockStat{
|
||||
targetsGround(StatCategory.shooting),
|
||||
ammo(StatCategory.shooting),
|
||||
|
||||
boostItem(StatCategory.optional),
|
||||
boostLiquid(StatCategory.optional),
|
||||
booster(StatCategory.optional),
|
||||
|
||||
;
|
||||
|
||||
|
@ -5,6 +5,7 @@ import io.anuke.arc.collection.OrderedMap;
|
||||
import io.anuke.mindustry.type.Item;
|
||||
import io.anuke.mindustry.type.ItemStack;
|
||||
import io.anuke.mindustry.type.Liquid;
|
||||
import io.anuke.mindustry.type.LiquidStack;
|
||||
import io.anuke.mindustry.world.meta.values.*;
|
||||
|
||||
/**Hold and organizes a list of block stats.*/
|
||||
@ -37,6 +38,11 @@ public class BlockStats{
|
||||
add(stat, new ItemValue(item));
|
||||
}
|
||||
|
||||
/**Adds an item value.*/
|
||||
public void add(BlockStat stat, LiquidStack stack){
|
||||
add(stat, new LiquidValue(stack.liquid, stack.amount));
|
||||
}
|
||||
|
||||
/**Adds a single string value with this stat.*/
|
||||
public void add(BlockStat stat, String format, Object... args){
|
||||
add(stat, new StringValue(format, args));
|
||||
|
@ -8,9 +8,15 @@ import io.anuke.arc.scene.ui.layout.Table;
|
||||
|
||||
public class LiquidValue implements ContentStatValue{
|
||||
private final Liquid liquid;
|
||||
private final float amount;
|
||||
|
||||
public LiquidValue(Liquid liquid, float amount){
|
||||
this.liquid = liquid;
|
||||
this.amount = amount;
|
||||
}
|
||||
|
||||
public LiquidValue(Liquid liquid){
|
||||
this.liquid = liquid;
|
||||
this(liquid, 0f);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -20,6 +26,6 @@ public class LiquidValue implements ContentStatValue{
|
||||
|
||||
@Override
|
||||
public void display(Table table){
|
||||
table.add(new LiquidDisplay(liquid));
|
||||
table.add(new LiquidDisplay(liquid, amount));
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user