use of io.anuke.mindustry.world.blocks.types.Rock in project Mindustry by Anuken.
the class Save13 method write.
@Override
public void write(DataOutputStream stream) throws IOException {
// --META--
// version id
stream.writeInt(version);
// last saved
stream.writeLong(TimeUtils.millis());
// --GENERAL STATE--
// gamemode
stream.writeByte(state.mode.ordinal());
// map ID
stream.writeByte(world.getMap().id);
// wave
stream.writeInt(state.wave);
// wave countdown
stream.writeFloat(state.wavetime);
// player x/y
stream.writeFloat(Vars.player.x);
stream.writeFloat(Vars.player.y);
// player health
stream.writeInt(Vars.player.health);
// amount of weapons
stream.writeByte(control.upgrades().getWeapons().size - 1);
// start at 1, because the first weapon is always the starter - ignore that
for (int i = 1; i < control.upgrades().getWeapons().size; i++) {
// weapon ordinal
stream.writeByte(control.upgrades().getWeapons().get(i).id);
}
// --INVENTORY--
int l = state.inventory.getItems().length;
int itemsize = 0;
for (int i = 0; i < l; i++) {
if (state.inventory.getItems()[i] > 0) {
itemsize++;
}
}
// amount of items
stream.writeByte(itemsize);
for (int i = 0; i < l; i++) {
if (state.inventory.getItems()[i] > 0) {
// item ID
stream.writeByte(i);
// item amount
stream.writeInt(state.inventory.getItems()[i]);
}
}
// --ENEMIES--
EntityContainer<Enemy> enemies = enemyGroup.all();
// enemy amount
stream.writeInt(enemies.size());
for (int i = 0; i < enemies.size(); i++) {
Enemy enemy = enemies.get(i);
// type
stream.writeByte(enemy.type.id);
// lane
stream.writeByte(enemy.lane);
// x
stream.writeFloat(enemy.x);
// y
stream.writeFloat(enemy.y);
// tier
stream.writeByte(enemy.tier);
// health
stream.writeShort(enemy.health);
}
// --MAP DATA--
// seed
stream.writeInt(world.getSeed());
int totalblocks = 0;
int totalrocks = 0;
for (int x = 0; x < world.width(); x++) {
for (int y = 0; y < world.height(); y++) {
Tile tile = world.tile(x, y);
if (tile.breakable()) {
if (tile.block() instanceof Rock) {
totalrocks++;
} else {
totalblocks++;
}
}
}
}
// amount of rocks
stream.writeInt(totalrocks);
// write all rocks
for (int x = 0; x < world.width(); x++) {
for (int y = 0; y < world.height(); y++) {
Tile tile = world.tile(x, y);
if (tile.block() instanceof Rock) {
stream.writeInt(tile.packedPosition());
}
}
}
// write all blocks
stream.writeInt(totalblocks);
for (int x = 0; x < world.width(); x++) {
for (int y = 0; y < world.height(); y++) {
Tile tile = world.tile(x, y);
if (tile.breakable() && !(tile.block() instanceof Rock)) {
// tile pos
stream.writeInt(x + y * world.width());
// block ID
stream.writeInt(tile.block().id);
if (tile.block() instanceof BlockPart)
stream.writeByte(tile.link);
if (tile.entity != null) {
// rotation
stream.writeByte(tile.getRotation());
// health
stream.writeShort((short) tile.entity.health);
byte amount = 0;
for (int i = 0; i < tile.entity.items.length; i++) {
if (tile.entity.items[i] > 0)
amount++;
}
// amount of items
stream.writeByte(amount);
for (int i = 0; i < tile.entity.items.length; i++) {
if (tile.entity.items[i] > 0) {
// item ID
stream.writeByte(i);
// item amount
stream.writeInt(tile.entity.items[i]);
}
}
tile.entity.write(stream);
}
}
}
}
}
use of io.anuke.mindustry.world.blocks.types.Rock in project Mindustry by Anuken.
the class Save14 method write.
@Override
public void write(DataOutputStream stream) throws IOException {
// --META--
// version id
stream.writeInt(version);
// last saved
stream.writeLong(TimeUtils.millis());
// --GENERAL STATE--
// gamemode
stream.writeByte(state.mode.ordinal());
// map ID
stream.writeByte(world.getMap().id);
// wave
stream.writeInt(state.wave);
// wave countdown
stream.writeFloat(state.wavetime);
// --BLOCK HEADER--
stream.writeInt(Block.getAllBlocks().size);
for (int i = 0; i < Block.getAllBlocks().size; i++) {
Block block = Block.getAllBlocks().get(i);
writeString(stream, block.name);
stream.writeShort(block.id);
}
// player x/y
stream.writeFloat(Vars.player.x);
stream.writeFloat(Vars.player.y);
// player health
stream.writeInt(Vars.player.health);
// amount of weapons
stream.writeByte(control.upgrades().getWeapons().size - 1);
// start at 1, because the first weapon is always the starter - ignore that
for (int i = 1; i < control.upgrades().getWeapons().size; i++) {
// weapon ordinal
stream.writeByte(control.upgrades().getWeapons().get(i).id);
}
// --INVENTORY--
int l = state.inventory.getItems().length;
int itemsize = 0;
for (int i = 0; i < l; i++) {
if (state.inventory.getItems()[i] > 0) {
itemsize++;
}
}
// amount of items
stream.writeByte(itemsize);
for (int i = 0; i < l; i++) {
if (state.inventory.getItems()[i] > 0) {
// item ID
stream.writeByte(i);
// item amount
stream.writeInt(state.inventory.getItems()[i]);
}
}
// --ENEMIES--
EntityContainer<Enemy> enemies = enemyGroup.all();
// enemy amount
stream.writeInt(enemies.size());
for (int i = 0; i < enemies.size(); i++) {
Enemy enemy = enemies.get(i);
// type
stream.writeByte(enemy.type.id);
// lane
stream.writeByte(enemy.lane);
// x
stream.writeFloat(enemy.x);
// y
stream.writeFloat(enemy.y);
// tier
stream.writeByte(enemy.tier);
// health
stream.writeShort(enemy.health);
}
// --MAP DATA--
// seed
stream.writeInt(world.getSeed());
int totalblocks = 0;
int totalrocks = 0;
for (int x = 0; x < world.width(); x++) {
for (int y = 0; y < world.height(); y++) {
Tile tile = world.tile(x, y);
if (tile.breakable()) {
if (tile.block() instanceof Rock) {
totalrocks++;
} else {
totalblocks++;
}
}
}
}
// amount of rocks
stream.writeInt(totalrocks);
// write all rocks
for (int x = 0; x < world.width(); x++) {
for (int y = 0; y < world.height(); y++) {
Tile tile = world.tile(x, y);
if (tile.block() instanceof Rock) {
stream.writeInt(tile.packedPosition());
}
}
}
// write all blocks
stream.writeInt(totalblocks);
for (int x = 0; x < world.width(); x++) {
for (int y = 0; y < world.height(); y++) {
Tile tile = world.tile(x, y);
if (tile.breakable() && !(tile.block() instanceof Rock)) {
// tile pos
stream.writeInt(x + y * world.width());
// block ID
stream.writeInt(tile.block().id);
if (tile.block() instanceof BlockPart)
stream.writeByte(tile.link);
if (tile.entity != null) {
// rotation
stream.writeByte(tile.getRotation());
// health
stream.writeShort((short) tile.entity.health);
byte amount = 0;
for (int i = 0; i < tile.entity.items.length; i++) {
if (tile.entity.items[i] > 0)
amount++;
}
// amount of items
stream.writeByte(amount);
for (int i = 0; i < tile.entity.items.length; i++) {
if (tile.entity.items[i] > 0) {
// item ID
stream.writeByte(i);
// item amount
stream.writeInt(tile.entity.items[i]);
}
}
tile.entity.write(stream);
}
}
}
}
}
use of io.anuke.mindustry.world.blocks.types.Rock in project Mindustry by Anuken.
the class Save15 method write.
@Override
public void write(DataOutputStream stream) throws IOException {
// --META--
// version id
stream.writeInt(version);
// last saved
stream.writeLong(TimeUtils.millis());
// --GENERAL STATE--
// gamemode
stream.writeByte(state.mode.ordinal());
// map ID
stream.writeByte(world.getMap().id);
// wave
stream.writeInt(state.wave);
// wave countdown
stream.writeFloat(state.wavetime);
stream.writeByte(state.difficulty.ordinal());
// --BLOCK HEADER--
stream.writeInt(Block.getAllBlocks().size);
for (int i = 0; i < Block.getAllBlocks().size; i++) {
Block block = Block.getAllBlocks().get(i);
writeString(stream, block.name);
stream.writeShort(block.id);
}
if (!headless) {
// player x/y
stream.writeFloat(player.x);
stream.writeFloat(player.y);
// player health
stream.writeInt(player.health);
// amount of weapons
stream.writeByte(control.upgrades().getWeapons().size - 1);
// start at 1, because the first weapon is always the starter - ignore that
for (int i = 1; i < control.upgrades().getWeapons().size; i++) {
// weapon ordinal
stream.writeByte(control.upgrades().getWeapons().get(i).id);
}
} else {
stream.writeFloat(world.getSpawnX());
stream.writeFloat(world.getSpawnY());
stream.writeInt(150);
stream.writeByte(0);
}
// --INVENTORY--
int l = state.inventory.getItems().length;
int itemsize = 0;
for (int i = 0; i < l; i++) {
if (state.inventory.getItems()[i] > 0) {
itemsize++;
}
}
// amount of items
stream.writeByte(itemsize);
for (int i = 0; i < l; i++) {
if (state.inventory.getItems()[i] > 0) {
// item ID
stream.writeByte(i);
// item amount
stream.writeInt(state.inventory.getItems()[i]);
}
}
// --ENEMIES--
EntityContainer<Enemy> enemies = enemyGroup.all();
// enemy amount
stream.writeInt(enemies.size());
for (int i = 0; i < enemies.size(); i++) {
Enemy enemy = enemies.get(i);
// type
stream.writeByte(enemy.type.id);
// lane
stream.writeByte(enemy.lane);
// x
stream.writeFloat(enemy.x);
// y
stream.writeFloat(enemy.y);
// tier
stream.writeByte(enemy.tier);
// health
stream.writeShort(enemy.health);
}
// --MAP DATA--
// seed
stream.writeInt(world.getSeed());
int totalblocks = 0;
int totalrocks = 0;
for (int x = 0; x < world.width(); x++) {
for (int y = 0; y < world.height(); y++) {
Tile tile = world.tile(x, y);
if (tile != null && tile.breakable()) {
if (tile.block() instanceof Rock) {
totalrocks++;
} else {
totalblocks++;
}
}
}
}
// amount of rocks
stream.writeInt(totalrocks);
// write all rocks
for (int x = 0; x < world.width(); x++) {
for (int y = 0; y < world.height(); y++) {
Tile tile = world.tile(x, y);
if (tile != null && tile.block() instanceof Rock) {
stream.writeInt(tile.packedPosition());
}
}
}
// write all blocks
stream.writeInt(totalblocks);
for (int x = 0; x < world.width(); x++) {
for (int y = 0; y < world.height(); y++) {
Tile tile = world.tile(x, y);
if (tile != null && tile.breakable() && !(tile.block() instanceof Rock)) {
// tile pos
stream.writeInt(x + y * world.width());
// block ID
stream.writeInt(tile.block().id);
if (tile.block() instanceof BlockPart)
stream.writeByte(tile.link);
if (tile.entity != null) {
// rotation
stream.writeByte(tile.getRotation());
// health
stream.writeShort((short) tile.entity.health);
byte amount = 0;
for (int i = 0; i < tile.entity.items.length; i++) {
if (tile.entity.items[i] > 0)
amount++;
}
// amount of items
stream.writeByte(amount);
for (int i = 0; i < tile.entity.items.length; i++) {
if (tile.entity.items[i] > 0) {
// item ID
stream.writeByte(i);
// item amount
stream.writeInt(tile.entity.items[i]);
}
}
tile.entity.write(stream);
}
}
}
}
}