Changed teleporter validity system

This commit is contained in:
Anuken
2018-02-15 19:22:39 -05:00
parent 71ce6d0bec
commit b70f5b82ee
4 changed files with 18 additions and 21 deletions

View File

@@ -1,7 +1,7 @@
#Autogenerated file. Do not modify. #Autogenerated file. Do not modify.
#Thu Feb 15 18:00:20 EST 2018 #Thu Feb 15 19:14:34 EST 2018
version=beta version=beta
androidBuildCode=228 androidBuildCode=230
name=Mindustry name=Mindustry
code=3.3 code=3.3
build=22 build=22

View File

@@ -279,9 +279,6 @@ public class NetClient extends Module {
Tile next = tile.getNearby(packet.rotation); Tile next = tile.getNearby(packet.rotation);
tile.entity.items[packet.itemid] --; tile.entity.items[packet.itemid] --;
next.block().handleItem(Item.getByID(packet.itemid), next, tile); next.block().handleItem(Item.getByID(packet.itemid), next, tile);
//if(tile.block() instanceof Teleporter)
// Log.info("Recieved dump for teleporter! items: {0}", tile.entity.totalItems());
}; };
if(threads.isEnabled()){ if(threads.isEnabled()){

View File

@@ -179,7 +179,7 @@ public class Block{
/** /**
* Tries to put this item into a nearby container, if there are no available * Tries to put this item into a nearby container, if there are no available
* containers, it gets added to the block's inventory.*/ * containers, it gets added to the block's inventory.*/
protected void offloadNear(Tile tile, Item item){ public void offloadNear(Tile tile, Item item){
if(Net.client()){ if(Net.client()){
handleItem(item, tile, tile); handleItem(item, tile, tile);
return; return;

View File

@@ -5,9 +5,7 @@ import com.badlogic.gdx.utils.Array;
import com.badlogic.gdx.utils.ObjectSet; import com.badlogic.gdx.utils.ObjectSet;
import io.anuke.mindustry.entities.TileEntity; import io.anuke.mindustry.entities.TileEntity;
import io.anuke.mindustry.net.Net; import io.anuke.mindustry.net.Net;
import io.anuke.mindustry.net.NetEvents;
import io.anuke.mindustry.resource.Item; import io.anuke.mindustry.resource.Item;
import io.anuke.mindustry.world.BlockBar;
import io.anuke.mindustry.world.Tile; import io.anuke.mindustry.world.Tile;
import io.anuke.mindustry.world.blocks.types.PowerBlock; import io.anuke.mindustry.world.blocks.types.PowerBlock;
import io.anuke.ucore.core.Timers; import io.anuke.ucore.core.Timers;
@@ -47,8 +45,6 @@ public class Teleporter extends PowerBlock{
solid = true; solid = true;
health = 80; health = 80;
powerCapacity = 30f; powerCapacity = 30f;
bars.add(new BlockBar(Color.RED, true, tile -> tile.entity.totalItems() / 4f));
} }
@Override @Override
@@ -90,10 +86,6 @@ public class Teleporter extends PowerBlock{
TeleporterEntity entity = tile.entity(); TeleporterEntity entity = tile.entity();
teleporters[entity.color].add(tile); teleporters[entity.color].add(tile);
if(entity.totalItems() > 0){
tryDump(tile);
}
} }
@Override @Override
@@ -135,14 +127,12 @@ public class Teleporter extends PowerBlock{
public void handleItem(Item item, Tile tile, Tile source){ public void handleItem(Item item, Tile tile, Tile source){
PowerEntity entity = tile.entity(); PowerEntity entity = tile.entity();
Array<Tile> links = findLinks(tile); Array<Tile> links = findLinks(tile, item);
if(links.size > 0){ if(links.size > 0){
if(Net.server() || !Net.active()){ if(Net.server() || !Net.active()){
Tile target = links.random(); Tile target = links.random();
target.entity.addItem(item, 1); target.block().offloadNear(target, item);
if(Net.server()) NetEvents.handleItemSet(target, item, (byte)1);
} }
} }
@@ -152,7 +142,7 @@ public class Teleporter extends PowerBlock{
@Override @Override
public boolean acceptItem(Item item, Tile tile, Tile source){ public boolean acceptItem(Item item, Tile tile, Tile source){
PowerEntity entity = tile.entity(); PowerEntity entity = tile.entity();
return entity.power >= powerPerItem && findLinks(tile).size > 0; return entity.power >= powerPerItem && findLinks(tile, item).size > 0;
} }
@Override @Override
@@ -160,7 +150,17 @@ public class Teleporter extends PowerBlock{
return new TeleporterEntity(); return new TeleporterEntity();
} }
private Array<Tile> findLinks(Tile tile){ public boolean available(Tile tile, Item item){
for(int i = 0; i < 4; i ++){
Tile next = tile.getNearby(i);
if(next != null && next.block().acceptItem(item, next, tile)){
return true;
}
}
return false;
}
private Array<Tile> findLinks(Tile tile, Item output){
TeleporterEntity entity = tile.entity(); TeleporterEntity entity = tile.entity();
removal.clear(); removal.clear();
@@ -171,7 +171,7 @@ public class Teleporter extends PowerBlock{
if(other.block() instanceof Teleporter){ if(other.block() instanceof Teleporter){
if(other.<TeleporterEntity>entity().color != entity.color){ if(other.<TeleporterEntity>entity().color != entity.color){
removal.add(other); removal.add(other);
}else if(other.entity.totalItems() <= 0){ }else if(((Teleporter)other.block()).available(other, output)){
returns.add(other); returns.add(other);
} }
}else{ }else{