Fixed some multiplayer crashes
This commit is contained in:
@@ -250,7 +250,7 @@ public class NetClient extends Module {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Remote(variants = Variant.one, priority = PacketPriority.low, unreliable = true)
|
@Remote(variants = Variant.one, priority = PacketPriority.low, unreliable = true)
|
||||||
public static void onSnapshot(byte[] chunk, int snapshotID, short chunkID, short totalLength, int base){
|
public static void onSnapshot(byte[] chunk, int snapshotID, short chunkID, int totalLength, int base){
|
||||||
if(NetServer.showSnapshotSize) Log.info("Recieved snapshot: len {0} ID {1} chunkID {2} totalLength {3} base {4} client-base {5}", chunk.length, snapshotID, chunkID, totalLength, base, netClient.lastSnapshotBaseID);
|
if(NetServer.showSnapshotSize) Log.info("Recieved snapshot: len {0} ID {1} chunkID {2} totalLength {3} base {4} client-base {5}", chunk.length, snapshotID, chunkID, totalLength, base, netClient.lastSnapshotBaseID);
|
||||||
|
|
||||||
//skip snapshot IDs that have already been recieved OR snapshots that are too far in front
|
//skip snapshot IDs that have already been recieved OR snapshots that are too far in front
|
||||||
|
|||||||
@@ -449,7 +449,7 @@ public class NetServer extends Module{
|
|||||||
/**Sends a raw byte[] snapshot to a client, splitting up into chunks when needed.*/
|
/**Sends a raw byte[] snapshot to a client, splitting up into chunks when needed.*/
|
||||||
private static void sendSplitSnapshot(int userid, byte[] bytes, int snapshotID, int base){
|
private static void sendSplitSnapshot(int userid, byte[] bytes, int snapshotID, int base){
|
||||||
if(bytes.length < maxSnapshotSize){
|
if(bytes.length < maxSnapshotSize){
|
||||||
Call.onSnapshot(userid, bytes, snapshotID, (short)0, (short)bytes.length, base);
|
Call.onSnapshot(userid, bytes, snapshotID, (short)0, bytes.length, base);
|
||||||
}else{
|
}else{
|
||||||
int remaining = bytes.length;
|
int remaining = bytes.length;
|
||||||
int offset = 0;
|
int offset = 0;
|
||||||
@@ -464,7 +464,7 @@ public class NetServer extends Module{
|
|||||||
}else {
|
}else {
|
||||||
toSend = Arrays.copyOfRange(bytes, offset, Math.min(offset + maxSnapshotSize, bytes.length));
|
toSend = Arrays.copyOfRange(bytes, offset, Math.min(offset + maxSnapshotSize, bytes.length));
|
||||||
}
|
}
|
||||||
Call.onSnapshot(userid, toSend, snapshotID, (short)chunkid, (short)bytes.length, base);
|
Call.onSnapshot(userid, toSend, snapshotID, (short)chunkid, bytes.length, base);
|
||||||
|
|
||||||
remaining -= used;
|
remaining -= used;
|
||||||
offset += used;
|
offset += used;
|
||||||
|
|||||||
@@ -473,7 +473,9 @@ public class Player extends Unit implements BuilderTrait, CarryTrait, ShooterTra
|
|||||||
updateMech();
|
updateMech();
|
||||||
}
|
}
|
||||||
|
|
||||||
avoidOthers(8f);
|
if(isLocal) {
|
||||||
|
avoidOthers(8f);
|
||||||
|
}
|
||||||
|
|
||||||
if(!isShooting()) {
|
if(!isShooting()) {
|
||||||
updateBuilding(this);
|
updateBuilding(this);
|
||||||
|
|||||||
@@ -199,7 +199,6 @@ public abstract class Unit extends DestructibleEntity implements SaveTrait, Targ
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void avoidOthers(float avoidRange){
|
public void avoidOthers(float avoidRange){
|
||||||
if(Net.client()) return;
|
|
||||||
|
|
||||||
EntityPhysics.getNearby(getGroup(), x, y, avoidRange*2f, t -> {
|
EntityPhysics.getNearby(getGroup(), x, y, avoidRange*2f, t -> {
|
||||||
if(t == this || (t instanceof Unit && (((Unit) t).isDead() || (((Unit) t).isFlying() != isFlying()) || ((Unit) t).getCarrier() == this) || getCarrier() == t)) return;
|
if(t == this || (t instanceof Unit && (((Unit) t).isDead() || (((Unit) t).isFlying() != isFlying()) || ((Unit) t).getCarrier() == this) || getCarrier() == t)) return;
|
||||||
|
|||||||
@@ -41,6 +41,7 @@ public interface CarryTrait extends TeamTrait, SolidTrait, TargetTrait{
|
|||||||
|
|
||||||
@Remote(called = Loc.both, targets = Loc.both, forward = true, in = In.entities)
|
@Remote(called = Loc.both, targets = Loc.both, forward = true, in = In.entities)
|
||||||
static void setCarryOf(Player player, CarryTrait trait, CarriableTrait unit){
|
static void setCarryOf(Player player, CarryTrait trait, CarriableTrait unit){
|
||||||
|
if(trait == null) return;
|
||||||
if(player != null){ //when a server recieves this called from a player, set the carrier to the player.
|
if(player != null){ //when a server recieves this called from a player, set the carrier to the player.
|
||||||
trait = player;
|
trait = player;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -283,7 +283,9 @@ public abstract class BaseUnit extends Unit implements ShooterTrait{
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
avoidOthers(8f);
|
if(!Net.client()){
|
||||||
|
avoidOthers(8f);
|
||||||
|
}
|
||||||
|
|
||||||
if(squad != null){
|
if(squad != null){
|
||||||
squad.update();
|
squad.update();
|
||||||
|
|||||||
@@ -106,6 +106,7 @@ public class TypeIO {
|
|||||||
public static void writeCarry(ByteBuffer buffer, CarryTrait unit){
|
public static void writeCarry(ByteBuffer buffer, CarryTrait unit){
|
||||||
if(unit == null){
|
if(unit == null){
|
||||||
buffer.put((byte)-1);
|
buffer.put((byte)-1);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
buffer.put((byte)unit.getGroup().getID());
|
buffer.put((byte)unit.getGroup().getID());
|
||||||
buffer.putInt(unit.getID());
|
buffer.putInt(unit.getID());
|
||||||
@@ -123,7 +124,7 @@ public class TypeIO {
|
|||||||
|
|
||||||
@WriteClass(BaseUnit.class)
|
@WriteClass(BaseUnit.class)
|
||||||
public static void writeBaseUnit(ByteBuffer buffer, BaseUnit unit){
|
public static void writeBaseUnit(ByteBuffer buffer, BaseUnit unit){
|
||||||
buffer.put((byte)unit.getGroup().getID());
|
buffer.put((byte)unitGroups[unit.getTeam().ordinal()].getID());
|
||||||
buffer.putInt(unit.getID());
|
buffer.putInt(unit.getID());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -27,16 +27,9 @@ import static io.anuke.mindustry.Vars.headless;
|
|||||||
|
|
||||||
public class GenericCrafter extends Block{
|
public class GenericCrafter extends Block{
|
||||||
protected final int timerDump = timers++;
|
protected final int timerDump = timers++;
|
||||||
|
|
||||||
/**Can be null. If you use this, make sure to set hasItems to true!*/
|
|
||||||
//protected ItemStack inputItem;
|
|
||||||
/**Can be null. If you use this, make sure to set hasLiquids to true!*/
|
|
||||||
//protected Liquid inputLiquid;
|
|
||||||
/**Required.*/
|
|
||||||
protected Item output;
|
protected Item output;
|
||||||
protected float craftTime = 80;
|
protected float craftTime = 80;
|
||||||
//protected float powerUse;
|
|
||||||
//protected float liquidUse;
|
|
||||||
protected Effect craftEffect = BlockFx.purify;
|
protected Effect craftEffect = BlockFx.purify;
|
||||||
protected Effect updateEffect = Fx.none;
|
protected Effect updateEffect = Fx.none;
|
||||||
protected float updateEffectChance = 0.04f;
|
protected float updateEffectChance = 0.04f;
|
||||||
|
|||||||
Reference in New Issue
Block a user