Added overflow gate block

This commit is contained in:
Anuken
2018-04-10 21:30:24 -04:00
parent 5b11875a5a
commit 25778a143c
8 changed files with 155 additions and 88 deletions

View File

@@ -35,6 +35,7 @@ public class Recipes {
new Recipe(distribution, DistributionBlocks.tunnel, stack(Items.iron, 2)),
new Recipe(distribution, DistributionBlocks.sorter, stack(Items.steel, 2)),
new Recipe(distribution, DistributionBlocks.splitter, stack(Items.steel, 1)),
new Recipe(distribution, DistributionBlocks.overflowgate, stack(Items.steel, 1)),
new Recipe(distribution, StorageBlocks.vault, stack(Items.steel, 50)),
new Recipe(distribution, StorageBlocks.core, stack(Items.steel, 50)),
new Recipe(distribution, StorageBlocks.unloader, stack(Items.steel, 5)),

View File

@@ -44,5 +44,7 @@ public class DistributionBlocks{
sorter = new Sorter("sorter"),
splitter = new Splitter("splitter");
splitter = new Splitter("splitter"),
overflowgate = new OverflowGate("overflowgate");
}

View File

@@ -21,8 +21,9 @@ import static io.anuke.mindustry.Vars.tilesize;
import static io.anuke.mindustry.Vars.world;
public class ItemBridge extends Block {
protected int timerTransport = timers++;
protected static int lastPlaced;
protected int timerTransport = timers++;
protected int range;
protected float powerUse = 0.05f;
protected float transportTime = 2f;
@@ -37,6 +38,15 @@ public class ItemBridge extends Block {
itemCapacity = 30;
}
@Override
public void placed(Tile tile) {
if(linkValid(tile, world.tile(lastPlaced))){
ItemBridgeEntity entity = tile.entity();
entity.link = lastPlaced;
}
lastPlaced = tile.packedPosition();
}
@Override
public boolean isConfigurable(Tile tile) {
return true;
@@ -111,9 +121,9 @@ public class ItemBridge extends Block {
}else{
float use = Math.min(powerCapacity, powerUse * Timers.delta());
if(entity.power.amount >= use){
if(!hasPower || entity.power.amount >= use){
entity.uptime = Mathf.lerpDelta(entity.uptime, 1f, 0.04f);
entity.power.amount -= use;
if(hasPower) entity.power.amount -= use;
}else{
entity.uptime = Mathf.lerpDelta(entity.uptime, 0f, 0.02f);
}
@@ -190,7 +200,7 @@ public class ItemBridge extends Block {
return false;
}
return other.block() instanceof ItemBridge && other.<ItemBridgeEntity>entity().link != tile.packedPosition();
return other.block() == this && other.<ItemBridgeEntity>entity().link != tile.packedPosition();
}
public static class ItemBridgeEntity extends TileEntity{

View File

@@ -0,0 +1,47 @@
package io.anuke.mindustry.world.blocks.types.distribution;
import io.anuke.mindustry.resource.Item;
import io.anuke.mindustry.world.Tile;
import io.anuke.ucore.util.Mathf;
public class OverflowGate extends Splitter {
public OverflowGate(String name) {
super(name);
}
@Override
Tile getTileTarget(Item item, Tile dest, Tile source, boolean flip){
int dir = source.relativeTo(dest.x, dest.y);
if(dir == -1) return null;
Tile to = dest.getNearby(dir);
if(!(to.block().acceptItem(item, to, dest) &&
!(to.block().instantTransfer && source.block().instantTransfer))){
Tile a = dest.getNearby(Mathf.mod(dir - 1, 4));
Tile b = dest.getNearby(Mathf.mod(dir + 1, 4));
boolean ac = !(a.block().instantTransfer && source.block().instantTransfer) &&
a.block().acceptItem(item, a, dest);
boolean bc = !(b.block().instantTransfer && source.block().instantTransfer) &&
b.block().acceptItem(item, b, dest);
if(ac && !bc){
to = a;
}else if(bc && !ac){
to = b;
}else{
if(dest.getDump() == 0){
to = a;
if(flip)
dest.setDump((byte)1);
}else{
to = b;
if(flip)
dest.setDump((byte)0);
}
}
}
return to;
}
}