From 8f31d19e90b75462ae48ef5374b810e04ec8abc1 Mon Sep 17 00:00:00 2001 From: Anuken Date: Sat, 3 Feb 2018 23:27:01 -0500 Subject: [PATCH] Fixed bugs with desynced block events --- core/src/io/anuke/mindustry/core/NetClient.java | 3 +++ core/src/io/anuke/mindustry/graphics/Fx.java | 6 ++++++ core/src/io/anuke/mindustry/net/Net.java | 12 ++++++++---- .../anuke/mindustry/ui/fragments/DebugFragment.java | 5 ++--- core/src/io/anuke/mindustry/world/Block.java | 5 ++++- .../world/blocks/types/production/Smelter.java | 2 ++ 6 files changed, 25 insertions(+), 8 deletions(-) diff --git a/core/src/io/anuke/mindustry/core/NetClient.java b/core/src/io/anuke/mindustry/core/NetClient.java index 1c56ad2b8e..39078cd2aa 100644 --- a/core/src/io/anuke/mindustry/core/NetClient.java +++ b/core/src/io/anuke/mindustry/core/NetClient.java @@ -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); }); } diff --git a/core/src/io/anuke/mindustry/graphics/Fx.java b/core/src/io/anuke/mindustry/graphics/Fx.java index 179eb02676..5616176b28 100644 --- a/core/src/io/anuke/mindustry/graphics/Fx.java +++ b/core/src/io/anuke/mindustry/graphics/Fx.java @@ -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(); }); } diff --git a/core/src/io/anuke/mindustry/net/Net.java b/core/src/io/anuke/mindustry/net/Net.java index 65da4b6d3d..7b7d0010af 100644 --- a/core/src/io/anuke/mindustry/net/Net.java +++ b/core/src/io/anuke/mindustry/net/Net.java @@ -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*/ diff --git a/core/src/io/anuke/mindustry/ui/fragments/DebugFragment.java b/core/src/io/anuke/mindustry/ui/fragments/DebugFragment.java index 278a9604bb..ddb8aec8b7 100644 --- a/core/src/io/anuke/mindustry/ui/fragments/DebugFragment.java +++ b/core/src/io/anuke/mindustry/ui/fragments/DebugFragment.java @@ -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(); diff --git a/core/src/io/anuke/mindustry/world/Block.java b/core/src/io/anuke/mindustry/world/Block.java index 0a08e157b5..8d140696eb 100644 --- a/core/src/io/anuke/mindustry/world/Block.java +++ b/core/src/io/anuke/mindustry/world/Block.java @@ -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); diff --git a/core/src/io/anuke/mindustry/world/blocks/types/production/Smelter.java b/core/src/io/anuke/mindustry/world/blocks/types/production/Smelter.java index b00b4465e6..581f9414c3 100644 --- a/core/src/io/anuke/mindustry/world/blocks/types/production/Smelter.java +++ b/core/src/io/anuke/mindustry/world/blocks/types/production/Smelter.java @@ -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