mirror of
https://github.com/Anuken/Mindustry.git
synced 2025-02-25 22:17:59 +07:00
Experimental sync changes
This commit is contained in:
parent
86a4ff971c
commit
4d54e5c0e1
@ -1,5 +1,5 @@
|
||||
#Autogenerated file. Do not modify.
|
||||
#Mon Feb 12 16:05:35 EST 2018
|
||||
#Mon Feb 12 17:32:19 EST 2018
|
||||
version=beta
|
||||
androidBuildCode=177
|
||||
name=Mindustry
|
||||
|
@ -284,7 +284,7 @@ public class NetClient extends Module {
|
||||
Tile tile = world.tile(packet.position);
|
||||
if (tile == null || tile.entity == null) return;
|
||||
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);
|
||||
};
|
||||
|
||||
@ -294,6 +294,20 @@ public class NetClient extends Module {
|
||||
r.run();
|
||||
}
|
||||
});
|
||||
|
||||
Net.handleClient(ItemAddPacket.class, packet -> {
|
||||
Runnable r = () -> {
|
||||
Tile tile = world.tile(packet.position);
|
||||
if (tile == null || tile.entity == null) return;
|
||||
tile.entity.items[packet.itemid] ++;
|
||||
};
|
||||
|
||||
if(threads.isEnabled()){
|
||||
threads.run(r);
|
||||
}else{
|
||||
r.run();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -152,7 +152,7 @@ public class Renderer extends RendererModule{
|
||||
|
||||
camera.position.set(lastx - deltax, lasty - deltay, 0);
|
||||
|
||||
if(debug) record(); //this only does something if GdxGifRecorder is on the class path, which it usually isn't
|
||||
if(debug && ui.chatfrag.chatOpen()) record(); //this only does something if GdxGifRecorder is on the class path, which it usually isn't
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -137,4 +137,11 @@ public class NetEvents {
|
||||
packet.itemid = (byte)item.id;
|
||||
Net.send(packet, SendMode.udp);
|
||||
}
|
||||
|
||||
public static void handleItemAdd(Tile tile, Item item){
|
||||
ItemAddPacket packet = new ItemAddPacket();
|
||||
packet.position = tile.packedPosition();
|
||||
packet.itemid = (byte)item.id;
|
||||
Net.send(packet, SendMode.udp);
|
||||
}
|
||||
}
|
||||
|
@ -522,4 +522,21 @@ public class Packets {
|
||||
itemid = buffer.get();
|
||||
}
|
||||
}
|
||||
|
||||
public static class ItemAddPacket implements Packet{
|
||||
public int position;
|
||||
public byte itemid;
|
||||
|
||||
@Override
|
||||
public void write(ByteBuffer buffer) {
|
||||
buffer.putInt(position);
|
||||
buffer.put(itemid);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void read(ByteBuffer buffer) {
|
||||
position = buffer.getInt();
|
||||
itemid = buffer.get();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -38,7 +38,8 @@ public class Registrator {
|
||||
CustomMapPacket.class,
|
||||
MapAckPacket.class,
|
||||
EntitySpawnPacket.class,
|
||||
ItemTransferPacket.class
|
||||
ItemTransferPacket.class,
|
||||
ItemAddPacket.class,
|
||||
};
|
||||
private static ObjectIntMap<Class<?>> ids = new ObjectIntMap<>();
|
||||
|
||||
|
@ -150,7 +150,12 @@ public class Block{
|
||||
|
||||
public void handleItem(Item item, Tile tile, Tile source){
|
||||
if(tile.entity == null) return;
|
||||
|
||||
if(Net.server() || !Net.active()){
|
||||
tile.entity.addItem(item, 1);
|
||||
|
||||
if(Net.server()) NetEvents.handleItemAdd(tile, item);
|
||||
}
|
||||
}
|
||||
|
||||
public boolean acceptItem(Item item, Tile tile, Tile source){
|
||||
|
@ -48,7 +48,7 @@ public class Router extends Block{
|
||||
@Override
|
||||
public void handleItem(Item item, Tile tile, Tile source){
|
||||
super.handleItem(item, tile, source);
|
||||
tile.setExtra((byte)tile.relativeTo(source.x, source.y));
|
||||
tile.setExtra(tile.relativeTo(source.x, source.y));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -4,11 +4,13 @@ import com.badlogic.gdx.graphics.Color;
|
||||
import com.badlogic.gdx.utils.Array;
|
||||
import com.badlogic.gdx.utils.ObjectSet;
|
||||
import io.anuke.mindustry.entities.TileEntity;
|
||||
import io.anuke.mindustry.net.Net;
|
||||
import io.anuke.mindustry.net.NetEvents;
|
||||
import io.anuke.mindustry.resource.Item;
|
||||
import io.anuke.mindustry.world.Tile;
|
||||
import io.anuke.mindustry.world.blocks.types.PowerBlock;
|
||||
import io.anuke.ucore.graphics.Draw;
|
||||
import io.anuke.ucore.core.Timers;
|
||||
import io.anuke.ucore.graphics.Draw;
|
||||
import io.anuke.ucore.scene.ui.ButtonGroup;
|
||||
import io.anuke.ucore.scene.ui.ImageButton;
|
||||
import io.anuke.ucore.scene.ui.layout.Table;
|
||||
@ -133,8 +135,13 @@ public class Teleporter extends PowerBlock{
|
||||
Array<Tile> links = findLinks(tile);
|
||||
|
||||
if(links.size > 0){
|
||||
Tile target = links.get(Mathf.random(0, links.size-1));
|
||||
|
||||
if(Net.server() || !Net.active()){
|
||||
Tile target = links.random();
|
||||
target.entity.addItem(item, 1);
|
||||
|
||||
if(Net.server()) NetEvents.handleItemAdd(target, item);
|
||||
}
|
||||
}
|
||||
|
||||
entity.power -= powerPerItem;
|
||||
@ -170,6 +177,7 @@ public class Teleporter extends PowerBlock{
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for(Tile remove : removal)
|
||||
teleporters[entity.color].remove(remove);
|
||||
|
||||
|
@ -188,7 +188,7 @@ public class ServerControl extends Module {
|
||||
return;
|
||||
}
|
||||
|
||||
netCommon.sendMessage("[DARK_GRAY][[Server]:[] " + arg[0]);
|
||||
netCommon.sendMessage("[GRAY][[Server]:[] " + arg[0]);
|
||||
info("&lyServer: &lb{0}", arg[0]);
|
||||
}).mergeArgs();
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user