use of io.anuke.mindustry.resource.Item in project Mindustry by Anuken.
the class Save14 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();
// block header
int blocksize = stream.readInt();
IntMap<Block> map = new IntMap<>();
for (int i = 0; i < blocksize; i++) {
String name = readString(stream);
int id = stream.readShort();
map.put(id, Block.getByName(name));
}
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());
if (tile == null)
continue;
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(map.get(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);
}
}
}
use of io.anuke.mindustry.resource.Item in project Mindustry by Anuken.
the class Save15 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();
byte difficulty = stream.readByte();
state.difficulty = Difficulty.values()[difficulty];
// block header
int blocksize = stream.readInt();
IntMap<Block> map = new IntMap<>();
for (int i = 0; i < blocksize; i++) {
String name = readString(stream);
int id = stream.readShort();
map.put(id, Block.getByName(name));
}
float playerx = stream.readFloat();
float playery = stream.readFloat();
int playerhealth = stream.readInt();
if (!headless) {
player.x = playerx;
player.y = playery;
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);
player.weaponLeft = 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();
} else {
byte b = stream.readByte();
for (int i = 0; i < b; i++) stream.readByte();
}
// 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;
}
if (!headless)
ui.hudfrag.updateItems();
// enemies
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 && !headless)
player.add();
// map
int seed = stream.readInt();
world.loadMap(world.maps().getMap(mapid), seed);
if (!headless)
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());
if (tile == null)
continue;
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(map.get(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);
}
}
}
use of io.anuke.mindustry.resource.Item in project Mindustry by Anuken.
the class Save12 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.readInt();
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();
int tiles = stream.readInt();
world.loadMap(world.maps().getMap(mapid), seed);
renderer.clearTiles();
for (Enemy enemy : enemiesToUpdate) {
enemy.node = -2;
}
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 < tiles; i++) {
int pos = stream.readInt();
byte link = stream.readByte();
boolean hasEntity = stream.readBoolean();
int blockid = stream.readInt();
Tile tile = world.tile(pos % world.width(), pos / world.width());
tile.setBlock(BlockLoader.getByOldID(blockid));
tile.link = link;
if (hasEntity) {
byte rotation = stream.readByte();
int health = stream.readInt();
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);
}
}
}
use of io.anuke.mindustry.resource.Item in project Mindustry by Anuken.
the class TunnelConveyor method getDebugInfo.
@Override
public Array<Object> getDebugInfo(Tile tile) {
TunnelEntity entity = tile.entity();
Array<Object> arr = super.getDebugInfo(tile);
for (int i = 0; i < 4; i++) {
arr.add("nearby." + i);
arr.add(tile.getNearby(i));
}
arr.add("buffer");
arr.add(entity.index);
for (int i = 0; i < entity.index; i++) {
long l = entity.items[i];
float time = NumberUtils.intBitsToFloat(Bits.getLeftInt(l));
Item item = Item.getByID(Bits.getRightInt(l));
Tile dest = getDestTunnel(tile, item);
arr.add(" buffer.item");
arr.add(time + " | " + item.name + " | " + (dest == null ? "no dest" : dest.block() + ":" + dest.floor()));
}
return arr;
}
use of io.anuke.mindustry.resource.Item in project Mindustry by Anuken.
the class Block method tryDump.
/**
* Try dumping any item near the tile. -1 = any direction
*/
protected boolean tryDump(Tile tile, int direction, Item todump) {
if (Net.client() && syncBlockState)
return false;
int i = tile.getDump() % 4;
for (int j = 0; j < 4; j++) {
Tile other = tile.getNearby(i);
if (i == direction || direction == -1) {
for (Item item : Item.getAllItems()) {
if (todump != null && item != todump)
continue;
if (tile.entity.hasItem(item) && other != null && other.block().acceptItem(item, other, tile)) {
other.block().handleItem(item, other, tile);
tile.entity.removeItem(item, 1);
tile.setDump((byte) ((i + 1) % 4));
if (Net.server() && syncBlockState)
NetEvents.handleTransfer(tile, (byte) i, item);
return true;
}
}
}
i++;
i %= 4;
}
return false;
}
Aggregations