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
+43 -44
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();
}
+30 -30
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;
}
+2 -2
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;
+9 -31
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();
+4
View File
@@ -0,0 +1,4 @@
package mindustry.world;
public class TileData{
}
@@ -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){
@@ -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;
@@ -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;
}
}
@@ -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
@@ -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;
@@ -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;
@@ -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;
@@ -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);
}
@@ -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);
@@ -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;
@@ -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));
@@ -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();
}
@@ -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));
@@ -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));
}
}
@@ -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;
}
}
@@ -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{
@@ -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();
@@ -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;
@@ -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;
@@ -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
@@ -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;
@@ -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;
@@ -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;
@@ -139,7 +139,7 @@ public class Sorter extends Block{
});
}
public class SorterEntity extends TileEntity{
public class SorterEntity extends Tilec{
@Nullable Item sortItem;
@Override
@@ -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;
@@ -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);
@@ -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);
@@ -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);
}
}
@@ -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 = {""};
@@ -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;
}
}
@@ -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);
@@ -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();
}
@@ -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
@@ -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){
@@ -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
@@ -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;
@@ -88,7 +88,7 @@ public class PowerGraph{
for(Tile battery : batteries){
Consumers consumes = battery.block().consumes;
if(consumes.hasPower()){
totalAccumulator += battery.entity.power.status * consumes.getPower().capacity;
totalAccumulator += battery.entity.getPower().status * consumes.getPower().capacity;
}
}
return totalAccumulator;
@@ -99,7 +99,7 @@ public class PowerGraph{
for(Tile battery : batteries){
if(battery.block().consumes.hasPower()){
ConsumePower power = battery.block().consumes.getPower();
totalCapacity += (1f - battery.entity.power.status) * power.capacity;
totalCapacity += (1f - battery.entity.getPower().status) * power.capacity;
}
}
return totalCapacity;
@@ -124,7 +124,7 @@ public class PowerGraph{
for(Tile battery : batteries){
Consumers consumes = battery.block().consumes;
if(consumes.hasPower()){
battery.entity.power.status *= (1f-consumedPowerPercentage);
battery.entity.getPower().status *= (1f-consumedPowerPercentage);
}
}
return used;
@@ -141,7 +141,7 @@ public class PowerGraph{
if(consumes.hasPower()){
ConsumePower consumePower = consumes.getPower();
if(consumePower.capacity > 0f){
battery.entity.power.status += (1f-battery.entity.power.status) * chargedPercent;
battery.entity.getPower().status += (1f-battery.entity.getPower().status) * chargedPercent;
}
}
}
@@ -159,17 +159,17 @@ public class PowerGraph{
if(!Mathf.zero(consumePower.capacity)){
// Add an equal percentage of power to all buffers, based on the global power coverage in this graph
float maximumRate = consumePower.requestedPower(consumer.entity) * coverage * consumer.entity.delta();
consumer.entity.power.status = Mathf.clamp(consumer.entity.power.status + maximumRate / consumePower.capacity);
consumer.entity.getPower().status = Mathf.clamp(consumer.entity.getPower().status + maximumRate / consumePower.capacity);
}
}else{
//valid consumers get power as usual
if(otherConsumersAreValid(consumer, consumePower)){
consumer.entity.power.status = coverage;
consumer.entity.getPower().status = coverage;
}else{ //invalid consumers get an estimate, if they were to activate
consumer.entity.power.status = Math.min(1, produced / (needed + consumePower.usage * consumer.entity.delta()));
consumer.entity.getPower().status = Math.min(1, produced / (needed + consumePower.usage * consumer.entity.delta()));
//just in case
if(Float.isNaN(consumer.entity.power.status)){
consumer.entity.power.status = 0f;
if(Float.isNaN(consumer.entity.getPower().status)){
consumer.entity.getPower().status = 0f;
}
}
}
@@ -183,7 +183,7 @@ public class PowerGraph{
}else if(!consumers.isEmpty() && consumers.first().isEnemyCheat()){
//when cheating, just set status to 1
for(Tile tile : consumers){
tile.entity.power.status = 1f;
tile.entity.getPower().status = 1f;
}
lastPowerNeeded = lastPowerProduced = lastUsageFraction = 1f;
@@ -230,8 +230,8 @@ public class PowerGraph{
}
public void add(Tile tile){
if(tile.entity == null || tile.entity.power == null) return;
tile.entity.power.graph = this;
if(tile.entity == null || tile.entity.getPower() == null) return;
tile.entity.getPower().graph = this;
all.add(tile);
if(tile.block().outputsPower && tile.block().consumesPower && !tile.block().consumes.getPower().buffered){
@@ -277,7 +277,7 @@ public class PowerGraph{
//go through all the connections of this tile
for(Tile other : tile.block().getPowerConnections(tile, outArray1)){
//a graph has already been assigned to this tile from a previous call, skip it
if(other.entity.power.graph != this) continue;
if(other.entity.getPower().graph != this) continue;
//create graph for this branch
PowerGraph graph = new PowerGraph();
@@ -296,7 +296,7 @@ public class PowerGraph{
for(Tile next : child.block().getPowerConnections(child, outArray2)){
//make sure it hasn't looped back, and that the new graph being assigned hasn't already been assigned
//also skip closed tiles
if(next != tile && next.entity.power.graph != graph && !closedSet.contains(next.pos())){
if(next != tile && next.entity.getPower().graph != graph && !closedSet.contains(next.pos())){
queue.addLast(next);
closedSet.add(next.pos());
}
@@ -39,40 +39,40 @@ public class PowerNode extends PowerBlock{
@Override
public void configured(Tile tile, Player player, int value){
TileEntity entity = tile.entity;
Tilec entity = tile.entity;
Tile other = world.tile(value);
boolean contains = entity.power.links.contains(value), valid = other != null && other.entity != null && other.entity.power != null;
boolean contains = entity.getPower().links.contains(value), valid = other != null && other.entity != null && other.entity.getPower() != null;
if(contains){
//unlink
entity.power.links.removeValue(value);
if(valid) other.entity.power.links.removeValue(tile.pos());
entity.getPower().links.removeValue(value);
if(valid) other.entity.getPower().links.removeValue(tile.pos());
PowerGraph newgraph = new PowerGraph();
//reflow from this point, covering all tiles on this side
newgraph.reflow(tile);
if(valid && other.entity.power.graph != newgraph){
if(valid && other.entity.getPower().graph != newgraph){
//create new graph for other end
PowerGraph og = new PowerGraph();
//reflow from other end
og.reflow(other);
}
}else if(linkValid(tile, other) && valid && entity.power.links.size < maxNodes){
}else if(linkValid(tile, other) && valid && entity.getPower().links.size < maxNodes){
if(!entity.power.links.contains(other.pos())){
entity.power.links.add(other.pos());
if(!entity.getPower().links.contains(other.pos())){
entity.getPower().links.add(other.pos());
}
if(other.getTeamID() == tile.getTeamID()){
if(!other.entity.power.links.contains(tile.pos())){
other.entity.power.links.add(tile.pos());
if(!other.entity.getPower().links.contains(tile.pos())){
other.entity.getPower().links.add(tile.pos());
}
}
entity.power.graph.add(other.entity.power.graph);
entity.getPower().graph.add(other.entity.getPower().graph);
}
}
@@ -89,15 +89,15 @@ public class PowerNode extends PowerBlock{
super.setBars();
bars.add("power", entity -> new Bar(() ->
Core.bundle.format("bar.powerbalance",
((entity.power.graph.getPowerBalance() >= 0 ? "+" : "") + Strings.fixed(entity.power.graph.getPowerBalance() * 60, 1))),
((entity.getPower().graph.getPowerBalance() >= 0 ? "+" : "") + Strings.fixed(entity.getPower().graph.getPowerBalance() * 60, 1))),
() -> Pal.powerBar,
() -> Mathf.clamp(entity.power.graph.getLastPowerProduced() / entity.power.graph.getLastPowerNeeded())));
() -> Mathf.clamp(entity.getPower().graph.getLastPowerProduced() / entity.getPower().graph.getLastPowerNeeded())));
bars.add("batteries", entity -> new Bar(() ->
Core.bundle.format("bar.powerstored",
(ui.formatAmount((int)entity.power.graph.getBatteryStored())), ui.formatAmount((int)entity.power.graph.getTotalBatteryCapacity())),
(ui.formatAmount((int)entity.getPower().graph.getBatteryStored())), ui.formatAmount((int)entity.getPower().graph.getTotalBatteryCapacity())),
() -> Pal.powerBar,
() -> Mathf.clamp(entity.power.graph.getBatteryStored() / entity.power.graph.getTotalBatteryCapacity())));
() -> Mathf.clamp(entity.getPower().graph.getBatteryStored() / entity.getPower().graph.getTotalBatteryCapacity())));
}
@Override
@@ -105,7 +105,7 @@ public class PowerNode extends PowerBlock{
if(net.client()) return;
Boolf<Tile> valid = other -> other != null && other != tile && ((!other.block().outputsPower && other.block().consumesPower) || (other.block().outputsPower && !other.block().consumesPower) || other.block() instanceof PowerNode) && linkValid(tile, other)
&& !other.entity.proximity().contains(tile) && other.entity.power.graph != tile.entity.power.graph;
&& !other.entity.proximity().contains(tile) && other.entity.getPower().graph != tile.entity.getPower().graph;
tempTiles.clear();
Geometry.circle(tile.x, tile.y, (int)(laserRange + 2), (x, y) -> {
@@ -123,7 +123,7 @@ public class PowerNode extends PowerBlock{
return Float.compare(a.dst2(tile), b.dst2(tile));
});
tempTiles.each(valid, other -> {
if(!tile.entity.power.links.contains(other.pos())){
if(!tile.entity.getPower().links.contains(other.pos())){
tile.configureAny(other.pos());
}
});
@@ -132,10 +132,10 @@ public class PowerNode extends PowerBlock{
}
private void getPotentialLinks(Tile tile, Cons<Tile> others){
Boolf<Tile> valid = other -> other != null && other != tile && other.entity != null && other.entity.power != null &&
Boolf<Tile> valid = other -> other != null && other != tile && other.entity != null && other.entity.getPower() != null &&
((!other.block().outputsPower && other.block().consumesPower) || (other.block().outputsPower && !other.block().consumesPower) || other.block() instanceof PowerNode) &&
overlaps(tile.x * tilesize + offset(), tile.y * tilesize + offset(), other, laserRange * tilesize) && other.getTeam() == player.getTeam()
&& !other.entity.proximity().contains(tile) && !graphs.contains(other.entity.power.graph);
&& !other.entity.proximity().contains(tile) && !graphs.contains(other.entity.getPower().graph);
tempTiles.clear();
graphs.clear();
@@ -152,7 +152,7 @@ public class PowerNode extends PowerBlock{
return Float.compare(a.dst2(tile), b.dst2(tile));
});
tempTiles.each(valid, t -> {
graphs.add(t.entity.power.graph);
graphs.add(t.entity.getPower().graph);
others.get(t);
});
}
@@ -167,12 +167,12 @@ public class PowerNode extends PowerBlock{
@Override
public void update(Tile tile){
tile.entity.power.graph.update();
tile.entity.getPower().graph.update();
}
@Override
public boolean onConfigureTileTapped(Tile tile, Tile other){
TileEntity entity = tile.ent();
Tilec entity = tile.ent();
other = other.link();
if(linkValid(tile, other)){
@@ -181,7 +181,7 @@ public class PowerNode extends PowerBlock{
}
if(tile == other){
if(other.entity.power.links.size == 0){
if(other.entity.getPower().links.size == 0){
int[] total = {0};
getPotentialLinks(tile, link -> {
if(!insulated(tile, link) && total[0]++ < maxNodes){
@@ -189,8 +189,8 @@ public class PowerNode extends PowerBlock{
}
});
}else{
while(entity.power.links.size > 0){
tile.configure(entity.power.links.get(0));
while(entity.getPower().links.size > 0){
tile.configure(entity.getPower().links.get(0));
}
}
return false;
@@ -265,10 +265,10 @@ public class PowerNode extends PowerBlock{
public void drawLayer(Tile tile){
if(Core.settings.getInt("lasersopacity") == 0) return;
TileEntity entity = tile.ent();
Tilec entity = tile.ent();
for(int i = 0; i < entity.power.links.size; i++){
Tile link = world.tile(entity.power.links.get(i));
for(int i = 0; i < entity.getPower().links.size; i++){
Tile link = world.tile(entity.getPower().links.get(i));
if(!linkValid(tile, link)) continue;
@@ -281,7 +281,7 @@ public class PowerNode extends PowerBlock{
}
protected boolean linked(Tile tile, Tile other){
return tile.entity.power.links.contains(other.pos());
return tile.entity.getPower().links.contains(other.pos());
}
public boolean linkValid(Tile tile, Tile link){
@@ -293,7 +293,7 @@ public class PowerNode extends PowerBlock{
if(overlaps(tile, link, laserRange * tilesize) || (link.block() instanceof PowerNode && overlaps(link, tile, link.<PowerNode>cblock().laserRange * tilesize))){
if(checkMaxNodes && link.block() instanceof PowerNode){
return link.entity.power.links.size < link.<PowerNode>cblock().maxNodes || link.entity.power.links.contains(tile.pos());
return link.entity.getPower().links.size < link.<PowerNode>cblock().maxNodes || link.entity.getPower().links.contains(tile.pos());
}
return true;
}
@@ -331,7 +331,7 @@ public class PowerNode extends PowerBlock{
x2 += t2.x;
y2 += t2.y;
float fract = 1f - tile.entity.power.graph.getSatisfaction();
float fract = 1f - tile.entity.getPower().graph.getSatisfaction();
Draw.color(Color.white, Pal.powerLight, fract * 0.86f + Mathf.absin(3f, 0.1f));
Draw.alpha(opacity);
@@ -43,7 +43,7 @@ public class Cultivator extends GenericCrafter{
super.update(tile);
CultivatorEntity entity = tile.ent();
entity.warmup = Mathf.lerpDelta(entity.warmup, entity.cons.valid() ? 1f : 0f, 0.015f);
entity.warmup = Mathf.lerpDelta(entity.warmup, entity.consValid() ? 1f : 0f, 0.015f);
}
@Override
@@ -110,7 +110,7 @@ public class Cultivator extends GenericCrafter{
}
@Override
protected float getProgressIncrease(TileEntity entity, float baseTime){
protected float getProgressIncrease(Tilec entity, float baseTime){
CultivatorEntity c = (CultivatorEntity)entity;
return super.getProgressIncrease(entity, baseTime) * (1f + c.boost);
}
@@ -8,8 +8,7 @@ import arc.math.*;
import arc.util.*;
import mindustry.content.*;
import mindustry.entities.*;
import mindustry.entities.Effects.*;
import mindustry.entities.type.*;
import mindustry.gen.*;
import mindustry.gen.*;
import mindustry.graphics.*;
import mindustry.type.*;
@@ -77,7 +76,7 @@ public class Drill extends Block{
bars.add("drillspeed", e -> {
DrillEntity entity = (DrillEntity)e;
return new Bar(() -> Core.bundle.format("bar.drillspeed", Strings.fixed(entity.lastDrillSpeed * 60 * entity.timeScale, 2)), () -> Pal.ammo, () -> entity.warmup);
return new Bar(() -> Core.bundle.format("bar.drillspeed", Strings.fixed(entity.lastDrillSpeed * 60 * entity.getTimeScale(), 2)), () -> Pal.ammo, () -> entity.warmup);
});
}
@@ -129,7 +128,7 @@ public class Drill extends Block{
@Override
public boolean shouldConsume(Tile tile){
return tile.entity.items.total() < itemCapacity;
return tile.entity.getItems().total() < itemCapacity;
}
@Override
@@ -247,17 +246,17 @@ public class Drill extends Block{
entity.dominantItems = returnCount;
}
if(entity.timer.get(timerDump, dumpTime)){
if(entity.timer(timerDump, dumpTime)){
tryDump(tile, entity.dominantItem);
}
entity.drillTime += entity.warmup * entity.delta();
if(entity.items.total() < itemCapacity && entity.dominantItems > 0 && entity.cons.valid()){
if(entity.getItems().total() < itemCapacity && entity.dominantItems > 0 && entity.consValid()){
float speed = 1f;
if(entity.cons.optionalValid()){
if(entity.getCons().optionalValid()){
speed = liquidBoostIntensity;
}
@@ -269,14 +268,14 @@ public class Drill extends Block{
* entity.dominantItems * speed * entity.warmup;
if(Mathf.chance(Time.delta() * updateEffectChance * entity.warmup))
updateEffect.at(entity.x + Mathf.range(size * 2f), entity.y + Mathf.range(size * 2f));
updateEffect.at(entity.getX() + Mathf.range(size * 2f), entity.getY() + Mathf.range(size * 2f));
}else{
entity.lastDrillSpeed = 0f;
entity.warmup = Mathf.lerpDelta(entity.warmup, 0f, warmupSpeed);
return;
}
if(entity.dominantItems > 0 && entity.progress >= drillTime + hardnessDrillMultiplier * entity.dominantItem.hardness && tile.entity.items.total() < itemCapacity){
if(entity.dominantItems > 0 && entity.progress >= drillTime + hardnessDrillMultiplier * entity.dominantItem.hardness && tile.entity.getItems().total() < itemCapacity){
offloadNear(tile, entity.dominantItem);
@@ -285,8 +284,7 @@ public class Drill extends Block{
entity.index++;
entity.progress = 0f;
drillEffect.at(entity.dominantItem.color,
entity.x + Mathf.range(size), entity.y + Mathf.range(size));
drillEffect.at(entity.getX() + Mathf.range(size), entity.getY() + Mathf.range(size), entity.dominantItem.color);
}
}
@@ -318,7 +316,7 @@ public class Drill extends Block{
return drops != null && drops.hardness <= tier;
}
public static class DrillEntity extends TileEntity{
public static class DrillEntity extends Tilec{
float progress;
int index;
float warmup;
@@ -44,7 +44,7 @@ public class Fracker extends SolidPump{
@Override
public boolean shouldConsume(Tile tile){
return tile.entity.liquids.get(result) < liquidCapacity - 0.01f;
return tile.entity.getLiquids().get(result) < liquidCapacity - 0.01f;
}
@Override
@@ -55,7 +55,7 @@ public class Fracker extends SolidPump{
super.drawCracks(tile);
Draw.color(result.color);
Draw.alpha(tile.entity.liquids.get(result) / liquidCapacity);
Draw.alpha(tile.entity.getLiquids().get(result) / liquidCapacity);
Draw.rect(liquidRegion, tile.drawx(), tile.drawy());
Draw.color();
@@ -72,9 +72,9 @@ public class Fracker extends SolidPump{
public void update(Tile tile){
FrackerEntity entity = tile.ent();
if(entity.cons.valid()){
if(entity.consValid()){
if(entity.accumulator >= itemUseTime){
entity.cons.trigger();
entity.consume();
entity.accumulator -= itemUseTime;
}
@@ -87,7 +87,7 @@ public class Fracker extends SolidPump{
@Override
public float typeLiquid(Tile tile){
return tile.entity.liquids.get(result);
return tile.entity.getLiquids().get(result);
}
public static class FrackerEntity extends SolidPumpEntity{
@@ -6,8 +6,7 @@ import arc.math.*;
import arc.util.*;
import mindustry.content.*;
import mindustry.entities.*;
import mindustry.entities.Effects.*;
import mindustry.entities.type.*;
import mindustry.gen.*;
import mindustry.gen.*;
import mindustry.type.*;
import mindustry.world.*;
@@ -61,7 +60,7 @@ public class GenericCrafter extends Block{
@Override
public boolean shouldIdleSound(Tile tile){
return tile.entity.cons.valid();
return tile.entity.getCons().valid();
}
@Override
@@ -88,21 +87,21 @@ public class GenericCrafter extends Block{
public void update(Tile tile){
GenericCrafterEntity entity = tile.ent();
if(entity.cons.valid()){
if(entity.consValid()){
entity.progress += getProgressIncrease(entity, craftTime);
entity.totalProgress += entity.delta();
entity.warmup = Mathf.lerpDelta(entity.warmup, 1f, 0.02f);
if(Mathf.chance(Time.delta() * updateEffectChance)){
updateEffect.at(entity.x + Mathf.range(size * 4f), entity.y + Mathf.range(size * 4));
updateEffect.at(entity.getX() + Mathf.range(size * 4f), entity.getY() + Mathf.range(size * 4));
}
}else{
entity.warmup = Mathf.lerp(entity.warmup, 0f, 0.02f);
}
if(entity.progress >= 1f){
entity.cons.trigger();
entity.consume();
if(outputItem != null){
useContent(tile, outputItem.item);
@@ -120,7 +119,7 @@ public class GenericCrafter extends Block{
entity.progress = 0f;
}
if(outputItem != null && tile.entity.timer.get(timerDump, dumpTime)){
if(outputItem != null && tile.entity.timer(timerDump, dumpTime)){
tryDump(tile, outputItem.item);
}
@@ -136,10 +135,10 @@ public class GenericCrafter extends Block{
@Override
public boolean shouldConsume(Tile tile){
if(outputItem != null && tile.entity.items.get(outputItem.item) >= itemCapacity){
if(outputItem != null && tile.entity.getItems().get(outputItem.item) >= itemCapacity){
return false;
}
return outputLiquid == null || !(tile.entity.liquids.get(outputLiquid.liquid) >= liquidCapacity);
return outputLiquid == null || !(tile.entity.getLiquids().get(outputLiquid.liquid) >= liquidCapacity);
}
@Override
@@ -147,7 +146,7 @@ public class GenericCrafter extends Block{
return itemCapacity;
}
public static class GenericCrafterEntity extends TileEntity{
public static class GenericCrafterEntity extends Tilec{
public float progress;
public float totalProgress;
public float warmup;
@@ -6,9 +6,8 @@ import arc.graphics.g2d.Fill;
import arc.math.Mathf;
import arc.util.Time;
import mindustry.content.Fx;
import mindustry.entities.Effects;
import mindustry.entities.Effects.Effect;
import mindustry.entities.type.TileEntity;
import mindustry.entities.*;
import mindustry.gen.*;
import mindustry.type.Item;
import mindustry.type.Liquid;
import mindustry.world.Block;
@@ -31,7 +30,7 @@ public class Incinerator extends Block{
public void update(Tile tile){
IncineratorEntity entity = tile.ent();
if(entity.cons.valid()){
if(entity.consValid()){
entity.heat = Mathf.lerpDelta(entity.heat, 1f, 0.04f);
}else{
entity.heat = Mathf.lerpDelta(entity.heat, 0f, 0.02f);
@@ -85,7 +84,7 @@ public class Incinerator extends Block{
return entity.heat > 0.5f;
}
public static class IncineratorEntity extends TileEntity{
public static class IncineratorEntity extends Tilec{
public float heat;
}
}
@@ -35,7 +35,7 @@ public class LiquidConverter extends GenericCrafter{
@Override
public void drawLight(Tile tile){
if(hasLiquids && drawLiquidLight && outputLiquid.liquid.lightColor.a > 0.001f){
drawLiquidLight(tile, outputLiquid.liquid, tile.entity.liquids.get(outputLiquid.liquid));
drawLiquidLight(tile, outputLiquid.liquid, tile.entity.getLiquids().get(outputLiquid.liquid));
}
}
@@ -44,14 +44,14 @@ public class LiquidConverter extends GenericCrafter{
GenericCrafterEntity entity = tile.ent();
ConsumeLiquidBase cl = consumes.get(ConsumeType.liquid);
if(tile.entity.cons.valid()){
float use = Math.min(cl.amount * entity.delta(), liquidCapacity - entity.liquids.get(outputLiquid.liquid)) * entity.efficiency();
if(tile.entity.getCons().valid()){
float use = Math.min(cl.amount * entity.delta(), liquidCapacity - entity.getLiquids().get(outputLiquid.liquid)) * entity.efficiency();
useContent(tile, outputLiquid.liquid);
entity.progress += use / cl.amount / craftTime;
entity.liquids.add(outputLiquid.liquid, use);
entity.getLiquids().add(outputLiquid.liquid, use);
if(entity.progress >= 1f){
entity.cons.trigger();
entity.consume();
entity.progress = 0f;
}
}
@@ -48,8 +48,8 @@ public class Pump extends LiquidBlock{
public void draw(Tile tile){
Draw.rect(name, tile.drawx(), tile.drawy());
Draw.color(tile.entity.liquids.current().color);
Draw.alpha(tile.entity.liquids.total() / liquidCapacity);
Draw.color(tile.entity.getLiquids().current().color);
Draw.alpha(tile.entity.getLiquids().total() / liquidCapacity);
Draw.rect(liquidRegion, tile.drawx(), tile.drawy());
Draw.color();
}
@@ -118,16 +118,16 @@ public class Pump extends LiquidBlock{
liquidDrop = tile.floor().liquidDrop;
}
if(tile.entity.cons.valid() && liquidDrop != null){
float maxPump = Math.min(liquidCapacity - tile.entity.liquids.total(), tiles * pumpAmount * tile.entity.delta() / size / size) * tile.entity.efficiency();
tile.entity.liquids.add(liquidDrop, maxPump);
if(tile.entity.getCons().valid() && liquidDrop != null){
float maxPump = Math.min(liquidCapacity - tile.entity.getLiquids().total(), tiles * pumpAmount * tile.entity.delta() / size / size) * tile.entity.efficiency();
tile.entity.getLiquids().add(liquidDrop, maxPump);
}
if(tile.entity.liquids.currentAmount() > 0f && tile.entity.timer.get(timerContentCheck, 10)){
useContent(tile, tile.entity.liquids.current());
if(tile.entity.getLiquids().currentAmount() > 0f && tile.entity.timer(timerContentCheck, 10)){
useContent(tile, tile.entity.getLiquids().current());
}
tryDumpLiquid(tile, tile.entity.liquids.current());
tryDumpLiquid(tile, tile.entity.getLiquids().current());
}
protected boolean isValid(Tile tile){
@@ -54,7 +54,7 @@ public class Separator extends Block{
@Override
public boolean shouldConsume(Tile tile){
return tile.entity.items.total() < itemCapacity;
return tile.entity.getItems().total() < itemCapacity;
}
@Override
@@ -63,8 +63,8 @@ public class Separator extends Block{
GenericCrafterEntity entity = tile.ent();
Draw.color(tile.entity.liquids.current().color);
Draw.alpha(tile.entity.liquids.total() / liquidCapacity);
Draw.color(tile.entity.getLiquids().current().color);
Draw.alpha(tile.entity.getLiquids().total() / liquidCapacity);
Draw.rect(reg(liquidRegion), tile.drawx(), tile.drawy());
Draw.reset();
@@ -79,7 +79,7 @@ public class Separator extends Block{
entity.totalProgress += entity.warmup * entity.delta();
if(entity.cons.valid()){
if(entity.consValid()){
entity.progress += getProgressIncrease(entity, craftTime);
entity.warmup = Mathf.lerpDelta(entity.warmup, 1f, 0.02f);
}else{
@@ -104,14 +104,14 @@ public class Separator extends Block{
count += stack.amount;
}
entity.cons.trigger();
entity.consume();
if(item != null && entity.items.get(item) < itemCapacity){
if(item != null && entity.getItems().get(item) < itemCapacity){
offloadNear(tile, item);
}
}
if(entity.timer.get(timerDump, dumpTime)){
if(entity.timer(timerDump, dumpTime)){
tryDump(tile);
}
}
@@ -8,9 +8,8 @@ import arc.util.*;
import arc.util.ArcAnnotate.*;
import mindustry.content.Fx;
import mindustry.content.Liquids;
import mindustry.entities.Effects;
import mindustry.entities.Effects.Effect;
import mindustry.entities.type.TileEntity;
import mindustry.entities.*;
import mindustry.gen.*;
import mindustry.graphics.Pal;
import mindustry.type.Liquid;
import mindustry.ui.Bar;
@@ -75,8 +74,8 @@ public class SolidPump extends Pump{
SolidPumpEntity entity = tile.ent();
Draw.rect(region, tile.drawx(), tile.drawy());
Draw.color(tile.entity.liquids.current().color);
Draw.alpha(tile.entity.liquids.total() / liquidCapacity);
Draw.color(tile.entity.getLiquids().current().color);
Draw.alpha(tile.entity.getLiquids().total() / liquidCapacity);
Draw.rect(liquidRegion, tile.drawx(), tile.drawy());
Draw.color();
Draw.rect(name + "-rotator", tile.drawx(), tile.drawy(), entity.pumpTime * rotateSpeed);
@@ -106,13 +105,13 @@ public class SolidPump extends Pump{
fraction += entity.boost;
if(tile.entity.cons.valid() && typeLiquid(tile) < liquidCapacity - 0.001f){
if(tile.entity.getCons().valid() && typeLiquid(tile) < liquidCapacity - 0.001f){
float maxPump = Math.min(liquidCapacity - typeLiquid(tile), pumpAmount * entity.delta() * fraction * entity.efficiency());
tile.entity.liquids.add(result, maxPump);
tile.entity.getLiquids().add(result, maxPump);
entity.lastPump = maxPump;
entity.warmup = Mathf.lerpDelta(entity.warmup, 1f, 0.02f);
if(Mathf.chance(entity.delta() * updateEffectChance))
updateEffect.at(entity.x + Mathf.range(size * 2f), entity.y + Mathf.range(size * 2f));
updateEffect.at(entity.getX() + Mathf.range(size * 2f), entity.getY() + Mathf.range(size * 2f));
}else{
entity.warmup = Mathf.lerpDelta(entity.warmup, 0f, 0.02f);
entity.lastPump = 0f;
@@ -153,10 +152,10 @@ public class SolidPump extends Pump{
}
public float typeLiquid(Tile tile){
return tile.entity.liquids.total();
return tile.entity.getLiquids().total();
}
public static class SolidPumpEntity extends TileEntity{
public static class SolidPumpEntity extends Tilec{
public float warmup;
public float pumpTime;
public float boost;
@@ -73,9 +73,9 @@ public class ItemSource extends Block{
ItemSourceEntity entity = tile.ent();
if(entity.outputItem == null) return;
entity.items.set(entity.outputItem, 1);
entity.getItems().set(entity.outputItem, 1);
tryDump(tile, entity.outputItem);
entity.items.set(entity.outputItem, 0);
entity.getItems().set(entity.outputItem, 0);
}
@Override
@@ -92,7 +92,7 @@ public class ItemSource extends Block{
return false;
}
public class ItemSourceEntity extends TileEntity{
public class ItemSourceEntity extends Tilec{
Item outputItem;
@Override
@@ -9,6 +9,7 @@ import arc.scene.ui.layout.*;
import arc.util.*;
import arc.util.ArcAnnotate.*;
import mindustry.entities.type.*;
import mindustry.gen.*;
import mindustry.entities.units.*;
import mindustry.gen.*;
import mindustry.type.*;
@@ -53,9 +54,9 @@ public class LiquidSource extends Block{
LiquidSourceEntity entity = tile.ent();
if(entity.source == null){
tile.entity.liquids.clear();
tile.entity.getLiquids().clear();
}else{
tile.entity.liquids.add(entity.source, liquidCapacity);
tile.entity.getLiquids().add(entity.source, liquidCapacity);
tryDumpLiquid(tile, entity.source);
}
}
@@ -112,7 +113,7 @@ public class LiquidSource extends Block{
tile.<LiquidSourceEntity>ent().source = value == -1 ? null : content.liquid(value);
}
class LiquidSourceEntity extends TileEntity{
class LiquidSourceEntity extends Tilec{
public @Nullable Liquid source = null;
@Override
@@ -10,6 +10,7 @@ import arc.math.geom.*;
import mindustry.content.*;
import mindustry.entities.traits.*;
import mindustry.entities.type.*;
import mindustry.gen.*;
import mindustry.game.EventType.*;
import mindustry.gen.*;
import mindustry.graphics.*;
@@ -70,7 +71,7 @@ public class CoreBlock extends StorageBlock{
@Override
public boolean acceptItem(Item item, Tile tile, Tile source){
return tile.entity.items.get(item) < getMaximumAccepted(tile, item);
return tile.entity.getItems().get(item) < getMaximumAccepted(tile, item);
}
@Override
@@ -83,27 +84,27 @@ public class CoreBlock extends StorageBlock{
public void onProximityUpdate(Tile tile){
CoreEntity entity = tile.ent();
for(TileEntity other : state.teams.cores(tile.getTeam())){
for(Tilec other : state.teams.cores(tile.getTeam())){
if(other.tile != tile){
entity.items = other.items;
entity.getItems() = other.items;
}
}
state.teams.registerCore(entity);
entity.storageCapacity = itemCapacity + entity.proximity().sum(e -> isContainer(e) ? e.block().itemCapacity : 0);
entity.proximity().each(this::isContainer, t -> {
t.entity.items = entity.items;
t.entity.getItems() = entity.getItems();
t.<StorageBlockEntity>ent().linkedCore = tile;
});
for(TileEntity other : state.teams.cores(tile.getTeam())){
for(Tilec other : state.teams.cores(tile.getTeam())){
if(other.tile == tile) continue;
entity.storageCapacity += other.block.itemCapacity + other.proximity().sum(e -> isContainer(e) ? e.block().itemCapacity : 0);
}
if(!world.isGenerating()){
for(Item item : content.items()){
entity.items.set(item, Math.min(entity.items.get(item), entity.storageCapacity));
entity.getItems().set(item, Math.min(entity.getItems().get(item), entity.storageCapacity));
}
}
@@ -122,10 +123,10 @@ public class CoreBlock extends StorageBlock{
Draw.rect("block-select", t.drawx() + offset * p.x, t.drawy() + offset * p.y, i * 90);
}
};
if(tile.entity.proximity().contains(e -> isContainer(e) && e.entity.items == tile.entity.items)){
if(tile.entity.proximity().contains(e -> isContainer(e) && e.entity.getItems() == tile.entity.getItems())){
outline.get(tile);
}
tile.entity.proximity().each(e -> isContainer(e) && e.entity.items == tile.entity.items, outline);
tile.entity.proximity().each(e -> isContainer(e) && e.entity.getItems() == tile.entity.getItems(), outline);
Draw.reset();
}
@@ -150,15 +151,15 @@ public class CoreBlock extends StorageBlock{
@Override
public void removed(Tile tile){
CoreEntity entity = tile.ent();
int total = tile.entity.proximity().count(e -> e.entity != null && e.entity.items != null && e.entity.items == tile.entity.items);
int total = tile.entity.proximity().count(e -> e.entity != null && e.entity.getItems() != null && e.entity.getItems() == tile.entity.getItems());
float fract = 1f / total / state.teams.cores(tile.getTeam()).size;
tile.entity.proximity().each(e -> isContainer(e) && e.entity.items == tile.entity.items, t -> {
tile.entity.proximity().each(e -> isContainer(e) && e.entity.getItems() == tile.entity.getItems(), t -> {
StorageBlockEntity ent = (StorageBlockEntity)t.entity;
ent.linkedCore = null;
ent.items = new ItemModule();
for(Item item : content.items()){
ent.items.set(item, (int)(fract * tile.entity.items.get(item)));
ent.items.set(item, (int)(fract * tile.entity.getItems().get(item)));
}
});
@@ -166,7 +167,7 @@ public class CoreBlock extends StorageBlock{
int max = itemCapacity * state.teams.cores(tile.getTeam()).size;
for(Item item : content.items()){
tile.entity.items.set(item, Math.min(tile.entity.items.get(item), max));
tile.entity.getItems().set(item, Math.min(tile.entity.getItems().get(item), max));
}
for(CoreEntity other : state.teams.cores(tile.getTeam())){
@@ -230,7 +231,7 @@ public class CoreBlock extends StorageBlock{
return entity.spawnPlayer != null;
}
public class CoreEntity extends TileEntity implements SpawnerTrait{
public class CoreEntity extends Tilec implements SpawnerTrait{
protected Player spawnPlayer;
protected float progress;
protected float time;
@@ -7,8 +7,7 @@ import arc.math.Mathf;
import arc.util.Time;
import mindustry.Vars;
import mindustry.content.Fx;
import mindustry.entities.Effects;
import mindustry.entities.type.TileEntity;
import mindustry.gen.*;
import mindustry.game.EventType.*;
import mindustry.graphics.Pal;
import mindustry.type.Item;
@@ -41,14 +40,14 @@ public class LaunchPad extends StorageBlock{
@Override
public boolean acceptItem(Item item, Tile tile, Tile source){
return item.type == ItemType.material && tile.entity.items.total() < itemCapacity;
return item.type == ItemType.material && tile.entity.getItems().total() < itemCapacity;
}
@Override
public void draw(Tile tile){
super.draw(tile);
float progress = Mathf.clamp(Mathf.clamp((tile.entity.items.total() / (float)itemCapacity)) * ((tile.entity.timer.getTime(timerLaunch) / (launchTime / tile.entity.timeScale))));
float progress = Mathf.clamp(Mathf.clamp((tile.entity.getItems().total() / (float)itemCapacity)) * ((tile.entity.timerTime(timerLaunch) / (launchTime / tile.entity.timeScale))));
float scale = size / 3f;
Lines.stroke(2f);
@@ -57,7 +56,7 @@ public class LaunchPad extends StorageBlock{
Draw.color(Pal.accent);
if(tile.entity.cons.valid()){
if(tile.entity.getCons().valid()){
for(int i = 0; i < 3; i++){
float f = (Time.time() / 200f + i * 0.5f) % 1f;
@@ -71,15 +70,15 @@ public class LaunchPad extends StorageBlock{
@Override
public void update(Tile tile){
TileEntity entity = tile.entity;
Tilec entity = tile.entity;
if(world.isZone() && entity.cons.valid() && entity.items.total() >= itemCapacity && entity.timer.get(timerLaunch, launchTime / entity.timeScale)){
if(world.isZone() && entity.consValid() && entity.getItems().total() >= itemCapacity && entity.timer(timerLaunch, launchTime / entity.timeScale)){
for(Item item : Vars.content.items()){
Events.fire(Trigger.itemLaunch);
Fx.padlaunch.at(tile);
int used = Math.min(entity.items.get(item), itemCapacity);
int used = Math.min(entity.getItems().get(item), itemCapacity);
data.addItem(item, used);
entity.items.remove(item, used);
entity.getItems().remove(item, used);
Events.fire(new LaunchItemEvent(item, used));
}
}
@@ -1,7 +1,7 @@
package mindustry.world.blocks.storage;
import arc.util.ArcAnnotate.*;
import mindustry.entities.type.TileEntity;
import mindustry.gen.*;
import mindustry.type.Item;
import mindustry.world.Block;
import mindustry.world.Tile;
@@ -17,7 +17,7 @@ public abstract class StorageBlock extends Block{
@Override
public boolean acceptItem(Item item, Tile tile, Tile source){
StorageBlockEntity entity = tile.ent();
return entity.linkedCore != null ? entity.linkedCore.block().acceptItem(item, entity.linkedCore, source) : tile.entity.items.get(item) < getMaximumAccepted(tile, item);
return entity.linkedCore != null ? entity.linkedCore.block().acceptItem(item, entity.linkedCore, source) : tile.entity.getItems().get(item) < getMaximumAccepted(tile, item);
}
@Override
@@ -43,13 +43,13 @@ public abstract class StorageBlock extends Block{
* Returns null if no items are there.
*/
public Item removeItem(Tile tile, Item item){
TileEntity entity = tile.entity;
Tilec entity = tile.entity;
if(item == null){
return entity.items.take();
return entity.getItems().take();
}else{
if(entity.items.has(item)){
entity.items.remove(item, 1);
if(entity.getItems().has(item)){
entity.getItems().remove(item, 1);
return item;
}
@@ -62,15 +62,15 @@ public abstract class StorageBlock extends Block{
* If the item is null, it should return whether it has ANY items.
*/
public boolean hasItem(Tile tile, Item item){
TileEntity entity = tile.entity;
Tilec entity = tile.entity;
if(item == null){
return entity.items.total() > 0;
return entity.getItems().total() > 0;
}else{
return entity.items.has(item);
return entity.getItems().has(item);
}
}
public class StorageBlockEntity extends TileEntity{
public class StorageBlockEntity extends Tilec{
protected @Nullable
Tile linkedCore;
}
@@ -55,7 +55,7 @@ public class Unloader extends Block{
@Override
public void configured(Tile tile, Player player, int value){
tile.entity.items.clear();
tile.entity.getItems().clear();
tile.<UnloaderEntity>ent().sortItem = content.item(value);
}
@@ -63,16 +63,16 @@ public class Unloader extends Block{
public void update(Tile tile){
UnloaderEntity entity = tile.ent();
if(tile.entity.timer.get(timerUnload, speed / entity.timeScale) && tile.entity.items.total() == 0){
if(tile.entity.timer(timerUnload, speed / entity.timeScale) && tile.entity.getItems().total() == 0){
for(Tile other : tile.entity.proximity()){
if(other.interactable(tile.getTeam()) && other.block().unloadable && other.block().hasItems && entity.items.total() == 0 &&
((entity.sortItem == null && other.entity.items.total() > 0) || hasItem(other, entity.sortItem))){
if(other.interactable(tile.getTeam()) && other.block().unloadable && other.block().hasItems && entity.getItems().total() == 0 &&
((entity.sortItem == null && other.entity.getItems().total() > 0) || hasItem(other, entity.sortItem))){
offloadNear(tile, removeItem(other, entity.sortItem));
}
}
}
if(entity.items.total() > 0){
if(entity.getItems().total() > 0){
tryDump(tile);
}
}
@@ -82,13 +82,13 @@ public class Unloader extends Block{
* Returns null if no items are there.
*/
private Item removeItem(Tile tile, Item item){
TileEntity entity = tile.entity;
Tilec entity = tile.entity;
if(item == null){
return entity.items.take();
return entity.getItems().take();
}else{
if(entity.items.has(item)){
entity.items.remove(item, 1);
if(entity.getItems().has(item)){
entity.getItems().remove(item, 1);
return item;
}
@@ -101,11 +101,11 @@ public class Unloader extends Block{
* If the item is null, it should return whether it has ANY items.
*/
private boolean hasItem(Tile tile, Item item){
TileEntity entity = tile.entity;
Tilec entity = tile.entity;
if(item == null){
return entity.items.total() > 0;
return entity.getItems().total() > 0;
}else{
return entity.items.has(item);
return entity.getItems().has(item);
}
}
@@ -129,7 +129,7 @@ public class Unloader extends Block{
});
}
public static class UnloaderEntity extends TileEntity{
public static class UnloaderEntity extends Tilec{
public Item sortItem = null;
@Override
@@ -10,7 +10,6 @@ import arc.struct.*;
import arc.util.*;
import mindustry.content.*;
import mindustry.entities.*;
import mindustry.entities.Effects.*;
import mindustry.entities.type.*;
import mindustry.entities.units.*;
import mindustry.game.EventType.*;
@@ -118,7 +117,7 @@ public class CommandCenter extends Block{
Events.fire(new CommandIssueEvent(tile, command));
}
public class CommandCenterEntity extends TileEntity{
public class CommandCenterEntity extends Tilec{
public UnitCommand command = UnitCommand.attack;
@Override
@@ -11,6 +11,7 @@ import arc.util.ArcAnnotate.*;
import mindustry.content.*;
import mindustry.entities.traits.*;
import mindustry.entities.type.*;
import mindustry.gen.*;
import mindustry.game.EventType.*;
import mindustry.gen.*;
import mindustry.graphics.*;
@@ -49,7 +50,7 @@ public class MechPad extends Block{
MechFactoryEntity entity = tile.ent();
if(!entity.cons.valid()) return;
if(!entity.consValid()) return;
player.beginRespawning(entity);
entity.sameMech = false;
}
@@ -80,7 +81,7 @@ public class MechPad extends Block{
protected static boolean checkValidTap(Tile tile, Player player){
MechFactoryEntity entity = tile.ent();
return !player.isDead() && tile.interactable(player.getTeam()) && Math.abs(player.x - tile.drawx()) <= tile.block().size * tilesize &&
Math.abs(player.y - tile.drawy()) <= tile.block().size * tilesize && entity.cons.valid() && entity.player == null;
Math.abs(player.y - tile.drawy()) <= tile.block().size * tilesize && entity.consValid() && entity.player == null;
}
@Override
@@ -99,7 +100,7 @@ public class MechPad extends Block{
if(checkValidTap(tile, player)){
Call.onMechFactoryTap(player, tile);
}else if(player.isLocal && mobile && !player.isDead() && entity.cons.valid() && entity.player == null){
}else if(player.isLocal && mobile && !player.isDead() && entity.consValid() && entity.player == null){
//deselect on double taps
player.moveTarget = player.moveTarget == tile.entity ? null : tile.entity;
}
@@ -133,7 +134,7 @@ public class MechPad extends Block{
}
}
public class MechFactoryEntity extends TileEntity implements SpawnerTrait{
public class MechFactoryEntity extends Tilec implements SpawnerTrait{
Player player;
boolean sameMech;
float progress;
@@ -9,7 +9,7 @@ import arc.math.Mathf;
import arc.math.geom.Rect;
import arc.util.Time;
import mindustry.entities.Units;
import mindustry.entities.type.TileEntity;
import mindustry.gen.*;
import mindustry.graphics.*;
import mindustry.world.Block;
import mindustry.world.Tile;
@@ -112,7 +112,7 @@ public class RepairPoint extends Block{
boolean targetIsBeingRepaired = false;
if(entity.target != null && (entity.target.isDead() || entity.target.dst(tile) > repairRadius || entity.target.health >= entity.target.maxHealth())){
entity.target = null;
}else if(entity.target != null && entity.cons.valid()){
}else if(entity.target != null && entity.consValid()){
entity.target.health += repairSpeed * Time.delta() * entity.strength * entity.efficiency();
entity.target.clampHealth();
entity.rotation = Mathf.slerpDelta(entity.rotation, entity.angleTo(entity.target), 0.5f);
@@ -125,7 +125,7 @@ public class RepairPoint extends Block{
entity.strength = Mathf.lerpDelta(entity.strength, 0f, 0.07f * Time.delta());
}
if(entity.timer.get(timerTarget, 20)){
if(entity.timer(timerTarget, 20)){
rect.setSize(repairRadius * 2).setCenter(tile.drawx(), tile.drawy());
entity.target = Units.closest(tile.getTeam(), tile.drawx(), tile.drawy(), repairRadius,
unit -> unit.health < unit.maxHealth());
@@ -139,7 +139,7 @@ public class RepairPoint extends Block{
return entity.target != null;
}
public class RepairPointEntity extends TileEntity{
public class RepairPointEntity extends Tilec{
public Unitc target;
public float strength, rotation = 90;
}
@@ -159,7 +159,7 @@ public class UnitFactory extends Block{
return;
}
if(entity.cons.valid() || tile.isEnemyCheat()){
if(entity.consValid() || tile.isEnemyCheat()){
entity.time += entity.delta() * entity.speedScl * Vars.state.rules.unitBuildSpeedMultiplier * entity.efficiency();
entity.buildTime += entity.delta() * entity.efficiency() * Vars.state.rules.unitBuildSpeedMultiplier;
entity.speedScl = Mathf.lerpDelta(entity.speedScl, 1f, 0.05f);
@@ -173,7 +173,7 @@ public class UnitFactory extends Block{
Call.onUnitFactorySpawn(tile, entity.spawned + 1);
useContent(tile, unitType);
entity.cons.trigger();
entity.consume();
}
}
@@ -188,7 +188,7 @@ public class UnitFactory extends Block{
return entity.spawned < maxSpawn;
}
public static class UnitFactoryEntity extends TileEntity{
public static class UnitFactoryEntity extends Tilec{
float buildTime;
float time;
float speedScl;
@@ -2,7 +2,7 @@ package mindustry.world.consumers;
import arc.struct.*;
import arc.scene.ui.layout.Table;
import mindustry.entities.type.TileEntity;
import mindustry.gen.*;
import mindustry.world.Tile;
import mindustry.world.meta.BlockStats;
@@ -62,15 +62,15 @@ public abstract class Consume{
public abstract void build(Tile tile, Table table);
/** Called when a consumption is triggered manually. */
public void trigger(TileEntity entity){
public void trigger(Tilec entity){
}
public abstract String getIcon();
public abstract void update(TileEntity entity);
public abstract void update(Tilec entity);
public abstract boolean valid(TileEntity entity);
public abstract boolean valid(Tilec entity);
public abstract void display(BlockStats stats);
}
@@ -35,7 +35,7 @@ public class ConsumeItemFilter extends Consume{
@Override
public void build(Tile tile, Table table){
MultiReqImage image = new MultiReqImage();
content.items().each(i -> filter.get(i) && (!world.isZone() || data.isUnlocked(i)), item -> image.add(new ReqImage(new ItemImage(item.icon(Cicon.medium), 1), () -> tile.entity != null && tile.entity.items != null && tile.entity.items.has(item))));
content.items().each(i -> filter.get(i) && (!world.isZone() || data.isUnlocked(i)), item -> image.add(new ReqImage(new ItemImage(item.icon(Cicon.medium), 1), () -> tile.entity != null && tile.entity.getItems() != null && tile.entity.getItems().has(item))));
table.add(image).size(8 * 4);
}
@@ -46,26 +46,26 @@ public class ConsumeItemFilter extends Consume{
}
@Override
public void update(TileEntity entity){
public void update(Tilec entity){
}
@Override
public void trigger(TileEntity entity){
public void trigger(Tilec entity){
for(int i = 0; i < content.items().size; i++){
Item item = content.item(i);
if(entity.items != null && entity.items.has(item) && this.filter.get(item)){
entity.items.remove(item, 1);
if(entity.getItems() != null && entity.getItems().has(item) && this.filter.get(item)){
entity.getItems().remove(item, 1);
break;
}
}
}
@Override
public boolean valid(TileEntity entity){
public boolean valid(Tilec entity){
for(int i = 0; i < content.items().size; i++){
Item item = content.item(i);
if(entity.items != null && entity.items.has(item) && this.filter.get(item)){
if(entity.getItems() != null && entity.getItems().has(item) && this.filter.get(item)){
return true;
}
}
@@ -38,7 +38,7 @@ public class ConsumeItems extends Consume{
@Override
public void build(Tile tile, Table table){
for(ItemStack stack : items){
table.add(new ReqImage(new ItemImage(stack.item.icon(Cicon.medium), stack.amount), () -> tile.entity != null && tile.entity.items != null && tile.entity.items.has(stack.item, stack.amount))).size(8 * 4).padRight(5);
table.add(new ReqImage(new ItemImage(stack.item.icon(Cicon.medium), stack.amount), () -> tile.entity != null && tile.entity.getItems() != null && tile.entity.getItems().has(stack.item, stack.amount))).size(8 * 4).padRight(5);
}
}
@@ -48,20 +48,20 @@ public class ConsumeItems extends Consume{
}
@Override
public void update(TileEntity entity){
public void update(Tilec entity){
}
@Override
public void trigger(TileEntity entity){
public void trigger(Tilec entity){
for(ItemStack stack : items){
entity.items.remove(stack);
entity.getItems().remove(stack);
}
}
@Override
public boolean valid(TileEntity entity){
return entity.items != null && entity.items.has(items);
public boolean valid(Tilec entity){
return entity.getItems() != null && entity.getItems().has(items);
}
@Override
@@ -38,13 +38,13 @@ public class ConsumeLiquid extends ConsumeLiquidBase{
}
@Override
public void update(TileEntity entity){
entity.liquids.remove(liquid, Math.min(use(entity), entity.liquids.get(liquid)));
public void update(Tilec entity){
entity.getLiquids().remove(liquid, Math.min(use(entity), entity.getLiquids().get(liquid)));
}
@Override
public boolean valid(TileEntity entity){
return entity != null && entity.liquids != null && entity.liquids.get(liquid) >= use(entity);
public boolean valid(Tilec entity){
return entity != null && entity.getLiquids() != null && entity.getLiquids().get(liquid) >= use(entity);
}
@Override
@@ -1,6 +1,6 @@
package mindustry.world.consumers;
import mindustry.entities.type.TileEntity;
import mindustry.gen.*;
public abstract class ConsumeLiquidBase extends Consume{
/** amount used per frame */
@@ -22,7 +22,7 @@ public abstract class ConsumeLiquidBase extends Consume{
return ConsumeType.liquid;
}
protected float use(TileEntity entity){
protected float use(Tilec entity){
return Math.min(amount * entity.delta(), entity.block.liquidCapacity);
}
}
@@ -3,7 +3,7 @@ package mindustry.world.consumers;
import arc.struct.*;
import arc.func.Boolf;
import arc.scene.ui.layout.Table;
import mindustry.entities.type.TileEntity;
import mindustry.gen.*;
import mindustry.type.Liquid;
import mindustry.ui.Cicon;
import mindustry.ui.MultiReqImage;
@@ -32,7 +32,7 @@ public class ConsumeLiquidFilter extends ConsumeLiquidBase{
public void build(Tile tile, Table table){
Array<Liquid> list = content.liquids().select(l -> !l.isHidden() && filter.get(l));
MultiReqImage image = new MultiReqImage();
list.each(liquid -> image.add(new ReqImage(liquid.icon(Cicon.medium), () -> tile.entity != null && tile.entity.liquids != null && tile.entity.liquids.get(liquid) >= use(tile.entity))));
list.each(liquid -> image.add(new ReqImage(liquid.icon(Cicon.medium), () -> tile.entity != null && tile.entity.getLiquids() != null && tile.entity.getLiquids().get(liquid) >= use(tile.entity))));
table.add(image).size(8 * 4);
}
@@ -43,13 +43,13 @@ public class ConsumeLiquidFilter extends ConsumeLiquidBase{
}
@Override
public void update(TileEntity entity){
entity.liquids.remove(entity.liquids.current(), use(entity));
public void update(Tilec entity){
entity.getLiquids().remove(entity.getLiquids().current(), use(entity));
}
@Override
public boolean valid(TileEntity entity){
return entity != null && entity.liquids != null && filter.get(entity.liquids.current()) && entity.liquids.currentAmount() >= use(entity);
public boolean valid(Tilec entity){
return entity != null && entity.getLiquids() != null && filter.get(entity.getLiquids().current()) && entity.getLiquids().currentAmount() >= use(entity);
}
@Override
@@ -2,7 +2,7 @@ package mindustry.world.consumers;
import arc.math.Mathf;
import arc.scene.ui.layout.Table;
import mindustry.entities.type.TileEntity;
import mindustry.gen.*;
import mindustry.world.Tile;
import mindustry.world.meta.*;
@@ -41,16 +41,16 @@ public class ConsumePower extends Consume{
}
@Override
public void update(TileEntity entity){
// Nothing to do since PowerGraph directly updates entity.power.status
public void update(Tilec entity){
// Nothing to do since PowerGraph directly updates entity.getPower().status
}
@Override
public boolean valid(TileEntity entity){
public boolean valid(Tilec entity){
if(buffered){
return true;
}else{
return entity.power.status > 0f;
return entity.getPower().status > 0f;
}
}
@@ -68,13 +68,13 @@ public class ConsumePower extends Consume{
* @param entity The entity which contains the power module.
* @return The amount of power which is requested per tick.
*/
public float requestedPower(TileEntity entity){
if(entity.tile.entity == null) return 0f;
public float requestedPower(Tilec entity){
if(entity.getTile().entity == null) return 0f;
if(buffered){
return (1f-entity.power.status)*capacity;
return (1f-entity.getPower().status)*capacity;
}else{
try{
return usage * Mathf.num(entity.block.shouldConsume(entity.tile));
return usage * Mathf.num(entity.getBlock().shouldConsume(entity.getTile()));
}catch(Exception e){
//HACK an error will only happen with a bar that is checking its requested power, and the entity is null/a different class
return 0;
@@ -4,7 +4,7 @@ import arc.struct.*;
import arc.func.Boolf;
import arc.util.Structs;
import mindustry.Vars;
import mindustry.entities.type.TileEntity;
import mindustry.gen.*;
import mindustry.type.*;
import mindustry.world.blocks.power.ConditionalConsumePower;
import mindustry.world.meta.BlockStats;
@@ -48,7 +48,7 @@ public class Consumers{
}
/** Creates a consumer which only consumes power when the condition is met. */
public ConsumePower powerCond(float usage, Boolf<TileEntity> cons){
public ConsumePower powerCond(float usage, Boolf<Tilec> cons){
return add(new ConditionalConsumePower(usage, cons));
}
+4 -4
View File
@@ -2,13 +2,13 @@ package mindustry.world.meta;
import arc.struct.OrderedMap;
import arc.func.Func;
import mindustry.entities.type.TileEntity;
import mindustry.gen.*;
import mindustry.ui.Bar;
public class BlockBars{
private OrderedMap<String, Func<TileEntity, Bar>> bars = new OrderedMap<>();
private OrderedMap<String, Func<Tilec, Bar>> bars = new OrderedMap<>();
public void add(String name, Func<TileEntity, Bar> sup){
public void add(String name, Func<Tilec, Bar> sup){
bars.put(name, sup);
}
@@ -18,7 +18,7 @@ public class BlockBars{
bars.remove(name);
}
public Iterable<Func<TileEntity, Bar>> list(){
public Iterable<Func<Tilec, Bar>> list(){
return bars.values();
}
}
@@ -1,15 +1,15 @@
package mindustry.world.modules;
import mindustry.entities.type.TileEntity;
import mindustry.gen.*;
import mindustry.world.consumers.Consume;
import java.io.*;
public class ConsumeModule extends BlockModule{
private boolean valid, optionalValid;
private final TileEntity entity;
private final Tilec entity;
public ConsumeModule(TileEntity entity){
public ConsumeModule(Tilec entity){
this.entity = entity;
}