Sync spawned units immediately
This commit is contained in:
@@ -12,6 +12,7 @@ import mindustry.annotations.Annotations.*;
|
||||
import mindustry.content.TechTree.*;
|
||||
import mindustry.ctype.*;
|
||||
import mindustry.entities.*;
|
||||
import mindustry.entities.Units.*;
|
||||
import mindustry.entities.abilities.*;
|
||||
import mindustry.entities.bullet.*;
|
||||
import mindustry.entities.units.*;
|
||||
@@ -278,6 +279,46 @@ public class TypeIO{
|
||||
return noAbilities;
|
||||
}
|
||||
|
||||
public static void writeUnitContainer(Writes write, Units.UnitContainer cont){
|
||||
write.i(cont.unit.id);
|
||||
write.b(cont.unit.classId() & 0xFF);
|
||||
cont.unit.beforeWrite();
|
||||
cont.unit.writeSync(write);
|
||||
}
|
||||
|
||||
public static UnitContainer readUnitContainer(Reads read){
|
||||
int id = read.i();
|
||||
int typeID = read.ub();
|
||||
|
||||
Unit entity = Groups.unit.getByID(id);
|
||||
boolean add = false, created = false;
|
||||
|
||||
if(entity == null){
|
||||
entity = (Unit)EntityMapping.map(typeID & 0xFF).get();
|
||||
entity.id(id);
|
||||
|
||||
if(!netClient.isEntityUsed(entity.id())){
|
||||
add = true;
|
||||
}
|
||||
created = true;
|
||||
}
|
||||
|
||||
//read the entity
|
||||
entity.readSync(read);
|
||||
|
||||
if(created){
|
||||
//snap initial starting position
|
||||
entity.snapSync();
|
||||
}
|
||||
|
||||
if(add){
|
||||
entity.add();
|
||||
netClient.addRemovedEntity(entity.id());
|
||||
}
|
||||
|
||||
return null; //no need to actually return anything
|
||||
}
|
||||
|
||||
public static void writeUnit(Writes write, Unit unit){
|
||||
write.b(unit == null ? 0 : unit instanceof BlockUnitc ? 1 : 2);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user