Massive amount of bugfixes / Multi-liquid support / Broken build

This commit is contained in:
Anuken
2018-07-06 23:24:14 -04:00
parent 64f1fbe400
commit d988bb1821
74 changed files with 633 additions and 511 deletions

View File

@@ -20,7 +20,7 @@
<activity <activity
android:name="io.anuke.mindustry.AndroidLauncher" android:name="io.anuke.mindustry.AndroidLauncher"
android:label="@string/app_name" android:label="@string/app_name"
android:screenOrientation="sensor" android:screenOrientation="user"
android:configChanges="keyboard|keyboardHidden|orientation|screenSize"> android:configChanges="keyboard|keyboardHidden|orientation|screenSize">
<intent-filter> <intent-filter>

View File

@@ -461,8 +461,8 @@ block.multiplexer.name=Multiplexer
block.multiplexer.description=A router that can split items into 8 directions. block.multiplexer.description=A router that can split items into 8 directions.
block.sorter.name=Sorter block.sorter.name=Sorter
block.sorter.description=Sorts items. If an item matches the selection, it is allowed to pass. Otherwise, the item is outputted to the left and right. block.sorter.description=Sorts items. If an item matches the selection, it is allowed to pass. Otherwise, the item is outputted to the left and right.
block.overflowgate.name=Overflow Gate block.overflow-gate.name=Overflow Gate
block.overflowgate.description=A combination splitter and router that only outputs to the left and right if the front path is blocked. block.overflow-gate.description=A combination splitter and router that only outputs to the left and right if the front path is blocked.
block.bridgeconveyor.name=Bridge Conveyor block.bridgeconveyor.name=Bridge Conveyor
block.bridgeconveyor.description=A conveyor that can go over other blocks, for up to two total blocks. block.bridgeconveyor.description=A conveyor that can go over other blocks, for up to two total blocks.
block.smelter.name=Smelter block.smelter.name=Smelter
@@ -512,7 +512,6 @@ block.swarmer.name=Swarmer
block.salvo.name=Salvo block.salvo.name=Salvo
block.ripple.name=Ripple block.ripple.name=Ripple
block.phase-conveyor.name=Phase Conveyor block.phase-conveyor.name=Phase Conveyor
block.overflow-gate.name=Overflow Gate
block.bridge-conveyor.name=Bridge Conveyor block.bridge-conveyor.name=Bridge Conveyor
block.plastanium-compressor.name=Plastanium Compressor block.plastanium-compressor.name=Plastanium Compressor
block.pyratite-mixer.name=Pyratite Mixer block.pyratite-mixer.name=Pyratite Mixer

View File

