Vault optimizations / Removed unloader
This commit is contained in:
@@ -47,7 +47,6 @@ public class Recipes implements ContentList{
|
||||
new Recipe(distribution, DistributionBlocks.splitter, new ItemStack(Items.lead, 6));
|
||||
|
||||
//advanced carbide transporation
|
||||
//new Recipe(distribution, DistributionBlocks.splitter, new ItemStack(Items.carbide, 2), new ItemStack(Items.tungsten, 2));
|
||||
new Recipe(distribution, DistributionBlocks.distributor, new ItemStack(Items.carbide, 8), new ItemStack(Items.tungsten, 8));
|
||||
new Recipe(distribution, DistributionBlocks.sorter, new ItemStack(Items.carbide, 4), new ItemStack(Items.tungsten, 4));
|
||||
new Recipe(distribution, DistributionBlocks.overflowGate, new ItemStack(Items.carbide, 4), new ItemStack(Items.tungsten, 8));
|
||||
@@ -105,8 +104,8 @@ public class Recipes implements ContentList{
|
||||
new Recipe(power, PowerBlocks.nuclearReactor, new ItemStack(Items.lead, 600), new ItemStack(Items.silicon, 400), new ItemStack(Items.carbide, 300), new ItemStack(Items.thorium, 300));
|
||||
|
||||
//new Recipe(distribution, StorageBlocks.core, new ItemStack(Items.carbide, 50));
|
||||
new Recipe(distribution, StorageBlocks.unloader, new ItemStack(Items.carbide, 40), new ItemStack(Items.silicon, 50));
|
||||
new Recipe(distribution, StorageBlocks.sortedunloader, new ItemStack(Items.carbide, 40), new ItemStack(Items.silicon, 70));
|
||||
//new Recipe(distribution, StorageBlocks.unloader, new ItemStack(Items.carbide, 40), new ItemStack(Items.silicon, 50));
|
||||
new Recipe(distribution, StorageBlocks.unloader, new ItemStack(Items.carbide, 40), new ItemStack(Items.silicon, 70));
|
||||
new Recipe(distribution, StorageBlocks.vault, new ItemStack(Items.carbide, 500), new ItemStack(Items.thorium, 350));
|
||||
|
||||
//DRILLS, PRODUCERS
|
||||
|
||||
@@ -4,11 +4,10 @@ import io.anuke.mindustry.type.ContentList;
|
||||
import io.anuke.mindustry.world.Block;
|
||||
import io.anuke.mindustry.world.blocks.storage.CoreBlock;
|
||||
import io.anuke.mindustry.world.blocks.storage.SortedUnloader;
|
||||
import io.anuke.mindustry.world.blocks.storage.Unloader;
|
||||
import io.anuke.mindustry.world.blocks.storage.Vault;
|
||||
|
||||
public class StorageBlocks extends BlockList implements ContentList{
|
||||
public static Block core, vault, unloader, sortedunloader;
|
||||
public static Block core, vault, unloader;
|
||||
|
||||
@Override
|
||||
public void load(){
|
||||
@@ -22,11 +21,7 @@ public class StorageBlocks extends BlockList implements ContentList{
|
||||
itemCapacity = 2000;
|
||||
}};
|
||||
|
||||
unloader = new Unloader("unloader"){{
|
||||
speed = 5;
|
||||
}};
|
||||
|
||||
sortedunloader = new SortedUnloader("sortedunloader"){{
|
||||
unloader = new SortedUnloader("unloader"){{
|
||||
speed = 5;
|
||||
}};
|
||||
}
|
||||
|
||||
@@ -259,12 +259,13 @@ public class TypeIO{
|
||||
|
||||
@WriteClass(Item.class)
|
||||
public static void writeItem(ByteBuffer buffer, Item item){
|
||||
buffer.put((byte) item.id);
|
||||
buffer.put(item == null ? -1 : (byte) item.id);
|
||||
}
|
||||
|
||||
@ReadClass(Item.class)
|
||||
public static Item readItem(ByteBuffer buffer){
|
||||
return Item.getByID(buffer.get());
|
||||
byte id = buffer.get();
|
||||
return id == -1 ? null : Item.getByID(id);
|
||||
}
|
||||
|
||||
@WriteClass(Recipe.class)
|
||||
|
||||
@@ -255,7 +255,7 @@ public abstract class BaseBlock{
|
||||
return false;
|
||||
}
|
||||
|
||||
private void incrementDump(Tile tile, int prox){
|
||||
protected void incrementDump(Tile tile, int prox){
|
||||
tile.setDump((byte) ((tile.getDump() + 1) % prox));
|
||||
}
|
||||
|
||||
|
||||
@@ -207,7 +207,7 @@ public class BuildBlock extends Block{
|
||||
builderID = builder.getID();
|
||||
}
|
||||
|
||||
if(progress >= 1f){
|
||||
if(progress >= 1f || debug){
|
||||
CallBlocks.onConstructFinish(tile, recipe.result, builderID, tile.getRotation(), tile.getTeam());
|
||||
}
|
||||
}
|
||||
@@ -233,7 +233,7 @@ public class BuildBlock extends Block{
|
||||
|
||||
progress = Mathf.clamp(progress - amount);
|
||||
|
||||
if(progress <= 0){
|
||||
if(progress <= 0 || debug){
|
||||
CallBlocks.onDeconstructFinish(tile, this.recipe == null ? previous : this.recipe.result);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
package io.anuke.mindustry.world.blocks;
|
||||
|
||||
import com.badlogic.gdx.graphics.g2d.TextureRegion;
|
||||
import com.badlogic.gdx.utils.Array;
|
||||
import io.anuke.mindustry.type.Item;
|
||||
import io.anuke.ucore.function.Consumer;
|
||||
import io.anuke.ucore.function.Supplier;
|
||||
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;
|
||||
@@ -15,22 +15,34 @@ import static io.anuke.mindustry.Vars.control;
|
||||
public interface SelectionTrait{
|
||||
|
||||
default void buildItemTable(Table table, Supplier<Item> holder, Consumer<Item> consumer){
|
||||
buildItemTable(table, false, holder, consumer);
|
||||
}
|
||||
|
||||
default void buildItemTable(Table table, boolean nullItem, Supplier<Item> holder, Consumer<Item> consumer){
|
||||
|
||||
Array<Item> items = Item.all();
|
||||
|
||||
ButtonGroup<ImageButton> group = new ButtonGroup<>();
|
||||
Table cont = new Table();
|
||||
cont.defaults().size(38, 42).padBottom(-5.1f);
|
||||
|
||||
int i = 0;
|
||||
|
||||
if(nullItem){
|
||||
ImageButton button = cont.addImageButton("white", "toggle", 24, () -> consumer.accept(null)).group(group).get();
|
||||
button.getStyle().imageUp = new TextureRegionDrawable(Draw.region("icon-nullitem"));
|
||||
button.setChecked(holder.get() == null);
|
||||
|
||||
i ++;
|
||||
}
|
||||
|
||||
for(Item item : items){
|
||||
if(!control.database().isUnlocked(item)) continue;
|
||||
|
||||
final int f = i;
|
||||
ImageButton button = cont.addImageButton("white", "toggle", 24, () -> consumer.accept(items.get(f)))
|
||||
.size(38, 42).padBottom(-5.1f).group(group).get();
|
||||
button.getStyle().imageUp = new TextureRegionDrawable(new TextureRegion(items.get(i).region));
|
||||
button.setChecked(holder.get().id == f);
|
||||
ImageButton button = cont.addImageButton("white", "toggle", 24, () -> consumer.accept(item))
|
||||
.group(group).get();
|
||||
button.getStyle().imageUp = new TextureRegionDrawable(item.region);
|
||||
button.setChecked(holder.get() == item);
|
||||
|
||||
if(i++ % 4 == 3){
|
||||
cont.row();
|
||||
|
||||
@@ -1,55 +0,0 @@
|
||||
package io.anuke.mindustry.world.blocks.distribution;
|
||||
|
||||
import io.anuke.mindustry.type.Item;
|
||||
import io.anuke.mindustry.world.Block;
|
||||
import io.anuke.mindustry.world.Tile;
|
||||
import io.anuke.mindustry.world.meta.BlockGroup;
|
||||
import io.anuke.ucore.core.Timers;
|
||||
|
||||
public class Router extends Block{
|
||||
|
||||
public Router(String name){
|
||||
super(name);
|
||||
update = true;
|
||||
solid = true;
|
||||
itemCapacity = 20;
|
||||
hasItems = true;
|
||||
group = BlockGroup.transportation;
|
||||
autoSleep = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update(Tile tile){
|
||||
int iterations = Math.max(1, (int) (Timers.delta() + 0.4f));
|
||||
boolean moved = tile.entity.items.total() > 0;
|
||||
|
||||
for(int i = 0; i < iterations; i++){
|
||||
if(tile.entity.items.total() > 0){
|
||||
tryDump(tile);
|
||||
moved = true;
|
||||
}
|
||||
}
|
||||
|
||||
if(!moved){
|
||||
tile.entity.sleep();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canDump(Tile tile, Tile to, Item item){
|
||||
return !(to.block() instanceof Router) || ((float) to.target().entity.items.total() / to.target().block().itemCapacity) < ((float) tile.entity.items.total() / to.target().block().itemCapacity);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleItem(Item item, Tile tile, Tile source){
|
||||
super.handleItem(item, tile, source);
|
||||
tile.entity.wakeUp();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean acceptItem(Item item, Tile tile, Tile source){
|
||||
int items = tile.entity.items.total();
|
||||
return items < itemCapacity;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
package io.anuke.mindustry.world.blocks.storage;
|
||||
|
||||
import com.badlogic.gdx.graphics.Color;
|
||||
import io.anuke.annotations.Annotations.Loc;
|
||||
import io.anuke.annotations.Annotations.Remote;
|
||||
import io.anuke.mindustry.content.Items;
|
||||
@@ -24,8 +25,6 @@ public class SortedUnloader extends Unloader implements SelectionTrait{
|
||||
configurable = true;
|
||||
}
|
||||
|
||||
//TODO call event
|
||||
|
||||
@Remote(targets = Loc.both, called = Loc.both, in = In.blocks, forward = true)
|
||||
public static void setSortedUnloaderItem(Player player, Tile tile, Item item){
|
||||
SortedUnloaderEntity entity = tile.entity();
|
||||
@@ -39,7 +38,7 @@ public class SortedUnloader extends Unloader implements SelectionTrait{
|
||||
if(entity.items.total() == 0 && entity.timer.get(timerUnload, speed)){
|
||||
tile.allNearby(other -> {
|
||||
if(other.block() instanceof StorageBlock && entity.items.total() == 0 &&
|
||||
((StorageBlock) other.block()).hasItem(other, entity.sortItem)){
|
||||
((entity.sortItem == null && other.entity.items.total() > 0) || ((StorageBlock) other.block()).hasItem(other, entity.sortItem))){
|
||||
offloadNear(tile, ((StorageBlock) other.block()).removeItem(other, entity.sortItem));
|
||||
}
|
||||
});
|
||||
@@ -56,7 +55,7 @@ public class SortedUnloader extends Unloader implements SelectionTrait{
|
||||
|
||||
SortedUnloaderEntity entity = tile.entity();
|
||||
|
||||
Draw.color(entity.sortItem.color);
|
||||
Draw.color(entity.sortItem == null ? Color.WHITE : entity.sortItem.color);
|
||||
Draw.rect("blank", tile.worldx(), tile.worldy(), 2f, 2f);
|
||||
Draw.color();
|
||||
}
|
||||
@@ -64,7 +63,7 @@ public class SortedUnloader extends Unloader implements SelectionTrait{
|
||||
@Override
|
||||
public void buildTable(Tile tile, Table table){
|
||||
SortedUnloaderEntity entity = tile.entity();
|
||||
buildItemTable(table, () -> entity.sortItem, item -> CallBlocks.setSortedUnloaderItem(null, tile, item));
|
||||
buildItemTable(table, true, () -> entity.sortItem, item -> CallBlocks.setSortedUnloaderItem(null, tile, item));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -73,16 +72,17 @@ public class SortedUnloader extends Unloader implements SelectionTrait{
|
||||
}
|
||||
|
||||
public static class SortedUnloaderEntity extends TileEntity{
|
||||
public Item sortItem = Items.tungsten;
|
||||
public Item sortItem = null;
|
||||
|
||||
@Override
|
||||
public void write(DataOutputStream stream) throws IOException{
|
||||
stream.writeByte(sortItem.id);
|
||||
stream.writeByte(sortItem == null ? -1 : sortItem.id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void read(DataInputStream stream) throws IOException{
|
||||
sortItem = Item.all().get(stream.readByte());
|
||||
byte id = stream.readByte();
|
||||
sortItem = id == -1 ? null : Item.all().get(id);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
package io.anuke.mindustry.world.blocks.storage;
|
||||
|
||||
import com.badlogic.gdx.utils.Array;
|
||||
import io.anuke.mindustry.entities.TileEntity;
|
||||
import io.anuke.mindustry.type.Item;
|
||||
import io.anuke.mindustry.world.Edges;
|
||||
import io.anuke.mindustry.world.Tile;
|
||||
import io.anuke.ucore.core.Timers;
|
||||
|
||||
@@ -34,12 +37,53 @@ public class Vault extends StorageBlock{
|
||||
return tile.entity.items.total() < itemCapacity;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean tryDump(Tile tile, Item todump){
|
||||
TileEntity entity = tile.entity;
|
||||
if(entity == null || !hasItems || tile.entity.items.total() == 0 || (todump != null && !entity.items.has(todump)))
|
||||
return false;
|
||||
|
||||
Array<Tile> proximity = entity.proximity();
|
||||
int dump = tile.getDump();
|
||||
|
||||
if(proximity.size == 0) return false;
|
||||
|
||||
for(int i = 0; i < proximity.size; i++){
|
||||
Tile other = proximity.get((i + dump) % proximity.size);
|
||||
Tile in = Edges.getFacingEdge(tile, other);
|
||||
|
||||
if(other == null || !(other.block() instanceof StorageBlock)) continue;
|
||||
|
||||
if(other.block() instanceof Vault){
|
||||
|
||||
for(int ii = 0; ii < Item.all().size; ii++){
|
||||
Item item = Item.getByID(ii);
|
||||
|
||||
if(entity.items.has(item) && other.block().acceptItem(item, other, in) && canDump(tile, other, item)){
|
||||
other.block().handleItem(item, other, in);
|
||||
tile.entity.items.remove(item, 1);
|
||||
incrementDump(tile, proximity.size);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}else{
|
||||
|
||||
if(other.block().acceptItem(todump, other, in) && canDump(tile, other, todump)){
|
||||
other.block().handleItem(todump, other, in);
|
||||
tile.entity.items.remove(todump, 1);
|
||||
incrementDump(tile, proximity.size);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
incrementDump(tile, proximity.size);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canDump(Tile tile, Tile to, Item item){
|
||||
to = to.target();
|
||||
if(!(to.block() instanceof StorageBlock)) return false;
|
||||
|
||||
return !(to.block() instanceof Vault) || (float) to.entity.items.total() / to.block().itemCapacity < (float) tile.entity.items.total() / itemCapacity;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user