More cleanup
This commit is contained in:
@@ -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));
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user