use of io.anuke.mindustry.resource.Item in project Mindustry by Anuken.
the class Omnidrill method draw.
@Override
public void draw(Tile tile) {
super.draw(tile);
if (tile.floor().drops == null)
return;
Item item = tile.floor().drops.item;
TextureRegion region = item.region;
Tmp.tr1.setRegion(region, 4, 4, 1, 1);
Draw.rect(Tmp.tr1, tile.worldx(), tile.worldy(), 2f, 2f);
}
use of io.anuke.mindustry.resource.Item in project Mindustry by Anuken.
the class Smelter method update.
@Override
public void update(Tile tile) {
CrafterEntity entity = tile.entity();
if (entity.timer.get(timerDump, 5) && entity.hasItem(result)) {
tryDump(tile, -1, result);
}
// add fuel
if (entity.getItem(fuel) > 0 && entity.burnTime <= 0f) {
entity.removeItem(fuel, 1);
entity.burnTime += burnDuration;
Effects.effect(burnEffect, entity.x + Mathf.range(2f), entity.y + Mathf.range(2f));
}
// decrement burntime
if (entity.burnTime > 0) {
entity.burnTime -= Timers.delta();
}
// make sure it has all the items
for (Item item : inputs) {
if (!entity.hasItem(item)) {
return;
}
}
if (// output full
entity.getItem(result) >= capacity || // not burning
entity.burnTime <= 0 || !entity.timer.get(timerCraft, craftTime)) {
// not yet time
return;
}
for (Item item : inputs) {
entity.removeItem(item, 1);
}
offloadNear(tile, result);
Effects.effect(craftEffect, entity);
}
use of io.anuke.mindustry.resource.Item in project Mindustry by Anuken.
the class Sorter method buildTable.
@Override
public void buildTable(Tile tile, Table table) {
SorterEntity entity = tile.entity();
Array<Item> items = Item.getAllItems();
ButtonGroup<ImageButton> group = new ButtonGroup<>();
Table cont = new Table();
cont.margin(4);
cont.marginBottom(5);
cont.add().colspan(4).height(105f);
cont.row();
for (int i = 0; i < items.size; i++) {
final int f = i;
ImageButton button = cont.addImageButton("white", "toggle", 24, () -> {
entity.sortItem = items.get(f);
setConfigure(tile, (byte) f);
}).size(38, 42).padBottom(-5.1f).group(group).get();
button.getStyle().imageUp = new TextureRegionDrawable(new TextureRegion(items.get(i).region));
button.setChecked(entity.sortItem.id == f);
if (i % 4 == 3) {
cont.row();
}
}
table.add(cont);
}
use of io.anuke.mindustry.resource.Item in project Mindustry by Anuken.
the class TunnelConveyor method update.
@Override
public void update(Tile tile) {
TunnelEntity entity = tile.entity();
if (entity.index > 0) {
long l = entity.buffer[0];
float time = NumberUtils.intBitsToFloat(Bits.getLeftInt(l));
if (Timers.time() >= time + speed || Timers.time() < time) {
Item item = Item.getByID(Bits.getRightInt(l));
Tile tunnel = getDestTunnel(tile, item);
if (tunnel == null)
return;
Tile target = tunnel.getNearby(tunnel.getRotation());
if (target == null)
return;
if (!target.block().acceptItem(item, target, tunnel))
return;
target.block().handleItem(item, target, tunnel);
System.arraycopy(entity.buffer, 1, entity.buffer, 0, entity.index - 1);
entity.index--;
}
}
}
use of io.anuke.mindustry.resource.Item in project Mindustry by Anuken.
the class Save13 method read.
@Override
public void read(DataInputStream stream) throws IOException {
/*long loadTime = */
stream.readLong();
// general state
byte mode = stream.readByte();
byte mapid = stream.readByte();
int wave = stream.readInt();
float wavetime = stream.readFloat();
float playerx = stream.readFloat();
float playery = stream.readFloat();
int playerhealth = stream.readInt();
Vars.player.x = playerx;
Vars.player.y = playery;
Vars.player.health = playerhealth;
state.mode = GameMode.values()[mode];
Core.camera.position.set(playerx, playery, 0);
// weapons
control.upgrades().getWeapons().clear();
control.upgrades().getWeapons().add(Weapon.blaster);
Vars.player.weaponLeft = Vars.player.weaponRight = Weapon.blaster;
int weapons = stream.readByte();
for (int i = 0; i < weapons; i++) {
control.upgrades().addWeapon((Weapon) Upgrade.getByID(stream.readByte()));
}
ui.hudfrag.updateWeapons();
// inventory
int totalItems = stream.readByte();
Arrays.fill(state.inventory.getItems(), 0);
for (int i = 0; i < totalItems; i++) {
Item item = Item.getByID(stream.readByte());
int amount = stream.readInt();
state.inventory.getItems()[item.id] = amount;
}
ui.hudfrag.updateItems();
// enemies
Entities.clear();
int enemies = stream.readInt();
Array<Enemy> enemiesToUpdate = new Array<>();
for (int i = 0; i < enemies; i++) {
byte type = stream.readByte();
int lane = stream.readByte();
float x = stream.readFloat();
float y = stream.readFloat();
byte tier = stream.readByte();
int health = stream.readShort();
try {
Enemy enemy = new Enemy(EnemyType.getByID(type));
enemy.lane = lane;
enemy.health = health;
enemy.x = x;
enemy.y = y;
enemy.tier = tier;
enemy.add(enemyGroup);
enemiesToUpdate.add(enemy);
} catch (Exception e) {
throw new RuntimeException(e);
}
}
state.enemies = enemies;
state.wave = wave;
state.wavetime = wavetime;
if (!android)
Vars.player.add();
// map
int seed = stream.readInt();
world.loadMap(world.maps().getMap(mapid), seed);
renderer.clearTiles();
for (Enemy enemy : enemiesToUpdate) {
enemy.node = -2;
}
int rocks = stream.readInt();
for (int x = 0; x < world.width(); x++) {
for (int y = 0; y < world.height(); y++) {
Tile tile = world.tile(x, y);
// remove breakables like rocks
if (tile.breakable()) {
world.tile(x, y).setBlock(Blocks.air);
}
}
}
for (int i = 0; i < rocks; i++) {
int pos = stream.readInt();
Tile tile = world.tile(pos % world.width(), pos / world.width());
Block result = WorldGenerator.rocks.get(tile.floor());
if (result != null)
tile.setBlock(result);
}
int tiles = stream.readInt();
for (int i = 0; i < tiles; i++) {
int pos = stream.readInt();
int blockid = stream.readInt();
Tile tile = world.tile(pos % world.width(), pos / world.width());
tile.setBlock(BlockLoader.getByOldID(blockid));
if (blockid == Blocks.blockpart.id) {
tile.link = stream.readByte();
}
if (tile.entity != null) {
byte rotation = stream.readByte();
short health = stream.readShort();
int items = stream.readByte();
tile.entity.health = health;
tile.setRotation(rotation);
for (int j = 0; j < items; j++) {
int itemid = stream.readByte();
int itemamount = stream.readInt();
tile.entity.items[itemid] = itemamount;
}
tile.entity.read(stream);
}
}
}
Aggregations