Variable name refactorings / Untested entity sleeping

This commit is contained in:
Anuken
2018-04-17 09:31:41 -04:00
parent 47d61c4a0e
commit b020bf6816
56 changed files with 269 additions and 244 deletions

View File

@@ -141,6 +141,7 @@ public class Vars{
public static final EntityGroup<Player> playerGroup = Entities.addGroup(Player.class).enableMapping();
public static final EntityGroup<TileEntity> tileGroup = Entities.addGroup(TileEntity.class, false);
public static final EntityGroup<TileEntity> disabledTileGroup = Entities.addGroup(TileEntity.class, false);
public static final EntityGroup<Bullet> bulletGroup = Entities.addGroup(Bullet.class);
public static final EntityGroup<Shield> shieldGroup = Entities.addGroup(Shield.class, false);
public static final EntityGroup<EffectEntity> effectGroup = Entities.addGroup(EffectEntity.class, false);

View File

@@ -166,7 +166,7 @@ public class CraftingBlocks {
craftEffect = BlockFx.pulverize;
craftTime = 60f;
updateEffect = BlockFx.pulverizeSmall;
hasInventory = hasPower = true;
hasItems = hasPower = true;
}},
oilRefinery = new GenericCrafter("oilrefinery") {{
@@ -177,7 +177,7 @@ public class CraftingBlocks {
output = Items.coal;
health = 80;
craftEffect = BlockFx.purifyoil;
hasInventory = hasLiquids = hasPower = true;
hasItems = hasLiquids = hasPower = true;
}},
stoneFormer = new GenericCrafter("stoneformer") {{
@@ -188,7 +188,7 @@ public class CraftingBlocks {
output = Items.stone;
health = 80;
craftEffect = BlockFx.purifystone;
hasLiquids = hasInventory = true;
hasLiquids = hasItems = true;
}},
weaponFactory = new WeaponFactory("weaponfactory") {{

View File

@@ -45,7 +45,7 @@ public class DebugBlocks {
@Override
public void update(Tile tile) {
SorterEntity entity = tile.entity();
entity.inventory.items[entity.sortItem.id] = 1;
entity.items.items[entity.sortItem.id] = 1;
tryDump(tile, entity.sortItem);
}
@@ -72,8 +72,8 @@ public class DebugBlocks {
public void update(Tile tile) {
LiquidSourceEntity entity = tile.entity();
tile.entity.liquid.amount = liquidCapacity;
tile.entity.liquid.liquid = entity.source;
tile.entity.liquids.amount = liquidCapacity;
tile.entity.liquids.liquid = entity.source;
tryDumpLiquid(tile);
}

View File

@@ -76,13 +76,13 @@ public class PowerBlocks {
battery = new PowerGenerator("battery") {{
powerCapacity = 320f;
hasInventory = false;
hasItems = false;
}},
batteryLarge = new PowerGenerator("batterylarge") {{
size = 3;
powerCapacity = 2000f;
hasInventory = false;
hasItems = false;
}},
powernode = new PowerDistributor("powernode"),

View File

@@ -134,8 +134,8 @@ public class WeaponBlocks{
drawer = (tile, entity) -> {
Draw.rect(name, tile.drawx() + tr2.x, tile.drawy() + tr2.y, entity.rotation - 90);
Draw.color(entity.liquid.liquid.color);
Draw.alpha(entity.liquid.amount/liquidCapacity);
Draw.color(entity.liquids.liquid.color);
Draw.alpha(entity.liquids.amount/liquidCapacity);
Draw.rect(name + "-liquid", tile.drawx() + tr2.x, tile.drawy() + tr2.y, entity.rotation - 90);
Draw.color();
};

View File

@@ -19,19 +19,25 @@ import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import static io.anuke.mindustry.Vars.disabledTileGroup;
import static io.anuke.mindustry.Vars.tileGroup;
import static io.anuke.mindustry.Vars.world;
public class TileEntity extends Entity{
public static final float timeToSleep = 60f*3; //3 seconds to fall asleep
public Tile tile;
public Timer timer;
public float health;
public boolean dead = false;
public boolean added;
public PowerModule power;
public InventoryModule inventory;
public LiquidModule liquid;
public InventoryModule items;
public LiquidModule liquids;
private boolean added;
private boolean sleeping;
private float sleepTime;
/**Sets this tile entity data to this tile, and adds it if necessary.*/
public TileEntity init(Tile tile, boolean added){
@@ -50,14 +56,31 @@ public class TileEntity extends Entity{
return this;
}
public void write(DataOutputStream stream) throws IOException{
/**Call when nothing is happening to the entity.
* This increments the internal sleep timer.*/
public void sleep(){
sleepTime += Timers.delta();
if(!sleeping && sleepTime >= timeToSleep){
remove();
add(disabledTileGroup);
sleeping = true;
}
}
/**Call when something just happened to the entity.
* If the entity was sleeping, this enables it. This also resets the sleep timer.*/
public void wakeUp(){
sleepTime = 0f;
if(sleeping){
remove();
add(tileGroup);
sleeping = false;
}
}
public void read(DataInputStream stream) throws IOException{
}
public void write(DataOutputStream stream) throws IOException{}
public void read(DataInputStream stream) throws IOException{}
public void onDeath(){
onDeath(false);
@@ -81,6 +104,10 @@ public class TileEntity extends Entity{
}
}
}
public boolean collide(Bullet other){
return true;
}
public void collision(Bullet other){
damage(other.getDamage());
@@ -98,13 +125,10 @@ public class TileEntity extends Entity{
}
}
public boolean collide(Bullet other){
return true;
}
@Override
public void update(){
synchronized (Tile.tileSetLock) {
//TODO better smoke effect, this one is awful
if (health != 0 && health < tile.block().health && !(tile.block() instanceof Wall) &&
Mathf.chance(0.009f * Timers.delta() * (1f - health / tile.block().health))) {

View File

@@ -91,6 +91,6 @@ public class Inventory {
if(set.size == 0) return empty;
Array<Tile> tiles = set.first().cores;
if(tiles.size == 0) return empty;
return tiles.first().entity.inventory.items;
return tiles.first().entity.items.items;
}
}

View File

@@ -118,9 +118,9 @@ public class Save16 extends SaveFileVersion {
tile.entity.health = health;
tile.setRotation(rotation);
if (tile.entity.inventory != null) tile.entity.inventory.read(stream);
if (tile.entity.items != null) tile.entity.items.read(stream);
if (tile.entity.power != null) tile.entity.power.read(stream);
if (tile.entity.liquid != null) tile.entity.liquid.read(stream);
if (tile.entity.liquids != null) tile.entity.liquids.read(stream);
tile.entity.read(stream);
@@ -206,9 +206,9 @@ public class Save16 extends SaveFileVersion {
stream.writeByte(Bits.packByte((byte)tile.getTeam().ordinal(), tile.getRotation())); //team + rotation
stream.writeShort((short)tile.entity.health); //health
if(tile.entity.inventory != null) tile.entity.inventory.write(stream);
if(tile.entity.items != null) tile.entity.items.write(stream);
if(tile.entity.power != null) tile.entity.power.write(stream);
if(tile.entity.liquid != null) tile.entity.liquid.write(stream);
if(tile.entity.liquids != null) tile.entity.liquids.write(stream);
tile.entity.write(stream);
}

View File

@@ -69,9 +69,9 @@ public class NetworkIO {
stream.writeByte(Bits.packByte((byte)tile.getTeam().ordinal(), tile.getRotation()));
stream.writeShort((short)tile.entity.health); //health
if(tile.entity.inventory != null) tile.entity.inventory.write(stream);
if(tile.entity.items != null) tile.entity.items.write(stream);
if(tile.entity.power != null) tile.entity.power.write(stream);
if(tile.entity.liquid != null) tile.entity.liquid.write(stream);
if(tile.entity.liquids != null) tile.entity.liquids.write(stream);
tile.entity.write(stream);
}
@@ -156,9 +156,9 @@ public class NetworkIO {
tile.entity.health = health;
if (tile.entity.inventory != null) tile.entity.inventory.read(stream);
if (tile.entity.items != null) tile.entity.items.read(stream);
if (tile.entity.power != null) tile.entity.power.read(stream);
if (tile.entity.liquid != null) tile.entity.liquid.read(stream);
if (tile.entity.liquids != null) tile.entity.liquids.read(stream);
tile.entity.read(stream);
}

View File

@@ -63,8 +63,8 @@ public class BlockInventoryFragment implements Fragment {
hide();
}else {
updateTablePosition();
if(tile.block().hasInventory) {
int[] items = tile.entity.inventory.items;
if(tile.block().hasItems) {
int[] items = tile.entity.items.items;
for (int i = 0; i < items.length; i++) {
if ((items[i] == 0) == container.contains(i)) {
rebuild();
@@ -80,8 +80,8 @@ public class BlockInventoryFragment implements Fragment {
table.margin(3f);
table.defaults().size(16 * 2).space(6f);
if(tile.block().hasInventory) {
int[] items = tile.entity.inventory.items;
if(tile.block().hasItems) {
int[] items = tile.entity.items.items;
for (int i = 0; i < items.length; i++) {
final int f = i;

View File

@@ -9,7 +9,7 @@ import io.anuke.ucore.util.Mathf;
import io.anuke.ucore.util.Translator;
public abstract class BaseBlock {
public boolean hasInventory = true;
public boolean hasItems = true;
public boolean hasLiquids;
public boolean hasPower;
@@ -20,8 +20,8 @@ public abstract class BaseBlock {
/**Returns the amount of items this block can accept.*/
public int acceptStack(Item item, int amount, Tile tile, Unit source){
if(acceptItem(item, tile, tile) && hasInventory && source.team == tile.getTeam()){
return Math.min(itemCapacity - tile.entity.inventory.totalItems(), amount);
if(acceptItem(item, tile, tile) && hasItems && source.team == tile.getTeam()){
return Math.min(itemCapacity - tile.entity.items.totalItems(), amount);
}else{
return 0;
}
@@ -29,13 +29,13 @@ public abstract class BaseBlock {
/**Remove a stack from this inventory, and return the amount removed.*/
public int removeStack(Tile tile, Item item, int amount){
tile.entity.inventory.removeItem(item, amount);
tile.entity.items.removeItem(item, amount);
return amount;
}
/**Handle a stack input.*/
public void handleStack(Item item, int amount, Tile tile, Unit source){
tile.entity.inventory.addItem(item, amount);
tile.entity.items.addItem(item, amount);
}
/**Returns offset for stack placement.*/
@@ -44,7 +44,7 @@ public abstract class BaseBlock {
}
public void handleItem(Item item, Tile tile, Tile source){
tile.entity.inventory.addItem(item, 1);
tile.entity.items.addItem(item, 1);
}
public boolean acceptItem(Item item, Tile tile, Tile source){
@@ -52,13 +52,13 @@ public abstract class BaseBlock {
}
public boolean acceptLiquid(Tile tile, Tile source, Liquid liquid, float amount){
return tile.entity.liquid.amount + amount < liquidCapacity
&& (tile.entity.liquid.liquid == liquid || tile.entity.liquid.amount <= 0.1f);
return tile.entity.liquids.amount + amount < liquidCapacity
&& (tile.entity.liquids.liquid == liquid || tile.entity.liquids.amount <= 0.1f);
}
public void handleLiquid(Tile tile, Tile source, Liquid liquid, float amount){
tile.entity.liquid.liquid = liquid;
tile.entity.liquid.amount += amount;
tile.entity.liquids.liquid = liquid;
tile.entity.liquids.amount += amount;
}
public boolean acceptPower(Tile tile, Tile source, float amount){
@@ -75,7 +75,7 @@ public abstract class BaseBlock {
}
public void tryDumpLiquid(Tile tile){
if(tile.entity.liquid.amount < 0.001f) return;
if(tile.entity.liquids.amount < 0.001f) return;
int size = tile.block().size;
@@ -89,8 +89,8 @@ public abstract class BaseBlock {
if(other != null) other = other.target();
if (other != null && other.block().hasLiquids) {
float ofract = other.entity.liquid.amount / other.block().liquidCapacity;
float fract = tile.entity.liquid.amount / liquidCapacity;
float ofract = other.entity.liquids.amount / other.block().liquidCapacity;
float fract = tile.entity.liquids.amount / liquidCapacity;
if(ofract < fract) tryMoveLiquid(tile, in, other, (fract - ofract) * liquidCapacity / 2f);
}
@@ -101,11 +101,11 @@ public abstract class BaseBlock {
}
public void tryMoveLiquid(Tile tile, Tile tileSource, Tile next, float amount){
float flow = Math.min(next.block().liquidCapacity - next.entity.liquid.amount - 0.001f, amount);
float flow = Math.min(next.block().liquidCapacity - next.entity.liquids.amount - 0.001f, amount);
if(next.block().acceptLiquid(next, tileSource, tile.entity.liquid.liquid, flow)){
next.block().handleLiquid(next, tileSource, tile.entity.liquid.liquid, flow);
tile.entity.liquid.amount -= flow;
if(next.block().acceptLiquid(next, tileSource, tile.entity.liquids.liquid, flow)){
next.block().handleLiquid(next, tileSource, tile.entity.liquids.liquid, flow);
tile.entity.liquids.amount -= flow;
}
}
@@ -114,29 +114,29 @@ public abstract class BaseBlock {
next = next.target();
if(next.block().hasLiquids && tile.entity.liquid.amount > 0f){
float ofract = next.entity.liquid.amount / next.block().liquidCapacity;
float fract = tile.entity.liquid.amount / liquidCapacity;
if(next.block().hasLiquids && tile.entity.liquids.amount > 0f){
float ofract = next.entity.liquids.amount / next.block().liquidCapacity;
float fract = tile.entity.liquids.amount / liquidCapacity;
if(ofract > fract) return 0;
float flow = Math.min(Mathf.clamp((fract - ofract)*(1f)) * (liquidCapacity), tile.entity.liquid.amount);
float flow = Math.min(Mathf.clamp((fract - ofract)*(1f)) * (liquidCapacity), tile.entity.liquids.amount);
flow = Math.min(flow, next.block().liquidCapacity - next.entity.liquid.amount - 0.001f);
flow = Math.min(flow, next.block().liquidCapacity - next.entity.liquids.amount - 0.001f);
if(flow <= 0f) return 0;
float amount = flow;
if(next.block().acceptLiquid(next, tile, tile.entity.liquid.liquid, amount)){
next.block().handleLiquid(next, tile, tile.entity.liquid.liquid, amount);
tile.entity.liquid.amount -= amount;
if(next.block().acceptLiquid(next, tile, tile.entity.liquids.liquid, amount)){
next.block().handleLiquid(next, tile, tile.entity.liquids.liquid, amount);
tile.entity.liquids.amount -= amount;
return flow;
}
}else if(leak && !next.block().solid && !next.block().hasLiquids){
float leakAmount = Math.min(tile.entity.liquid.amount, tile.entity.liquid.amount/1.5f);
Puddle.deposit(next, tile, tile.entity.liquid.liquid, leakAmount);
tile.entity.liquid.amount -= leakAmount;
float leakAmount = Math.min(tile.entity.liquids.amount, tile.entity.liquids.amount/1.5f);
Puddle.deposit(next, tile, tile.entity.liquids.liquid, leakAmount);
tile.entity.liquids.amount -= leakAmount;
}
return 0;
}
@@ -185,9 +185,9 @@ public abstract class BaseBlock {
if(todump != null && item != todump) continue;
if(tile.entity.inventory.hasItem(item) && other != null && other.block().acceptItem(item, other, in) && canDump(tile, other, item)){
if(tile.entity.items.hasItem(item) && other != null && other.block().acceptItem(item, other, in) && canDump(tile, other, item)){
other.block().handleItem(item, other, in);
tile.entity.inventory.removeItem(item, 1);
tile.entity.items.removeItem(item, 1);
i = (byte)((i + 1) % nearby.length);
tile.setDump(i);
return true;

View File

@@ -171,14 +171,14 @@ public class Block extends BaseBlock {
if(hasPower) stats.add("powercapacity", powerCapacity);
if(hasLiquids) stats.add("liquidcapacity", liquidCapacity);
if(hasInventory) stats.add("capacity", itemCapacity);
if(hasItems) stats.add("capacity", itemCapacity);
}
//TODO make this easier to config.
public void setBars(){
if(hasPower) bars.add(new BlockBar(BarType.power, true, tile -> tile.entity.power.amount / powerCapacity));
if(hasLiquids) bars.add(new BlockBar(BarType.liquid, true, tile -> tile.entity.liquid.amount / liquidCapacity));
if(hasInventory) bars.add(new BlockBar(BarType.inventory, true, tile -> (float)tile.entity.inventory.totalItems() / itemCapacity));
if(hasLiquids) bars.add(new BlockBar(BarType.liquid, true, tile -> tile.entity.liquids.amount / liquidCapacity));
if(hasItems) bars.add(new BlockBar(BarType.inventory, true, tile -> (float)tile.entity.items.totalItems() / itemCapacity));
}
public String name(){
@@ -200,7 +200,7 @@ public class Block extends BaseBlock {
public void update(Tile tile){}
public boolean isAccessible(){
return (hasInventory && itemCapacity > 0);
return (hasItems && itemCapacity > 0);
}
public void onDestroyed(Tile tile){
@@ -212,9 +212,9 @@ public class Block extends BaseBlock {
int units = 1;
tempColor.set(Palette.darkFlame);
if(hasInventory){
if(hasItems){
for(Item item : Item.getAllItems()){
int amount = tile.entity.inventory.getItem(item);
int amount = tile.entity.items.getItem(item);
explosiveness += item.explosiveness*amount;
flammability += item.flammability*amount;
@@ -226,14 +226,14 @@ public class Block extends BaseBlock {
}
if(hasLiquids){
float amount = tile.entity.liquid.amount;
explosiveness += tile.entity.liquid.liquid.explosiveness*amount/2f;
flammability += tile.entity.liquid.liquid.flammability*amount/2f;
heat += Mathf.clamp(tile.entity.liquid.liquid.temperature-0.5f)*amount/2f;
float amount = tile.entity.liquids.amount;
explosiveness += tile.entity.liquids.liquid.explosiveness*amount/2f;
flammability += tile.entity.liquids.liquid.flammability*amount/2f;
heat += Mathf.clamp(tile.entity.liquids.liquid.temperature-0.5f)*amount/2f;
if(tile.entity.liquid.liquid.flammability*amount > 2f){
if(tile.entity.liquids.liquid.flammability*amount > 2f){
units ++;
Hue.addu(tempColor, tile.entity.liquid.liquid.flameColor);
Hue.addu(tempColor, tile.entity.liquids.liquid.flameColor);
}
}
@@ -243,10 +243,10 @@ public class Block extends BaseBlock {
tempColor.mul(1f/units);
Liquid liquid = tile.entity.liquid.liquid;
float splash = Mathf.clamp(tile.entity.liquid.amount/4f, 0f, 10f);
Liquid liquid = tile.entity.liquids.liquid;
float splash = Mathf.clamp(tile.entity.liquids.amount/4f, 0f, 10f);
for(int i = 0; i < Mathf.clamp(tile.entity.liquid.amount / 5, 0, 30); i ++){
for(int i = 0; i < Mathf.clamp(tile.entity.liquids.amount / 5, 0, 30); i ++){
Timers.run(i/2, () -> {
Tile other = world.tile(tile.x + Mathf.range(size/2), tile.y + Mathf.range(size/2));
if(other != null){
@@ -261,7 +261,7 @@ public class Block extends BaseBlock {
/**Returns the flammability of the tile. Used for fire calculations.
* Takes flammability of floor liquid into account.*/
public float getFlammability(Tile tile){
if(!hasInventory || tile.entity == null){
if(!hasItems || tile.entity == null){
if(tile.floor().liquid && !solid){
return tile.floor().liquidDrop.flammability;
}
@@ -269,11 +269,11 @@ public class Block extends BaseBlock {
}else{
float result = 0f;
for(Item item : Item.getAllItems()){
int amount = tile.entity.inventory.getItem(item);
int amount = tile.entity.items.getItem(item);
result += item.flammability*amount;
}
if(hasLiquids){
result += tile.entity.liquid.amount * tile.entity.liquid.liquid.flammability/3f;
result += tile.entity.liquids.amount * tile.entity.liquids.liquid.flammability/3f;
}
return result;
}
@@ -376,7 +376,7 @@ public class Block extends BaseBlock {
"entity.x", tile.entity.x,
"entity.y", tile.entity.y,
"entity.id", tile.entity.id,
"entity.items.total", hasInventory ? tile.entity.inventory.totalItems() : null
"entity.items.total", hasItems ? tile.entity.items.totalItems() : null
);
}

View File

@@ -318,8 +318,8 @@ public class Tile{
if (block.hasEntity()) {
entity = block.getEntity().init(this, block.update);
if(block.hasInventory) entity.inventory = new InventoryModule();
if(block.hasLiquids) entity.liquid = new LiquidModule();
if(block.hasItems) entity.items = new InventoryModule();
if(block.hasLiquids) entity.liquids = new LiquidModule();
if(block.hasPower) entity.power = new PowerModule();
}

View File

@@ -13,7 +13,7 @@ public class BlockPart extends Block{
public BlockPart() {
super("blockpart");
solid = false;
hasPower = hasInventory = hasLiquids = true;
hasPower = hasItems = hasLiquids = true;
}
@Override

View File

@@ -15,7 +15,7 @@ public class LiquidBlock extends Block{
update = true;
solid = true;
hasLiquids = true;
hasInventory = false;
hasItems = false;
group = BlockGroup.liquids;
}
@@ -26,7 +26,7 @@ public class LiquidBlock extends Block{
@Override
public void draw(Tile tile){
LiquidModule mod = tile.entity.liquid;
LiquidModule mod = tile.entity.liquids;
int rotation = rotate ? tile.getRotation() * 90 : 0;

View File

@@ -10,7 +10,7 @@ public class Wall extends Block{
solid = true;
destructible = true;
group = BlockGroup.walls;
hasInventory = false;
hasItems = false;
}
@Override

View File

@@ -23,7 +23,7 @@ public class ShieldBlock extends PowerBlock{
public ShieldBlock(String name) {
super(name);
powerCapacity = 80f;
hasInventory = false;
hasItems = false;
}
@Override

View File

@@ -70,7 +70,7 @@ public abstract class Turret extends Block{
solid = true;
layer = Layer.turret;
group = BlockGroup.turrets;
hasInventory = false;
hasItems = false;
}
@Override

View File

@@ -23,7 +23,7 @@ public abstract class LiquidTurret extends Turret {
public void setBars() {
super.setBars();
bars.remove(BarType.inventory);
bars.replace(new BlockBar(BarType.liquid, true, tile -> tile.entity.liquid.amount / liquidCapacity));
bars.replace(new BlockBar(BarType.liquid, true, tile -> tile.entity.liquids.amount / liquidCapacity));
}
@Override
@@ -45,20 +45,20 @@ public abstract class LiquidTurret extends Turret {
@Override
public AmmoType useAmmo(Tile tile){
TurretEntity entity = tile.entity();
AmmoType type = liquidAmmoMap.get(entity.liquid.liquid);
entity.liquid.amount -= type.quantityMultiplier;
AmmoType type = liquidAmmoMap.get(entity.liquids.liquid);
entity.liquids.amount -= type.quantityMultiplier;
return type;
}
@Override
public AmmoType peekAmmo(Tile tile){
return liquidAmmoMap.get(tile.entity.liquid.liquid);
return liquidAmmoMap.get(tile.entity.liquids.liquid);
}
@Override
public boolean hasAmmo(Tile tile){
TurretEntity entity = tile.entity();
return liquidAmmoMap.get(entity.liquid.liquid) != null && entity.liquid.amount >= liquidAmmoMap.get(entity.liquid.liquid).quantityMultiplier;
return liquidAmmoMap.get(entity.liquids.liquid) != null && entity.liquids.amount >= liquidAmmoMap.get(entity.liquids.liquid).quantityMultiplier;
}
@Override

View File

@@ -25,8 +25,8 @@ public class BufferedItemBridge extends ExtendingItemBridge {
public void updateTransport(Tile tile, Tile other){
BufferedItemBridgeEntity entity = tile.entity();
if(entity.buffer.accepts() && entity.inventory.totalItems() > 0){
entity.buffer.accept(entity.inventory.takeItem());
if(entity.buffer.accepts() && entity.items.totalItems() > 0){
entity.buffer.accept(entity.items.takeItem());
}
Item item = entity.buffer.poll();

View File

@@ -26,7 +26,7 @@ public class Conduit extends LiquidBlock {
@Override
public void draw(Tile tile){
ConduitEntity entity = tile.entity();
LiquidModule mod = tile.entity.liquid;
LiquidModule mod = tile.entity.liquids;
int rotation = rotate ? tile.getRotation() * 90 : 0;
@@ -43,9 +43,9 @@ public class Conduit extends LiquidBlock {
@Override
public void update(Tile tile){
ConduitEntity entity = tile.entity();
entity.smoothLiquid = Mathf.lerpDelta(entity.smoothLiquid, entity.liquid.amount/liquidCapacity, 0.05f);
entity.smoothLiquid = Mathf.lerpDelta(entity.smoothLiquid, entity.liquids.amount/liquidCapacity, 0.05f);
if(tile.entity.liquid.amount > 0.001f && tile.entity.timer.get(timerFlow, 1)){
if(tile.entity.liquids.amount > 0.001f && tile.entity.timer.get(timerFlow, 1)){
tryMoveLiquid(tile, tile.getNearby(tile.getRotation()), true);
}
}

View File

@@ -41,7 +41,7 @@ public class Conveyor extends Block{
update = true;
layer = Layer.overlay;
group = BlockGroup.transportation;
hasInventory = true;
hasItems = true;
}
@Override
@@ -154,7 +154,7 @@ public class Conveyor extends Block{
if (pos.y >= 0.9999f && offloadDir(tile, pos.item)) {
minremove = Math.min(i, minremove);
tile.entity.inventory.removeItem(pos.item, 1);
tile.entity.items.removeItem(pos.item, 1);
} else {
value = pos.pack();
@@ -187,7 +187,7 @@ public class Conveyor extends Block{
ItemPos pos = pos1.set(val, ItemPos.drawShorts);
if(pos.item == item){
entity.convey.removeValue(val);
entity.inventory.removeItem(item, 1);
entity.items.removeItem(item, 1);
removed ++;
break;
}
@@ -213,7 +213,7 @@ public class Conveyor extends Block{
long result = ItemPos.packItem(item, 0f, 0f, (byte)Mathf.random(255));
entity.convey.insert(0, result);
entity.inventory.addItem(item, 1);
entity.items.addItem(item, 1);
}
@Override
@@ -238,7 +238,7 @@ public class Conveyor extends Block{
long result = ItemPos.packItem(item, y*0.9f, pos, (byte)Mathf.random(255));
boolean inserted = false;
tile.entity.inventory.addItem(item, 1);
tile.entity.items.addItem(item, 1);
for(int i = 0; i < entity.convey.size; i ++){
if(compareItems(result, entity.convey.get(i)) < 0){

View File

@@ -159,13 +159,13 @@ public class ItemBridge extends Block {
ItemBridgeEntity entity = tile.entity();
if(entity.uptime >= 0.5f && entity.timer.get(timerTransport, transportTime)){
Item item = entity.inventory.takeItem();
Item item = entity.items.takeItem();
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.inventory.addItem(item, 1);
if(item != null) entity.items.addItem(item, 1);
}
}
}
@@ -211,7 +211,7 @@ public class ItemBridge extends Block {
@Override
public boolean acceptItem(Item item, Tile tile, Tile source) {
return tile.entity.inventory.totalItems() < itemCapacity;
return tile.entity.items.totalItems() < itemCapacity;
}
@Override

View File

@@ -21,7 +21,7 @@ public class Junction extends Block{
solid = true;
instantTransfer = true;
group = BlockGroup.transportation;
hasInventory = false;
hasItems = false;
}
@Override

View File

@@ -11,7 +11,7 @@ public class LiquidBridge extends ItemBridge {
public LiquidBridge(String name) {
super(name);
hasInventory = false;
hasItems = false;
hasLiquids = true;
}

View File

@@ -11,7 +11,7 @@ public class LiquidExtendingBridge extends ExtendingItemBridge {
public LiquidExtendingBridge(String name) {
super(name);
hasInventory = false;
hasItems = false;
hasLiquids = true;
}

View File

@@ -12,7 +12,7 @@ public class LiquidRouter extends LiquidBlock{
@Override
public void update(Tile tile){
if(tile.entity.liquid.amount > 0){
if(tile.entity.liquids.amount > 0){
tryDumpLiquid(tile);
}
}

View File

@@ -21,7 +21,7 @@ public class Router extends Block{
int iterations = Math.max(1, (int) (Timers.delta() + 0.4f));
for(int i = 0; i < iterations; i ++) {
if (tile.entity.inventory.totalItems() > 0) {
if (tile.entity.items.totalItems() > 0) {
tryDump(tile);
}
}
@@ -30,8 +30,8 @@ public class Router extends Block{
@Override
public boolean canDump(Tile tile, Tile to, Item item) {
if(to.block() instanceof Router){
return ((float)to.target().entity.inventory.totalItems() / to.target().block().itemCapacity) <
((float)tile.entity.inventory.totalItems() / to.target().block().itemCapacity);
return ((float)to.target().entity.items.totalItems() / to.target().block().itemCapacity) <
((float)tile.entity.items.totalItems() / to.target().block().itemCapacity);
}else{
return true;
}
@@ -45,7 +45,7 @@ public class Router extends Block{
@Override
public boolean acceptItem(Item item, Tile tile, Tile source){
int items = tile.entity.inventory.totalItems();
int items = tile.entity.items.totalItems();
return items < itemCapacity;
}

View File

@@ -13,7 +13,7 @@ public class Splitter extends Block{
solid = true;
instantTransfer = true;
destructible = true;
hasInventory = false;
hasItems = false;
group = BlockGroup.transportation;
}

View File

@@ -72,7 +72,7 @@ public class Teleporter extends PowerBlock{
TeleporterEntity entity = tile.entity();
if(entity != null){
entity.color = data;
entity.inventory.clear();
entity.items.clear();
}
}
@@ -138,7 +138,7 @@ public class Teleporter extends PowerBlock{
teleporters[entity.color].add(tile);
if(entity.inventory.totalItems() > 0){
if(entity.items.totalItems() > 0){
tryDump(tile);
}
@@ -172,8 +172,8 @@ public class Teleporter extends PowerBlock{
entity.speedScl = Mathf.lerpDelta(entity.speedScl, 2f, 0.01f);
float liquidUsed = Math.min(liquidCapacity, liquidUse * Timers.delta());
if (entity.liquid.amount >= liquidUsed) {
entity.liquid.amount -= liquidUsed;
if (entity.liquids.amount >= liquidUsed) {
entity.liquids.amount -= liquidUsed;
} else {
catastrophicFailure(tile);
}
@@ -183,7 +183,7 @@ public class Teleporter extends PowerBlock{
entity.time += Timers.delta() * entity.speedScl;
if (entity.inventory.totalItems() == itemCapacity && entity.power.amount >= powerCapacity &&
if (entity.items.totalItems() == itemCapacity && entity.power.amount >= powerCapacity &&
entity.timer.get(timerTeleport, teleportMax)) {
Array<Tile> testLinks = findLinks(tile);
@@ -196,12 +196,12 @@ public class Teleporter extends PowerBlock{
Array<Tile> links = findLinks(tile);
for (Tile other : links) {
int canAccept = itemCapacity - other.entity.inventory.totalItems();
int total = entity.inventory.totalItems();
int canAccept = itemCapacity - other.entity.items.totalItems();
int total = entity.items.totalItems();
if (total == 0) break;
Effects.effect(teleportOutEffect, getColor(tile, 0), other.drawx(), other.drawy());
for (int i = 0; i < canAccept && i < total; i++) {
other.entity.inventory.addItem(entity.inventory.takeItem(), 1);
other.entity.items.addItem(entity.items.takeItem(), 1);
}
}
Effects.effect(teleportOutEffect, getColor(tile, 0), tile.drawx(), tile.drawy());
@@ -249,7 +249,7 @@ public class Teleporter extends PowerBlock{
@Override
public boolean acceptItem(Item item, Tile tile, Tile source){
TeleporterEntity entity = tile.entity();
return entity.inventory.totalItems() < itemCapacity;
return entity.items.totalItems() < itemCapacity;
}
@Override
@@ -289,7 +289,7 @@ public class Teleporter extends PowerBlock{
if(!oe.active) continue;
if(oe.color != entity.color){
removal.add(other);
}else if(other.entity.inventory.totalItems() == 0){
}else if(other.entity.items.totalItems() == 0){
returns.add(other);
}
}else{

View File

@@ -84,7 +84,7 @@ public class TunnelConveyor extends Block{
arr.add(entity.index);
for(int i = 0; i < entity.index; i++){
long l = entity.inventory.items[i];
long l = entity.items.items[i];
float time = NumberUtils.intBitsToFloat(Bits.getLeftInt(l));
Item item = Item.getByID(Bits.getRightInt(l));
Tile dest = getDestTunnel(tile, item);

View File

@@ -33,7 +33,7 @@ public class BurnerGenerator extends PowerGenerator {
@Override
public void setBars(){
super.setBars();
bars.replace(new BlockBar(BarType.inventory, true, tile -> (float)tile.entity.inventory.totalItems() / itemCapacity));
bars.replace(new BlockBar(BarType.inventory, true, tile -> (float)tile.entity.items.totalItems() / itemCapacity));
}
@Override
@@ -51,7 +51,7 @@ public class BurnerGenerator extends PowerGenerator {
if(entity.generateTime > 0){
Draw.color(heatColor);
float alpha = (entity.inventory.totalItems() > 0 ? 1f : Mathf.clamp(entity.generateTime));
float alpha = (entity.items.totalItems() > 0 ? 1f : Mathf.clamp(entity.generateTime));
alpha = alpha * 0.7f + Mathf.absin(Timers.time(), 12f, 0.3f) * alpha;
Draw.alpha(alpha);
Draw.rect(name + "-top", tile.worldx(), tile.worldy());
@@ -61,7 +61,7 @@ public class BurnerGenerator extends PowerGenerator {
@Override
public boolean acceptItem(Item item, Tile tile, Tile source){
return getItemEfficiency(item) >= minEfficiency && tile.entity.inventory.totalItems() < itemCapacity;
return getItemEfficiency(item) >= minEfficiency && tile.entity.items.totalItems() < itemCapacity;
}
@Override
@@ -77,11 +77,11 @@ public class BurnerGenerator extends PowerGenerator {
entity.generateTime = Mathf.clamp(entity.generateTime);
}
if(entity.generateTime <= 0f && entity.inventory.totalItems() > 0){
if(entity.generateTime <= 0f && entity.items.totalItems() > 0){
Effects.effect(generateEffect, tile.worldx() + Mathf.range(3f), tile.worldy() + Mathf.range(3f));
for(int i = 0; i < entity.inventory.items.length; i ++){
if(entity.inventory.items[i] > 0){
entity.inventory.items[i] --;
for(int i = 0; i < entity.items.items.length; i ++){
if(entity.items.items[i] > 0){
entity.items.items[i] --;
entity.efficiency = getItemEfficiency(Item.getByID(i));
break;
}

View File

@@ -26,7 +26,7 @@ public class FusionReactor extends PowerGenerator {
hasLiquids = true;
powerCapacity = 100f;
liquidCapacity = 30f;
hasInventory = true;
hasItems = true;
}
@Override
@@ -36,9 +36,9 @@ public class FusionReactor extends PowerGenerator {
float powerUse = Math.min(powerCapacity, powerUsage * Timers.delta());
float liquidUse = Math.min(liquidCapacity, liquidUsage * Timers.delta());
if(entity.power.amount >= powerUse && entity.liquid.amount >= liquidUse){
if(entity.power.amount >= powerUse && entity.liquids.amount >= liquidUse){
entity.power.amount -= powerUse;
entity.liquid.amount -= liquidUse;
entity.liquids.amount -= liquidUse;
entity.warmup = Mathf.lerpDelta(entity.warmup, 1f, warmupSpeed);
}else{
entity.warmup = Mathf.lerpDelta(entity.warmup, 0f, 0.01f);

View File

@@ -38,8 +38,8 @@ public class LiquidBurnerGenerator extends PowerGenerator {
TileEntity entity = tile.entity();
Draw.color(entity.liquid.liquid.color);
Draw.alpha(entity.liquid.amount / liquidCapacity);
Draw.color(entity.liquids.liquid.color);
Draw.alpha(entity.liquids.amount / liquidCapacity);
drawLiquidCenter(tile);
Draw.color();
}
@@ -52,12 +52,12 @@ public class LiquidBurnerGenerator extends PowerGenerator {
public void update(Tile tile){
TileEntity entity = tile.entity();
if(entity.liquid.amount > 0){
float powerPerLiquid = getEfficiency(entity.liquid.liquid)*this.powerPerLiquid;
float used = Math.min(entity.liquid.amount, maxLiquidGenerate * Timers.delta());
if(entity.liquids.amount > 0){
float powerPerLiquid = getEfficiency(entity.liquids.liquid)*this.powerPerLiquid;
float used = Math.min(entity.liquids.amount, maxLiquidGenerate * Timers.delta());
used = Math.min(used, (powerCapacity - entity.power.amount)/powerPerLiquid);
entity.liquid.amount -= used;
entity.liquids.amount -= used;
entity.power.amount += used * powerPerLiquid;
if(used > 0.001f && Mathf.chance(0.05 * Timers.delta())){

View File

@@ -52,7 +52,7 @@ public class NuclearReactor extends LiquidBurnerGenerator {
@Override
public void setBars(){
super.setBars();
bars.replace(new BlockBar(BarType.inventory, true, tile -> (float)tile.entity.inventory.getItem(generateItem) / itemCapacity));
bars.replace(new BlockBar(BarType.inventory, true, tile -> (float)tile.entity.items.getItem(generateItem) / itemCapacity));
bars.add(new BlockBar(BarType.heat, true, tile -> tile.<NuclearReactorEntity>entity().heat));
}
@@ -70,7 +70,7 @@ public class NuclearReactor extends LiquidBurnerGenerator {
public void update(Tile tile){
NuclearReactorEntity entity = tile.entity();
int fuel = entity.inventory.getItem(generateItem);
int fuel = entity.items.getItem(generateItem);
float fullness = (float)fuel / itemCapacity;
if(fuel > 0){
@@ -78,19 +78,19 @@ public class NuclearReactor extends LiquidBurnerGenerator {
entity.power.amount += powerMultiplier * fullness * Timers.delta();
entity.power.amount = Mathf.clamp(entity.power.amount, 0f, powerCapacity);
if(entity.timer.get(timerFuel, fuelUseTime)){
entity.inventory.removeItem(generateItem, 1);
entity.items.removeItem(generateItem, 1);
}
}
if(entity.liquid.amount > 0){
if(entity.liquids.amount > 0){
//TODO steam when cooling large amounts?
float liquidPower = 1f;
if(liquidPower > 0){ //is coolant
float pow = coolantPower * entity.liquid.liquid.heatCapacity;
float maxCool = Math.min(entity.liquid.amount, entity.heat / pow); //max that can be cooled in terms of liquid
float pow = coolantPower * entity.liquids.liquid.heatCapacity;
float maxCool = Math.min(entity.liquids.amount, entity.heat / pow); //max that can be cooled in terms of liquid
entity.heat -= maxCool * pow;
entity.liquid.amount -= maxCool;
entity.liquids.amount -= maxCool;
}else{ //is heater
//TODO
}
@@ -124,7 +124,7 @@ public class NuclearReactor extends LiquidBurnerGenerator {
NuclearReactorEntity entity = tile.entity();
int fuel = entity.inventory.getItem(generateItem);
int fuel = entity.items.getItem(generateItem);
if(fuel < 5 && entity.heat < 0.5f) return;
@@ -156,13 +156,13 @@ public class NuclearReactor extends LiquidBurnerGenerator {
@Override
public boolean acceptItem(Item item, Tile tile, Tile source){
return item == generateItem && tile.entity.inventory.getItem(generateItem) < itemCapacity;
return item == generateItem && tile.entity.items.getItem(generateItem) < itemCapacity;
}
@Override
public boolean acceptLiquid(Tile tile, Tile source, Liquid liquid, float amount){
return tile.entity.liquid.amount + amount < liquidCapacity
&& (tile.entity.liquid.liquid == liquid || tile.entity.liquid.amount <= 0.001f);
return tile.entity.liquids.amount + amount < liquidCapacity
&& (tile.entity.liquids.liquid == liquid || tile.entity.liquids.amount <= 0.001f);
}
@Override

View File

@@ -43,7 +43,7 @@ public class PowerDistributor extends PowerBlock{
super(name);
expanded = true;
layer = Layer.power;
hasInventory = false;
hasItems = false;
powerCapacity = 5f;
}

View File

@@ -9,7 +9,7 @@ public class SolarGenerator extends io.anuke.mindustry.world.blocks.types.power.
public SolarGenerator(String name){
super(name);
hasInventory = false;
hasItems = false;
}
@Override

View File

@@ -20,17 +20,17 @@ public class Compressor extends PowerCrafter {
GenericCrafterEntity entity = tile.entity();
float powerUsed = Math.min(Timers.delta() * powerUse, tile.entity.power.amount);
float liquidAdded = Math.min(outputLiquidAmount * Timers.delta(), liquidCapacity - entity.liquid.amount);
float liquidAdded = Math.min(outputLiquidAmount * Timers.delta(), liquidCapacity - entity.liquids.amount);
int itemsUsed = Mathf.ceil(1 + input.amount * entity.progress);
if(entity.power.amount > powerUsed && entity.inventory.hasItem(input.item, itemsUsed) && liquidAdded > 0.001f){
if(entity.power.amount > powerUsed && entity.items.hasItem(input.item, itemsUsed) && liquidAdded > 0.001f){
entity.progress += 1f/craftTime;
entity.totalProgress += Timers.delta();
handleLiquid(tile, tile, outputLiquid, liquidAdded);
}
if(entity.progress >= 1f){
entity.inventory.removeItem(input);
entity.items.removeItem(input);
if(outputItem != null) offloadNear(tile, outputItem);
entity.progress = 0f;
}
@@ -50,7 +50,7 @@ public class Compressor extends PowerCrafter {
Draw.rect(name, tile.drawx(), tile.drawy());
Draw.rect(name + "-frame" + (int) Mathf.absin(entity.totalProgress, 5f, 2.999f), tile.drawx(), tile.drawy());
Draw.color(Color.CLEAR, tile.entity.liquid.liquid.color, tile.entity.liquid.amount / liquidCapacity);
Draw.color(Color.CLEAR, tile.entity.liquids.liquid.color, tile.entity.liquids.amount / liquidCapacity);
Draw.rect(name + "-liquid", tile.drawx(), tile.drawy());
Draw.color();
Draw.rect(name + "-top", tile.drawx(), tile.drawy());

View File

@@ -37,7 +37,7 @@ public class Cultivator extends Drill {
CultivatorEntity entity = tile.entity();
entity.warmup = Mathf.lerpDelta(entity.warmup,
tile.entity.liquid.amount > liquidUse ? 1f : 0f, 0.015f);
tile.entity.liquids.amount > liquidUse ? 1f : 0f, 0.015f);
}
@Override

View File

@@ -135,17 +135,17 @@ public class Drill extends Block{
float powerUsed = Math.min(powerCapacity, powerUse * Timers.delta());
float liquidUsed = Math.min(liquidCapacity, liquidUse * Timers.delta());
if(entity.inventory.totalItems() < itemCapacity && toAdd.size > 0 &&
if(entity.items.totalItems() < itemCapacity && toAdd.size > 0 &&
(!hasPower || entity.power.amount >= powerUsed) &&
(!liquidRequired || entity.liquid.amount >= liquidUsed)){
(!liquidRequired || entity.liquids.amount >= liquidUsed)){
if(hasPower) entity.power.amount -= powerUsed;
if(liquidRequired) entity.liquid.amount -= liquidUsed;
if(liquidRequired) entity.liquids.amount -= liquidUsed;
float speed = 1f;
if(entity.liquid.amount >= liquidUsed && !liquidRequired){
entity.liquid.amount -= liquidUsed;
if(entity.liquids.amount >= liquidUsed && !liquidRequired){
entity.liquids.amount -= liquidUsed;
speed = liquidBoostIntensity;
}
@@ -160,7 +160,7 @@ public class Drill extends Block{
}
if(toAdd.size > 0 && entity.progress >= drillTime + hardnessDrillMultiplier*Math.max(totalHardness, 1f)/multiplier
&& tile.entity.inventory.totalItems() < itemCapacity){
&& tile.entity.items.totalItems() < itemCapacity){
int index = entity.index % toAdd.size;
offloadNear(tile, toAdd.get(index));

View File

@@ -21,8 +21,8 @@ public class Fracker extends SolidPump {
Draw.rect(name, tile.drawx(), tile.drawy());
Draw.color(tile.entity.liquid.liquid.color);
Draw.alpha(tile.entity.liquid.amount/liquidCapacity);
Draw.color(tile.entity.liquids.liquid.color);
Draw.alpha(tile.entity.liquids.amount/liquidCapacity);
Draw.rect(name + "-liquid", tile.drawx(), tile.drawy());
Draw.color();

View File

@@ -50,7 +50,7 @@ public class GenericCrafter extends Block{
super.setBars();
if(inputItem != null) bars.replace(new BlockBar(BarType.inventory, true,
tile -> (float)tile.entity.inventory.getItem(inputItem.item) / itemCapacity));
tile -> (float)tile.entity.items.getItem(inputItem.item) / itemCapacity));
}
@Override
@@ -68,8 +68,8 @@ public class GenericCrafter extends Block{
if(!hasLiquids) return;
Draw.color(tile.entity.liquid.liquid.color);
Draw.alpha(tile.entity.liquid.amount / liquidCapacity);
Draw.color(tile.entity.liquids.liquid.color);
Draw.alpha(tile.entity.liquids.amount / liquidCapacity);
Draw.rect("blank", tile.drawx(), tile.drawy(), 2, 2);
Draw.color();
}
@@ -87,15 +87,15 @@ public class GenericCrafter extends Block{
float liquidUsed = Math.min(liquidCapacity, liquidUse * Timers.delta());
int itemsUsed = (inputItem == null ? 0 : (int)(1 + inputItem.amount * entity.progress));
if((!hasLiquids || entity.liquid.amount >= liquidUsed) &&
if((!hasLiquids || entity.liquids.amount >= liquidUsed) &&
(!hasPower || entity.power.amount >= powerUsed) &&
(inputItem == null || entity.inventory.hasItem(inputItem.item, itemsUsed))){
(inputItem == null || entity.items.hasItem(inputItem.item, itemsUsed))){
entity.progress += 1f / craftTime * Timers.delta();
entity.totalProgress += Timers.delta();
entity.warmup = Mathf.lerp(entity.warmup, 1f, 0.02f);
if(hasPower) entity.power.amount -= powerUsed;
if(hasLiquids) entity.liquid.amount -= liquidUsed;
if(hasLiquids) entity.liquids.amount -= liquidUsed;
if(Mathf.chance(Timers.delta() * updateEffectChance))
Effects.effect(updateEffect, entity.x + Mathf.range(size*4f), entity.y + Mathf.range(size*4));
@@ -105,7 +105,7 @@ public class GenericCrafter extends Block{
if(entity.progress >= 1f){
if(inputItem != null) tile.entity.inventory.removeItem(inputItem);
if(inputItem != null) tile.entity.items.removeItem(inputItem);
offloadNear(tile, output);
Effects.effect(craftEffect, tile.drawx(), tile.drawy());
entity.progress = 0f;
@@ -124,7 +124,7 @@ public class GenericCrafter extends Block{
@Override
public boolean acceptItem(Item item, Tile tile, Tile source){
TileEntity entity = tile.entity();
return inputItem != null && item == inputItem.item && entity.inventory.getItem(inputItem.item) < itemCapacity;
return inputItem != null && item == inputItem.item && entity.items.getItem(inputItem.item) < itemCapacity;
}
@Override

View File

@@ -23,7 +23,7 @@ public class Incinerator extends Block {
public Incinerator(String name) {
super(name);
hasPower = true;
hasInventory = false;
hasItems = false;
hasLiquids = true;
update = true;
solid = true;

View File

@@ -17,7 +17,7 @@ public class LiquidMixer extends LiquidBlock{
public LiquidMixer(String name) {
super(name);
hasInventory = true;
hasItems = true;
hasPower = true;
rotate = false;
liquidRegion = name() + "-liquid";
@@ -38,21 +38,21 @@ public class LiquidMixer extends LiquidBlock{
LiquidMixerEntity entity = tile.entity();
entity.accumulator += amount;
int items = (int)(entity.accumulator / liquidPerItem);
entity.inventory.removeItem(inputItem, items);
entity.items.removeItem(inputItem, items);
entity.accumulator %= liquidPerItem;
entity.liquid.liquid = outputLiquid;
entity.liquid.amount += amount;
entity.liquids.liquid = outputLiquid;
entity.liquids.amount += amount;
}
@Override
public boolean acceptItem(Item item, Tile tile, Tile source) {
return item == inputItem && tile.entity.inventory.getItem(item) < itemCapacity;
return item == inputItem && tile.entity.items.getItem(item) < itemCapacity;
}
@Override
public boolean acceptLiquid(Tile tile, Tile source, Liquid liquid, float amount) {
return liquid == inputLiquid && tile.entity.liquid.amount + amount <= liquidCapacity &&
tile.entity.inventory.hasItem(inputItem, (int)((tile.<LiquidMixerEntity>entity().accumulator + amount)/amount)) &&
return liquid == inputLiquid && tile.entity.liquids.amount + amount <= liquidCapacity &&
tile.entity.items.hasItem(inputItem, (int)((tile.<LiquidMixerEntity>entity().accumulator + amount)/amount)) &&
tile.entity.power.amount >= powerUse;
}

View File

@@ -37,13 +37,13 @@ public class PowerCrafter extends Block{
float powerUsed = Math.min(Timers.delta() * powerUse, tile.entity.power.amount);
int itemsUsed = Mathf.ceil(1 + input.amount * entity.progress);
if(entity.power.amount > powerUsed && entity.inventory.hasItem(input.item, itemsUsed)){
if(entity.power.amount > powerUsed && entity.items.hasItem(input.item, itemsUsed)){
entity.progress += 1f/craftTime;
entity.totalProgress += Timers.delta();
}
if(entity.progress >= 1f){
entity.inventory.removeItem(input);
entity.items.removeItem(input);
if(outputItem != null) offloadNear(tile, outputItem);
if(outputLiquid != null) handleLiquid(tile, tile, outputLiquid, outputLiquidAmount);
entity.progress = 0f;
@@ -60,7 +60,7 @@ public class PowerCrafter extends Block{
@Override
public boolean acceptItem(Item item, Tile tile, Tile source) {
return item == input.item && tile.entity.inventory.getItem(input.item) < itemCapacity;
return item == input.item && tile.entity.items.getItem(input.item) < itemCapacity;
}
@Override

View File

@@ -55,7 +55,7 @@ public class PowerSmelter extends PowerBlock {
bars.remove(BarType.inventory);
for(ItemStack item : inputs){
bars.add(new BlockBar(BarType.inventory, true, tile -> (float) tile.entity.inventory.getItem(item.item) / capacity));
bars.add(new BlockBar(BarType.inventory, true, tile -> (float) tile.entity.items.getItem(item.item) / capacity));
}
}
@@ -76,7 +76,7 @@ public class PowerSmelter extends PowerBlock {
PowerSmelterEntity entity = tile.entity();
if(entity.timer.get(timerDump, 5) && entity.inventory.hasItem(result)){
if(entity.timer.get(timerDump, 5) && entity.items.hasItem(result)){
tryDump(tile, result);
}
@@ -96,19 +96,19 @@ public class PowerSmelter extends PowerBlock {
//make sure it has all the items
for(ItemStack item : inputs){
if(!entity.inventory.hasItem(item.item, item.amount)){
if(!entity.items.hasItem(item.item, item.amount)){
return;
}
}
if(entity.inventory.getItem(result) >= capacity //output full
if(entity.items.getItem(result) >= capacity //output full
|| entity.heat <= minHeat //not burning
|| !entity.timer.get(timerCraft, craftTime)){ //not yet time
return;
}
for(ItemStack item : inputs){
entity.inventory.removeItem(item.item, item.amount);
entity.items.removeItem(item.item, item.amount);
}
offloadNear(tile, result);
@@ -120,7 +120,7 @@ public class PowerSmelter extends PowerBlock {
for(ItemStack stack : inputs){
if(stack.item == item){
return tile.entity.inventory.getItem(item) < capacity;
return tile.entity.items.getItem(item) < capacity;
}
}

View File

@@ -37,8 +37,8 @@ public class Pump extends LiquidBlock{
public void draw(Tile tile){
Draw.rect(name(), tile.drawx(), tile.drawy());
Draw.color(tile.entity.liquid.liquid.color);
Draw.alpha(tile.entity.liquid.amount / liquidCapacity);
Draw.color(tile.entity.liquids.liquid.color);
Draw.alpha(tile.entity.liquids.amount / liquidCapacity);
Draw.rect(liquidRegion, tile.drawx(), tile.drawy());
Draw.color();
}
@@ -64,9 +64,9 @@ public class Pump extends LiquidBlock{
public void update(Tile tile){
if(tile.floor().liquidDrop != null){
float maxPump = Math.min(liquidCapacity - tile.entity.liquid.amount, pumpAmount * Timers.delta());
tile.entity.liquid.liquid = tile.floor().liquidDrop;
tile.entity.liquid.amount += maxPump;
float maxPump = Math.min(liquidCapacity - tile.entity.liquids.amount, pumpAmount * Timers.delta());
tile.entity.liquids.liquid = tile.floor().liquidDrop;
tile.entity.liquids.amount += maxPump;
}
tryDumpLiquid(tile);

View File

@@ -33,7 +33,7 @@ public class Separator extends Block {
super(name);
update = true;
solid = true;
hasInventory = true;
hasItems = true;
hasLiquids = true;
}
@@ -43,8 +43,8 @@ public class Separator extends Block {
GenericCrafterEntity entity = tile.entity();
Draw.color(tile.entity.liquid.liquid.color);
Draw.alpha(tile.entity.liquid.amount / liquidCapacity);
Draw.color(tile.entity.liquids.liquid.color);
Draw.alpha(tile.entity.liquids.amount / liquidCapacity);
Draw.rect(name + "-liquid", tile.drawx(), tile.drawy());
Draw.color(Color.valueOf("858585"));
@@ -64,10 +64,10 @@ public class Separator extends Block {
entity.totalProgress += entity.warmup*Timers.delta();
if(entity.liquid.amount >= liquidUsed && entity.inventory.hasItem(item) &&
if(entity.liquids.amount >= liquidUsed && entity.items.hasItem(item) &&
(!hasPower || entity.power.amount >= powerUsed)){
entity.progress += 1f/filterTime;
entity.liquid.amount -= liquidUsed;
entity.liquids.amount -= liquidUsed;
if(hasPower) entity.power.amount -= powerUsed;
entity.warmup = Mathf.lerpDelta(entity.warmup, 1f, 0.02f);
@@ -78,7 +78,7 @@ public class Separator extends Block {
if(entity.progress >= 1f){
entity.progress = 0f;
Item item = Mathf.select(results);
entity.inventory.removeItem(this.item, 1);
entity.items.removeItem(this.item, 1);
if(item != null){
offloading = true;
offloadNear(tile, item);
@@ -103,7 +103,7 @@ public class Separator extends Block {
@Override
public boolean acceptItem(Item item, Tile tile, Tile source) {
return this.item == item && tile.entity.inventory.getItem(item) < itemCapacity;
return this.item == item && tile.entity.items.getItem(item) < itemCapacity;
}
@Override

View File

@@ -42,7 +42,7 @@ public class Smelter extends Block{
@Override
public void setBars(){
for(Item item : inputs){
bars.add(new BlockBar(BarType.inventory, true, tile -> (float)tile.entity.inventory.getItem(item)/capacity));
bars.add(new BlockBar(BarType.inventory, true, tile -> (float)tile.entity.items.getItem(item)/capacity));
}
}
@@ -62,13 +62,13 @@ public class Smelter extends Block{
public void update(Tile tile){
SmelterEntity entity = tile.entity();
if(entity.timer.get(timerDump, 5) && entity.inventory.hasItem(result)){
if(entity.timer.get(timerDump, 5) && entity.items.hasItem(result)){
tryDump(tile, result);
}
//add fuel
if(entity.inventory.getItem(fuel) > 0 && entity.burnTime <= 0f){
entity.inventory.removeItem(fuel, 1);
if(entity.items.getItem(fuel) > 0 && entity.burnTime <= 0f){
entity.items.removeItem(fuel, 1);
entity.burnTime += burnDuration;
Effects.effect(burnEffect, entity.x + Mathf.range(2f), entity.y + Mathf.range(2f));
}
@@ -83,19 +83,19 @@ public class Smelter extends Block{
//make sure it has all the items
for(Item item : inputs){
if(!entity.inventory.hasItem(item)){
if(!entity.items.hasItem(item)){
return;
}
}
if(entity.inventory.getItem(result) >= capacity //output full
if(entity.items.getItem(result) >= capacity //output full
|| entity.burnTime <= 0 //not burning
|| !entity.timer.get(timerCraft, craftTime)){ //not yet time
return;
}
for(Item item : inputs){
entity.inventory.removeItem(item, 1);
entity.items.removeItem(item, 1);
}
offloadNear(tile, result);
@@ -113,7 +113,7 @@ public class Smelter extends Block{
}
}
return (isInput && tile.entity.inventory.getItem(item) < capacity) || (item == fuel && tile.entity.inventory.getItem(fuel) < capacity);
return (isInput && tile.entity.items.getItem(item) < capacity) || (item == fuel && tile.entity.items.getItem(fuel) < capacity);
}
@Override

View File

@@ -35,8 +35,8 @@ public class SolidPump extends Pump {
SolidPumpEntity entity = tile.entity();
Draw.rect(name, tile.drawx(), tile.drawy());
Draw.color(tile.entity.liquid.liquid.color);
Draw.alpha(tile.entity.liquid.amount / liquidCapacity);
Draw.color(tile.entity.liquids.liquid.color);
Draw.alpha(tile.entity.liquids.amount / liquidCapacity);
Draw.rect(liquidRegion, tile.drawx(), tile.drawy());
Draw.color();
Draw.rect(name + "-rotator", tile.drawx(), tile.drawy(), entity.pumpTime * rotateSpeed);
@@ -66,10 +66,10 @@ public class SolidPump extends Pump {
if(isValid(tile)) fraction = 1f;
}
if(tile.entity.power.amount >= used && tile.entity.liquid.amount < liquidCapacity - 0.001f){
float maxPump = Math.min(liquidCapacity - tile.entity.liquid.amount, pumpAmount * Timers.delta() * fraction);
tile.entity.liquid.liquid = result;
tile.entity.liquid.amount += maxPump;
if(tile.entity.power.amount >= used && tile.entity.liquids.amount < liquidCapacity - 0.001f){
float maxPump = Math.min(liquidCapacity - tile.entity.liquids.amount, pumpAmount * Timers.delta() * fraction);
tile.entity.liquids.liquid = result;
tile.entity.liquids.amount += maxPump;
tile.entity.power.amount -= used;
entity.warmup = Mathf.lerpDelta(entity.warmup, 1f, 0.02f);
if(Mathf.chance(Timers.delta() * updateEffectChance))

View File

@@ -123,7 +123,7 @@ public class UnitFactory extends Block {
}
}
if(hasRequirements(entity.inventory, entity.buildTime/produceTime) &&
if(hasRequirements(entity.items, entity.buildTime/produceTime) &&
entity.power.amount >= used && !entity.open){
entity.buildTime += Timers.delta();
@@ -151,7 +151,7 @@ public class UnitFactory extends Block {
//Timers.run(openDuration, () -> entity.open = false);
for(ItemStack stack : requirements){
entity.inventory.removeItem(stack.item, stack.amount);
entity.items.removeItem(stack.item, stack.amount);
}
}
}
@@ -159,7 +159,7 @@ public class UnitFactory extends Block {
@Override
public boolean acceptItem(Item item, Tile tile, Tile source) {
for(ItemStack stack : requirements){
if(item == stack.item && tile.entity.inventory.getItem(item) <= stack.amount*2){
if(item == stack.item && tile.entity.items.getItem(item) <= stack.amount*2){
return true;
}
}

View File

@@ -15,7 +15,7 @@ public class CoreBlock extends StorageBlock {
destructible = true;
unbreakable = true;
size = 3;
hasInventory = true;
hasItems = true;
itemCapacity = 2000;
}

View File

@@ -26,16 +26,16 @@ public class SortedUnloader extends Unloader {
public void update(Tile tile){
SortedUnloaderEntity entity = tile.entity();
if(entity.inventory.totalItems() == 0 && entity.timer.get(timerUnload, speed)){
if(entity.items.totalItems() == 0 && entity.timer.get(timerUnload, speed)){
tile.allNearby(other -> {
if(other.block() instanceof StorageBlock && entity.inventory.totalItems() == 0 &&
if(other.block() instanceof StorageBlock && entity.items.totalItems() == 0 &&
((StorageBlock)other.block()).hasItem(other, entity.sortItem)){
offloadNear(tile, ((StorageBlock)other.block()).removeItem(other, entity.sortItem));
}
});
}
if(entity.inventory.totalItems() > 0){
if(entity.items.totalItems() > 0){
tryDump(tile);
}
}
@@ -61,7 +61,7 @@ public class SortedUnloader extends Unloader {
SortedUnloaderEntity entity = tile.entity();
if(entity != null){
entity.sortItem = Item.getByID(data);
entity.inventory.clear();
entity.items.clear();
}
}

View File

@@ -15,9 +15,9 @@ public abstract class StorageBlock extends Block {
* Returns null if no items are there.*/
public Item removeItem(Tile tile, Item item){
TileEntity entity = tile.entity;
for(int i = 0; i < entity.inventory.items.length; i ++){
if(entity.inventory.items[i] > 0 && (item == null || i == item.id)){
entity.inventory.items[i] --;
for(int i = 0; i < entity.items.items.length; i ++){
if(entity.items.items[i] > 0 && (item == null || i == item.id)){
entity.items.items[i] --;
return Item.getByID(i);
}
}
@@ -28,8 +28,8 @@ 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;
for(int i = 0; i < entity.inventory.items.length; i ++){
if(entity.inventory.items[i] > 0 && (item == null || i == item.id)){
for(int i = 0; i < entity.items.items.length; i ++){
if(entity.items.items[i] > 0 && (item == null || i == item.id)){
return true;
}
}

View File

@@ -19,16 +19,16 @@ public class Unloader extends Block {
@Override
public void update(Tile tile){
if(tile.entity.inventory.totalItems() == 0 && tile.entity.timer.get(timerUnload, speed)){
if(tile.entity.items.totalItems() == 0 && tile.entity.timer.get(timerUnload, speed)){
tile.allNearby(other -> {
if(other.block() instanceof StorageBlock && tile.entity.inventory.totalItems() == 0 &&
if(other.block() instanceof StorageBlock && tile.entity.items.totalItems() == 0 &&
((StorageBlock)other.block()).hasItem(other, null)){
offloadNear(tile, ((StorageBlock)other.block()).removeItem(other, null));
}
});
}
if(tile.entity.inventory.totalItems() > 0){
if(tile.entity.items.totalItems() > 0){
tryDump(tile);
}
}

View File

@@ -18,7 +18,7 @@ public class Vault extends StorageBlock {
int iterations = Math.max(1, (int) (Timers.delta() + 0.4f));
for(int i = 0; i < iterations; i ++) {
if (tile.entity.inventory.totalItems() > 0) {
if (tile.entity.items.totalItems() > 0) {
tryDump(tile);
}
}
@@ -32,7 +32,7 @@ public class Vault extends StorageBlock {
@Override
public boolean acceptItem(Item item, Tile tile, Tile source) {
return tile.entity.inventory.totalItems() < itemCapacity;
return tile.entity.items.totalItems() < itemCapacity;
}
@Override
@@ -41,8 +41,8 @@ public class Vault extends StorageBlock {
if(!(to.block() instanceof StorageBlock)) return false;
if(to.block() instanceof Vault){
return (float)to.entity.inventory.totalItems() / to.block().itemCapacity <
(float)tile.entity.inventory.totalItems() / itemCapacity;
return (float)to.entity.items.totalItems() / to.block().itemCapacity <
(float)tile.entity.items.totalItems() / itemCapacity;
}
return true;