diff --git a/core/src/io/anuke/mindustry/input/InputHandler.java b/core/src/io/anuke/mindustry/input/InputHandler.java index 4957b8fc42..e010a699fc 100644 --- a/core/src/io/anuke/mindustry/input/InputHandler.java +++ b/core/src/io/anuke/mindustry/input/InputHandler.java @@ -125,7 +125,7 @@ public abstract class InputHandler extends InputAdapter{ //consume tap event if necessary if(tile.getTeam() == player.getTeam() && tile.block().consumesTap){ consumed = true; - }else if(tile.getTeam() == player.getTeam() && tile.block().synthetic() && tile.block().hasItems){ + }else if(tile.getTeam() == player.getTeam() && tile.block().synthetic() && tile.block().hasItems && !consumed){ frag.inv.showFor(tile); consumed = true; showedInventory = true; diff --git a/core/src/io/anuke/mindustry/world/Block.java b/core/src/io/anuke/mindustry/world/Block.java index e51c1aeb51..f848408578 100644 --- a/core/src/io/anuke/mindustry/world/Block.java +++ b/core/src/io/anuke/mindustry/world/Block.java @@ -185,7 +185,7 @@ public class Block extends BaseBlock implements UnlockableContent{ /**Returns whether or not a hand cursor should be shown over this block.*/ public CursorType getCursor(Tile tile){ - return configurable ? CursorType.normal : CursorType.hand; + return configurable ? CursorType.hand : CursorType.normal; } /**Called when this block is tapped to build a UI on the table. diff --git a/core/src/io/anuke/mindustry/world/blocks/distribution/ItemBridge.java b/core/src/io/anuke/mindustry/world/blocks/distribution/ItemBridge.java index e31a6ac838..2c42f3f025 100644 --- a/core/src/io/anuke/mindustry/world/blocks/distribution/ItemBridge.java +++ b/core/src/io/anuke/mindustry/world/blocks/distribution/ItemBridge.java @@ -4,9 +4,14 @@ import com.badlogic.gdx.graphics.Color; import com.badlogic.gdx.utils.IntArray; import com.badlogic.gdx.utils.IntSet; import com.badlogic.gdx.utils.IntSet.IntSetIterator; +import io.anuke.annotations.Annotations.Loc; +import io.anuke.annotations.Annotations.Remote; +import io.anuke.mindustry.entities.Player; import io.anuke.mindustry.entities.TileEntity; +import io.anuke.mindustry.gen.CallBlocks; import io.anuke.mindustry.graphics.Layer; import io.anuke.mindustry.graphics.Palette; +import io.anuke.mindustry.net.In; import io.anuke.mindustry.type.Item; import io.anuke.mindustry.world.Block; import io.anuke.mindustry.world.Tile; @@ -50,7 +55,7 @@ public class ItemBridge extends Block { if(linkValid(tile, last)){ ItemBridgeEntity entity = last.entity(); if(!linkValid(last, world.tile(entity.link))){ - link(last, tile); + CallBlocks.linkItemBridge(null, last, tile); } } lastPlaced = tile.packedPosition(); @@ -103,9 +108,9 @@ public class ItemBridge extends Block { if(linkValid(tile, other)){ if(entity.link == other.packedPosition()){ - unlink(tile, other); + CallBlocks.unlinkItemBridge(null, tile, other); }else{ - link(tile, other); + CallBlocks.linkItemBridge(null, tile, other); } return false; } @@ -243,22 +248,6 @@ public class ItemBridge extends Block { return new ItemBridgeEntity(); } - public void link(Tile tile, Tile other){ - ItemBridgeEntity entity = tile.entity(); - ItemBridgeEntity oe = other.entity(); - entity.link = other.packedPosition(); - oe.incoming.add(tile.packedPosition()); - } - - public void unlink(Tile tile, Tile other){ - ItemBridgeEntity entity = tile.entity(); - entity.link = -1; - if(other != null) { - ItemBridgeEntity oe = other.entity(); - oe.incoming.remove(tile.packedPosition()); - } - } - public boolean linkValid(Tile tile, Tile other){ return linkValid(tile, other, true); } @@ -276,6 +265,24 @@ public class ItemBridge extends Block { return other.block() == this && (!checkDouble || other.entity().link != tile.packedPosition()); } + @Remote(targets = Loc.both, called = Loc.both, in = In.blocks, forward = true) + public static void linkItemBridge(Player player, Tile tile, Tile other){ + ItemBridgeEntity entity = tile.entity(); + ItemBridgeEntity oe = other.entity(); + entity.link = other.packedPosition(); + oe.incoming.add(tile.packedPosition()); + } + + @Remote(targets = Loc.both, called = Loc.server, in = In.blocks, forward = true) + public static void unlinkItemBridge(Player player, Tile tile, Tile other){ + ItemBridgeEntity entity = tile.entity(); + entity.link = -1; + if(other != null) { + ItemBridgeEntity oe = other.entity(); + oe.incoming.remove(tile.packedPosition()); + } + } + public static class ItemBridgeEntity extends TileEntity{ public int link = -1; public IntSet incoming = new IntSet(); diff --git a/core/src/io/anuke/mindustry/world/blocks/distribution/Teleporter.java b/core/src/io/anuke/mindustry/world/blocks/distribution/Teleporter.java index 5023d3a85a..bc0d1f8d12 100644 --- a/core/src/io/anuke/mindustry/world/blocks/distribution/Teleporter.java +++ b/core/src/io/anuke/mindustry/world/blocks/distribution/Teleporter.java @@ -3,9 +3,14 @@ package io.anuke.mindustry.world.blocks.distribution; import com.badlogic.gdx.graphics.Color; import com.badlogic.gdx.utils.Array; import com.badlogic.gdx.utils.ObjectSet; +import io.anuke.annotations.Annotations.Loc; +import io.anuke.annotations.Annotations.Remote; import io.anuke.mindustry.content.Liquids; import io.anuke.mindustry.content.fx.BlockFx; +import io.anuke.mindustry.entities.Player; import io.anuke.mindustry.entities.TileEntity; +import io.anuke.mindustry.gen.CallBlocks; +import io.anuke.mindustry.net.In; import io.anuke.mindustry.type.Item; import io.anuke.mindustry.type.Liquid; import io.anuke.mindustry.world.Tile; @@ -75,8 +80,7 @@ public class Teleporter extends PowerBlock{ @Override public void placed(Tile tile){ - tile.entity().color = lastColor; - tile.entity().color = lastColor; + CallBlocks.setTeleporterColor(null, tile, lastColor); } @Override @@ -222,6 +226,7 @@ public class Teleporter extends PowerBlock{ final int f = i; ImageButton button = cont.addImageButton("white", "toggle", 24, () -> { lastColor = (byte)f; + CallBlocks.setTeleporterColor(null, tile, (byte)f); }).size(34, 38).padBottom(-5.1f).group(group).get(); button.getStyle().imageUpColor = colorArray[f]; button.setChecked(entity.color == f); @@ -292,6 +297,12 @@ public class Teleporter extends PowerBlock{ return returns; } + @Remote(targets = Loc.both, called = Loc.both, in = In.blocks, forward = true) + public static void setTeleporterColor(Player player, Tile tile, byte color){ + TeleporterEntity entity = tile.entity(); + entity.color = color; + } + public static class TeleporterEntity extends TileEntity{ public byte color = 0; public boolean teleporting; diff --git a/core/src/io/anuke/mindustry/world/blocks/power/PowerDistributor.java b/core/src/io/anuke/mindustry/world/blocks/power/PowerDistributor.java index dfb61db967..07e4142533 100644 --- a/core/src/io/anuke/mindustry/world/blocks/power/PowerDistributor.java +++ b/core/src/io/anuke/mindustry/world/blocks/power/PowerDistributor.java @@ -2,9 +2,14 @@ package io.anuke.mindustry.world.blocks.power; import com.badlogic.gdx.math.Vector2; import com.badlogic.gdx.utils.IntArray; +import io.anuke.annotations.Annotations.Loc; +import io.anuke.annotations.Annotations.Remote; +import io.anuke.mindustry.entities.Player; import io.anuke.mindustry.entities.TileEntity; +import io.anuke.mindustry.gen.CallBlocks; import io.anuke.mindustry.graphics.Layer; import io.anuke.mindustry.graphics.Palette; +import io.anuke.mindustry.net.In; import io.anuke.mindustry.world.Edges; import io.anuke.mindustry.world.Tile; import io.anuke.mindustry.world.blocks.PowerBlock; @@ -54,7 +59,7 @@ public class PowerDistributor extends PowerBlock{ public void placed(Tile tile) { Tile before = world.tile(lastPlaced); if(linkValid(tile, before) && before.block() instanceof PowerDistributor){ - link(tile, before); + CallBlocks.linkPowerDistributors(null, tile, before); } lastPlaced = tile.packedPosition(); @@ -80,9 +85,9 @@ public class PowerDistributor extends PowerBlock{ if(linkValid(tile, other)){ if(linked(tile, other)){ - unlink(tile, other); + CallBlocks.unlinkPowerDistributors(null, tile, other); }else if(entity.links.size < maxNodes){ - link(tile, other); + CallBlocks.linkPowerDistributors(null, tile, other); } return false; } @@ -215,7 +220,7 @@ public class PowerDistributor extends PowerBlock{ } } } - +/* protected void link(Tile tile, Tile other){ DistributorEntity entity = tile.entity(); @@ -242,7 +247,7 @@ public class PowerDistributor extends PowerBlock{ oe.links.removeValue(tile.packedPosition()); } - } + }*/ protected boolean linked(Tile tile, Tile other){ return tile.entity().links.contains(other.packedPosition()); @@ -283,6 +288,36 @@ public class PowerDistributor extends PowerBlock{ return new DistributorEntity(); } + @Remote(targets = Loc.both, called = Loc.both, in = In.blocks, forward = true) + public static void linkPowerDistributors(Player player, Tile tile, Tile other){ + DistributorEntity entity = tile.entity(); + + if(!entity.links.contains(other.packedPosition())){ + entity.links.add(other.packedPosition()); + } + + if(other.block() instanceof PowerDistributor){ + DistributorEntity oe = other.entity(); + + if(!oe.links.contains(tile.packedPosition()) ){ + oe.links.add(tile.packedPosition()); + } + } + } + + @Remote(targets = Loc.both, called = Loc.server, in = In.blocks, forward = true) + public static void unlinkPowerDistributors(Player player, Tile tile, Tile other){ + DistributorEntity entity = tile.entity(); + + entity.links.removeValue(other.packedPosition()); + + if(other.block() instanceof PowerDistributor){ + DistributorEntity oe = other.entity(); + + oe.links.removeValue(tile.packedPosition()); + } + } + public static class DistributorEntity extends TileEntity{ public float laserColor = 0f; public float powerRecieved = 0f; diff --git a/core/src/io/anuke/mindustry/world/blocks/storage/SortedUnloader.java b/core/src/io/anuke/mindustry/world/blocks/storage/SortedUnloader.java index 5c550c9ace..033191c131 100644 --- a/core/src/io/anuke/mindustry/world/blocks/storage/SortedUnloader.java +++ b/core/src/io/anuke/mindustry/world/blocks/storage/SortedUnloader.java @@ -1,7 +1,12 @@ package io.anuke.mindustry.world.blocks.storage; +import io.anuke.annotations.Annotations.Loc; +import io.anuke.annotations.Annotations.Remote; import io.anuke.mindustry.content.Items; +import io.anuke.mindustry.entities.Player; import io.anuke.mindustry.entities.TileEntity; +import io.anuke.mindustry.gen.CallBlocks; +import io.anuke.mindustry.net.In; import io.anuke.mindustry.type.Item; import io.anuke.mindustry.world.Tile; import io.anuke.mindustry.world.blocks.SelectionTrait; @@ -53,7 +58,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 -> entity.sortItem = item); + buildItemTable(table, () -> entity.sortItem, item -> CallBlocks.setSortedUnloaderItem(null, tile, item)); } @Override @@ -61,6 +66,12 @@ public class SortedUnloader extends Unloader implements SelectionTrait{ return new SortedUnloaderEntity(); } + @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(); + entity.sortItem = item; + } + public static class SortedUnloaderEntity extends TileEntity{ public Item sortItem = Items.iron;