Fixed bugs with desynced block events

This commit is contained in:
Anuken
2018-02-03 23:27:01 -05:00
parent 2ba38c2ee3
commit 8f31d19e90
6 changed files with 25 additions and 8 deletions

View File

@ -10,6 +10,7 @@ import io.anuke.mindustry.entities.BulletType;
import io.anuke.mindustry.entities.Player;
import io.anuke.mindustry.entities.SyncEntity;
import io.anuke.mindustry.entities.enemies.Enemy;
import io.anuke.mindustry.graphics.Fx;
import io.anuke.mindustry.io.Platform;
import io.anuke.mindustry.net.Net;
import io.anuke.mindustry.net.Net.SendMode;
@ -19,6 +20,7 @@ import io.anuke.mindustry.resource.Item;
import io.anuke.mindustry.world.Map;
import io.anuke.mindustry.world.Tile;
import io.anuke.mindustry.world.blocks.ProductionBlocks;
import io.anuke.ucore.core.Effects;
import io.anuke.ucore.core.Timers;
import io.anuke.ucore.entities.BaseBulletType;
import io.anuke.ucore.entities.Entities;
@ -273,6 +275,7 @@ public class NetClient extends Module {
Tile next = tile.getNearby(packet.rotation);
tile.entity.items[packet.itemid] --;
next.block().handleItem(Item.getByID(packet.itemid), next, tile);
Effects.effect(Fx.transfer, tile.drawx(), tile.drawy(), packet.rotation * 90);
});
}

View File

@ -510,5 +510,11 @@ public class Fx{
Draw.text("Respawning in " + (int)((e.lifetime-e.time)/60), e.x, e.y);
Draw.tscl(0.5f);
Draw.reset();
}),
transfer = new Effect(20, e -> {
Draw.color(Color.SCARLET, Color.CLEAR, e.fract());
Lines.square(e.x, e.y, 4);
Lines.lineAngle(e.x, e.y, e.rotation, 5f);
Draw.reset();
});
}

View File

@ -65,11 +65,15 @@ public class Net{
/**Connect to an address.*/
public static void connect(String ip, int port) throws IOException{
clientProvider.connect(ip, port);
active = true;
server = false;
if(!active) {
clientProvider.connect(ip, port);
active = true;
server = false;
Timers.runTask(60f, Platform.instance::updateRPC);
Timers.runTask(60f, Platform.instance::updateRPC);
}else{
throw new IOException("Already connected!");
}
}
/**Host a server at an address*/

View File

@ -2,9 +2,8 @@ package io.anuke.mindustry.ui.fragments;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.files.FileHandle;
import io.anuke.mindustry.Vars;
import io.anuke.mindustry.entities.Player;
import io.anuke.mindustry.entities.enemies.Enemy;
import io.anuke.mindustry.entities.enemies.EnemyTypes;
import io.anuke.mindustry.net.Net;
import io.anuke.ucore.scene.builders.button;
import io.anuke.ucore.scene.builders.label;
@ -59,7 +58,7 @@ public class DebugFragment implements Fragment {
netClient.clearRecieved();
});
row();
new button("spawn", () -> new Enemy(EnemyTypes.standard).set(player.x, player.y).add());
new button("spawn", () -> {try{ Net.connect("localhost", Vars.port); }catch (Exception e){e.printStackTrace();}});
row();
new button("stuff", () -> netClient.test());
row();

View File

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

View File

@ -43,6 +43,8 @@ public class Smelter extends Block{
final Item item = inputs[i];
bars.add(new BlockBar(Color.GREEN, true, tile -> (float)tile.entity.getItem(item)/capacity));
}
//bars.add(new BlockBar(Color.ORANGE, true, tile -> (float)tile.entity.getItem(fuel)/capacity));
//bars.add(new BlockBar(Color.LIGHT_GRAY, true, tile -> (float)tile.entity.getItem(result)/capacity));
}
@Override