Actually implemented puddle syncing
This commit is contained in:
@@ -11,6 +11,7 @@ import io.anuke.mindustry.entities.Player;
|
|||||||
import io.anuke.mindustry.entities.bullet.BulletType;
|
import io.anuke.mindustry.entities.bullet.BulletType;
|
||||||
import io.anuke.mindustry.entities.effect.Fire;
|
import io.anuke.mindustry.entities.effect.Fire;
|
||||||
import io.anuke.mindustry.entities.effect.ItemDrop;
|
import io.anuke.mindustry.entities.effect.ItemDrop;
|
||||||
|
import io.anuke.mindustry.entities.effect.Puddle;
|
||||||
import io.anuke.mindustry.entities.traits.SyncTrait;
|
import io.anuke.mindustry.entities.traits.SyncTrait;
|
||||||
import io.anuke.mindustry.entities.units.UnitType;
|
import io.anuke.mindustry.entities.units.UnitType;
|
||||||
import io.anuke.mindustry.entities.units.types.Drone;
|
import io.anuke.mindustry.entities.units.types.Drone;
|
||||||
@@ -135,5 +136,6 @@ public class ContentLoader {
|
|||||||
Scout.typeID = SyncTrait.registerType(Scout::new);
|
Scout.typeID = SyncTrait.registerType(Scout::new);
|
||||||
ItemDrop.typeID = SyncTrait.registerType(ItemDrop::new);
|
ItemDrop.typeID = SyncTrait.registerType(ItemDrop::new);
|
||||||
Fire.typeID = SyncTrait.registerType(Fire::new);
|
Fire.typeID = SyncTrait.registerType(Fire::new);
|
||||||
|
Puddle.typeID = SyncTrait.registerType(Puddle::new);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ import io.anuke.mindustry.content.fx.BlockFx;
|
|||||||
import io.anuke.mindustry.content.fx.EnvironmentFx;
|
import io.anuke.mindustry.content.fx.EnvironmentFx;
|
||||||
import io.anuke.mindustry.entities.Units;
|
import io.anuke.mindustry.entities.Units;
|
||||||
import io.anuke.mindustry.entities.traits.SaveTrait;
|
import io.anuke.mindustry.entities.traits.SaveTrait;
|
||||||
|
import io.anuke.mindustry.entities.traits.SyncTrait;
|
||||||
import io.anuke.mindustry.gen.CallEntity;
|
import io.anuke.mindustry.gen.CallEntity;
|
||||||
import io.anuke.mindustry.net.In;
|
import io.anuke.mindustry.net.In;
|
||||||
import io.anuke.mindustry.net.Net;
|
import io.anuke.mindustry.net.Net;
|
||||||
@@ -38,7 +39,7 @@ import java.io.IOException;
|
|||||||
|
|
||||||
import static io.anuke.mindustry.Vars.*;
|
import static io.anuke.mindustry.Vars.*;
|
||||||
|
|
||||||
public class Puddle extends BaseEntity implements SaveTrait, Poolable, DrawTrait {
|
public class Puddle extends BaseEntity implements SaveTrait, Poolable, DrawTrait, SyncTrait {
|
||||||
private static final IntMap<Puddle> map = new IntMap<>();
|
private static final IntMap<Puddle> map = new IntMap<>();
|
||||||
private static final float maxLiquid = 70f;
|
private static final float maxLiquid = 70f;
|
||||||
private static final int maxGeneration = 2;
|
private static final int maxGeneration = 2;
|
||||||
@@ -47,13 +48,15 @@ public class Puddle extends BaseEntity implements SaveTrait, Poolable, DrawTrait
|
|||||||
private static final Rectangle rect2 = new Rectangle();
|
private static final Rectangle rect2 = new Rectangle();
|
||||||
private static int seeds;
|
private static int seeds;
|
||||||
|
|
||||||
|
public static int typeID = -1;
|
||||||
|
|
||||||
private int loadedPosition = -1;
|
private int loadedPosition = -1;
|
||||||
|
|
||||||
private Tile tile;
|
private Tile tile;
|
||||||
private Liquid liquid;
|
private Liquid liquid;
|
||||||
private float amount;
|
private float amount, targetAmount;
|
||||||
private byte generation;
|
|
||||||
private float accepting;
|
private float accepting;
|
||||||
|
private byte generation;
|
||||||
|
|
||||||
/**Deposists a puddle between tile and source.*/
|
/**Deposists a puddle between tile and source.*/
|
||||||
public static void deposit(Tile tile, Tile source, Liquid liquid, float amount){
|
public static void deposit(Tile tile, Tile source, Liquid liquid, float amount){
|
||||||
@@ -143,7 +146,7 @@ public class Puddle extends BaseEntity implements SaveTrait, Poolable, DrawTrait
|
|||||||
@Override
|
@Override
|
||||||
public void update() {
|
public void update() {
|
||||||
if(amount >= maxLiquid/2f && Timers.get(this, "update", 20)){
|
if(amount >= maxLiquid/2f && Timers.get(this, "update", 20)){
|
||||||
Units.getNearby(rect.setSize(Mathf.clamp(amount/(maxLiquid/1.5f))*10f).setCenter(tile.worldx(), tile.worldy()), unit -> {
|
Units.getNearby(rect.setSize(Mathf.clamp(amount/(maxLiquid/1.5f))*10f).setCenter(x, y), unit -> {
|
||||||
unit.getHitbox(rect2);
|
unit.getHitbox(rect2);
|
||||||
if(!rect.overlaps(rect2)) return;
|
if(!rect.overlaps(rect2)) return;
|
||||||
|
|
||||||
@@ -160,7 +163,10 @@ public class Puddle extends BaseEntity implements SaveTrait, Poolable, DrawTrait
|
|||||||
}
|
}
|
||||||
|
|
||||||
//no updating happens clientside
|
//no updating happens clientside
|
||||||
if(Net.client()) return;
|
if(Net.client()){
|
||||||
|
amount = Mathf.lerpDelta(amount, targetAmount, 0.15f);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
float addSpeed = accepting > 0 ? 3f : 0f;
|
float addSpeed = accepting > 0 ? 3f : 0f;
|
||||||
|
|
||||||
@@ -255,6 +261,29 @@ public class Puddle extends BaseEntity implements SaveTrait, Poolable, DrawTrait
|
|||||||
reset();
|
reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getTypeID() {
|
||||||
|
return typeID;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void write(DataOutput data) throws IOException {
|
||||||
|
data.writeFloat(x);
|
||||||
|
data.writeFloat(y);
|
||||||
|
data.writeByte(liquid.id);
|
||||||
|
data.writeShort((short)(amount * 4));
|
||||||
|
data.writeInt(tile.packedPosition());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void read(DataInput data, long time) throws IOException {
|
||||||
|
x = data.readFloat();
|
||||||
|
y = data.readFloat();
|
||||||
|
liquid = Liquid.getByID(data.readByte());
|
||||||
|
targetAmount = data.readShort()/4f;
|
||||||
|
tile = world.tile(data.readInt());
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public EntityGroup targetGroup() {
|
public EntityGroup targetGroup() {
|
||||||
return puddleGroup;
|
return puddleGroup;
|
||||||
|
|||||||
Reference in New Issue
Block a user