mirror of
https://github.com/Anuken/Mindustry.git
synced 2025-02-26 15:27:19 +07:00
Made client queue packets while loading, changed reactor explode code
This commit is contained in:
parent
9814ea1d28
commit
a0d6ada6c0
@ -17,6 +17,7 @@ import io.anuke.mindustry.net.NetworkIO;
|
||||
import io.anuke.mindustry.net.Packets.*;
|
||||
import io.anuke.mindustry.world.Map;
|
||||
import io.anuke.mindustry.world.Tile;
|
||||
import io.anuke.mindustry.world.blocks.ProductionBlocks;
|
||||
import io.anuke.ucore.core.Timers;
|
||||
import io.anuke.ucore.entities.BaseBulletType;
|
||||
import io.anuke.ucore.entities.Entities;
|
||||
@ -252,6 +253,10 @@ public class NetClient extends Module {
|
||||
});
|
||||
|
||||
Net.handleClient(GameOverPacket.class, packet -> {
|
||||
if(world.getCore().block() != ProductionBlocks.core &&
|
||||
world.getCore().entity != null){
|
||||
world.getCore().entity.onDeath(true);
|
||||
}
|
||||
kicked = true;
|
||||
ui.restart.show();
|
||||
});
|
||||
@ -287,10 +292,10 @@ public class NetClient extends Module {
|
||||
private void finishConnecting(){
|
||||
Net.send(new ConnectConfirmPacket(), SendMode.tcp);
|
||||
state.set(State.playing);
|
||||
Net.setClientLoaded(true);
|
||||
connecting = false;
|
||||
ui.loadfrag.hide();
|
||||
ui.join.hide();
|
||||
Net.setClientLoaded(true);
|
||||
}
|
||||
|
||||
public void beginConnecting(){
|
||||
|
@ -26,6 +26,7 @@ public class Net{
|
||||
private static boolean server;
|
||||
private static boolean active;
|
||||
private static boolean clientLoaded;
|
||||
private static Array<Object> packetQueue = new Array<>();
|
||||
private static ObjectMap<Class<?>, Consumer> listeners = new ObjectMap<>();
|
||||
private static ObjectMap<Class<?>, Consumer> clientListeners = new ObjectMap<>();
|
||||
private static ObjectMap<Class<?>, BiConsumer<Integer, Object>> serverListeners = new ObjectMap<>();
|
||||
@ -46,6 +47,16 @@ public class Net{
|
||||
/**Sets the client loaded status, or whether it will recieve normal packets from the server.*/
|
||||
public static void setClientLoaded(boolean loaded){
|
||||
clientLoaded = loaded;
|
||||
|
||||
if(loaded){
|
||||
//handle all packets that were skipped while loading
|
||||
for(int i = 0; i < packetQueue.size; i ++){
|
||||
Log.info("Processing {0} packet post-load.", ClassReflection.getSimpleName(packetQueue.get(i).getClass()));
|
||||
handleClientReceived(packetQueue.get(i));
|
||||
}
|
||||
}
|
||||
//clear inbound packet queue
|
||||
packetQueue.clear();
|
||||
}
|
||||
|
||||
/**Connect to an address.*/
|
||||
@ -173,6 +184,7 @@ public class Net{
|
||||
if(clientListeners.get(object.getClass()) != null) clientListeners.get(object.getClass()).accept(object);
|
||||
if(listeners.get(object.getClass()) != null) listeners.get(object.getClass()).accept(object);
|
||||
}else{
|
||||
packetQueue.add(object);
|
||||
Log.info("Recieved {0}, but ignoring data, as client is not loaded.", ClassReflection.getSimpleName(object.getClass()));
|
||||
}
|
||||
}else{
|
||||
|
@ -89,9 +89,7 @@ public class NuclearReactor extends LiquidPowerGenerator{
|
||||
}
|
||||
|
||||
if(entity.heat >= 1f){
|
||||
onDestroyed(tile);
|
||||
world.removeBlock(tile);
|
||||
|
||||
entity.damage((int)entity.health);
|
||||
}else{
|
||||
distributeLaserPower(tile);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user