diff --git a/src/projectzombie/Main.java b/src/projectzombie/Main.java index e6e9dbb..58fdaf1 100755 --- a/src/projectzombie/Main.java +++ b/src/projectzombie/Main.java @@ -35,7 +35,7 @@ import projectzombie.settings.Environment; import projectzombie.settings.Settings; import projectzombie.time.GameTimer; import projectzombie.time.NoSleep; -import projectzombie.util.FileHelpers; +import projectzombie.util.SaveSystem; import projectzombie.worker.WorkerTasks; import projectzombie.worker.WorkerLighting; import projectzombie.world.World; @@ -108,7 +108,7 @@ public class Main LayerGenerators.init(); Recipes.init(); - bdf_saves = FileHelpers.readBDF("./saves.bdf.gz"); + bdf_saves = SaveSystem.readBDF("./saves.bdf.gz"); // Create the display window = new DisplayWindow(); diff --git a/src/projectzombie/entity/player/EntityPlayer.java b/src/projectzombie/entity/player/EntityPlayer.java index 417901a..60c2107 100755 --- a/src/projectzombie/entity/player/EntityPlayer.java +++ b/src/projectzombie/entity/player/EntityPlayer.java @@ -60,6 +60,7 @@ public class EntityPlayer extends Entity implements private Vec2i break_pos = new Vec2i(0, 0); public boolean dead = false; public boolean in_animation = false; + public int attackedCooldown = 0; private ArrayList tasks; private Inventory inventory; @@ -88,9 +89,8 @@ public class EntityPlayer extends Entity implements angle = nl.get("angle").getDouble(); temperature = nl.get("temperature").getDouble(); hydration = nl.get("hydration").getDouble(); - in_animation = nl.get("inAnimation").getBoolean(); - moving = nl.get("moving").getBoolean(); inventory_hand = nl.get("hand").getInteger(); + attackedCooldown = nl.get("attackedCooldown").getInteger(); tasks = new ArrayList(); @@ -122,9 +122,8 @@ public class EntityPlayer extends Entity implements nl.set("temperature", bdf.newObject().setDouble(temperature)); nl.set("hydration", bdf.newObject().setDouble(hydration)); nl.set("tasks", Task.saveTasks(bdf.newObject(), tasks.toArray(new Task[0]))); - nl.set("inAnimation", bdf.newObject().setBoolean(in_animation)); - nl.set("moving", bdf.newObject().setBoolean(moving)); nl.set("hand", bdf.newObject().setInteger(inventory_hand)); + nl.set("attackedCooldown", bdf.newObject().setInteger(attackedCooldown)); } public EntityPlayer() { @@ -201,6 +200,10 @@ public class EntityPlayer extends Entity implements // Call super super.tick(chunk, layer); + if(attackedCooldown > 0) { + attackedCooldown -= 1; + } + double temp_diff = MathHelpers.biggest( layer.layergen.getTemperature(layer, getPos().xz()), chunk.getLightLevel(getPos().xz().toInt()) * 0.6) - temperature; @@ -210,15 +213,22 @@ public class EntityPlayer extends Entity implements if(temperature < 0.3) { health -= 2 * (0.3 - temperature); + resetAttackTimer(); } - if(temperature > 0.7) { + else if(temperature > 0.7) { health -= 4 * (temperature - 0.7); + resetAttackTimer(); + } + + else if(attackedCooldown == 0 && health < health_max) { + health += 0.1; } if(hydration <= 0) { hydration = 0; health -= 0.1; + resetAttackTimer(); } // Rotate left @@ -350,8 +360,12 @@ public class EntityPlayer extends Entity implements @Override public void addDamage(double amount) { - //amount = amount / (defence_level / 2.5 + 1); health -= amount; + resetAttackTimer(); + } + + public void resetAttackTimer() { + attackedCooldown = 3000; // Don't heal for 30 seconds } @Override @@ -425,7 +439,8 @@ public class EntityPlayer extends Entity implements Model model_place = holding.item.getPlaceModel(holding); Model model_spawn = holding.item.getSpawnModel(holding); Vec2d pos = ppos.xz().add(MathHelpers.moveTowards2(1, Math.toRadians(angle))); - boolean render_place_model = model_place != null && layer.getFrontTile(pos.toInt()).tile == Tiles.VOID; + boolean render_place_model = model_place != null && + holding.item.showPlaceModel(layer, pos.toInt(), holding); if(render_place_model || model_spawn != null) { @@ -434,13 +449,13 @@ public class EntityPlayer extends Entity implements if(render_place_model) { - model_place.setModel(Matrix4.translate(Math.floor(pos.x) - ppos.x + 0.5, 0, Math.floor(pos.y) - ppos.z + 0.5)); + model_place.setModel(Matrix4.translate(Math.floor(pos.x) - ppos.x + 0.5, 0.001, Math.floor(pos.y) - ppos.z + 0.5)); model_place.render(); } if(model_spawn != null) { - model_spawn.setModel(Matrix4.translate(pos.x - ppos.x, 0, pos.y - ppos.z)); + model_spawn.setModel(Matrix4.translate(pos.x - ppos.x, 0.001, pos.y - ppos.z)); model_spawn.render(); } diff --git a/src/projectzombie/init/Items.java b/src/projectzombie/init/Items.java index 1ad8e4d..f2df7f3 100755 --- a/src/projectzombie/init/Items.java +++ b/src/projectzombie/init/Items.java @@ -31,6 +31,7 @@ import projectzombie.items.ItemStonePick; import projectzombie.items.ItemStoneShovel; import projectzombie.items.ItemTnt; import projectzombie.items.ItemTorch; +import projectzombie.items.ItemWoodPlanks; import projectzombie.items.ItemWorkbench; import projectzombie.items.spawner.ItemSpawnDummy; import projectzombie.items.spawner.ItemSpawnZombie; @@ -78,6 +79,7 @@ public class Items register(CLAY_POT_WET); register(TORCH); register(COAL); + register(WOOD_PLANKS); } public static final Item AMMO = new ItemAmmo(); @@ -111,4 +113,5 @@ public class Items public static final Item CLAY_POT_WET = new ItemClayPotWet(); public static final Item TORCH = new ItemTorch(); public static final Item COAL = new ItemCoal(); + public static final Item WOOD_PLANKS = new ItemWoodPlanks(); } diff --git a/src/projectzombie/init/Models.java b/src/projectzombie/init/Models.java index b5316c2..2d32baa 100755 --- a/src/projectzombie/init/Models.java +++ b/src/projectzombie/init/Models.java @@ -18,6 +18,7 @@ import projectzombie.model.ModelTile; import projectzombie.model.ModelTree; import projectzombie.model.ModelTreeSnow; import projectzombie.model.ModelVertical; +import projectzombie.model.ModelWall; public class Models { @@ -89,6 +90,19 @@ public class Models public static final Model TILE_ROCK_COAL = new ModelRock(Resources.ATLAS.get("/tile/rock_coal.png")); public static final Model TILE_ROCK_URANIUM = new ModelRock(Resources.ATLAS.get("/tile/rock_uranium.png")); + public static final Model TILE_WOOD_FLOOR = new ModelTile(Resources.ATLAS.get("/tile/wood_floor.png")); + public static final Model TILE_WOOD_SNOW_FLOOR = new ModelTile(Resources.ATLAS.get("/tile/wood_snow_floor.png")); + + public static final Model[] TILE_WOOD_WALL = ModelWall.rotationArray( + Resources.ATLAS.get("/tile/wood_wall_front.png"), + Resources.ATLAS.get("/tile/wood_wall_top.png"), + Resources.ATLAS.get("/tile/wood_wall_side.png")); + + public static final Model[] TILE_WOOD_SNOW_WALL = ModelWall.rotationArray( + Resources.ATLAS.get("/tile/wood_snow_wall_front.png"), + Resources.ATLAS.get("/tile/wood_snow_wall_top.png"), + Resources.ATLAS.get("/tile/wood_snow_wall_side.png")); + public static final Model ENTITY_BOSS_IDLE = new ModelVertical(Resources.ATLAS.get("/entity/boss1/boss_still.png"), new Vec2d(4, 4)); public static final Model ENTITY_BOSS_FIRING = new ModelVertical(Resources.ATLAS.get("/entity/boss1/boss_firing.png"), new Vec2d(4, 4), 4, 50); public static final Model ENTITY_BOSS_WALKING = new ModelVertical(Resources.ATLAS.get("/entity/boss1/boss_walking.png"), new Vec2d(4, 4), 4, 50); @@ -199,6 +213,10 @@ public class Models public static final ModelItem ITEM_LOG_SNOW = new ModelItem(Resources.ATLAS.get("/item/log_snow.png")); public static final ModelItem ITEM_CHARCOAL = new ModelItem(Resources.ATLAS.get("/item/charcoal.png")); public static final ModelItem ITEM_ASH = new ModelItem(Resources.ATLAS.get("/item/ash.png")); + public static final ModelItem ITEM_WOOD_FLOOR = new ModelItem(Resources.ATLAS.get("/item/wood_floor.png")); + public static final ModelItem ITEM_WOOD_SNOW_FLOOR = new ModelItem(Resources.ATLAS.get("/item/wood_snow_floor.png")); + public static final ModelItem ITEM_WOOD_PLANKS = new ModelItem(Resources.ATLAS.get("/item/wood_planks.png")); + public static final ModelItem ITEM_WOOD_SNOW_PLANKS = new ModelItem(Resources.ATLAS.get("/item/wood_snow_planks.png")); // Player varients public static final ModelPlayer ENTITY_PLAYER_W = new ModelPlayer( diff --git a/src/projectzombie/init/Recipes.java b/src/projectzombie/init/Recipes.java index 5adf0ca..ffac85c 100644 --- a/src/projectzombie/init/Recipes.java +++ b/src/projectzombie/init/Recipes.java @@ -41,6 +41,13 @@ public class Recipes // Basic crafting items + recipies.add(new RecipeBasic( + new ItemStack[] { + new ItemStack(Items.LOG, 1), + }, new Crafting[] { + Crafting.BASIC, + }, new ItemStack(Items.WOOD_PLANKS, 2))); + recipies.add(new RecipeBasic( new ItemStack[] { new ItemStack(Items.FLINT, 2), diff --git a/src/projectzombie/items/Item.java b/src/projectzombie/items/Item.java index 3abad39..a376291 100755 --- a/src/projectzombie/items/Item.java +++ b/src/projectzombie/items/Item.java @@ -3,10 +3,12 @@ package projectzombie.items; import gl_engine.vec.Vec2d; import gl_engine.vec.Vec2i; import gl_engine.vec.Vec3d; +import projectzombie.Main; import projectzombie.entity.Entity; import projectzombie.entity.EntityHasInventory; import projectzombie.entity.player.EntityPlayer; import projectzombie.init.Models; +import projectzombie.init.Tiles; import projectzombie.inventory.IInventory; import projectzombie.items.modifier.ItemModifierDamage; import projectzombie.model.Model; @@ -36,6 +38,10 @@ public abstract class Item return null; } + public boolean showPlaceModel(Layer layer, Vec2i pos, ItemStack stack) { + return layer.getFrontTile(pos).tile == Tiles.VOID; + } + public Model getSpawnModel(ItemStack stack) { return null; } diff --git a/src/projectzombie/items/ItemWoodPlanks.java b/src/projectzombie/items/ItemWoodPlanks.java new file mode 100644 index 0000000..79e8aba --- /dev/null +++ b/src/projectzombie/items/ItemWoodPlanks.java @@ -0,0 +1,40 @@ +package projectzombie.items; + +import gl_engine.vec.Vec2i; +import projectzombie.init.Models; +import projectzombie.items.modifier.ItemModifierMeta; +import projectzombie.model.Model; +import projectzombie.model.ModelItem; +import projectzombie.util.ItemStack; +import projectzombie.world.layer.Layer; + +public class ItemWoodPlanks extends Item +{ + + @Override + public ModelItem getModel(ItemStack stack) + { + switch(ItemModifierMeta.getStackMeta(stack)) + { + case 0: return Models.ITEM_WOOD_PLANKS; + case 1: return Models.ITEM_WOOD_SNOW_PLANKS; + default: return Models.ITEM_EMPTY; + } + } + + @Override + public boolean showPlaceModel(Layer layer, Vec2i pos, ItemStack stack) { + return true; + } + + @Override + public Model getPlaceModel(ItemStack stack) { + return Models.TILE_WOOD_FLOOR; + } + + @Override + public String getName(ItemStack stack) { + return "Wood Planks"; + } + +} diff --git a/src/projectzombie/menu/MenuSaves.java b/src/projectzombie/menu/MenuSaves.java index 087653e..8bc9277 100644 --- a/src/projectzombie/menu/MenuSaves.java +++ b/src/projectzombie/menu/MenuSaves.java @@ -21,7 +21,6 @@ import projectzombie.menu.gui.GUIContainerSlider; import projectzombie.menu.gui.GUILabel; import projectzombie.menu.gui.GUISavesCard; import projectzombie.model.ModelGui; -import projectzombie.util.FileHelpers; import projectzombie.worker.WorkerTasks; import projectzombie.world.World; diff --git a/src/projectzombie/menu/MenuWorldDelete.java b/src/projectzombie/menu/MenuWorldDelete.java index 5a48141..2c40b37 100644 --- a/src/projectzombie/menu/MenuWorldDelete.java +++ b/src/projectzombie/menu/MenuWorldDelete.java @@ -24,7 +24,6 @@ import projectzombie.menu.gui.GUIBackToMenu; import projectzombie.menu.gui.GUIButtonBasic; import projectzombie.menu.gui.GUILabel; import projectzombie.menu.gui.GUITextBox; -import projectzombie.util.FileHelpers; import projectzombie.worker.WorkerTasks; public class MenuWorldDelete extends Menu diff --git a/src/projectzombie/menu/MenuWorldNew.java b/src/projectzombie/menu/MenuWorldNew.java index 277be1a..9cfbc42 100644 --- a/src/projectzombie/menu/MenuWorldNew.java +++ b/src/projectzombie/menu/MenuWorldNew.java @@ -6,7 +6,6 @@ import java.util.Random; import bdf.types.BdfArray; import bdf.types.BdfNamedList; import bdf.types.BdfObject; -import bdf.types.BdfReader; import gl_engine.vec.Vec2d; import projectzombie.Main; import projectzombie.init.Models; @@ -17,7 +16,6 @@ import projectzombie.menu.gui.GUIBackToMenu; import projectzombie.menu.gui.GUIButtonBasic; import projectzombie.menu.gui.GUILabel; import projectzombie.menu.gui.GUITextBox; -import projectzombie.util.FileHelpers; import projectzombie.worker.WorkerTasks; import projectzombie.world.World; diff --git a/src/projectzombie/model/ModelWall.java b/src/projectzombie/model/ModelWall.java new file mode 100644 index 0000000..4c3b22c --- /dev/null +++ b/src/projectzombie/model/ModelWall.java @@ -0,0 +1,113 @@ +package projectzombie.model; + +import gl_engine.texture.TextureRef3D; + +public class ModelWall extends Model +{ + private int rotation; + private TextureRef3D front; + private TextureRef3D side; + private TextureRef3D top; + + public ModelWall(TextureRef3D front, TextureRef3D top, TextureRef3D side, int rotation) { + this.rotation = rotation; + this.front = front; + this.side = side; + this.top = top; + } + + public static ModelWall[] rotationArray(TextureRef3D front, TextureRef3D top, TextureRef3D side) { + return new ModelWall[] { + new ModelWall(front, top, side, 0), + new ModelWall(front, top, side, 1), + new ModelWall(front, top, side, 2), + new ModelWall(front, top, side, 3), + }; + } + + @Override + public int[] getIndicies() { + return new int[] { + 0, 1, 2, + 2, 3, 0, + + 4, 5, 6, + 6, 7, 4, + + 8, 9, 10, + 10, 11, 8, + + 12, 13, 14, + 14, 15, 12, + + 16, 17, 18, + 18, 19, 16, + }; + } + + @Override + public float[] getVerticies() + { + float x1 = 0.5f, z1 = 0.5f, x2 = 0.25f, z2 = -0.5f; + + return new float[] + { + x1, 0, z1, 0, 0, 0, 0, 1, 0, 0, 0, 1, 1, 1, 0, 0, + x1, 0, z2, 1, 0, 0, 0, 1, 0, 0, 0, 1, 1, 1, 0, 0, + x1, 1, z2, 1, 1, 0, 0, 1, 0, 0, 0, 1, 1, 1, 0, 0, + x1, 1, z1, 0, 1, 0, 0, 1, 0, 0, 0, 1, 1, 1, 0, 0, + + x2, 0, z1, 0, 0, 0, 0, 1, 0, 0, 0, 1, 1, 1, 0, 0, + x2, 0, z2, 1, 0, 0, 0, 1, 0, 0, 0, 1, 1, 1, 0, 0, + x2, 1, z2, 1, 1, 0, 0, 1, 0, 0, 0, 1, 1, 1, 0, 0, + x2, 1, z1, 0, 1, 0, 0, 1, 0, 0, 0, 1, 1, 1, 0, 0, + + x1, 0, z1, 0, 0, 0, 0, 1, 0, 0, 0, 1, 1, 1, 0, 0, + x2, 0, z1, 1, 0, 0, 0, 1, 0, 0, 0, 1, 1, 1, 0, 0, + x2, 1, z1, 1, 1, 0, 0, 1, 0, 0, 0, 1, 1, 1, 0, 0, + x1, 1, z1, 0, 1, 0, 0, 1, 0, 0, 0, 1, 1, 1, 0, 0, + + x1, 0, z2, 0, 0, 0, 0, 1, 0, 0, 0, 1, 1, 1, 0, 0, + x2, 0, z2, 1, 0, 0, 0, 1, 0, 0, 0, 1, 1, 1, 0, 0, + x2, 1, z2, 1, 1, 0, 0, 1, 0, 0, 0, 1, 1, 1, 0, 0, + x1, 1, z2, 0, 1, 0, 0, 1, 0, 0, 0, 1, 1, 1, 0, 0, + + x1, 1, z1, 0, 0, 0, 0, 1, 0, 0, 0, 1, 1, 1, 0, 0, + x2, 1, z1, 1, 0, 0, 0, 1, 0, 0, 0, 1, 1, 1, 0, 0, + x2, 1, z2, 1, 1, 0, 0, 1, 0, 0, 0, 1, 1, 1, 0, 0, + x1, 1, z2, 0, 1, 0, 0, 1, 0, 0, 0, 1, 1, 1, 0, 0, + }; + } + + @Override + public TextureRef3D[] getTextures() { + return new TextureRef3D[] { + front, front, front, front, + front, front, front, front, + side, side, side, side, + side, side, side, side, + top, top, top, top, + }; + } + + @Override + public double getWidth() { + return 1; + } + + @Override + public double getHeight() { + return 1; + } + + @Override + public int getIndexSize() { + return 30; + } + + @Override + public int getSize() { + return 20; + } + +} diff --git a/src/projectzombie/settings/Settings.java b/src/projectzombie/settings/Settings.java index 7978fe7..f21427d 100755 --- a/src/projectzombie/settings/Settings.java +++ b/src/projectzombie/settings/Settings.java @@ -1,7 +1,7 @@ package projectzombie.settings; import projectzombie.util.ClassBdf; -import projectzombie.util.FileHelpers; +import projectzombie.util.SaveSystem; import projectzombie.worker.WorkerTasks; import bdf.types.BdfNamedList; import bdf.types.BdfObject; @@ -122,7 +122,7 @@ public class Settings implements ClassBdf } public static void init() { - READER = FileHelpers.readBDF("./settings.bdf.gz"); + READER = SaveSystem.readBDF("./settings.bdf.gz"); SETTINGS.BdfClassLoad(READER.getObject()); } diff --git a/src/projectzombie/tiles/TileHemp.java b/src/projectzombie/tiles/TileHemp.java index 2a4673e..91b4369 100644 --- a/src/projectzombie/tiles/TileHemp.java +++ b/src/projectzombie/tiles/TileHemp.java @@ -24,7 +24,7 @@ public class TileHemp extends Tile public void tickRandomly(Layer layer, Chunk chunk, TileState state, Vec2i pos) { super.tickRandomly(layer, chunk, state, pos); - if(Math.random() > 0.9) { + if(Math.random() > 0.96) { if(state.meta < 7) { layer.setFrontTile(new TileState(this, state.meta + 1), pos); } diff --git a/src/projectzombie/util/FileHelpers.java b/src/projectzombie/util/FileHelpers.java deleted file mode 100644 index b42ef85..0000000 --- a/src/projectzombie/util/FileHelpers.java +++ /dev/null @@ -1,37 +0,0 @@ -package projectzombie.util; - -import java.io.ByteArrayOutputStream; -import java.io.FileInputStream; -import java.io.IOException; -import java.io.InputStream; -import java.util.zip.GZIPInputStream; - -import bdf.types.BdfReader; -import projectzombie.settings.Environment; - -public class FileHelpers -{ - public static BdfReader readBDF(String path) - { - try - { - InputStream in = new GZIPInputStream(new FileInputStream(Environment.gdir + path)); - ByteArrayOutputStream out = new ByteArrayOutputStream(); - - byte buffer[] = new byte[1024]; - int size; - - while((size = in.read(buffer)) != -1) { - out.write(buffer, 0, size); - } - - in.close(); - - return new BdfReader(out.toByteArray()); - } - - catch(IOException e) { - return new BdfReader(); - } - } -} diff --git a/src/projectzombie/util/SaveSystem.java b/src/projectzombie/util/SaveSystem.java new file mode 100644 index 0000000..a5d886a --- /dev/null +++ b/src/projectzombie/util/SaveSystem.java @@ -0,0 +1,87 @@ +package projectzombie.util; + +import java.io.ByteArrayOutputStream; +import java.io.FileInputStream; +import java.io.IOException; +import java.io.InputStream; +import java.util.HashMap; +import java.util.zip.GZIPInputStream; + +import bdf.types.BdfReader; +import projectzombie.Main; +import projectzombie.settings.Environment; +import projectzombie.worker.WorkerTasks; +import projectzombie.world.chunk.Chunk; + +public class SaveSystem +{ + private static HashMap map = new HashMap(); + + public static BdfReader readBDF(String path) + { + try + { + InputStream in = new GZIPInputStream(new FileInputStream(Environment.gdir + path)); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + + byte buffer[] = new byte[1024]; + int size; + + while((size = in.read(buffer)) != -1) { + out.write(buffer, 0, size); + } + + in.close(); + + return new BdfReader(out.toByteArray()); + } + + catch(IOException e) { + return new BdfReader(); + } + } + + public synchronized static void save(String path, BdfReader reader) { + map.put(path, reader); + } + + public synchronized static void saveChunk(Chunk chunk) + { + String path = Main.world.getSavePath(); + + if(path == null) { + return; + } + + path = "./saves/" + path + "/c_" + chunk.layer.id + "_" + chunk.c_pos.x + "_" + chunk.c_pos.y + ".bdf.gz"; + + BdfReader reader = new BdfReader(); + + chunk.BdfClassSave(reader.getObject()); + + map.put(path, reader); + } + + public synchronized static BdfReader load(String path) + { + if(map.containsKey(path)) { + return map.get(path); + } + + else { + return readBDF(path); + } + } + + public synchronized static void saveAll() + { + for(String path : map.keySet()) + { + BdfReader reader = map.get(path); + + WorkerTasks.saveToFile(path, reader); + } + + map.clear(); + } +} diff --git a/src/projectzombie/worker/WorkerTaskChunkLoad.java b/src/projectzombie/worker/WorkerTaskChunkLoad.java index 956177d..1bc2a76 100644 --- a/src/projectzombie/worker/WorkerTaskChunkLoad.java +++ b/src/projectzombie/worker/WorkerTaskChunkLoad.java @@ -4,7 +4,7 @@ import java.util.Vector; import bdf.types.BdfReader; import gl_engine.vec.Vec2i; -import projectzombie.util.FileHelpers; +import projectzombie.util.SaveSystem; import projectzombie.world.chunk.Chunk; import projectzombie.world.layer.Layer; @@ -29,7 +29,7 @@ public class WorkerTaskChunkLoad extends WorkerTaskChunk String path = "./saves/" + this.path + "/c_" + layer.id + "_" + pos.x + "_" + pos.y + ".bdf.gz"; - BdfReader reader = FileHelpers.readBDF(path); + BdfReader reader = SaveSystem.load(path); Chunk chunk = new Chunk(layer, pos, reader.getObject()); diff --git a/src/projectzombie/worker/WorkerTaskChunkSave.java b/src/projectzombie/worker/WorkerTaskChunkSave.java deleted file mode 100644 index 4d6536b..0000000 --- a/src/projectzombie/worker/WorkerTaskChunkSave.java +++ /dev/null @@ -1,54 +0,0 @@ -package projectzombie.worker; - -import java.io.FileOutputStream; -import java.io.IOException; -import java.io.OutputStream; -import java.util.Vector; -import java.util.zip.GZIPOutputStream; - -import bdf.types.BdfReader; -import gl_engine.vec.Vec2i; -import projectzombie.settings.Environment; -import projectzombie.util.FileHelpers; -import projectzombie.world.chunk.Chunk; - -public class WorkerTaskChunkSave extends WorkerTaskChunk -{ - Chunk chunk; - String path; - int id; - - public WorkerTaskChunkSave(String path, Vec2i pos, Chunk chunk, int id) { - this.path = path; - this.pos = pos; - this.chunk = chunk; - this.id = id; - } - - @Override - public void run() - { - if(path == null) { - return; - } - - String path = "./saves/" + this.path + "/c_" + id + "_" + pos.x + "_" + pos.y + ".bdf.gz"; - - BdfReader reader = new BdfReader(); - - chunk.BdfClassSave(reader.getObject()); - - try - { - OutputStream out = new GZIPOutputStream(new FileOutputStream(Environment.gdir + path)); - - reader.serialize().writeToStream(out); - - out.close(); - } - - catch(IOException e) { - e.printStackTrace(); - } - } -} diff --git a/src/projectzombie/worker/WorkerTasks.java b/src/projectzombie/worker/WorkerTasks.java index ba5be0b..319c593 100644 --- a/src/projectzombie/worker/WorkerTasks.java +++ b/src/projectzombie/worker/WorkerTasks.java @@ -25,10 +25,6 @@ public class WorkerTasks extends Thread public static void loadChunk(String path, Layer layer, Vec2i pos) { tasks_in.add(new WorkerTaskChunkLoad(path, layer, pos.copy())); } - - public static void saveChunk(String path, Vec2i pos, Chunk chunk, int id) { - tasks_in.add(new WorkerTaskChunkSave(path, pos.copy(), chunk, id)); - } public static void saveToFile(String path, BdfReader reader) { tasks_in.add(new WorkerTaskFile(path, reader)); diff --git a/src/projectzombie/world/World.java b/src/projectzombie/world/World.java index 3a431d4..0b1460a 100755 --- a/src/projectzombie/world/World.java +++ b/src/projectzombie/world/World.java @@ -9,7 +9,7 @@ import org.lwjgl.BufferUtils; import org.lwjgl.opengl.GL33; import projectzombie.util.ClassBdf; -import projectzombie.util.FileHelpers; +import projectzombie.util.SaveSystem; import bdf.types.BdfArray; import bdf.types.BdfNamedList; import bdf.types.BdfObject; @@ -62,7 +62,7 @@ public class World implements ClassBdf } if(file_dir.exists()) { - BdfReader reader = FileHelpers.readBDF(path + "world.bdf.gz"); + BdfReader reader = SaveSystem.load(path + "world.bdf.gz"); BdfClassLoad(reader.getObject()); } } @@ -270,10 +270,10 @@ public class World implements ClassBdf } BdfReader reader = new BdfReader(); - BdfObject bdf = reader.getObject(); - BdfClassSave(bdf); + BdfClassSave(reader.getObject()); - WorkerTasks.saveToFile("./saves/" + path + "/world.bdf.gz", reader); + SaveSystem.save("./saves/" + path + "/world.bdf.gz", reader); + SaveSystem.saveAll(); } } diff --git a/src/projectzombie/world/layer/Layer.java b/src/projectzombie/world/layer/Layer.java index d035c17..2dec54f 100755 --- a/src/projectzombie/world/layer/Layer.java +++ b/src/projectzombie/world/layer/Layer.java @@ -5,6 +5,7 @@ import java.util.ArrayList; import java.util.Random; import projectzombie.util.ClassBdf; +import projectzombie.util.SaveSystem; import projectzombie.util.TileState; import bdf.types.BdfArray; import bdf.types.BdfNamedList; @@ -316,7 +317,7 @@ public class Layer implements ClassBdf Chunk chunk = chunks.get(pos); if(chunk.isDirty()) { - WorkerTasks.saveChunk(Main.world.getSavePath(), pos, chunk, id); + SaveSystem.saveChunk(chunk); if(!hasSavedChunk(pos)) { chunks_saved.add(pos); @@ -405,7 +406,7 @@ public class Layer implements ClassBdf { if(chunk.o.isDirty()) { - WorkerTasks.saveChunk(Main.world.getSavePath(), chunk.pos, chunk.o, id); + SaveSystem.saveChunk(chunk.o); if(!hasSavedChunk(chunk.pos)) { chunks_saved.add(chunk.pos); diff --git a/src/resources/texture/item/wood_planks.png b/src/resources/texture/item/wood_planks.png new file mode 100644 index 0000000..1709c7a Binary files /dev/null and b/src/resources/texture/item/wood_planks.png differ diff --git a/src/resources/texture/item/wood_snow_planks.png b/src/resources/texture/item/wood_snow_planks.png new file mode 100644 index 0000000..7d5b81f Binary files /dev/null and b/src/resources/texture/item/wood_snow_planks.png differ diff --git a/src/resources/texture/item/wood_snow_wall.png b/src/resources/texture/item/wood_snow_wall.png new file mode 100644 index 0000000..1df8a62 Binary files /dev/null and b/src/resources/texture/item/wood_snow_wall.png differ diff --git a/src/resources/texture/item/wood_wall.png b/src/resources/texture/item/wood_wall.png new file mode 100644 index 0000000..b0d6046 Binary files /dev/null and b/src/resources/texture/item/wood_wall.png differ diff --git a/src/resources/texture/list.txt b/src/resources/texture/list.txt index 927d3a5..c062e6d 100644 --- a/src/resources/texture/list.txt +++ b/src/resources/texture/list.txt @@ -1,259 +1,274 @@ -./text/char_question.png -./text/char_l_a.png -./text/char_u_j.png -./text/char_l_u.png -./text/char_u_s.png -./text/char_l_s.png -./text/char_apostrophe.png -./text/char_plus.png -./text/char_l_e.png -./text/char_7.png -./text/char_minus.png -./text/char_u_r.png -./text/char_u_l.png -./text/char_obracket.png -./text/char_pow.png -./text/char_u_m.png -./text/char_l_t.png -./text/char_percent.png -./text/char_l_y.png -./text/char_0.png -./text/char_4.png -./text/char_l_r.png -./text/char_l_m.png -./text/char_cbracket.png -./text/char_u_g.png -./text/char_u_q.png -./text/char_u_i.png -./text/char_tilde.png -./text/char_l_w.png -./text/char_l_v.png -./text/char_fslash.png -./text/char_u_p.png -./text/char_gthan.png -./text/char_8.png -./text/char_unknown.png -./text/char_and.png -./text/char_osbracket.png -./text/char_u_n.png -./text/char_l_i.png -./text/char_u_y.png -./text/char_l_p.png -./text/char_lthan.png -./text/char_l_g.png -./text/char_bslash.png -./text/char_1.png -./text/char_u_z.png -./text/char_l_f.png -./text/char_u_w.png -./text/char_9.png -./text/char_l_x.png -./text/char_ccbracket.png -./text/char_l_o.png -./text/char_equals.png -./text/char_l_d.png -./text/char_dollar.png -./text/char_hashtag.png -./text/char_l_q.png -./text/char_u_o.png -./text/char_6.png -./text/char_u_d.png -./text/char_u_e.png -./text/char_exclamation.png -./text/char_vertical.png -./text/char_ocbracket.png -./text/char_u_k.png -./text/char_u_c.png -./text/char_l_n.png -./text/char_semicolon.png -./text/char_u_b.png -./text/char_u_f.png -./text/char_l_h.png -./text/char_l_k.png -./text/char_u_t.png -./text/char_3.png -./text/char_u_v.png -./text/char_u_h.png -./text/char_quotation.png -./text/char_u_a.png -./text/char_l_b.png -./text/char_underscore.png -./text/char_u_x.png -./text/char_comma.png -./text/char_csbracket.png -./text/char_l_l.png -./text/char_5.png -./text/char_star.png -./text/char_colon.png -./text/char_l_z.png -./text/char_space.png -./text/char_2.png -./text/char_at.png -./text/char_grave.png -./text/char_l_j.png -./text/char_fullstop.png -./text/char_l_c.png -./text/char_u_u.png +./tile/hemp6.png +./tile/rock_gold.png +./tile/hemp7.png +./tile/hemp1.png +./tile/rock.png +./tile/rock_ice.png +./tile/sapling3.png +./tile/ladder.png +./tile/tree_leaves_snow.png +./tile/wood_wall_front.png +./tile/ice_wall.png +./tile/water.png +./tile/sandstone_wall.png +./tile/ladder_up.png +./tile/rock_copper.png +./tile/cactus4.png +./tile/tall_grass.png +./tile/wood_snow_floor.png +./tile/cactus2.png +./tile/grass_infested.png +./tile/tree_branch_leaves.png +./tile/dirt.png +./tile/wall.png +./tile/rock_tin.png +./tile/tree_base.png +./tile/cactus1.png +./tile/sapling4.png +./tile/hemp3.png +./tile/wood_floor.png +./tile/cactus_top.png +./tile/tunnel_down.png +./tile/stone.png +./tile/snow.png +./tile/boss_portal.png +./tile/rock_coal.png +./tile/hemp4.png +./tile/sand.png +./tile/rock_iron.png +./tile/lantern.png +./tile/ice.png +./tile/rock_uranium.png +./tile/sapling1.png +./tile/campfire_lit.png +./tile/grass_burnt.png +./tile/chest.png +./tile/hemp2.png +./tile/hemp8.png +./tile/cactus3.png +./tile/lava.png +./tile/wood_wall_top.png +./tile/tree_leaves.png +./tile/hemp5.png +./tile/campfire_unlit.png +./tile/lava_flow.png +./tile/wood_snow_wall_side.png +./tile/grass.png +./tile/tree_branch.png +./tile/wood_snow_wall_front.png +./tile/wood_snow_wall_top.png +./tile/sandstone.png +./tile/tree_branch_leaves_snow.png +./tile/rock_sandstone.png +./tile/wood_wall_side.png +./tile/sapling2.png ./list.txt -./player/player_white_front_moving.png -./player/player_white_back_moving.png -./player/player_black_back_moving.png -./player/player_black_back_still.png +./item/rock_gold.png +./item/log.png +./item/rock.png +./item/stone_shovel.png +./item/wood_snow_planks.png +./item/coal.png +./item/rock_copper.png +./item/acorn.png +./item/iron_pick.png +./item/clay.png +./item/stone_pick.png +./item/rock_tin.png +./item/charcoal.png +./item/ammo_box.png +./item/plant_fibre.png +./item/wood_snow_wall.png +./item/iron_hatchet.png +./item/torch_lit.png +./item/rock_iron.png +./item/stone_hatchet.png +./item/flint_hatchet.png +./item/rock_uranium.png +./item/hemp_seed.png +./item/shield_upgrade.png +./item/grappling_hook.png +./item/log_snow.png +./item/wood_planks.png +./item/iron_shovel.png +./item/wood_wall.png +./item/health_potion.png +./item/ash.png +./item/snow_pile.png +./item/torch_unlit.png +./item/gun_upgrade.png +./item/sandstone.png +./item/flint.png ./player/player_white_back_still.png ./player/player_white_front_still.png ./player/player_black_front_moving.png ./player/player_black_front_still.png -./particle/smoke_trail.png -./particle/water.png -./particle/smoke_0.png -./particle/smoke_1.png -./particle/blood.png -./particle/lava.png -./particle/bullet.png -./particle/smoke_2.png -./particle/snow.png -./particle/rain.png -./particle/smoke_4.png -./particle/smoke_3.png -./particle/smoke_5.png -./gui/temperature.png -./gui/slot_armor_chest.png -./gui/health_empty.png -./gui/button_hover.png +./player/player_black_back_moving.png +./player/player_black_back_still.png +./player/player_white_back_moving.png +./player/player_white_front_moving.png +./gui/selection_box_wide.png ./gui/item_slot_storage.png +./gui/text_box.png +./gui/pixel_white.png ./gui/water.png +./gui/gun.png +./gui/selection_box_storage.png +./gui/button_delete.png +./gui/button_delete_hover.png +./gui/slot_armor_chest.png +./gui/pixel_black.png +./gui/slot_clothing_shirt.png +./gui/button_play.png ./gui/slot_armor_legs.png -./gui/button_normal.png +./gui/inventory.png ./gui/label.png -./gui/hotbar.png +./gui/slot_clothing_pants.png +./gui/health_empty.png +./gui/label_recipe.png +./gui/hotbar_selected.png +./gui/health_full.png +./gui/temperature.png +./gui/button_play_hover.png +./gui/text_cursor.png ./gui/slot_armor_helmet.png ./gui/selection_box_crafting.png -./gui/button_delete.png -./gui/text_cursor.png -./gui/inventory.png -./gui/button_delete_hover.png -./gui/button_play_hover.png -./gui/health_full.png -./gui/hotbar_selected.png -./gui/slot_clothing_shirt.png -./gui/selection_box_storage.png -./gui/pixel_white.png -./gui/pixel_black.png -./gui/slot_clothing_pants.png -./gui/text_box.png -./gui/shield.png -./gui/label_recipe.png ./gui/slot_clothing_boots.png -./gui/selection_box_wide.png -./gui/gun.png -./gui/button_play.png -./tile/cactus4.png -./tile/hemp1.png -./tile/campfire_lit.png -./tile/dirt.png -./tile/lantern.png -./tile/hemp8.png -./tile/campfire_unlit.png -./tile/rock_gold.png -./tile/wall.png -./tile/cactus_top.png -./tile/cactus2.png -./tile/rock.png -./tile/water.png -./tile/hemp4.png -./tile/stone.png -./tile/tree_leaves.png -./tile/sapling2.png -./tile/ladder_up.png -./tile/sapling3.png -./tile/lava_flow.png -./tile/ice_wall.png -./tile/rock_iron.png -./tile/grass.png -./tile/chest.png -./tile/sapling4.png -./tile/lava.png -./tile/rock_coal.png -./tile/tall_grass.png -./tile/rock_uranium.png -./tile/rock_tin.png -./tile/hemp5.png -./tile/sapling1.png -./tile/snow.png -./tile/sandstone_wall.png -./tile/rock_sandstone.png -./tile/hemp6.png -./tile/cactus1.png -./tile/tree_branch_leaves.png -./tile/tunnel_down.png -./tile/tree_branch_leaves_snow.png -./tile/tree_leaves_snow.png -./tile/rock_ice.png -./tile/boss_portal.png -./tile/ladder.png -./tile/grass_burnt.png -./tile/hemp7.png -./tile/grass_infested.png -./tile/tree_branch.png -./tile/sand.png -./tile/tree_base.png -./tile/cactus3.png -./tile/sandstone.png -./tile/rock_copper.png -./tile/hemp3.png -./tile/hemp2.png -./tile/ice.png -./entity/flare.png -./entity/grappling_hook.png -./entity/zombie_back_moving.png -./entity/tnt.png +./gui/hotbar.png +./gui/button_normal.png +./gui/shield.png +./gui/button_hover.png +./text/char_bslash.png +./text/char_dollar.png +./text/char_l_w.png +./text/char_u_d.png +./text/char_u_t.png +./text/char_space.png +./text/char_l_x.png +./text/char_l_k.png +./text/char_6.png +./text/char_unknown.png +./text/char_comma.png +./text/char_obracket.png +./text/char_u_w.png +./text/char_7.png +./text/char_l_f.png +./text/char_vertical.png +./text/char_plus.png +./text/char_u_a.png +./text/char_star.png +./text/char_9.png +./text/char_u_k.png +./text/char_grave.png +./text/char_u_n.png +./text/char_percent.png +./text/char_u_m.png +./text/char_exclamation.png +./text/char_1.png +./text/char_l_q.png +./text/char_l_z.png +./text/char_l_h.png +./text/char_u_c.png +./text/char_l_g.png +./text/char_l_s.png +./text/char_fullstop.png +./text/char_u_j.png +./text/char_l_m.png +./text/char_l_t.png +./text/char_u_v.png +./text/char_colon.png +./text/char_l_i.png +./text/char_l_y.png +./text/char_semicolon.png +./text/char_u_l.png +./text/char_apostrophe.png +./text/char_u_e.png +./text/char_5.png +./text/char_2.png +./text/char_3.png +./text/char_l_p.png +./text/char_and.png +./text/char_fslash.png +./text/char_l_u.png +./text/char_u_f.png +./text/char_u_u.png +./text/char_at.png +./text/char_l_e.png +./text/char_l_l.png +./text/char_u_g.png +./text/char_u_q.png +./text/char_u_b.png +./text/char_l_o.png +./text/char_csbracket.png +./text/char_osbracket.png +./text/char_minus.png +./text/char_l_v.png +./text/char_lthan.png +./text/char_u_s.png +./text/char_equals.png +./text/char_8.png +./text/char_ccbracket.png +./text/char_underscore.png +./text/char_u_x.png +./text/char_0.png +./text/char_l_d.png +./text/char_l_c.png +./text/char_l_j.png +./text/char_u_z.png +./text/char_u_h.png +./text/char_pow.png +./text/char_hashtag.png +./text/char_gthan.png +./text/char_cbracket.png +./text/char_u_i.png +./text/char_question.png +./text/char_u_o.png +./text/char_u_y.png +./text/char_l_r.png +./text/char_l_b.png +./text/char_ocbracket.png +./text/char_l_a.png +./text/char_quotation.png +./text/char_l_n.png +./text/char_u_p.png +./text/char_tilde.png +./text/char_u_r.png +./text/char_4.png ./entity/armored_zombie_back_moving.png -./entity/armored_zombie_front_moving.png -./entity/player/hair_side.png -./entity/player/head_top.png -./entity/player/head_side.png -./entity/player/head_back.png -./entity/player/head_bottom.png -./entity/player/hair_front.png -./entity/player/head_front.png -./entity/player/hair_back.png -./entity/player/hair_top.png -./entity/dummy.png -./entity/armored_zombie_front_still.png -./entity/armored_zombie_back_still.png -./entity/zombie_front_moving.png -./entity/boss1/boss_walking_firing.png +./entity/zombie_front_still.png +./entity/tnt.png +./entity/flare.png +./entity/boss1/boss_walking.png ./entity/boss1/boss_firing.png ./entity/boss1/boss_still.png -./entity/boss1/boss_walking.png +./entity/boss1/boss_walking_firing.png +./entity/armored_zombie_back_still.png +./entity/armored_zombie_front_moving.png +./entity/player/head_back.png +./entity/player/hair_top.png +./entity/player/head_front.png +./entity/player/head_top.png +./entity/player/hair_side.png +./entity/player/head_side.png +./entity/player/hair_back.png +./entity/player/hair_front.png +./entity/player/head_bottom.png +./entity/grappling_hook.png ./entity/zombie_back_still.png -./entity/zombie_front_still.png -./item/acorn.png -./item/clay.png -./item/stone_hatchet.png -./item/grappling_hook.png -./item/gun_upgrade.png -./item/shield_upgrade.png -./item/rock_gold.png -./item/rock.png -./item/flint_hatchet.png -./item/rock_iron.png -./item/log.png -./item/ash.png -./item/charcoal.png -./item/torch_unlit.png -./item/log_snow.png -./item/hemp_seed.png -./item/stone_shovel.png -./item/rock_uranium.png -./item/rock_tin.png -./item/ammo_box.png -./item/plant_fibre.png -./item/health_potion.png -./item/snow_pile.png -./item/coal.png -./item/flint.png -./item/sandstone.png -./item/rock_copper.png -./item/stone_pick.png -./item/torch_lit.png +./entity/dummy.png +./entity/zombie_back_moving.png +./entity/armored_zombie_front_still.png +./entity/zombie_front_moving.png +./particle/smoke_1.png +./particle/water.png +./particle/rain.png +./particle/blood.png +./particle/snow.png +./particle/smoke_3.png +./particle/smoke_4.png +./particle/smoke_2.png +./particle/smoke_0.png +./particle/bullet.png +./particle/lava.png +./particle/smoke_trail.png +./particle/smoke_5.png diff --git a/src/resources/texture/tile/wood_floor.png b/src/resources/texture/tile/wood_floor.png new file mode 100644 index 0000000..fcfcb6f Binary files /dev/null and b/src/resources/texture/tile/wood_floor.png differ diff --git a/src/resources/texture/tile/wood_snow_floor.png b/src/resources/texture/tile/wood_snow_floor.png new file mode 100644 index 0000000..45781ca Binary files /dev/null and b/src/resources/texture/tile/wood_snow_floor.png differ diff --git a/src/resources/texture/tile/wood_snow_wall_front.png b/src/resources/texture/tile/wood_snow_wall_front.png new file mode 100644 index 0000000..d5087fb Binary files /dev/null and b/src/resources/texture/tile/wood_snow_wall_front.png differ diff --git a/src/resources/texture/tile/wood_snow_wall_side.png b/src/resources/texture/tile/wood_snow_wall_side.png new file mode 100644 index 0000000..1947018 Binary files /dev/null and b/src/resources/texture/tile/wood_snow_wall_side.png differ diff --git a/src/resources/texture/tile/wood_snow_wall_top.png b/src/resources/texture/tile/wood_snow_wall_top.png new file mode 100644 index 0000000..c56199f Binary files /dev/null and b/src/resources/texture/tile/wood_snow_wall_top.png differ diff --git a/src/resources/texture/tile/wood_wall_front.png b/src/resources/texture/tile/wood_wall_front.png new file mode 100644 index 0000000..d24cfd5 Binary files /dev/null and b/src/resources/texture/tile/wood_wall_front.png differ diff --git a/src/resources/texture/tile/wood_wall_side.png b/src/resources/texture/tile/wood_wall_side.png new file mode 100644 index 0000000..a244515 Binary files /dev/null and b/src/resources/texture/tile/wood_wall_side.png differ diff --git a/src/resources/texture/tile/wood_wall_top.png b/src/resources/texture/tile/wood_wall_top.png new file mode 100644 index 0000000..529ea3d Binary files /dev/null and b/src/resources/texture/tile/wood_wall_top.png differ