More cleanup

This commit is contained in:
Anuken
2020-02-03 20:24:49 -05:00
parent 88d2ec5be8
commit a942ed2cad
141 changed files with 2213 additions and 1819 deletions

View File

@@ -13,9 +13,6 @@ import arc.util.io.*;
import mindustry.ai.*;
import mindustry.core.*;
import mindustry.entities.*;
import mindustry.entities.effect.*;
import mindustry.entities.traits.*;
import mindustry.entities.type.*;
import mindustry.game.*;
import mindustry.game.EventType.*;
import mindustry.gen.*;
@@ -24,7 +21,6 @@ import mindustry.maps.*;
import mindustry.mod.*;
import mindustry.net.Net;
import mindustry.net.*;
import mindustry.world.blocks.defense.ForceProjector.*;
import java.io.*;
import java.nio.charset.*;
@@ -178,17 +174,6 @@ public class Vars implements Loadable{
public static NetServer netServer;
public static NetClient netClient;
public static Entities entities;
public static EntityGroup<Player> playerGroup;
public static EntityGroup<TileEntity> tileGroup;
public static EntityGroup<Bullet> bulletGroup;
public static EntityGroup<EffectEntity> effectGroup;
public static EntityGroup<DrawTrait> groundEffectGroup;
public static EntityGroup<ShieldEntity> shieldGroup;
public static EntityGroup<Puddle> puddleGroup;
public static EntityGroup<Fire> fireGroup;
public static EntityGroup<BaseUnit> unitGroup;
public static Unitc player;
@Override
@@ -234,25 +219,6 @@ public class Vars implements Loadable{
indexer = new BlockIndexer();
pathfinder = new Pathfinder();
entities = new Entities();
playerGroup = entities.add(Player.class).enableMapping();
tileGroup = entities.add(TileEntity.class, false);
bulletGroup = entities.add(Bullet.class).enableMapping();
effectGroup = entities.add(EffectEntity.class, false);
groundEffectGroup = entities.add(DrawTrait.class, false);
puddleGroup = entities.add(Puddle.class).enableMapping();
shieldGroup = entities.add(ShieldEntity.class, false);
fireGroup = entities.add(Fire.class).enableMapping();
unitGroup = entities.add(BaseUnit.class).enableMapping();
for(EntityGroup<?> group : entities.all()){
group.setRemoveListener(entity -> {
if(entity instanceof SyncTrait && net.client()){
netClient.addRemovedEntity((entity).getID());
}
});
}
state = new GameState();
data = new GlobalData();

View File

@@ -7,10 +7,9 @@ import arc.math.geom.*;
import arc.struct.*;
import arc.util.*;
import mindustry.content.*;
import mindustry.entities.traits.*;
import mindustry.entities.type.*;
import mindustry.game.EventType.*;
import mindustry.game.*;
import mindustry.gen.*;
import mindustry.type.*;
import mindustry.world.*;
import mindustry.world.blocks.*;
@@ -164,8 +163,8 @@ public class BlockIndexer{
return flagMap[team.id][type.ordinal()];
}
public boolean eachBlock(TeamTrait trait, float range, Boolf<Tile> pred, Cons<Tile> cons){
return eachBlock(trait.getTeam(), trait.getX(), trait.getY(), range, pred, cons);
public boolean eachBlock(Teamc team, float range, Boolf<Tile> pred, Cons<Tile> cons){
return eachBlock(team.getTeam(), team.getX(), team.getY(), range, pred, cons);
}
public boolean eachBlock(Team team, float wx, float wy, float range, Boolf<Tile> pred, Cons<Tile> cons){
@@ -213,20 +212,20 @@ public class BlockIndexer{
return returnArray;
}
public void notifyTileDamaged(TileEntity entity){
public void notifyTileDamaged(Tilec entity){
if(damagedTiles[(int)entity.getTeam().id] == null){
damagedTiles[(int)entity.getTeam().id] = new ObjectSet<>();
}
ObjectSet<Tile> set = damagedTiles[(int)entity.getTeam().id];
set.add(entity.tile);
set.add(entity.getTile());
}
public TileEntity findEnemyTile(Team team, float x, float y, float range, Boolf<Tile> pred){
public Tilec findEnemyTile(Team team, float x, float y, float range, Boolf<Tile> pred){
for(Team enemy : activeTeams){
if(!team.isEnemy(enemy)) continue;
TileEntity entity = indexer.findTile(enemy, x, y, range, pred, true);
Tilec entity = indexer.findTile(enemy, x, y, range, pred, true);
if(entity != null){
return entity;
}
@@ -235,12 +234,12 @@ public class BlockIndexer{
return null;
}
public TileEntity findTile(Team team, float x, float y, float range, Boolf<Tile> pred){
public Tilec findTile(Team team, float x, float y, float range, Boolf<Tile> pred){
return findTile(team, x, y, range, pred, false);
}
public TileEntity findTile(Team team, float x, float y, float range, Boolf<Tile> pred, boolean usePriority){
TileEntity closest = null;
public Tilec findTile(Team team, float x, float y, float range, Boolf<Tile> pred, boolean usePriority){
Tilec closest = null;
float dst = 0;
float range2 = range*range;
@@ -258,14 +257,14 @@ public class BlockIndexer{
if(other.entity == null || other.getTeam() != team || !pred.get(other) || !other.block().targetable)
continue;
TileEntity e = other.entity;
Tilec e = other.entity;
float ndst = Mathf.dst2(x, y, e.x, e.y);
float ndst = e.dst2(x, y);
if(ndst < range2 && (closest == null ||
//this one is closer, and it is at least of equal priority
(ndst < dst && (!usePriority || closest.block.priority.ordinal() <= e.block.priority.ordinal())) ||
(ndst < dst && (!usePriority || closest.getBlock().priority.ordinal() <= e.getBlock().priority.ordinal())) ||
//priority is used, and new block has higher priority regardless of range
(usePriority && closest.block.priority.ordinal() < e.block.priority.ordinal()))){
(usePriority && closest.getBlock().priority.ordinal() < e.getBlock().priority.ordinal()))){
dst = ndst;
closest = e;
}

View File

@@ -87,8 +87,8 @@ public class WaveSpawner{
}
if(state.rules.attackMode && state.teams.isActive(state.rules.waveTeam) && !state.teams.playerCores().isEmpty()){
TileEntity firstCore = state.teams.playerCores().first();
for(TileEntity core : state.rules.waveTeam.cores()){
Tilec firstCore = state.teams.playerCores().first();
for(Tilec core : state.rules.waveTeam.cores()){
Tmp.v1.set(firstCore).sub(core.x, core.y).limit(coreMargin + core.block.size*tilesize);
cons.accept(core.x + Tmp.v1.x, core.y + Tmp.v1.y, false);
}
@@ -104,7 +104,7 @@ public class WaveSpawner{
}
if(state.rules.attackMode && state.teams.isActive(state.rules.waveTeam)){
for(TileEntity core : state.teams.get(state.rules.waveTeam).cores){
for(Tilec core : state.teams.get(state.rules.waveTeam).cores){
cons.get(core.x, core.y);
}
}

View File

@@ -10,7 +10,6 @@ import mindustry.*;
import mindustry.ctype.*;
import mindustry.entities.*;
import mindustry.entities.bullet.*;
import mindustry.entities.type.*;
import mindustry.gen.*;
import mindustry.graphics.*;
import mindustry.type.*;
@@ -585,7 +584,7 @@ public class Blocks implements ContentList{
drawIcons = () -> new TextureRegion[]{Core.atlas.find(name + "-bottom"), Core.atlas.find(name + "-top")};
drawer = tile -> {
LiquidModule mod = tile.entity.liquids;
LiquidModule mod = tile.entity.getLiquids();
int rotation = rotate ? tile.rotation() * 90 : 0;
@@ -681,7 +680,7 @@ public class Blocks implements ContentList{
Draw.rect(region, tile.drawx(), tile.drawy());
Draw.rect(reg(frameRegions[(int)Mathf.absin(entity.totalProgress, 5f, 2.999f)]), tile.drawx(), tile.drawy());
Draw.color(Color.clear, tile.entity.liquids.current().color, tile.entity.liquids.total() / liquidCapacity);
Draw.color(Color.clear, tile.entity.getLiquids().current().color, tile.entity.getLiquids().total() / liquidCapacity);
Draw.rect(reg(liquidRegion), tile.drawx(), tile.drawy());
Draw.color();
Draw.rect(reg(topRegion), tile.drawx(), tile.drawy());
@@ -1536,14 +1535,14 @@ public class Blocks implements ContentList{
}
@Override
public void init(mindustry.entities.type.Bullet b){
public void init(Bulletc b){
for(int i = 0; i < rays; i++){
Damage.collideLine(b, b.getTeam(), hitEffect, b.x, b.y, b.rot(), rayLength - Math.abs(i - (rays / 2)) * 20f);
}
}
@Override
public void draw(Bullet b){
public void draw(Bulletc b){
super.draw(b);
Draw.color(Color.white, Pal.lancerLaser, b.fin());
//Draw.alpha(b.fout());

View File

@@ -9,6 +9,7 @@ import mindustry.entities.*;
import mindustry.entities.bullet.*;
import mindustry.entities.effect.*;
import mindustry.entities.type.*;
import mindustry.gen.*;
import mindustry.graphics.*;
import mindustry.world.*;
@@ -410,19 +411,19 @@ public class Bullets implements ContentList{
}
@Override
public void init(Bullet b){
public void init(Bulletc b){
b.velocity().setLength(0.6f + Mathf.random(2f));
}
@Override
public void draw(Bullet b){
public void draw(Bulletc b){
Draw.color(Pal.lightFlame, Pal.darkFlame, Color.gray, b.fin());
Fill.circle(b.x, b.y, 3f * b.fout());
Draw.reset();
}
@Override
public void update(Bullet b){
public void update(Bulletc b){
if(Mathf.chance(0.04 * Time.delta())){
Tile tile = world.tileWorld(b.x, b.y);
if(tile != null){
@@ -461,7 +462,7 @@ public class Bullets implements ContentList{
}
@Override
public void draw(Bullet b){
public void draw(Bulletc b){
}
};
@@ -480,7 +481,7 @@ public class Bullets implements ContentList{
}
@Override
public void draw(Bullet b){
public void draw(Bulletc b){
}
};
@@ -510,7 +511,7 @@ public class Bullets implements ContentList{
}
@Override
public void update(Bullet b){
public void update(Bulletc b){
if(b.timer.get(1, 5f)){
Damage.collideLine(b, b.getTeam(), hitEffect, b.x, b.y, b.rot(), length, true);
}
@@ -518,7 +519,7 @@ public class Bullets implements ContentList{
}
@Override
public void hit(Bullet b, float hitx, float hity){
public void hit(Bulletc b, float hitx, float hity){
hitEffect.at(colors[2], hitx, hity);
if(Mathf.chance(0.4)){
Fire.create(world.tileWorld(hitx + Mathf.range(5f), hity + Mathf.range(5f)));
@@ -526,7 +527,7 @@ public class Bullets implements ContentList{
}
@Override
public void draw(Bullet b){
public void draw(Bulletc b){
float baseLen = (length) * b.fout();
Lines.lineAngle(b.x, b.y, b.rot(), baseLen);
@@ -581,11 +582,11 @@ public class Bullets implements ContentList{
}
@Override
public void draw(Bullet b){
public void draw(Bulletc b){
}
@Override
public void init(Bullet b){
public void init(Bulletc b){
Lightning.create(b.getTeam(), Pal.lancerLaser, damage * (b.getOwner() instanceof Player ? state.rules.playerDamageMultiplier : 1f), b.x, b.y, b.rot(), 30);
}
};
@@ -634,7 +635,7 @@ public class Bullets implements ContentList{
}
@Override
public void hit(Bullet b, float x, float y){
public void hit(Bulletc b, float x, float y){
super.hit(b, x, y);
for(int i = 0; i < 3; i++){

View File

@@ -14,6 +14,7 @@ import mindustry.content.*;
import mindustry.core.GameState.*;
import mindustry.entities.*;
import mindustry.entities.type.*;
import mindustry.gen.*;
import mindustry.game.EventType.*;
import mindustry.game.*;
import mindustry.gen.*;
@@ -163,7 +164,7 @@ public class Control implements ApplicationListener, Loadable{
});
Events.on(Trigger.newGame, () -> {
TileEntity core = player.getClosestCore();
Tilec core = player.getClosestCore();
if(core == null) return;
@@ -256,7 +257,7 @@ public class Control implements ApplicationListener, Loadable{
world.loadGenerator(zone.generator);
zone.rules.get(state.rules);
state.rules.zone = zone;
for(TileEntity core : state.teams.playerCores()){
for(Tilec core : state.teams.playerCores()){
for(ItemStack stack : zone.getStartingItems()){
core.items.add(stack.item, stack.amount);
}
@@ -305,12 +306,12 @@ public class Control implements ApplicationListener, Loadable{
zone.rules.get(state.rules);
state.rules.zone = zone;
for(TileEntity core : state.teams.playerCores()){
for(Tilec core : state.teams.playerCores()){
for(ItemStack stack : zone.getStartingItems()){
core.items.add(stack.item, stack.amount);
}
}
TileEntity core = state.teams.playerCores().first();
Tilec core = state.teams.playerCores().first();
core.items.clear();
logic.play();
@@ -434,7 +435,7 @@ public class Control implements ApplicationListener, Loadable{
input.update();
if(world.isZone()){
for(TileEntity tile : state.teams.cores(player.getTeam())){
for(Tilec tile : state.teams.cores(player.getTeam())){
for(Item item : content.items()){
if(tile.items.has(item)){
data.unlockContent(item);

View File

@@ -6,8 +6,8 @@ import mindustry.annotations.Annotations.*;
import mindustry.content.*;
import mindustry.core.GameState.*;
import mindustry.ctype.*;
import mindustry.entities.*;
import mindustry.entities.type.*;
import mindustry.gen.*;
import mindustry.game.EventType.*;
import mindustry.game.*;
import mindustry.game.Teams.*;
@@ -16,7 +16,6 @@ import mindustry.type.*;
import mindustry.world.*;
import mindustry.world.blocks.*;
import mindustry.world.blocks.BuildBlock.*;
import mindustry.world.blocks.power.*;
import java.util.*;
@@ -109,10 +108,10 @@ public class Logic implements ApplicationListener{
if(!world.isZone()){
for(TeamData team : state.teams.getActive()){
if(team.hasCore()){
TileEntity entity = team.core();
entity.items.clear();
Tilec entity = team.core();
entity.getItems().clear();
for(ItemStack stack : state.rules.loadout){
entity.items.add(stack.item, stack.amount);
entity.getItems().add(stack.item, stack.amount);
}
}
}
@@ -129,8 +128,6 @@ public class Logic implements ApplicationListener{
entities.clear();
Time.clear();
TileEntity.sleepingEntities = 0;
Events.fire(new ResetEvent());
}
@@ -176,7 +173,7 @@ public class Logic implements ApplicationListener{
ui.hudfrag.showLaunch();
}
for(TileEntity tile : state.teams.playerCores()){
for(Tilec tile : state.teams.playerCores()){
Fx.launch.at(tile);
}
@@ -185,12 +182,12 @@ public class Logic implements ApplicationListener{
}
Time.runTask(30f, () -> {
for(TileEntity entity : state.teams.playerCores()){
for(Tilec entity : state.teams.playerCores()){
for(Item item : content.items()){
data.addItem(item, entity.items.get(item));
Events.fire(new LaunchItemEvent(item, entity.items.get(item)));
data.addItem(item, entity.getItems().get(item));
Events.fire(new LaunchItemEvent(item, entity.getItems().get(item)));
}
entity.tile.remove();
entity.getTile().remove();
}
state.launched = true;
state.gameOver = true;
@@ -257,7 +254,6 @@ public class Logic implements ApplicationListener{
if(!state.isEditor()){
//bulletGroup
collisions.collideGroups(bulletGroup, unitGroup);
collisions.collideGroups(bulletGroup, playerGroup);
}
}

View File

@@ -420,7 +420,7 @@ public class NetClient implements ApplicationListener{
Tile tile = world.tile(pos);
if(tile != null && tile.entity != null){
tile.entity.items.read(input);
tile.entity.getItems().read(input);
}else{
new ItemModule().read(input);
}

View File

@@ -14,6 +14,7 @@ import mindustry.core.GameState.*;
import mindustry.entities.*;
import mindustry.entities.traits.*;
import mindustry.entities.type.*;
import mindustry.gen.*;
import mindustry.entities.units.*;
import mindustry.net.Administration;
import mindustry.game.EventType.*;
@@ -688,7 +689,7 @@ public class NetServer implements ApplicationListener{
syncStream.reset();
short sent = 0;
for(TileEntity entity : tileGroup.all()){
for(Tilec entity : tileGroup.all()){
if(!entity.block.sync) continue;
sent ++;
@@ -719,7 +720,7 @@ public class NetServer implements ApplicationListener{
for(CoreEntity entity : cores){
dataStream.writeInt(entity.tile.pos());
entity.items.write(dataStream);
entity.getItems().write(dataStream);
}
dataStream.close();

View File

@@ -80,7 +80,7 @@ public class Renderer implements ApplicationListener{
Vec2 position = Tmp.v3.set(player);
if(player.isDead()){
TileEntity core = player.getClosestCore();
Tilec core = player.getClosestCore();
if(core != null){
if(player.spawner == null){
camera.position.lerpDelta(core.x, core.y, 0.08f);
@@ -279,23 +279,23 @@ public class Renderer implements ApplicationListener{
private void drawLanding(){
if(landTime > 0 && player.getClosestCore() != null){
float fract = landTime / Fx.coreLand.lifetime;
TileEntity entity = player.getClosestCore();
Tilec entity = player.getClosestCore();
TextureRegion reg = entity.block.icon(Cicon.full);
float scl = Scl.scl(4f) / camerascale;
float s = reg.getWidth() * Draw.scl * scl * 4f * fract;
Draw.color(Pal.lightTrail);
Draw.rect("circle-shadow", entity.x, entity.y, s, s);
Draw.rect("circle-shadow", entity.getX(), entity.getY(), s, s);
Angles.randLenVectors(1, (1f- fract), 100, 1000f * scl * (1f-fract), (x, y, fin, fout) -> {
Lines.stroke(scl * fin);
Lines.lineAngle(entity.x + x, entity.y + y, Mathf.angle(x, y), (fin * 20 + 1f) * scl);
Lines.lineAngle(entity.getX() + x, entity.getY() + y, Mathf.angle(x, y), (fin * 20 + 1f) * scl);
});
Draw.color();
Draw.mixcol(Color.white, fract);
Draw.rect(reg, entity.x, entity.y, reg.getWidth() * Draw.scl * scl, reg.getHeight() * Draw.scl * scl, fract * 135f);
Draw.rect(reg, entity.getX(), entity.getY(), reg.getWidth() * Draw.scl * scl, reg.getHeight() * Draw.scl * scl, fract * 135f);
Draw.reset();
}

View File

@@ -141,9 +141,9 @@ public class EditorTile extends Tile{
if(block.hasEntity()){
entity = block.newEntity().init(this, false);
entity.cons = new ConsumeModule(entity);
if(block.hasItems) entity.items = new ItemModule();
if(block.hasLiquids) entity.liquids = new LiquidModule();
if(block.hasPower) entity.power = new PowerModule();
if(block.hasItems) entity.getItems() = new ItemModule();
if(block.hasLiquids) entity.getLiquids() = new LiquidModule();
if(block.hasPower) entity.getPower() = new PowerModule();
}
}

View File

@@ -181,10 +181,10 @@ public class Damage{
if(entity.getTeam() == team || entity.dst(x, y) > radius){
return;
}
float amount = calculateDamage(x, y, entity.x, entity.y, radius, damage);
float amount = calculateDamage(x, y, entity.getX(), entity.getY(), radius, damage);
entity.damage(amount);
//TODO better velocity displacement
float dst = tr.set(entity.x - x, entity.y - y).len();
float dst = tr.set(entity.getX() - x, entity.getY() - y).len();
entity.velocity().add(tr.setLength((1f - dst / radius) * 2f / entity.mass()));
if(complete && damage >= 9999999f && entity == player){

View File

@@ -47,6 +47,10 @@ public class Effect{
Effects.createEffect(this, x, y, rotation, color, null);
}
public void at(float x, float y, Color color){
Effects.createEffect(this, x, y, 0, color, null);
}
public void at(float x, float y, float rotation, Color color, Object data){
Effects.createEffect(this, x, y, rotation, color, data);
}

View File

@@ -1,33 +0,0 @@
package mindustry.entities;
import arc.struct.*;
import mindustry.entities.traits.*;
/** Simple container for managing entity groups.*/
public class Entities{
private final Array<EntityGroup<?>> groupArray = new Array<>();
public void clear(){
for(EntityGroup group : groupArray){
group.clear();
}
}
public EntityGroup<?> get(int id){
return groupArray.get(id);
}
public Array<EntityGroup<?>> all(){
return groupArray;
}
public <T extends Entity> EntityGroup<T> add(Class<T> type){
return add(type, true);
}
public <T extends Entity> EntityGroup<T> add(Class<T> type, boolean useTree){
EntityGroup<T> group = new EntityGroup<>(groupArray.size, type, useTree);
groupArray.add(group);
return group;
}
}

View File

@@ -3,6 +3,7 @@ package mindustry.entities;
import arc.struct.Array;
import arc.math.Mathf;
import arc.math.geom.*;
import mindustry.gen.*;
import mindustry.world.Tile;
import static mindustry.Vars.tilesize;
@@ -22,9 +23,9 @@ public class EntityCollisions{
private Rect r2 = new Rect();
//entity collisions
private Array<SolidTrait> arrOut = new Array<>();
private Array<Hitboxc> arrOut = new Array<>();
public void move(SolidTrait entity, float deltax, float deltay){
public void move(Hitboxc entity, float deltax, float deltay){
boolean movedx = false;
@@ -53,8 +54,7 @@ public class EntityCollisions{
}
}
public void moveDelta(SolidTrait entity, float deltax, float deltay, boolean x){
public void moveDelta(Hitboxc entity, float deltax, float deltay, boolean x){
Rect rect = r1;
entity.hitboxTile(rect);
entity.hitboxTile(r2);
@@ -66,7 +66,7 @@ public class EntityCollisions{
for(int dx = -r; dx <= r; dx++){
for(int dy = -r; dy <= r; dy++){
int wx = dx + tilex, wy = dy + tiley;
if(solid(wx, wy) && entity.collidesGrid(wx, wy)){
if(solid(wx, wy)){
tmp.setSize(tilesize).setCenter(wx * tilesize, wy * tilesize);
if(tmp.overlaps(rect)){
@@ -106,18 +106,16 @@ public class EntityCollisions{
}
@SuppressWarnings("unchecked")
public <T extends Entity> void updatePhysics(EntityGroup<T> group){
public <T extends Hitboxc> void updatePhysics(EntityGroup<T> group){
QuadTree tree = group.tree();
tree.clear();
for(Entity entity : group.all()){
if(entity instanceof SolidTrait){
SolidTrait s = (SolidTrait)entity;
s.lastPosition().set(s.getX(), s.getY());
tree.insert(s);
}
}
group.each(s -> {
s.setLastX(s.getX());
s.setLastY(s.getY());
tree.insert(s);
});
}
private static boolean solid(int x, int y){
@@ -125,25 +123,22 @@ public class EntityCollisions{
return tile != null && tile.solid();
}
private void checkCollide(Entity entity, Entity other){
SolidTrait a = (SolidTrait)entity;
SolidTrait b = (SolidTrait)other;
private void checkCollide(Hitboxc a, Hitboxc b){
a.hitbox(this.r1);
b.hitbox(this.r2);
r1.x += (a.lastPosition().x - a.getX());
r1.y += (a.lastPosition().y - a.getY());
r2.x += (b.lastPosition().x - b.getX());
r2.y += (b.lastPosition().y - b.getY());
r1.x += (a.getLastX() - a.getX());
r1.y += (a.getLastY() - a.getY());
r2.x += (b.getLastX() - b.getX());
r2.y += (b.getLastY() - b.getY());
float vax = a.getX() - a.lastPosition().x;
float vay = a.getY() - a.lastPosition().y;
float vbx = b.getX() - b.lastPosition().x;
float vby = b.getY() - b.lastPosition().y;
float vax = a.getX() - a.getLastX();
float vay = a.getY() - a.getLastY();
float vbx = b.getX() - b.getLastX();
float vby = b.getY() - b.getLastY();
if(a != b && a.collides(b) && b.collides(a)){
if(a != b && a.collides(b)){
l1.set(a.getX(), a.getY());
boolean collide = r1.overlaps(r2) || collide(r1.x, r1.y, r1.width, r1.height, vax, vay,
r2.x, r2.y, r2.width, r2.height, vbx, vby, l1);
@@ -205,17 +200,12 @@ public class EntityCollisions{
}
@SuppressWarnings("unchecked")
public void collideGroups(EntityGroup<?> groupa, EntityGroup<?> groupb){
for(Entity entity : groupa.all()){
if(!(entity instanceof SolidTrait))
continue;
SolidTrait solid = (SolidTrait)entity;
public void collideGroups(EntityGroup<? extends Hitboxc> groupa, EntityGroup<? extends Hitboxc> groupb){
groupa.each(solid -> {
solid.hitbox(r1);
r1.x += (solid.lastPosition().x - solid.getX());
r1.y += (solid.lastPosition().y - solid.getY());
r1.x += (solid.getLastX() - solid.getX());
r1.y += (solid.getLastY() - solid.getY());
solid.hitbox(r2);
r2.merge(r1);
@@ -223,12 +213,12 @@ public class EntityCollisions{
arrOut.clear();
groupb.tree().getIntersect(arrOut, r2);
for(SolidTrait sc : arrOut){
for(Hitboxc sc : arrOut){
sc.hitbox(r1);
if(r2.overlaps(r1)){
checkCollide(entity, sc);
checkCollide(solid, sc);
}
}
}
});
}
}

View File

@@ -1,39 +1,26 @@
package mindustry.entities;
import arc.*;
import arc.struct.*;
import arc.func.*;
import arc.graphics.*;
import arc.math.geom.*;
import mindustry.entities.traits.*;
import arc.struct.*;
import mindustry.gen.*;
import java.util.*;
import static mindustry.Vars.collisions;
import static mindustry.Vars.*;
/** Represents a group of a certain type of entity.*/
@SuppressWarnings("unchecked")
public class EntityGroup<T extends Entity> implements Iterable<T>{
public class EntityGroup<T extends Entityc>{
private final boolean useTree;
private final int id;
private final Class<T> type;
private final Array<T> entityArray = new Array<>(false, 32);
private final Array<T> entitiesToRemove = new Array<>(false, 32);
private final Array<T> entitiesToAdd = new Array<>(false, 32);
private final Array<T> array = new Array<>(false, 32);
private final Array<T> intersectArray = new Array<>();
private final Rect intersectRect = new Rect();
private IntMap<T> map;
private QuadTree tree;
private Cons<T> removeListener;
private Cons<T> addListener;
private final Rect viewport = new Rect();
private int count = 0;
private int index;
public EntityGroup(int id, Class<T> type, boolean useTree){
public EntityGroup(boolean useTree){
this.useTree = useTree;
this.id = id;
this.type = type;
if(useTree){
tree = new QuadTree<>(new Rect(0, 0, 0, 0));
@@ -41,42 +28,18 @@ public class EntityGroup<T extends Entity> implements Iterable<T>{
}
public void update(){
updateEvents();
if(useTree()){
collisions.updatePhysics(this);
collisions.updatePhysics((EntityGroup<? extends Hitboxc>)this);
}
for(Entity e : all()){
e.update();
}
each(Entityc::update);
}
public int countInBounds(){
count = 0;
draw(e -> true, e -> count++);
return count;
}
public void draw(){
draw(e -> true);
}
public void draw(Boolf<T> toDraw){
draw(toDraw, t -> ((DrawTrait)t).draw());
}
public void draw(Boolf<T> toDraw, Cons<T> cons){
Camera cam = Core.camera;
viewport.set(cam.position.x - cam.width / 2, cam.position.y - cam.height / 2, cam.width, cam.height);
for(Entity e : all()){
if(!(e instanceof DrawTrait) || !toDraw.get((T)e) || !e.isAdded()) continue;
DrawTrait draw = (DrawTrait)e;
if(viewport.overlaps(draw.getX() - draw.drawSize()/2f, draw.getY() - draw.drawSize()/2f, draw.drawSize(), draw.drawSize())){
cons.get((T)e);
}
public void each(Cons<T> cons){
T[] items = array.items;
for(index = 0; index < array.size; index++){
cons.get(items[index]);
}
}
@@ -84,14 +47,6 @@ public class EntityGroup<T extends Entity> implements Iterable<T>{
return useTree;
}
public void setRemoveListener(Cons<T> removeListener){
this.removeListener = removeListener;
}
public void setAddListener(Cons<T> addListener){
this.addListener = addListener;
}
public EntityGroup<T> enableMapping(){
map = new IntMap<>();
return this;
@@ -101,40 +56,6 @@ public class EntityGroup<T extends Entity> implements Iterable<T>{
return map != null;
}
public Class<T> getType(){
return type;
}
public int getID(){
return id;
}
public void updateEvents(){
for(T e : entitiesToAdd){
if(e == null)
continue;
entityArray.add(e);
e.added();
if(map != null){
map.put(e.getID(), e);
}
}
entitiesToAdd.clear();
for(T e : entitiesToRemove){
entityArray.removeValue(e, true);
if(map != null){
map.remove(e.getID());
}
e.removed();
}
entitiesToRemove.clear();
}
public T getByID(int id){
if(map == null) throw new RuntimeException("Mapping is not enabled for group " + id + "!");
return map.get(id);
@@ -145,16 +66,6 @@ public class EntityGroup<T extends Entity> implements Iterable<T>{
T t = map.get(id);
if(t != null){ //remove if present in map already
remove(t);
}else{ //maybe it's being queued?
for(T check : entitiesToAdd){
if(check.getID() == id){ //if it is indeed queued, remove it
entitiesToAdd.removeValue(check, true);
if(removeListener != null){
removeListener.get(check);
}
break;
}
}
}
}
@@ -187,81 +98,46 @@ public class EntityGroup<T extends Entity> implements Iterable<T>{
}
public boolean isEmpty(){
return entityArray.size == 0;
return array.size == 0;
}
public int size(){
return entityArray.size;
return array.size;
}
public int count(Boolf<T> pred){
int count = 0;
for(int i = 0; i < entityArray.size; i++){
if(pred.get(entityArray.get(i))) count++;
}
return count;
return array.count(pred);
}
public void add(T type){
if(type == null) throw new RuntimeException("Cannot add a null entity!");
if(type.getGroup() != null) return;
type.setGroup(this);
entitiesToAdd.add(type);
array.add(type);
if(mappingEnabled()){
map.put(type.getID(), type);
}
if(addListener != null){
addListener.get(type);
map.put(type.getId(), type);
}
}
public void remove(T type){
if(type == null) throw new RuntimeException("Cannot remove a null entity!");
type.setGroup(null);
entitiesToRemove.add(type);
int idx = array.indexOf(type, true);
if(idx != -1){
array.remove(idx);
if(removeListener != null){
removeListener.get(type);
//fix iteration index when removing
if(index >= idx){
index --;
}
}
}
public void clear(){
for(T entity : entityArray){
entity.removed();
entity.setGroup(null);
}
for(T entity : entitiesToAdd)
entity.setGroup(null);
for(T entity : entitiesToRemove)
entity.setGroup(null);
entitiesToAdd.clear();
entitiesToRemove.clear();
entityArray.clear();
array.clear();
if(map != null)
map.clear();
}
public T find(Boolf<T> pred){
for(int i = 0; i < entityArray.size; i++){
if(pred.get(entityArray.get(i))) return entityArray.get(i);
}
return null;
}
/** Returns the array for iteration. */
public Array<T> all(){
return entityArray;
}
@Override
public Iterator<T> iterator(){
return entityArray.iterator();
return array.find(pred);
}
}

View File

@@ -54,7 +54,7 @@ public class Predict{
/**
* See {@link #intercept(float, float, float, float, float, float, float)}.
*/
public static Vec2 intercept(TargetTrait src, TargetTrait dst, float v){
public static Vec2 intercept(Teamc src, Teamc dst, float v){
return intercept(src.getX(), src.getY(), dst.getX(), dst.getY(), dst.getTargetVelocityX() - src.getTargetVelocityX()/(2f*Time.delta()), dst.getTargetVelocityY() - src.getTargetVelocityY()/(2f*Time.delta()), v);
}

View File

@@ -5,6 +5,7 @@ import arc.math.*;
import arc.math.geom.*;
import mindustry.entities.type.*;
import mindustry.game.*;
import mindustry.gen.*;
import mindustry.world.*;
import static mindustry.Vars.*;
@@ -30,17 +31,17 @@ public class Units{
* @param range The maximum distance from the target X/Y the targeter can be for it to be valid
* @return whether the target is invalid
*/
public static boolean invalidateTarget(TargetTrait target, Team team, float x, float y, float range){
public static boolean invalidateTarget(Teamc target, Team team, float x, float y, float range){
return target == null || (range != Float.MAX_VALUE && !target.withinDst(x, y, range)) || target.getTeam() == team || !target.isValid();
}
/** See {@link #invalidateTarget(TargetTrait, Team, float, float, float)} */
public static boolean invalidateTarget(TargetTrait target, Team team, float x, float y){
/** See {@link #invalidateTarget(Teamc, Team, float, float, float)} */
public static boolean invalidateTarget(Teamc target, Team team, float x, float y){
return invalidateTarget(target, team, x, y, Float.MAX_VALUE);
}
/** See {@link #invalidateTarget(TargetTrait, Team, float, float, float)} */
public static boolean invalidateTarget(TargetTrait target, Unitc targeter){
/** See {@link #invalidateTarget(Teamc, Team, float, float, float)} */
public static boolean invalidateTarget(Teamc target, Unitc targeter){
return invalidateTarget(target, targeter.getTeam(), targeter.x, targeter.y, targeter.getWeapon().bullet.range());
}
@@ -68,35 +69,35 @@ public class Units{
}
/** Returns the neareset damaged tile. */
public static TileEntity findDamagedTile(Team team, float x, float y){
public static Tilec findDamagedTile(Team team, float x, float y){
Tile tile = Geometry.findClosest(x, y, indexer.getDamaged(team));
return tile == null ? null : tile.entity;
}
/** Returns the neareset ally tile in a range. */
public static TileEntity findAllyTile(Team team, float x, float y, float range, Boolf<Tile> pred){
public static Tilec findAllyTile(Team team, float x, float y, float range, Boolf<Tile> pred){
return indexer.findTile(team, x, y, range, pred);
}
/** Returns the neareset enemy tile in a range. */
public static TileEntity findEnemyTile(Team team, float x, float y, float range, Boolf<Tile> pred){
public static Tilec findEnemyTile(Team team, float x, float y, float range, Boolf<Tile> pred){
if(team == Team.derelict) return null;
return indexer.findEnemyTile(team, x, y, range, pred);
}
/** Returns the closest target enemy. First, units are checked, then tile entities. */
public static TargetTrait closestTarget(Team team, float x, float y, float range){
public static Teamc closestTarget(Team team, float x, float y, float range){
return closestTarget(team, x, y, range, Unitc::isValid);
}
/** Returns the closest target enemy. First, units are checked, then tile entities. */
public static TargetTrait closestTarget(Team team, float x, float y, float range, Boolf<Unitc> unitPred){
public static Teamc closestTarget(Team team, float x, float y, float range, Boolf<Unitc> unitPred){
return closestTarget(team, x, y, range, unitPred, t -> true);
}
/** Returns the closest target enemy. First, units are checked, then tile entities. */
public static TargetTrait closestTarget(Team team, float x, float y, float range, Boolf<Unitc> unitPred, Boolf<Tile> tilePred){
public static Teamc closestTarget(Team team, float x, float y, float range, Boolf<Unitc> unitPred, Boolf<Tile> tilePred){
if(team == Team.derelict) return null;
Unitc unit = closestEnemy(team, x, y, range, unitPred);
@@ -152,11 +153,6 @@ public class Units{
cons.get(u);
}
});
playerGroup.intersect(x, y, width, height, player -> {
if(player.getTeam() == team){
cons.get(player);
}
});
}
/** Iterates over all units in a circle around this position. */
@@ -166,18 +162,11 @@ public class Units{
cons.get(unit);
}
});
playerGroup.intersect(x - radius, y - radius, radius*2f, radius*2f, unit -> {
if(unit.getTeam() == team && unit.withinDst(x, y, radius)){
cons.get(unit);
}
});
}
/** Iterates over all units in a rectangle. */
public static void nearby(float x, float y, float width, float height, Cons<Unitc> cons){
unitGroup.intersect(x, y, width, height, cons);
playerGroup.intersect(x, y, width, height, cons);
}
/** Iterates over all units in a rectangle. */
@@ -192,12 +181,6 @@ public class Units{
cons.get(u);
}
});
playerGroup.intersect(x, y, width, height, player -> {
if(team.isEnemy(player.getTeam())){
cons.get(player);
}
});
}
/** Iterates over all units that are enemies of this team. */
@@ -208,7 +191,6 @@ public class Units{
/** Iterates over all units. */
public static void all(Cons<Unitc> cons){
unitGroup.all().each(cons);
playerGroup.all().each(cons);
}
public static void each(Team team, Cons<BaseUnit> cons){

View File

@@ -3,7 +3,6 @@ package mindustry.entities.bullet;
import arc.graphics.g2d.*;
import mindustry.content.*;
import mindustry.entities.*;
import mindustry.entities.type.Bullet;
import mindustry.gen.*;
//TODO scale velocity depending on fslope()
@@ -24,7 +23,7 @@ public class ArtilleryBulletType extends BasicBulletType{
}
@Override
public void update(Bullet b){
public void update(Bulletc b){
super.update(b);
if(b.timer.get(0, 3 + b.fslope() * 2f)){
@@ -33,7 +32,7 @@ public class ArtilleryBulletType extends BasicBulletType{
}
@Override
public void draw(Bullet b){
public void draw(Bulletc b){
float baseScale = 0.7f;
float scale = (baseScale + b.fslope() * (1f - baseScale));

View File

@@ -4,7 +4,7 @@ import arc.Core;
import arc.graphics.Color;
import arc.graphics.g2d.Draw;
import arc.graphics.g2d.TextureRegion;
import mindustry.entities.type.Bullet;
import mindustry.gen.*;
import mindustry.graphics.Pal;
/** An extended BulletType for most ammo-based bullets shot from turrets and units. */
@@ -34,7 +34,7 @@ public class BasicBulletType extends BulletType{
}
@Override
public void draw(Bullet b){
public void draw(Bulletc b){
float height = bulletHeight * ((1f - bulletShrink) + bulletShrink * b.fout());
Draw.color(backColor);

View File

@@ -2,13 +2,16 @@ package mindustry.entities.bullet;
import arc.audio.*;
import arc.math.*;
import arc.math.geom.*;
import arc.util.*;
import arc.util.pooling.*;
import mindustry.annotations.Annotations.*;
import mindustry.content.*;
import mindustry.ctype.*;
import mindustry.entities.*;
import mindustry.entities.Effects.*;
import mindustry.entities.effect.*;
import mindustry.entities.traits.*;
import mindustry.entities.type.*;
import mindustry.game.*;
import mindustry.gen.*;
import mindustry.graphics.*;
import mindustry.type.*;
@@ -97,20 +100,20 @@ public abstract class BulletType extends Content{
return speed * lifetime * (1f - drag);
}
public boolean collides(Bullet bullet, Tile tile){
public boolean collides(Bulletc bullet, Tile tile){
return true;
}
public void hitTile(Bullet b, Tile tile){
public void hitTile(Bulletc b, Tile tile){
hit(b);
}
public void hit(Bullet b){
hit(b, b.x, b.y);
public void hit(Bulletc b){
hit(b, b.getX(), b.getY());
}
public void hit(Bullet b, float x, float y){
hitEffect.at(x, y, b.rot());
public void hit(Bulletc b, float x, float y){
hitEffect.at(x, y, b.getRotation());
hitSound.at(b);
Effects.shake(hitShake, hitShake, b);
@@ -119,7 +122,7 @@ public abstract class BulletType extends Content{
for(int i = 0; i < fragBullets; i++){
float len = Mathf.random(1f, 7f);
float a = Mathf.random(360f);
Bullet.create(fragBullet, b, x + Angles.trnsx(a, len), y + Angles.trnsy(a, len), a, Mathf.random(fragVelocityMin, fragVelocityMax));
fragBullet.create(b, x + Angles.trnsx(a, len), y + Angles.trnsy(a, len), a, Mathf.random(fragVelocityMin, fragVelocityMax));
}
}
@@ -132,8 +135,8 @@ public abstract class BulletType extends Content{
}
}
public void despawned(Bullet b){
despawnEffect.at(b.x, b.y, b.rot());
public void despawned(Bulletc b){
despawnEffect.at(b.getX(), b.getY(), b.getRotation());
hitSound.at(b);
if(fragBullet != null || splashDamageRadius > 0){
@@ -145,23 +148,23 @@ public abstract class BulletType extends Content{
}
}
public void draw(Bullet b){
public void draw(Bulletc b){
}
public void init(Bullet b){
if(killShooter && b.getOwner() instanceof HealthTrait){
((HealthTrait)b.getOwner()).kill();
public void init(Bulletc b){
if(killShooter && b.getOwner() instanceof Healthc){
((Healthc)b.getOwner()).kill();
}
if(instantDisappear){
b.time(lifetime);
b.setTime(lifetime);
}
}
public void update(Bullet b){
public void update(Bulletc b){
if(homingPower > 0.0001f){
TargetTrait target = Units.closestTarget(b.getTeam(), b.x, b.y, homingRange, e -> !e.isFlying() || collidesAir);
Teamc target = Units.closestTarget(b.getTeam(), b.x, b.y, homingRange, e -> !e.isFlying() || collidesAir);
if(target != null){
b.velocity().setAngle(Mathf.slerpDelta(b.velocity().angle(), b.angleTo(target), 0.08f));
}
@@ -172,4 +175,61 @@ public abstract class BulletType extends Content{
public ContentType getContentType(){
return ContentType.bullet;
}
//TODO change 'create' to 'at'
public Bulletc create(Teamc owner, float x, float y, float angle){
return create(owner, owner.getTeam(), x, y, angle);
}
public Bulletc create(Entityc owner, Team team, float x, float y, float angle){
return create(owner, team, x, y, angle, 1f);
}
public Bulletc create(Entityc owner, Team team, float x, float y, float angle, float velocityScl){
return create(owner, team, x, y, angle, velocityScl, 1f, null);
}
public Bulletc create(Entityc owner, Team team, float x, float y, float angle, float velocityScl, float lifetimeScl){
return create(owner, team, x, y, angle, velocityScl, lifetimeScl, null);
}
public Bulletc create(Entityc owner, Team team, float x, float y, float angle, float velocityScl, float lifetimeScl, Object data){
//TODO implement
return null;
/*
Bullet bullet = Pools.obtain(Bullet.class, Bullet::new);
bullet.type = type;
bullet.owner = owner;
bullet.data = data;
bullet.velocity.set(0, type.speed).setAngle(angle).scl(velocityScl);
if(type.keepVelocity){
bullet.velocity.add(owner instanceof VelocityTrait ? ((VelocityTrait)owner).velocity() : Vec2.ZERO);
}
bullet.team = team;
bullet.type = type;
bullet.lifeScl = lifetimeScl;
bullet.set(x - bullet.velocity.x * Time.delta(), y - bullet.velocity.y * Time.delta());
bullet.add();
return bullet;*/
}
public Bulletc create(Bulletc parent, float x, float y, float angle){
return create(parent.getOwner(), parent.getTeam(), x, y, angle);
}
public Bulletc create(Bulletc parent, float x, float y, float angle, float velocityScl){
return create(parent.getOwner(), parent.getTeam(), x, y, angle, velocityScl);
}
@Remote(called = Loc.server, unreliable = true)
public static void createBullet(BulletType type, Team team, float x, float y, float angle, float velocityScl, float lifetimeScl){
type.create(null, team, x, y, angle, velocityScl, lifetimeScl, null);
}
}

View File

@@ -4,7 +4,7 @@ import arc.math.geom.Rect;
import arc.util.Time;
import mindustry.content.Fx;
import mindustry.entities.Units;
import mindustry.entities.type.Bullet;
import mindustry.gen.*;
public class FlakBulletType extends BasicBulletType{
protected static Rect rect = new Rect();
@@ -24,7 +24,7 @@ public class FlakBulletType extends BasicBulletType{
}
@Override
public void update(Bullet b){
public void update(Bulletc b){
super.update(b);
if(b.getData() instanceof Integer) return;

View File

@@ -3,7 +3,7 @@ package mindustry.entities.bullet;
import arc.graphics.*;
import arc.graphics.g2d.*;
import mindustry.content.*;
import mindustry.entities.type.*;
import mindustry.gen.*;
import mindustry.graphics.*;
import mindustry.world.*;
import mindustry.world.blocks.*;
@@ -28,12 +28,12 @@ public class HealBulletType extends BulletType{
}
@Override
public boolean collides(Bullet b, Tile tile){
public boolean collides(Bulletc b, Tile tile){
return tile.getTeam() != b.getTeam() || tile.entity.healthf() < 1f;
}
@Override
public void draw(Bullet b){
public void draw(Bulletc b){
Draw.color(backColor);
Lines.stroke(bulletWidth);
Lines.lineAngleCenter(b.x, b.y, b.rot(), bulletHeight);
@@ -43,7 +43,7 @@ public class HealBulletType extends BulletType{
}
@Override
public void hitTile(Bullet b, Tile tile){
public void hitTile(Bulletc b, Tile tile){
super.hit(b);
tile = tile.link();

View File

@@ -6,7 +6,7 @@ import arc.math.*;
import arc.util.*;
import mindustry.content.*;
import mindustry.entities.*;
import mindustry.entities.type.*;
import mindustry.gen.*;
import mindustry.graphics.*;
public class LaserBulletType extends BulletType{
@@ -40,12 +40,12 @@ public class LaserBulletType extends BulletType{
}
@Override
public void init(Bullet b){
public void init(Bulletc b){
Damage.collideLine(b, b.getTeam(), hitEffect, b.x, b.y, b.rot(), length);
}
@Override
public void draw(Bullet b){
public void draw(Bulletc b){
float f = Mathf.curve(b.fin(), 0f, 0.2f);
float baseLen = length * f;
float cwidth = width;

View File

@@ -3,7 +3,7 @@ package mindustry.entities.bullet;
import arc.graphics.*;
import mindustry.content.*;
import mindustry.entities.effect.*;
import mindustry.entities.type.*;
import mindustry.gen.*;
import mindustry.graphics.*;
public class LightningBulletType extends BulletType{
@@ -20,11 +20,11 @@ public class LightningBulletType extends BulletType{
}
@Override
public void draw(Bullet b){
public void draw(Bulletc b){
}
@Override
public void init(Bullet b){
public void init(Bulletc b){
Lightning.create(b.getTeam(), lightningColor, damage, b.x, b.y, b.rot(), lightningLength);
}
}

View File

@@ -5,9 +5,8 @@ import arc.graphics.g2d.*;
import arc.math.geom.*;
import arc.util.ArcAnnotate.*;
import mindustry.content.*;
import mindustry.entities.*;
import mindustry.entities.effect.*;
import mindustry.entities.type.Bullet;
import mindustry.gen.*;
import mindustry.type.*;
import mindustry.world.*;
@@ -45,7 +44,7 @@ public class LiquidBulletType extends BulletType{
}
@Override
public void update(Bullet b){
public void update(Bulletc b){
super.update(b);
if(liquid.canExtinguish()){
@@ -59,14 +58,14 @@ public class LiquidBulletType extends BulletType{
}
@Override
public void draw(Bullet b){
public void draw(Bulletc b){
Draw.color(liquid.color, Color.white, b.fout() / 100f);
Fill.circle(b.x, b.y, 0.5f + b.fout() * 2.5f);
}
@Override
public void hit(Bullet b, float hitx, float hity){
public void hit(Bulletc b, float hitx, float hity){
hitEffect.at(liquid.color, hitx, hity);
Puddle.deposit(world.tileWorld(hitx, hity), liquid, puddleSize);

View File

@@ -5,7 +5,7 @@ import arc.graphics.g2d.Draw;
import arc.math.Angles;
import arc.math.Mathf;
import mindustry.content.Fx;
import mindustry.entities.type.Bullet;
import mindustry.gen.*;
import mindustry.graphics.Pal;
import mindustry.world.blocks.distribution.MassDriver.DriverBulletData;
@@ -23,7 +23,7 @@ public class MassDriverBolt extends BulletType{
}
@Override
public void draw(mindustry.entities.type.Bullet b){
public void draw(Bulletc b){
float w = 11f, h = 13f;
Draw.color(Pal.bulletYellowBack);
@@ -36,7 +36,7 @@ public class MassDriverBolt extends BulletType{
}
@Override
public void update(mindustry.entities.type.Bullet b){
public void update(Bulletc b){
//data MUST be an instance of DriverBulletData
if(!(b.getData() instanceof DriverBulletData)){
hit(b);
@@ -82,7 +82,7 @@ public class MassDriverBolt extends BulletType{
}
@Override
public void despawned(mindustry.entities.type.Bullet b){
public void despawned(Bulletc b){
super.despawned(b);
if(!(b.getData() instanceof DriverBulletData)) return;
@@ -99,7 +99,7 @@ public class MassDriverBolt extends BulletType{
}
@Override
public void hit(Bullet b, float hitx, float hity){
public void hit(Bulletc b, float hitx, float hity){
super.hit(b, hitx, hity);
despawned(b);
}

View File

@@ -4,7 +4,6 @@ import arc.graphics.Color;
import arc.math.Mathf;
import arc.util.Time;
import mindustry.content.Fx;
import mindustry.entities.type.Bullet;
import mindustry.gen.*;
import mindustry.graphics.Pal;
@@ -27,7 +26,7 @@ public class MissileBulletType extends BasicBulletType{
}
@Override
public void update(Bullet b){
public void update(Bulletc b){
super.update(b);
if(Mathf.chance(Time.delta() * 0.2)){

View File

@@ -5,6 +5,7 @@ import arc.graphics.*;
import arc.graphics.g2d.*;
import arc.math.*;
import arc.math.geom.*;
import arc.math.geom.QuadTree.*;
import arc.scene.ui.layout.*;
import arc.struct.Bits;
import arc.struct.Queue;
@@ -19,7 +20,6 @@ import mindustry.ctype.*;
import mindustry.entities.*;
import mindustry.entities.bullet.*;
import mindustry.entities.effect.*;
import mindustry.entities.type.*;
import mindustry.entities.units.*;
import mindustry.game.EventType.*;
import mindustry.game.*;
@@ -31,18 +31,19 @@ import mindustry.ui.*;
import mindustry.world.*;
import mindustry.world.blocks.*;
import mindustry.world.blocks.BuildBlock.*;
import mindustry.world.consumers.*;
import mindustry.world.modules.*;
import java.io.*;
import java.util.*;
import static mindustry.Vars.*;
import static mindustry.entities.traits.BuilderTrait.BuildDataStatic.tmptr;
@SuppressWarnings("unused")
public class EntityComps{
@Component
abstract class UnitComp implements Healthc, Velc, Statusc, Teamc, Itemsc, Hitboxc, Rotc{
abstract class UnitComp implements Healthc, Velc, Statusc, Teamc, Itemsc, Hitboxc, Rotc, Massc{
UnitDef type;
UnitController controller;
@@ -138,8 +139,8 @@ public class EntityComps{
}
@Component
abstract class BulletComp implements Timedc, Damagec, Hitboxc, Teamc{
private boolean supressCollision, supressOnce, deflected;
abstract class BulletComp implements Timedc, Damagec, Hitboxc, Teamc, Posc, Drawc, Shielderc, Ownerc, Velc, Bulletc{
private float lifeScl;
Object data;
BulletType type;
@@ -148,196 +149,91 @@ public class EntityComps{
return type.damage;
}
public void init(){
//TODO
type.init((Bulletc)this);
public void add(){
type.init(this);
setDrag(type.drag);
setHitSize(type.hitSize);
setLifetime(lifeScl * type.lifetime);
}
public void remove(){
//TODO
type.despawned((Bulletc)this);
type.despawned(this);
}
public float getLifetime(){
return type.lifetime;
}
void deflect(){
supressCollision = true;
supressOnce = true;
deflected = true;
}
public boolean isDeflected(){
return deflected;
}
public float damageMultiplier(){
if(owner instanceof Unitc){
return ((Unitc)owner).getDamageMultipler();
if(getOwner() instanceof Unitc){
return ((Unitc)getOwner()).getDamageMultiplier();
}
return 1f;
}
@Override
public void killed(Entity other){
if(owner instanceof KillerTrait){
((KillerTrait)owner).killed(other);
}
}
@Override
public void absorb(){
supressCollision = true;
//TODO
remove();
}
@Override
public float drawSize(){
public float clipSize(){
return type.drawSize;
}
@Override
public float damage(){
if(owner instanceof Lightning && data instanceof Float){
return (Float)data;
}
return type.damage * damageMultiplier();
}
@Override
public Team getTeam(){
return team;
}
@Override
public float getShieldDamage(){
return Math.max(damage(), type.splashDamage);
}
@Override
public boolean collides(SolidTrait other){
return type.collides && (other != owner && !(other instanceof DamageTrait)) && !supressCollision && !(other instanceof Unitc && ((Unitc)other).isFlying() && !type.collidesAir);
}
@Override
public void collision(SolidTrait other, float x, float y){
public void collision(Hitboxc other, float x, float y){
if(!type.pierce) remove();
type.hit(this, x, y);
if(other instanceof Unitc){
Unitc unit = (Unitc)other;
unit.velocity().add(Tmp.v3.set(other.getX(), other.getY()).sub(x, y).setLength(type.knockback / unit.mass()));
unit.applyEffect(type.status, type.statusDuration);
unit.getVel().add(Tmp.v3.set(other.getX(), other.getY()).sub(x, y).setLength(type.knockback / unit.getMass()));
unit.apply(type.status, type.statusDuration);
}
}
@Override
public void update(){
type.update(this);
x += velocity.x * Time.delta();
y += velocity.y * Time.delta();
velocity.scl(Mathf.clamp(1f - type.drag * Time.delta()));
time += Time.delta() * 1f / (lifeScl);
time = Mathf.clamp(time, 0, type.lifetime);
if(time >= type.lifetime){
if(!supressCollision) type.despawned(this);
remove();
}
if(type.hitTiles && collidesTiles() && !supressCollision && initialized){
world.raycastEach(world.toTile(lastPosition().x), world.toTile(lastPosition().y), world.toTile(x), world.toTile(y), (x, y) -> {
if(type.hitTiles){
world.raycastEach(world.toTile(getLastX()), world.toTile(getLastY()), tileX(), tileY(), (x, y) -> {
Tile tile = world.ltile(x, y);
if(tile == null) return false;
if(tile.entity != null && tile.entity.collide(this) && type.collides(this, tile) && !tile.entity.isDead() && (type.collidesTeam || tile.getTeam() != team)){
if(tile.getTeam() != team){
if(tile.entity != null && tile.entity.collide(this) && type.collides(this, tile) && !tile.entity.isDead() && (type.collidesTeam || tile.getTeam() != getTeam())){
if(tile.getTeam() != getTeam()){
tile.entity.collision(this);
}
if(!supressCollision){
type.hitTile(this, tile);
remove();
}
type.hitTile(this, tile);
remove();
return true;
}
return false;
});
}
if(supressOnce){
supressCollision = false;
supressOnce = false;
}
initialized = true;
}
@Override
public void reset(){
type = null;
owner = null;
velocity.setZero();
time = 0f;
timer.clear();
lifeScl = 1f;
team = null;
data = null;
supressCollision = false;
supressOnce = false;
deflected = false;
initialized = false;
}
@Override
public void hitbox(Rect rect){
rect.setSize(type.hitSize).setCenter(x, y);
}
@Override
public void hitboxTile(Rect rect){
rect.setSize(type.hitSize).setCenter(x, y);
}
@Override
public void draw(){
type.draw(this);
renderer.lights.add(x, y, 16f, Pal.powerLight, 0.3f);
}
@Override
public float fin(){
return time / type.lifetime;
}
@Override
public Vec2 velocity(){
return velocity;
}
public void velocity(float speed, float angle){
velocity.set(0, speed).setAngle(angle);
}
public void limit(float f){
velocity.limit(f);
//TODO refactor
renderer.lights.add(getX(), getY(), 16f, Pal.powerLight, 0.3f);
}
/** Sets the bullet's rotation in degrees. */
public void rot(float angle){
velocity.setAngle(angle);
public void setRotation(float angle){
getVel().setAngle(angle);
}
/** @return the bullet's rotation. */
public float rot(){
float angle = Mathf.atan2(velocity.x, velocity.y) * Mathf.radiansToDegrees;
public float getRotation(){
float angle = Mathf.atan2(getVel().x, getVel().y) * Mathf.radiansToDegrees;
if(angle < 0) angle += 360;
return angle;
}
@@ -491,17 +387,218 @@ public class EntityComps{
}
@Component
abstract class TileComp implements Posc, Teamc{
static abstract class TileComp implements Posc, Teamc, Healthc, Tilec{
static final float timeToSleep = 60f * 1;
static final ObjectSet<Tile> tmpTiles = new ObjectSet<>();
static int sleepingEntities = 0;
Tile tile;
Block block;
Array<Tile> proximity = new Array<>(8);
PowerModule power;
ItemModule items;
LiquidModule liquids;
ConsumeModule cons;
private Interval timer;
private float timeScale = 1f, timeScaleDuration;
private @Nullable SoundLoop sound;
private boolean sleeping;
private float sleepTime;
/** Sets this tile entity data to this tile, and adds it if necessary. */
public Tilec init(Tile tile, boolean shouldAdd){
this.tile = tile;
this.block = tile.block();
set(tile.drawx(), tile.drawy());
if(block.activeSound != Sounds.none){
sound = new SoundLoop(block.activeSound, block.activeSoundVolume);
}
setHealth(block.health);
setMaxHealth(block.health);
timer = new Interval(block.timers);
if(shouldAdd){
add();
}
return this;
}
public float getTimeScale(){
return timeScale;
}
public boolean consValid(){
return cons.valid();
}
public void consume(){
cons.trigger();
}
public boolean timer(int id, float time){
return timer.get(id, time);
}
/** Scaled delta. */
public float delta(){
return Time.delta() * timeScale;
}
/** Base efficiency. If this entity has non-buffered power, returns the power %, otherwise returns 1. */
public float efficiency(){
return power != null && (block.consumes.has(ConsumeType.power) && !block.consumes.getPower().buffered) ? power.status : 1f;
}
/** Call when nothing is happening to the entity. This increments the internal sleep timer. */
public void sleep(){
sleepTime += Time.delta();
if(!sleeping && sleepTime >= timeToSleep){
remove();
sleeping = true;
sleepingEntities++;
}
}
/** Call when this entity is updating. This wakes it up. */
public void noSleep(){
sleepTime = 0f;
if(sleeping){
add();
sleeping = false;
sleepingEntities--;
}
}
/** Returns the version of this TileEntity IO code.*/
public byte version(){
return 0;
}
public boolean collide(Bulletc other){
return true;
}
public void collision(Bulletc other){
block.handleBulletHit(this, other);
}
//TODO Implement damage!
public void removeFromProximity(){
block.onProximityRemoved(tile);
Point2[] nearby = Edges.getEdges(block.size);
for(Point2 point : nearby){
Tile other = world.ltile(tile.x + point.x, tile.y + point.y);
//remove this tile from all nearby tile's proximities
if(other != null){
other.block().onProximityUpdate(other);
if(other.entity != null){
other.entity.getProximity().remove(tile, true);
}
}
}
}
public void updateProximity(){
tmpTiles.clear();
proximity.clear();
Point2[] nearby = Edges.getEdges(block.size);
for(Point2 point : nearby){
Tile other = world.ltile(tile.x + point.x, tile.y + point.y);
if(other == null) continue;
if(other.entity == null || !(other.interactable(tile.getTeam()))) continue;
//add this tile to proximity of nearby tiles
if(!other.entity.getProximity().contains(tile, true)){
other.entity.getProximity().add(tile);
}
tmpTiles.add(other);
}
//using a set to prevent duplicates
for(Tile tile : tmpTiles){
proximity.add(tile);
}
block.onProximityAdded(tile);
block.onProximityUpdate(tile);
for(Tile other : tmpTiles){
other.block().onProximityUpdate(other);
}
}
public Array<Tile> proximity(){
return proximity;
}
/** Tile configuration. Defaults to 0. Used for block rebuilding. */
public int config(){
return 0;
}
public void remove(){
if(sound != null){
sound.stop();
}
}
public void killed(){
Events.fire(new BlockDestroyEvent(tile));
block.breakSound.at(tile);
block.onDestroyed(tile);
tile.remove();
}
public void update(){
timeScaleDuration -= Time.delta();
if(timeScaleDuration <= 0f || !block.canOverdrive){
timeScale = 1f;
}
if(sound != null){
sound.update(getX(), getY(), block.shouldActiveSound(tile));
}
if(block.idleSound != Sounds.none && block.shouldIdleSound(tile)){
loops.play(block.idleSound, this, block.idleSoundVolume);
}
block.update(tile);
if(liquids != null){
liquids.update();
}
if(cons != null){
cons.update();
}
if(power != null){
power.graph.update();
}
}
}
@Component
abstract class TeamComp implements Posc{
abstract class TeamComp implements Posc, Healthc{
transient float x, y;
Team team = Team.sharded;
public @Nullable TileEntity getClosestCore(){
public @Nullable Tilec getClosestCore(){
return state.teams.closestCore(x, y, team);
}
}
@@ -838,14 +935,14 @@ public class EntityComps{
}
void updateMining(){
TileEntity core = getClosestCore();
Tilec core = getClosestCore();
if(core != null && mineTile != null && mineTile.drop() != null && !acceptsItem(mineTile.drop()) && dst(core) < mineTransferRange){
int accepted = core.tile.block().acceptStack(item(), getStack().amount, core.tile, this);
int accepted = core.getTile().block().acceptStack(item(), getStack().amount, core.getTile(), this);
if(accepted > 0){
Call.transferItemTo(item(), accepted,
mineTile.worldx() + Mathf.range(tilesize / 2f),
mineTile.worldy() + Mathf.range(tilesize / 2f), core.tile);
mineTile.worldy() + Mathf.range(tilesize / 2f), core.getTile());
clearItem();
}
}
@@ -859,10 +956,10 @@ public class EntityComps{
if(Mathf.chance(Time.delta() * (0.06 - item.hardness * 0.01) * getMiningSpeed())){
if(dst(core) < mineTransferRange && core.tile.block().acceptStack(item, 1, core.tile, this) == 1 && offloadImmediately()){
if(dst(core) < mineTransferRange && core.getTile().block().acceptStack(item, 1, core.getTile(), this) == 1 && offloadImmediately()){
Call.transferItemTo(item, 1,
mineTile.worldx() + Mathf.range(tilesize / 2f),
mineTile.worldy() + Mathf.range(tilesize / 2f), core.tile);
mineTile.worldy() + Mathf.range(tilesize / 2f), core.getTile());
}else if(acceptsItem(item)){
//this is clientside, since items are synced anyway
ItemTransfer.transferItemToUnit(item,
@@ -927,7 +1024,7 @@ public class EntityComps{
}
}
TileEntity core = getClosestCore();
Tilec core = getClosestCore();
//nothing to build.
if(buildRequest() == null) return;
@@ -996,10 +1093,10 @@ public class EntityComps{
}
/** @return whether this request should be skipped, in favor of the next one. */
boolean shouldSkip(BuildRequest request, @Nullable TileEntity core){
boolean shouldSkip(BuildRequest request, @Nullable Tilec core){
//requests that you have at least *started* are considered
if(state.rules.infiniteResources || request.breaking || !request.initialized || core == null) return false;
return request.stuck && !core.items.has(request.block.requirements);
return request.stuck && !core.getItems().has(request.block.requirements);
}
void removeBuild(int x, int y, boolean breaking){
@@ -1163,7 +1260,7 @@ public class EntityComps{
}
@Component
abstract class HitboxComp implements Posc{
abstract class HitboxComp implements Posc, QuadTreeObject{
transient float x, y;
float hitSize;
@@ -1178,7 +1275,7 @@ public class EntityComps{
lastY = y;
}
void collision(Hitboxc other){
void collision(Hitboxc other, float x, float y){
}
@@ -1194,6 +1291,15 @@ public class EntityComps{
return Intersector.overlapsRect(x - hitSize/2f, y - hitSize/2f, hitSize, hitSize,
other.getX() - other.getHitSize()/2f, other.getY() - other.getHitSize()/2f, other.getHitSize(), other.getHitSize());
}
public void hitbox(Rect rect){
rect.setCentered(x, y, hitSize, hitSize);
}
public void hitboxTile(Rect rect){
float scale = 0.6f;
rect.setCentered(x, y, hitSize * scale, hitSize * scale);
}
}
@Component
@@ -1201,9 +1307,9 @@ public class EntityComps{
private Array<StatusEntry> statuses = new Array<>();
private Bits applied = new Bits(content.getBy(ContentType.status).size);
private float speedMultiplier;
private float damageMultiplier;
private float armorMultiplier;
float speedMultiplier;
float damageMultiplier;
float armorMultiplier;
/** @return damage taken based on status armor multipliers */
float getDamage(float amount){
@@ -1329,10 +1435,11 @@ public class EntityComps{
@Component
@BaseComponent
class EntityComp{
private boolean added;
int id;
boolean isAdded(){
return true;
return added;
}
void init(){}
@@ -1340,11 +1447,11 @@ public class EntityComps{
void update(){}
void remove(){
added = false;
}
void add(){
added = true;
}
boolean isLocal(){

View File

@@ -7,4 +7,7 @@ class EntityDefs{
@EntityDef({BulletComp.class, VelComp.class, TimedComp.class})
class BulletDef{}
@EntityDef({TileComp.class})
class TileDef{}
}

View File

@@ -0,0 +1,4 @@
package mindustry.entities.def;
public class EntityGroupDefs{
}

View File

@@ -8,7 +8,7 @@ import arc.math.geom.*;
import arc.util.*;
import mindustry.content.*;
import mindustry.entities.*;
import mindustry.entities.type.*;
import mindustry.gen.*;
import mindustry.game.EventType.*;
import mindustry.game.*;
import mindustry.gen.*;
@@ -119,7 +119,7 @@ public class Fire extends TimedEntity implements SaveTrait, SyncTrait{
return;
}
TileEntity entity = tile.link().entity;
Tilec entity = tile.link().entity;
boolean damage = entity != null;
float flammability = baseFlammability + puddleFlammability;

View File

@@ -4,7 +4,7 @@ import arc.math.Mathf;
import arc.util.Time;
import mindustry.Vars;
import mindustry.entities.Effects;
import mindustry.entities.Effects.Effect;
import mindustry.entities.*;
import mindustry.entities.Effects.EffectRenderer;
import mindustry.world.Tile;

View File

@@ -42,11 +42,11 @@ public class ItemTransfer extends TimedEntity implements DrawTrait{
@Remote(called = Loc.server, unreliable = true)
public static void transferItemTo(Item item, int amount, float x, float y, Tile tile){
if(tile == null || tile.entity == null || tile.entity.items == null) return;
if(tile == null || tile.entity == null || tile.entity.getItems() == null) return;
for(int i = 0; i < Mathf.clamp(amount / 3, 1, 8); i++){
Time.run(i * 3, () -> create(item, x, y, tile, () -> {}));
}
tile.entity.items.add(item, amount);
tile.entity.getItems().add(item, amount);
}
public static void create(Item item, float fromx, float fromy, Position to, Runnable done){

View File

@@ -12,7 +12,6 @@ import arc.util.pooling.Pools;
import mindustry.content.Bullets;
import mindustry.entities.EntityGroup;
import mindustry.entities.Units;
import mindustry.entities.type.Bullet;
import mindustry.game.Team;
import mindustry.gen.Call;
import mindustry.graphics.Pal;

View File

@@ -1,350 +0,0 @@
package mindustry.entities.type;
import arc.*;
import mindustry.annotations.Annotations.*;
import arc.graphics.g2d.*;
import arc.math.*;
import arc.math.geom.*;
import arc.util.*;
import arc.util.ArcAnnotate.*;
import mindustry.*;
import mindustry.content.*;
import mindustry.ctype.ContentType;
import mindustry.entities.*;
import mindustry.entities.units.*;
import mindustry.game.EventType.*;
import mindustry.game.*;
import mindustry.gen.*;
import mindustry.type.*;
import mindustry.type.TypeID;
import mindustry.ui.Cicon;
import mindustry.world.*;
import mindustry.world.blocks.*;
import mindustry.world.blocks.defense.DeflectorWall.*;
import mindustry.world.blocks.units.CommandCenter.*;
import mindustry.world.blocks.units.UnitFactory.*;
import mindustry.world.meta.*;
import java.io.*;
import static mindustry.Vars.*;
/** Base class for AI units. */
public abstract class BaseUnit extends Unitc implements ShooterTrait{
protected static int timerIndex = 0;
protected static final int timerTarget = timerIndex++;
protected static final int timerTarget2 = timerIndex++;
protected boolean loaded;
protected UnitDef type;
protected Interval timer = new Interval(5);
protected StateMachine state = new StateMachine();
protected TargetTrait target;
protected int spawner = noSpawner;
/** internal constructor used for deserialization, DO NOT USE */
public BaseUnit(){
}
@Remote(called = Loc.server)
public static void onUnitDeath(BaseUnit unit){
if(unit == null) return;
if(net.server() || !net.active()){
UnitDrops.dropItems(unit);
}
unit.onSuperDeath();
unit.type.deathSound.at(unit);
//visual only.
if(net.client()){
Tile tile = world.tile(unit.spawner);
if(tile != null){
tile.block().unitRemoved(tile, unit);
}
unit.spawner = noSpawner;
}
//must run afterwards so the unit's group is not null when sending the removal packet
Core.app.post(unit::remove);
}
@Override
public TypeID getTypeID(){
return type.typeID;
}
@Override
public void onHit(SolidTrait entity){
if(entity instanceof Bullet && ((Bullet)entity).getOwner() instanceof DeflectorEntity && player != null && getTeam() != player.getTeam()){
Core.app.post(() -> {
if(isDead()){
Events.fire(Trigger.phaseDeflectHit);
}
});
}
}
public @Nullable
Tile getSpawner(){
return world.tile(spawner);
}
public boolean isCommanded(){
return indexer.getAllied(team, BlockFlag.comandCenter).size != 0 && indexer.getAllied(team, BlockFlag.comandCenter).first().entity instanceof CommandCenterEntity;
}
public @Nullable UnitCommand getCommand(){
if(isCommanded()){
return indexer.getAllied(team, BlockFlag.comandCenter).first().<CommandCenterEntity>ent().command;
}
return null;
}
/**Called when a command is recieved from the command center.*/
public void onCommand(UnitCommand command){
}
/** Initialize the type and team of this unit. Only call once! */
public void init(UnitDef type, Team team){
if(this.type != null) throw new RuntimeException("This unit is already initialized!");
this.type = type;
this.team = team;
}
/** @return whether this unit counts toward the enemy amount in the wave UI. */
public boolean countsAsEnemy(){
return true;
}
public void setSpawner(Tile tile){
this.spawner = tile.pos();
}
public void rotate(float angle){
rotation = Mathf.slerpDelta(rotation, angle, type.rotateSpeed);
}
public boolean targetHasFlag(BlockFlag flag){
return (target instanceof TileEntity && ((TileEntity)target).tile.block().flags.contains(flag)) ||
(target instanceof Tile && ((Tile)target).block().flags.contains(flag));
}
public void setState(UnitState state){
this.state.set(state);
}
public boolean retarget(){
return timer.get(timerTarget, 20);
}
/** Only runs when the unit has a target. */
public void behavior(){
}
public void updateTargeting(){
if(target == null || (target instanceof Unitc && (target.isDead() || target.getTeam() == team))
|| (target instanceof TileEntity && ((TileEntity)target).tile.entity == null)){
target = null;
}
}
public void targetClosestAllyFlag(BlockFlag flag){
Tile target = Geometry.findClosest(x, y, indexer.getAllied(team, flag));
if(target != null) this.target = target.entity;
}
public void targetClosestEnemyFlag(BlockFlag flag){
Tile target = Geometry.findClosest(x, y, indexer.getEnemy(team, flag));
if(target != null) this.target = target.entity;
}
public void targetClosest(){
TargetTrait newTarget = Units.closestTarget(team, x, y, type.range, u -> type.targetAir || !u.isFlying());
if(newTarget != null){
target = newTarget;
}
}
public @Nullable Tile getClosest(BlockFlag flag){
return Geometry.findClosest(x, y, indexer.getAllied(team, flag));
}
public @Nullable Tile getClosestSpawner(){
return Geometry.findClosest(x, y, Vars.spawner.getGroundSpawns());
}
public @Nullable TileEntity getClosestEnemyCore(){
return Vars.state.teams.closestEnemyCore(x, y, team);
}
public UnitState getStartState(){
return null;
}
public boolean isBoss(){
return hasEffect(StatusEffects.boss);
}
@Override
public float getDamageMultipler(){
return status.getDamageMultiplier() * Vars.state.rules.unitDamageMultiplier;
}
@Override
public TextureRegion getIconRegion(){
return type.icon(Cicon.full);
}
@Override
public void interpolate(){
super.interpolate();
if(interpolator.values.length > 0){
rotation = interpolator.values[0];
}
}
@Override
public float maxHealth(){
return type.health * Vars.state.rules.unitHealthMultiplier;
}
@Override
public void update(){
if(isDead()){
//dead enemies should get immediately removed
remove();
return;
}
hitTime -= Time.delta();
if(net.client()){
interpolate();
status.update(this);
return;
}
if(!isFlying() && (world.tileWorld(x, y) != null && !(world.tileWorld(x, y).block() instanceof BuildBlock) && world.tileWorld(x, y).solid())){
kill();
}
avoidOthers();
if(spawner != noSpawner && (world.tile(spawner) == null || !(world.tile(spawner).entity instanceof UnitFactoryEntity))){
kill();
}
updateTargeting();
state.update();
updateVelocityStatus();
if(target != null) behavior();
if(!isFlying()){
clampPosition();
}
}
@Override
public void draw(){
}
@Override
public void removed(){
super.removed();
Tile tile = world.tile(spawner);
if(tile != null && !net.client()){
tile.block().unitRemoved(tile, this);
}
spawner = noSpawner;
}
@Override
public float drawSize(){
return type.hitsize * 10;
}
@Override
public void onDeath(){
Call.onUnitDeath(this);
}
@Override
public void added(){
state.set(getStartState());
if(!loaded){
health(maxHealth());
}
if(isCommanded()){
onCommand(getCommand());
}
}
@Override
public EntityGroup targetGroup(){
return unitGroup;
}
@Override
public byte version(){
return 0;
}
@Override
public void writeSave(DataOutput stream) throws IOException{
super.writeSave(stream);
stream.writeByte(type.id);
stream.writeInt(spawner);
}
@Override
public void readSave(DataInput stream, byte version) throws IOException{
super.readSave(stream, version);
loaded = true;
byte type = stream.readByte();
this.spawner = stream.readInt();
this.type = content.getByID(ContentType.unit, type);
add();
}
@Override
public void write(DataOutput data) throws IOException{
super.writeSave(data);
data.writeByte(type.id);
data.writeInt(spawner);
}
@Override
public void read(DataInput data) throws IOException{
float lastx = x, lasty = y, lastrot = rotation;
super.readSave(data, version());
this.type = content.getByID(ContentType.unit, data.readByte());
this.spawner = data.readInt();
interpolator.read(lastx, lasty, x, y, rotation);
rotation = lastrot;
x = lastx;
y = lasty;
}
public void onSuperDeath(){
super.onDeath();
}
}

View File

@@ -1,322 +0,0 @@
package mindustry.entities.type;
import mindustry.annotations.Annotations.*;
import arc.math.*;
import arc.math.geom.*;
import arc.util.*;
import arc.util.pooling.Pool.*;
import arc.util.pooling.*;
import mindustry.entities.*;
import mindustry.entities.bullet.*;
import mindustry.entities.effect.*;
import mindustry.game.*;
import mindustry.graphics.*;
import mindustry.world.*;
import static mindustry.Vars.*;
public class Bullet extends SolidEntity implements DamageTrait, Scaled, Poolable, DrawTrait, VelocityTrait, TimeTrait, TeamTrait, AbsorbTrait{
public Interval timer = new Interval(3);
private float lifeScl;
private Team team;
private Object data;
private boolean supressCollision, supressOnce, initialized, deflected;
protected BulletType type;
protected Entity owner;
protected float time;
/** Internal use only! */
public Bullet(){
}
public static Bullet create(BulletType type, TeamTrait owner, float x, float y, float angle){
return create(type, owner, owner.getTeam(), x, y, angle);
}
public static Bullet create(BulletType type, Entity owner, Team team, float x, float y, float angle){
return create(type, owner, team, x, y, angle, 1f);
}
public static Bullet create(BulletType type, Entity owner, Team team, float x, float y, float angle, float velocityScl){
return create(type, owner, team, x, y, angle, velocityScl, 1f, null);
}
public static Bullet create(BulletType type, Entity owner, Team team, float x, float y, float angle, float velocityScl, float lifetimeScl){
return create(type, owner, team, x, y, angle, velocityScl, lifetimeScl, null);
}
public static Bullet create(BulletType type, Entity owner, Team team, float x, float y, float angle, float velocityScl, float lifetimeScl, Object data){
Bullet bullet = Pools.obtain(Bullet.class, Bullet::new);
bullet.type = type;
bullet.owner = owner;
bullet.data = data;
bullet.velocity.set(0, type.speed).setAngle(angle).scl(velocityScl);
if(type.keepVelocity){
bullet.velocity.add(owner instanceof VelocityTrait ? ((VelocityTrait)owner).velocity() : Vec2.ZERO);
}
bullet.team = team;
bullet.type = type;
bullet.lifeScl = lifetimeScl;
bullet.set(x - bullet.velocity.x * Time.delta(), y - bullet.velocity.y * Time.delta());
bullet.add();
return bullet;
}
public static Bullet create(BulletType type, Bullet parent, float x, float y, float angle){
return create(type, parent.owner, parent.team, x, y, angle);
}
public static Bullet create(BulletType type, Bullet parent, float x, float y, float angle, float velocityScl){
return create(type, parent.owner, parent.team, x, y, angle, velocityScl);
}
@Remote(called = Loc.server, unreliable = true)
public static void createBullet(BulletType type, Team team, float x, float y, float angle, float velocityScl, float lifetimeScl){
create(type, null, team, x, y, angle, velocityScl, lifetimeScl, null);
}
public Entity getOwner(){
return owner;
}
public boolean collidesTiles(){
return type.collidesTiles;
}
public void deflect(){
supressCollision = true;
supressOnce = true;
deflected = true;
}
public boolean isDeflected(){
return deflected;
}
public BulletType getBulletType(){
return type;
}
public void resetOwner(Entity entity, Team team){
this.owner = entity;
this.team = team;
}
public void scaleTime(float add){
time += add;
}
public Object getData(){
return data;
}
public void setData(Object data){
this.data = data;
}
public float damageMultiplier(){
if(owner instanceof Unitc){
return ((Unitc)owner).getDamageMultipler();
}
return 1f;
}
@Override
public void killed(Entity other){
if(owner instanceof KillerTrait){
((KillerTrait)owner).killed(other);
}
}
@Override
public void absorb(){
supressCollision = true;
remove();
}
@Override
public float drawSize(){
return type.drawSize;
}
@Override
public float damage(){
if(owner instanceof Lightning && data instanceof Float){
return (Float)data;
}
return type.damage * damageMultiplier();
}
@Override
public Team getTeam(){
return team;
}
@Override
public float getShieldDamage(){
return Math.max(damage(), type.splashDamage);
}
@Override
public boolean collides(SolidTrait other){
return type.collides && (other != owner && !(other instanceof DamageTrait)) && !supressCollision && !(other instanceof Unitc && ((Unitc)other).isFlying() && !type.collidesAir);
}
@Override
public void collision(SolidTrait other, float x, float y){
if(!type.pierce) remove();
type.hit(this, x, y);
if(other instanceof Unitc){
Unitc unit = (Unitc)other;
unit.velocity().add(Tmp.v3.set(other.getX(), other.getY()).sub(x, y).setLength(type.knockback / unit.mass()));
unit.applyEffect(type.status, type.statusDuration);
}
}
@Override
public void update(){
type.update(this);
x += velocity.x * Time.delta();
y += velocity.y * Time.delta();
velocity.scl(Mathf.clamp(1f - type.drag * Time.delta()));
time += Time.delta() * 1f / (lifeScl);
time = Mathf.clamp(time, 0, type.lifetime);
if(time >= type.lifetime){
if(!supressCollision) type.despawned(this);
remove();
}
if(type.hitTiles && collidesTiles() && !supressCollision && initialized){
world.raycastEach(world.toTile(lastPosition().x), world.toTile(lastPosition().y), world.toTile(x), world.toTile(y), (x, y) -> {
Tile tile = world.ltile(x, y);
if(tile == null) return false;
if(tile.entity != null && tile.entity.collide(this) && type.collides(this, tile) && !tile.entity.isDead() && (type.collidesTeam || tile.getTeam() != team)){
if(tile.getTeam() != team){
tile.entity.collision(this);
}
if(!supressCollision){
type.hitTile(this, tile);
remove();
}
return true;
}
return false;
});
}
if(supressOnce){
supressCollision = false;
supressOnce = false;
}
initialized = true;
}
@Override
public void reset(){
type = null;
owner = null;
velocity.setZero();
time = 0f;
timer.clear();
lifeScl = 1f;
team = null;
data = null;
supressCollision = false;
supressOnce = false;
deflected = false;
initialized = false;
}
@Override
public void hitbox(Rect rect){
rect.setSize(type.hitSize).setCenter(x, y);
}
@Override
public void hitboxTile(Rect rect){
rect.setSize(type.hitSize).setCenter(x, y);
}
@Override
public float lifetime(){
return type.lifetime;
}
@Override
public void time(float time){
this.time = time;
}
@Override
public float time(){
return time;
}
@Override
public void removed(){
Pools.free(this);
}
@Override
public EntityGroup targetGroup(){
return bulletGroup;
}
@Override
public void added(){
type.init(this);
}
@Override
public void draw(){
type.draw(this);
renderer.lights.add(x, y, 16f, Pal.powerLight, 0.3f);
}
@Override
public float fin(){
return time / type.lifetime;
}
@Override
public Vec2 velocity(){
return velocity;
}
public void velocity(float speed, float angle){
velocity.set(0, speed).setAngle(angle);
}
public void limit(float f){
velocity.limit(f);
}
/** Sets the bullet's rotation in degrees. */
public void rot(float angle){
velocity.setAngle(angle);
}
/** @return the bullet's rotation. */
public float rot(){
float angle = Mathf.atan2(velocity.x, velocity.y) * Mathf.radiansToDegrees;
if(angle < 0) angle += 360;
return angle;
}
}

View File

@@ -59,8 +59,8 @@ public class Player extends Unitc implements BuilderMinerTrait, ShooterTrait{
public @Nullable NetConnection con;
public boolean isLocal = false;
public Interval timer = new Interval(6);
public TargetTrait target;
public TargetTrait moveTarget;
public Teamc target;
public Teamc moveTarget;
public @Nullable String lastText;
public float textFadeTime;
@@ -604,7 +604,7 @@ public class Player extends Unitc implements BuilderMinerTrait, ShooterTrait{
protected void updateTouch(){
if(Units.invalidateTarget(target, this) &&
!(target instanceof TileEntity && ((TileEntity)target).damaged() && target.isValid() && target.getTeam() == team && mech.canHeal && dst(target) < mech.range && !(((TileEntity)target).block instanceof BuildBlock))){
!(target instanceof Tilec && ((Tilec)target).damaged() && target.isValid() && target.getTeam() == team && mech.canHeal && dst(target) < mech.range && !(((Tilec)target).block instanceof BuildBlock))){
target = null;
}
@@ -619,7 +619,7 @@ public class Player extends Unitc implements BuilderMinerTrait, ShooterTrait{
if(moveTarget != null && !moveTarget.isDead()){
targetX = moveTarget.getX();
targetY = moveTarget.getY();
boolean tapping = moveTarget instanceof TileEntity && moveTarget.getTeam() == team;
boolean tapping = moveTarget instanceof Tilec && moveTarget.getTeam() == team;
attractDst = 0f;
if(tapping){
@@ -628,7 +628,7 @@ public class Player extends Unitc implements BuilderMinerTrait, ShooterTrait{
if(dst(moveTarget) <= 2f * Time.delta()){
if(tapping && !isDead()){
Tile tile = ((TileEntity)moveTarget).tile;
Tile tile = ((Tilec)moveTarget).tile;
tile.block().tapped(tile, this);
}
@@ -695,7 +695,7 @@ public class Player extends Unitc implements BuilderMinerTrait, ShooterTrait{
setMineTile(null);
}
}
}else if(target.isValid() || (target instanceof TileEntity && ((TileEntity)target).damaged() && target.getTeam() == team && mech.canHeal && dst(target) < mech.range)){
}else if(target.isValid() || (target instanceof Tilec && ((Tilec)target).damaged() && target.getTeam() == team && mech.canHeal && dst(target) < mech.range)){
//rotate toward and shoot the target
if(mech.faceTarget){
rotation = Mathf.slerpDelta(rotation, angleTo(target), 0.2f);

View File

@@ -6,10 +6,8 @@ import arc.Events;
import arc.struct.Array;
import arc.struct.ObjectSet;
import arc.math.geom.Point2;
import arc.math.geom.Vec2;
import arc.util.*;
import arc.util.ArcAnnotate.*;
import mindustry.entities.EntityGroup;
import mindustry.game.*;
import mindustry.game.EventType.BlockDestroyEvent;
import mindustry.gen.*;
@@ -21,7 +19,7 @@ import java.io.*;
import static mindustry.Vars.*;
public class TileEntity{
public class Tilec__{
public static final float timeToSleep = 60f * 1; //1 second to fall asleep
private static final ObjectSet<Tile> tmpTiles = new ObjectSet<>();
/** This value is only used for debugging. */
@@ -63,7 +61,7 @@ public class TileEntity{
}
/** Sets this tile entity data to this tile, and adds it if necessary. */
public TileEntity init(Tile tile, boolean shouldAdd){
public Tilec init(Tile tile, boolean shouldAdd){
this.tile = tile;
x = tile.drawx();
y = tile.drawy();
@@ -148,11 +146,11 @@ public class TileEntity{
return 0;
}
public boolean collide(Bullet other){
public boolean collide(Bulletc other){
return true;
}
public void collision(Bullet other){
public void collision(Bulletc other){
block.handleBulletHit(this, other);
}

View File

@@ -39,7 +39,7 @@ public class BuilderDrone extends BaseDrone implements BuilderTrait{
public void update(){
BuildEntity entity = (BuildEntity)target;
TileEntity core = getClosestCore();
Tilec core = getClosestCore();
if(isBuilding() && entity == null && canRebuild()){
target = world.tile(buildRequest().x, buildRequest().y);
@@ -97,7 +97,7 @@ public class BuilderDrone extends BaseDrone implements BuilderTrait{
}
}else{
incDrones(playerTarget);
TargetTrait prev = target;
Teamc prev = target;
target = playerTarget;
float dst = 90f + (id % 10)*3;
float tdst = dst(target);

View File

@@ -12,7 +12,6 @@ import mindustry.entities.bullet.*;
import mindustry.entities.type.*;
import mindustry.entities.units.*;
import mindustry.game.*;
import mindustry.type.*;
import mindustry.world.*;
import mindustry.world.blocks.*;
import mindustry.world.meta.*;
@@ -34,7 +33,7 @@ public class GroundUnit extends BaseUnit{
}
public void update(){
TileEntity core = getClosestEnemyCore();
Tilec core = getClosestEnemyCore();
if(core == null){
Tile closestSpawn = getClosestSpawner();
@@ -251,7 +250,7 @@ public class GroundUnit extends BaseUnit{
Tile tile = world.tileWorld(x, y);
if(tile == null) return;
Tile targetTile = pathfinder.getTargetTile(tile, enemy, PathTarget.enemyCores);
TileEntity core = getClosestCore();
Tilec core = getClosestCore();
if(tile == targetTile || core == null || dst(core) < 120f) return;

View File

@@ -3,7 +3,7 @@ package mindustry.entities.type.base;
import arc.math.Mathf;
import arc.util.Structs;
import mindustry.content.Blocks;
import mindustry.entities.type.TileEntity;
import mindustry.gen.*;
import mindustry.entities.units.UnitState;
import mindustry.gen.Call;
import mindustry.type.Item;
@@ -28,7 +28,7 @@ public class MinerDrone extends BaseDrone implements MinerTrait{
}
public void update(){
TileEntity entity = getClosestCore();
Tilec entity = getClosestCore();
if(entity == null) return;
@@ -90,7 +90,7 @@ public class MinerDrone extends BaseDrone implements MinerTrait{
if(target == null) return;
TileEntity tile = (TileEntity)target;
Tilec tile = (Tilec)target;
if(dst(target) < type.range){
if(tile.tile.block().acceptStack(item.item, item.amount, tile.tile, MinerDrone.this) > 0){
@@ -169,10 +169,10 @@ public class MinerDrone extends BaseDrone implements MinerTrait{
}
protected void findItem(){
TileEntity entity = getClosestCore();
Tilec entity = getClosestCore();
if(entity == null){
return;
}
targetItem = Structs.findMin(type.toMine, indexer::hasOre, (a, b) -> -Integer.compare(entity.items.get(a), entity.items.get(b)));
targetItem = Structs.findMin(type.toMine, indexer::hasOre, (a, b) -> -Integer.compare(entity.getItems().get(a), entity.getItems().get(b)));
}
}

View File

@@ -1,7 +1,7 @@
package mindustry.entities.type.base;
import mindustry.entities.Units;
import mindustry.entities.type.TileEntity;
import mindustry.gen.*;
import mindustry.entities.units.UnitState;
import mindustry.world.Pos;
import mindustry.world.Tile;
@@ -24,7 +24,7 @@ public class RepairDrone extends BaseDrone{
target = Units.findDamagedTile(team, x, y);
}
if(target instanceof TileEntity && ((TileEntity)target).block instanceof BuildBlock){
if(target instanceof Tilec && ((Tilec)target).block instanceof BuildBlock){
target = null;
}
@@ -58,7 +58,7 @@ public class RepairDrone extends BaseDrone{
@Override
public void write(DataOutput data) throws IOException{
super.write(data);
data.writeInt(state.is(repair) && target instanceof TileEntity ? ((TileEntity)target).tile.pos() : Pos.invalid);
data.writeInt(state.is(repair) && target instanceof Tilec ? ((Tilec)target).tile.pos() : Pos.invalid);
}
@Override

View File

@@ -3,8 +3,7 @@ package mindustry.entities.units;
import arc.math.Mathf;
import mindustry.Vars;
import mindustry.content.Items;
import mindustry.entities.type.BaseUnit;
import mindustry.entities.type.TileEntity;
import mindustry.gen.*;
import mindustry.gen.Call;
import mindustry.type.Item;
import static mindustry.Vars.*;
@@ -18,7 +17,7 @@ public class UnitDrops{
return;
}
TileEntity core = unit.getClosestEnemyCore();
Tilec core = unit.getClosestEnemyCore();
if(core == null || core.dst(unit) > Vars.mineTransferRange){
return;

View File

@@ -311,7 +311,7 @@ public class Saves{
public void delete(){
file.delete();
saves.removeValue(this, true);
saves.remove(this, true);
if(this == current){
current = null;
}

View File

@@ -5,7 +5,6 @@ import arc.util.serialization.Json.Serializable;
import arc.util.serialization.JsonValue;
import mindustry.content.*;
import mindustry.ctype.ContentType;
import mindustry.entities.type.BaseUnit;
import mindustry.type.*;
import static mindustry.Vars.content;

View File

@@ -54,10 +54,10 @@ public class Teams{
return false;
}
public void eachEnemyCore(Team team, Cons<TileEntity> ret){
public void eachEnemyCore(Team team, Cons<Tilec> ret){
for(TeamData data : active){
if(areEnemies(team, data.team)){
for(TileEntity tile : data.cores){
for(Tilec tile : data.cores){
ret.get(tile);
}
}

View File

@@ -240,7 +240,7 @@ public class Tutorial{
//utility
static void placeBlocks(){
TileEntity core = state.teams.playerCores().first();
Tilec core = state.teams.playerCores().first();
for(int i = 0; i < blocksToBreak; i++){
world.ltile(core.tile.x + blockOffset, core.tile.y + i).remove();
world.tile(core.tile.x + blockOffset, core.tile.y + i).setBlock(Blocks.scrapWall, state.rules.defaultTeam);
@@ -248,7 +248,7 @@ public class Tutorial{
}
static boolean blocksBroken(){
TileEntity core = state.teams.playerCores().first();
Tilec core = state.teams.playerCores().first();
for(int i = 0; i < blocksToBreak; i++){
if(world.tile(core.tile.x + blockOffset, core.tile.y + i).block() == Blocks.scrapWall){

View File

@@ -233,7 +233,7 @@ public class BlockRenderer implements Disposable{
addRequest(tile, block.layer2);
}
if(tile.entity != null && tile.entity.power != null && tile.entity.power.links.size > 0){
if(tile.entity != null && tile.entity.getPower() != null && tile.entity.getPower().links.size > 0){
for(Tile other : block.getPowerConnections(tile, outArray)){
if(other.block().layer == Layer.power){
addRequest(other, Layer.power);

View File

@@ -132,7 +132,7 @@ public abstract class InputHandler implements InputProcessor, GestureListener{
ItemTransfer.create(item,
player.x + Angles.trnsx(player.rotation + 180f, backTrns), player.y + Angles.trnsy(player.rotation + 180f, backTrns),
new Vec2(tile.drawx() + stackTrns.x, tile.drawy() + stackTrns.y), () -> {
if(tile.block() != block || tile.entity == null || tile.entity.items == null) return;
if(tile.block() != block || tile.entity == null || tile.entity.getItems() == null) return;
tile.block().handleStack(item, removed, tile, player);
remaining[1] -= removed;
@@ -595,7 +595,7 @@ public abstract class InputHandler implements InputProcessor, GestureListener{
if(tile.interactable(player.getTeam()) && tile.block().consumesTap){
consumed = true;
}else if(tile.interactable(player.getTeam()) && tile.block().synthetic() && !consumed){
if(tile.block().hasItems && tile.entity.items.total() > 0){
if(tile.block().hasItems && tile.entity.getItems().total() > 0){
frag.inv.showFor(tile);
consumed = true;
showedInventory = true;

View File

@@ -16,11 +16,10 @@ import mindustry.*;
import mindustry.content.*;
import mindustry.core.GameState.*;
import mindustry.entities.*;
import mindustry.entities.type.*;
import mindustry.gen.*;
import mindustry.entities.units.*;
import mindustry.game.EventType.*;
import mindustry.game.*;
import mindustry.gen.*;
import mindustry.graphics.*;
import mindustry.ui.*;
import mindustry.world.*;
@@ -45,7 +44,7 @@ public class MobileInput extends InputHandler implements GestureListener{
private float lineScale;
/** Animation data for crosshair. */
private float crosshairScale;
private TargetTrait lastTarget;
private Teamc lastTarget;
/** Used for shifting build requests. */
private float shiftDeltaX, shiftDeltaY;
@@ -77,7 +76,7 @@ public class MobileInput extends InputHandler implements GestureListener{
Tile tile = world.ltileWorld(x, y);
if(tile != null && tile.synthetic() && player.getTeam().isEnemy(tile.getTeam())){
TileEntity entity = tile.entity;
Tilec entity = tile.entity;
player.setMineTile(null);
player.target = entity;
}else if(tile != null && player.mech.canHeal && tile.entity != null && tile.getTeam() == player.getTeam() && tile.entity.damaged()){
@@ -155,7 +154,7 @@ public class MobileInput extends InputHandler implements GestureListener{
}
void removeRequest(BuildRequest request){
selectRequests.removeValue(request, true);
selectRequests.remove(request, true);
if(!request.breaking){
removals.add(request);
}
@@ -376,7 +375,7 @@ public class MobileInput extends InputHandler implements GestureListener{
}
}
TargetTrait target = player.target;
Teamc target = player.target;
//draw targeting crosshair
if(target != null && !state.isEditor()){

View File

@@ -5,8 +5,7 @@ import mindustry.annotations.Annotations.WriteClass;
import arc.graphics.Color;
import mindustry.ctype.ContentType;
import mindustry.entities.Effects;
import mindustry.entities.Effects.Effect;
import mindustry.entities.type.Bullet;
import mindustry.entities.*;
import mindustry.entities.bullet.BulletType;
import mindustry.entities.units.BuildRequest;
import mindustry.entities.type.*;

View File

@@ -1,7 +1,6 @@
package mindustry.io.versions;
import arc.func.Prov;
import mindustry.entities.type.Bullet;
import mindustry.entities.effect.*;
import mindustry.entities.type.Player;
import mindustry.entities.type.base.*;

View File

@@ -111,7 +111,7 @@ public class MapGenerator extends Generator{
if(tile.block() instanceof StorageBlock && !(tile.block() instanceof CoreBlock) && world.getZone() != null){
for(Item item : world.getZone().resources){
if(Mathf.chance(0.3)){
tile.entity.items.add(item, Math.min(Mathf.random(500), tile.block().itemCapacity));
tile.entity.getItems().add(item, Math.min(Mathf.random(500), tile.block().itemCapacity));
}
}
}

View File

@@ -190,7 +190,7 @@ public class Administration{
}
}
bannedIPs.removeValue(ip, false);
bannedIPs.remove(ip, false);
if(found){
save();

View File

@@ -1,24 +1,15 @@
package mindustry.type;
import arc.*;
import mindustry.annotations.Annotations.*;
import arc.audio.*;
import arc.graphics.g2d.*;
import arc.math.*;
import arc.util.*;
import arc.util.ArcAnnotate.*;
import mindustry.*;
import mindustry.content.*;
import mindustry.entities.*;
import mindustry.entities.Effects.*;
import mindustry.entities.bullet.*;
import mindustry.entities.traits.*;
import mindustry.entities.type.*;
import mindustry.entities.type.Bullet;
import mindustry.gen.*;
import static mindustry.Vars.net;
public class Weapon{
/** displayed weapon region */
public String name;

View File

@@ -157,7 +157,7 @@ public class JoinDialog extends FloatingDialog{
inner.addImageButton(Icon.trash, Styles.emptyi, () -> {
ui.showConfirm("$confirm", "$server.delete", () -> {
servers.removeValue(server, true);
servers.remove(server, true);
saveServers();
setupRemote();
refreshRemote();

View File

@@ -71,7 +71,7 @@ public class BlockInventoryFragment extends Fragment{
return;
}
this.tile = t;
if(tile == null || tile.entity == null || !tile.block().isAccessible() || tile.entity.items.total() == 0)
if(tile == null || tile.entity == null || !tile.block().isAccessible() || tile.entity.getItems().total() == 0)
return;
rebuild(true);
}
@@ -98,14 +98,14 @@ public class BlockInventoryFragment extends Fragment{
table.touchable(Touchable.enabled);
table.update(() -> {
if(state.is(State.menu) || tile == null || tile.entity == null || !tile.block().isAccessible() || tile.entity.items.total() == 0){
if(state.is(State.menu) || tile == null || tile.entity == null || !tile.block().isAccessible() || tile.entity.getItems().total() == 0){
hide();
}else{
if(holding && lastItem != null){
holdTime += Time.delta();
if(holdTime >= holdWithdraw){
int amount = Math.min(tile.entity.items.get(lastItem), player.maxAccepted(lastItem));
int amount = Math.min(tile.entity.getItems().get(lastItem), player.maxAccepted(lastItem));
Call.requestItem(player, tile, lastItem, amount);
holding = false;
holdTime = 0f;
@@ -117,7 +117,7 @@ public class BlockInventoryFragment extends Fragment{
updateTablePosition();
if(tile.block().hasItems){
for(int i = 0; i < content.items().size; i++){
boolean has = tile.entity.items.has(content.item(i));
boolean has = tile.entity.getItems().has(content.item(i));
if(has != container.contains(i)){
rebuild(false);
}
@@ -136,7 +136,7 @@ public class BlockInventoryFragment extends Fragment{
for(int i = 0; i < content.items().size; i++){
Item item = content.item(i);
if(!tile.entity.items.has(item)) continue;
if(!tile.entity.getItems().has(item)) continue;
container.add(i);
@@ -149,14 +149,14 @@ public class BlockInventoryFragment extends Fragment{
if(tile == null || tile.entity == null){
return "";
}
return round(tile.entity.items.get(item));
return round(tile.entity.getItems().get(item));
});
image.addListener(l);
image.addListener(new InputListener(){
@Override
public boolean touchDown(InputEvent event, float x, float y, int pointer, KeyCode button){
if(!canPick.get() || tile == null || tile.entity == null || tile.entity.items == null || !tile.entity.items.has(item)) return false;
if(!canPick.get() || tile == null || tile.entity == null || tile.entity.getItems() == null || !tile.entity.getItems().has(item)) return false;
int amount = Math.min(1, player.maxAccepted(item));
if(amount > 0){
Call.requestItem(player, tile, item, amount);

View File

@@ -12,7 +12,7 @@ import arc.scene.ui.layout.*;
import arc.struct.*;
import arc.util.*;
import mindustry.content.*;
import mindustry.entities.type.*;
import mindustry.gen.*;
import mindustry.entities.units.*;
import mindustry.game.EventType.*;
import mindustry.gen.*;
@@ -220,7 +220,7 @@ public class PlacementFragment extends Fragment{
button.resizeImage(Cicon.medium.size);
button.update(() -> { //color unplacable things gray
TileEntity core = player.getClosestCore();
Tilec core = player.getClosestCore();
Color color = state.rules.infiniteResources || (core != null && (core.items.has(block.requirements, state.rules.buildCostMultiplier) || state.rules.infiniteResources)) ? Color.white : Color.gray;
button.forEach(elem -> elem.setColor(color));
button.setChecked(control.input.block == block);
@@ -308,7 +308,7 @@ public class PlacementFragment extends Fragment{
line.addImage(stack.item.icon(Cicon.small)).size(8 * 2);
line.add(stack.item.localizedName).maxWidth(140f).fillX().color(Color.lightGray).padLeft(2).left().get().setEllipsis(true);
line.labelWrap(() -> {
TileEntity core = player.getClosestCore();
Tilec core = player.getClosestCore();
if(core == null || state.rules.infiniteResources) return "*/*";
int amount = core.items.get(stack.item);

View File

@@ -1,12 +1,9 @@
package mindustry.world;
import arc.*;
import mindustry.annotations.Annotations.*;
import arc.Graphics.*;
import arc.Graphics.Cursor.*;
import arc.audio.*;
import arc.struct.EnumSet;
import arc.struct.*;
import arc.func.*;
import arc.graphics.*;
import arc.graphics.g2d.*;
@@ -14,11 +11,13 @@ import arc.graphics.g2d.TextureAtlas.*;
import arc.math.*;
import arc.math.geom.*;
import arc.scene.ui.layout.*;
import arc.struct.EnumSet;
import arc.struct.*;
import arc.util.*;
import arc.util.ArcAnnotate.*;
import arc.util.pooling.*;
import mindustry.annotations.Annotations.*;
import mindustry.ctype.*;
import mindustry.ctype.ContentType;
import mindustry.entities.*;
import mindustry.entities.effect.*;
import mindustry.entities.type.*;
@@ -145,7 +144,7 @@ public class Block extends BlockStorage{
protected TextureRegion[] cacheRegions = {};
protected Array<String> cacheRegionStrings = new Array<>();
protected Prov<TileEntity> entityType = TileEntity::new;
protected Prov<TileData> entityType = TileData::new;
protected Array<Tile> tempTiles = new Array<>();
protected TextureRegion[] generatedIcons;
@@ -177,7 +176,7 @@ public class Block extends BlockStorage{
}
public void onProximityRemoved(Tile tile){
if(tile.entity.power != null){
if(tile.entity.getPower() != null){
tile.block().powerGraphRemoved(tile);
}
}
@@ -187,49 +186,49 @@ public class Block extends BlockStorage{
}
protected void updatePowerGraph(Tile tile){
TileEntity entity = tile.ent();
Tilec entity = tile.ent();
for(Tile other : getPowerConnections(tile, tempTiles)){
if(other.entity.power != null){
other.entity.power.graph.add(entity.power.graph);
if(other.entity.getPower() != null){
other.entity.getPower().graph.add(entity.getPower().graph);
}
}
}
protected void powerGraphRemoved(Tile tile){
if(tile.entity == null || tile.entity.power == null){
if(tile.entity == null || tile.entity.getPower() == null){
return;
}
tile.entity.power.graph.remove(tile);
for(int i = 0; i < tile.entity.power.links.size; i++){
Tile other = world.tile(tile.entity.power.links.get(i));
if(other != null && other.entity != null && other.entity.power != null){
other.entity.power.links.removeValue(tile.pos());
tile.entity.getPower().graph.remove(tile);
for(int i = 0; i < tile.entity.getPower().links.size; i++){
Tile other = world.tile(tile.entity.getPower().links.get(i));
if(other != null && other.entity != null && other.entity.getPower() != null){
other.entity.getPower().links.removeValue(tile.pos());
}
}
}
public Array<Tile> getPowerConnections(Tile tile, Array<Tile> out){
out.clear();
if(tile == null || tile.entity == null || tile.entity.power == null) return out;
if(tile == null || tile.entity == null || tile.entity.getPower() == null) return out;
for(Tile other : tile.entity.proximity()){
if(other != null && other.entity != null && other.entity.power != null
if(other != null && other.entity != null && other.entity.getPower() != null
&& !(consumesPower && other.block().consumesPower && !outputsPower && !other.block().outputsPower)
&& !tile.entity.power.links.contains(other.pos())){
&& !tile.entity.getPower().links.contains(other.pos())){
out.add(other);
}
}
for(int i = 0; i < tile.entity.power.links.size; i++){
Tile link = world.tile(tile.entity.power.links.get(i));
if(link != null && link.entity != null && link.entity.power != null) out.add(link);
for(int i = 0; i < tile.entity.getPower().links.size; i++){
Tile link = world.tile(tile.entity.getPower().links.get(i));
if(link != null && link.entity != null && link.entity.getPower() != null) out.add(link);
}
return out;
}
protected float getProgressIncrease(TileEntity entity, float baseTime){
protected float getProgressIncrease(Tilec entity, float baseTime){
return 1f / baseTime * entity.delta() * entity.efficiency();
}
@@ -301,8 +300,8 @@ public class Block extends BlockStorage{
}
public void drawLight(Tile tile){
if(tile.entity != null && hasLiquids && drawLiquidLight && tile.entity.liquids.current().lightColor.a > 0.001f){
drawLiquidLight(tile, tile.entity.liquids.current(), tile.entity.liquids.smoothAmount());
if(tile.entity != null && hasLiquids && drawLiquidLight && tile.entity.getLiquids().current().lightColor.a > 0.001f){
drawLiquidLight(tile, tile.entity.getLiquids().current(), tile.entity.getLiquids().smoothAmount());
}
}
@@ -340,14 +339,14 @@ public class Block extends BlockStorage{
Geometry.circle(tile.x, tile.y, range, (x, y) -> {
Tile other = world.ltile(x, y);
if(other != null && other.block instanceof PowerNode && ((PowerNode)other.block).linkValid(other, tile) && !PowerNode.insulated(other, tile) && !other.entity.proximity().contains(tile) &&
!(outputsPower && tile.entity.proximity().contains(p -> p.entity != null && p.entity.power != null && p.entity.power.graph == other.entity.power.graph))){
!(outputsPower && tile.entity.proximity().contains(p -> p.entity != null && p.entity.getPower() != null && p.entity.getPower().graph == other.entity.getPower().graph))){
tempTiles.add(other);
}
});
tempTiles.sort(Structs.comparingFloat(t -> t.dst2(tile)));
if(!tempTiles.isEmpty()){
Tile toLink = tempTiles.first();
if(!toLink.entity.power.links.contains(tile.pos())){
if(!toLink.entity.getPower().links.contains(tile.pos())){
toLink.configureAny(tile.pos());
}
}
@@ -543,15 +542,15 @@ public class Block extends BlockStorage{
bars.add("health", entity -> new Bar("blocks.health", Pal.health, entity::healthf).blink(Color.white));
if(hasLiquids){
Func<TileEntity, Liquid> current;
Func<Tilec, Liquid> current;
if(consumes.has(ConsumeType.liquid) && consumes.get(ConsumeType.liquid) instanceof ConsumeLiquid){
Liquid liquid = consumes.<ConsumeLiquid>get(ConsumeType.liquid).liquid;
current = entity -> liquid;
}else{
current = entity -> entity.liquids.current();
current = entity -> entity.getLiquids().current();
}
bars.add("liquid", entity -> new Bar(() -> entity.liquids.get(current.get(entity)) <= 0.001f ? Core.bundle.get("bar.liquid") : current.get(entity).localizedName,
() -> current.get(entity).barColor(), () -> entity.liquids.get(current.get(entity)) / liquidCapacity));
bars.add("liquid", entity -> new Bar(() -> entity.getLiquids().get(current.get(entity)) <= 0.001f ? Core.bundle.get("bar.liquid") : current.get(entity).localizedName,
() -> current.get(entity).barColor(), () -> entity.getLiquids().get(current.get(entity)) / liquidCapacity));
}
if(hasPower && consumes.hasPower()){
@@ -559,12 +558,12 @@ public class Block extends BlockStorage{
boolean buffered = cons.buffered;
float capacity = cons.capacity;
bars.add("power", entity -> new Bar(() -> buffered ? Core.bundle.format("bar.poweramount", Float.isNaN(entity.power.status * capacity) ? "<ERROR>" : (int)(entity.power.status * capacity)) :
Core.bundle.get("bar.power"), () -> Pal.powerBar, () -> Mathf.zero(cons.requestedPower(entity)) && entity.power.graph.getPowerProduced() + entity.power.graph.getBatteryStored() > 0f ? 1f : entity.power.status));
bars.add("power", entity -> new Bar(() -> buffered ? Core.bundle.format("bar.poweramount", Float.isNaN(entity.getPower().status * capacity) ? "<ERROR>" : (int)(entity.getPower().status * capacity)) :
Core.bundle.get("bar.power"), () -> Pal.powerBar, () -> Mathf.zero(cons.requestedPower(entity)) && entity.getPower().graph.getPowerProduced() + entity.getPower().graph.getBatteryStored() > 0f ? 1f : entity.getPower().status));
}
if(hasItems && configurable){
bars.add("items", entity -> new Bar(() -> Core.bundle.format("bar.items", entity.items.total()), () -> Pal.items, () -> (float)entity.items.total() / itemCapacity));
bars.add("items", entity -> new Bar(() -> Core.bundle.format("bar.items", entity.getItems().total()), () -> Pal.items, () -> (float)entity.getItems().total() / itemCapacity));
}
}
@@ -589,7 +588,7 @@ public class Block extends BlockStorage{
return amount;
}
public void handleBulletHit(TileEntity entity, Bullet bullet){
public void handleBulletHit(Tilec entity, Bulletc bullet){
entity.damage(bullet.damage());
}
@@ -609,24 +608,24 @@ public class Block extends BlockStorage{
if(hasItems){
for(Item item : content.items()){
int amount = tile.entity.items.get(item);
int amount = tile.entity.getItems().get(item);
explosiveness += item.explosiveness * amount;
flammability += item.flammability * amount;
}
}
if(hasLiquids){
flammability += tile.entity.liquids.sum((liquid, amount) -> liquid.explosiveness * amount / 2f);
explosiveness += tile.entity.liquids.sum((liquid, amount) -> liquid.flammability * amount / 2f);
flammability += tile.entity.getLiquids().sum((liquid, amount) -> liquid.explosiveness * amount / 2f);
explosiveness += tile.entity.getLiquids().sum((liquid, amount) -> liquid.flammability * amount / 2f);
}
if(consumes.hasPower() && consumes.getPower().buffered){
power += tile.entity.power.status * consumes.getPower().capacity;
power += tile.entity.getPower().status * consumes.getPower().capacity;
}
if(hasLiquids){
tile.entity.liquids.each((liquid, amount) -> {
tile.entity.getLiquids().each((liquid, amount) -> {
float splash = Mathf.clamp(amount / 4f, 0f, 10f);
for(int i = 0; i < Mathf.clamp(amount / 5, 0, 30); i++){
@@ -657,10 +656,10 @@ public class Block extends BlockStorage{
}
return 0;
}else{
float result = tile.entity.items.sum((item, amount) -> item.flammability * amount);
float result = tile.entity.getItems().sum((item, amount) -> item.flammability * amount);
if(hasLiquids){
result += tile.entity.liquids.sum((liquid, amount) -> liquid.flammability * amount / 3f);
result += tile.entity.getLiquids().sum((liquid, amount) -> liquid.flammability * amount / 3f);
}
return result;
@@ -676,7 +675,7 @@ public class Block extends BlockStorage{
}
public void display(Tile tile, Table table){
TileEntity entity = tile.entity;
Tilec entity = tile.entity;
if(entity != null){
table.table(bars -> {
@@ -702,7 +701,7 @@ public class Block extends BlockStorage{
}
public void displayBars(Tile tile, Table table){
for(Func<TileEntity, Bar> bar : bars.list()){
for(Func<Tilec, Bar> bar : bars.list()){
table.add(bar.get(tile.entity)).growX();
table.row();
}
@@ -857,7 +856,7 @@ public class Block extends BlockStorage{
return destructible || update;
}
public final TileEntity newEntity(){
public final TileData newData(){
return entityType.get();
}

View File

@@ -8,7 +8,7 @@ import mindustry.*;
import mindustry.content.*;
import mindustry.ctype.*;
import mindustry.entities.effect.*;
import mindustry.entities.type.*;
import mindustry.gen.*;
import mindustry.gen.*;
import mindustry.type.*;
import mindustry.world.consumers.*;
@@ -50,7 +50,7 @@ public abstract class BlockStorage extends UnlockableContent{
/** Returns the amount of items this block can accept. */
public int acceptStack(Item item, int amount, Tile tile, Teamc source){
if(acceptItem(item, tile, tile) && hasItems && (source == null || source.getTeam() == tile.getTeam())){
return Math.min(getMaximumAccepted(tile, item) - tile.entity.items.get(item), amount);
return Math.min(getMaximumAccepted(tile, item) - tile.entity.getItems().get(item), amount);
}else{
return 0;
}
@@ -62,17 +62,17 @@ public abstract class BlockStorage extends UnlockableContent{
/** Remove a stack from this inventory, and return the amount removed. */
public int removeStack(Tile tile, Item item, int amount){
if(tile.entity == null || tile.entity.items == null) return 0;
amount = Math.min(amount, tile.entity.items.get(item));
if(tile.entity == null || tile.entity.getItems() == null) return 0;
amount = Math.min(amount, tile.entity.getItems().get(item));
tile.entity.noSleep();
tile.entity.items.remove(item, amount);
tile.entity.getItems().remove(item, amount);
return amount;
}
/** Handle a stack input. */
public void handleStack(Item item, int amount, Tile tile, Teamc source){
tile.entity.noSleep();
tile.entity.items.add(item, amount);
tile.entity.getItems().add(item, amount);
}
public boolean outputsItems(){
@@ -89,19 +89,19 @@ public abstract class BlockStorage extends UnlockableContent{
}
public void handleItem(Item item, Tile tile, Tile source){
tile.entity.items.add(item, 1);
tile.entity.getItems().add(item, 1);
}
public boolean acceptItem(Item item, Tile tile, Tile source){
return consumes.itemFilters.get(item.id) && tile.entity.items.get(item) < getMaximumAccepted(tile, item);
return consumes.itemFilters.get(item.id) && tile.entity.getItems().get(item) < getMaximumAccepted(tile, item);
}
public boolean acceptLiquid(Tile tile, Tile source, Liquid liquid, float amount){
return hasLiquids && tile.entity.liquids.get(liquid) + amount < liquidCapacity && consumes.liquidfilters.get(liquid.id);
return hasLiquids && tile.entity.getLiquids().get(liquid) + amount < liquidCapacity && consumes.liquidfilters.get(liquid.id);
}
public void handleLiquid(Tile tile, Tile source, Liquid liquid, float amount){
tile.entity.liquids.add(liquid, amount);
tile.entity.getLiquids().add(liquid, amount);
}
public void tryDumpLiquid(Tile tile, Liquid liquid){
@@ -115,9 +115,9 @@ public abstract class BlockStorage extends UnlockableContent{
other = other.block().getLiquidDestination(other, in, liquid);
if(other != null && other.getTeam() == tile.getTeam() && other.block().hasLiquids && canDumpLiquid(tile, other, liquid) && other.entity.liquids != null){
float ofract = other.entity.liquids.get(liquid) / other.block().liquidCapacity;
float fract = tile.entity.liquids.get(liquid) / liquidCapacity;
if(other != null && other.getTeam() == tile.getTeam() && other.block().hasLiquids && canDumpLiquid(tile, other, liquid) && other.entity.getLiquids() != null){
float ofract = other.entity.getLiquids().get(liquid) / other.block().liquidCapacity;
float fract = tile.entity.getLiquids().get(liquid) / liquidCapacity;
if(ofract < fract) tryMoveLiquid(tile, in, other, (fract - ofract) * liquidCapacity / 2f, liquid);
}
@@ -130,11 +130,11 @@ public abstract class BlockStorage extends UnlockableContent{
}
public void tryMoveLiquid(Tile tile, Tile tileSource, Tile next, float amount, Liquid liquid){
float flow = Math.min(next.block().liquidCapacity - next.entity.liquids.get(liquid) - 0.001f, amount);
float flow = Math.min(next.block().liquidCapacity - next.entity.getLiquids().get(liquid) - 0.001f, amount);
if(next.block().acceptLiquid(next, tileSource, liquid, flow)){
next.block().handleLiquid(next, tileSource, liquid, flow);
tile.entity.liquids.remove(liquid, flow);
tile.entity.getLiquids().remove(liquid, flow);
}
}
@@ -148,20 +148,20 @@ public abstract class BlockStorage extends UnlockableContent{
next = next.link();
next = next.block().getLiquidDestination(next, tile, liquid);
if(next.getTeam() == tile.getTeam() && next.block().hasLiquids && tile.entity.liquids.get(liquid) > 0f){
if(next.getTeam() == tile.getTeam() && next.block().hasLiquids && tile.entity.getLiquids().get(liquid) > 0f){
if(next.block().acceptLiquid(next, tile, liquid, 0f)){
float ofract = next.entity.liquids.get(liquid) / next.block().liquidCapacity;
float fract = tile.entity.liquids.get(liquid) / liquidCapacity * liquidPressure;
float flow = Math.min(Mathf.clamp((fract - ofract) * (1f)) * (liquidCapacity), tile.entity.liquids.get(liquid));
flow = Math.min(flow, next.block().liquidCapacity - next.entity.liquids.get(liquid) - 0.001f);
float ofract = next.entity.getLiquids().get(liquid) / next.block().liquidCapacity;
float fract = tile.entity.getLiquids().get(liquid) / liquidCapacity * liquidPressure;
float flow = Math.min(Mathf.clamp((fract - ofract) * (1f)) * (liquidCapacity), tile.entity.getLiquids().get(liquid));
flow = Math.min(flow, next.block().liquidCapacity - next.entity.getLiquids().get(liquid) - 0.001f);
if(flow > 0f && ofract <= fract && next.block().acceptLiquid(next, tile, liquid, flow)){
next.block().handleLiquid(next, tile, liquid, flow);
tile.entity.liquids.remove(liquid, flow);
tile.entity.getLiquids().remove(liquid, flow);
return flow;
}else if(ofract > 0.1f && fract > 0.1f){
Liquid other = next.entity.liquids.current();
Liquid other = next.entity.getLiquids().current();
if((other.flammability > 0.3f && liquid.temperature > 0.7f) || (liquid.flammability > 0.3f && other.temperature > 0.7f)){
tile.entity.damage(1 * Time.delta());
next.entity.damage(1 * Time.delta());
@@ -169,7 +169,7 @@ public abstract class BlockStorage extends UnlockableContent{
Fx.fire.at((tile.worldx() + next.worldx()) / 2f, (tile.worldy() + next.worldy()) / 2f);
}
}else if((liquid.temperature > 0.7f && other.temperature < 0.55f) || (other.temperature > 0.7f && liquid.temperature < 0.55f)){
tile.entity.liquids.remove(liquid, Math.min(tile.entity.liquids.get(liquid), 0.7f * Time.delta()));
tile.entity.getLiquids().remove(liquid, Math.min(tile.entity.getLiquids().get(liquid), 0.7f * Time.delta()));
if(Mathf.chance(0.2f * Time.delta())){
Fx.steam.at((tile.worldx() + next.worldx()) / 2f, (tile.worldy() + next.worldy()) / 2f);
}
@@ -177,9 +177,9 @@ public abstract class BlockStorage extends UnlockableContent{
}
}
}else if(leakResistance != 100f && !next.block().solid && !next.block().hasLiquids){
float leakAmount = tile.entity.liquids.get(liquid) / leakResistance;
float leakAmount = tile.entity.getLiquids().get(liquid) / leakResistance;
Puddle.deposit(next, tile, liquid, leakAmount);
tile.entity.liquids.remove(liquid, leakAmount);
tile.entity.getLiquids().remove(liquid, leakAmount);
}
return 0;
}
@@ -219,8 +219,8 @@ public abstract class BlockStorage extends UnlockableContent{
* @param todump Item to dump. Can be null to dump anything.
*/
public boolean tryDump(Tile tile, Item todump){
TileEntity entity = tile.entity;
if(entity == null || !hasItems || tile.entity.items.total() == 0 || (todump != null && !entity.items.has(todump)))
Tilec entity = tile.entity;
if(entity == null || !hasItems || tile.entity.getItems().total() == 0 || (todump != null && !entity.getItems().has(todump)))
return false;
Array<Tile> proximity = entity.proximity();
@@ -237,9 +237,9 @@ public abstract class BlockStorage extends UnlockableContent{
for(int ii = 0; ii < Vars.content.items().size; ii++){
Item item = Vars.content.item(ii);
if(other.getTeam() == tile.getTeam() && entity.items.has(item) && other.block().acceptItem(item, other, in) && canDump(tile, other, item)){
if(other.getTeam() == tile.getTeam() && entity.getItems().has(item) && other.block().acceptItem(item, other, in) && canDump(tile, other, item)){
other.block().handleItem(item, other, in);
tile.entity.items.remove(item, 1);
tile.entity.getItems().remove(item, 1);
incrementDump(tile, proximity.size);
return true;
}
@@ -248,7 +248,7 @@ public abstract class BlockStorage extends UnlockableContent{
if(other.getTeam() == tile.getTeam() && other.block().acceptItem(todump, other, in) && canDump(tile, other, todump)){
other.block().handleItem(todump, other, in);
tile.entity.items.remove(todump, 1);
tile.entity.getItems().remove(todump, 1);
incrementDump(tile, proximity.size);
return true;
}

View File

@@ -1,6 +1,6 @@
package mindustry.world;
import mindustry.entities.type.TileEntity;
import mindustry.gen.*;
import mindustry.game.Team;
import mindustry.world.modules.*;
@@ -32,7 +32,7 @@ public class CachedTile extends Tile{
Block block = block();
if(block.hasEntity()){
TileEntity n = block.newEntity();
Tilec n = block.newEntity();
n.cons = new ConsumeModule(entity);
n.tile = this;
n.block = block;

View File

@@ -7,8 +7,6 @@ import arc.struct.*;
import arc.util.ArcAnnotate.*;
import mindustry.annotations.Annotations.*;
import mindustry.content.*;
import mindustry.entities.traits.*;
import mindustry.entities.type.*;
import mindustry.game.*;
import mindustry.gen.*;
import mindustry.type.*;
@@ -17,11 +15,11 @@ import mindustry.world.modules.*;
import static mindustry.Vars.*;
public class Tile implements Position, TargetTrait{
public class Tile implements Position{
/** Tile traversal cost. */
public byte cost = 1;
/** Tile entity, usually null. */
public TileEntity entity;
public Tilec entity;
public short x, y;
protected Block block;
protected Floor floor;
@@ -100,7 +98,7 @@ public class Tile implements Position, TargetTrait{
}
@SuppressWarnings("unchecked")
public <T extends TileEntity> T ent(){
public <T extends Tilec> T ent(){
return (T)entity;
}
@@ -141,7 +139,6 @@ public class Tile implements Position, TargetTrait{
return (T)block;
}
@Override
public Team getTeam(){
return Team.get(link().team);
}
@@ -456,13 +453,14 @@ public class Tile implements Position, TargetTrait{
Block block = block();
if(block.hasEntity()){
//TODO assign data and don't use new entity
entity = block.newEntity().init(this, block.update);
entity.cons = new ConsumeModule(entity);
if(block.hasItems) entity.items = new ItemModule();
if(block.hasLiquids) entity.liquids = new LiquidModule();
entity.setCons(new ConsumeModule(entity));
if(block.hasItems) entity.setItems(new ItemModule());
if(block.hasLiquids) entity.setLiquids(new LiquidModule());
if(block.hasPower){
entity.power = new PowerModule();
entity.power.graph.add(this);
entity.setPower(new PowerModule());
entity.getPower().graph.add(this);
}
if(!world.isGenerating()){
@@ -483,36 +481,16 @@ public class Tile implements Position, TargetTrait{
world.notifyChanged(this);
}
@Override
public boolean isDead(){
return entity == null;
}
@Override
public Vec2 velocity(){
return Vec2.ZERO;
}
@Override
public float getX(){
return drawx();
}
@Override
public void setX(float x){
throw new IllegalArgumentException("Tile position cannot change.");
}
@Override
public float getY(){
return drawy();
}
@Override
public void setY(float y){
throw new IllegalArgumentException("Tile position cannot change.");
}
@Override
public String toString(){
return floor.name + ":" + block.name + ":" + overlay + "[" + x + "," + y + "] " + "entity=" + (entity == null ? "null" : (entity.getClass())) + ":" + getTeam();

View File

@@ -0,0 +1,4 @@
package mindustry.world;
public class TileData{
}

View File

@@ -11,6 +11,7 @@ import arc.util.*;
import mindustry.content.*;
import mindustry.entities.effect.*;
import mindustry.entities.type.*;
import mindustry.gen.*;
import mindustry.entities.units.*;
import mindustry.game.EventType.*;
import mindustry.game.*;
@@ -197,7 +198,7 @@ public class BuildBlock extends Block{
}
}
public class BuildEntity extends TileEntity{
public class BuildEntity extends Tilec{
/**
* The recipe of the block that is being constructed.
* If there is no recipe for this block, as is the case with rocks, 'previous' is used.
@@ -217,7 +218,7 @@ public class BuildBlock extends Block{
private float[] accumulator;
private float[] totalAccumulator;
public boolean construct(Unitc builder, @Nullable TileEntity core, float amount, boolean configured){
public boolean construct(Unitc builder, @Nullable Tilec core, float amount, boolean configured){
if(cblock == null){
kill();
return false;
@@ -247,7 +248,7 @@ public class BuildBlock extends Block{
return false;
}
public void deconstruct(Unitc builder, @Nullable TileEntity core, float amount){
public void deconstruct(Unitc builder, @Nullable Tilec core, float amount){
float deconstructMultiplier = 0.5f;
if(cblock != null){

View File

@@ -36,7 +36,7 @@ public class LiquidBlock extends Block{
@Override
public void draw(Tile tile){
LiquidModule mod = tile.entity.liquids;
LiquidModule mod = tile.entity.getLiquids();
int rotation = rotate ? tile.rotation() * 90 : 0;

View File

@@ -5,8 +5,6 @@ import arc.graphics.g2d.*;
import arc.math.*;
import arc.math.geom.*;
import arc.util.*;
import mindustry.entities.type.*;
import mindustry.entities.type.Bullet;
import mindustry.world.*;
import static mindustry.Vars.tilesize;
@@ -42,18 +40,18 @@ public class DeflectorWall extends Wall{
}
@Override
public void handleBulletHit(TileEntity entity, Bullet bullet){
public void handleBulletHit(Tilec entity, Bullet bullet){
super.handleBulletHit(entity, bullet);
//doesn't reflect powerful bullets
if(bullet.damage() > maxDamageDeflect || bullet.isDeflected()) return;
float penX = Math.abs(entity.x - bullet.x), penY = Math.abs(entity.y - bullet.y);
float penX = Math.abs(entity.getX() - bullet.x), penY = Math.abs(entity.getY() - bullet.y);
bullet.hitbox(rect2);
Vec2 position = Geometry.raycastRect(bullet.x - bullet.velocity().x*Time.delta(), bullet.y - bullet.velocity().y*Time.delta(), bullet.x + bullet.velocity().x*Time.delta(), bullet.y + bullet.velocity().y*Time.delta(),
rect.setSize(size * tilesize + rect2.width*2 + rect2.height*2).setCenter(entity.x, entity.y));
rect.setSize(size * tilesize + rect2.width*2 + rect2.height*2).setCenter(entity.getX(), entity.getY()));
if(position != null){
bullet.set(position.x, position.y);
@@ -73,7 +71,7 @@ public class DeflectorWall extends Wall{
((DeflectorEntity)entity).hit = 1f;
}
public static class DeflectorEntity extends TileEntity{
public static class DeflectorEntity extends Tilec{
public float hit;
}
}

View File

@@ -8,9 +8,9 @@ import arc.graphics.g2d.*;
import arc.math.geom.*;
import mindustry.content.*;
import mindustry.entities.*;
import mindustry.entities.Effects.*;
import mindustry.entities.type.*;
import mindustry.gen.*;
import mindustry.gen.*;
import mindustry.world.*;
import java.io.*;
@@ -83,14 +83,14 @@ public class Door extends Wall{
public void tapped(Tile tile, Player player){
DoorEntity entity = tile.ent();
if((Units.anyEntities(tile) && entity.open) || !tile.entity.timer.get(timerToggle, 30f)){
if((Units.anyEntities(tile) && entity.open) || !tile.entity.timer(timerToggle, 30f)){
return;
}
Call.onDoorToggle(null, tile, !entity.open);
}
public class DoorEntity extends TileEntity{
public class DoorEntity extends Tilec{
public boolean open = false;
@Override

View File

@@ -98,8 +98,8 @@ public class ForceProjector extends Block{
entity.phaseHeat = Mathf.lerpDelta(entity.phaseHeat, Mathf.num(phaseValid), 0.1f);
if(phaseValid && !entity.broken && entity.timer.get(timerUse, phaseUseTime) && entity.efficiency() > 0){
entity.cons.trigger();
if(phaseValid && !entity.broken && entity.timer(timerUse, phaseUseTime) && entity.efficiency() > 0){
entity.consume();
}
entity.radscl = Mathf.lerpDelta(entity.radscl, entity.broken ? 0f : entity.warmup, 0.05f);
@@ -115,7 +115,7 @@ public class ForceProjector extends Block{
ConsumeLiquidFilter cons = consumes.get(ConsumeType.liquid);
if(cons.valid(entity)){
cons.update(entity);
scale *= (cooldownLiquid * (1f + (entity.liquids.current().heatCapacity - 0.4f) * 0.9f));
scale *= (cooldownLiquid * (1f + (entity.getLiquids().current().heatCapacity - 0.4f) * 0.9f));
}
entity.buildup -= Time.delta() * scale;
@@ -161,7 +161,7 @@ public class ForceProjector extends Block{
Draw.reset();
}
class ForceEntity extends TileEntity{
class ForceEntity extends Tilec{
ShieldEntity shield;
boolean broken = true;
float buildup = 0f;

View File

@@ -7,7 +7,7 @@ import arc.graphics.g2d.*;
import arc.math.Mathf;
import arc.util.*;
import mindustry.content.Fx;
import mindustry.entities.type.TileEntity;
import mindustry.gen.*;
import mindustry.graphics.*;
import mindustry.world.*;
import mindustry.world.meta.*;
@@ -64,13 +64,13 @@ public class MendProjector extends Block{
@Override
public void update(Tile tile){
MendEntity entity = tile.ent();
entity.heat = Mathf.lerpDelta(entity.heat, entity.cons.valid() || tile.isEnemyCheat() ? 1f : 0f, 0.08f);
entity.heat = Mathf.lerpDelta(entity.heat, entity.consValid() || tile.isEnemyCheat() ? 1f : 0f, 0.08f);
entity.charge += entity.heat * entity.delta();
entity.phaseHeat = Mathf.lerpDelta(entity.phaseHeat, Mathf.num(entity.cons.optionalValid()), 0.1f);
if(entity.cons.optionalValid() && entity.timer.get(timerUse, useTime) && entity.efficiency() > 0){
entity.cons.trigger();
if(entity.cons.optionalValid() && entity.timer(timerUse, useTime) && entity.efficiency() > 0){
entity.consume();
}
if(entity.charge >= reload){
@@ -120,7 +120,7 @@ public class MendProjector extends Block{
renderer.lights.add(tile.drawx(), tile.drawy(), 50f * tile.entity.efficiency(), baseColor, 0.7f * tile.entity.efficiency());
}
class MendEntity extends TileEntity{
class MendEntity extends Tilec{
float heat;
float charge = Mathf.random(reload);
float phaseHeat;

View File

@@ -6,7 +6,7 @@ import arc.graphics.Color;
import arc.graphics.g2d.*;
import arc.math.Mathf;
import arc.util.Time;
import mindustry.entities.type.TileEntity;
import mindustry.gen.*;
import mindustry.graphics.*;
import mindustry.world.*;
import mindustry.world.meta.*;
@@ -75,13 +75,13 @@ public class OverdriveProjector extends Block{
@Override
public void update(Tile tile){
OverdriveEntity entity = tile.ent();
entity.heat = Mathf.lerpDelta(entity.heat, entity.cons.valid() ? 1f : 0f, 0.08f);
entity.heat = Mathf.lerpDelta(entity.heat, entity.consValid() ? 1f : 0f, 0.08f);
entity.charge += entity.heat * Time.delta();
entity.phaseHeat = Mathf.lerpDelta(entity.phaseHeat, Mathf.num(entity.cons.optionalValid()), 0.1f);
if(entity.timer.get(timerUse, useTime) && entity.efficiency() > 0){
entity.cons.trigger();
if(entity.timer(timerUse, useTime) && entity.efficiency() > 0){
entity.consume();
}
if(entity.charge >= reload){
@@ -118,7 +118,7 @@ public class OverdriveProjector extends Block{
Draw.reset();
}
class OverdriveEntity extends TileEntity{
class OverdriveEntity extends Tilec{
float heat;
float charge = Mathf.random(reload);
float phaseHeat;

View File

@@ -49,7 +49,7 @@ public class ShockMine extends Block{
@Override
public void unitOn(Tile tile, Unitc unit){
if(unit.getTeam() != tile.getTeam() && tile.entity.timer.get(timerDamage, cooldown)){
if(unit.getTeam() != tile.getTeam() && tile.entity.timer(timerDamage, cooldown)){
for(int i = 0; i < tendrils; i++){
Lightning.create(tile.getTeam(), Pal.lancerLaser, damage, tile.drawx(), tile.drawy(), Mathf.random(360f), length);
}

View File

@@ -1,9 +1,8 @@
package mindustry.world.blocks.defense;
import arc.math.Mathf;
import mindustry.entities.type.Bullet;
import mindustry.entities.effect.Lightning;
import mindustry.entities.type.TileEntity;
import mindustry.gen.*;
import mindustry.graphics.Pal;
public class SurgeWall extends Wall{
@@ -16,7 +15,7 @@ public class SurgeWall extends Wall{
}
@Override
public void handleBulletHit(TileEntity entity, Bullet bullet){
public void handleBulletHit(Tilec entity, Bullet bullet){
super.handleBulletHit(entity, bullet);
if(Mathf.chance(lightningChance)){
Lightning.create(entity.getTeam(), Pal.surge, lightningDamage, bullet.x, bullet.y, bullet.rot() + 180f, lightningLength);

View File

@@ -3,7 +3,6 @@ package mindustry.world.blocks.defense.turrets;
import arc.math.Mathf;
import arc.math.geom.Vec2;
import mindustry.entities.Predict;
import mindustry.entities.type.Bullet;
import mindustry.entities.bullet.BulletType;
import mindustry.world.Tile;

View File

@@ -37,7 +37,7 @@ public class CooledTurret extends Turret{
@Override
public void handleLiquid(Tile tile, Tile source, Liquid liquid, float amount){
if(tile.entity.liquids.currentAmount() <= 0.001f){
if(tile.entity.getLiquids().currentAmount() <= 0.001f){
Events.fire(Trigger.turretCool);
}
@@ -51,11 +51,11 @@ public class CooledTurret extends Turret{
float maxUsed = consumes.<ConsumeLiquidBase>get(ConsumeType.liquid).amount;
TurretEntity entity = tile.ent();
Liquid liquid = entity.liquids.current();
Liquid liquid = entity.getLiquids().current();
float used = Math.min(Math.min(entity.liquids.get(liquid), maxUsed * Time.delta()), Math.max(0, ((reload - entity.reload) / coolantMultiplier) / liquid.heatCapacity)) * baseReloadSpeed(tile);
float used = Math.min(Math.min(entity.getLiquids().get(liquid), maxUsed * Time.delta()), Math.max(0, ((reload - entity.reload) / coolantMultiplier) / liquid.heatCapacity)) * baseReloadSpeed(tile);
entity.reload += used * liquid.heatCapacity * coolantMultiplier;
entity.liquids.remove(liquid, used);
entity.getLiquids().remove(liquid, used);
if(Mathf.chance(0.06 * used)){
coolEffect.at(tile.drawx() + Mathf.range(size * tilesize / 2f), tile.drawy() + Mathf.range(size * tilesize / 2f));

View File

@@ -53,7 +53,7 @@ public class ItemTurret extends CooledTurret{
}
@Override
public boolean valid(TileEntity entity){
public boolean valid(Tilec entity){
//valid when there's any ammo in the turret
return !((ItemTurretEntity)entity).ammo.isEmpty();
}

View File

@@ -65,19 +65,19 @@ public class LaserTurret extends PowerTurret{
return;
}
if(entity.reload >= reload && (entity.cons.valid() || tile.isEnemyCheat())){
if(entity.reload >= reload && (entity.consValid() || tile.isEnemyCheat())){
BulletType type = peekAmmo(tile);
shoot(tile, type);
entity.reload = 0f;
}else{
Liquid liquid = entity.liquids.current();
Liquid liquid = entity.getLiquids().current();
float maxUsed = consumes.<ConsumeLiquidBase>get(ConsumeType.liquid).amount;
float used = baseReloadSpeed(tile) * (tile.isEnemyCheat() ? maxUsed : Math.min(entity.liquids.get(liquid), maxUsed * Time.delta())) * liquid.heatCapacity * coolantMultiplier;
float used = baseReloadSpeed(tile) * (tile.isEnemyCheat() ? maxUsed : Math.min(entity.getLiquids().get(liquid), maxUsed * Time.delta())) * liquid.heatCapacity * coolantMultiplier;
entity.reload += used;
entity.liquids.remove(liquid, used);
entity.getLiquids().remove(liquid, used);
if(Mathf.chance(0.06 * used)){
coolEffect.at(tile.drawx() + Mathf.range(size * tilesize / 2f), tile.drawy() + Mathf.range(size * tilesize / 2f));

View File

@@ -6,7 +6,7 @@ import arc.struct.*;
import mindustry.entities.*;
import mindustry.entities.bullet.*;
import mindustry.entities.effect.*;
import mindustry.entities.type.*;
import mindustry.gen.*;
import mindustry.gen.*;
import mindustry.type.*;
import mindustry.world.*;
@@ -38,8 +38,8 @@ public class LiquidTurret extends Turret{
TurretEntity entity = tile.ent();
if(Core.atlas.isFound(reg(liquidRegion))){
Draw.color(entity.liquids.current().color);
Draw.alpha(entity.liquids.total() / liquidCapacity);
Draw.color(entity.getLiquids().current().color);
Draw.alpha(entity.getLiquids().total() / liquidCapacity);
Draw.rect(reg(liquidRegion), tile.drawx() + tr2.x, tile.drawy() + tr2.y, entity.rotation - 90);
Draw.color();
}
@@ -52,7 +52,7 @@ public class LiquidTurret extends Turret{
stats.add(BlockStat.ammo, new AmmoListValue<>(ammo));
consumes.add(new ConsumeLiquidFilter(i -> ammo.containsKey(i), 1f){
@Override
public boolean valid(TileEntity entity){
public boolean valid(Tilec entity){
return !((TurretEntity)entity).ammo.isEmpty();
}
@@ -72,7 +72,7 @@ public class LiquidTurret extends Turret{
@Override
protected boolean validateTarget(Tile tile){
TurretEntity entity = tile.ent();
if(entity.liquids.current().canExtinguish() && entity.target instanceof Tile){
if(entity.getLiquids().current().canExtinguish() && entity.target instanceof Tile){
return Fire.has(((Tile)entity.target).x, ((Tile)entity.target).y);
}
return super.validateTarget(tile);
@@ -81,7 +81,7 @@ public class LiquidTurret extends Turret{
@Override
protected void findTarget(Tile tile){
TurretEntity entity = tile.ent();
if(entity.liquids.current().canExtinguish()){
if(entity.getLiquids().current().canExtinguish()){
int tr = (int)(range / tilesize);
for(int x = -tr; x <= tr; x++){
for(int y = -tr; y <= tr; y++){
@@ -102,8 +102,8 @@ public class LiquidTurret extends Turret{
TurretEntity entity = tile.ent();
type.shootEffect.at(tile.drawx() + tr.x, tile.drawy() + tr.y, entity.rotation, entity.liquids.current().color);
type.smokeEffect.at(tile.drawx() + tr.x, tile.drawy() + tr.y, entity.rotation, entity.liquids.current().color);
type.shootEffect.at(tile.drawx() + tr.x, tile.drawy() + tr.y, entity.rotation, entity.getLiquids().current().color);
type.smokeEffect.at(tile.drawx() + tr.x, tile.drawy() + tr.y, entity.rotation, entity.getLiquids().current().color);
//shootSound.at(tile);
if(shootShake > 0){
@@ -116,21 +116,21 @@ public class LiquidTurret extends Turret{
@Override
public BulletType useAmmo(Tile tile){
TurretEntity entity = tile.ent();
if(tile.isEnemyCheat()) return ammo.get(entity.liquids.current());
BulletType type = ammo.get(entity.liquids.current());
entity.liquids.remove(entity.liquids.current(), type.ammoMultiplier);
if(tile.isEnemyCheat()) return ammo.get(entity.getLiquids().current());
BulletType type = ammo.get(entity.getLiquids().current());
entity.getLiquids().remove(entity.getLiquids().current(), type.ammoMultiplier);
return type;
}
@Override
public BulletType peekAmmo(Tile tile){
return ammo.get(tile.entity.liquids.current());
return ammo.get(tile.entity.getLiquids().current());
}
@Override
public boolean hasAmmo(Tile tile){
TurretEntity entity = tile.ent();
return ammo.get(entity.liquids.current()) != null && entity.liquids.total() >= ammo.get(entity.liquids.current()).ammoMultiplier;
return ammo.get(entity.getLiquids().current()) != null && entity.getLiquids().total() >= ammo.get(entity.getLiquids().current()).ammoMultiplier;
}
@Override
@@ -141,7 +141,7 @@ public class LiquidTurret extends Turret{
@Override
public boolean acceptLiquid(Tile tile, Tile source, Liquid liquid, float amount){
return ammo.get(liquid) != null
&& (tile.entity.liquids.current() == liquid || (ammo.containsKey(tile.entity.liquids.current()) && tile.entity.liquids.get(tile.entity.liquids.current()) <= ammo.get(tile.entity.liquids.current()).ammoMultiplier + 0.001f));
&& (tile.entity.getLiquids().current() == liquid || (ammo.containsKey(tile.entity.getLiquids().current()) && tile.entity.getLiquids().get(tile.entity.getLiquids().current()) <= ammo.get(tile.entity.getLiquids().current()).ammoMultiplier + 0.001f));
}
}

View File

@@ -47,6 +47,6 @@ public class PowerTurret extends CooledTurret{
@Override
protected float baseReloadSpeed(Tile tile){
return tile.isEnemyCheat() ? 1f : tile.entity.power.status;
return tile.isEnemyCheat() ? 1f : tile.entity.getPower().status;
}
}

View File

@@ -14,10 +14,9 @@ import arc.math.geom.Vec2;
import arc.util.Time;
import mindustry.content.Fx;
import mindustry.entities.*;
import mindustry.entities.Effects.Effect;
import mindustry.entities.type.Bullet;
import mindustry.entities.*;
import mindustry.entities.bullet.BulletType;
import mindustry.entities.type.TileEntity;
import mindustry.gen.*;
import mindustry.gen.*;
import mindustry.graphics.*;
import mindustry.world.Block;
@@ -153,7 +152,7 @@ public abstract class Turret extends Block{
if(hasAmmo(tile)){
if(entity.timer.get(timerTarget, targetInterval)){
if(entity.timer(timerTarget, targetInterval)){
findTarget(tile);
}
@@ -312,7 +311,7 @@ public abstract class Turret extends Block{
public abstract BulletType type();
}
public static class TurretEntity extends TileEntity{
public static class TurretEntity extends Tilec{
public Array<AmmoEntry> ammo = new Array<>();
public int totalAmmo;
public float reload;
@@ -320,7 +319,7 @@ public abstract class Turret extends Block{
public float recoil = 0f;
public float heat;
public int shots;
public TargetTrait target;
public Teamc target;
@Override
public void write(DataOutput stream) throws IOException{

View File

@@ -23,12 +23,12 @@ public class BufferedItemBridge extends ExtendingItemBridge{
public void updateTransport(Tile tile, Tile other){
BufferedItemBridgeEntity entity = tile.ent();
if(entity.buffer.accepts() && entity.items.total() > 0){
entity.buffer.accept(entity.items.take());
if(entity.buffer.accepts() && entity.getItems().total() > 0){
entity.buffer.accept(entity.getItems().take());
}
Item item = entity.buffer.poll();
if(entity.timer.get(timerAccept, 4) && item != null && other.block().acceptItem(item, other, tile)){
if(entity.timer(timerAccept, 4) && item != null && other.block().acceptItem(item, other, tile)){
entity.cycleSpeed = Mathf.lerpDelta(entity.cycleSpeed, 4f, 0.05f);
other.block().handleItem(item, other, tile);
entity.buffer.remove();

View File

@@ -9,7 +9,7 @@ import arc.struct.*;
import arc.util.ArcAnnotate.*;
import arc.util.*;
import mindustry.content.*;
import mindustry.entities.type.*;
import mindustry.gen.*;
import mindustry.entities.units.*;
import mindustry.gen.*;
import mindustry.graphics.*;
@@ -309,7 +309,7 @@ public class Conveyor extends Block implements Autotiler{
}
}
public static class ConveyorEntity extends TileEntity{
public static class ConveyorEntity extends Tilec{
//parallel array data
Item[] ids = new Item[capacity];
float[] xs = new float[capacity];
@@ -317,7 +317,7 @@ public class Conveyor extends Block implements Autotiler{
//amount of items, always < capacity
int len = 0;
//next entity
@Nullable TileEntity next;
@Nullable Tilec next;
@Nullable ConveyorEntity nextc;
//whether the next conveyor's rotation == tile rotation
boolean aligned;

View File

@@ -187,7 +187,7 @@ public class ItemBridge extends Block{
}else{
((ItemBridgeEntity)world.tile(entity.link).entity).incoming.add(tile.pos());
if(entity.cons.valid() && Mathf.zero(1f - entity.efficiency())){
if(entity.consValid() && Mathf.zero(1f - entity.efficiency())){
entity.uptime = Mathf.lerpDelta(entity.uptime, 1f, 0.04f);
}else{
entity.uptime = Mathf.lerpDelta(entity.uptime, 0f, 0.02f);
@@ -200,14 +200,14 @@ public class ItemBridge extends Block{
public void updateTransport(Tile tile, Tile other){
ItemBridgeEntity entity = tile.ent();
if(entity.uptime >= 0.5f && entity.timer.get(timerTransport, transportTime)){
Item item = entity.items.take();
if(entity.uptime >= 0.5f && entity.timer(timerTransport, transportTime)){
Item item = entity.getItems().take();
if(item != null && other.block().acceptItem(item, other, tile)){
other.block().handleItem(item, other, tile);
entity.cycleSpeed = Mathf.lerpDelta(entity.cycleSpeed, 4f, 0.05f);
}else{
entity.cycleSpeed = Mathf.lerpDelta(entity.cycleSpeed, 1f, 0.01f);
if(item != null) entity.items.add(item, 1);
if(item != null) entity.getItems().add(item, 1);
}
}
}
@@ -266,10 +266,10 @@ public class ItemBridge extends Block{
if(rel == rel2) return false;
}else{
return source.block() instanceof ItemBridge && source.<ItemBridgeEntity>ent().link == tile.pos() && tile.entity.items.total() < itemCapacity;
return source.block() instanceof ItemBridge && source.<ItemBridgeEntity>ent().link == tile.pos() && tile.entity.getItems().total() < itemCapacity;
}
return tile.entity.items.total() < itemCapacity;
return tile.entity.getItems().total() < itemCapacity;
}
@@ -315,7 +315,7 @@ public class ItemBridge extends Block{
return false;
}
return tile.entity.liquids.get(liquid) + amount < liquidCapacity && (tile.entity.liquids.current() == liquid || tile.entity.liquids.get(tile.entity.liquids.current()) < 0.2f);
return tile.entity.getLiquids().get(liquid) + amount < liquidCapacity && (tile.entity.getLiquids().current() == liquid || tile.entity.getLiquids().get(tile.entity.getLiquids().current()) < 0.2f);
}
@Override
@@ -361,7 +361,7 @@ public class ItemBridge extends Block{
return other.block() == this && (!checkDouble || other.<ItemBridgeEntity>ent().link != tile.pos());
}
public static class ItemBridgeEntity extends TileEntity{
public static class ItemBridgeEntity extends Tilec{
public int link = Pos.invalid;
public IntSet incoming = new IntSet();
public float uptime;

View File

@@ -1,7 +1,7 @@
package mindustry.world.blocks.distribution;
import arc.util.Time;
import mindustry.entities.type.TileEntity;
import mindustry.gen.*;
import mindustry.gen.BufferItem;
import mindustry.type.Item;
import mindustry.world.Block;
@@ -86,7 +86,7 @@ public class Junction extends Block{
return to != null && to.link().entity != null && to.getTeam() == tile.getTeam();
}
class JunctionEntity extends TileEntity{
class JunctionEntity extends Tilec{
DirectionalItemBuffer buffer = new DirectionalItemBuffer(capacity, speed);
@Override

View File

@@ -9,7 +9,6 @@ import arc.util.pooling.Pool.*;
import arc.util.pooling.*;
import mindustry.content.*;
import mindustry.entities.*;
import mindustry.entities.Effects.*;
import mindustry.entities.type.*;
import mindustry.graphics.*;
import mindustry.type.*;
@@ -81,7 +80,7 @@ public class MassDriver extends Block{
//switch states
if(entity.state == DriverState.idle){
//start accepting when idle and there's space
if(!entity.waitingShooters.isEmpty() && (itemCapacity - entity.items.total() >= minDistribute)){
if(!entity.waitingShooters.isEmpty() && (itemCapacity - entity.getItems().total() >= minDistribute)){
entity.state = DriverState.accepting;
}else if(hasLink){ //switch to shooting if there's a valid link.
entity.state = DriverState.shooting;
@@ -94,13 +93,13 @@ public class MassDriver extends Block{
}
//skip when there's no power
if(!entity.cons.valid()){
if(!entity.consValid()){
return;
}
if(entity.state == DriverState.accepting){
//if there's nothing shooting at this, bail - OR, items full
if(entity.currentShooter() == null || (itemCapacity - entity.items.total() < minDistribute)){
if(entity.currentShooter() == null || (itemCapacity - entity.getItems().total() < minDistribute)){
entity.state = DriverState.idle;
return;
}
@@ -109,7 +108,7 @@ public class MassDriver extends Block{
entity.rotation = Mathf.slerpDelta(entity.rotation, tile.angleTo(entity.currentShooter()), rotateSpeed * entity.efficiency());
}else if(entity.state == DriverState.shooting){
//if there's nothing to shoot at OR someone wants to shoot at this thing, bail
if(!hasLink || (!entity.waitingShooters.isEmpty() && (itemCapacity - entity.items.total() >= minDistribute))){
if(!hasLink || (!entity.waitingShooters.isEmpty() && (itemCapacity - entity.getItems().total() >= minDistribute))){
entity.state = DriverState.idle;
return;
}
@@ -117,8 +116,8 @@ public class MassDriver extends Block{
float targetRotation = tile.angleTo(link);
if(
tile.entity.items.total() >= minDistribute && //must shoot minimum amount of items
link.block().itemCapacity - link.entity.items.total() >= minDistribute //must have minimum amount of space
tile.entity.getItems().total() >= minDistribute && //must shoot minimum amount of items
link.block().itemCapacity - link.entity.getItems().total() >= minDistribute //must have minimum amount of space
){
MassDriverEntity other = link.ent();
other.waitingShooters.add(tile);
@@ -226,7 +225,7 @@ public class MassDriver extends Block{
@Override
public boolean acceptItem(Item item, Tile tile, Tile source){
//mass drivers that ouput only cannot accept items
return tile.entity.items.total() < itemCapacity && linkValid(tile);
return tile.entity.getItems().total() < itemCapacity && linkValid(tile);
}
protected void fire(Tile tile, Tile target){
@@ -241,10 +240,10 @@ public class MassDriver extends Block{
data.to = other;
int totalUsed = 0;
for(int i = 0; i < content.items().size; i++){
int maxTransfer = Math.min(entity.items.get(content.item(i)), ((MassDriver)tile.block()).itemCapacity - totalUsed);
int maxTransfer = Math.min(entity.getItems().get(content.item(i)), ((MassDriver)tile.block()).itemCapacity - totalUsed);
data.items[i] = maxTransfer;
totalUsed += maxTransfer;
entity.items.remove(content.item(i), maxTransfer);
entity.getItems().remove(content.item(i), maxTransfer);
}
float angle = tile.angleTo(target);
@@ -263,12 +262,12 @@ public class MassDriver extends Block{
}
protected void handlePayload(MassDriverEntity entity, Bullet bullet, DriverBulletData data){
int totalItems = entity.items.total();
int totalItems = entity.getItems().total();
//add all the items possible
for(int i = 0; i < data.items.length; i++){
int maxAdd = Math.min(data.items[i], itemCapacity * 2 - totalItems);
entity.items.add(content.item(i), maxAdd);
entity.getItems().add(content.item(i), maxAdd);
data.items[i] -= maxAdd;
totalItems += maxAdd;
@@ -312,7 +311,7 @@ public class MassDriver extends Block{
}
}
public class MassDriverEntity extends TileEntity{
public class MassDriverEntity extends Tilec{
int link = -1;
float rotation = 90;
float reload = 0f;

View File

@@ -2,7 +2,7 @@ package mindustry.world.blocks.distribution;
import arc.math.Mathf;
import arc.util.Time;
import mindustry.entities.type.TileEntity;
import mindustry.gen.*;
import mindustry.type.Item;
import mindustry.world.*;
import mindustry.world.meta.BlockGroup;
@@ -42,8 +42,8 @@ public class OverflowGate extends Block{
public void update(Tile tile){
OverflowGateEntity entity = tile.ent();
if(entity.lastItem == null && entity.items.total() > 0){
entity.items.clear();
if(entity.lastItem == null && entity.getItems().total() > 0){
entity.getItems().clear();
}
if(entity.lastItem != null){
@@ -53,7 +53,7 @@ public class OverflowGate extends Block{
if(target != null && (entity.time >= 1f)){
getTileTarget(tile, entity.lastItem, entity.lastInput, true);
target.block().handleItem(entity.lastItem, target, Edges.getFacingEdge(tile, target));
entity.items.remove(entity.lastItem, 1);
entity.getItems().remove(entity.lastItem, 1);
entity.lastItem = null;
}
}
@@ -63,13 +63,13 @@ public class OverflowGate extends Block{
public boolean acceptItem(Item item, Tile tile, Tile source){
OverflowGateEntity entity = tile.ent();
return tile.getTeam() == source.getTeam() && entity.lastItem == null && entity.items.total() == 0;
return tile.getTeam() == source.getTeam() && entity.lastItem == null && entity.getItems().total() == 0;
}
@Override
public void handleItem(Item item, Tile tile, Tile source){
OverflowGateEntity entity = tile.ent();
entity.items.add(item, 1);
entity.getItems().add(item, 1);
entity.lastItem = item;
entity.time = 0f;
entity.lastInput = source;
@@ -113,7 +113,7 @@ public class OverflowGate extends Block{
return to;
}
public class OverflowGateEntity extends TileEntity{
public class OverflowGateEntity extends Tilec{
Item lastItem;
Tile lastInput;
float time;

View File

@@ -3,7 +3,7 @@ package mindustry.world.blocks.distribution;
import arc.struct.Array;
import arc.util.Time;
import mindustry.content.*;
import mindustry.entities.type.TileEntity;
import mindustry.gen.*;
import mindustry.type.Item;
import mindustry.world.*;
import mindustry.world.meta.BlockGroup;
@@ -26,8 +26,8 @@ public class Router extends Block{
public void update(Tile tile){
RouterEntity entity = tile.ent();
if(entity.lastItem == null && entity.items.total() > 0){
entity.items.clear();
if(entity.lastItem == null && entity.getItems().total() > 0){
entity.getItems().clear();
}
if(entity.lastItem != null){
@@ -37,7 +37,7 @@ public class Router extends Block{
if(target != null && (entity.time >= 1f || !(target.block() instanceof Router))){
getTileTarget(tile, entity.lastItem, entity.lastInput, true);
target.block().handleItem(entity.lastItem, target, Edges.getFacingEdge(tile, target));
entity.items.remove(entity.lastItem, 1);
entity.getItems().remove(entity.lastItem, 1);
entity.lastItem = null;
}
}
@@ -47,13 +47,13 @@ public class Router extends Block{
public boolean acceptItem(Item item, Tile tile, Tile source){
RouterEntity entity = tile.ent();
return tile.getTeam() == source.getTeam() && entity.lastItem == null && entity.items.total() == 0;
return tile.getTeam() == source.getTeam() && entity.lastItem == null && entity.getItems().total() == 0;
}
@Override
public void handleItem(Item item, Tile tile, Tile source){
RouterEntity entity = tile.ent();
entity.items.add(item, 1);
entity.getItems().add(item, 1);
entity.lastItem = item;
entity.time = 0f;
entity.lastInput = source;
@@ -83,7 +83,7 @@ public class Router extends Block{
return result;
}
public class RouterEntity extends TileEntity{
public class RouterEntity extends Tilec{
Item lastItem;
Tile lastInput;
float time;

View File

@@ -139,7 +139,7 @@ public class Sorter extends Block{
});
}
public class SorterEntity extends TileEntity{
public class SorterEntity extends Tilec{
@Nullable Item sortItem;
@Override

View File

@@ -96,7 +96,7 @@ public class Conduit extends LiquidBlock implements Autotiler{
Draw.colorl(0.34f);
Draw.rect(botRegions[entity.blendbits], tile.drawx(), tile.drawy(), rotation);
Draw.color(tile.entity.liquids.current().color);
Draw.color(tile.entity.getLiquids().current().color);
Draw.alpha(entity.smoothLiquid);
Draw.rect(botRegions[entity.blendbits], tile.drawx(), tile.drawy(), rotation);
Draw.color();
@@ -107,10 +107,10 @@ public class Conduit extends LiquidBlock implements Autotiler{
@Override
public void update(Tile tile){
ConduitEntity entity = tile.ent();
entity.smoothLiquid = Mathf.lerpDelta(entity.smoothLiquid, entity.liquids.currentAmount() / liquidCapacity, 0.05f);
entity.smoothLiquid = Mathf.lerpDelta(entity.smoothLiquid, entity.getLiquids().currentAmount() / liquidCapacity, 0.05f);
if(tile.entity.liquids.total() > 0.001f && tile.entity.timer.get(timerFlow, 1)){
tryMoveLiquid(tile, tile.getNearby(tile.rotation()), leakResistance, tile.entity.liquids.current());
if(tile.entity.getLiquids().total() > 0.001f && tile.entity.timer(timerFlow, 1)){
tryMoveLiquid(tile, tile.getNearby(tile.rotation()), leakResistance, tile.entity.getLiquids().current());
entity.noSleep();
}else{
entity.sleep();
@@ -125,11 +125,11 @@ public class Conduit extends LiquidBlock implements Autotiler{
@Override
public boolean acceptLiquid(Tile tile, Tile source, Liquid liquid, float amount){
tile.entity.noSleep();
return tile.entity.liquids.get(liquid) + amount < liquidCapacity && (tile.entity.liquids.current() == liquid || tile.entity.liquids.get(tile.entity.liquids.current()) < 0.2f)
return tile.entity.getLiquids().get(liquid) + amount < liquidCapacity && (tile.entity.getLiquids().current() == liquid || tile.entity.getLiquids().get(tile.entity.getLiquids().current()) < 0.2f)
&& ((source.absoluteRelativeTo(tile.x, tile.y) + 2) % 4 != tile.rotation());
}
public static class ConduitEntity extends TileEntity{
public static class ConduitEntity extends Tilec{
public float smoothLiquid;
int blendbits;

View File

@@ -28,11 +28,11 @@ public class LiquidBridge extends ItemBridge{
Tile other = world.tile(entity.link);
if(!linkValid(tile, other)){
tryDumpLiquid(tile, entity.liquids.current());
tryDumpLiquid(tile, entity.getLiquids().current());
}else{
((ItemBridgeEntity)world.tile(entity.link).entity).incoming.add(tile.pos());
if(entity.cons.valid()){
if(entity.consValid()){
float alpha = 0.04f;
if(hasPower){
alpha *= entity.efficiency(); // Exceed boot time unless power is at max.
@@ -44,7 +44,7 @@ public class LiquidBridge extends ItemBridge{
if(entity.uptime >= 0.5f){
if(tryMoveLiquid(tile, other, false, entity.liquids.current()) > 0.1f){
if(tryMoveLiquid(tile, other, false, entity.getLiquids().current()) > 0.1f){
entity.cycleSpeed = Mathf.lerpDelta(entity.cycleSpeed, 4f, 0.05f);
}else{
entity.cycleSpeed = Mathf.lerpDelta(entity.cycleSpeed, 1f, 0.01f);

View File

@@ -28,11 +28,11 @@ public class LiquidExtendingBridge extends ExtendingItemBridge{
Tile other = world.tile(entity.link);
if(!linkValid(tile, other)){
tryDumpLiquid(tile, entity.liquids.current());
tryDumpLiquid(tile, entity.getLiquids().current());
}else{
((ItemBridgeEntity)world.tile(entity.link).entity).incoming.add(tile.pos());
if(entity.cons.valid()){
if(entity.consValid()){
entity.uptime = Mathf.lerpDelta(entity.uptime, 1f, 0.04f);
}else{
entity.uptime = Mathf.lerpDelta(entity.uptime, 0f, 0.02f);
@@ -40,7 +40,7 @@ public class LiquidExtendingBridge extends ExtendingItemBridge{
if(entity.uptime >= 0.5f){
if(tryMoveLiquid(tile, other, false, entity.liquids.current()) > 0.1f){
if(tryMoveLiquid(tile, other, false, entity.getLiquids().current()) > 0.1f){
entity.cycleSpeed = Mathf.lerpDelta(entity.cycleSpeed, 4f, 0.05f);
}else{
entity.cycleSpeed = Mathf.lerpDelta(entity.cycleSpeed, 1f, 0.01f);

View File

@@ -13,13 +13,13 @@ public class LiquidRouter extends LiquidBlock{
@Override
public void update(Tile tile){
if(tile.entity.liquids.total() > 0.01f){
tryDumpLiquid(tile, tile.entity.liquids.current());
if(tile.entity.getLiquids().total() > 0.01f){
tryDumpLiquid(tile, tile.entity.getLiquids().current());
}
}
@Override
public boolean acceptLiquid(Tile tile, Tile source, Liquid liquid, float amount){
return tile.entity.liquids.get(liquid) + amount < liquidCapacity && (tile.entity.liquids.current() == liquid || tile.entity.liquids.get(tile.entity.liquids.current()) < 0.2f);
return tile.entity.getLiquids().get(liquid) + amount < liquidCapacity && (tile.entity.getLiquids().current() == liquid || tile.entity.getLiquids().get(tile.entity.getLiquids().current()) < 0.2f);
}
}

View File

@@ -13,6 +13,7 @@ import arc.util.pooling.*;
import mindustry.entities.*;
import mindustry.entities.type.*;
import mindustry.gen.*;
import mindustry.gen.*;
import mindustry.net.*;
import mindustry.ui.*;
import mindustry.ui.dialogs.*;
@@ -146,7 +147,7 @@ public class MessageBlock extends Block{
table.setPosition(pos.x, pos.y, Align.bottom);
}
public class MessageBlockEntity extends TileEntity{
public class MessageBlockEntity extends Tilec{
public String message = "";
public String[] lines = {""};

View File

@@ -1,20 +1,20 @@
package mindustry.world.blocks.power;
import arc.func.Boolf;
import mindustry.entities.type.TileEntity;
import mindustry.gen.*;
import mindustry.world.consumers.ConsumePower;
/** A power consumer that only activates sometimes. */
public class ConditionalConsumePower extends ConsumePower{
private final Boolf<TileEntity> consume;
private final Boolf<Tilec> consume;
public ConditionalConsumePower(float usage, Boolf<TileEntity> consume){
public ConditionalConsumePower(float usage, Boolf<Tilec> consume){
super(usage, 0, false);
this.consume = consume;
}
@Override
public float requestedPower(TileEntity entity){
public float requestedPower(Tilec entity){
return consume.get(entity) ? usage : 0f;
}
}

View File

@@ -71,7 +71,7 @@ public class ImpactReactor extends PowerGenerator{
public void update(Tile tile){
FusionReactorEntity entity = tile.ent();
if(entity.cons.valid() && entity.power.status >= 0.99f){
if(entity.consValid() && entity.getPower().status >= 0.99f){
boolean prevOut = getPowerProduction(tile) <= consumes.getPower().requestedPower(entity);
entity.warmup = Mathf.lerpDelta(entity.warmup, 1f, warmupSpeed);
@@ -83,8 +83,8 @@ public class ImpactReactor extends PowerGenerator{
Events.fire(Trigger.impactPower);
}
if(entity.timer.get(timerUse, itemDuration / entity.timeScale)){
entity.cons.trigger();
if(entity.timer(timerUse, itemDuration / entity.timeScale)){
entity.consume();
}
}else{
entity.warmup = Mathf.lerpDelta(entity.warmup, 0f, 0.01f);

View File

@@ -99,14 +99,14 @@ public class ItemLiquidGenerator extends PowerGenerator{
//Power amount is delta'd by PowerGraph class already.
float calculationDelta = entity.delta();
if(!entity.cons.valid()){
if(!entity.consValid()){
entity.productionEfficiency = 0.0f;
return;
}
Liquid liquid = null;
for(Liquid other : content.liquids()){
if(hasLiquids && entity.liquids.get(other) >= 0.001f && getLiquidEfficiency(other) >= minLiquidEfficiency){
if(hasLiquids && entity.getLiquids().get(other) >= 0.001f && getLiquidEfficiency(other) >= minLiquidEfficiency){
liquid = other;
break;
}
@@ -115,12 +115,12 @@ public class ItemLiquidGenerator extends PowerGenerator{
entity.heat = Mathf.lerpDelta(entity.heat, entity.generateTime >= 0.001f ? 1f : 0f, 0.05f);
//liquid takes priority over solids
if(hasLiquids && liquid != null && entity.liquids.get(liquid) >= 0.001f){
if(hasLiquids && liquid != null && entity.getLiquids().get(liquid) >= 0.001f){
float baseLiquidEfficiency = getLiquidEfficiency(liquid);
float maximumPossible = maxLiquidGenerate * calculationDelta;
float used = Math.min(entity.liquids.get(liquid) * calculationDelta, maximumPossible);
float used = Math.min(entity.getLiquids().get(liquid) * calculationDelta, maximumPossible);
entity.liquids.remove(liquid, used * entity.power.graph.getUsageFraction());
entity.getLiquids().remove(liquid, used * entity.getPower().graph.getUsageFraction());
entity.productionEfficiency = baseLiquidEfficiency * used / maximumPossible;
if(used > 0.001f && Mathf.chance(0.05 * entity.delta())){
@@ -128,16 +128,16 @@ public class ItemLiquidGenerator extends PowerGenerator{
}
}else if(hasItems){
// No liquids accepted or none supplied, try using items if accepted
if(entity.generateTime <= 0f && entity.items.total() > 0){
if(entity.generateTime <= 0f && entity.getItems().total() > 0){
generateEffect.at(tile.worldx() + Mathf.range(3f), tile.worldy() + Mathf.range(3f));
Item item = entity.items.take();
Item item = entity.getItems().take();
entity.productionEfficiency = getItemEfficiency(item);
entity.explosiveness = item.explosiveness;
entity.generateTime = 1f;
}
if(entity.generateTime > 0f){
entity.generateTime -= Math.min(1f / itemDuration * entity.delta() * entity.power.graph.getUsageFraction(), entity.generateTime);
entity.generateTime -= Math.min(1f / itemDuration * entity.delta() * entity.getPower().graph.getUsageFraction(), entity.generateTime);
if(randomlyExplode && state.rules.reactorExplosions && Mathf.chance(entity.delta() * 0.06 * Mathf.clamp(entity.explosiveness - 0.5f))){
//this block is run last so that in the event of a block destruction, no code relies on the block type
@@ -166,8 +166,8 @@ public class ItemLiquidGenerator extends PowerGenerator{
}
if(hasLiquids){
Draw.color(entity.liquids.current().color);
Draw.alpha(entity.liquids.currentAmount() / liquidCapacity);
Draw.color(entity.getLiquids().current().color);
Draw.alpha(entity.getLiquids().currentAmount() / liquidCapacity);
Draw.rect(liquidRegion, tile.drawx(), tile.drawy());
Draw.color();
}

View File

@@ -6,6 +6,7 @@ import arc.scene.ui.layout.*;
import arc.util.*;
import mindustry.entities.type.*;
import mindustry.gen.*;
import mindustry.gen.*;
import mindustry.graphics.*;
import mindustry.world.*;
@@ -72,7 +73,7 @@ public class LightBlock extends Block{
renderer.lights.add(tile.drawx(), tile.drawy(), radius, Tmp.c1.set(entity.color), brightness * tile.entity.efficiency());
}
public class LightEntity extends TileEntity{
public class LightEntity extends Tilec{
public int color = Pal.accent.rgba();
@Override

View File

@@ -79,24 +79,24 @@ public class NuclearReactor extends PowerGenerator{
ConsumeLiquid cliquid = consumes.get(ConsumeType.liquid);
Item item = consumes.<ConsumeItems>get(ConsumeType.item).items[0].item;
int fuel = entity.items.get(item);
int fuel = entity.getItems().get(item);
float fullness = (float)fuel / itemCapacity;
entity.productionEfficiency = fullness;
if(fuel > 0){
entity.heat += fullness * heating * Math.min(entity.delta(), 4f);
if(entity.timer.get(timerFuel, itemDuration / entity.timeScale)){
entity.cons.trigger();
if(entity.timer(timerFuel, itemDuration / entity.timeScale)){
entity.consume();
}
}
Liquid liquid = cliquid.liquid;
if(entity.heat > 0){
float maxUsed = Math.min(entity.liquids.get(liquid), entity.heat / coolantPower);
float maxUsed = Math.min(entity.getLiquids().get(liquid), entity.heat / coolantPower);
entity.heat -= maxUsed * coolantPower;
entity.liquids.remove(liquid, maxUsed);
entity.getLiquids().remove(liquid, maxUsed);
}
if(entity.heat > smokeThreshold){
@@ -123,7 +123,7 @@ public class NuclearReactor extends PowerGenerator{
NuclearReactorEntity entity = tile.ent();
int fuel = entity.items.get(consumes.<ConsumeItems>get(ConsumeType.item).items[0].item);
int fuel = entity.getItems().get(consumes.<ConsumeItems>get(ConsumeType.item).items[0].item);
if((fuel < 5 && entity.heat < 0.5f) || !state.rules.reactorExplosions) return;
@@ -166,8 +166,8 @@ public class NuclearReactor extends PowerGenerator{
Draw.color(coolColor, hotColor, entity.heat);
Fill.rect(tile.drawx(), tile.drawy(), size * tilesize, size * tilesize);
Draw.color(entity.liquids.current().color);
Draw.alpha(entity.liquids.currentAmount() / liquidCapacity);
Draw.color(entity.getLiquids().current().color);
Draw.alpha(entity.getLiquids().currentAmount() / liquidCapacity);
Draw.rect(topRegion, tile.drawx(), tile.drawy());
if(entity.heat > flashThreshold){

View File

@@ -29,8 +29,8 @@ public class PowerDiode extends Block{
if(tile.front() == null || tile.back() == null || !tile.back().block().hasPower || !tile.front().block().hasPower || tile.back().getTeam() != tile.front().getTeam()) return;
PowerGraph backGraph = tile.back().entity.power.graph;
PowerGraph frontGraph = tile.front().entity.power.graph;
PowerGraph backGraph = tile.back().entity.getPower().graph;
PowerGraph frontGraph = tile.front().entity.getPower().graph;
if(backGraph == frontGraph) return;
// 0f - 1f of battery capacity in use
@@ -51,7 +51,7 @@ public class PowerDiode extends Block{
// battery % of the graph on either side, defaults to zero
public float bar(Tile tile){
return (tile != null && tile.block().hasPower) ? tile.entity.power.graph.getBatteryStored() / tile.entity.power.graph.getTotalBatteryCapacity() : 0f;
return (tile != null && tile.block().hasPower) ? tile.entity.getPower().graph.getBatteryStored() / tile.entity.getPower().graph.getTotalBatteryCapacity() : 0f;
}
@Override

View File

@@ -3,7 +3,7 @@ package mindustry.world.blocks.power;
import arc.Core;
import arc.struct.EnumSet;
import arc.util.Strings;
import mindustry.entities.type.TileEntity;
import mindustry.gen.*;
import mindustry.graphics.Pal;
import mindustry.ui.Bar;
import mindustry.world.Tile;
@@ -53,7 +53,7 @@ public class PowerGenerator extends PowerDistributor{
return false;
}
public static class GeneratorEntity extends TileEntity{
public static class GeneratorEntity extends Tilec{
public float generateTime;
/** The efficiency of the producer. An efficiency of 1.0 means 100% */
public float productionEfficiency = 0.0f;

Some files were not shown because too many files have changed in this diff Show More