Synced whole place queue / Fixed player flash desync
This commit is contained in:
@@ -82,14 +82,6 @@ public class Player extends Unit implements BuilderTrait, CarryTrait, ShooterTra
|
||||
|
||||
//region unit and event overrides, utility methods
|
||||
|
||||
@Remote(targets = Loc.server, called = Loc.server)
|
||||
public static void onPlayerDamage(Player player, float amount){
|
||||
if(player == null) return;
|
||||
|
||||
player.hitTime = hitDuration;
|
||||
player.health -= amount;
|
||||
}
|
||||
|
||||
@Remote(targets = Loc.server, called = Loc.server)
|
||||
public static void onPlayerDeath(Player player){
|
||||
if(player == null) return;
|
||||
@@ -227,7 +219,10 @@ public class Player extends Unit implements BuilderTrait, CarryTrait, ShooterTra
|
||||
|
||||
@Override
|
||||
public void damage(float amount){
|
||||
Call.onPlayerDamage(this, calculateDamage(amount));
|
||||
hitTime = hitDuration;
|
||||
if(!Net.client()){
|
||||
health -= amount;
|
||||
}
|
||||
|
||||
if(health <= 0 && !dead){
|
||||
Call.onPlayerDeath(this);
|
||||
|
||||
@@ -185,7 +185,6 @@ public class NetworkIO{
|
||||
int height = stream.readShort();
|
||||
|
||||
//TODO send advanced map meta such as author, etc
|
||||
//TODO scan for cores
|
||||
Map currentMap = new Map(map, new MapMeta(0, new ObjectMap<>(), width, height, null), true, () -> null);
|
||||
currentMap.meta.tags.clear();
|
||||
currentMap.meta.tags.putAll(tags);
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package io.anuke.mindustry.net;
|
||||
|
||||
import com.badlogic.gdx.utils.Array;
|
||||
import com.badlogic.gdx.utils.Base64Coder;
|
||||
import com.badlogic.gdx.utils.TimeUtils;
|
||||
import io.anuke.mindustry.Vars;
|
||||
@@ -155,7 +156,7 @@ public class Packets{
|
||||
public float x, y, pointerX, pointerY, rotation, baseRotation, xv, yv;
|
||||
public Tile mining;
|
||||
public boolean boosting, shooting;
|
||||
public BuildRequest currentRequest;
|
||||
public Array<BuildRequest> requests = new Array<>();
|
||||
|
||||
@Override
|
||||
public void write(ByteBuffer buffer){
|
||||
@@ -180,17 +181,14 @@ public class Packets{
|
||||
|
||||
buffer.putInt(player.getMineTile() == null ? -1 : player.getMineTile().packedPosition());
|
||||
|
||||
BuildRequest request = player.getCurrentRequest();
|
||||
|
||||
if(request != null){
|
||||
buffer.putShort((short)player.getPlaceQueue().size);
|
||||
for(BuildRequest request : player.getPlaceQueue()){
|
||||
buffer.put(request.remove ? (byte) 1 : 0);
|
||||
buffer.putInt(world.toPacked(request.x, request.y));
|
||||
if(!request.remove){
|
||||
buffer.put((byte) request.recipe.id);
|
||||
buffer.put((byte) request.rotation);
|
||||
}
|
||||
}else{
|
||||
buffer.put((byte) -1);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -211,10 +209,13 @@ public class Packets{
|
||||
rotation = buffer.getShort() / 2f;
|
||||
baseRotation = buffer.getShort() / 2f;
|
||||
mining = world.tile(buffer.getInt());
|
||||
requests.clear();
|
||||
|
||||
byte type = buffer.get();
|
||||
if(type != -1){
|
||||
short reqamount = buffer.getShort();
|
||||
for(int i = 0; i < reqamount; i++){
|
||||
byte type = buffer.get();
|
||||
int position = buffer.getInt();
|
||||
BuildRequest currentRequest;
|
||||
|
||||
if(type == 1){ //remove
|
||||
currentRequest = new BuildRequest(position % world.width(), position / world.width());
|
||||
@@ -223,8 +224,8 @@ public class Packets{
|
||||
byte rotation = buffer.get();
|
||||
currentRequest = new BuildRequest(position % world.width(), position / world.width(), rotation, Recipe.getByID(recipe));
|
||||
}
|
||||
}else{
|
||||
currentRequest = null;
|
||||
|
||||
requests.add(currentRequest);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user