@@ -12,13 +12,6 @@ public class Liquids implements ContentList {
@Override @Override
public void load() { public void load() {
none = new Liquid("none", Color.CLEAR){
@Override
public boolean isHidden(){
return true;
}
};
water = new Liquid("water", Color.valueOf("486acd")) { water = new Liquid("water", Color.valueOf("486acd")) {
{ {
heatCapacity = 0.4f; heatCapacity = 0.4f;

View File

@@ -145,17 +145,14 @@ public class Blocks extends BlockList implements ContentList{
rock = new Rock("rock") {{ rock = new Rock("rock") {{
variants = 2; variants = 2;
varyShadow = true;
}}; }};
icerock = new Rock("icerock") {{ icerock = new Rock("icerock") {{
variants = 2; variants = 2;
varyShadow = true;
}}; }};
blackrock = new Rock("blackrock") {{ blackrock = new Rock("blackrock") {{
variants = 1; variants = 1;
varyShadow = true;
}}; }};
} }
} }

View File

@@ -56,7 +56,7 @@ public class DebugBlocks extends BlockList implements ContentList{
@Override @Override
public void update(Tile tile) { public void update(Tile tile) {
SorterEntity entity = tile.entity(); SorterEntity entity = tile.entity();
entity.items.items[entity.sortItem.id] = 1; entity.items.set(entity.sortItem, 1);
tryDump(tile, entity.sortItem); tryDump(tile, entity.sortItem);
} }
@@ -79,9 +79,8 @@ public class DebugBlocks extends BlockList implements ContentList{
public void update(Tile tile) { public void update(Tile tile) {
LiquidSourceEntity entity = tile.entity(); LiquidSourceEntity entity = tile.entity();
tile.entity.liquids.amount = liquidCapacity; tile.entity.liquids.add(entity.source, liquidCapacity);
tile.entity.liquids.liquid = entity.source; tryDumpLiquid(tile, entity.source);
tryDumpLiquid(tile);
} }
@Override @Override

View File

@@ -35,11 +35,11 @@ public class DefenseBlocks extends BlockList implements ContentList {
}}; }};
thoriumWall = new Wall("thorium-wall") {{ thoriumWall = new Wall("thorium-wall") {{
health = 110 * wallHealthMultiplier; health = 200 * wallHealthMultiplier;
}}; }};
thoriumWallLarge = new Wall("thorium-wall-large") {{ thoriumWallLarge = new Wall("thorium-wall-large") {{
health = 110 * wallHealthMultiplier*4; health = 200 * wallHealthMultiplier*4;
size = 2; size = 2;
}}; }};

View File

@@ -19,6 +19,7 @@ public class StorageBlocks extends BlockList implements ContentList {
vault = new Vault("vault") {{ vault = new Vault("vault") {{
size = 3; size = 3;
health = 600; health = 600;
itemCapacity = 2000;
}}; }};
unloader = new Unloader("unloader") {{ unloader = new Unloader("unloader") {{

View File

@@ -73,10 +73,10 @@ public class TurretBlocks extends BlockList implements ContentList {
health = 360; health = 360;
drawer = (tile, entity) -> { drawer = (tile, entity) -> {
Draw.rect(name, tile.drawx() + tr2.x, tile.drawy() + tr2.y, entity.rotation - 90); Draw.rect(region, tile.drawx() + tr2.x, tile.drawy() + tr2.y, entity.rotation - 90);
Draw.color(entity.liquids.liquid.color); Draw.color(entity.liquids.current().color);
Draw.alpha(entity.liquids.amount / liquidCapacity); Draw.alpha(entity.liquids.total() / 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();
}; };
@@ -145,7 +145,7 @@ public class TurretBlocks extends BlockList implements ContentList {
ammoUseEffect = ShootFx.shellEjectBig; ammoUseEffect = ShootFx.shellEjectBig;
drawer = (tile, entity) -> { drawer = (tile, entity) -> {
Draw.rect(name, tile.drawx() + tr2.x, tile.drawy() + tr2.y, entity.rotation - 90); Draw.rect(region, tile.drawx() + tr2.x, tile.drawy() + tr2.y, entity.rotation - 90);
float offsetx = (int) (Mathf.abscurve(Mathf.curve(entity.reload / reload, 0.3f, 0.2f)) * 3f); float offsetx = (int) (Mathf.abscurve(Mathf.curve(entity.reload / reload, 0.3f, 0.2f)) * 3f);
float offsety = -(int) (Mathf.abscurve(Mathf.curve(entity.reload / reload, 0.3f, 0.2f)) * 2f); float offsety = -(int) (Mathf.abscurve(Mathf.curve(entity.reload / reload, 0.3f, 0.2f)) * 2f);

View File

@@ -20,7 +20,6 @@ import io.anuke.mindustry.input.MobileInput;
import io.anuke.mindustry.io.Map; import io.anuke.mindustry.io.Map;
import io.anuke.mindustry.io.Saves; import io.anuke.mindustry.io.Saves;
import io.anuke.mindustry.net.Net; import io.anuke.mindustry.net.Net;
import io.anuke.mindustry.type.Item;
import io.anuke.mindustry.type.Recipe; import io.anuke.mindustry.type.Recipe;
import io.anuke.mindustry.ui.dialogs.FloatingDialog; import io.anuke.mindustry.ui.dialogs.FloatingDialog;
import io.anuke.ucore.core.*; import io.anuke.ucore.core.*;
@@ -264,11 +263,7 @@ public class Control extends Module{
if(entity == null) return; if(entity == null) return;
for (int i = 0; i < entity.items.items.length; i++) { entity.items.forEach((item, amount) -> control.database().unlockContent(item));
if(entity.items.items[i] <= 0) continue;
Item item = Item.getByID(i);
control.database().unlockContent(item);
}
if(players[0].inventory.hasItem()){ if(players[0].inventory.hasItem()){
control.database().unlockContent(players[0].inventory.getItem().item); control.database().unlockContent(players[0].inventory.getItem().item);
@@ -276,7 +271,7 @@ public class Control extends Module{
for(int i = 0 ; i < Recipe.all().size; i ++){ for(int i = 0 ; i < Recipe.all().size; i ++){
Recipe recipe = Recipe.all().get(i); Recipe recipe = Recipe.all().get(i);
if(!recipe.debugOnly && entity.items.hasItems(recipe.requirements, 1.4f)){ if(!recipe.debugOnly && entity.items.has(recipe.requirements, 1.4f)){
if(control.database().unlockContent(recipe)){ if(control.database().unlockContent(recipe)){
ui.hudfrag.showUnlock(recipe); ui.hudfrag.showUnlock(recipe);
} }

View File

@@ -54,12 +54,12 @@ public class Logic extends Module {
if(debug) { if(debug) {
for (Item item : Item.all()) { for (Item item : Item.all()) {
if (item.type == ItemType.material) { if (item.type == ItemType.material) {
tile.entity.items.addItem(item, 1000); tile.entity.items.add(item, 1000);
} }
} }
}else{ }else{
tile.entity.items.addItem(Items.tungsten, 50); tile.entity.items.add(Items.tungsten, 50);
tile.entity.items.addItem(Items.lead, 20); tile.entity.items.add(Items.lead, 20);
} }
} }
} }
@@ -158,13 +158,6 @@ public class Logic extends Module {
for(EntityGroup group : unitGroups){ for(EntityGroup group : unitGroups){
if(!group.isEmpty()){ if(!group.isEmpty()){
EntityPhysics.collideGroups(bulletGroup, group); EntityPhysics.collideGroups(bulletGroup, group);
/*
for(EntityGroup other : unitGroups){
if(!other.isEmpty()){
EntityPhysics.collideGroups(group, other);
}
}*/
} }
} }

View File

@@ -9,6 +9,7 @@ import com.badlogic.gdx.utils.Queue;
import io.anuke.annotations.Annotations.Loc; import io.anuke.annotations.Annotations.Loc;
import io.anuke.annotations.Annotations.Remote; import io.anuke.annotations.Annotations.Remote;
import io.anuke.mindustry.Vars; import io.anuke.mindustry.Vars;
import io.anuke.mindustry.content.Mechs;
import io.anuke.mindustry.entities.effect.ItemDrop; import io.anuke.mindustry.entities.effect.ItemDrop;
import io.anuke.mindustry.entities.effect.ScorchDecal; import io.anuke.mindustry.entities.effect.ScorchDecal;
import io.anuke.mindustry.entities.traits.*; import io.anuke.mindustry.entities.traits.*;
@@ -660,6 +661,8 @@ public class Player extends Unit implements BuilderTrait, CarryTrait, ShooterTra
dead = true; dead = true;
trail.clear(); trail.clear();
health = maxHealth(); health = maxHealth();
mech = (mobile ? Mechs.starterMobile : Mechs.starterDesktop);
placeQueue.clear();
add(); add();
} }

View File

@@ -1,6 +1,7 @@
package io.anuke.mindustry.entities; package io.anuke.mindustry.entities;
import com.badlogic.gdx.math.Vector2; import com.badlogic.gdx.math.Vector2;
import com.badlogic.gdx.utils.Array;
import io.anuke.annotations.Annotations.Loc; import io.anuke.annotations.Annotations.Loc;
import io.anuke.annotations.Annotations.Remote; import io.anuke.annotations.Annotations.Remote;
import io.anuke.mindustry.content.fx.Fx; import io.anuke.mindustry.content.fx.Fx;
@@ -10,11 +11,12 @@ import io.anuke.mindustry.game.Team;
import io.anuke.mindustry.gen.CallBlocks; import io.anuke.mindustry.gen.CallBlocks;
import io.anuke.mindustry.net.In; import io.anuke.mindustry.net.In;
import io.anuke.mindustry.world.Block; import io.anuke.mindustry.world.Block;
import io.anuke.mindustry.world.consumers.Consume;
import io.anuke.mindustry.world.Tile; import io.anuke.mindustry.world.Tile;
import io.anuke.mindustry.world.blocks.Wall; import io.anuke.mindustry.world.blocks.Wall;
import io.anuke.mindustry.world.blocks.modules.InventoryModule; import io.anuke.mindustry.world.modules.InventoryModule;
import io.anuke.mindustry.world.blocks.modules.LiquidModule; import io.anuke.mindustry.world.modules.LiquidModule;
import io.anuke.mindustry.world.blocks.modules.PowerModule; import io.anuke.mindustry.world.modules.PowerModule;
import io.anuke.ucore.core.Effects; import io.anuke.ucore.core.Effects;
import io.anuke.ucore.core.Timers; import io.anuke.ucore.core.Timers;
import io.anuke.ucore.entities.EntityGroup; import io.anuke.ucore.entities.EntityGroup;
@@ -42,6 +44,8 @@ public class TileEntity extends BaseEntity implements TargetTrait {
public InventoryModule items; public InventoryModule items;
public LiquidModule liquids; public LiquidModule liquids;
public Array<Consume> consumers = new Array<>();
private boolean dead = false; private boolean dead = false;
private boolean sleeping; private boolean sleeping;
private float sleepTime; private float sleepTime;
@@ -55,14 +59,10 @@ public class TileEntity extends BaseEntity implements TargetTrait {
health = tile.block().health; health = tile.block().health;
timer = new Timer(tile.block().timers); timer = new Timer(tile.block().timers);
tile.block().setConsumers(consumers);
if(added){ if(added){
//if(!tile.block().autoSleep) { //TODO only autosleep when creating a fresh block! add();
add();
/*}else{
sleeping = true;
sleepingEntities ++;
}*/
} }
return this; return this;
@@ -160,6 +160,9 @@ public class TileEntity extends BaseEntity implements TargetTrait {
} }
tile.block().update(tile); tile.block().update(tile);
for(Consume cons : consumers){
cons.update(this);
}
} }
} }

View File

@@ -197,6 +197,7 @@ public abstract class Unit extends DestructibleEntity implements SaveTrait, Targ
} }
public void avoidOthers(float avoidRange){ public void avoidOthers(float avoidRange){
if(Net.client()) return;
EntityPhysics.getNearby(getGroup(), x, y, avoidRange*2f, t -> { EntityPhysics.getNearby(getGroup(), x, y, avoidRange*2f, t -> {
if(t == this || (t instanceof Unit && (((Unit) t).isDead() || (((Unit) t).isFlying() != isFlying()) || ((Unit) t).getCarrier() == this) || getCarrier() == t)) return; if(t == this || (t instanceof Unit && (((Unit) t).isDead() || (((Unit) t).isFlying() != isFlying()) || ((Unit) t).getCarrier() == this) || getCarrier() == t)) return;

View File

@@ -57,7 +57,7 @@ public class ItemTransfer extends TimedEntity implements DrawTrait{
for (int i = 0; i < Mathf.clamp(amount/3, 1, 8); i++) { for (int i = 0; i < Mathf.clamp(amount/3, 1, 8); i++) {
Timers.run(i*3, () -> create(item, x, y, tile, () -> {})); Timers.run(i*3, () -> create(item, x, y, tile, () -> {}));
} }
tile.entity.items.addItem(item, amount); tile.entity.items.add(item, amount);
} }
public static void create(Item item, float fromx, float fromy, PosTrait to, Runnable done){ public static void create(Item item, float fromx, float fromy, PosTrait to, Runnable done){

View File

@@ -181,7 +181,7 @@ public class Drone extends FlyingUnit implements BuilderTrait {
if(entity == null){ if(entity == null){
return; return;
} }
targetItem = Mathf.findMin(toMine, (a, b) -> -Integer.compare(entity.items.getItem(a), entity.items.getItem(b))); targetItem = Mathf.findMin(toMine, (a, b) -> -Integer.compare(entity.items.get(a), entity.items.get(b)));
} }
protected boolean findItemDrop(){ protected boolean findItemDrop(){
@@ -247,7 +247,7 @@ public class Drone extends FlyingUnit implements BuilderTrait {
//if it's missing requirements, try and mine them //if it's missing requirements, try and mine them
for(ItemStack stack : entity.recipe.requirements){ for(ItemStack stack : entity.recipe.requirements){
if(!core.items.hasItem(stack.item, stack.amount) && toMine.contains(stack.item)){ if(!core.items.has(stack.item, stack.amount) && toMine.contains(stack.item)){
targetItem = stack.item; targetItem = stack.item;
getPlaceQueue().clear(); getPlaceQueue().clear();
setState(mine); setState(mine);

View File

@@ -32,7 +32,6 @@ public class DefaultKeybinds {
"menu", Gdx.app.getType() == ApplicationType.Android ? Input.BACK : Input.ESCAPE, "menu", Gdx.app.getType() == ApplicationType.Android ? Input.BACK : Input.ESCAPE,
"pause", Input.SPACE, "pause", Input.SPACE,
"toggle_menus", Input.C, "toggle_menus", Input.C,
"item_withdraw", Input.SHIFT_LEFT,
new Category("Multiplayer"), new Category("Multiplayer"),
"player_list", Input.TAB, "player_list", Input.TAB,
"chat", Input.ENTER, "chat", Input.ENTER,

View File

@@ -129,7 +129,7 @@ public abstract class InputHandler extends InputAdapter{
//consume tap event if necessary //consume tap event if necessary
if(tile.getTeam() == player.getTeam() && tile.block().consumesTap){ if(tile.getTeam() == player.getTeam() && tile.block().consumesTap){
consumed = true; consumed = true;
}else if(tile.getTeam() == player.getTeam() && tile.block().synthetic() && tile.block().hasItems && !consumed){ }else if(tile.getTeam() == player.getTeam() && tile.block().synthetic() && tile.block().hasItems && tile.entity.items.total() > 0 && !consumed){
frag.inv.showFor(tile); frag.inv.showFor(tile);
consumed = true; consumed = true;
showedInventory = true; showedInventory = true;

View File

@@ -16,7 +16,6 @@ import io.anuke.mindustry.type.Item;
import io.anuke.mindustry.ui.ItemImage; import io.anuke.mindustry.ui.ItemImage;
import io.anuke.mindustry.world.Tile; import io.anuke.mindustry.world.Tile;
import io.anuke.ucore.core.Graphics; import io.anuke.ucore.core.Graphics;
import io.anuke.ucore.core.Inputs;
import io.anuke.ucore.core.Timers; import io.anuke.ucore.core.Timers;
import io.anuke.ucore.function.BooleanProvider; import io.anuke.ucore.function.BooleanProvider;
import io.anuke.ucore.scene.Group; import io.anuke.ucore.scene.Group;
@@ -29,9 +28,7 @@ import io.anuke.ucore.scene.ui.layout.Table;
import io.anuke.ucore.util.Mathf; import io.anuke.ucore.util.Mathf;
import io.anuke.ucore.util.Strings; import io.anuke.ucore.util.Strings;
import static io.anuke.mindustry.Vars.mobile; import static io.anuke.mindustry.Vars.*;
import static io.anuke.mindustry.Vars.state;
import static io.anuke.mindustry.Vars.tilesize;
public class BlockInventoryFragment extends Fragment { public class BlockInventoryFragment extends Fragment {
private final static float holdWithdraw = 40f; private final static float holdWithdraw = 40f;
@@ -58,7 +55,7 @@ public class BlockInventoryFragment extends Fragment {
public void showFor(Tile t){ public void showFor(Tile t){
this.tile = t.target(); this.tile = t.target();
if(tile == null || tile.entity == null || !tile.block().isAccessible() || tile.entity.items.totalItems() == 0) return; if(tile == null || tile.entity == null || !tile.block().isAccessible() || tile.entity.items.total() == 0) return;
rebuild(true); rebuild(true);
} }
@@ -80,14 +77,14 @@ public class BlockInventoryFragment extends Fragment {
table.background("inventory"); table.background("inventory");
table.setTouchable(Touchable.enabled); table.setTouchable(Touchable.enabled);
table.update(() -> { table.update(() -> {
if(tile == null || tile.entity == null || !tile.block().isAccessible() || tile.entity.items.totalItems() == 0){ if(tile == null || tile.entity == null || !tile.block().isAccessible() || tile.entity.items.total() == 0){
hide(); hide();
}else{ }else{
if(holding && lastItem != null){ if(holding && lastItem != null){
holdTime += Timers.delta(); holdTime += Timers.delta();
if(holdTime >= holdWithdraw){ if(holdTime >= holdWithdraw){
int amount = Math.min(tile.entity.items.getItem(lastItem), player.inventory.itemCapacityUsed(lastItem)); int amount = Math.min(tile.entity.items.get(lastItem), player.inventory.itemCapacityUsed(lastItem));
CallBlocks.requestItem(player, tile, lastItem, amount); CallBlocks.requestItem(player, tile, lastItem, amount);
holding = false; holding = false;
holdTime = 0f; holdTime = 0f;
@@ -96,9 +93,8 @@ public class BlockInventoryFragment extends Fragment {
updateTablePosition(); updateTablePosition();
if(tile.block().hasItems) { if(tile.block().hasItems) {
int[] items = tile.entity.items.items; for (int i = 0; i < Item.all().size; i++) {
for (int i = 0; i < items.length; i++) { if ((tile.entity.items.has(Item.getByID(i))) == container.contains(i)) {
if ((items[i] == 0) == container.contains(i)) {
rebuild(false); rebuild(false);
} }
} }
@@ -113,12 +109,10 @@ public class BlockInventoryFragment extends Fragment {
table.defaults().size(mobile ? 16*3 : 16*2).space(6f); table.defaults().size(mobile ? 16*3 : 16*2).space(6f);
if(tile.block().hasItems) { if(tile.block().hasItems) {
int[] items = tile.entity.items.items;
for (int i = 0; i < items.length; i++) { for (int i = 0; i < Item.all().size; i++) {
final int f = i;
if (items[i] == 0) continue;
Item item = Item.getByID(i); Item item = Item.getByID(i);
if (!tile.entity.items.has(item)) continue;
container.add(i); container.add(i);
@@ -127,14 +121,14 @@ public class BlockInventoryFragment extends Fragment {
HandCursorListener l = new HandCursorListener(); HandCursorListener l = new HandCursorListener();
l.setEnabled(canPick); l.setEnabled(canPick);
ItemImage image = new ItemImage(item.region, () -> round(items[f])); ItemImage image = new ItemImage(item.region, () -> round(tile.entity.items.get(item)));
image.addListener(l); image.addListener(l);
image.addListener(new InputListener(){ image.addListener(new InputListener(){
@Override @Override
public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) { public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) {
if(!canPick.get() || items[f] == 0) return false; if(!canPick.get() || !tile.entity.items.has(item)) return false;
int amount = Math.min(Inputs.keyDown("item_withdraw") ? items[f] : 1, player.inventory.itemCapacityUsed(item)); int amount = Math.min(1, player.inventory.itemCapacityUsed(item));
CallBlocks.requestItem(player, tile, item, amount); CallBlocks.requestItem(player, tile, item, amount);
lastItem = item; lastItem = item;
holding = true; holding = true;

View File

@@ -244,7 +244,7 @@ public class BlocksFragment extends Fragment{
if(entity == null) return; if(entity == null) return;
for(ItemStack s : r.requirements){ for(ItemStack s : r.requirements){
if(!entity.items.hasItem(s.item, Mathf.ceil(s.amount))){ if(!entity.items.has(s.item, Mathf.ceil(s.amount))){
istack.setColor(Color.GRAY); istack.setColor(Color.GRAY);
return; return;
} }
@@ -328,7 +328,7 @@ public class BlocksFragment extends Fragment{
TileEntity core = players[0].getClosestCore(); TileEntity core = players[0].getClosestCore();
if(core == null) return "*/*"; if(core == null) return "*/*";
int amount = core.items.getItem(stack.item); int amount = core.items.get(stack.item);
String color = (amount < stack.amount/2f ? "[red]" : amount < stack.amount ? "[orange]" : "[white]"); String color = (amount < stack.amount/2f ? "[red]" : amount < stack.amount ? "[orange]" : "[white]");
return color + format(amount) + "[white]/" + stack.amount; return color + format(amount) + "[white]/" + stack.amount;

View File

@@ -31,20 +31,20 @@ public abstract class BaseBlock {
} }
public int getMaximumAccepted(Tile tile, Item item){ public int getMaximumAccepted(Tile tile, Item item){
return itemCapacity - tile.entity.items.totalItems(); return itemCapacity - tile.entity.items.total();
} }
/**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.wakeUp(); tile.entity.wakeUp();
tile.entity.items.removeItem(item, amount); tile.entity.items.remove(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.wakeUp(); tile.entity.wakeUp();
tile.entity.items.addItem(item, amount); tile.entity.items.add(item, amount);
} }
/**Returns offset for stack placement.*/ /**Returns offset for stack placement.*/
@@ -53,7 +53,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.items.addItem(item, 1); tile.entity.items.add(item, 1);
} }
public boolean acceptItem(Item item, Tile tile, Tile source){ public boolean acceptItem(Item item, Tile tile, Tile source){
@@ -61,17 +61,11 @@ 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.liquids.amount + amount < liquidCapacity return tile.entity.liquids.get(liquid) + amount < liquidCapacity;
&& (tile.entity.liquids.liquid == liquid || tile.entity.liquids.amount <= 0.1f);
}
public float handleAuxLiquid(Tile tile, Tile source, Liquid liquid, float amount){
return 0f;
} }
public void handleLiquid(Tile tile, Tile source, Liquid liquid, float amount){ public void handleLiquid(Tile tile, Tile source, Liquid liquid, float amount){
tile.entity.liquids.liquid = liquid; tile.entity.liquids.add(liquid, amount);
tile.entity.liquids.amount += amount;
} }
public boolean acceptPower(Tile tile, Tile source, float amount){ public boolean acceptPower(Tile tile, Tile source, float amount){
@@ -87,9 +81,7 @@ public abstract class BaseBlock {
return canAccept; return canAccept;
} }
public void tryDumpLiquid(Tile tile){ public void tryDumpLiquid(Tile tile, Liquid liquid){
if(tile.entity.liquids.amount < 0.001f) return;
int size = tile.block().size; int size = tile.block().size;
GridPoint2[] nearby = Edges.getEdges(size); GridPoint2[] nearby = Edges.getEdges(size);
@@ -102,10 +94,10 @@ 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.liquids.amount / other.block().liquidCapacity; float ofract = other.entity.liquids.get(liquid) / other.block().liquidCapacity;
float fract = tile.entity.liquids.amount / liquidCapacity; float fract = tile.entity.liquids.get(liquid) / liquidCapacity;
if(ofract < fract) tryMoveLiquid(tile, in, other, (fract - ofract) * liquidCapacity / 2f); if(ofract < fract) tryMoveLiquid(tile, in, other, (fract - ofract) * liquidCapacity / 2f, liquid);
} }
i = (byte) ((i + 1) % nearby.length); i = (byte) ((i + 1) % nearby.length);
@@ -113,35 +105,34 @@ 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, Liquid liquid){
float flow = Math.min(next.block().liquidCapacity - next.entity.liquids.amount - 0.001f, amount); float flow = Math.min(next.block().liquidCapacity - next.entity.liquids.get(liquid) - 0.001f, amount);
if(next.block().acceptLiquid(next, tileSource, tile.entity.liquids.liquid, flow)){ if(next.block().acceptLiquid(next, tileSource, liquid, flow)){
next.block().handleLiquid(next, tileSource, tile.entity.liquids.liquid, flow); next.block().handleLiquid(next, tileSource, liquid, flow);
tile.entity.liquids.amount -= flow; tile.entity.liquids.remove(liquid, flow);
} }
} }
public float tryMoveLiquid(Tile tile, Tile next, boolean leak){ public float tryMoveLiquid(Tile tile, Tile next, boolean leak, Liquid liquid){
if(next == null) return 0; if(next == null) return 0;
next = next.target(); next = next.target();
if(next.block().hasLiquids && tile.entity.liquids.amount > 0f){ if(next.block().hasLiquids && tile.entity.liquids.get(liquid) > 0f){
if((next.entity.liquids.liquid == tile.entity.liquids.liquid || next.entity.liquids.amount <= 0.01f) && if(next.block().acceptLiquid(next, tile, liquid, 0f)) {
next.block().acceptLiquid(next, tile, tile.entity.liquids.liquid, 0f)) { float ofract = next.entity.liquids.get(liquid) / next.block().liquidCapacity;
float ofract = next.entity.liquids.amount / next.block().liquidCapacity; float fract = tile.entity.liquids.get(liquid) / liquidCapacity;
float fract = tile.entity.liquids.amount / liquidCapacity; float flow = Math.min(Mathf.clamp((fract - ofract) * (1f)) * (liquidCapacity), tile.entity.liquids.get(liquid));
float flow = Math.min(Mathf.clamp((fract - ofract) * (1f)) * (liquidCapacity), tile.entity.liquids.amount); flow = Math.min(flow, next.block().liquidCapacity - next.entity.liquids.get(liquid) - 0.001f);
flow = Math.min(flow, next.block().liquidCapacity - next.entity.liquids.amount - 0.001f);
if (flow > 0f && ofract <= fract && next.block().acceptLiquid(next, tile, tile.entity.liquids.liquid, flow)) { if (flow > 0f && ofract <= fract && next.block().acceptLiquid(next, tile, liquid, flow)) {
next.block().handleLiquid(next, tile, tile.entity.liquids.liquid, flow); next.block().handleLiquid(next, tile, liquid, flow);
tile.entity.liquids.amount -= flow; tile.entity.liquids.remove(liquid, flow);
return flow; return flow;
} else if (ofract > 0.1f && fract > 0.1f) { } else if (ofract > 0.1f && fract > 0.1f) {
Liquid liquid = tile.entity.liquids.liquid, other = next.entity.liquids.liquid; Liquid other = next.entity.liquids.current();
if ((other.flammability > 0.3f && liquid.temperature > 0.7f) || if ((other.flammability > 0.3f && liquid.temperature > 0.7f) ||
(liquid.flammability > 0.3f && other.temperature > 0.7f)) { (liquid.flammability > 0.3f && other.temperature > 0.7f)) {
tile.entity.damage(1 * Timers.delta()); tile.entity.damage(1 * Timers.delta());
@@ -151,20 +142,17 @@ public abstract class BaseBlock {
} }
} else if ((liquid.temperature > 0.7f && other.temperature < 0.55f) || } else if ((liquid.temperature > 0.7f && other.temperature < 0.55f) ||
(other.temperature > 0.7f && liquid.temperature < 0.55f)) { (other.temperature > 0.7f && liquid.temperature < 0.55f)) {
tile.entity.liquids.amount -= Math.min(tile.entity.liquids.amount, 0.7f * Timers.delta()); tile.entity.liquids.remove(liquid, Math.min(tile.entity.liquids.get(liquid), 0.7f * Timers.delta()));
if (Mathf.chance(0.2f * Timers.delta())) { if (Mathf.chance(0.2f * Timers.delta())) {
Effects.effect(EnvironmentFx.steam, (tile.worldx() + next.worldx()) / 2f, (tile.worldy() + next.worldy()) / 2f); Effects.effect(EnvironmentFx.steam, (tile.worldx() + next.worldx()) / 2f, (tile.worldy() + next.worldy()) / 2f);
} }
} }
} }
}else{
float accepted = next.block().handleAuxLiquid(next, tile, tile.entity.liquids.liquid, tile.entity.liquids.amount);
tile.entity.liquids.amount -= accepted;
} }
}else if(leak && !next.block().solid && !next.block().hasLiquids){ }else if(leak && !next.block().solid && !next.block().hasLiquids){
float leakAmount = Math.min(tile.entity.liquids.amount, tile.entity.liquids.amount/1.5f); float leakAmount = tile.entity.liquids.get(liquid)/1.5f;
Puddle.deposit(next, tile, tile.entity.liquids.liquid, leakAmount); Puddle.deposit(next, tile, liquid, leakAmount);
tile.entity.liquids.amount -= leakAmount; tile.entity.liquids.remove(liquid, leakAmount);
} }
return 0; return 0;
} }
@@ -198,7 +186,7 @@ public abstract class BaseBlock {
/**Try dumping a specific item near the tile.*/ /**Try dumping a specific item near the tile.*/
public boolean tryDump(Tile tile, Item todump){ public boolean tryDump(Tile tile, Item todump){
if(tile.entity == null || !hasItems) return false; if(tile.entity == null || !hasItems || tile.entity.items.total() == 0) return false;
int size = tile.block().size; int size = tile.block().size;
@@ -216,9 +204,9 @@ public abstract class BaseBlock {
if(todump != null && item != todump) continue; if(todump != null && item != todump) continue;
if(tile.entity.items.hasItem(item) && other != null && other.block().acceptItem(item, other, in) && canDump(tile, other, item)){ if(tile.entity.items.has(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.items.removeItem(item, 1); tile.entity.items.remove(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

@@ -5,7 +5,6 @@ import com.badlogic.gdx.graphics.g2d.TextureRegion;
import com.badlogic.gdx.utils.Array; import com.badlogic.gdx.utils.Array;
import com.badlogic.gdx.utils.ObjectMap; import com.badlogic.gdx.utils.ObjectMap;
import com.badlogic.gdx.utils.reflect.ClassReflection; import com.badlogic.gdx.utils.reflect.ClassReflection;
import io.anuke.mindustry.core.GameState.State;
import io.anuke.mindustry.entities.Damage; import io.anuke.mindustry.entities.Damage;
import io.anuke.mindustry.entities.Player; import io.anuke.mindustry.entities.Player;
import io.anuke.mindustry.entities.TileEntity; import io.anuke.mindustry.entities.TileEntity;
@@ -20,7 +19,7 @@ import io.anuke.mindustry.graphics.Palette;
import io.anuke.mindustry.input.CursorType; import io.anuke.mindustry.input.CursorType;
import io.anuke.mindustry.type.Item; import io.anuke.mindustry.type.Item;
import io.anuke.mindustry.type.ItemStack; import io.anuke.mindustry.type.ItemStack;
import io.anuke.mindustry.type.Liquid; import io.anuke.mindustry.world.consumers.Consume;
import io.anuke.mindustry.world.meta.*; import io.anuke.mindustry.world.meta.*;
import io.anuke.ucore.core.Timers; import io.anuke.ucore.core.Timers;
import io.anuke.ucore.graphics.Draw; import io.anuke.ucore.graphics.Draw;
@@ -31,7 +30,8 @@ import io.anuke.ucore.util.Bundles;
import io.anuke.ucore.util.EnumSet; import io.anuke.ucore.util.EnumSet;
import io.anuke.ucore.util.Mathf; import io.anuke.ucore.util.Mathf;
import static io.anuke.mindustry.Vars.*; import static io.anuke.mindustry.Vars.tilesize;
import static io.anuke.mindustry.Vars.world;
public class Block extends BaseBlock implements Content{ public class Block extends BaseBlock implements Content{
private static int lastid; private static int lastid;
@@ -46,6 +46,9 @@ public class Block extends BaseBlock implements Content{
protected TextureRegion[] compactIcon; protected TextureRegion[] compactIcon;
protected TextureRegion editorIcon; protected TextureRegion editorIcon;
protected TextureRegion shadowRegion;
protected TextureRegion region;
/**internal name*/ /**internal name*/
public final String name; public final String name;
/**internal ID*/ /**internal ID*/
@@ -72,12 +75,8 @@ public class Block extends BaseBlock implements Content{
public int health = -1; public int health = -1;
/**base block explosiveness*/ /**base block explosiveness*/
public float baseExplosiveness = 0f; public float baseExplosiveness = 0f;
/**whether to display a different shadow per variant*/
public boolean varyShadow = false;
/**whether this block can be placed on liquids.*/ /**whether this block can be placed on liquids.*/
public boolean floating = true; public boolean floating = true;
/**number of block variants, 0 to disable*/
public int variants = 0;
/**stuff that drops when broken*/ /**stuff that drops when broken*/
public ItemStack drops = null; public ItemStack drops = null;
/**multiblock size*/ /**multiblock size*/
@@ -110,10 +109,6 @@ public class Block extends BaseBlock implements Content{
public boolean autoSleep; public boolean autoSleep;
/**Name of shadow region to load. Null to indicate normal shadow.*/ /**Name of shadow region to load. Null to indicate normal shadow.*/
public String shadow = null; public String shadow = null;
/**Region used for drawing shadows.*/
public TextureRegion shadowRegion;
/**Texture region array for drawing multiple shadows.*/
public TextureRegion[] shadowRegions;
/**Whether the block can be tapped and selected to configure.*/ /**Whether the block can be tapped and selected to configure.*/
public boolean configurable; public boolean configurable;
/**Whether this block consumes touchDown events when tapped.*/ /**Whether this block consumes touchDown events when tapped.*/
@@ -138,6 +133,10 @@ public class Block extends BaseBlock implements Content{
blocks.add(this); blocks.add(this);
} }
public void setConsumers(Array<Consume> consumers){
}
public boolean isLayer(Tile tile){return true;} public boolean isLayer(Tile tile){return true;}
public boolean isLayer2(Tile tile){return true;} public boolean isLayer2(Tile tile){return true;}
public void drawLayer(Tile tile){} public void drawLayer(Tile tile){}
@@ -173,13 +172,7 @@ public class Block extends BaseBlock implements Content{
@Override @Override
public void load() { public void load() {
shadowRegion = Draw.region(shadow == null ? "shadow-" + size : shadow); shadowRegion = Draw.region(shadow == null ? "shadow-" + size : shadow);
region = Draw.region(name);
if(varyShadow && variants > 0) {
shadowRegions = new TextureRegion[variants];
for(int i = 0; i < variants; i ++){
shadowRegions[i] = Draw.region(name + "shadow" + (i + 1));
}
}
} }
/**Called when the block is tapped.*/ /**Called when the block is tapped.*/
@@ -236,8 +229,8 @@ public class Block extends BaseBlock implements Content{
//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.liquids.amount / liquidCapacity)); if(hasLiquids) bars.add(new BlockBar(BarType.liquid, true, tile -> tile.entity.liquids.total() / liquidCapacity));
if(hasItems) bars.add(new BlockBar(BarType.inventory, true, tile -> (float)tile.entity.items.totalItems() / itemCapacity)); if(hasItems) bars.add(new BlockBar(BarType.inventory, true, tile -> (float)tile.entity.items.total() / itemCapacity));
} }
public String name(){ public String name(){
@@ -276,14 +269,13 @@ public class Block extends BaseBlock implements Content{
float x = tile.worldx(), y = tile.worldy(); float x = tile.worldx(), y = tile.worldy();
float explosiveness = baseExplosiveness; float explosiveness = baseExplosiveness;
float flammability = 0f; float flammability = 0f;
float heat = 0f;
float power = 0f; float power = 0f;
int units = 1; int units = 1;
tempColor.set(Palette.darkFlame); tempColor.set(Palette.darkFlame);
if(hasItems){ if(hasItems){
for(Item item : Item.all()){ for(Item item : Item.all()){
int amount = tile.entity.items.getItem(item); int amount = tile.entity.items.get(item);
explosiveness += item.explosiveness*amount; explosiveness += item.explosiveness*amount;
flammability += item.flammability*amount; flammability += item.flammability*amount;
@@ -295,15 +287,8 @@ public class Block extends BaseBlock implements Content{
} }
if(hasLiquids){ if(hasLiquids){
float amount = tile.entity.liquids.amount; flammability += tile.entity.liquids.sum((liquid, amount) -> liquid.explosiveness * amount/2f);
explosiveness += tile.entity.liquids.liquid.explosiveness*amount/2f; explosiveness += tile.entity.liquids.sum((liquid, amount) -> liquid.flammability * 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.liquids.liquid.flammability*amount > 2f){
units ++;
Hue.addu(tempColor, tile.entity.liquids.liquid.flameColor);
}
} }
if(hasPower){ if(hasPower){
@@ -314,17 +299,18 @@ public class Block extends BaseBlock implements Content{
if(hasLiquids) { if(hasLiquids) {
Liquid liquid = tile.entity.liquids.liquid; tile.entity.liquids.forEach((liquid, amount) -> {
float splash = Mathf.clamp(tile.entity.liquids.amount / 4f, 0f, 10f); float splash = Mathf.clamp(amount / 4f, 0f, 10f);
for (int i = 0; i < Mathf.clamp(tile.entity.liquids.amount / 5, 0, 30); i++) { for (int i = 0; i < Mathf.clamp(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) {
Puddle.deposit(other, liquid, splash); Puddle.deposit(other, liquid, splash);
} }
}); });
} }
});
} }
Damage.dynamicExplosion(x, y, flammability, explosiveness, power, tilesize * size/2f, tempColor); Damage.dynamicExplosion(x, y, flammability, explosiveness, power, tilesize * size/2f, tempColor);
@@ -342,14 +328,12 @@ public class Block extends BaseBlock implements Content{
} }
return 0; return 0;
}else{ }else{
float result = 0f; float result = tile.entity.items.sum((item, amount) -> item.flammability * amount);
for (int i = 0; i < Item.all().size; i++) {
int amount = tile.entity.items.items[i];
result += Item.getByID(i).flammability*amount;
}
if(hasLiquids){ if(hasLiquids){
result += tile.entity.liquids.amount * tile.entity.liquids.liquid.flammability/3f; result += tile.entity.liquids.sum((liquid, amount) -> liquid.flammability * amount/3f);
} }
return result; return result;
} }
} }
@@ -411,30 +395,13 @@ public class Block extends BaseBlock implements Content{
} }
public void draw(Tile tile){ public void draw(Tile tile){
//note: multiblocks do not support rotation Draw.rect(region, tile.drawx(), tile.drawy(), rotate ? tile.getRotation() * 90 : 0);
if(!isMultiblock()){
Draw.rect(variants > 0 ? (name() + Mathf.randomSeed(tile.id(), 1, variants)) : name(),
tile.worldx(), tile.worldy(), rotate ? tile.getRotation() * 90 : 0);
}else{
//if multiblock, make sure to draw even block sizes offset, since the core block is at the BOTTOM LEFT
Draw.rect(name(), tile.drawx(), tile.drawy());
}
//update the tile entity through the draw method, only if it's an entity without updating
if(destructible && !update && !state.is(State.paused)){
tile.entity.update();
}
} }
public void drawNonLayer(Tile tile){} public void drawNonLayer(Tile tile){}
public void drawShadow(Tile tile){ public void drawShadow(Tile tile){
Draw.rect(shadowRegion, tile.drawx(), tile.drawy());
if(shadowRegions != null) {
Draw.rect(shadowRegions[(Mathf.randomSeed(tile.id(), 0, variants - 1))], tile.worldx(), tile.worldy());
}else if(shadowRegion != null){
Draw.rect(shadowRegion, tile.drawx(), tile.drawy());
}
} }
/**Offset for placing and drawing multiblocks.*/ /**Offset for placing and drawing multiblocks.*/
@@ -456,7 +423,7 @@ public class Block extends BaseBlock implements Content{
"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", hasItems ? tile.entity.items.totalItems() : null "entity.items.total", hasItems ? tile.entity.items.total() : null
); );
} }

View File

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

View File

@@ -10,9 +10,9 @@ import io.anuke.mindustry.entities.traits.TargetTrait;
import io.anuke.mindustry.game.Team; import io.anuke.mindustry.game.Team;
import io.anuke.mindustry.type.Recipe; import io.anuke.mindustry.type.Recipe;
import io.anuke.mindustry.world.blocks.Floor; import io.anuke.mindustry.world.blocks.Floor;
import io.anuke.mindustry.world.blocks.modules.InventoryModule; import io.anuke.mindustry.world.modules.InventoryModule;
import io.anuke.mindustry.world.blocks.modules.LiquidModule; import io.anuke.mindustry.world.modules.LiquidModule;
import io.anuke.mindustry.world.blocks.modules.PowerModule; import io.anuke.mindustry.world.modules.PowerModule;
import io.anuke.ucore.entities.trait.PosTrait; import io.anuke.ucore.entities.trait.PosTrait;
import io.anuke.ucore.function.Consumer; import io.anuke.ucore.function.Consumer;
import io.anuke.ucore.util.Bits; import io.anuke.ucore.util.Bits;

View File

@@ -1,30 +0,0 @@
package io.anuke.mindustry.world.blocks;
import io.anuke.mindustry.world.Block;
import io.anuke.mindustry.world.Tile;
import io.anuke.ucore.graphics.Draw;
import io.anuke.ucore.function.Predicate;
import io.anuke.ucore.util.Mathf;
public class BlendBlock extends Block{
protected String edge;
protected Predicate<Block> blend = block -> block == this;
public BlendBlock(String name) {
super(name);
edge = name + "-edge";
}
@Override
public void draw(Tile tile){
Draw.rect(variants > 0 ? (name() + Mathf.randomSeed(tile.id(), 1, variants)) : name(),
tile.worldx(), tile.worldy());
for(int i = 0; i < 4; i ++){
Tile near = tile.getNearby(i);
if(near != null && !blend.test(near.block())){
Draw.rect(edge + "-" + i, tile.worldx(), tile.worldy());
}
}
}
}

View File

@@ -22,7 +22,7 @@ import io.anuke.mindustry.type.Recipe;
import io.anuke.mindustry.world.BarType; import io.anuke.mindustry.world.BarType;
import io.anuke.mindustry.world.Block; import io.anuke.mindustry.world.Block;
import io.anuke.mindustry.world.Tile; import io.anuke.mindustry.world.Tile;
import io.anuke.mindustry.world.blocks.modules.InventoryModule; import io.anuke.mindustry.world.modules.InventoryModule;
import io.anuke.mindustry.world.meta.BlockBar; import io.anuke.mindustry.world.meta.BlockBar;
import io.anuke.ucore.core.Effects; import io.anuke.ucore.core.Effects;
import io.anuke.ucore.core.Graphics; import io.anuke.ucore.core.Graphics;
@@ -157,11 +157,10 @@ public class BuildBlock extends Block {
} }
@Remote(called = Loc.server, in = In.blocks) @Remote(called = Loc.server, in = In.blocks)
public static void onConstructFinish(Tile tile, Block block, int builderID, byte rotation){ public static void onConstructFinish(Tile tile, Block block, int builderID, byte rotation, Team team){
Team team = tile.getTeam();
tile.setBlock(block); tile.setBlock(block);
tile.setTeam(team);
tile.setRotation(rotation); tile.setRotation(rotation);
tile.setTeam(team);
Effects.effect(Fx.placeBlock, tile.drawx(), tile.drawy(), block.size); Effects.effect(Fx.placeBlock, tile.drawx(), tile.drawy(), block.size);
//last builder was this local client player, call placed() //last builder was this local client player, call placed()
@@ -197,7 +196,7 @@ public class BuildBlock extends Block {
progress = Mathf.clamp(progress + maxProgress); progress = Mathf.clamp(progress + maxProgress);
if(progress >= 1f){ if(progress >= 1f){
CallBlocks.onConstructFinish(tile, recipe.result, builder.getID(), tile.getRotation()); CallBlocks.onConstructFinish(tile, recipe.result, builder.getID(), tile.getRotation(), tile.getTeam());
} }
} }
@@ -233,11 +232,11 @@ public class BuildBlock extends Block {
for(int i = 0; i < recipe.requirements.length; i ++){ for(int i = 0; i < recipe.requirements.length; i ++){
int required = (int)(accumulator[i]); //calculate items that are required now int required = (int)(accumulator[i]); //calculate items that are required now
if(inventory.getItem(recipe.requirements[i].item) == 0){ if(inventory.get(recipe.requirements[i].item) == 0){
maxProgress = 0f; maxProgress = 0f;
}else if(required > 0){ //if this amount is positive... }else if(required > 0){ //if this amount is positive...
//calculate how many items it can actually use //calculate how many items it can actually use
int maxUse = Math.min(required, inventory.getItem(recipe.requirements[i].item)); int maxUse = Math.min(required, inventory.get(recipe.requirements[i].item));
//get this as a fraction //get this as a fraction
float fraction = maxUse / (float)required; float fraction = maxUse / (float)required;
@@ -248,7 +247,7 @@ public class BuildBlock extends Block {
//remove stuff that is actually used //remove stuff that is actually used
if(remove) { if(remove) {
inventory.removeItem(recipe.requirements[i].item, maxUse); inventory.remove(recipe.requirements[i].item, maxUse);
} }
} }
//else, no items are required yet, so just keep going //else, no items are required yet, so just keep going

View File

@@ -35,6 +35,8 @@ public class Floor extends Block{
protected Predicate<Floor> blends = block -> block != this && !block.blendOverride(this); protected Predicate<Floor> blends = block -> block != this && !block.blendOverride(this);
protected boolean blend = true; protected boolean blend = true;
/**number of different variant regions to use*/
public int variants = 0;
/**edge fallback, used mainly for ores*/ /**edge fallback, used mainly for ores*/
public String edge = "stone"; public String edge = "stone";
/**Multiplies unit velocity by this when walked on.*/ /**Multiplies unit velocity by this when walked on.*/

View File

@@ -4,11 +4,11 @@ import com.badlogic.gdx.graphics.g2d.TextureRegion;
import io.anuke.mindustry.world.Block; import io.anuke.mindustry.world.Block;
import io.anuke.mindustry.world.meta.BlockGroup; import io.anuke.mindustry.world.meta.BlockGroup;
import io.anuke.mindustry.world.Tile; import io.anuke.mindustry.world.Tile;
import io.anuke.mindustry.world.blocks.modules.LiquidModule; import io.anuke.mindustry.world.modules.LiquidModule;
import io.anuke.ucore.graphics.Draw; import io.anuke.ucore.graphics.Draw;
public class LiquidBlock extends Block{ public class LiquidBlock extends Block{
protected String liquidRegion = name() + "-liquid"; protected TextureRegion liquidRegion, bottomRegion, topRegion;
public LiquidBlock(String name) { public LiquidBlock(String name) {
super(name); super(name);
@@ -18,6 +18,15 @@ public class LiquidBlock extends Block{
group = BlockGroup.liquids; group = BlockGroup.liquids;
} }
@Override
public void load() {
super.load();
liquidRegion = Draw.region(name + "-liquid");
topRegion = Draw.region(name + "-top");
bottomRegion = Draw.region(name + "-bottom");
}
@Override @Override
public TextureRegion[] getIcon(){ public TextureRegion[] getIcon(){
return new TextureRegion[]{Draw.region(name() + "-bottom"), Draw.region(name() + "-top")}; return new TextureRegion[]{Draw.region(name() + "-bottom"), Draw.region(name() + "-top")};
@@ -29,15 +38,15 @@ public class LiquidBlock extends Block{
int rotation = rotate ? tile.getRotation() * 90 : 0; int rotation = rotate ? tile.getRotation() * 90 : 0;
Draw.rect(name() + "-bottom", tile.drawx(), tile.drawy(), rotation); Draw.rect(bottomRegion, tile.drawx(), tile.drawy(), rotation);
if(mod.amount > 0.001f){ if(mod.total() > 0.001f){
Draw.color(mod.liquid.color); Draw.color(mod.current().color);
Draw.alpha(mod.amount / liquidCapacity); Draw.alpha(mod.total() / liquidCapacity);
Draw.rect(liquidRegion, tile.drawx(), tile.drawy(), rotation); Draw.rect(liquidRegion, tile.drawx(), tile.drawy(), rotation);
Draw.color(); Draw.color();
} }
Draw.rect(name() + "-top", tile.drawx(), tile.drawy(), rotation); Draw.rect(topRegion, tile.drawx(), tile.drawy(), rotation);
} }
} }

View File

@@ -1,13 +1,51 @@
package io.anuke.mindustry.world.blocks; package io.anuke.mindustry.world.blocks;
import com.badlogic.gdx.graphics.g2d.TextureRegion;
import io.anuke.mindustry.world.Block; import io.anuke.mindustry.world.Block;
import io.anuke.mindustry.world.Tile;
import io.anuke.ucore.graphics.Draw;
import io.anuke.ucore.util.Mathf;
public class Rock extends Block { public class Rock extends Block {
protected TextureRegion[] shadowRegions, regions;
protected int variants;
public Rock(String name) { public Rock(String name) {
super(name); super(name);
varyShadow = true;
breakable = true; breakable = true;
alwaysReplace = true; alwaysReplace = true;
} }
@Override
public void draw(Tile tile) {
if(variants > 0){
Draw.rect(regions[Mathf.randomSeed(tile.id(), 0, Math.max(0, regions.length-1))], tile.worldx(), tile.worldy());
}else{
Draw.rect(region, tile.worldx(), tile.worldy());
}
}
@Override
public void drawShadow(Tile tile) {
if(shadowRegions != null) {
Draw.rect(shadowRegions[(Mathf.randomSeed(tile.id(), 0, variants - 1))], tile.worldx(), tile.worldy());
}else if(shadowRegion != null){
Draw.rect(shadowRegion, tile.drawx(), tile.drawy());
}
}
@Override
public void load() {
super.load();
if(variants > 0){
shadowRegions = new TextureRegion[variants];
regions = new TextureRegion[variants];
for (int i = 0; i < variants; i++) {
shadowRegions[i] = Draw.region(name + "-shadow" + (i+1));
regions[i] = Draw.region(name + (i+1));
}
}
}
} }

View File

@@ -45,7 +45,7 @@ public class Door extends Wall{
DoorEntity entity = tile.entity(); DoorEntity entity = tile.entity();
if(!entity.open){ if(!entity.open){
Draw.rect(name, tile.drawx(), tile.drawy()); Draw.rect(region, tile.drawx(), tile.drawy());
}else{ }else{
Draw.rect(openRegion, tile.drawx(), tile.drawy()); Draw.rect(openRegion, tile.drawx(), tile.drawy());
} }

View File

@@ -38,17 +38,18 @@ public class CooledTurret extends Turret {
super.updateShooting(tile); super.updateShooting(tile);
TurretEntity entity = tile.entity(); TurretEntity entity = tile.entity();
Liquid liquid = entity.liquids.current();
float used = Math.min(Math.min(entity.liquids.amount, maxUsed * Timers.delta()), Math.max(0, ((reload - entity.reload) / coolantMultiplier) / entity.liquids.liquid.heatCapacity)); float used = Math.min(Math.min(entity.liquids.get(liquid), maxUsed * Timers.delta()), Math.max(0, ((reload - entity.reload) / coolantMultiplier) / liquid.heatCapacity));
entity.reload += (used * entity.liquids.liquid.heatCapacity) / entity.liquids.liquid.heatCapacity; entity.reload += (used * liquid.heatCapacity) / liquid.heatCapacity;
entity.liquids.amount -= used; entity.liquids.remove(liquid, used);
if(Mathf.chance(0.04 * used)){ if(Mathf.chance(0.04 * used)){
Effects.effect(coolEffect, tile.drawx() + Mathf.range(size * tilesize/2f), tile.drawy() + Mathf.range(size * tilesize/2f)); Effects.effect(coolEffect, tile.drawx() + Mathf.range(size * tilesize/2f), tile.drawy() + Mathf.range(size * tilesize/2f));
} }
//don't use oil as coolant, thanks //don't use oil as coolant, thanks
if(Mathf.chance(entity.liquids.liquid.flammability / 10f * used)){ if(Mathf.chance(liquid.flammability / 10f * used)){
Fire.create(tile); Fire.create(tile);
} }
} }

View File

@@ -60,7 +60,7 @@ public class ItemTurret extends CooledTurret {
AmmoType type = ammoMap.get(item); AmmoType type = ammoMap.get(item);
entity.totalAmmo += type.quantityMultiplier; entity.totalAmmo += type.quantityMultiplier;
entity.items.addItem(item, 1); entity.items.add(item, 1);
//find ammo entry by type //find ammo entry by type
for(int i = 0; i < entity.ammo.size; i ++){ for(int i = 0; i < entity.ammo.size; i ++){

View File

@@ -27,7 +27,10 @@ import io.anuke.ucore.core.Timers;
import io.anuke.ucore.function.BiConsumer; import io.anuke.ucore.function.BiConsumer;
import io.anuke.ucore.graphics.Draw; import io.anuke.ucore.graphics.Draw;
import io.anuke.ucore.graphics.Lines; import io.anuke.ucore.graphics.Lines;
import io.anuke.ucore.util.*; import io.anuke.ucore.util.Angles;
import io.anuke.ucore.util.Mathf;
import io.anuke.ucore.util.ThreadArray;
import io.anuke.ucore.util.Translator;
import java.io.DataInputStream; import java.io.DataInputStream;
import java.io.DataOutputStream; import java.io.DataOutputStream;
@@ -66,8 +69,9 @@ public abstract class Turret extends Block{
protected TextureRegion heatRegion; protected TextureRegion heatRegion;
protected TextureRegion baseTopRegion; protected TextureRegion baseTopRegion;
protected BiConsumer<Tile, TurretEntity> drawer = (tile, entity) -> Draw.rect(name, tile.drawx() + tr2.x, tile.drawy() + tr2.y, entity.rotation - 90); protected BiConsumer<Tile, TurretEntity> drawer = (tile, entity) -> Draw.rect(region, tile.drawx() + tr2.x, tile.drawy() + tr2.y, entity.rotation - 90);
protected BiConsumer<Tile, TurretEntity> heatDrawer = (tile, entity) ->{ protected BiConsumer<Tile, TurretEntity> heatDrawer = (tile, entity) ->{
if(entity.heat <= 0.00001f) return;
Graphics.setAdditiveBlending(); Graphics.setAdditiveBlending();
Draw.color(heatColor); Draw.color(heatColor);
Draw.alpha(entity.heat); Draw.alpha(entity.heat);
@@ -129,7 +133,7 @@ public abstract class Turret extends Block{
drawer.accept(tile, entity); drawer.accept(tile, entity);
if(Draw.hasRegion(name + "-heat")){ if(heatRegion != null){
heatDrawer.accept(tile, entity); heatDrawer.accept(tile, entity);
} }

View File

@@ -26,8 +26,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.items.totalItems() > 0){ if(entity.buffer.accepts() && entity.items.total() > 0){
entity.buffer.accept(entity.items.takeItem()); entity.buffer.accept(entity.items.take());
} }
Item item = entity.buffer.poll(); Item item = entity.buffer.poll();

View File

@@ -5,7 +5,7 @@ import io.anuke.mindustry.entities.TileEntity;
import io.anuke.mindustry.type.Liquid; import io.anuke.mindustry.type.Liquid;
import io.anuke.mindustry.world.Tile; import io.anuke.mindustry.world.Tile;
import io.anuke.mindustry.world.blocks.LiquidBlock; import io.anuke.mindustry.world.blocks.LiquidBlock;
import io.anuke.mindustry.world.blocks.modules.LiquidModule; import io.anuke.mindustry.world.modules.LiquidModule;
import io.anuke.ucore.graphics.Draw; import io.anuke.ucore.graphics.Draw;
import io.anuke.ucore.util.Mathf; import io.anuke.ucore.util.Mathf;
@@ -18,11 +18,17 @@ public class Conduit extends LiquidBlock {
public Conduit(String name) { public Conduit(String name) {
super(name); super(name);
liquidRegion = "conduit-liquid";
rotate = true; rotate = true;
solid = false; solid = false;
} }
@Override
public void load() {
super.load();
liquidRegion = Draw.region("conduit-liquid");
}
@Override @Override
public void draw(Tile tile){ public void draw(Tile tile){
ConduitEntity entity = tile.entity(); ConduitEntity entity = tile.entity();
@@ -30,23 +36,23 @@ public class Conduit extends LiquidBlock {
int rotation = rotate ? tile.getRotation() * 90 : 0; int rotation = rotate ? tile.getRotation() * 90 : 0;
Draw.rect(name() + "-bottom", tile.drawx(), tile.drawy(), rotation); Draw.rect(bottomRegion, tile.drawx(), tile.drawy(), rotation);
Draw.color(mod.liquid.color); Draw.color(mod.current().color);
Draw.alpha(entity.smoothLiquid); Draw.alpha(entity.smoothLiquid);
Draw.rect(liquidRegion, tile.drawx(), tile.drawy(), rotation); Draw.rect(liquidRegion, tile.drawx(), tile.drawy(), rotation);
Draw.color(); Draw.color();
Draw.rect(name() + "-top", tile.drawx(), tile.drawy(), rotation); Draw.rect(topRegion, tile.drawx(), tile.drawy(), rotation);
} }
@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.liquids.amount/liquidCapacity, 0.05f); entity.smoothLiquid = Mathf.lerpDelta(entity.smoothLiquid, entity.liquids.total()/liquidCapacity, 0.05f);
if(tile.entity.liquids.amount > 0.001f && tile.entity.timer.get(timerFlow, 1)){ if(tile.entity.liquids.total() > 0.001f && tile.entity.timer.get(timerFlow, 1)){
tryMoveLiquid(tile, tile.getNearby(tile.getRotation()), true); tryMoveLiquid(tile, tile.getNearby(tile.getRotation()), true, tile.entity.liquids.current());
entity.wakeUp(); entity.wakeUp();
}else{ }else{
entity.sleep(); entity.sleep();
@@ -61,7 +67,8 @@ public class Conduit extends LiquidBlock {
@Override @Override
public boolean acceptLiquid(Tile tile, Tile source, Liquid liquid, float amount) { public boolean acceptLiquid(Tile tile, Tile source, Liquid liquid, float amount) {
tile.entity.wakeUp(); tile.entity.wakeUp();
return super.acceptLiquid(tile, source, liquid, amount) && ((2 + source.relativeTo(tile.x, tile.y)) % 4 != tile.getRotation()); return super.acceptLiquid(tile, source, liquid, amount) && (tile.entity.liquids.current() == liquid || tile.entity.liquids.get(tile.entity.liquids.current()) < 0.01f) &&
((2 + source.relativeTo(tile.x, tile.y)) % 4 != tile.getRotation());
} }
@Override @Override

View File

@@ -189,7 +189,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);
totalMoved = 1f; totalMoved = 1f;
tile.entity.items.removeItem(pos.item, 1); tile.entity.items.remove(pos.item, 1);
} else { } else {
value = pos.pack(); value = pos.pack();
@@ -232,7 +232,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.items.removeItem(item, 1); entity.items.remove(item, 1);
removed ++; removed ++;
break; break;
} }
@@ -258,7 +258,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.items.addItem(item, 1); entity.items.add(item, 1);
entity.wakeUp(); entity.wakeUp();
} }
@@ -285,7 +285,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.items.addItem(item, 1); tile.entity.items.add(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

@@ -33,14 +33,14 @@ public class ExtendingItemBridge extends ItemBridge {
ey *= entity.uptime; ey *= entity.uptime;
Lines.stroke(8f); Lines.stroke(8f);
Lines.line(Draw.region(name + "-bridge"), Lines.line(bridgeRegion,
tile.worldx() + Geometry.d4[i].x*tilesize/2f, tile.worldx() + Geometry.d4[i].x*tilesize/2f,
tile.worldy() + Geometry.d4[i].y*tilesize/2f, tile.worldy() + Geometry.d4[i].y*tilesize/2f,
tile.worldx() + ex, tile.worldx() + ex,
tile.worldy() + ey, CapStyle.none, 0f); tile.worldy() + ey, CapStyle.none, 0f);
Draw.rect(name + "-end", tile.drawx(), tile.drawy(), i*90 + 90); Draw.rect(endRegion, tile.drawx(), tile.drawy(), i*90 + 90);
Draw.rect(name + "-end", Draw.rect(endRegion,
tile.worldx() + ex + Geometry.d4[i].x*tilesize/2f, tile.worldx() + ex + Geometry.d4[i].x*tilesize/2f,
tile.worldy() + ey + Geometry.d4[i].y*tilesize/2f, i*90 + 270); tile.worldy() + ey + Geometry.d4[i].y*tilesize/2f, i*90 + 270);
@@ -52,7 +52,7 @@ public class ExtendingItemBridge extends ItemBridge {
for(int a = 0; a < arrows; a ++){ for(int a = 0; a < arrows; a ++){
Draw.alpha(Mathf.absin(a/(float)arrows - entity.time/100f, 0.1f, 1f) * entity.uptime); Draw.alpha(Mathf.absin(a/(float)arrows - entity.time/100f, 0.1f, 1f) * entity.uptime);
Draw.rect(name + "-arrow", Draw.rect(arrowRegion,
tile.worldx() + Geometry.d4[i].x*(tilesize/2f + a*6f + 2) * entity.uptime, tile.worldx() + Geometry.d4[i].x*(tilesize/2f + a*6f + 2) * entity.uptime,
tile.worldy() + Geometry.d4[i].y*(tilesize/2f + a*6f + 2) * entity.uptime, tile.worldy() + Geometry.d4[i].y*(tilesize/2f + a*6f + 2) * entity.uptime,
i*90f); i*90f);

View File

@@ -1,6 +1,7 @@
package io.anuke.mindustry.world.blocks.distribution; package io.anuke.mindustry.world.blocks.distribution;
import com.badlogic.gdx.graphics.Color; import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.g2d.TextureRegion;
import com.badlogic.gdx.utils.IntArray; import com.badlogic.gdx.utils.IntArray;
import com.badlogic.gdx.utils.IntSet; import com.badlogic.gdx.utils.IntSet;
import com.badlogic.gdx.utils.IntSet.IntSetIterator; import com.badlogic.gdx.utils.IntSet.IntSetIterator;
@@ -38,6 +39,8 @@ public class ItemBridge extends Block {
protected float transportTime = 2f; protected float transportTime = 2f;
protected IntArray removals = new IntArray(); protected IntArray removals = new IntArray();
protected TextureRegion endRegion, bridgeRegion, arrowRegion;
public ItemBridge(String name) { public ItemBridge(String name) {
super(name); super(name);
update = true; update = true;
@@ -50,6 +53,13 @@ public class ItemBridge extends Block {
hasItems = true; hasItems = true;
} }
@Override
public void load() {
endRegion = Draw.region(name + "-end");
bridgeRegion = Draw.region(name + "-bridge");
arrowRegion = Draw.region(name + "-arrow");
}
@Override @Override
public void placed(Tile tile) { public void placed(Tile tile) {
Tile last = world.tile(lastPlaced); Tile last = world.tile(lastPlaced);
@@ -162,13 +172,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.items.takeItem(); Item item = entity.items.take();
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.items.addItem(item, 1); if(item != null) entity.items.add(item, 1);
} }
} }
} }
@@ -185,11 +195,11 @@ public class ItemBridge extends Block {
Draw.color(Color.WHITE, Color.BLACK, Mathf.absin(Timers.time(), 6f, 0.07f)); Draw.color(Color.WHITE, Color.BLACK, Mathf.absin(Timers.time(), 6f, 0.07f));
Draw.alpha(Math.max(entity.uptime, 0.25f)); Draw.alpha(Math.max(entity.uptime, 0.25f));
Draw.rect(name + "-end", tile.drawx(), tile.drawy(), i*90 + 90); Draw.rect(endRegion, tile.drawx(), tile.drawy(), i*90 + 90);
Draw.rect(name + "-end", other.drawx(), other.drawy(), i*90 + 270); Draw.rect(endRegion, other.drawx(), other.drawy(), i*90 + 270);
Lines.stroke(8f); Lines.stroke(8f);
Lines.line(Draw.region(name + "-bridge"), Lines.line(bridgeRegion,
tile.worldx(), tile.worldx(),
tile.worldy(), tile.worldy(),
other.worldx(), other.worldx(),
@@ -204,7 +214,7 @@ public class ItemBridge extends Block {
for(int a = 0; a < arrows; a ++){ for(int a = 0; a < arrows; a ++){
Draw.alpha(Mathf.absin(a/(float)arrows - entity.time/100f, 0.1f, 1f) * entity.uptime); Draw.alpha(Mathf.absin(a/(float)arrows - entity.time/100f, 0.1f, 1f) * entity.uptime);
Draw.rect(name + "-arrow", Draw.rect(arrowRegion,
tile.worldx() + Geometry.d4[i].x*(tilesize/2f + a*4f + time % 4f), tile.worldx() + Geometry.d4[i].x*(tilesize/2f + a*4f + time % 4f),
tile.worldy() + Geometry.d4[i].y*(tilesize/2f + a*4f + time % 4f), tile.worldy() + Geometry.d4[i].y*(tilesize/2f + a*4f + time % 4f),
i*90f); i*90f);
@@ -214,7 +224,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.items.totalItems() < itemCapacity; return tile.entity.items.total() < itemCapacity;
} }
@Override @Override

View File

@@ -64,7 +64,7 @@ public class MassDriver extends Block {
if(entity.isUnloading){ if(entity.isUnloading){
tryDump(tile); tryDump(tile);
if(entity.items.totalItems() <= 0){ if(entity.items.total() <= 0){
entity.isUnloading = false; entity.isUnloading = false;
} }
} }
@@ -79,10 +79,10 @@ public class MassDriver extends Block {
Tile waiter = entity.waiting.first(); Tile waiter = entity.waiting.first();
entity.rotation = Mathf.slerpDelta(entity.rotation, tile.angleTo(waiter), rotateSpeed); entity.rotation = Mathf.slerpDelta(entity.rotation, tile.angleTo(waiter), rotateSpeed);
}else if (tile.entity.items.totalItems() >= minDistribute && }else if (tile.entity.items.total() >= minDistribute &&
linkValid(tile) && //only fire when at least at half-capacity and power linkValid(tile) && //only fire when at least at half-capacity and power
tile.entity.power.amount >= powerCapacity && tile.entity.power.amount >= powerCapacity &&
link.block().itemCapacity - link.entity.items.totalItems() >= minDistribute && entity.reload <= 0.0001f) { link.block().itemCapacity - link.entity.items.total() >= minDistribute && entity.reload <= 0.0001f) {
MassDriverEntity other = link.entity(); MassDriverEntity other = link.entity();
other.waiting.add(tile); other.waiting.add(tile);
@@ -150,7 +150,7 @@ public class MassDriver 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.items.totalItems() < itemCapacity; return tile.entity.items.total() < itemCapacity;
} }
@Override @Override
@@ -221,7 +221,7 @@ public class MassDriver extends Block {
public float reload = 0f; public float reload = 0f;
public void handlePayload(Bullet bullet, DriverBulletData data){ public void handlePayload(Bullet bullet, DriverBulletData data){
int totalItems = items.totalItems(); int totalItems = items.total();
//add all the items possible //add all the items possible
for(int i = 0; i < data.items.length; i ++){ for(int i = 0; i < data.items.length; i ++){

View File

@@ -21,10 +21,10 @@ public class Router extends Block{
@Override @Override
public void update(Tile tile){ public void update(Tile tile){
int iterations = Math.max(1, (int) (Timers.delta() + 0.4f)); int iterations = Math.max(1, (int) (Timers.delta() + 0.4f));
boolean moved = tile.entity.items.totalItems() > 0; boolean moved = tile.entity.items.total() > 0;
for(int i = 0; i < iterations; i ++) { for(int i = 0; i < iterations; i ++) {
if (tile.entity.items.totalItems() > 0) { if (tile.entity.items.total() > 0) {
tryDump(tile); tryDump(tile);
moved = true; moved = true;
} }
@@ -37,7 +37,7 @@ 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) {
return !(to.block() instanceof Router) || ((float) to.target().entity.items.totalItems() / to.target().block().itemCapacity) < ((float) tile.entity.items.totalItems() / to.target().block().itemCapacity); return !(to.block() instanceof Router) || ((float) to.target().entity.items.total() / to.target().block().itemCapacity) < ((float) tile.entity.items.total() / to.target().block().itemCapacity);
} }
@Override @Override
@@ -48,7 +48,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.items.totalItems(); int items = tile.entity.items.total();
return items < itemCapacity; return items < itemCapacity;
} }

View File

@@ -33,7 +33,7 @@ public class TunnelConduit extends LiquidBlock {
@Override @Override
public void draw(Tile tile){ public void draw(Tile tile){
Draw.rect(name, tile.drawx(), tile.drawy(), tile.getRotation() * 90); Draw.rect(region, tile.drawx(), tile.drawy(), tile.getRotation() * 90);
} }
@Override @Override

View File

@@ -147,7 +147,7 @@ public class WarpGate extends PowerBlock{
teleporters[entity.color].add(tile); teleporters[entity.color].add(tile);
if(entity.items.totalItems() > 0){ if(entity.items.total() > 0){
tryDump(tile); tryDump(tile);
} }
@@ -210,7 +210,7 @@ public class WarpGate extends PowerBlock{
entity.time += Timers.delta() * entity.speedScl; entity.time += Timers.delta() * entity.speedScl;
if (!entity.teleporting && entity.items.totalItems() >= itemCapacity && entity.power.amount >= powerCapacity - 0.01f - powerUse && if (!entity.teleporting && entity.items.total() >= itemCapacity && entity.power.amount >= powerCapacity - 0.01f - powerUse &&
entity.timer.get(timerTeleport, teleportMax)) { entity.timer.get(timerTeleport, teleportMax)) {
Array<Tile> testLinks = findLinks(tile); Array<Tile> testLinks = findLinks(tile);
@@ -226,12 +226,12 @@ public class WarpGate 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.items.totalItems(); int canAccept = itemCapacity - other.entity.items.total();
int total = entity.items.totalItems(); int total = entity.items.total();
if (total == 0) break; if (total == 0) break;
Effects.effect(teleportOutEffect, resultColor, other.drawx(), other.drawy()); Effects.effect(teleportOutEffect, resultColor, other.drawx(), other.drawy());
for (int i = 0; i < canAccept && i < total; i++) { for (int i = 0; i < canAccept && i < total; i++) {
other.entity.items.addItem(entity.items.takeItem(), 1); other.entity.items.add(entity.items.take(), 1);
} }
} }
Effects.effect(teleportOutEffect, resultColor, tile.drawx(), tile.drawy()); Effects.effect(teleportOutEffect, resultColor, tile.drawx(), tile.drawy());
@@ -271,7 +271,7 @@ public class WarpGate 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.items.totalItems() < itemCapacity; return entity.items.total() < itemCapacity;
} }
@Override @Override
@@ -323,7 +323,7 @@ public class WarpGate 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.items.totalItems() == 0){ }else if(other.entity.items.total() == 0){
returns.add(other); returns.add(other);
} }
}else{ }else{

View File

@@ -1,110 +0,0 @@
package io.anuke.mindustry.world.blocks.modules;
import io.anuke.mindustry.type.Item;
import io.anuke.mindustry.type.ItemStack;
import io.anuke.mindustry.world.blocks.BlockModule;
import java.io.*;
import java.util.Arrays;
public class InventoryModule extends BlockModule{
//TODO make private!
public int[] items = new int[Item.all().size];
public boolean hasItems(ItemStack[] stacks){
for(ItemStack stack : stacks){
if(!hasItem(stack.item, stack.amount)) return false;
}
return true;
}
public boolean hasItems(ItemStack[] stacks, float amountScaling){
for(ItemStack stack : stacks){
if(!hasItem(stack.item, (int)(stack.amount * amountScaling))) return false;
}
return true;
}
/**Returns true if this entity has at least one of each item in each stack.*/
public boolean hasAtLeastOneOfItems(ItemStack[] stacks){
for(ItemStack stack : stacks){
if(!hasItem(stack.item, 1)) return false;
}
return true;
}
//TODO optimize!
public int totalItems(){
int sum = 0;
for(int i = 0; i < items.length; i ++){
sum += items[i];
}
return sum;
}
public Item takeItem(){
for(int i = 0; i < items.length; i ++){
if(items[i] > 0){
items[i] --;
return Item.getByID(i);
}
}
return null;
}
public int getItem(Item item){
return items[item.id];
}
public boolean hasItem(Item item){
return getItem(item) > 0;
}
public boolean hasItem(Item item, int amount){
return getItem(item) >= amount;
}
public void addItem(Item item, int amount){
items[item.id] += amount;
}
public void removeItem(Item item, int amount){
items[item.id] -= amount;
}
public void removeItem(ItemStack stack){
items[stack.item.id] -= stack.amount;
}
public void clear(){
Arrays.fill(items, 0);
}
@Override
public void write(DataOutput stream) throws IOException {
byte amount = 0;
for(int i = 0; i < items.length; i ++){
if(items[i] > 0) amount ++;
}
stream.writeByte(amount); //amount of items
for(int i = 0; i < items.length; i ++){
if(items[i] > 0){
stream.writeByte(i); //item ID
stream.writeInt(items[i]); //item amount
}
}
}
@Override
public void read(DataInput stream) throws IOException {
byte count = stream.readByte();
for(int j = 0; j < count; j ++){
int itemid = stream.readByte();
int itemamount = stream.readInt();
items[itemid] = itemamount;
}
}
}

View File

@@ -1,28 +0,0 @@
package io.anuke.mindustry.world.blocks.modules;
import io.anuke.mindustry.content.Liquids;
import io.anuke.mindustry.type.Liquid;
import io.anuke.mindustry.world.blocks.BlockModule;
import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;
public class LiquidModule extends BlockModule {
public float amount;
/**Should never be null.*/
public Liquid liquid = Liquids.none;
@Override
public void write(DataOutput stream) throws IOException {
stream.writeByte(liquid.id);
stream.writeFloat(amount);
}
@Override
public void read(DataInput stream) throws IOException{
byte id = stream.readByte();
liquid = Liquid.getByID(id);
amount = stream.readFloat();
}
}

View File

@@ -93,7 +93,7 @@ public class FusionReactor extends PowerGenerator {
Graphics.setNormalBlending(); Graphics.setNormalBlending();
Draw.rect(name, tile.drawx(), tile.drawy()); Draw.rect(region, tile.drawx(), tile.drawy());
Draw.rect(name + "-top", tile.drawx(), tile.drawy()); Draw.rect(name + "-top", tile.drawx(), tile.drawy());

View File

@@ -55,7 +55,7 @@ public abstract class ItemGenerator 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.items.totalItems() / itemCapacity)); bars.replace(new BlockBar(BarType.inventory, true, tile -> (float)tile.entity.items.total() / itemCapacity));
} }
@Override @Override
@@ -66,7 +66,7 @@ public abstract class ItemGenerator extends PowerGenerator {
if(entity.generateTime > 0){ if(entity.generateTime > 0){
Draw.color(heatColor); Draw.color(heatColor);
float alpha = (entity.items.totalItems() > 0 ? 1f : Mathf.clamp(entity.generateTime)); float alpha = (entity.items.total() > 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(topRegion, tile.drawx(), tile.drawy()); Draw.rect(topRegion, tile.drawx(), tile.drawy());
@@ -76,7 +76,7 @@ public abstract class ItemGenerator 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) >= minItemEfficiency && tile.entity.items.totalItems() < itemCapacity; return getItemEfficiency(item) >= minItemEfficiency && tile.entity.items.total() < itemCapacity;
} }
@Override @Override
@@ -97,7 +97,7 @@ public abstract class ItemGenerator extends PowerGenerator {
} }
} }
if(entity.generateTime <= 0f && entity.items.totalItems() > 0){ if(entity.generateTime <= 0f && entity.items.total() > 0){
Effects.effect(generateEffect, tile.worldx() + Mathf.range(size * tilesize/2f), tile.worldy() + Mathf.range(size * tilesize/2f)); Effects.effect(generateEffect, tile.worldx() + Mathf.range(size * tilesize/2f), tile.worldy() + Mathf.range(size * tilesize/2f));
for(int i = 0; i < entity.items.items.length; i ++){ for(int i = 0; i < entity.items.items.length; i ++){
if(entity.items.items[i] > 0){ if(entity.items.items[i] > 0){

View File

@@ -64,7 +64,7 @@ public abstract class ItemLiquidGenerator extends ItemGenerator {
} }
} }
if (entity.generateTime <= 0f && entity.items.totalItems() > 0) { if (entity.generateTime <= 0f && entity.items.total() > 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.items.items.length; i++) { for (int i = 0; i < entity.items.items.length; i++) {
if (entity.items.items[i] > 0) { if (entity.items.items[i] > 0) {

View File

@@ -57,7 +57,7 @@ public class NuclearReactor 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.items.getItem(generateItem) / itemCapacity)); bars.replace(new BlockBar(BarType.inventory, true, tile -> (float)tile.entity.items.get(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));
} }
@@ -73,7 +73,7 @@ public class NuclearReactor extends PowerGenerator {
public void update(Tile tile){ public void update(Tile tile){
NuclearReactorEntity entity = tile.entity(); NuclearReactorEntity entity = tile.entity();
int fuel = entity.items.getItem(generateItem); int fuel = entity.items.get(generateItem);
float fullness = (float)fuel / itemCapacity; float fullness = (float)fuel / itemCapacity;
if(fuel > 0){ if(fuel > 0){
@@ -81,7 +81,7 @@ public class NuclearReactor extends PowerGenerator {
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.items.removeItem(generateItem, 1); entity.items.remove(generateItem, 1);
} }
} }
@@ -123,7 +123,7 @@ public class NuclearReactor extends PowerGenerator {
NuclearReactorEntity entity = tile.entity(); NuclearReactorEntity entity = tile.entity();
int fuel = entity.items.getItem(generateItem); int fuel = entity.items.get(generateItem);
if(fuel < 5 && entity.heat < 0.5f) return; if(fuel < 5 && entity.heat < 0.5f) return;
@@ -155,7 +155,7 @@ public class NuclearReactor extends PowerGenerator {
@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.items.getItem(generateItem) < itemCapacity; return item == generateItem && tile.entity.items.get(generateItem) < itemCapacity;
} }
@Override @Override

View File

@@ -23,14 +23,14 @@ public class Compressor extends PowerCrafter {
float liquidAdded = Math.min(outputLiquidAmount * Timers.delta(), liquidCapacity - entity.liquids.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.items.hasItem(input.item, itemsUsed) && liquidAdded > 0.001f){ if(entity.power.amount > powerUsed && entity.items.has(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.items.removeItem(input); entity.items.remove(input);
if(outputItem != null) offloadNear(tile, outputItem); if(outputItem != null) offloadNear(tile, outputItem);
entity.progress = 0f; entity.progress = 0f;
} }
@@ -48,7 +48,7 @@ public class Compressor extends PowerCrafter {
public void draw(Tile tile) { public void draw(Tile tile) {
GenericCrafterEntity entity = tile.entity(); GenericCrafterEntity entity = tile.entity();
Draw.rect(name, tile.drawx(), tile.drawy()); Draw.rect(region, 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.liquids.liquid.color, tile.entity.liquids.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());

View File

@@ -57,7 +57,7 @@ public class Cultivator extends Drill {
public void draw(Tile tile) { public void draw(Tile tile) {
CultivatorEntity entity = tile.entity(); CultivatorEntity entity = tile.entity();
Draw.rect(name, tile.drawx(), tile.drawy()); Draw.rect(region, tile.drawx(), tile.drawy());
Draw.color(plantColor); Draw.color(plantColor);
Draw.alpha(entity.warmup); Draw.alpha(entity.warmup);

View File

@@ -91,7 +91,7 @@ public class Drill extends Block{
DrillEntity entity = tile.entity(); DrillEntity entity = tile.entity();
Draw.rect(name, tile.drawx(), tile.drawy()); Draw.rect(region, tile.drawx(), tile.drawy());
if(drawRim) { if(drawRim) {
Graphics.setAdditiveBlending(); Graphics.setAdditiveBlending();
@@ -178,7 +178,7 @@ 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.items.totalItems() < itemCapacity && toAdd.size > 0 && if(entity.items.total() < itemCapacity && toAdd.size > 0 &&
(!hasPower || entity.power.amount >= powerUsed) && (!hasPower || entity.power.amount >= powerUsed) &&
(!liquidRequired || entity.liquids.amount >= liquidUsed)){ (!liquidRequired || entity.liquids.amount >= liquidUsed)){
@@ -203,7 +203,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.items.totalItems() < itemCapacity){ && tile.entity.items.total() < 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

@@ -10,7 +10,6 @@ import io.anuke.mindustry.world.meta.BlockStat;
import io.anuke.mindustry.world.meta.StatUnit; import io.anuke.mindustry.world.meta.StatUnit;
import io.anuke.ucore.core.Timers; import io.anuke.ucore.core.Timers;
import io.anuke.ucore.graphics.Draw; import io.anuke.ucore.graphics.Draw;
import io.anuke.ucore.util.Log;
public class Fracker extends SolidPump { public class Fracker extends SolidPump {
protected Liquid inputLiquid; protected Liquid inputLiquid;
@@ -51,7 +50,7 @@ public class Fracker extends SolidPump {
public void draw(Tile tile) { public void draw(Tile tile) {
FrackerEntity entity = tile.entity(); FrackerEntity entity = tile.entity();
Draw.rect(name, tile.drawx(), tile.drawy()); Draw.rect(region, tile.drawx(), tile.drawy());
Draw.color(tile.entity.liquids.liquid.color); Draw.color(tile.entity.liquids.liquid.color);
Draw.alpha(tile.entity.liquids.amount/liquidCapacity); Draw.alpha(tile.entity.liquids.amount/liquidCapacity);
@@ -71,8 +70,8 @@ public class Fracker extends SolidPump {
public void update(Tile tile) { public void update(Tile tile) {
FrackerEntity entity = tile.entity(); FrackerEntity entity = tile.entity();
while(entity.accumulator > itemUseTime && entity.items.hasItem(inputItem, 1)){ while(entity.accumulator > itemUseTime && entity.items.has(inputItem, 1)){
entity.items.removeItem(inputItem, 1); entity.items.remove(inputItem, 1);
entity.accumulator -= itemUseTime; entity.accumulator -= itemUseTime;
} }
@@ -87,7 +86,7 @@ public class Fracker extends SolidPump {
@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.items.totalItems() < itemCapacity; return item == inputItem && tile.entity.items.total() < itemCapacity;
} }
@Override @Override

View File

@@ -51,7 +51,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.items.getItem(inputItem.item) / itemCapacity)); tile -> (float)tile.entity.items.get(inputItem.item) / itemCapacity));
} }
@Override @Override
@@ -93,7 +93,7 @@ public class GenericCrafter extends Block{
if((!hasLiquids || entity.liquids.amount >= liquidUsed) && if((!hasLiquids || entity.liquids.amount >= liquidUsed) &&
(!hasPower || entity.power.amount >= powerUsed) && (!hasPower || entity.power.amount >= powerUsed) &&
(inputItem == null || entity.items.hasItem(inputItem.item, itemsUsed))){ (inputItem == null || entity.items.has(inputItem.item, itemsUsed))){
entity.progress += 1f / craftTime * Timers.delta(); entity.progress += 1f / craftTime * Timers.delta();
entity.totalProgress += Timers.delta(); entity.totalProgress += Timers.delta();
@@ -109,7 +109,7 @@ public class GenericCrafter extends Block{
if(entity.progress >= 1f){ if(entity.progress >= 1f){
if(inputItem != null) tile.entity.items.removeItem(inputItem); if(inputItem != null) tile.entity.items.remove(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;
@@ -128,7 +128,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.items.getItem(inputItem.item) < itemCapacity; return inputItem != null && item == inputItem.item && entity.items.get(inputItem.item) < itemCapacity;
} }
@Override @Override

View File

@@ -46,21 +46,21 @@ public class LiquidMixer extends LiquidBlock{
@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.items.getItem(item) < itemCapacity; return item == inputItem && tile.entity.items.get(item) < itemCapacity;
} }
@Override @Override
public float handleAuxLiquid(Tile tile, Tile source, Liquid liquid, float amount) { public float handleAuxLiquid(Tile tile, Tile source, Liquid liquid, float amount) {
LiquidMixerEntity entity = tile.entity(); LiquidMixerEntity entity = tile.entity();
if(liquid == inputLiquid && tile.entity.items.hasItem(inputItem, (int)((entity.accumulator + amount)/amount)) && if(liquid == inputLiquid && tile.entity.items.has(inputItem, (int)((entity.accumulator + amount)/amount)) &&
tile.entity.power.amount >= powerUse){ tile.entity.power.amount >= powerUse){
amount = Math.min(liquidCapacity - tile.entity.liquids.amount, amount); amount = Math.min(liquidCapacity - tile.entity.liquids.amount, amount);
entity.accumulator += amount; entity.accumulator += amount;
int items = (int)(entity.accumulator / liquidPerItem); int items = (int)(entity.accumulator / liquidPerItem);
entity.items.removeItem(inputItem, items); entity.items.remove(inputItem, items);
entity.accumulator %= liquidPerItem; entity.accumulator %= liquidPerItem;
entity.liquids.liquid = outputLiquid; entity.liquids.liquid = outputLiquid;
entity.liquids.amount += amount; entity.liquids.amount += amount;

View File

@@ -64,6 +64,6 @@ public class PhaseWeaver extends PowerSmelter{
Draw.reset(); Draw.reset();
} }
Draw.rect(name, tile.drawx(), tile.drawy()); Draw.rect(region, tile.drawx(), tile.drawy());
} }
} }

View File

@@ -59,13 +59,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.items.hasItem(input.item, itemsUsed)){ if(entity.power.amount > powerUsed && entity.items.has(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.items.removeItem(input); entity.items.remove(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;
@@ -82,7 +82,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.items.getItem(input.item) < itemCapacity; return item == input.item && tile.entity.items.get(input.item) < itemCapacity;
} }
@Override @Override

View File

@@ -71,7 +71,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.items.getItem(item.item) / itemCapacity)); bars.add(new BlockBar(BarType.inventory, true, tile -> (float) tile.entity.items.get(item.item) / itemCapacity));
} }
} }
@@ -93,7 +93,7 @@ public class PowerSmelter extends PowerBlock {
PowerSmelterEntity entity = tile.entity(); PowerSmelterEntity entity = tile.entity();
if(entity.timer.get(timerDump, 5) && entity.items.hasItem(result)){ if(entity.timer.get(timerDump, 5) && entity.items.has(result)){
tryDump(tile, result); tryDump(tile, result);
} }
@@ -114,12 +114,12 @@ 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.items.hasItem(item.item, item.amount)){ if(!entity.items.has(item.item, item.amount)){
return; return;
} }
} }
if(entity.items.getItem(result) >= itemCapacity //output full if(entity.items.get(result) >= itemCapacity //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;
@@ -130,8 +130,8 @@ public class PowerSmelter extends PowerBlock {
if(useFlux){ if(useFlux){
//remove flux materials if present //remove flux materials if present
for(Item item : Item.all()){ for(Item item : Item.all()){
if(item.fluxiness >= minFlux && tile.entity.items.getItem(item) >= fluxNeeded){ if(item.fluxiness >= minFlux && tile.entity.items.get(item) >= fluxNeeded){
tile.entity.items.removeItem(item, fluxNeeded); tile.entity.items.remove(item, fluxNeeded);
//chance of not consuming inputs if flux material present //chance of not consuming inputs if flux material present
consumeInputs = !Mathf.chance(item.fluxiness * baseFluxChance); consumeInputs = !Mathf.chance(item.fluxiness * baseFluxChance);
@@ -142,7 +142,7 @@ public class PowerSmelter extends PowerBlock {
if(consumeInputs) { if(consumeInputs) {
for (ItemStack item : inputs) { for (ItemStack item : inputs) {
entity.items.removeItem(item.item, item.amount); entity.items.remove(item.item, item.amount);
} }
} }
@@ -155,12 +155,12 @@ public class PowerSmelter extends PowerBlock {
for(ItemStack stack : inputs){ for(ItemStack stack : inputs){
if(stack.item == item){ if(stack.item == item){
return tile.entity.items.getItem(item) < itemCapacity; return tile.entity.items.get(item) < itemCapacity;
} }
} }
if(useFlux && item.fluxiness >= minFlux){ if(useFlux && item.fluxiness >= minFlux){
return tile.entity.items.getItem(item) < itemCapacity; return tile.entity.items.get(item) < itemCapacity;
} }
return false; return false;
@@ -168,7 +168,7 @@ public class PowerSmelter extends PowerBlock {
@Override @Override
public int getMaximumAccepted(Tile tile, Item item) { public int getMaximumAccepted(Tile tile, Item item) {
return itemCapacity - tile.entity.items.getItem(item); return itemCapacity - tile.entity.items.get(item);
} }
@Override @Override

View File

@@ -5,18 +5,26 @@ import io.anuke.mindustry.world.Tile;
import io.anuke.ucore.graphics.Draw; import io.anuke.ucore.graphics.Draw;
public class Pulverizer extends GenericCrafter { public class Pulverizer extends GenericCrafter {
protected TextureRegion rotatorRegion;
public Pulverizer(String name) { public Pulverizer(String name) {
super(name); super(name);
hasItems = true; hasItems = true;
} }
@Override
public void load() {
super.load();
rotatorRegion = Draw.region(name + "-rotator");
}
@Override @Override
public void draw(Tile tile) { public void draw(Tile tile) {
GenericCrafterEntity entity = tile.entity(); GenericCrafterEntity entity = tile.entity();
Draw.rect(name, tile.drawx(), tile.drawy()); Draw.rect(region, tile.drawx(), tile.drawy());
Draw.rect(name + "-rotator", tile.drawx(), tile.drawy(), entity.totalProgress * 2f); Draw.rect(rotatorRegion, tile.drawx(), tile.drawy(), entity.totalProgress * 2f);
} }
@Override @Override

View File

@@ -1,6 +1,7 @@
package io.anuke.mindustry.world.blocks.production; package io.anuke.mindustry.world.blocks.production;
import com.badlogic.gdx.graphics.Color; import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.g2d.TextureRegion;
import io.anuke.mindustry.entities.TileEntity; import io.anuke.mindustry.entities.TileEntity;
import io.anuke.mindustry.type.Item; import io.anuke.mindustry.type.Item;
import io.anuke.mindustry.type.Liquid; import io.anuke.mindustry.type.Liquid;
@@ -30,6 +31,9 @@ public class Separator extends Block {
protected float spinnerThickness = 1f; protected float spinnerThickness = 1f;
protected float spinnerSpeed = 2f; protected float spinnerSpeed = 2f;
protected Color color = Color.valueOf("858585");
protected TextureRegion liquidRegion;
protected boolean offloading = false; protected boolean offloading = false;
public Separator(String name) { public Separator(String name) {
@@ -40,6 +44,13 @@ public class Separator extends Block {
hasLiquids = true; hasLiquids = true;
} }
@Override
public void load() {
super.load();
liquidRegion = Draw.region(name + "-liquid");
}
@Override @Override
public void setStats() { public void setStats() {
super.setStats(); super.setStats();
@@ -67,9 +78,9 @@ public class Separator extends Block {
Draw.color(tile.entity.liquids.liquid.color); Draw.color(tile.entity.liquids.liquid.color);
Draw.alpha(tile.entity.liquids.amount / liquidCapacity); Draw.alpha(tile.entity.liquids.amount / liquidCapacity);
Draw.rect(name + "-liquid", tile.drawx(), tile.drawy()); Draw.rect(liquidRegion, tile.drawx(), tile.drawy());
Draw.color(Color.valueOf("858585")); Draw.color(color);
Lines.stroke(spinnerThickness); Lines.stroke(spinnerThickness);
Lines.spikes(tile.drawx(), tile.drawy(), spinnerRadius, spinnerLength, 3, entity.totalProgress*spinnerSpeed); Lines.spikes(tile.drawx(), tile.drawy(), spinnerRadius, spinnerLength, 3, entity.totalProgress*spinnerSpeed);
Draw.reset(); Draw.reset();
@@ -84,7 +95,7 @@ public class Separator extends Block {
entity.totalProgress += entity.warmup*Timers.delta(); entity.totalProgress += entity.warmup*Timers.delta();
if(entity.liquids.amount >= liquidUsed && entity.items.hasItem(item) && if(entity.liquids.amount >= liquidUsed && entity.items.has(item) &&
(!hasPower || entity.power.amount >= powerUsed)){ (!hasPower || entity.power.amount >= powerUsed)){
entity.progress += 1f/filterTime; entity.progress += 1f/filterTime;
entity.liquids.amount -= liquidUsed; entity.liquids.amount -= liquidUsed;
@@ -98,7 +109,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.items.removeItem(this.item, 1); entity.items.remove(this.item, 1);
if(item != null){ if(item != null){
offloading = true; offloading = true;
offloadNear(tile, item); offloadNear(tile, item);
@@ -123,7 +134,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.items.getItem(item) < itemCapacity; return this.item == item && tile.entity.items.get(item) < itemCapacity;
} }
@Override @Override

View File

@@ -47,7 +47,7 @@ public class Smelter extends Block{
@Override @Override
public void setBars(){ public void setBars(){
for(ItemStack item : inputs){ for(ItemStack item : inputs){
bars.add(new BlockBar(BarType.inventory, true, tile -> (float)tile.entity.items.getItem(item.item)/itemCapacity)); bars.add(new BlockBar(BarType.inventory, true, tile -> (float)tile.entity.items.get(item.item)/itemCapacity));
} }
} }
@@ -79,13 +79,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.items.hasItem(result)){ if(entity.timer.get(timerDump, 5) && entity.items.has(result)){
tryDump(tile, result); tryDump(tile, result);
} }
//add fuel //add fuel
if(entity.items.getItem(fuel) > 0 && entity.burnTime <= 0f){ if(entity.items.get(fuel) > 0 && entity.burnTime <= 0f){
entity.items.removeItem(fuel, 1); entity.items.remove(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));
} }
@@ -100,12 +100,12 @@ public class Smelter extends Block{
//make sure it has all the items //make sure it has all the items
for(ItemStack item : inputs){ for(ItemStack item : inputs){
if(!entity.items.hasItem(item.item, item.amount)){ if(!entity.items.has(item.item, item.amount)){
return; return;
} }
} }
if(entity.items.getItem(result) >= itemCapacity //output full if(entity.items.get(result) >= itemCapacity //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;
@@ -116,8 +116,8 @@ public class Smelter extends Block{
if(useFlux){ if(useFlux){
//remove flux materials if present //remove flux materials if present
for(Item item : Item.all()){ for(Item item : Item.all()){
if(item.fluxiness >= minFlux && tile.entity.items.getItem(item) > 0){ if(item.fluxiness >= minFlux && tile.entity.items.get(item) > 0){
tile.entity.items.removeItem(item, 1); tile.entity.items.remove(item, 1);
//chance of not consuming inputs if flux material present //chance of not consuming inputs if flux material present
consumeInputs = !Mathf.chance(item.fluxiness * baseFluxChance); consumeInputs = !Mathf.chance(item.fluxiness * baseFluxChance);
@@ -128,7 +128,7 @@ public class Smelter extends Block{
if(consumeInputs) { if(consumeInputs) {
for (ItemStack item : inputs) { for (ItemStack item : inputs) {
entity.items.removeItem(item.item, item.amount); entity.items.remove(item.item, item.amount);
} }
} }
@@ -138,7 +138,7 @@ public class Smelter extends Block{
@Override @Override
public int getMaximumAccepted(Tile tile, Item item) { public int getMaximumAccepted(Tile tile, Item item) {
return itemCapacity - tile.entity.items.getItem(item); return itemCapacity - tile.entity.items.get(item);
} }
@Override @Override
@@ -152,8 +152,8 @@ public class Smelter extends Block{
} }
} }
return (isInput && tile.entity.items.getItem(item) < itemCapacity) || (item == fuel && tile.entity.items.getItem(fuel) < itemCapacity) || return (isInput && tile.entity.items.get(item) < itemCapacity) || (item == fuel && tile.entity.items.get(fuel) < itemCapacity) ||
(useFlux && item.fluxiness >= minFlux && tile.entity.items.getItem(item) < itemCapacity); (useFlux && item.fluxiness >= minFlux && tile.entity.items.get(item) < itemCapacity);
} }
@Override @Override

View File

@@ -43,7 +43,7 @@ public class SolidPump extends Pump {
public void draw(Tile tile) { public void draw(Tile tile) {
SolidPumpEntity entity = tile.entity(); SolidPumpEntity entity = tile.entity();
Draw.rect(name, tile.drawx(), tile.drawy()); Draw.rect(region, tile.drawx(), tile.drawy());
Draw.color(tile.entity.liquids.liquid.color); Draw.color(tile.entity.liquids.liquid.color);
Draw.alpha(tile.entity.liquids.amount / liquidCapacity); Draw.alpha(tile.entity.liquids.amount / liquidCapacity);
Draw.rect(liquidRegion, tile.drawx(), tile.drawy()); Draw.rect(liquidRegion, tile.drawx(), tile.drawy());

View File

@@ -133,7 +133,7 @@ public class CoreBlock extends StorageBlock {
@Override @Override
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) && hasItems && source.getTeam() == tile.getTeam()){ if(acceptItem(item, tile, tile) && hasItems && source.getTeam() == tile.getTeam()){
return Math.min(itemCapacity - tile.entity.items.getItem(item), amount); return Math.min(itemCapacity - tile.entity.items.get(item), amount);
}else{ }else{
return 0; return 0;
} }

View File

@@ -30,16 +30,16 @@ public class SortedUnloader extends Unloader implements SelectionTrait{
public void update(Tile tile){ public void update(Tile tile){
SortedUnloaderEntity entity = tile.entity(); SortedUnloaderEntity entity = tile.entity();
if(entity.items.totalItems() == 0 && entity.timer.get(timerUnload, speed)){ if(entity.items.total() == 0 && entity.timer.get(timerUnload, speed)){
tile.allNearby(other -> { tile.allNearby(other -> {
if(other.block() instanceof StorageBlock && entity.items.totalItems() == 0 && if(other.block() instanceof StorageBlock && entity.items.total() == 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.items.totalItems() > 0){ if(entity.items.total() > 0){
tryDump(tile); tryDump(tile);
} }
} }

View File

@@ -20,16 +20,16 @@ public class Unloader extends Block {
@Override @Override
public void update(Tile tile){ public void update(Tile tile){
if(tile.entity.items.totalItems() == 0 && tile.entity.timer.get(timerUnload, speed)){ if(tile.entity.items.total() == 0 && tile.entity.timer.get(timerUnload, speed)){
tile.allNearby(other -> { tile.allNearby(other -> {
if(other.block() instanceof StorageBlock && tile.entity.items.totalItems() == 0 && if(other.block() instanceof StorageBlock && tile.entity.items.total() == 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.items.totalItems() > 0){ if(tile.entity.items.total() > 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.items.totalItems() > 0) { if (tile.entity.items.total() > 0) {
tryDump(tile); tryDump(tile);
} }
} }
@@ -31,7 +31,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.items.totalItems() < itemCapacity; return tile.entity.items.total() < itemCapacity;
} }
@Override @Override
@@ -39,7 +39,7 @@ public class Vault extends StorageBlock {
to = to.target(); to = to.target();
if (!(to.block() instanceof StorageBlock)) return false; if (!(to.block() instanceof StorageBlock)) return false;
return !(to.block() instanceof Vault) || (float) to.entity.items.totalItems() / to.block().itemCapacity < (float) tile.entity.items.totalItems() / itemCapacity; return !(to.block() instanceof Vault) || (float) to.entity.items.total() / to.block().itemCapacity < (float) tile.entity.items.total() / itemCapacity;
} }
} }

View File

@@ -21,7 +21,7 @@ public class DropPoint extends Block {
@Override @Override
public void update(Tile tile) { public void update(Tile tile) {
if (tile.entity.items.totalItems() > 0) { if (tile.entity.items.total() > 0) {
tryDump(tile); tryDump(tile);
} }
} }

View File

@@ -112,7 +112,7 @@ public class Reconstructor extends Block{
ReconstructorEntity entity = tile.entity(); ReconstructorEntity entity = tile.entity();
if(entity.solid){ if(entity.solid){
Draw.rect(name, tile.drawx(), tile.drawy()); Draw.rect(region, tile.drawx(), tile.drawy());
}else{ }else{
Draw.rect(openRegion, tile.drawx(), tile.drawy()); Draw.rect(openRegion, tile.drawx(), tile.drawy());
} }

View File

@@ -118,7 +118,7 @@ public class ResupplyPoint 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.items.totalItems() < itemCapacity; return tile.entity.items.total() < itemCapacity;
} }
@Override @Override

View File

@@ -19,7 +19,7 @@ import io.anuke.mindustry.type.ItemStack;
import io.anuke.mindustry.world.BarType; import io.anuke.mindustry.world.BarType;
import io.anuke.mindustry.world.Block; import io.anuke.mindustry.world.Block;
import io.anuke.mindustry.world.Tile; import io.anuke.mindustry.world.Tile;
import io.anuke.mindustry.world.blocks.modules.InventoryModule; import io.anuke.mindustry.world.modules.InventoryModule;
import io.anuke.mindustry.world.meta.BlockBar; import io.anuke.mindustry.world.meta.BlockBar;
import io.anuke.mindustry.world.meta.BlockStat; import io.anuke.mindustry.world.meta.BlockStat;
import io.anuke.mindustry.world.meta.StatUnit; import io.anuke.mindustry.world.meta.StatUnit;
@@ -154,7 +154,7 @@ public class UnitFactory extends Block {
entity.openCountdown = openDuration; entity.openCountdown = openDuration;
for(ItemStack stack : requirements){ for(ItemStack stack : requirements){
entity.items.removeItem(stack.item, stack.amount); entity.items.remove(stack.item, stack.amount);
} }
} }
} }
@@ -162,7 +162,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.items.getItem(item) <= stack.amount*2){ if(item == stack.item && tile.entity.items.get(item) <= stack.amount*2){
return true; return true;
} }
} }
@@ -176,7 +176,7 @@ public class UnitFactory extends Block {
protected boolean hasRequirements(InventoryModule inv, float fraction){ protected boolean hasRequirements(InventoryModule inv, float fraction){
for(ItemStack stack : requirements){ for(ItemStack stack : requirements){
if(!inv.hasItem(stack.item, (int)(fraction * stack.amount))){ if(!inv.has(stack.item, (int)(fraction * stack.amount))){
return false; return false;
} }
} }

View File

@@ -0,0 +1,8 @@
package io.anuke.mindustry.world.consumers;
import io.anuke.mindustry.entities.TileEntity;
public interface Consume {
void update(TileEntity entity);
boolean valid();
}

View File

@@ -0,0 +1,145 @@
package io.anuke.mindustry.world.modules;
import io.anuke.mindustry.type.Item;
import io.anuke.mindustry.type.ItemStack;
import io.anuke.mindustry.world.blocks.BlockModule;
import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;
import java.util.Arrays;
public class InventoryModule extends BlockModule{
private int[] items = new int[Item.all().size];
private int total;
public void forEach(ItemConsumer cons){
for (int i = 0; i < items.length; i++) {
if(items[i] > 0){
cons.accept(Item.getByID(i), items[i]);
}
}
}
public float sum(ItemCalculator calc){
float sum = 0f;
for (int i = 0; i < items.length; i++) {
if(items[i] > 0){
sum += calc.get(Item.getByID(i), items[i]);
}
}
return sum;
}
public boolean has(Item item){
return get(item) > 0;
}
public boolean has(Item item, int amount){
return get(item) >= amount;
}
public boolean has(ItemStack[] stacks){
for(ItemStack stack : stacks){
if(!has(stack.item, stack.amount)) return false;
}
return true;
}
public boolean has(ItemStack[] stacks, float amountScaling){
for(ItemStack stack : stacks){
if(!has(stack.item, (int)(stack.amount * amountScaling))) return false;
}
return true;
}
/**Returns true if this entity has at least one of each item in each stack.*/
public boolean hasOne(ItemStack[] stacks){
for(ItemStack stack : stacks){
if(!has(stack.item, 1)) return false;
}
return true;
}
//TODO optimize!
public int total(){
return total;
}
public Item take(){
for(int i = 0; i < items.length; i ++){
if(items[i] > 0){
items[i] --;
total --;
return Item.getByID(i);
}
}
return null;
}
public int get(Item item){
return items[item.id];
}
public void set(Item item, int amount){
total += (amount - items[item.id]);
items[item.id] = amount;
}
public void add(Item item, int amount){
items[item.id] += amount;
total += amount;
}
public void remove(Item item, int amount){
items[item.id] -= amount;
total -= amount;
}
public void remove(ItemStack stack){
remove(stack.item, stack.amount);
}
public void clear(){
Arrays.fill(items, 0);
total = 0;
}
@Override
public void write(DataOutput stream) throws IOException {
byte amount = 0;
for (int item : items) {
if (item > 0) amount++;
}
stream.writeByte(amount); //amount of items
for(int i = 0; i < items.length; i ++){
if(items[i] > 0){
stream.writeByte(i); //item ID
stream.writeInt(items[i]); //item amount
}
}
}
@Override
public void read(DataInput stream) throws IOException {
byte count = stream.readByte();
total = 0;
for(int j = 0; j < count; j ++){
int itemid = stream.readByte();
int itemamount = stream.readInt();
items[itemid] = itemamount;
total += itemamount;
}
}
public interface ItemConsumer{
void accept(Item item, float amount);
}
public interface ItemCalculator{
float get(Item item, int amount);
}
}

View File

@@ -0,0 +1,95 @@
package io.anuke.mindustry.world.modules;
import io.anuke.mindustry.type.Liquid;
import io.anuke.mindustry.world.blocks.BlockModule;
import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;
public class LiquidModule extends BlockModule {
private float[] liquids = new float[Liquid.all().size];
private float total;
private Liquid current = Liquid.getByID(0);
/**Returns total amount of liquids.*/
public float total(){
return total;
}
/**Last recieved or loaded liquid. Only valid for liquid modules with 1 type of liquid.*/
public Liquid current(){
return current;
}
public float get(Liquid liquid){
return liquids[liquid.id];
}
public void add(Liquid liquid, float amount){
liquids[liquid.id] += amount;
total += amount;
}
public void remove(Liquid liquid, float amount){
add(liquid, -amount);
}
public void forEach(LiquidConsumer cons){
for (int i = 0; i < liquids.length; i++) {
if(liquids[i] > 0){
cons.accept(Liquid.getByID(i), liquids[i]);
}
}
}
public float sum(LiquidCalculator calc){
float sum = 0f;
for (int i = 0; i < liquids.length; i++) {
if(liquids[i] > 0){
sum += calc.get(Liquid.getByID(i), liquids[i]);
}
}
return sum;
}
@Override
public void write(DataOutput stream) throws IOException {
byte amount = 0;
for (float liquid : liquids) {
if (liquid > 0) amount++;
}
stream.writeByte(amount); //amount of liquids
for(int i = 0; i < liquids.length; i ++){
if(liquids[i] > 0){
stream.writeByte(i); //liquid ID
stream.writeFloat(liquids[i]); //item amount
}
}
}
@Override
public void read(DataInput stream) throws IOException {
byte count = stream.readByte();
for(int j = 0; j < count; j ++){
int liquidid = stream.readByte();
float amount = stream.readFloat();
liquids[liquidid] = amount;
if(amount > 0){
current = Liquid.getByID(liquidid);
}
this.total += amount;
}
}
public interface LiquidConsumer{
void accept(Liquid liquid, float amount);
}
public interface LiquidCalculator{
float get(Liquid liquid, float amount);
}
}

View File

@@ -1,4 +1,4 @@
package io.anuke.mindustry.world.blocks.modules; package io.anuke.mindustry.world.modules;
import io.anuke.mindustry.world.blocks.BlockModule; import io.anuke.mindustry.world.blocks.BlockModule;

View File

@@ -43,3 +43,12 @@ task generateSprites(dependsOn: classes, type: JavaExec) {
standardInput = System.in standardInput = System.in
workingDir = textureFolder workingDir = textureFolder
} }
task fixBundles(dependsOn: classes, type: JavaExec) {
file(textureFolder).mkdirs()
main = "io.anuke.mindustry.BundleLauncher"
classpath = sourceSets.main.runtimeClasspath
standardInput = System.in
workingDir = "../core/assets/bundles/"
}

View File

@@ -0,0 +1,17 @@
package io.anuke.mindustry;
import io.anuke.ucore.util.Log;
import java.io.File;
import java.nio.file.Paths;
public class BundleLauncher {
public static void main(String[] args){
File file = new File("bundle.properties");
Paths.get("").forEach(child -> {
Log.info("Directory: {0}", child);
});
}
}