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<Player> playerGroup = Entities.addGroup(Player.class).enableMapping();
public static final EntityGroup<TileEntity> tileGroup = Entities.addGroup(TileEntity.class, false); 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<Bullet> bulletGroup = Entities.addGroup(Bullet.class);
public static final EntityGroup<Shield> shieldGroup = Entities.addGroup(Shield.class, false); public static final EntityGroup<Shield> shieldGroup = Entities.addGroup(Shield.class, false);
public static final EntityGroup<EffectEntity> effectGroup = Entities.addGroup(EffectEntity.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; craftEffect = BlockFx.pulverize;
craftTime = 60f; craftTime = 60f;
updateEffect = BlockFx.pulverizeSmall; updateEffect = BlockFx.pulverizeSmall;
hasInventory = hasPower = true; hasItems = hasPower = true;
}}, }},
oilRefinery = new GenericCrafter("oilrefinery") {{ oilRefinery = new GenericCrafter("oilrefinery") {{
@@ -177,7 +177,7 @@ public class CraftingBlocks {
output = Items.coal; output = Items.coal;
health = 80; health = 80;
craftEffect = BlockFx.purifyoil; craftEffect = BlockFx.purifyoil;
hasInventory = hasLiquids = hasPower = true; hasItems = hasLiquids = hasPower = true;
}}, }},
stoneFormer = new GenericCrafter("stoneformer") {{ stoneFormer = new GenericCrafter("stoneformer") {{
@@ -188,7 +188,7 @@ public class CraftingBlocks {
output = Items.stone; output = Items.stone;
health = 80; health = 80;
craftEffect = BlockFx.purifystone; craftEffect = BlockFx.purifystone;
hasLiquids = hasInventory = true; hasLiquids = hasItems = true;
}}, }},
weaponFactory = new WeaponFactory("weaponfactory") {{ weaponFactory = new WeaponFactory("weaponfactory") {{

View File

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

View File

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

View File

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

View File

@@ -19,19 +19,25 @@ import java.io.DataInputStream;
import java.io.DataOutputStream; import java.io.DataOutputStream;
import java.io.IOException; import java.io.IOException;
import static io.anuke.mindustry.Vars.disabledTileGroup;
import static io.anuke.mindustry.Vars.tileGroup; import static io.anuke.mindustry.Vars.tileGroup;
import static io.anuke.mindustry.Vars.world; import static io.anuke.mindustry.Vars.world;
public class TileEntity extends Entity{ public class TileEntity extends Entity{
public static final float timeToSleep = 60f*3; //3 seconds to fall asleep
public Tile tile; public Tile tile;
public Timer timer; public Timer timer;
public float health; public float health;
public boolean dead = false; public boolean dead = false;
public boolean added;
public PowerModule power; public PowerModule power;
public InventoryModule inventory; public InventoryModule items;
public LiquidModule liquid; 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.*/ /**Sets this tile entity data to this tile, and adds it if necessary.*/
public TileEntity init(Tile tile, boolean added){ public TileEntity init(Tile tile, boolean added){
@@ -51,13 +57,30 @@ public class TileEntity extends Entity{
return this; 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;
}
} }
public void read(DataInputStream stream) throws IOException{ /**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 write(DataOutputStream stream) throws IOException{}
public void read(DataInputStream stream) throws IOException{}
public void onDeath(){ public void onDeath(){
onDeath(false); onDeath(false);
@@ -82,6 +105,10 @@ public class TileEntity extends Entity{
} }
} }
public boolean collide(Bullet other){
return true;
}
public void collision(Bullet other){ public void collision(Bullet other){
damage(other.getDamage()); damage(other.getDamage());
} }
@@ -98,13 +125,10 @@ public class TileEntity extends Entity{
} }
} }
public boolean collide(Bullet other){
return true;
}
@Override @Override
public void update(){ public void update(){
synchronized (Tile.tileSetLock) { synchronized (Tile.tileSetLock) {
//TODO better smoke effect, this one is awful
if (health != 0 && health < tile.block().health && !(tile.block() instanceof Wall) && if (health != 0 && health < tile.block().health && !(tile.block() instanceof Wall) &&
Mathf.chance(0.009f * Timers.delta() * (1f - health / tile.block().health))) { 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; if(set.size == 0) return empty;
Array<Tile> tiles = set.first().cores; Array<Tile> tiles = set.first().cores;
if(tiles.size == 0) return empty; 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.entity.health = health;
tile.setRotation(rotation); 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.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); 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.writeByte(Bits.packByte((byte)tile.getTeam().ordinal(), tile.getRotation())); //team + rotation
stream.writeShort((short)tile.entity.health); //health 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.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); tile.entity.write(stream);
} }

View File

@@ -69,9 +69,9 @@ public class NetworkIO {
stream.writeByte(Bits.packByte((byte)tile.getTeam().ordinal(), tile.getRotation())); stream.writeByte(Bits.packByte((byte)tile.getTeam().ordinal(), tile.getRotation()));
stream.writeShort((short)tile.entity.health); //health 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.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); tile.entity.write(stream);
} }
@@ -156,9 +156,9 @@ public class NetworkIO {
tile.entity.health = health; 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.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); tile.entity.read(stream);
} }

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@@ -23,7 +23,7 @@ public abstract class LiquidTurret extends Turret {
public void setBars() { public void setBars() {
super.setBars(); super.setBars();
bars.remove(BarType.inventory); 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 @Override
@@ -45,20 +45,20 @@ public abstract class LiquidTurret extends Turret {
@Override @Override
public AmmoType useAmmo(Tile tile){ public AmmoType useAmmo(Tile tile){
TurretEntity entity = tile.entity(); TurretEntity entity = tile.entity();
AmmoType type = liquidAmmoMap.get(entity.liquid.liquid); AmmoType type = liquidAmmoMap.get(entity.liquids.liquid);
entity.liquid.amount -= type.quantityMultiplier; entity.liquids.amount -= type.quantityMultiplier;
return type; return type;
} }
@Override @Override
public AmmoType peekAmmo(Tile tile){ public AmmoType peekAmmo(Tile tile){
return liquidAmmoMap.get(tile.entity.liquid.liquid); return liquidAmmoMap.get(tile.entity.liquids.liquid);
} }
@Override @Override
public boolean hasAmmo(Tile tile){ public boolean hasAmmo(Tile tile){
TurretEntity entity = tile.entity(); 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 @Override

View File

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

View File

@@ -26,7 +26,7 @@ public class Conduit extends LiquidBlock {
@Override @Override
public void draw(Tile tile){ public void draw(Tile tile){
ConduitEntity entity = tile.entity(); ConduitEntity entity = tile.entity();
LiquidModule mod = tile.entity.liquid; LiquidModule mod = tile.entity.liquids;
int rotation = rotate ? tile.getRotation() * 90 : 0; int rotation = rotate ? tile.getRotation() * 90 : 0;
@@ -43,9 +43,9 @@ public class Conduit extends LiquidBlock {
@Override @Override
public void update(Tile tile){ public void update(Tile tile){
ConduitEntity entity = tile.entity(); 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); tryMoveLiquid(tile, tile.getNearby(tile.getRotation()), true);
} }
} }

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@@ -33,7 +33,7 @@ public class BurnerGenerator extends PowerGenerator {
@Override @Override
public void setBars(){ public void setBars(){
super.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 @Override
@@ -51,7 +51,7 @@ public class BurnerGenerator extends PowerGenerator {
if(entity.generateTime > 0){ if(entity.generateTime > 0){
Draw.color(heatColor); 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; alpha = alpha * 0.7f + Mathf.absin(Timers.time(), 12f, 0.3f) * alpha;
Draw.alpha(alpha); Draw.alpha(alpha);
Draw.rect(name + "-top", tile.worldx(), tile.worldy()); Draw.rect(name + "-top", tile.worldx(), tile.worldy());
@@ -61,7 +61,7 @@ public class BurnerGenerator extends PowerGenerator {
@Override @Override
public boolean acceptItem(Item item, Tile tile, Tile source){ 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 @Override
@@ -77,11 +77,11 @@ public class BurnerGenerator extends PowerGenerator {
entity.generateTime = Mathf.clamp(entity.generateTime); 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)); Effects.effect(generateEffect, tile.worldx() + Mathf.range(3f), tile.worldy() + Mathf.range(3f));
for(int i = 0; i < entity.inventory.items.length; i ++){ for(int i = 0; i < entity.items.items.length; i ++){
if(entity.inventory.items[i] > 0){ if(entity.items.items[i] > 0){
entity.inventory.items[i] --; entity.items.items[i] --;
entity.efficiency = getItemEfficiency(Item.getByID(i)); entity.efficiency = getItemEfficiency(Item.getByID(i));
break; break;
} }

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@@ -37,7 +37,7 @@ public class Cultivator extends Drill {
CultivatorEntity entity = tile.entity(); CultivatorEntity entity = tile.entity();
entity.warmup = Mathf.lerpDelta(entity.warmup, 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 @Override

View File

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

View File

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

View File

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

View File

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

View File

@@ -17,7 +17,7 @@ public class LiquidMixer extends LiquidBlock{
public LiquidMixer(String name) { public LiquidMixer(String name) {
super(name); super(name);
hasInventory = true; hasItems = true;
hasPower = true; hasPower = true;
rotate = false; rotate = false;
liquidRegion = name() + "-liquid"; liquidRegion = name() + "-liquid";
@@ -38,21 +38,21 @@ public class LiquidMixer extends LiquidBlock{
LiquidMixerEntity entity = tile.entity(); LiquidMixerEntity entity = tile.entity();
entity.accumulator += amount; entity.accumulator += amount;
int items = (int)(entity.accumulator / liquidPerItem); int items = (int)(entity.accumulator / liquidPerItem);
entity.inventory.removeItem(inputItem, items); entity.items.removeItem(inputItem, items);
entity.accumulator %= liquidPerItem; entity.accumulator %= liquidPerItem;
entity.liquid.liquid = outputLiquid; entity.liquids.liquid = outputLiquid;
entity.liquid.amount += amount; entity.liquids.amount += amount;
} }
@Override @Override
public boolean acceptItem(Item item, Tile tile, Tile source) { 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 @Override
public boolean acceptLiquid(Tile tile, Tile source, Liquid liquid, float amount) { public boolean acceptLiquid(Tile tile, Tile source, Liquid liquid, float amount) {
return liquid == inputLiquid && tile.entity.liquid.amount + amount <= liquidCapacity && return liquid == inputLiquid && tile.entity.liquids.amount + amount <= liquidCapacity &&
tile.entity.inventory.hasItem(inputItem, (int)((tile.<LiquidMixerEntity>entity().accumulator + amount)/amount)) && tile.entity.items.hasItem(inputItem, (int)((tile.<LiquidMixerEntity>entity().accumulator + amount)/amount)) &&
tile.entity.power.amount >= powerUse; 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); float powerUsed = Math.min(Timers.delta() * powerUse, tile.entity.power.amount);
int itemsUsed = Mathf.ceil(1 + input.amount * entity.progress); 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.progress += 1f/craftTime;
entity.totalProgress += Timers.delta(); entity.totalProgress += Timers.delta();
} }
if(entity.progress >= 1f){ if(entity.progress >= 1f){
entity.inventory.removeItem(input); entity.items.removeItem(input);
if(outputItem != null) offloadNear(tile, outputItem); if(outputItem != null) offloadNear(tile, outputItem);
if(outputLiquid != null) handleLiquid(tile, tile, outputLiquid, outputLiquidAmount); if(outputLiquid != null) handleLiquid(tile, tile, outputLiquid, outputLiquidAmount);
entity.progress = 0f; entity.progress = 0f;
@@ -60,7 +60,7 @@ public class PowerCrafter extends Block{
@Override @Override
public boolean acceptItem(Item item, Tile tile, Tile source) { 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 @Override

View File

@@ -55,7 +55,7 @@ public class PowerSmelter extends PowerBlock {
bars.remove(BarType.inventory); bars.remove(BarType.inventory);
for(ItemStack item : inputs){ 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(); 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); tryDump(tile, result);
} }
@@ -96,19 +96,19 @@ public class PowerSmelter extends PowerBlock {
//make sure it has all the items //make sure it has all the items
for(ItemStack item : inputs){ for(ItemStack item : inputs){
if(!entity.inventory.hasItem(item.item, item.amount)){ if(!entity.items.hasItem(item.item, item.amount)){
return; return;
} }
} }
if(entity.inventory.getItem(result) >= capacity //output full if(entity.items.getItem(result) >= capacity //output full
|| entity.heat <= minHeat //not burning || entity.heat <= minHeat //not burning
|| !entity.timer.get(timerCraft, craftTime)){ //not yet time || !entity.timer.get(timerCraft, craftTime)){ //not yet time
return; return;
} }
for(ItemStack item : inputs){ for(ItemStack item : inputs){
entity.inventory.removeItem(item.item, item.amount); entity.items.removeItem(item.item, item.amount);
} }
offloadNear(tile, result); offloadNear(tile, result);
@@ -120,7 +120,7 @@ public class PowerSmelter extends PowerBlock {
for(ItemStack stack : inputs){ for(ItemStack stack : inputs){
if(stack.item == item){ 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){ public void draw(Tile tile){
Draw.rect(name(), tile.drawx(), tile.drawy()); Draw.rect(name(), tile.drawx(), tile.drawy());
Draw.color(tile.entity.liquid.liquid.color); Draw.color(tile.entity.liquids.liquid.color);
Draw.alpha(tile.entity.liquid.amount / liquidCapacity); Draw.alpha(tile.entity.liquids.amount / liquidCapacity);
Draw.rect(liquidRegion, tile.drawx(), tile.drawy()); Draw.rect(liquidRegion, tile.drawx(), tile.drawy());
Draw.color(); Draw.color();
} }
@@ -64,9 +64,9 @@ public class Pump extends LiquidBlock{
public void update(Tile tile){ public void update(Tile tile){
if(tile.floor().liquidDrop != null){ if(tile.floor().liquidDrop != null){
float maxPump = Math.min(liquidCapacity - tile.entity.liquid.amount, pumpAmount * Timers.delta()); float maxPump = Math.min(liquidCapacity - tile.entity.liquids.amount, pumpAmount * Timers.delta());
tile.entity.liquid.liquid = tile.floor().liquidDrop; tile.entity.liquids.liquid = tile.floor().liquidDrop;
tile.entity.liquid.amount += maxPump; tile.entity.liquids.amount += maxPump;
} }
tryDumpLiquid(tile); tryDumpLiquid(tile);

View File

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

View File

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

View File

@@ -35,8 +35,8 @@ public class SolidPump extends Pump {
SolidPumpEntity entity = tile.entity(); SolidPumpEntity entity = tile.entity();
Draw.rect(name, tile.drawx(), tile.drawy()); Draw.rect(name, tile.drawx(), tile.drawy());
Draw.color(tile.entity.liquid.liquid.color); Draw.color(tile.entity.liquids.liquid.color);
Draw.alpha(tile.entity.liquid.amount / liquidCapacity); Draw.alpha(tile.entity.liquids.amount / liquidCapacity);
Draw.rect(liquidRegion, tile.drawx(), tile.drawy()); Draw.rect(liquidRegion, tile.drawx(), tile.drawy());
Draw.color(); Draw.color();
Draw.rect(name + "-rotator", tile.drawx(), tile.drawy(), entity.pumpTime * rotateSpeed); 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(isValid(tile)) fraction = 1f;
} }
if(tile.entity.power.amount >= used && tile.entity.liquid.amount < liquidCapacity - 0.001f){ if(tile.entity.power.amount >= used && tile.entity.liquids.amount < liquidCapacity - 0.001f){
float maxPump = Math.min(liquidCapacity - tile.entity.liquid.amount, pumpAmount * Timers.delta() * fraction); float maxPump = Math.min(liquidCapacity - tile.entity.liquids.amount, pumpAmount * Timers.delta() * fraction);
tile.entity.liquid.liquid = result; tile.entity.liquids.liquid = result;
tile.entity.liquid.amount += maxPump; tile.entity.liquids.amount += maxPump;
tile.entity.power.amount -= used; tile.entity.power.amount -= used;
entity.warmup = Mathf.lerpDelta(entity.warmup, 1f, 0.02f); entity.warmup = Mathf.lerpDelta(entity.warmup, 1f, 0.02f);
if(Mathf.chance(Timers.delta() * updateEffectChance)) 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.power.amount >= used && !entity.open){
entity.buildTime += Timers.delta(); entity.buildTime += Timers.delta();
@@ -151,7 +151,7 @@ public class UnitFactory extends Block {
//Timers.run(openDuration, () -> entity.open = false); //Timers.run(openDuration, () -> entity.open = false);
for(ItemStack stack : requirements){ 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 @Override
public boolean acceptItem(Item item, Tile tile, Tile source) { public boolean acceptItem(Item item, Tile tile, Tile source) {
for(ItemStack stack : requirements){ 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; return true;
} }
} }

View File

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

View File

@@ -26,16 +26,16 @@ public class SortedUnloader extends Unloader {
public void update(Tile tile){ public void update(Tile tile){
SortedUnloaderEntity entity = tile.entity(); 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 -> { 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)){ ((StorageBlock)other.block()).hasItem(other, entity.sortItem)){
offloadNear(tile, ((StorageBlock)other.block()).removeItem(other, entity.sortItem)); offloadNear(tile, ((StorageBlock)other.block()).removeItem(other, entity.sortItem));
} }
}); });
} }
if(entity.inventory.totalItems() > 0){ if(entity.items.totalItems() > 0){
tryDump(tile); tryDump(tile);
} }
} }
@@ -61,7 +61,7 @@ public class SortedUnloader extends Unloader {
SortedUnloaderEntity entity = tile.entity(); SortedUnloaderEntity entity = tile.entity();
if(entity != null){ if(entity != null){
entity.sortItem = Item.getByID(data); 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.*/ * Returns null if no items are there.*/
public Item removeItem(Tile tile, Item item){ public Item removeItem(Tile tile, Item item){
TileEntity entity = tile.entity; TileEntity entity = tile.entity;
for(int i = 0; i < entity.inventory.items.length; i ++){ for(int i = 0; i < entity.items.items.length; i ++){
if(entity.inventory.items[i] > 0 && (item == null || i == item.id)){ if(entity.items.items[i] > 0 && (item == null || i == item.id)){
entity.inventory.items[i] --; entity.items.items[i] --;
return Item.getByID(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.*/ * If the item is null, it should return whether it has ANY items.*/
public boolean hasItem(Tile tile, Item item){ public boolean hasItem(Tile tile, Item item){
TileEntity entity = tile.entity; TileEntity entity = tile.entity;
for(int i = 0; i < entity.inventory.items.length; i ++){ for(int i = 0; i < entity.items.items.length; i ++){
if(entity.inventory.items[i] > 0 && (item == null || i == item.id)){ if(entity.items.items[i] > 0 && (item == null || i == item.id)){
return true; return true;
} }
} }

View File

@@ -19,16 +19,16 @@ public class Unloader extends Block {
@Override @Override
public void update(Tile tile){ 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 -> { 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)){ ((StorageBlock)other.block()).hasItem(other, null)){
offloadNear(tile, ((StorageBlock)other.block()).removeItem(other, null)); offloadNear(tile, ((StorageBlock)other.block()).removeItem(other, null));
} }
}); });
} }
if(tile.entity.inventory.totalItems() > 0){ if(tile.entity.items.totalItems() > 0){
tryDump(tile); tryDump(tile);
} }
} }

View File

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