Added sorted unloader and new block group system
This commit is contained in:
@@ -33,6 +33,7 @@ public class Recipes {
|
||||
new Recipe(distribution, DistributionBlocks.splitter, stack(Item.steel, 1)),
|
||||
new Recipe(distribution, DistributionBlocks.vault, stack(Item.steel, 50)),
|
||||
new Recipe(distribution, DistributionBlocks.unloader, stack(Item.steel, 5)),
|
||||
new Recipe(distribution, DistributionBlocks.sortedunloader, stack(Item.steel, 5)),
|
||||
|
||||
new Recipe(weapon, WeaponBlocks.doubleturret, stack(Item.stone, 7)),
|
||||
new Recipe(weapon, WeaponBlocks.gatlingturret, stack(Item.iron, 8), stack(Item.stone, 10)),
|
||||
|
||||
@@ -73,8 +73,6 @@ public class Block extends BaseBlock {
|
||||
public Liquid liquidDrop = null;
|
||||
/**multiblock size*/
|
||||
public int size = 1;
|
||||
/**Brief block description. Should be short enough fit in the place menu.*/
|
||||
public final String description;
|
||||
/**Detailed description of the block. Can be as long as necesary.*/
|
||||
public final String fullDescription;
|
||||
/**Whether to draw this block in the expanded draw range.*/
|
||||
@@ -89,6 +87,8 @@ public class Block extends BaseBlock {
|
||||
public boolean alwaysReplace = false;
|
||||
/**whether this block has instant transfer checking. used for calculations to prevent infinite loops.*/
|
||||
public boolean instantTransfer = false;
|
||||
/**The block group. Unless {@link #canReplace} is overriden, blocks in the same group can replace each other.*/
|
||||
public BlockGroup group = BlockGroup.none;
|
||||
/**list of displayed block status bars. Defaults to health bar.*/
|
||||
public BlockBars bars = new BlockBars();
|
||||
/**List of block stats.*/
|
||||
@@ -97,7 +97,6 @@ public class Block extends BaseBlock {
|
||||
public Block(String name) {
|
||||
this.name = name;
|
||||
this.formalName = Bundles.get("block." + name + ".name", name);
|
||||
this.description = Bundles.getOrNull("block." + name + ".description");
|
||||
this.fullDescription = Bundles.getOrNull("block." + name + ".fulldescription");
|
||||
this.solid = false;
|
||||
this.id = lastid++;
|
||||
@@ -129,6 +128,7 @@ public class Block extends BaseBlock {
|
||||
|
||||
public void setConfigure(Tile tile, byte data){
|
||||
if(Net.active()) NetEvents.handleBlockConfig(tile, data);
|
||||
configure(tile, data);
|
||||
}
|
||||
|
||||
public boolean isConfigurable(Tile tile){
|
||||
@@ -160,7 +160,7 @@ public class Block extends BaseBlock {
|
||||
}
|
||||
|
||||
public boolean canReplace(Block other){
|
||||
return false;
|
||||
return other != this && this.group != BlockGroup.none && other.group == this.group;
|
||||
}
|
||||
|
||||
public int handleDamage(Tile tile, int amount){
|
||||
|
||||
5
core/src/io/anuke/mindustry/world/BlockGroup.java
Normal file
5
core/src/io/anuke/mindustry/world/BlockGroup.java
Normal file
@@ -0,0 +1,5 @@
|
||||
package io.anuke.mindustry.world;
|
||||
|
||||
public enum BlockGroup {
|
||||
none, walls, turrets, transportation, power, liquids, drills;
|
||||
}
|
||||
@@ -14,9 +14,9 @@ public abstract class BaseBlock {
|
||||
public boolean hasPower;
|
||||
|
||||
public int itemCapacity;
|
||||
public float liquidCapacity;
|
||||
public float liquidCapacity = 10f;
|
||||
public float liquidFlowFactor = 4.9f;
|
||||
public float powerCapacity;
|
||||
public float powerCapacity = 10f;
|
||||
|
||||
public void handleItem(Item item, Tile tile, Tile source){
|
||||
tile.entity.inventory.addItem(item, 1);
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
package io.anuke.mindustry.world.blocks;
|
||||
|
||||
import io.anuke.mindustry.world.Block;
|
||||
import io.anuke.mindustry.world.blocks.types.LiquidBlock;
|
||||
import io.anuke.mindustry.world.blocks.types.distribution.*;
|
||||
import io.anuke.mindustry.world.blocks.types.storage.SortedUnloader;
|
||||
import io.anuke.mindustry.world.blocks.types.storage.Unloader;
|
||||
import io.anuke.mindustry.world.blocks.types.storage.Vault;
|
||||
|
||||
@@ -9,11 +11,11 @@ public class DistributionBlocks{
|
||||
|
||||
public static final Block
|
||||
|
||||
conduit = new Conduit("conduit"){{
|
||||
conduit = new LiquidBlock("conduit"){{
|
||||
health = 45;
|
||||
}},
|
||||
|
||||
pulseconduit = new Conduit("pulseconduit"){{
|
||||
pulseconduit = new LiquidBlock("pulseconduit"){{
|
||||
liquidCapacity = 16f;
|
||||
liquidFlowFactor = 4.9f;
|
||||
health = 65;
|
||||
@@ -51,6 +53,10 @@ public class DistributionBlocks{
|
||||
|
||||
unloader = new Unloader("unloader"){{
|
||||
|
||||
}},
|
||||
|
||||
sortedunloader = new SortedUnloader("sortedunloader"){{
|
||||
|
||||
}},
|
||||
|
||||
junction = new Junction("junction"){{
|
||||
|
||||
@@ -188,6 +188,7 @@ public class ProductionBlocks{
|
||||
drillTime = 240;
|
||||
size = 2;
|
||||
powerUse = 0.08f;
|
||||
hasPower = true;
|
||||
}
|
||||
},
|
||||
|
||||
@@ -196,6 +197,7 @@ public class ProductionBlocks{
|
||||
drillTime = 240;
|
||||
size = 3;
|
||||
powerUse = 0.32f;
|
||||
hasPower = true;
|
||||
}
|
||||
},
|
||||
|
||||
@@ -205,6 +207,8 @@ public class ProductionBlocks{
|
||||
drillTime = 240;
|
||||
size = 4;
|
||||
powerUse = 0.16f;
|
||||
hasLiquids = true;
|
||||
hasPower = true;
|
||||
}
|
||||
},
|
||||
|
||||
@@ -223,8 +227,10 @@ public class ProductionBlocks{
|
||||
result = Item.biomatter;
|
||||
inputLiquid = Liquid.water;
|
||||
liquidUse = 0.1f;
|
||||
drillTime = 50;
|
||||
drillTime = 300;
|
||||
size = 2;
|
||||
hasLiquids = true;
|
||||
hasPower = true;
|
||||
}
|
||||
},
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package io.anuke.mindustry.world.blocks.types;
|
||||
|
||||
import io.anuke.mindustry.world.Block;
|
||||
import io.anuke.mindustry.world.BlockGroup;
|
||||
import io.anuke.mindustry.world.Tile;
|
||||
import io.anuke.mindustry.world.blocks.types.modules.LiquidModule;
|
||||
import io.anuke.ucore.graphics.Draw;
|
||||
@@ -12,6 +13,8 @@ public class LiquidBlock extends Block{
|
||||
super(name);
|
||||
rotate = true;
|
||||
update = true;
|
||||
hasLiquids = true;
|
||||
group = BlockGroup.liquids;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -2,6 +2,7 @@ package io.anuke.mindustry.world.blocks.types;
|
||||
|
||||
import io.anuke.mindustry.entities.TileEntity;
|
||||
import io.anuke.mindustry.world.Block;
|
||||
import io.anuke.mindustry.world.BlockGroup;
|
||||
|
||||
public abstract class PowerBlock extends Block{
|
||||
public float powerCapacity = 10f;
|
||||
@@ -12,6 +13,7 @@ public abstract class PowerBlock extends Block{
|
||||
update = true;
|
||||
solid = true;
|
||||
hasPower = true;
|
||||
group = BlockGroup.power;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package io.anuke.mindustry.world.blocks.types;
|
||||
|
||||
import io.anuke.mindustry.world.Block;
|
||||
import io.anuke.mindustry.world.BlockGroup;
|
||||
|
||||
public class Wall extends Block{
|
||||
|
||||
@@ -8,10 +9,12 @@ public class Wall extends Block{
|
||||
super(name);
|
||||
solid = true;
|
||||
destructible = true;
|
||||
group = BlockGroup.walls;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean canReplace(Block other){
|
||||
return other instanceof Wall && health > other.health;
|
||||
return super.canReplace(other) && health > other.health;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -56,6 +56,7 @@ public class Turret extends Block{
|
||||
update = true;
|
||||
solid = true;
|
||||
layer = Layer.turret;
|
||||
group = BlockGroup.turrets;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -76,11 +77,6 @@ public class Turret extends Block{
|
||||
stats.add("shots", shots);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canReplace(Block other){
|
||||
return other instanceof Turret;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void draw(Tile tile){
|
||||
if(base == null) {
|
||||
|
||||
@@ -1,16 +0,0 @@
|
||||
package io.anuke.mindustry.world.blocks.types.distribution;
|
||||
|
||||
import io.anuke.mindustry.world.Block;
|
||||
import io.anuke.mindustry.world.blocks.types.LiquidBlock;
|
||||
|
||||
public class Conduit extends LiquidBlock {
|
||||
|
||||
public Conduit(String name) {
|
||||
super(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canReplace(Block other) {
|
||||
return other instanceof Conduit && other != this;
|
||||
}
|
||||
}
|
||||
@@ -4,6 +4,7 @@ import com.badlogic.gdx.utils.LongArray;
|
||||
import io.anuke.mindustry.entities.TileEntity;
|
||||
import io.anuke.mindustry.resource.Item;
|
||||
import io.anuke.mindustry.world.Block;
|
||||
import io.anuke.mindustry.world.BlockGroup;
|
||||
import io.anuke.mindustry.world.Layer;
|
||||
import io.anuke.mindustry.world.Tile;
|
||||
import io.anuke.ucore.core.Timers;
|
||||
@@ -38,6 +39,7 @@ public class Conveyor extends Block{
|
||||
rotate = true;
|
||||
update = true;
|
||||
layer = Layer.overlay;
|
||||
group = BlockGroup.transportation;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -46,11 +48,6 @@ public class Conveyor extends Block{
|
||||
stats.add("itemspeedsecond", Strings.toFixed(speed * 60, 1));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canReplace(Block other){
|
||||
return other instanceof Conveyor || other instanceof Router || other instanceof Junction;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void draw(Tile tile){
|
||||
byte rotation = tile.getRotation();
|
||||
|
||||
@@ -5,6 +5,7 @@ import com.badlogic.gdx.utils.NumberUtils;
|
||||
import io.anuke.mindustry.entities.TileEntity;
|
||||
import io.anuke.mindustry.resource.Item;
|
||||
import io.anuke.mindustry.world.Block;
|
||||
import io.anuke.mindustry.world.BlockGroup;
|
||||
import io.anuke.mindustry.world.Tile;
|
||||
import io.anuke.ucore.core.Timers;
|
||||
import io.anuke.ucore.function.Consumer;
|
||||
@@ -19,11 +20,7 @@ public class Junction extends Block{
|
||||
update = true;
|
||||
solid = true;
|
||||
instantTransfer = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canReplace(Block other){
|
||||
return other instanceof Conveyor || other instanceof Router;
|
||||
group = BlockGroup.transportation;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -6,7 +6,7 @@ import io.anuke.mindustry.world.blocks.types.LiquidBlock;
|
||||
import io.anuke.ucore.core.Timers;
|
||||
import io.anuke.ucore.graphics.Draw;
|
||||
|
||||
public class LiquidJunction extends Conduit{
|
||||
public class LiquidJunction extends LiquidBlock{
|
||||
|
||||
public LiquidJunction(String name) {
|
||||
super(name);
|
||||
|
||||
@@ -2,9 +2,10 @@ package io.anuke.mindustry.world.blocks.types.distribution;
|
||||
|
||||
import io.anuke.mindustry.resource.Liquid;
|
||||
import io.anuke.mindustry.world.Tile;
|
||||
import io.anuke.mindustry.world.blocks.types.LiquidBlock;
|
||||
import io.anuke.ucore.graphics.Draw;
|
||||
|
||||
public class LiquidRouter extends Conduit{
|
||||
public class LiquidRouter extends LiquidBlock{
|
||||
|
||||
public LiquidRouter(String name) {
|
||||
super(name);
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package io.anuke.mindustry.world.blocks.types.distribution;
|
||||
|
||||
import com.badlogic.gdx.graphics.Color;
|
||||
import io.anuke.mindustry.world.Block;
|
||||
import io.anuke.mindustry.world.Tile;
|
||||
import io.anuke.mindustry.world.blocks.types.generation.Generator;
|
||||
|
||||
@@ -17,11 +16,6 @@ public class PowerLaser extends Generator{
|
||||
health = 50;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canReplace(Block other) {
|
||||
return other instanceof PowerLaser && other != this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update(Tile tile){
|
||||
distributeLaserPower(tile);
|
||||
|
||||
@@ -2,6 +2,7 @@ package io.anuke.mindustry.world.blocks.types.distribution;
|
||||
|
||||
import io.anuke.mindustry.resource.Item;
|
||||
import io.anuke.mindustry.world.Block;
|
||||
import io.anuke.mindustry.world.BlockGroup;
|
||||
import io.anuke.mindustry.world.Tile;
|
||||
import io.anuke.ucore.core.Timers;
|
||||
|
||||
@@ -12,11 +13,7 @@ public class Router extends Block{
|
||||
update = true;
|
||||
solid = true;
|
||||
itemCapacity = 20;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canReplace(Block other){
|
||||
return other instanceof Junction || other instanceof Conveyor;
|
||||
group = BlockGroup.transportation;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -5,6 +5,7 @@ import com.badlogic.gdx.utils.Array;
|
||||
import io.anuke.mindustry.entities.TileEntity;
|
||||
import io.anuke.mindustry.resource.Item;
|
||||
import io.anuke.mindustry.world.Block;
|
||||
import io.anuke.mindustry.world.BlockGroup;
|
||||
import io.anuke.mindustry.world.Tile;
|
||||
import io.anuke.ucore.graphics.Draw;
|
||||
import io.anuke.ucore.scene.style.TextureRegionDrawable;
|
||||
@@ -25,6 +26,7 @@ public class Sorter extends Block{
|
||||
update = true;
|
||||
solid = true;
|
||||
instantTransfer = true;
|
||||
group = BlockGroup.transportation;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -38,11 +40,6 @@ public class Sorter extends Block{
|
||||
|
||||
Draw.rect(Tmp.tr1, tile.worldx(), tile.worldy(), 4f, 4f);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canReplace(Block other){
|
||||
return other instanceof Conveyor || other instanceof Router;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean acceptItem(Item item, Tile tile, Tile source){
|
||||
@@ -121,13 +118,12 @@ public class Sorter extends Block{
|
||||
cont.margin(4);
|
||||
cont.marginBottom(5);
|
||||
|
||||
cont.add().colspan(4).height(105f);
|
||||
cont.add().colspan(4).height(50f * (int)(items.size/4f + 1f));
|
||||
cont.row();
|
||||
|
||||
for(int i = 0; i < items.size; i ++){
|
||||
final int f = i;
|
||||
ImageButton button = cont.addImageButton("white", "toggle", 24, () -> {
|
||||
entity.sortItem = items.get(f);
|
||||
setConfigure(tile, (byte)f);
|
||||
}).size(38, 42).padBottom(-5.1f).group(group).get();
|
||||
button.getStyle().imageUp = new TextureRegionDrawable(new TextureRegion(items.get(i).region));
|
||||
|
||||
@@ -19,7 +19,6 @@ import io.anuke.ucore.util.Strings;
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.Arrays;
|
||||
|
||||
import static io.anuke.mindustry.Vars.syncBlockState;
|
||||
|
||||
@@ -56,7 +55,7 @@ public class Teleporter extends PowerBlock{
|
||||
TeleporterEntity entity = tile.entity();
|
||||
if(entity != null){
|
||||
entity.color = data;
|
||||
Arrays.fill(entity.inventory.items, 0);
|
||||
entity.inventory.clear();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -117,7 +116,6 @@ public class Teleporter extends PowerBlock{
|
||||
for(int i = 0; i < colors; i ++){
|
||||
final int f = i;
|
||||
ImageButton button = cont.addImageButton("white", "toggle", 24, () -> {
|
||||
entity.color = (byte)f;
|
||||
lastColor = (byte)f;
|
||||
setConfigure(tile, (byte)f);
|
||||
}).size(34, 38).padBottom(-5.1f).group(group).get();
|
||||
|
||||
@@ -2,9 +2,10 @@ package io.anuke.mindustry.world.blocks.types.distribution;
|
||||
|
||||
import io.anuke.mindustry.resource.Liquid;
|
||||
import io.anuke.mindustry.world.Tile;
|
||||
import io.anuke.mindustry.world.blocks.types.LiquidBlock;
|
||||
import io.anuke.ucore.graphics.Draw;
|
||||
|
||||
public class TunnelConduit extends Conduit {
|
||||
public class TunnelConduit extends LiquidBlock {
|
||||
protected int maxdist = 3;
|
||||
protected float speed = 53;
|
||||
|
||||
|
||||
@@ -5,6 +5,7 @@ import com.badlogic.gdx.utils.NumberUtils;
|
||||
import io.anuke.mindustry.entities.TileEntity;
|
||||
import io.anuke.mindustry.resource.Item;
|
||||
import io.anuke.mindustry.world.Block;
|
||||
import io.anuke.mindustry.world.BlockGroup;
|
||||
import io.anuke.mindustry.world.Tile;
|
||||
import io.anuke.ucore.core.Timers;
|
||||
import io.anuke.ucore.util.Bits;
|
||||
@@ -21,13 +22,9 @@ public class TunnelConveyor extends Block{
|
||||
solid = true;
|
||||
health = 70;
|
||||
instantTransfer = true;
|
||||
group = BlockGroup.transportation;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canReplace(Block other){
|
||||
return other instanceof Conveyor || other instanceof Router || other instanceof Junction;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void handleItem(Item item, Tile tile, Tile source){
|
||||
TunnelEntity entity = tile.entity();
|
||||
|
||||
@@ -6,6 +6,7 @@ import io.anuke.mindustry.world.blocks.types.BlockModule;
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.Arrays;
|
||||
|
||||
public class InventoryModule extends BlockModule{
|
||||
public int[] items = new int[Item.getAllItems().size];
|
||||
@@ -38,6 +39,10 @@ public class InventoryModule extends BlockModule{
|
||||
items[item.id] -= amount;
|
||||
}
|
||||
|
||||
public void clear(){
|
||||
Arrays.fill(items, 0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(DataOutputStream stream) throws IOException {
|
||||
byte amount = 0;
|
||||
|
||||
@@ -5,6 +5,7 @@ import io.anuke.mindustry.entities.TileEntity;
|
||||
import io.anuke.mindustry.graphics.Fx;
|
||||
import io.anuke.mindustry.resource.Item;
|
||||
import io.anuke.mindustry.world.Block;
|
||||
import io.anuke.mindustry.world.BlockGroup;
|
||||
import io.anuke.mindustry.world.Layer;
|
||||
import io.anuke.mindustry.world.Tile;
|
||||
import io.anuke.ucore.core.Effects;
|
||||
@@ -31,6 +32,7 @@ public class Drill extends Block{
|
||||
solid = true;
|
||||
layer = Layer.overlay;
|
||||
itemCapacity = 5;
|
||||
group = BlockGroup.drills;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package io.anuke.mindustry.world.blocks.types.production;
|
||||
|
||||
import io.anuke.mindustry.resource.Liquid;
|
||||
import io.anuke.mindustry.world.Block;
|
||||
import io.anuke.mindustry.world.BlockGroup;
|
||||
import io.anuke.mindustry.world.Layer;
|
||||
import io.anuke.mindustry.world.Tile;
|
||||
import io.anuke.mindustry.world.blocks.types.LiquidBlock;
|
||||
@@ -22,11 +22,7 @@ public class Pump extends LiquidBlock{
|
||||
solid = true;
|
||||
layer = Layer.overlay;
|
||||
liquidFlowFactor = 3f;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canReplace(Block other) {
|
||||
return other instanceof Pump && other != this;
|
||||
group = BlockGroup.liquids;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -58,7 +54,7 @@ public class Pump extends LiquidBlock{
|
||||
@Override
|
||||
public void drawLayer(Tile tile){
|
||||
Draw.colorl(0.85f + Mathf.absin(Timers.time(), 6f, 0.15f));
|
||||
Draw.rect("cross", tile.worldx(), tile.worldy());
|
||||
Draw.rect("cross-"+size, tile.worldx(), tile.worldy());
|
||||
Draw.color();
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
package io.anuke.mindustry.world.blocks.types.storage;
|
||||
|
||||
import io.anuke.mindustry.entities.TileEntity;
|
||||
import io.anuke.mindustry.net.Net;
|
||||
import io.anuke.mindustry.resource.Item;
|
||||
import io.anuke.mindustry.world.Tile;
|
||||
@@ -37,9 +36,9 @@ public class CoreBlock extends StorageBlock {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Item removeItem(Tile tile){
|
||||
public Item removeItem(Tile tile, Item item){
|
||||
for(int i = 0; i < state.inventory.getItems().length; i ++){
|
||||
if(state.inventory.getItems()[i] > 0){
|
||||
if(state.inventory.getItems()[i] > 0 && (item == null || item.id == i)){
|
||||
if(Net.server() || !Net.active()) state.inventory.getItems()[i] --;
|
||||
return Item.getByID(i);
|
||||
}
|
||||
@@ -48,10 +47,9 @@ public class CoreBlock extends StorageBlock {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasItem(Tile tile){
|
||||
TileEntity entity = tile.entity;
|
||||
public boolean hasItem(Tile tile, Item item){
|
||||
for(int i = 0; i < state.inventory.getItems().length; i ++){
|
||||
if(state.inventory.getItems()[i] > 0){
|
||||
if(state.inventory.getItems()[i] > 0 && (item == null || item.id == i)){
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,118 @@
|
||||
package io.anuke.mindustry.world.blocks.types.storage;
|
||||
|
||||
import com.badlogic.gdx.graphics.g2d.TextureRegion;
|
||||
import com.badlogic.gdx.utils.Array;
|
||||
import io.anuke.mindustry.entities.TileEntity;
|
||||
import io.anuke.mindustry.resource.Item;
|
||||
import io.anuke.mindustry.world.Tile;
|
||||
import io.anuke.ucore.graphics.Draw;
|
||||
import io.anuke.ucore.scene.style.TextureRegionDrawable;
|
||||
import io.anuke.ucore.scene.ui.ButtonGroup;
|
||||
import io.anuke.ucore.scene.ui.ImageButton;
|
||||
import io.anuke.ucore.scene.ui.layout.Table;
|
||||
import io.anuke.ucore.util.Tmp;
|
||||
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
public class SortedUnloader extends Unloader {
|
||||
|
||||
public SortedUnloader(String name){
|
||||
super(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update(Tile tile){
|
||||
SortedUnloaderEntity entity = tile.entity();
|
||||
|
||||
if(entity.inventory.totalItems() == 0 && entity.timer.get(timerUnload, 5)){
|
||||
tile.allNearby(other -> {
|
||||
if(other.block() instanceof StorageBlock && entity.inventory.totalItems() == 0 &&
|
||||
((StorageBlock)other.block()).hasItem(other, entity.sortItem)){
|
||||
offloadNear(tile, ((StorageBlock)other.block()).removeItem(other, entity.sortItem));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
if(entity.inventory.totalItems() > 0){
|
||||
tryDump(tile);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void draw(Tile tile){
|
||||
super.draw(tile);
|
||||
|
||||
SortedUnloaderEntity entity = tile.entity();
|
||||
|
||||
TextureRegion region = entity.sortItem.region;
|
||||
Tmp.tr1.setRegion(region, 4, 4, 1, 1);
|
||||
|
||||
Draw.rect(Tmp.tr1, tile.worldx(), tile.worldy(), 2f, 2f);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isConfigurable(Tile tile){
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void configure(Tile tile, byte data) {
|
||||
SortedUnloaderEntity entity = tile.entity();
|
||||
if(entity != null){
|
||||
entity.sortItem = Item.getByID(data);
|
||||
entity.inventory.clear();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void buildTable(Tile tile, Table table){
|
||||
SortedUnloaderEntity entity = tile.entity();
|
||||
|
||||
Array<Item> items = Item.getAllItems();
|
||||
|
||||
ButtonGroup<ImageButton> group = new ButtonGroup<>();
|
||||
Table cont = new Table();
|
||||
cont.margin(4);
|
||||
cont.marginBottom(5);
|
||||
|
||||
cont.add().colspan(4).height(50f * (int)(items.size/4f + 1f));
|
||||
cont.row();
|
||||
|
||||
for(int i = 0; i < items.size; i ++){
|
||||
|
||||
final int f = i;
|
||||
ImageButton button = cont.addImageButton("white", "toggle", 24, () -> {
|
||||
setConfigure(tile, (byte)f);
|
||||
}).size(38, 42).padBottom(-5.1f).group(group).get();
|
||||
button.getStyle().imageUp = new TextureRegionDrawable(new TextureRegion(items.get(i).region));
|
||||
button.setChecked(entity.sortItem.id == f);
|
||||
|
||||
if(i%4 == 3){
|
||||
cont.row();
|
||||
}
|
||||
}
|
||||
|
||||
table.add(cont);
|
||||
}
|
||||
|
||||
@Override
|
||||
public TileEntity getEntity(){
|
||||
return new SortedUnloaderEntity();
|
||||
}
|
||||
|
||||
public static class SortedUnloaderEntity extends TileEntity{
|
||||
public Item sortItem = Item.iron;
|
||||
|
||||
@Override
|
||||
public void write(DataOutputStream stream) throws IOException {
|
||||
stream.writeByte(sortItem.id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void read(DataInputStream stream) throws IOException{
|
||||
sortItem = Item.getAllItems().get(stream.readByte());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -11,11 +11,12 @@ public abstract class StorageBlock extends Block {
|
||||
super(name);
|
||||
}
|
||||
|
||||
/**Removes any one item and returns it. Returns null if no items are there.*/
|
||||
public Item removeItem(Tile tile){
|
||||
/**Removes an item and returns it. If item is not null, it should return the item.
|
||||
* Returns null if no items are there.*/
|
||||
public Item removeItem(Tile tile, Item item){
|
||||
TileEntity entity = tile.entity;
|
||||
for(int i = 0; i < entity.inventory.items.length; i ++){
|
||||
if(entity.inventory.items[i] > 0){
|
||||
if(entity.inventory.items[i] > 0 && (item == null || i == item.id)){
|
||||
entity.inventory.items[i] --;
|
||||
return Item.getByID(i);
|
||||
}
|
||||
@@ -23,10 +24,12 @@ public abstract class StorageBlock extends Block {
|
||||
return null;
|
||||
}
|
||||
|
||||
public boolean hasItem(Tile tile){
|
||||
/**Returns whether this storage block has the specified item.
|
||||
* If the item is null, it should return whether it has ANY items.*/
|
||||
public boolean hasItem(Tile tile, Item item){
|
||||
TileEntity entity = tile.entity;
|
||||
for(int i = 0; i < entity.inventory.items.length; i ++){
|
||||
if(entity.inventory.items[i] > 0){
|
||||
if(entity.inventory.items[i] > 0 && (item == null || i == item.id)){
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ package io.anuke.mindustry.world.blocks.types.storage;
|
||||
|
||||
import io.anuke.mindustry.resource.Item;
|
||||
import io.anuke.mindustry.world.Block;
|
||||
import io.anuke.mindustry.world.BlockGroup;
|
||||
import io.anuke.mindustry.world.Tile;
|
||||
|
||||
public class Unloader extends Block {
|
||||
@@ -12,6 +13,7 @@ public class Unloader extends Block {
|
||||
update = true;
|
||||
solid = true;
|
||||
health = 70;
|
||||
group = BlockGroup.transportation;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -19,8 +21,8 @@ public class Unloader extends Block {
|
||||
if(tile.entity.inventory.totalItems() == 0 && tile.entity.timer.get(timerUnload, 5)){
|
||||
tile.allNearby(other -> {
|
||||
if(other.block() instanceof StorageBlock && tile.entity.inventory.totalItems() == 0 &&
|
||||
((StorageBlock)other.block()).hasItem(other)){
|
||||
offloadNear(tile, ((StorageBlock)other.block()).removeItem(other));
|
||||
((StorageBlock)other.block()).hasItem(other, null)){
|
||||
offloadNear(tile, ((StorageBlock)other.block()).removeItem(other, null));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user