diff --git a/android/AndroidManifest.xml b/android/AndroidManifest.xml index 342222acf8..64fc9d218b 100644 --- a/android/AndroidManifest.xml +++ b/android/AndroidManifest.xml @@ -20,7 +20,7 @@ diff --git a/core/assets/bundles/bundle.properties b/core/assets/bundles/bundle.properties index 480b1a2213..b8a2fb2501 100644 --- a/core/assets/bundles/bundle.properties +++ b/core/assets/bundles/bundle.properties @@ -461,8 +461,8 @@ block.multiplexer.name=Multiplexer block.multiplexer.description=A router that can split items into 8 directions. 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.overflowgate.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.name=Overflow Gate +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.description=A conveyor that can go over other blocks, for up to two total blocks. block.smelter.name=Smelter @@ -512,7 +512,6 @@ block.swarmer.name=Swarmer block.salvo.name=Salvo block.ripple.name=Ripple block.phase-conveyor.name=Phase Conveyor -block.overflow-gate.name=Overflow Gate block.bridge-conveyor.name=Bridge Conveyor block.plastanium-compressor.name=Plastanium Compressor block.pyratite-mixer.name=Pyratite Mixer diff --git a/core/src/io/anuke/mindustry/content/Liquids.java b/core/src/io/anuke/mindustry/content/Liquids.java index e543988bc8..097d708a30 100644 --- a/core/src/io/anuke/mindustry/content/Liquids.java +++ b/core/src/io/anuke/mindustry/content/Liquids.java @@ -12,13 +12,6 @@ public class Liquids implements ContentList { @Override public void load() { - none = new Liquid("none", Color.CLEAR){ - @Override - public boolean isHidden(){ - return true; - } - }; - water = new Liquid("water", Color.valueOf("486acd")) { { heatCapacity = 0.4f; diff --git a/core/src/io/anuke/mindustry/content/blocks/Blocks.java b/core/src/io/anuke/mindustry/content/blocks/Blocks.java index cba522baa1..86a239c042 100644 --- a/core/src/io/anuke/mindustry/content/blocks/Blocks.java +++ b/core/src/io/anuke/mindustry/content/blocks/Blocks.java @@ -145,17 +145,14 @@ public class Blocks extends BlockList implements ContentList{ rock = new Rock("rock") {{ variants = 2; - varyShadow = true; }}; icerock = new Rock("icerock") {{ variants = 2; - varyShadow = true; }}; blackrock = new Rock("blackrock") {{ variants = 1; - varyShadow = true; }}; } } diff --git a/core/src/io/anuke/mindustry/content/blocks/DebugBlocks.java b/core/src/io/anuke/mindustry/content/blocks/DebugBlocks.java index 023e8bbc3c..ff875423f9 100644 --- a/core/src/io/anuke/mindustry/content/blocks/DebugBlocks.java +++ b/core/src/io/anuke/mindustry/content/blocks/DebugBlocks.java @@ -56,7 +56,7 @@ public class DebugBlocks extends BlockList implements ContentList{ @Override public void update(Tile tile) { SorterEntity entity = tile.entity(); - entity.items.items[entity.sortItem.id] = 1; + entity.items.set(entity.sortItem, 1); tryDump(tile, entity.sortItem); } @@ -79,9 +79,8 @@ public class DebugBlocks extends BlockList implements ContentList{ public void update(Tile tile) { LiquidSourceEntity entity = tile.entity(); - tile.entity.liquids.amount = liquidCapacity; - tile.entity.liquids.liquid = entity.source; - tryDumpLiquid(tile); + tile.entity.liquids.add(entity.source, liquidCapacity); + tryDumpLiquid(tile, entity.source); } @Override diff --git a/core/src/io/anuke/mindustry/content/blocks/DefenseBlocks.java b/core/src/io/anuke/mindustry/content/blocks/DefenseBlocks.java index 709e27ffd4..761f05b7b8 100644 --- a/core/src/io/anuke/mindustry/content/blocks/DefenseBlocks.java +++ b/core/src/io/anuke/mindustry/content/blocks/DefenseBlocks.java @@ -35,11 +35,11 @@ public class DefenseBlocks extends BlockList implements ContentList { }}; thoriumWall = new Wall("thorium-wall") {{ - health = 110 * wallHealthMultiplier; + health = 200 * wallHealthMultiplier; }}; thoriumWallLarge = new Wall("thorium-wall-large") {{ - health = 110 * wallHealthMultiplier*4; + health = 200 * wallHealthMultiplier*4; size = 2; }}; diff --git a/core/src/io/anuke/mindustry/content/blocks/StorageBlocks.java b/core/src/io/anuke/mindustry/content/blocks/StorageBlocks.java index 4e5a2953c9..0d736832cb 100644 --- a/core/src/io/anuke/mindustry/content/blocks/StorageBlocks.java +++ b/core/src/io/anuke/mindustry/content/blocks/StorageBlocks.java @@ -19,6 +19,7 @@ public class StorageBlocks extends BlockList implements ContentList { vault = new Vault("vault") {{ size = 3; health = 600; + itemCapacity = 2000; }}; unloader = new Unloader("unloader") {{ diff --git a/core/src/io/anuke/mindustry/content/blocks/TurretBlocks.java b/core/src/io/anuke/mindustry/content/blocks/TurretBlocks.java index 616dea4e7e..c993ec8fbc 100644 --- a/core/src/io/anuke/mindustry/content/blocks/TurretBlocks.java +++ b/core/src/io/anuke/mindustry/content/blocks/TurretBlocks.java @@ -73,10 +73,10 @@ public class TurretBlocks extends BlockList implements ContentList { health = 360; 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.alpha(entity.liquids.amount / liquidCapacity); + Draw.color(entity.liquids.current().color); + Draw.alpha(entity.liquids.total() / liquidCapacity); Draw.rect(name + "-liquid", tile.drawx() + tr2.x, tile.drawy() + tr2.y, entity.rotation - 90); Draw.color(); }; @@ -145,7 +145,7 @@ public class TurretBlocks extends BlockList implements ContentList { ammoUseEffect = ShootFx.shellEjectBig; 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 offsety = -(int) (Mathf.abscurve(Mathf.curve(entity.reload / reload, 0.3f, 0.2f)) * 2f); diff --git a/core/src/io/anuke/mindustry/core/Control.java b/core/src/io/anuke/mindustry/core/Control.java index 70fce441cd..1c53e73208 100644 --- a/core/src/io/anuke/mindustry/core/Control.java +++ b/core/src/io/anuke/mindustry/core/Control.java @@ -20,7 +20,6 @@ import io.anuke.mindustry.input.MobileInput; import io.anuke.mindustry.io.Map; import io.anuke.mindustry.io.Saves; import io.anuke.mindustry.net.Net; -import io.anuke.mindustry.type.Item; import io.anuke.mindustry.type.Recipe; import io.anuke.mindustry.ui.dialogs.FloatingDialog; import io.anuke.ucore.core.*; @@ -264,11 +263,7 @@ public class Control extends Module{ if(entity == null) return; - for (int i = 0; i < entity.items.items.length; i++) { - if(entity.items.items[i] <= 0) continue; - Item item = Item.getByID(i); - control.database().unlockContent(item); - } + entity.items.forEach((item, amount) -> control.database().unlockContent(item)); if(players[0].inventory.hasItem()){ 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 ++){ 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)){ ui.hudfrag.showUnlock(recipe); } diff --git a/core/src/io/anuke/mindustry/core/Logic.java b/core/src/io/anuke/mindustry/core/Logic.java index b137d380f0..d065be9098 100644 --- a/core/src/io/anuke/mindustry/core/Logic.java +++ b/core/src/io/anuke/mindustry/core/Logic.java @@ -54,12 +54,12 @@ public class Logic extends Module { if(debug) { for (Item item : Item.all()) { if (item.type == ItemType.material) { - tile.entity.items.addItem(item, 1000); + tile.entity.items.add(item, 1000); } } }else{ - tile.entity.items.addItem(Items.tungsten, 50); - tile.entity.items.addItem(Items.lead, 20); + tile.entity.items.add(Items.tungsten, 50); + tile.entity.items.add(Items.lead, 20); } } } @@ -158,13 +158,6 @@ public class Logic extends Module { for(EntityGroup group : unitGroups){ if(!group.isEmpty()){ EntityPhysics.collideGroups(bulletGroup, group); - - /* - for(EntityGroup other : unitGroups){ - if(!other.isEmpty()){ - EntityPhysics.collideGroups(group, other); - } - }*/ } } diff --git a/core/src/io/anuke/mindustry/entities/Player.java b/core/src/io/anuke/mindustry/entities/Player.java index 42c14c2a38..612b9bd379 100644 --- a/core/src/io/anuke/mindustry/entities/Player.java +++ b/core/src/io/anuke/mindustry/entities/Player.java @@ -9,6 +9,7 @@ import com.badlogic.gdx.utils.Queue; import io.anuke.annotations.Annotations.Loc; import io.anuke.annotations.Annotations.Remote; import io.anuke.mindustry.Vars; +import io.anuke.mindustry.content.Mechs; import io.anuke.mindustry.entities.effect.ItemDrop; import io.anuke.mindustry.entities.effect.ScorchDecal; import io.anuke.mindustry.entities.traits.*; @@ -660,6 +661,8 @@ public class Player extends Unit implements BuilderTrait, CarryTrait, ShooterTra dead = true; trail.clear(); health = maxHealth(); + mech = (mobile ? Mechs.starterMobile : Mechs.starterDesktop); + placeQueue.clear(); add(); } diff --git a/core/src/io/anuke/mindustry/entities/TileEntity.java b/core/src/io/anuke/mindustry/entities/TileEntity.java index 75a4d1f1e5..3347ed4ccf 100644 --- a/core/src/io/anuke/mindustry/entities/TileEntity.java +++ b/core/src/io/anuke/mindustry/entities/TileEntity.java @@ -1,6 +1,7 @@ package io.anuke.mindustry.entities; import com.badlogic.gdx.math.Vector2; +import com.badlogic.gdx.utils.Array; import io.anuke.annotations.Annotations.Loc; import io.anuke.annotations.Annotations.Remote; 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.net.In; import io.anuke.mindustry.world.Block; +import io.anuke.mindustry.world.consumers.Consume; import io.anuke.mindustry.world.Tile; import io.anuke.mindustry.world.blocks.Wall; -import io.anuke.mindustry.world.blocks.modules.InventoryModule; -import io.anuke.mindustry.world.blocks.modules.LiquidModule; -import io.anuke.mindustry.world.blocks.modules.PowerModule; +import io.anuke.mindustry.world.modules.InventoryModule; +import io.anuke.mindustry.world.modules.LiquidModule; +import io.anuke.mindustry.world.modules.PowerModule; import io.anuke.ucore.core.Effects; import io.anuke.ucore.core.Timers; import io.anuke.ucore.entities.EntityGroup; @@ -42,6 +44,8 @@ public class TileEntity extends BaseEntity implements TargetTrait { public InventoryModule items; public LiquidModule liquids; + public Array consumers = new Array<>(); + private boolean dead = false; private boolean sleeping; private float sleepTime; @@ -55,14 +59,10 @@ public class TileEntity extends BaseEntity implements TargetTrait { health = tile.block().health; timer = new Timer(tile.block().timers); + tile.block().setConsumers(consumers); if(added){ - //if(!tile.block().autoSleep) { //TODO only autosleep when creating a fresh block! - add(); - /*}else{ - sleeping = true; - sleepingEntities ++; - }*/ + add(); } return this; @@ -160,6 +160,9 @@ public class TileEntity extends BaseEntity implements TargetTrait { } tile.block().update(tile); + for(Consume cons : consumers){ + cons.update(this); + } } } diff --git a/core/src/io/anuke/mindustry/entities/Unit.java b/core/src/io/anuke/mindustry/entities/Unit.java index 4808b740a4..80bbd239a7 100644 --- a/core/src/io/anuke/mindustry/entities/Unit.java +++ b/core/src/io/anuke/mindustry/entities/Unit.java @@ -197,6 +197,7 @@ public abstract class Unit extends DestructibleEntity implements SaveTrait, Targ } public void avoidOthers(float avoidRange){ + if(Net.client()) return; 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; diff --git a/core/src/io/anuke/mindustry/entities/effect/ItemTransfer.java b/core/src/io/anuke/mindustry/entities/effect/ItemTransfer.java index 340073caa4..2e119b99ea 100644 --- a/core/src/io/anuke/mindustry/entities/effect/ItemTransfer.java +++ b/core/src/io/anuke/mindustry/entities/effect/ItemTransfer.java @@ -57,7 +57,7 @@ public class ItemTransfer extends TimedEntity implements DrawTrait{ for (int i = 0; i < Mathf.clamp(amount/3, 1, 8); i++) { 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){ diff --git a/core/src/io/anuke/mindustry/entities/units/types/Drone.java b/core/src/io/anuke/mindustry/entities/units/types/Drone.java index 89d7885892..f26a6796df 100644 --- a/core/src/io/anuke/mindustry/entities/units/types/Drone.java +++ b/core/src/io/anuke/mindustry/entities/units/types/Drone.java @@ -181,7 +181,7 @@ public class Drone extends FlyingUnit implements BuilderTrait { if(entity == null){ 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(){ @@ -247,7 +247,7 @@ public class Drone extends FlyingUnit implements BuilderTrait { //if it's missing requirements, try and mine them 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; getPlaceQueue().clear(); setState(mine); diff --git a/core/src/io/anuke/mindustry/input/DefaultKeybinds.java b/core/src/io/anuke/mindustry/input/DefaultKeybinds.java index 5c9bfafa21..4941ba130e 100644 --- a/core/src/io/anuke/mindustry/input/DefaultKeybinds.java +++ b/core/src/io/anuke/mindustry/input/DefaultKeybinds.java @@ -32,7 +32,6 @@ public class DefaultKeybinds { "menu", Gdx.app.getType() == ApplicationType.Android ? Input.BACK : Input.ESCAPE, "pause", Input.SPACE, "toggle_menus", Input.C, - "item_withdraw", Input.SHIFT_LEFT, new Category("Multiplayer"), "player_list", Input.TAB, "chat", Input.ENTER, diff --git a/core/src/io/anuke/mindustry/input/InputHandler.java b/core/src/io/anuke/mindustry/input/InputHandler.java index 57b3a99908..68e048cf3e 100644 --- a/core/src/io/anuke/mindustry/input/InputHandler.java +++ b/core/src/io/anuke/mindustry/input/InputHandler.java @@ -129,7 +129,7 @@ public abstract class InputHandler extends InputAdapter{ //consume tap event if necessary if(tile.getTeam() == player.getTeam() && tile.block().consumesTap){ 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); consumed = true; showedInventory = true; diff --git a/core/src/io/anuke/mindustry/ui/fragments/BlockInventoryFragment.java b/core/src/io/anuke/mindustry/ui/fragments/BlockInventoryFragment.java index 16e0dc602c..bbfc861d77 100644 --- a/core/src/io/anuke/mindustry/ui/fragments/BlockInventoryFragment.java +++ b/core/src/io/anuke/mindustry/ui/fragments/BlockInventoryFragment.java @@ -16,7 +16,6 @@ import io.anuke.mindustry.type.Item; import io.anuke.mindustry.ui.ItemImage; import io.anuke.mindustry.world.Tile; import io.anuke.ucore.core.Graphics; -import io.anuke.ucore.core.Inputs; import io.anuke.ucore.core.Timers; import io.anuke.ucore.function.BooleanProvider; 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.Strings; -import static io.anuke.mindustry.Vars.mobile; -import static io.anuke.mindustry.Vars.state; -import static io.anuke.mindustry.Vars.tilesize; +import static io.anuke.mindustry.Vars.*; public class BlockInventoryFragment extends Fragment { private final static float holdWithdraw = 40f; @@ -58,7 +55,7 @@ public class BlockInventoryFragment extends Fragment { public void showFor(Tile t){ 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); } @@ -80,14 +77,14 @@ public class BlockInventoryFragment extends Fragment { table.background("inventory"); table.setTouchable(Touchable.enabled); 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(); }else{ if(holding && lastItem != null){ holdTime += Timers.delta(); 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); holding = false; holdTime = 0f; @@ -96,9 +93,8 @@ public class BlockInventoryFragment extends Fragment { updateTablePosition(); if(tile.block().hasItems) { - int[] items = tile.entity.items.items; - for (int i = 0; i < items.length; i++) { - if ((items[i] == 0) == container.contains(i)) { + for (int i = 0; i < Item.all().size; i++) { + if ((tile.entity.items.has(Item.getByID(i))) == container.contains(i)) { rebuild(false); } } @@ -113,12 +109,10 @@ public class BlockInventoryFragment extends Fragment { table.defaults().size(mobile ? 16*3 : 16*2).space(6f); if(tile.block().hasItems) { - int[] items = tile.entity.items.items; - for (int i = 0; i < items.length; i++) { - final int f = i; - if (items[i] == 0) continue; + for (int i = 0; i < Item.all().size; i++) { Item item = Item.getByID(i); + if (!tile.entity.items.has(item)) continue; container.add(i); @@ -127,14 +121,14 @@ public class BlockInventoryFragment extends Fragment { HandCursorListener l = new HandCursorListener(); 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(new InputListener(){ @Override public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) { - if(!canPick.get() || items[f] == 0) return false; - int amount = Math.min(Inputs.keyDown("item_withdraw") ? items[f] : 1, player.inventory.itemCapacityUsed(item)); + if(!canPick.get() || !tile.entity.items.has(item)) return false; + int amount = Math.min(1, player.inventory.itemCapacityUsed(item)); CallBlocks.requestItem(player, tile, item, amount); lastItem = item; holding = true; diff --git a/core/src/io/anuke/mindustry/ui/fragments/BlocksFragment.java b/core/src/io/anuke/mindustry/ui/fragments/BlocksFragment.java index ddff5a96ce..673ac7c2aa 100644 --- a/core/src/io/anuke/mindustry/ui/fragments/BlocksFragment.java +++ b/core/src/io/anuke/mindustry/ui/fragments/BlocksFragment.java @@ -244,7 +244,7 @@ public class BlocksFragment extends Fragment{ if(entity == null) return; 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); return; } @@ -328,7 +328,7 @@ public class BlocksFragment extends Fragment{ TileEntity core = players[0].getClosestCore(); 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]"); return color + format(amount) + "[white]/" + stack.amount; diff --git a/core/src/io/anuke/mindustry/world/BaseBlock.java b/core/src/io/anuke/mindustry/world/BaseBlock.java index 9087faf510..2913a18222 100644 --- a/core/src/io/anuke/mindustry/world/BaseBlock.java +++ b/core/src/io/anuke/mindustry/world/BaseBlock.java @@ -31,20 +31,20 @@ public abstract class BaseBlock { } 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.*/ public int removeStack(Tile tile, Item item, int amount){ tile.entity.wakeUp(); - tile.entity.items.removeItem(item, amount); + tile.entity.items.remove(item, amount); return amount; } /**Handle a stack input.*/ public void handleStack(Item item, int amount, Tile tile, Unit source){ tile.entity.wakeUp(); - tile.entity.items.addItem(item, amount); + tile.entity.items.add(item, amount); } /**Returns offset for stack placement.*/ @@ -53,7 +53,7 @@ public abstract class BaseBlock { } 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){ @@ -61,17 +61,11 @@ public abstract class BaseBlock { } public boolean acceptLiquid(Tile tile, Tile source, Liquid liquid, float amount){ - return tile.entity.liquids.amount + 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; + return tile.entity.liquids.get(liquid) + amount < liquidCapacity; } public void handleLiquid(Tile tile, Tile source, Liquid liquid, float amount){ - tile.entity.liquids.liquid = liquid; - tile.entity.liquids.amount += amount; + tile.entity.liquids.add(liquid, amount); } public boolean acceptPower(Tile tile, Tile source, float amount){ @@ -87,9 +81,7 @@ public abstract class BaseBlock { return canAccept; } - public void tryDumpLiquid(Tile tile){ - if(tile.entity.liquids.amount < 0.001f) return; - + public void tryDumpLiquid(Tile tile, Liquid liquid){ int size = tile.block().size; GridPoint2[] nearby = Edges.getEdges(size); @@ -102,10 +94,10 @@ public abstract class BaseBlock { if(other != null) other = other.target(); if (other != null && other.block().hasLiquids) { - float ofract = other.entity.liquids.amount / other.block().liquidCapacity; - float fract = tile.entity.liquids.amount / liquidCapacity; + float ofract = other.entity.liquids.get(liquid) / other.block().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); @@ -113,35 +105,34 @@ public abstract class BaseBlock { } - public void tryMoveLiquid(Tile tile, Tile tileSource, Tile next, float amount){ - float flow = Math.min(next.block().liquidCapacity - next.entity.liquids.amount - 0.001f, amount); + public void tryMoveLiquid(Tile tile, Tile tileSource, Tile next, float amount, Liquid liquid){ + float flow = Math.min(next.block().liquidCapacity - next.entity.liquids.get(liquid) - 0.001f, amount); - if(next.block().acceptLiquid(next, tileSource, tile.entity.liquids.liquid, flow)){ - next.block().handleLiquid(next, tileSource, tile.entity.liquids.liquid, flow); - tile.entity.liquids.amount -= flow; + if(next.block().acceptLiquid(next, tileSource, liquid, flow)){ + next.block().handleLiquid(next, tileSource, liquid, 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; 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) && - next.block().acceptLiquid(next, tile, tile.entity.liquids.liquid, 0f)) { - float ofract = next.entity.liquids.amount / next.block().liquidCapacity; - float fract = tile.entity.liquids.amount / liquidCapacity; - float flow = Math.min(Mathf.clamp((fract - ofract) * (1f)) * (liquidCapacity), tile.entity.liquids.amount); - flow = Math.min(flow, next.block().liquidCapacity - next.entity.liquids.amount - 0.001f); + if(next.block().acceptLiquid(next, tile, liquid, 0f)) { + float ofract = next.entity.liquids.get(liquid) / next.block().liquidCapacity; + float fract = tile.entity.liquids.get(liquid) / liquidCapacity; + float flow = Math.min(Mathf.clamp((fract - ofract) * (1f)) * (liquidCapacity), tile.entity.liquids.get(liquid)); + flow = Math.min(flow, next.block().liquidCapacity - next.entity.liquids.get(liquid) - 0.001f); - if (flow > 0f && ofract <= fract && next.block().acceptLiquid(next, tile, tile.entity.liquids.liquid, flow)) { - next.block().handleLiquid(next, tile, tile.entity.liquids.liquid, flow); - tile.entity.liquids.amount -= flow; + if (flow > 0f && ofract <= fract && next.block().acceptLiquid(next, tile, liquid, flow)) { + next.block().handleLiquid(next, tile, liquid, flow); + tile.entity.liquids.remove(liquid, flow); return flow; } 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) || (liquid.flammability > 0.3f && other.temperature > 0.7f)) { tile.entity.damage(1 * Timers.delta()); @@ -151,20 +142,17 @@ public abstract class BaseBlock { } } else if ((liquid.temperature > 0.7f && other.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())) { 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){ - float leakAmount = Math.min(tile.entity.liquids.amount, tile.entity.liquids.amount/1.5f); - Puddle.deposit(next, tile, tile.entity.liquids.liquid, leakAmount); - tile.entity.liquids.amount -= leakAmount; + float leakAmount = tile.entity.liquids.get(liquid)/1.5f; + Puddle.deposit(next, tile, liquid, leakAmount); + tile.entity.liquids.remove(liquid, leakAmount); } return 0; } @@ -198,7 +186,7 @@ public abstract class BaseBlock { /**Try dumping a specific item near the tile.*/ 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; @@ -216,9 +204,9 @@ public abstract class BaseBlock { 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); - tile.entity.items.removeItem(item, 1); + tile.entity.items.remove(item, 1); i = (byte)((i + 1) % nearby.length); tile.setDump(i); return true; diff --git a/core/src/io/anuke/mindustry/world/Block.java b/core/src/io/anuke/mindustry/world/Block.java index 987041b034..51f5bce094 100644 --- a/core/src/io/anuke/mindustry/world/Block.java +++ b/core/src/io/anuke/mindustry/world/Block.java @@ -5,7 +5,6 @@ import com.badlogic.gdx.graphics.g2d.TextureRegion; import com.badlogic.gdx.utils.Array; import com.badlogic.gdx.utils.ObjectMap; 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.Player; 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.type.Item; 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.ucore.core.Timers; 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.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{ private static int lastid; @@ -46,6 +46,9 @@ public class Block extends BaseBlock implements Content{ protected TextureRegion[] compactIcon; protected TextureRegion editorIcon; + protected TextureRegion shadowRegion; + protected TextureRegion region; + /**internal name*/ public final String name; /**internal ID*/ @@ -72,12 +75,8 @@ public class Block extends BaseBlock implements Content{ public int health = -1; /**base block explosiveness*/ public float baseExplosiveness = 0f; - /**whether to display a different shadow per variant*/ - public boolean varyShadow = false; /**whether this block can be placed on liquids.*/ public boolean floating = true; - /**number of block variants, 0 to disable*/ - public int variants = 0; /**stuff that drops when broken*/ public ItemStack drops = null; /**multiblock size*/ @@ -110,10 +109,6 @@ public class Block extends BaseBlock implements Content{ public boolean autoSleep; /**Name of shadow region to load. Null to indicate normal shadow.*/ 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.*/ public boolean configurable; /**Whether this block consumes touchDown events when tapped.*/ @@ -138,6 +133,10 @@ public class Block extends BaseBlock implements Content{ blocks.add(this); } + public void setConsumers(Array consumers){ + + } + public boolean isLayer(Tile tile){return true;} public boolean isLayer2(Tile tile){return true;} public void drawLayer(Tile tile){} @@ -173,13 +172,7 @@ public class Block extends BaseBlock implements Content{ @Override public void load() { shadowRegion = Draw.region(shadow == null ? "shadow-" + size : shadow); - - if(varyShadow && variants > 0) { - shadowRegions = new TextureRegion[variants]; - for(int i = 0; i < variants; i ++){ - shadowRegions[i] = Draw.region(name + "shadow" + (i + 1)); - } - } + region = Draw.region(name); } /**Called when the block is tapped.*/ @@ -236,8 +229,8 @@ public class Block extends BaseBlock implements Content{ //TODO make this easier to config. public void setBars(){ if(hasPower) bars.add(new BlockBar(BarType.power, true, tile -> tile.entity.power.amount / powerCapacity)); - if(hasLiquids) bars.add(new BlockBar(BarType.liquid, true, tile -> tile.entity.liquids.amount / liquidCapacity)); - if(hasItems) bars.add(new BlockBar(BarType.inventory, true, tile -> (float)tile.entity.items.totalItems() / itemCapacity)); + 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.total() / itemCapacity)); } public String name(){ @@ -276,14 +269,13 @@ public class Block extends BaseBlock implements Content{ float x = tile.worldx(), y = tile.worldy(); float explosiveness = baseExplosiveness; float flammability = 0f; - float heat = 0f; float power = 0f; int units = 1; tempColor.set(Palette.darkFlame); if(hasItems){ for(Item item : Item.all()){ - int amount = tile.entity.items.getItem(item); + int amount = tile.entity.items.get(item); explosiveness += item.explosiveness*amount; flammability += item.flammability*amount; @@ -295,15 +287,8 @@ public class Block extends BaseBlock implements Content{ } if(hasLiquids){ - float amount = tile.entity.liquids.amount; - explosiveness += tile.entity.liquids.liquid.explosiveness*amount/2f; - flammability += tile.entity.liquids.liquid.flammability*amount/2f; - heat += Mathf.clamp(tile.entity.liquids.liquid.temperature-0.5f)*amount/2f; - - if(tile.entity.liquids.liquid.flammability*amount > 2f){ - units ++; - Hue.addu(tempColor, tile.entity.liquids.liquid.flameColor); - } + flammability += tile.entity.liquids.sum((liquid, amount) -> liquid.explosiveness * amount/2f); + explosiveness += tile.entity.liquids.sum((liquid, amount) -> liquid.flammability * amount/2f); } if(hasPower){ @@ -314,17 +299,18 @@ public class Block extends BaseBlock implements Content{ if(hasLiquids) { - Liquid liquid = tile.entity.liquids.liquid; - float splash = Mathf.clamp(tile.entity.liquids.amount / 4f, 0f, 10f); + tile.entity.liquids.forEach((liquid, amount) -> { + float splash = Mathf.clamp(amount / 4f, 0f, 10f); - for (int i = 0; i < Mathf.clamp(tile.entity.liquids.amount / 5, 0, 30); i++) { - Timers.run(i / 2, () -> { - Tile other = world.tile(tile.x + Mathf.range(size / 2), tile.y + Mathf.range(size / 2)); - if (other != null) { - Puddle.deposit(other, liquid, splash); - } - }); - } + for (int i = 0; i < Mathf.clamp(amount / 5, 0, 30); i++) { + Timers.run(i / 2, () -> { + Tile other = world.tile(tile.x + Mathf.range(size / 2), tile.y + Mathf.range(size / 2)); + if (other != null) { + Puddle.deposit(other, liquid, splash); + } + }); + } + }); } Damage.dynamicExplosion(x, y, flammability, explosiveness, power, tilesize * size/2f, tempColor); @@ -342,14 +328,12 @@ public class Block extends BaseBlock implements Content{ } return 0; }else{ - float result = 0f; - for (int i = 0; i < Item.all().size; i++) { - int amount = tile.entity.items.items[i]; - result += Item.getByID(i).flammability*amount; - } + float result = tile.entity.items.sum((item, amount) -> item.flammability * amount); + 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; } } @@ -411,30 +395,13 @@ public class Block extends BaseBlock implements Content{ } public void draw(Tile tile){ - //note: multiblocks do not support rotation - 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(); - } + Draw.rect(region, tile.drawx(), tile.drawy(), rotate ? tile.getRotation() * 90 : 0); } public void drawNonLayer(Tile tile){} 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()); - } + Draw.rect(shadowRegion, tile.drawx(), tile.drawy()); } /**Offset for placing and drawing multiblocks.*/ @@ -456,7 +423,7 @@ public class Block extends BaseBlock implements Content{ "entity.x", tile.entity.x, "entity.y", tile.entity.y, "entity.id", tile.entity.id, - "entity.items.total", hasItems ? tile.entity.items.totalItems() : null + "entity.items.total", hasItems ? tile.entity.items.total() : null ); } diff --git a/core/src/io/anuke/mindustry/world/Consumption.java b/core/src/io/anuke/mindustry/world/Consumption.java deleted file mode 100644 index e3d491e50b..0000000000 --- a/core/src/io/anuke/mindustry/world/Consumption.java +++ /dev/null @@ -1,4 +0,0 @@ -package io.anuke.mindustry.world; - -public class Consumption { -} diff --git a/core/src/io/anuke/mindustry/world/Tile.java b/core/src/io/anuke/mindustry/world/Tile.java index 3f60494762..3393a2de39 100644 --- a/core/src/io/anuke/mindustry/world/Tile.java +++ b/core/src/io/anuke/mindustry/world/Tile.java @@ -10,9 +10,9 @@ import io.anuke.mindustry.entities.traits.TargetTrait; import io.anuke.mindustry.game.Team; import io.anuke.mindustry.type.Recipe; import io.anuke.mindustry.world.blocks.Floor; -import io.anuke.mindustry.world.blocks.modules.InventoryModule; -import io.anuke.mindustry.world.blocks.modules.LiquidModule; -import io.anuke.mindustry.world.blocks.modules.PowerModule; +import io.anuke.mindustry.world.modules.InventoryModule; +import io.anuke.mindustry.world.modules.LiquidModule; +import io.anuke.mindustry.world.modules.PowerModule; import io.anuke.ucore.entities.trait.PosTrait; import io.anuke.ucore.function.Consumer; import io.anuke.ucore.util.Bits; diff --git a/core/src/io/anuke/mindustry/world/blocks/BlendBlock.java b/core/src/io/anuke/mindustry/world/blocks/BlendBlock.java deleted file mode 100644 index 7c01a052be..0000000000 --- a/core/src/io/anuke/mindustry/world/blocks/BlendBlock.java +++ /dev/null @@ -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 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()); - } - } - } -} diff --git a/core/src/io/anuke/mindustry/world/blocks/BuildBlock.java b/core/src/io/anuke/mindustry/world/blocks/BuildBlock.java index f672045459..5b03df2d21 100644 --- a/core/src/io/anuke/mindustry/world/blocks/BuildBlock.java +++ b/core/src/io/anuke/mindustry/world/blocks/BuildBlock.java @@ -22,7 +22,7 @@ import io.anuke.mindustry.type.Recipe; import io.anuke.mindustry.world.BarType; import io.anuke.mindustry.world.Block; 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.ucore.core.Effects; import io.anuke.ucore.core.Graphics; @@ -157,11 +157,10 @@ public class BuildBlock extends Block { } @Remote(called = Loc.server, in = In.blocks) - public static void onConstructFinish(Tile tile, Block block, int builderID, byte rotation){ - Team team = tile.getTeam(); + public static void onConstructFinish(Tile tile, Block block, int builderID, byte rotation, Team team){ tile.setBlock(block); - tile.setTeam(team); tile.setRotation(rotation); + tile.setTeam(team); Effects.effect(Fx.placeBlock, tile.drawx(), tile.drawy(), block.size); //last builder was this local client player, call placed() @@ -197,7 +196,7 @@ public class BuildBlock extends Block { progress = Mathf.clamp(progress + maxProgress); 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 ++){ 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; }else if(required > 0){ //if this amount is positive... //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 float fraction = maxUse / (float)required; @@ -248,7 +247,7 @@ public class BuildBlock extends Block { //remove stuff that is actually used 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 diff --git a/core/src/io/anuke/mindustry/world/blocks/Floor.java b/core/src/io/anuke/mindustry/world/blocks/Floor.java index 435b4f99a6..37c2938516 100644 --- a/core/src/io/anuke/mindustry/world/blocks/Floor.java +++ b/core/src/io/anuke/mindustry/world/blocks/Floor.java @@ -35,6 +35,8 @@ public class Floor extends Block{ protected Predicate blends = block -> block != this && !block.blendOverride(this); protected boolean blend = true; + /**number of different variant regions to use*/ + public int variants = 0; /**edge fallback, used mainly for ores*/ public String edge = "stone"; /**Multiplies unit velocity by this when walked on.*/ diff --git a/core/src/io/anuke/mindustry/world/blocks/LiquidBlock.java b/core/src/io/anuke/mindustry/world/blocks/LiquidBlock.java index bda16d1167..9feefc53b8 100644 --- a/core/src/io/anuke/mindustry/world/blocks/LiquidBlock.java +++ b/core/src/io/anuke/mindustry/world/blocks/LiquidBlock.java @@ -4,11 +4,11 @@ import com.badlogic.gdx.graphics.g2d.TextureRegion; import io.anuke.mindustry.world.Block; import io.anuke.mindustry.world.meta.BlockGroup; 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; public class LiquidBlock extends Block{ - protected String liquidRegion = name() + "-liquid"; + protected TextureRegion liquidRegion, bottomRegion, topRegion; public LiquidBlock(String name) { super(name); @@ -18,6 +18,15 @@ public class LiquidBlock extends Block{ 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 public TextureRegion[] getIcon(){ 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; - Draw.rect(name() + "-bottom", tile.drawx(), tile.drawy(), rotation); + Draw.rect(bottomRegion, tile.drawx(), tile.drawy(), rotation); - if(mod.amount > 0.001f){ - Draw.color(mod.liquid.color); - Draw.alpha(mod.amount / liquidCapacity); + if(mod.total() > 0.001f){ + Draw.color(mod.current().color); + Draw.alpha(mod.total() / liquidCapacity); Draw.rect(liquidRegion, tile.drawx(), tile.drawy(), rotation); Draw.color(); } - Draw.rect(name() + "-top", tile.drawx(), tile.drawy(), rotation); + Draw.rect(topRegion, tile.drawx(), tile.drawy(), rotation); } } diff --git a/core/src/io/anuke/mindustry/world/blocks/Rock.java b/core/src/io/anuke/mindustry/world/blocks/Rock.java index f6c463ece5..40066e08ec 100644 --- a/core/src/io/anuke/mindustry/world/blocks/Rock.java +++ b/core/src/io/anuke/mindustry/world/blocks/Rock.java @@ -1,13 +1,51 @@ package io.anuke.mindustry.world.blocks; +import com.badlogic.gdx.graphics.g2d.TextureRegion; 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 { + protected TextureRegion[] shadowRegions, regions; + protected int variants; public Rock(String name) { super(name); - varyShadow = true; breakable = 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)); + } + } + } } diff --git a/core/src/io/anuke/mindustry/world/blocks/defense/Door.java b/core/src/io/anuke/mindustry/world/blocks/defense/Door.java index c147d97e48..824fbaa961 100644 --- a/core/src/io/anuke/mindustry/world/blocks/defense/Door.java +++ b/core/src/io/anuke/mindustry/world/blocks/defense/Door.java @@ -45,7 +45,7 @@ public class Door extends Wall{ DoorEntity entity = tile.entity(); if(!entity.open){ - Draw.rect(name, tile.drawx(), tile.drawy()); + Draw.rect(region, tile.drawx(), tile.drawy()); }else{ Draw.rect(openRegion, tile.drawx(), tile.drawy()); } diff --git a/core/src/io/anuke/mindustry/world/blocks/defense/turrets/CooledTurret.java b/core/src/io/anuke/mindustry/world/blocks/defense/turrets/CooledTurret.java index b1588f85af..7ca7f09a9e 100644 --- a/core/src/io/anuke/mindustry/world/blocks/defense/turrets/CooledTurret.java +++ b/core/src/io/anuke/mindustry/world/blocks/defense/turrets/CooledTurret.java @@ -38,17 +38,18 @@ public class CooledTurret extends Turret { super.updateShooting(tile); 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)); - entity.reload += (used * entity.liquids.liquid.heatCapacity) / entity.liquids.liquid.heatCapacity; - entity.liquids.amount -= used; + 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 * liquid.heatCapacity) / liquid.heatCapacity; + entity.liquids.remove(liquid, used); if(Mathf.chance(0.04 * used)){ Effects.effect(coolEffect, tile.drawx() + Mathf.range(size * tilesize/2f), tile.drawy() + Mathf.range(size * tilesize/2f)); } //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); } } diff --git a/core/src/io/anuke/mindustry/world/blocks/defense/turrets/ItemTurret.java b/core/src/io/anuke/mindustry/world/blocks/defense/turrets/ItemTurret.java index 1fdfbdc39d..d1b1fde9c8 100644 --- a/core/src/io/anuke/mindustry/world/blocks/defense/turrets/ItemTurret.java +++ b/core/src/io/anuke/mindustry/world/blocks/defense/turrets/ItemTurret.java @@ -60,7 +60,7 @@ public class ItemTurret extends CooledTurret { AmmoType type = ammoMap.get(item); entity.totalAmmo += type.quantityMultiplier; - entity.items.addItem(item, 1); + entity.items.add(item, 1); //find ammo entry by type for(int i = 0; i < entity.ammo.size; i ++){ diff --git a/core/src/io/anuke/mindustry/world/blocks/defense/turrets/Turret.java b/core/src/io/anuke/mindustry/world/blocks/defense/turrets/Turret.java index 9feeb9d9a3..abebf95b80 100644 --- a/core/src/io/anuke/mindustry/world/blocks/defense/turrets/Turret.java +++ b/core/src/io/anuke/mindustry/world/blocks/defense/turrets/Turret.java @@ -27,7 +27,10 @@ import io.anuke.ucore.core.Timers; import io.anuke.ucore.function.BiConsumer; import io.anuke.ucore.graphics.Draw; 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.DataOutputStream; @@ -66,8 +69,9 @@ public abstract class Turret extends Block{ protected TextureRegion heatRegion; protected TextureRegion baseTopRegion; - protected BiConsumer drawer = (tile, entity) -> Draw.rect(name, tile.drawx() + tr2.x, tile.drawy() + tr2.y, entity.rotation - 90); + protected BiConsumer drawer = (tile, entity) -> Draw.rect(region, tile.drawx() + tr2.x, tile.drawy() + tr2.y, entity.rotation - 90); protected BiConsumer heatDrawer = (tile, entity) ->{ + if(entity.heat <= 0.00001f) return; Graphics.setAdditiveBlending(); Draw.color(heatColor); Draw.alpha(entity.heat); @@ -129,7 +133,7 @@ public abstract class Turret extends Block{ drawer.accept(tile, entity); - if(Draw.hasRegion(name + "-heat")){ + if(heatRegion != null){ heatDrawer.accept(tile, entity); } diff --git a/core/src/io/anuke/mindustry/world/blocks/distribution/BufferedItemBridge.java b/core/src/io/anuke/mindustry/world/blocks/distribution/BufferedItemBridge.java index 2a366bf0d4..c16ae2f2bf 100644 --- a/core/src/io/anuke/mindustry/world/blocks/distribution/BufferedItemBridge.java +++ b/core/src/io/anuke/mindustry/world/blocks/distribution/BufferedItemBridge.java @@ -26,8 +26,8 @@ public class BufferedItemBridge extends ExtendingItemBridge { public void updateTransport(Tile tile, Tile other){ BufferedItemBridgeEntity entity = tile.entity(); - if(entity.buffer.accepts() && entity.items.totalItems() > 0){ - entity.buffer.accept(entity.items.takeItem()); + if(entity.buffer.accepts() && entity.items.total() > 0){ + entity.buffer.accept(entity.items.take()); } Item item = entity.buffer.poll(); diff --git a/core/src/io/anuke/mindustry/world/blocks/distribution/Conduit.java b/core/src/io/anuke/mindustry/world/blocks/distribution/Conduit.java index ecaf8d1cea..f20d9d80af 100644 --- a/core/src/io/anuke/mindustry/world/blocks/distribution/Conduit.java +++ b/core/src/io/anuke/mindustry/world/blocks/distribution/Conduit.java @@ -5,7 +5,7 @@ import io.anuke.mindustry.entities.TileEntity; import io.anuke.mindustry.type.Liquid; import io.anuke.mindustry.world.Tile; 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.util.Mathf; @@ -18,11 +18,17 @@ public class Conduit extends LiquidBlock { public Conduit(String name) { super(name); - liquidRegion = "conduit-liquid"; rotate = true; solid = false; } + @Override + public void load() { + super.load(); + + liquidRegion = Draw.region("conduit-liquid"); + } + @Override public void draw(Tile tile){ ConduitEntity entity = tile.entity(); @@ -30,23 +36,23 @@ public class Conduit extends LiquidBlock { 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.rect(liquidRegion, tile.drawx(), tile.drawy(), rotation); Draw.color(); - Draw.rect(name() + "-top", tile.drawx(), tile.drawy(), rotation); + Draw.rect(topRegion, tile.drawx(), tile.drawy(), rotation); } @Override public void update(Tile tile){ 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)){ - tryMoveLiquid(tile, tile.getNearby(tile.getRotation()), true); + if(tile.entity.liquids.total() > 0.001f && tile.entity.timer.get(timerFlow, 1)){ + tryMoveLiquid(tile, tile.getNearby(tile.getRotation()), true, tile.entity.liquids.current()); entity.wakeUp(); }else{ entity.sleep(); @@ -61,7 +67,8 @@ public class Conduit extends LiquidBlock { @Override public boolean acceptLiquid(Tile tile, Tile source, Liquid liquid, float amount) { 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 diff --git a/core/src/io/anuke/mindustry/world/blocks/distribution/Conveyor.java b/core/src/io/anuke/mindustry/world/blocks/distribution/Conveyor.java index 47c2de709a..d47d269d16 100644 --- a/core/src/io/anuke/mindustry/world/blocks/distribution/Conveyor.java +++ b/core/src/io/anuke/mindustry/world/blocks/distribution/Conveyor.java @@ -189,7 +189,7 @@ public class Conveyor extends Block{ if (pos.y >= 0.9999f && offloadDir(tile, pos.item)) { minremove = Math.min(i, minremove); totalMoved = 1f; - tile.entity.items.removeItem(pos.item, 1); + tile.entity.items.remove(pos.item, 1); } else { value = pos.pack(); @@ -232,7 +232,7 @@ public class Conveyor extends Block{ ItemPos pos = pos1.set(val, ItemPos.drawShorts); if(pos.item == item){ entity.convey.removeValue(val); - entity.items.removeItem(item, 1); + entity.items.remove(item, 1); removed ++; break; } @@ -258,7 +258,7 @@ public class Conveyor extends Block{ long result = ItemPos.packItem(item, 0f, 0f, (byte)Mathf.random(255)); entity.convey.insert(0, result); - entity.items.addItem(item, 1); + entity.items.add(item, 1); entity.wakeUp(); } @@ -285,7 +285,7 @@ public class Conveyor extends Block{ long result = ItemPos.packItem(item, y*0.9f, pos, (byte)Mathf.random(255)); boolean inserted = false; - tile.entity.items.addItem(item, 1); + tile.entity.items.add(item, 1); for(int i = 0; i < entity.convey.size; i ++){ if(compareItems(result, entity.convey.get(i)) < 0){ diff --git a/core/src/io/anuke/mindustry/world/blocks/distribution/ExtendingItemBridge.java b/core/src/io/anuke/mindustry/world/blocks/distribution/ExtendingItemBridge.java index f427593c6d..4c7309859d 100644 --- a/core/src/io/anuke/mindustry/world/blocks/distribution/ExtendingItemBridge.java +++ b/core/src/io/anuke/mindustry/world/blocks/distribution/ExtendingItemBridge.java @@ -33,14 +33,14 @@ public class ExtendingItemBridge extends ItemBridge { ey *= entity.uptime; Lines.stroke(8f); - Lines.line(Draw.region(name + "-bridge"), + Lines.line(bridgeRegion, tile.worldx() + Geometry.d4[i].x*tilesize/2f, tile.worldy() + Geometry.d4[i].y*tilesize/2f, tile.worldx() + ex, tile.worldy() + ey, CapStyle.none, 0f); - Draw.rect(name + "-end", tile.drawx(), tile.drawy(), i*90 + 90); - Draw.rect(name + "-end", + Draw.rect(endRegion, tile.drawx(), tile.drawy(), i*90 + 90); + Draw.rect(endRegion, tile.worldx() + ex + Geometry.d4[i].x*tilesize/2f, 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 ++){ 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.worldy() + Geometry.d4[i].y*(tilesize/2f + a*6f + 2) * entity.uptime, i*90f); diff --git a/core/src/io/anuke/mindustry/world/blocks/distribution/ItemBridge.java b/core/src/io/anuke/mindustry/world/blocks/distribution/ItemBridge.java index b07b13c57a..cfad7d944e 100644 --- a/core/src/io/anuke/mindustry/world/blocks/distribution/ItemBridge.java +++ b/core/src/io/anuke/mindustry/world/blocks/distribution/ItemBridge.java @@ -1,6 +1,7 @@ package io.anuke.mindustry.world.blocks.distribution; import com.badlogic.gdx.graphics.Color; +import com.badlogic.gdx.graphics.g2d.TextureRegion; import com.badlogic.gdx.utils.IntArray; import com.badlogic.gdx.utils.IntSet; import com.badlogic.gdx.utils.IntSet.IntSetIterator; @@ -38,6 +39,8 @@ public class ItemBridge extends Block { protected float transportTime = 2f; protected IntArray removals = new IntArray(); + protected TextureRegion endRegion, bridgeRegion, arrowRegion; + public ItemBridge(String name) { super(name); update = true; @@ -50,6 +53,13 @@ public class ItemBridge extends Block { hasItems = true; } + @Override + public void load() { + endRegion = Draw.region(name + "-end"); + bridgeRegion = Draw.region(name + "-bridge"); + arrowRegion = Draw.region(name + "-arrow"); + } + @Override public void placed(Tile tile) { Tile last = world.tile(lastPlaced); @@ -162,13 +172,13 @@ public class ItemBridge extends Block { ItemBridgeEntity entity = tile.entity(); 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)){ other.block().handleItem(item, other, tile); entity.cycleSpeed = Mathf.lerpDelta(entity.cycleSpeed, 4f, 0.05f); }else{ entity.cycleSpeed = Mathf.lerpDelta(entity.cycleSpeed, 1f, 0.01f); - if(item != null) entity.items.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.alpha(Math.max(entity.uptime, 0.25f)); - Draw.rect(name + "-end", tile.drawx(), tile.drawy(), i*90 + 90); - Draw.rect(name + "-end", other.drawx(), other.drawy(), i*90 + 270); + Draw.rect(endRegion, tile.drawx(), tile.drawy(), i*90 + 90); + Draw.rect(endRegion, other.drawx(), other.drawy(), i*90 + 270); Lines.stroke(8f); - Lines.line(Draw.region(name + "-bridge"), + Lines.line(bridgeRegion, tile.worldx(), tile.worldy(), other.worldx(), @@ -204,7 +214,7 @@ public class ItemBridge extends Block { for(int a = 0; a < arrows; a ++){ 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.worldy() + Geometry.d4[i].y*(tilesize/2f + a*4f + time % 4f), i*90f); @@ -214,7 +224,7 @@ public class ItemBridge extends Block { @Override public boolean acceptItem(Item item, Tile tile, Tile source) { - return tile.entity.items.totalItems() < itemCapacity; + return tile.entity.items.total() < itemCapacity; } @Override diff --git a/core/src/io/anuke/mindustry/world/blocks/distribution/MassDriver.java b/core/src/io/anuke/mindustry/world/blocks/distribution/MassDriver.java index e0a81c997e..b5492d0e5a 100644 --- a/core/src/io/anuke/mindustry/world/blocks/distribution/MassDriver.java +++ b/core/src/io/anuke/mindustry/world/blocks/distribution/MassDriver.java @@ -64,7 +64,7 @@ public class MassDriver extends Block { if(entity.isUnloading){ tryDump(tile); - if(entity.items.totalItems() <= 0){ + if(entity.items.total() <= 0){ entity.isUnloading = false; } } @@ -79,10 +79,10 @@ public class MassDriver extends Block { Tile waiter = entity.waiting.first(); 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 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(); other.waiting.add(tile); @@ -150,7 +150,7 @@ public class MassDriver extends Block { @Override public boolean acceptItem(Item item, Tile tile, Tile source) { - return tile.entity.items.totalItems() < itemCapacity; + return tile.entity.items.total() < itemCapacity; } @Override @@ -221,7 +221,7 @@ public class MassDriver extends Block { public float reload = 0f; public void handlePayload(Bullet bullet, DriverBulletData data){ - int totalItems = items.totalItems(); + int totalItems = items.total(); //add all the items possible for(int i = 0; i < data.items.length; i ++){ diff --git a/core/src/io/anuke/mindustry/world/blocks/distribution/Router.java b/core/src/io/anuke/mindustry/world/blocks/distribution/Router.java index f34158d190..cd23e1990e 100644 --- a/core/src/io/anuke/mindustry/world/blocks/distribution/Router.java +++ b/core/src/io/anuke/mindustry/world/blocks/distribution/Router.java @@ -21,10 +21,10 @@ public class Router extends Block{ @Override public void update(Tile tile){ 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 ++) { - if (tile.entity.items.totalItems() > 0) { + if (tile.entity.items.total() > 0) { tryDump(tile); moved = true; } @@ -37,7 +37,7 @@ public class Router extends Block{ @Override 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 @@ -48,7 +48,7 @@ public class Router extends Block{ @Override public boolean acceptItem(Item item, Tile tile, Tile source){ - int items = tile.entity.items.totalItems(); + int items = tile.entity.items.total(); return items < itemCapacity; } diff --git a/core/src/io/anuke/mindustry/world/blocks/distribution/TunnelConduit.java b/core/src/io/anuke/mindustry/world/blocks/distribution/TunnelConduit.java index 1b636cd22a..a342a41efc 100644 --- a/core/src/io/anuke/mindustry/world/blocks/distribution/TunnelConduit.java +++ b/core/src/io/anuke/mindustry/world/blocks/distribution/TunnelConduit.java @@ -33,7 +33,7 @@ public class TunnelConduit extends LiquidBlock { @Override 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 diff --git a/core/src/io/anuke/mindustry/world/blocks/distribution/WarpGate.java b/core/src/io/anuke/mindustry/world/blocks/distribution/WarpGate.java index 622170e01a..5d7b1488b6 100644 --- a/core/src/io/anuke/mindustry/world/blocks/distribution/WarpGate.java +++ b/core/src/io/anuke/mindustry/world/blocks/distribution/WarpGate.java @@ -147,7 +147,7 @@ public class WarpGate extends PowerBlock{ teleporters[entity.color].add(tile); - if(entity.items.totalItems() > 0){ + if(entity.items.total() > 0){ tryDump(tile); } @@ -210,7 +210,7 @@ public class WarpGate extends PowerBlock{ 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)) { Array testLinks = findLinks(tile); @@ -226,12 +226,12 @@ public class WarpGate extends PowerBlock{ Array links = findLinks(tile); for (Tile other : links) { - int canAccept = itemCapacity - other.entity.items.totalItems(); - int total = entity.items.totalItems(); + int canAccept = itemCapacity - other.entity.items.total(); + int total = entity.items.total(); if (total == 0) break; Effects.effect(teleportOutEffect, resultColor, other.drawx(), other.drawy()); 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()); @@ -271,7 +271,7 @@ public class WarpGate extends PowerBlock{ @Override public boolean acceptItem(Item item, Tile tile, Tile source){ TeleporterEntity entity = tile.entity(); - return entity.items.totalItems() < itemCapacity; + return entity.items.total() < itemCapacity; } @Override @@ -323,7 +323,7 @@ public class WarpGate extends PowerBlock{ if(!oe.active) continue; if(oe.color != entity.color){ removal.add(other); - }else if(other.entity.items.totalItems() == 0){ + }else if(other.entity.items.total() == 0){ returns.add(other); } }else{ diff --git a/core/src/io/anuke/mindustry/world/blocks/modules/InventoryModule.java b/core/src/io/anuke/mindustry/world/blocks/modules/InventoryModule.java deleted file mode 100644 index b989c9b952..0000000000 --- a/core/src/io/anuke/mindustry/world/blocks/modules/InventoryModule.java +++ /dev/null @@ -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; - } - } -} diff --git a/core/src/io/anuke/mindustry/world/blocks/modules/LiquidModule.java b/core/src/io/anuke/mindustry/world/blocks/modules/LiquidModule.java deleted file mode 100644 index 3b26a62247..0000000000 --- a/core/src/io/anuke/mindustry/world/blocks/modules/LiquidModule.java +++ /dev/null @@ -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(); - } -} diff --git a/core/src/io/anuke/mindustry/world/blocks/power/FusionReactor.java b/core/src/io/anuke/mindustry/world/blocks/power/FusionReactor.java index f1bed4b378..a5da34207e 100644 --- a/core/src/io/anuke/mindustry/world/blocks/power/FusionReactor.java +++ b/core/src/io/anuke/mindustry/world/blocks/power/FusionReactor.java @@ -93,7 +93,7 @@ public class FusionReactor extends PowerGenerator { Graphics.setNormalBlending(); - Draw.rect(name, tile.drawx(), tile.drawy()); + Draw.rect(region, tile.drawx(), tile.drawy()); Draw.rect(name + "-top", tile.drawx(), tile.drawy()); diff --git a/core/src/io/anuke/mindustry/world/blocks/power/ItemGenerator.java b/core/src/io/anuke/mindustry/world/blocks/power/ItemGenerator.java index 63f551c112..265ae49baf 100644 --- a/core/src/io/anuke/mindustry/world/blocks/power/ItemGenerator.java +++ b/core/src/io/anuke/mindustry/world/blocks/power/ItemGenerator.java @@ -55,7 +55,7 @@ public abstract class ItemGenerator extends PowerGenerator { @Override public void 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 @@ -66,7 +66,7 @@ public abstract class ItemGenerator extends PowerGenerator { if(entity.generateTime > 0){ 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; Draw.alpha(alpha); Draw.rect(topRegion, tile.drawx(), tile.drawy()); @@ -76,7 +76,7 @@ public abstract class ItemGenerator extends PowerGenerator { @Override 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 @@ -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)); for(int i = 0; i < entity.items.items.length; i ++){ if(entity.items.items[i] > 0){ diff --git a/core/src/io/anuke/mindustry/world/blocks/power/ItemLiquidGenerator.java b/core/src/io/anuke/mindustry/world/blocks/power/ItemLiquidGenerator.java index 82e06c95d1..6adc8bf50f 100644 --- a/core/src/io/anuke/mindustry/world/blocks/power/ItemLiquidGenerator.java +++ b/core/src/io/anuke/mindustry/world/blocks/power/ItemLiquidGenerator.java @@ -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)); for (int i = 0; i < entity.items.items.length; i++) { if (entity.items.items[i] > 0) { diff --git a/core/src/io/anuke/mindustry/world/blocks/power/NuclearReactor.java b/core/src/io/anuke/mindustry/world/blocks/power/NuclearReactor.java index 55e6ce750c..1184da288b 100644 --- a/core/src/io/anuke/mindustry/world/blocks/power/NuclearReactor.java +++ b/core/src/io/anuke/mindustry/world/blocks/power/NuclearReactor.java @@ -57,7 +57,7 @@ public class NuclearReactor extends PowerGenerator { @Override public void 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.entity().heat)); } @@ -73,7 +73,7 @@ public class NuclearReactor extends PowerGenerator { public void update(Tile tile){ NuclearReactorEntity entity = tile.entity(); - int fuel = entity.items.getItem(generateItem); + int fuel = entity.items.get(generateItem); float fullness = (float)fuel / itemCapacity; if(fuel > 0){ @@ -81,7 +81,7 @@ public class NuclearReactor extends PowerGenerator { entity.power.amount += powerMultiplier * fullness * Timers.delta(); entity.power.amount = Mathf.clamp(entity.power.amount, 0f, powerCapacity); 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(); - int fuel = entity.items.getItem(generateItem); + int fuel = entity.items.get(generateItem); if(fuel < 5 && entity.heat < 0.5f) return; @@ -155,7 +155,7 @@ public class NuclearReactor extends PowerGenerator { @Override 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 diff --git a/core/src/io/anuke/mindustry/world/blocks/production/Compressor.java b/core/src/io/anuke/mindustry/world/blocks/production/Compressor.java index a7b85759f5..ffe9544a59 100644 --- a/core/src/io/anuke/mindustry/world/blocks/production/Compressor.java +++ b/core/src/io/anuke/mindustry/world/blocks/production/Compressor.java @@ -23,14 +23,14 @@ public class Compressor extends PowerCrafter { float liquidAdded = Math.min(outputLiquidAmount * Timers.delta(), liquidCapacity - entity.liquids.amount); int itemsUsed = Mathf.ceil(1 + input.amount * entity.progress); - if(entity.power.amount > powerUsed && entity.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.totalProgress += Timers.delta(); handleLiquid(tile, tile, outputLiquid, liquidAdded); } if(entity.progress >= 1f){ - entity.items.removeItem(input); + entity.items.remove(input); if(outputItem != null) offloadNear(tile, outputItem); entity.progress = 0f; } @@ -48,7 +48,7 @@ public class Compressor extends PowerCrafter { public void draw(Tile tile) { 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.color(Color.CLEAR, tile.entity.liquids.liquid.color, tile.entity.liquids.amount / liquidCapacity); Draw.rect(name + "-liquid", tile.drawx(), tile.drawy()); diff --git a/core/src/io/anuke/mindustry/world/blocks/production/Cultivator.java b/core/src/io/anuke/mindustry/world/blocks/production/Cultivator.java index 52bf4488a4..2af65d16a4 100644 --- a/core/src/io/anuke/mindustry/world/blocks/production/Cultivator.java +++ b/core/src/io/anuke/mindustry/world/blocks/production/Cultivator.java @@ -57,7 +57,7 @@ public class Cultivator extends Drill { public void draw(Tile tile) { CultivatorEntity entity = tile.entity(); - Draw.rect(name, tile.drawx(), tile.drawy()); + Draw.rect(region, tile.drawx(), tile.drawy()); Draw.color(plantColor); Draw.alpha(entity.warmup); diff --git a/core/src/io/anuke/mindustry/world/blocks/production/Drill.java b/core/src/io/anuke/mindustry/world/blocks/production/Drill.java index 1856f63c32..0de56aea3b 100644 --- a/core/src/io/anuke/mindustry/world/blocks/production/Drill.java +++ b/core/src/io/anuke/mindustry/world/blocks/production/Drill.java @@ -91,7 +91,7 @@ public class Drill extends Block{ DrillEntity entity = tile.entity(); - Draw.rect(name, tile.drawx(), tile.drawy()); + Draw.rect(region, tile.drawx(), tile.drawy()); if(drawRim) { Graphics.setAdditiveBlending(); @@ -178,7 +178,7 @@ public class Drill extends Block{ float powerUsed = Math.min(powerCapacity, powerUse * 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) && (!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 - && tile.entity.items.totalItems() < itemCapacity){ + && tile.entity.items.total() < itemCapacity){ int index = entity.index % toAdd.size; offloadNear(tile, toAdd.get(index)); diff --git a/core/src/io/anuke/mindustry/world/blocks/production/Fracker.java b/core/src/io/anuke/mindustry/world/blocks/production/Fracker.java index 16465d6d45..7b7c68c50e 100644 --- a/core/src/io/anuke/mindustry/world/blocks/production/Fracker.java +++ b/core/src/io/anuke/mindustry/world/blocks/production/Fracker.java @@ -10,7 +10,6 @@ import io.anuke.mindustry.world.meta.BlockStat; import io.anuke.mindustry.world.meta.StatUnit; import io.anuke.ucore.core.Timers; import io.anuke.ucore.graphics.Draw; -import io.anuke.ucore.util.Log; public class Fracker extends SolidPump { protected Liquid inputLiquid; @@ -51,7 +50,7 @@ public class Fracker extends SolidPump { public void draw(Tile tile) { 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.alpha(tile.entity.liquids.amount/liquidCapacity); @@ -71,8 +70,8 @@ public class Fracker extends SolidPump { public void update(Tile tile) { FrackerEntity entity = tile.entity(); - while(entity.accumulator > itemUseTime && entity.items.hasItem(inputItem, 1)){ - entity.items.removeItem(inputItem, 1); + while(entity.accumulator > itemUseTime && entity.items.has(inputItem, 1)){ + entity.items.remove(inputItem, 1); entity.accumulator -= itemUseTime; } @@ -87,7 +86,7 @@ public class Fracker extends SolidPump { @Override 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 diff --git a/core/src/io/anuke/mindustry/world/blocks/production/GenericCrafter.java b/core/src/io/anuke/mindustry/world/blocks/production/GenericCrafter.java index 1173847e9b..7abfd25839 100644 --- a/core/src/io/anuke/mindustry/world/blocks/production/GenericCrafter.java +++ b/core/src/io/anuke/mindustry/world/blocks/production/GenericCrafter.java @@ -51,7 +51,7 @@ public class GenericCrafter extends Block{ super.setBars(); 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 @@ -93,7 +93,7 @@ public class GenericCrafter extends Block{ if((!hasLiquids || entity.liquids.amount >= liquidUsed) && (!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.totalProgress += Timers.delta(); @@ -109,7 +109,7 @@ public class GenericCrafter extends Block{ if(entity.progress >= 1f){ - if(inputItem != null) tile.entity.items.removeItem(inputItem); + if(inputItem != null) tile.entity.items.remove(inputItem); offloadNear(tile, output); Effects.effect(craftEffect, tile.drawx(), tile.drawy()); entity.progress = 0f; @@ -128,7 +128,7 @@ public class GenericCrafter extends Block{ @Override public boolean acceptItem(Item item, Tile tile, Tile source){ TileEntity entity = tile.entity(); - return inputItem != null && item == inputItem.item && entity.items.getItem(inputItem.item) < itemCapacity; + return inputItem != null && item == inputItem.item && entity.items.get(inputItem.item) < itemCapacity; } @Override diff --git a/core/src/io/anuke/mindustry/world/blocks/production/LiquidMixer.java b/core/src/io/anuke/mindustry/world/blocks/production/LiquidMixer.java index 3f8523af20..02b889fc34 100644 --- a/core/src/io/anuke/mindustry/world/blocks/production/LiquidMixer.java +++ b/core/src/io/anuke/mindustry/world/blocks/production/LiquidMixer.java @@ -46,21 +46,21 @@ public class LiquidMixer extends LiquidBlock{ @Override 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 public float handleAuxLiquid(Tile tile, Tile source, Liquid liquid, float amount) { 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){ amount = Math.min(liquidCapacity - tile.entity.liquids.amount, amount); entity.accumulator += amount; int items = (int)(entity.accumulator / liquidPerItem); - entity.items.removeItem(inputItem, items); + entity.items.remove(inputItem, items); entity.accumulator %= liquidPerItem; entity.liquids.liquid = outputLiquid; entity.liquids.amount += amount; diff --git a/core/src/io/anuke/mindustry/world/blocks/production/PhaseWeaver.java b/core/src/io/anuke/mindustry/world/blocks/production/PhaseWeaver.java index baa50bb952..d58545f44f 100644 --- a/core/src/io/anuke/mindustry/world/blocks/production/PhaseWeaver.java +++ b/core/src/io/anuke/mindustry/world/blocks/production/PhaseWeaver.java @@ -64,6 +64,6 @@ public class PhaseWeaver extends PowerSmelter{ Draw.reset(); } - Draw.rect(name, tile.drawx(), tile.drawy()); + Draw.rect(region, tile.drawx(), tile.drawy()); } } diff --git a/core/src/io/anuke/mindustry/world/blocks/production/PowerCrafter.java b/core/src/io/anuke/mindustry/world/blocks/production/PowerCrafter.java index bec6388a72..efe340ce3a 100644 --- a/core/src/io/anuke/mindustry/world/blocks/production/PowerCrafter.java +++ b/core/src/io/anuke/mindustry/world/blocks/production/PowerCrafter.java @@ -59,13 +59,13 @@ public class PowerCrafter extends Block{ float powerUsed = Math.min(Timers.delta() * powerUse, tile.entity.power.amount); int itemsUsed = Mathf.ceil(1 + input.amount * entity.progress); - if(entity.power.amount > powerUsed && entity.items.hasItem(input.item, itemsUsed)){ + if(entity.power.amount > powerUsed && entity.items.has(input.item, itemsUsed)){ entity.progress += 1f/craftTime; entity.totalProgress += Timers.delta(); } if(entity.progress >= 1f){ - entity.items.removeItem(input); + entity.items.remove(input); if(outputItem != null) offloadNear(tile, outputItem); if(outputLiquid != null) handleLiquid(tile, tile, outputLiquid, outputLiquidAmount); entity.progress = 0f; @@ -82,7 +82,7 @@ public class PowerCrafter extends Block{ @Override 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 diff --git a/core/src/io/anuke/mindustry/world/blocks/production/PowerSmelter.java b/core/src/io/anuke/mindustry/world/blocks/production/PowerSmelter.java index fc552c8135..dcc147c953 100644 --- a/core/src/io/anuke/mindustry/world/blocks/production/PowerSmelter.java +++ b/core/src/io/anuke/mindustry/world/blocks/production/PowerSmelter.java @@ -71,7 +71,7 @@ public class PowerSmelter extends PowerBlock { bars.remove(BarType.inventory); for(ItemStack item : inputs){ - bars.add(new BlockBar(BarType.inventory, true, tile -> (float) tile.entity.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(); - if(entity.timer.get(timerDump, 5) && entity.items.hasItem(result)){ + if(entity.timer.get(timerDump, 5) && entity.items.has(result)){ tryDump(tile, result); } @@ -114,12 +114,12 @@ public class PowerSmelter extends PowerBlock { //make sure it has all the items for(ItemStack item : inputs){ - if(!entity.items.hasItem(item.item, item.amount)){ + if(!entity.items.has(item.item, item.amount)){ return; } } - if(entity.items.getItem(result) >= itemCapacity //output full + if(entity.items.get(result) >= itemCapacity //output full || entity.heat <= minHeat //not burning || !entity.timer.get(timerCraft, craftTime)){ //not yet time return; @@ -130,8 +130,8 @@ public class PowerSmelter extends PowerBlock { if(useFlux){ //remove flux materials if present for(Item item : Item.all()){ - if(item.fluxiness >= minFlux && tile.entity.items.getItem(item) >= fluxNeeded){ - tile.entity.items.removeItem(item, fluxNeeded); + if(item.fluxiness >= minFlux && tile.entity.items.get(item) >= fluxNeeded){ + tile.entity.items.remove(item, fluxNeeded); //chance of not consuming inputs if flux material present consumeInputs = !Mathf.chance(item.fluxiness * baseFluxChance); @@ -142,7 +142,7 @@ public class PowerSmelter extends PowerBlock { if(consumeInputs) { 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){ if(stack.item == item){ - return tile.entity.items.getItem(item) < itemCapacity; + return tile.entity.items.get(item) < itemCapacity; } } if(useFlux && item.fluxiness >= minFlux){ - return tile.entity.items.getItem(item) < itemCapacity; + return tile.entity.items.get(item) < itemCapacity; } return false; @@ -168,7 +168,7 @@ public class PowerSmelter extends PowerBlock { @Override public int getMaximumAccepted(Tile tile, Item item) { - return itemCapacity - tile.entity.items.getItem(item); + return itemCapacity - tile.entity.items.get(item); } @Override diff --git a/core/src/io/anuke/mindustry/world/blocks/production/Pulverizer.java b/core/src/io/anuke/mindustry/world/blocks/production/Pulverizer.java index d9bdfe2930..c96c0ec054 100644 --- a/core/src/io/anuke/mindustry/world/blocks/production/Pulverizer.java +++ b/core/src/io/anuke/mindustry/world/blocks/production/Pulverizer.java @@ -5,18 +5,26 @@ import io.anuke.mindustry.world.Tile; import io.anuke.ucore.graphics.Draw; public class Pulverizer extends GenericCrafter { + protected TextureRegion rotatorRegion; public Pulverizer(String name) { super(name); hasItems = true; } + @Override + public void load() { + super.load(); + + rotatorRegion = Draw.region(name + "-rotator"); + } + @Override public void draw(Tile tile) { GenericCrafterEntity entity = tile.entity(); - Draw.rect(name, tile.drawx(), tile.drawy()); - Draw.rect(name + "-rotator", tile.drawx(), tile.drawy(), entity.totalProgress * 2f); + Draw.rect(region, tile.drawx(), tile.drawy()); + Draw.rect(rotatorRegion, tile.drawx(), tile.drawy(), entity.totalProgress * 2f); } @Override diff --git a/core/src/io/anuke/mindustry/world/blocks/production/Separator.java b/core/src/io/anuke/mindustry/world/blocks/production/Separator.java index b150976239..2ee107fb5f 100644 --- a/core/src/io/anuke/mindustry/world/blocks/production/Separator.java +++ b/core/src/io/anuke/mindustry/world/blocks/production/Separator.java @@ -1,6 +1,7 @@ package io.anuke.mindustry.world.blocks.production; import com.badlogic.gdx.graphics.Color; +import com.badlogic.gdx.graphics.g2d.TextureRegion; import io.anuke.mindustry.entities.TileEntity; import io.anuke.mindustry.type.Item; import io.anuke.mindustry.type.Liquid; @@ -30,6 +31,9 @@ public class Separator extends Block { protected float spinnerThickness = 1f; protected float spinnerSpeed = 2f; + protected Color color = Color.valueOf("858585"); + protected TextureRegion liquidRegion; + protected boolean offloading = false; public Separator(String name) { @@ -40,6 +44,13 @@ public class Separator extends Block { hasLiquids = true; } + @Override + public void load() { + super.load(); + + liquidRegion = Draw.region(name + "-liquid"); + } + @Override public void setStats() { super.setStats(); @@ -67,9 +78,9 @@ public class Separator extends Block { Draw.color(tile.entity.liquids.liquid.color); 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.spikes(tile.drawx(), tile.drawy(), spinnerRadius, spinnerLength, 3, entity.totalProgress*spinnerSpeed); Draw.reset(); @@ -84,7 +95,7 @@ public class Separator extends Block { 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)){ entity.progress += 1f/filterTime; entity.liquids.amount -= liquidUsed; @@ -98,7 +109,7 @@ public class Separator extends Block { if(entity.progress >= 1f){ entity.progress = 0f; Item item = Mathf.select(results); - entity.items.removeItem(this.item, 1); + entity.items.remove(this.item, 1); if(item != null){ offloading = true; offloadNear(tile, item); @@ -123,7 +134,7 @@ public class Separator extends Block { @Override 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 diff --git a/core/src/io/anuke/mindustry/world/blocks/production/Smelter.java b/core/src/io/anuke/mindustry/world/blocks/production/Smelter.java index 303aded079..5deb96b27b 100644 --- a/core/src/io/anuke/mindustry/world/blocks/production/Smelter.java +++ b/core/src/io/anuke/mindustry/world/blocks/production/Smelter.java @@ -47,7 +47,7 @@ public class Smelter extends Block{ @Override public void setBars(){ 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){ 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); } //add fuel - if(entity.items.getItem(fuel) > 0 && entity.burnTime <= 0f){ - entity.items.removeItem(fuel, 1); + if(entity.items.get(fuel) > 0 && entity.burnTime <= 0f){ + entity.items.remove(fuel, 1); entity.burnTime += burnDuration; 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 for(ItemStack item : inputs){ - if(!entity.items.hasItem(item.item, item.amount)){ + if(!entity.items.has(item.item, item.amount)){ return; } } - if(entity.items.getItem(result) >= itemCapacity //output full + if(entity.items.get(result) >= itemCapacity //output full || entity.burnTime <= 0 //not burning || !entity.timer.get(timerCraft, craftTime)){ //not yet time return; @@ -116,8 +116,8 @@ public class Smelter extends Block{ if(useFlux){ //remove flux materials if present for(Item item : Item.all()){ - if(item.fluxiness >= minFlux && tile.entity.items.getItem(item) > 0){ - tile.entity.items.removeItem(item, 1); + if(item.fluxiness >= minFlux && tile.entity.items.get(item) > 0){ + tile.entity.items.remove(item, 1); //chance of not consuming inputs if flux material present consumeInputs = !Mathf.chance(item.fluxiness * baseFluxChance); @@ -128,7 +128,7 @@ public class Smelter extends Block{ if(consumeInputs) { 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 public int getMaximumAccepted(Tile tile, Item item) { - return itemCapacity - tile.entity.items.getItem(item); + return itemCapacity - tile.entity.items.get(item); } @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) || - (useFlux && item.fluxiness >= minFlux && tile.entity.items.getItem(item) < itemCapacity); + return (isInput && tile.entity.items.get(item) < itemCapacity) || (item == fuel && tile.entity.items.get(fuel) < itemCapacity) || + (useFlux && item.fluxiness >= minFlux && tile.entity.items.get(item) < itemCapacity); } @Override diff --git a/core/src/io/anuke/mindustry/world/blocks/production/SolidPump.java b/core/src/io/anuke/mindustry/world/blocks/production/SolidPump.java index a15ff7c5ea..6a4cfd6ccc 100644 --- a/core/src/io/anuke/mindustry/world/blocks/production/SolidPump.java +++ b/core/src/io/anuke/mindustry/world/blocks/production/SolidPump.java @@ -43,7 +43,7 @@ public class SolidPump extends Pump { public void draw(Tile tile) { 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.alpha(tile.entity.liquids.amount / liquidCapacity); Draw.rect(liquidRegion, tile.drawx(), tile.drawy()); diff --git a/core/src/io/anuke/mindustry/world/blocks/storage/CoreBlock.java b/core/src/io/anuke/mindustry/world/blocks/storage/CoreBlock.java index ea0189c6ef..6a64afcb31 100644 --- a/core/src/io/anuke/mindustry/world/blocks/storage/CoreBlock.java +++ b/core/src/io/anuke/mindustry/world/blocks/storage/CoreBlock.java @@ -133,7 +133,7 @@ public class CoreBlock extends StorageBlock { @Override public int acceptStack(Item item, int amount, Tile tile, Unit source){ 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{ return 0; } diff --git a/core/src/io/anuke/mindustry/world/blocks/storage/SortedUnloader.java b/core/src/io/anuke/mindustry/world/blocks/storage/SortedUnloader.java index 7d65048455..de4c79d10c 100644 --- a/core/src/io/anuke/mindustry/world/blocks/storage/SortedUnloader.java +++ b/core/src/io/anuke/mindustry/world/blocks/storage/SortedUnloader.java @@ -30,16 +30,16 @@ public class SortedUnloader extends Unloader implements SelectionTrait{ public void update(Tile tile){ 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 -> { - 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)){ offloadNear(tile, ((StorageBlock)other.block()).removeItem(other, entity.sortItem)); } }); } - if(entity.items.totalItems() > 0){ + if(entity.items.total() > 0){ tryDump(tile); } } diff --git a/core/src/io/anuke/mindustry/world/blocks/storage/Unloader.java b/core/src/io/anuke/mindustry/world/blocks/storage/Unloader.java index 71d801153e..aa59e769c7 100644 --- a/core/src/io/anuke/mindustry/world/blocks/storage/Unloader.java +++ b/core/src/io/anuke/mindustry/world/blocks/storage/Unloader.java @@ -20,16 +20,16 @@ public class Unloader extends Block { @Override 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 -> { - 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)){ offloadNear(tile, ((StorageBlock)other.block()).removeItem(other, null)); } }); } - if(tile.entity.items.totalItems() > 0){ + if(tile.entity.items.total() > 0){ tryDump(tile); } } diff --git a/core/src/io/anuke/mindustry/world/blocks/storage/Vault.java b/core/src/io/anuke/mindustry/world/blocks/storage/Vault.java index 314f22b0fc..54a9bffd28 100644 --- a/core/src/io/anuke/mindustry/world/blocks/storage/Vault.java +++ b/core/src/io/anuke/mindustry/world/blocks/storage/Vault.java @@ -18,7 +18,7 @@ public class Vault extends StorageBlock { int iterations = Math.max(1, (int) (Timers.delta() + 0.4f)); for(int i = 0; i < iterations; i ++) { - if (tile.entity.items.totalItems() > 0) { + if (tile.entity.items.total() > 0) { tryDump(tile); } } @@ -31,7 +31,7 @@ public class Vault extends StorageBlock { @Override public boolean acceptItem(Item item, Tile tile, Tile source) { - return tile.entity.items.totalItems() < itemCapacity; + return tile.entity.items.total() < itemCapacity; } @Override @@ -39,7 +39,7 @@ public class Vault extends StorageBlock { to = to.target(); 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; } } diff --git a/core/src/io/anuke/mindustry/world/blocks/units/DropPoint.java b/core/src/io/anuke/mindustry/world/blocks/units/DropPoint.java index 1834531712..b6a294465e 100644 --- a/core/src/io/anuke/mindustry/world/blocks/units/DropPoint.java +++ b/core/src/io/anuke/mindustry/world/blocks/units/DropPoint.java @@ -21,7 +21,7 @@ public class DropPoint extends Block { @Override public void update(Tile tile) { - if (tile.entity.items.totalItems() > 0) { + if (tile.entity.items.total() > 0) { tryDump(tile); } } diff --git a/core/src/io/anuke/mindustry/world/blocks/units/Reconstructor.java b/core/src/io/anuke/mindustry/world/blocks/units/Reconstructor.java index 3722567476..d893038086 100644 --- a/core/src/io/anuke/mindustry/world/blocks/units/Reconstructor.java +++ b/core/src/io/anuke/mindustry/world/blocks/units/Reconstructor.java @@ -112,7 +112,7 @@ public class Reconstructor extends Block{ ReconstructorEntity entity = tile.entity(); if(entity.solid){ - Draw.rect(name, tile.drawx(), tile.drawy()); + Draw.rect(region, tile.drawx(), tile.drawy()); }else{ Draw.rect(openRegion, tile.drawx(), tile.drawy()); } diff --git a/core/src/io/anuke/mindustry/world/blocks/units/ResupplyPoint.java b/core/src/io/anuke/mindustry/world/blocks/units/ResupplyPoint.java index 7c2e6177a7..af0078b72c 100644 --- a/core/src/io/anuke/mindustry/world/blocks/units/ResupplyPoint.java +++ b/core/src/io/anuke/mindustry/world/blocks/units/ResupplyPoint.java @@ -118,7 +118,7 @@ public class ResupplyPoint extends Block{ @Override public boolean acceptItem(Item item, Tile tile, Tile source) { - return tile.entity.items.totalItems() < itemCapacity; + return tile.entity.items.total() < itemCapacity; } @Override diff --git a/core/src/io/anuke/mindustry/world/blocks/units/UnitFactory.java b/core/src/io/anuke/mindustry/world/blocks/units/UnitFactory.java index d4fc03f531..c7777c4775 100644 --- a/core/src/io/anuke/mindustry/world/blocks/units/UnitFactory.java +++ b/core/src/io/anuke/mindustry/world/blocks/units/UnitFactory.java @@ -19,7 +19,7 @@ import io.anuke.mindustry.type.ItemStack; import io.anuke.mindustry.world.BarType; import io.anuke.mindustry.world.Block; 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.BlockStat; import io.anuke.mindustry.world.meta.StatUnit; @@ -154,7 +154,7 @@ public class UnitFactory extends Block { entity.openCountdown = openDuration; 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 public boolean acceptItem(Item item, Tile tile, Tile source) { 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; } } @@ -176,7 +176,7 @@ public class UnitFactory extends Block { protected boolean hasRequirements(InventoryModule inv, float fraction){ for(ItemStack stack : requirements){ - if(!inv.hasItem(stack.item, (int)(fraction * stack.amount))){ + if(!inv.has(stack.item, (int)(fraction * stack.amount))){ return false; } } diff --git a/core/src/io/anuke/mindustry/world/consumers/Consume.java b/core/src/io/anuke/mindustry/world/consumers/Consume.java new file mode 100644 index 0000000000..977435abae --- /dev/null +++ b/core/src/io/anuke/mindustry/world/consumers/Consume.java @@ -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(); +} diff --git a/core/src/io/anuke/mindustry/world/modules/InventoryModule.java b/core/src/io/anuke/mindustry/world/modules/InventoryModule.java new file mode 100644 index 0000000000..cc937769cd --- /dev/null +++ b/core/src/io/anuke/mindustry/world/modules/InventoryModule.java @@ -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); + } +} diff --git a/core/src/io/anuke/mindustry/world/modules/LiquidModule.java b/core/src/io/anuke/mindustry/world/modules/LiquidModule.java new file mode 100644 index 0000000000..57808eee6d --- /dev/null +++ b/core/src/io/anuke/mindustry/world/modules/LiquidModule.java @@ -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); + } +} diff --git a/core/src/io/anuke/mindustry/world/blocks/modules/PowerModule.java b/core/src/io/anuke/mindustry/world/modules/PowerModule.java similarity index 94% rename from core/src/io/anuke/mindustry/world/blocks/modules/PowerModule.java rename to core/src/io/anuke/mindustry/world/modules/PowerModule.java index 91c38f521f..f46f9ca817 100644 --- a/core/src/io/anuke/mindustry/world/blocks/modules/PowerModule.java +++ b/core/src/io/anuke/mindustry/world/modules/PowerModule.java @@ -1,4 +1,4 @@ -package io.anuke.mindustry.world.blocks.modules; +package io.anuke.mindustry.world.modules; import io.anuke.mindustry.world.blocks.BlockModule; diff --git a/packer/build.gradle b/packer/build.gradle index 64b054f422..06ce5fd606 100644 --- a/packer/build.gradle +++ b/packer/build.gradle @@ -43,3 +43,12 @@ task generateSprites(dependsOn: classes, type: JavaExec) { standardInput = System.in 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/" +} diff --git a/packer/src/io/anuke/mindustry/BundleLauncher.java b/packer/src/io/anuke/mindustry/BundleLauncher.java new file mode 100644 index 0000000000..f26ea64ad0 --- /dev/null +++ b/packer/src/io/anuke/mindustry/BundleLauncher.java @@ -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); + }); + } + +}