Added consumers for repair/resupply points

This commit is contained in:
Anuken
2018-07-10 18:57:50 -04:00
parent cb58eb82fc
commit bba418c79d
4 changed files with 22 additions and 11 deletions

View File

@@ -94,7 +94,7 @@ public class BlockConsumeFragment extends Fragment {
table.table("inventory", c::buildTooltip).visible(() -> hovered[0]).height(scale * 10 + 6).padBottom(-4).right().update(t -> { table.table("inventory", c::buildTooltip).visible(() -> hovered[0]).height(scale * 10 + 6).padBottom(-4).right().update(t -> {
if(t.getChildren().size == 0) t.remove(); if(t.getChildren().size == 0) t.remove();
}); }).get().act(0);
Table result = table.table(out -> { Table result = table.table(out -> {
out.addImage(c.getIcon()).size(10*scale).color(Color.DARK_GRAY).padRight(-10*scale).padBottom(-scale*2); out.addImage(c.getIcon()).size(10*scale).color(Color.DARK_GRAY).padRight(-10*scale).padBottom(-scale*2);

View File

@@ -22,6 +22,9 @@ import java.io.DataInputStream;
import java.io.DataOutputStream; import java.io.DataOutputStream;
import java.io.IOException; import java.io.IOException;
import static io.anuke.mindustry.Vars.control;
import static io.anuke.mindustry.Vars.headless;
public class GenericCrafter extends Block{ public class GenericCrafter extends Block{
protected final int timerDump = timers++; protected final int timerDump = timers++;
@@ -96,6 +99,12 @@ public class GenericCrafter extends Block{
if(entity.progress >= 1f){ if(entity.progress >= 1f){
if(consumes.has(ConsumeItem.class)) tile.entity.items.remove(consumes.item(), consumes.itemAmount()); if(consumes.has(ConsumeItem.class)) tile.entity.items.remove(consumes.item(), consumes.itemAmount());
//unlock output item
if(!headless){
control.database().unlockContent(output);
}
offloadNear(tile, output); offloadNear(tile, output);
Effects.effect(craftEffect, tile.drawx(), tile.drawy()); Effects.effect(craftEffect, tile.drawx(), tile.drawy());
entity.progress = 0f; entity.progress = 0f;

View File

@@ -26,7 +26,6 @@ public class RepairPoint extends Block{
protected float repairRadius = 50f; protected float repairRadius = 50f;
protected float repairSpeed = 0.3f; protected float repairSpeed = 0.3f;
protected float powerUsage = 0.2f;
protected TextureRegion topRegion; protected TextureRegion topRegion;
@@ -39,6 +38,7 @@ public class RepairPoint extends Block{
layer2 = Layer.laser; layer2 = Layer.laser;
hasPower = true; hasPower = true;
powerCapacity = 20f; powerCapacity = 20f;
consumes.power(0.06f);
} }
@Override @Override
@@ -92,10 +92,7 @@ public class RepairPoint extends Block{
entity.rotation = Mathf.slerpDelta(entity.rotation, entity.angleTo(entity.target), 0.5f); entity.rotation = Mathf.slerpDelta(entity.rotation, entity.angleTo(entity.target), 0.5f);
} }
float powerUse = Math.min(Timers.delta() * powerUsage, powerCapacity); if(entity.target != null && entity.cons.valid()){
if(entity.target != null && entity.power.amount >= powerUse){
entity.power.amount -= powerUse;
entity.strength = Mathf.lerpDelta(entity.strength, 1f, 0.08f * Timers.delta()); entity.strength = Mathf.lerpDelta(entity.strength, 1f, 0.08f * Timers.delta());
}else{ }else{
entity.strength = Mathf.lerpDelta(entity.strength, 0f, 0.07f * Timers.delta()); entity.strength = Mathf.lerpDelta(entity.strength, 0f, 0.07f * Timers.delta());
@@ -108,6 +105,13 @@ public class RepairPoint extends Block{
} }
} }
@Override
public boolean shouldConsume(Tile tile) {
RepairPointEntity entity = tile.entity();
return entity.target != null;
}
@Override @Override
public TileEntity getEntity() { public TileEntity getEntity() {
return new RepairPointEntity(); return new RepairPointEntity();

View File

@@ -27,7 +27,6 @@ public class ResupplyPoint extends Block{
protected float supplyRadius = 50f; protected float supplyRadius = 50f;
protected float supplyInterval = 10f; protected float supplyInterval = 10f;
protected float powerUsage = 0.2f;
public ResupplyPoint(String name) { public ResupplyPoint(String name) {
super(name); super(name);
@@ -38,6 +37,8 @@ public class ResupplyPoint extends Block{
hasItems = true; hasItems = true;
hasPower = true; hasPower = true;
powerCapacity = 20f; powerCapacity = 20f;
consumes.power(0.02f);
} }
@Override @Override
@@ -98,10 +99,7 @@ public class ResupplyPoint extends Block{
entity.rotation = Mathf.slerpDelta(entity.rotation, entity.angleTo(entity.target), 0.5f); entity.rotation = Mathf.slerpDelta(entity.rotation, entity.angleTo(entity.target), 0.5f);
} }
float powerUse = Math.min(Timers.delta() * powerUsage, powerCapacity); if(entity.target != null && entity.cons.valid()){
if(entity.target != null && entity.power.amount >= powerUse){
entity.power.amount -= powerUse;
entity.lastx = entity.target.x; entity.lastx = entity.target.x;
entity.lasty = entity.target.y; entity.lasty = entity.target.y;
entity.strength = Mathf.lerpDelta(entity.strength, 1f, 0.08f * Timers.delta()); entity.strength = Mathf.lerpDelta(entity.strength, 1f, 0.08f * Timers.delta());