diff --git a/src/minicraft/core/Game.java b/src/minicraft/core/Game.java index 18c5c454a..100356a4d 100644 --- a/src/minicraft/core/Game.java +++ b/src/minicraft/core/Game.java @@ -26,7 +26,7 @@ public class Game { public static boolean HAS_GUI = true; public static final String NAME = "Minicraft Plus"; // This is the name on the application window - public static final Version VERSION = new Version("2.0.4"); + public static final Version VERSION = new Version("2.0.5-dev1"); public static InputHandler input; // input used in Game, Player, and just about all the *Menu classes. public static Player player; diff --git a/src/minicraft/core/Renderer.java b/src/minicraft/core/Renderer.java index bb16bd772..d2dcb2c7a 100644 --- a/src/minicraft/core/Renderer.java +++ b/src/minicraft/core/Renderer.java @@ -24,7 +24,6 @@ import minicraft.item.Items; import minicraft.item.PotionType; import minicraft.item.ToolItem; -import minicraft.item.ToolType; import minicraft.level.Level; import minicraft.screen.LoadingDisplay; import minicraft.screen.RelPos; @@ -250,9 +249,10 @@ else if(Game.isValidClient()) { } } - // FISHING ROD STATUS - if (player.activeItem instanceof ToolItem && ((ToolItem)player.activeItem).type == ToolType.FishingRod) { - int dura = ((ToolItem)player.activeItem).dur * 100 / ((ToolItem)player.activeItem).type.durability; + // TOOL DURABILITY STATUS + if (player.activeItem instanceof ToolItem) { + ToolItem tool = (ToolItem) player.activeItem; + int dura = tool.dur * 100 / (tool.type.durability * (tool.level+1)); //if (dura > 100) dura = 100; Font.draw(dura + "%", screen, 164, Screen.h - 16, Color.get(0, 30)); } diff --git a/src/minicraft/entity/mob/Player.java b/src/minicraft/entity/mob/Player.java index 3446fd707..c5172f585 100644 --- a/src/minicraft/entity/mob/Player.java +++ b/src/minicraft/entity/mob/Player.java @@ -529,10 +529,11 @@ protected void attack() { // the player is holding a tool, and has stamina available. ToolItem tool = (ToolItem) activeItem; - if (tool.type == ToolType.Bow && inventory.count(Items.arrowItem) > 0) { // if the player is holding a bow, and has arrows... + if (tool.type == ToolType.Bow && tool.dur > 0 && inventory.count(Items.arrowItem) > 0) { // if the player is holding a bow, and has arrows... if (!Game.isMode("creative")) inventory.removeItem(Items.arrowItem); level.add(new Arrow(this, attackDir, tool.level)); attackTime = 10; + if (!Game.isMode("creative")) tool.dur--; return; // we have attacked! } } @@ -579,14 +580,17 @@ protected void attack() { if (activeItem == null || activeItem.canAttack()) { // if there is no active item, OR if the item can be used to attack... attackTime = 5; // attacks the enemy in the appropriate direction. - hurt(getInteractionBox(ATTACK_DIST)); + boolean used = hurt(getInteractionBox(ATTACK_DIST)); // attempts to hurt the tile in the appropriate direction. Point t = getInteractionTile(); if (t.x >= 0 && t.y >= 0 && t.x < level.w && t.y < level.h) { Tile tile = level.getTile(t.x, t.y); - tile.hurt(level, t.x, t.y, this, random.nextInt(3) + 1, attackDir); + used = tile.hurt(level, t.x, t.y, this, random.nextInt(3) + 1, attackDir) || used; } + + if(used && activeItem instanceof ToolItem) + ((ToolItem)activeItem).payDurability(); } } @@ -644,13 +648,19 @@ private boolean interact(Rectangle area) { } /** same, but for attacking. */ - private void hurt(Rectangle area) { + private boolean hurt(Rectangle area) { List entities = level.getEntitiesInRect(area); + int maxDmg = 0; for (int i = 0; i < entities.size(); i++) { Entity e = entities.get(i); - if (e != this && e instanceof Mob) ((Mob)e).hurt(this, getAttackDamage(e), attackDir); // note: this really only does something for mobs. + if (e != this && e instanceof Mob) { + int dmg = getAttackDamage(e); + maxDmg = Math.max(dmg, maxDmg); + ((Mob)e).hurt(this, dmg, attackDir); // note: this really only does something for mobs. + } if (e != this && e instanceof Furniture) e.interact(this, null, attackDir); // note: this really only does something for mobs. } + return maxDmg > 0; } /** @@ -961,7 +971,7 @@ protected String getUpdateString() { ";hunger,"+hunger+ ";attackTime,"+attackTime+ ";attackDir,"+attackDir.ordinal()+ - ";activeItem,"+(activeItem==null?"null": activeItem.getName()); + ";activeItem,"+(activeItem==null?"null": activeItem.getData()); return updates; } diff --git a/src/minicraft/item/Items.java b/src/minicraft/item/Items.java index dbe971438..a6c07034e 100644 --- a/src/minicraft/item/Items.java +++ b/src/minicraft/item/Items.java @@ -58,7 +58,9 @@ public static Item get(String name, boolean allowNull) { name = name.toUpperCase(); //System.out.println("fetching name: \"" + name + "\""); int amount = 1; + boolean hadUnderscore = false; if(name.contains("_")) { + hadUnderscore = true; try { amount = Integer.parseInt(name.substring(name.indexOf("_")+1)); } catch(Exception ex) { @@ -90,6 +92,8 @@ public static Item get(String name, boolean allowNull) { if(i != null) { if(i instanceof StackableItem) ((StackableItem)i).count = amount; + if(i instanceof ToolItem && hadUnderscore) + ((ToolItem)i).dur = amount; return i.clone(); } else { System.out.println(Network.onlinePrefix()+"ITEMS GET: invalid name requested: \"" + name + "\""); diff --git a/src/minicraft/item/ToolItem.java b/src/minicraft/item/ToolItem.java index 0a1d4febe..010560558 100644 --- a/src/minicraft/item/ToolItem.java +++ b/src/minicraft/item/ToolItem.java @@ -32,13 +32,11 @@ protected static ArrayList getAllInstances() { private Random random = new Random(); - public static final int MAX_LEVEL = 5; // How many different levels of tools there are public static final String[] LEVEL_NAMES = {"Wood", "Rock", "Iron", "Gold", "Gem"}; // The names of the different levels. A later level means a stronger tool. public ToolType type; // Type of tool (Sword, hoe, axe, pickaxe, shovel) public int level; // Level of said tool - public int dur; // the durability of the tool; currently only used for fishing rod. - // TODO implement durabilities for all tools? + public int dur; // the durability of the tool public static final int[] LEVEL_COLORS = { // Colors of the tools, same position as LEVEL_NAMES Color.get(-1, 100, 321, 431), // wood @@ -63,7 +61,7 @@ public ToolItem(ToolType type, int level) { this.type = type; this.level = level; - dur = type.durability; // initial durability fetched from the ToolType + dur = type.durability * (level+1); // initial durability fetched from the ToolType } private static int getColor(ToolType type, int level) { @@ -87,10 +85,9 @@ public String getDisplayName() { @Override public boolean interactOn(Tile tile, Level level, int xt, int yt, Player player, Direction attackDir) { - if (type == ToolType.FishingRod && dur > 0) { - if (tile == Tiles.get("water")) { + if (type == ToolType.FishingRod && tile == Tiles.get("water")) { + if (payDurability()) { player.goFishing(player.x - 5, player.y - 5); - if(!Game.isMode("creative")) dur--; return true; } } @@ -107,8 +104,16 @@ public boolean canAttack() { return true; } + public boolean payDurability() { + if(dur <= 0) return false; + if(!Game.isMode("creative")) dur--; + return true; + } + /** Gets the attack damage bonus from an item/tool (sword/axe) */ public int getAttackDamageBonus(Entity e) { + if(!payDurability()) + return 0; if(e instanceof Mob) { if (type == ToolType.Axe) { @@ -128,6 +133,11 @@ public int getAttackDamageBonus(Entity e) { return 0; } + @Override + public String getData() { + return super.getData()+"_"+dur; + } + /** Sees if this item equals another. */ @Override public boolean equals(Item item) { diff --git a/src/minicraft/item/ToolType.java b/src/minicraft/item/ToolType.java index 56b9281f7..9d837faf6 100644 --- a/src/minicraft/item/ToolType.java +++ b/src/minicraft/item/ToolType.java @@ -1,14 +1,14 @@ package minicraft.item; public enum ToolType { - Shovel (0), - Hoe (1), - Sword (2), - Pickaxe (3), - Axe (4), - Bow (5), - FishingRod (6, 15), // if there's a second number, it specifies durability. - Claymore (7); + Shovel (0, 24), // if there's a second number, it specifies durability. + Hoe (1, 20), + Sword (2, 42), + Pickaxe (3, 28), + Axe (4, 24), + Bow (5, 20), + FishingRod (6, 16), + Claymore (7, 34); //Hatchet (10), //Spade (11), //Pick (12); diff --git a/src/minicraft/level/tile/CactusTile.java b/src/minicraft/level/tile/CactusTile.java index 15b79efe4..13f659526 100644 --- a/src/minicraft/level/tile/CactusTile.java +++ b/src/minicraft/level/tile/CactusTile.java @@ -30,7 +30,7 @@ public boolean mayPass(Level level, int x, int y, Entity e) { return false; } - public void hurt(Level level, int x, int y, Mob source, int dmg, Direction attackDir) { + public boolean hurt(Level level, int x, int y, Mob source, int dmg, Direction attackDir) { int damage = level.getData(x, y) + dmg; int cHealth = 10; if (Game.isMode("creative")) dmg = damage = cHealth; @@ -44,6 +44,7 @@ public void hurt(Level level, int x, int y, Mob source, int dmg, Direction attac } else { level.setData(x, y, damage); } + return true; } public void bumpedInto(Level level, int x, int y, Entity entity) { diff --git a/src/minicraft/level/tile/CloudCactusTile.java b/src/minicraft/level/tile/CloudCactusTile.java index bfc3bd4e5..f59d1ae63 100644 --- a/src/minicraft/level/tile/CloudCactusTile.java +++ b/src/minicraft/level/tile/CloudCactusTile.java @@ -27,15 +27,16 @@ public boolean mayPass(Level level, int x, int y, Entity e) { return e instanceof AirWizard; } - public void hurt(Level level, int x, int y, Mob source, int dmg, Direction attackDir) { + public boolean hurt(Level level, int x, int y, Mob source, int dmg, Direction attackDir) { hurt(level, x, y, 0); + return true; } public boolean interact(Level level, int xt, int yt, Player player, Item item, Direction attackDir) { if (item instanceof ToolItem) { ToolItem tool = (ToolItem) item; if (tool.type == ToolType.Pickaxe) { - if (player.payStamina(6 - tool.level)) { + if (player.payStamina(6 - tool.level) && tool.payDurability()) { hurt(level, xt, yt, 1); return true; } diff --git a/src/minicraft/level/tile/DirtTile.java b/src/minicraft/level/tile/DirtTile.java index 1bc3504dc..64eafcc45 100644 --- a/src/minicraft/level/tile/DirtTile.java +++ b/src/minicraft/level/tile/DirtTile.java @@ -42,7 +42,7 @@ public boolean interact(Level level, int xt, int yt, Player player, Item item, D if (item instanceof ToolItem) { ToolItem tool = (ToolItem) item; if (tool.type == ToolType.Shovel) { - if (player.payStamina(4 - tool.level)) { + if (player.payStamina(4 - tool.level) && tool.payDurability()) { level.setTile(xt, yt, Tiles.get("hole")); level.dropItem(xt*16+8, yt*16+8, Items.get("dirt")); Sound.monsterHurt.play(); @@ -50,7 +50,7 @@ public boolean interact(Level level, int xt, int yt, Player player, Item item, D } } if (tool.type == ToolType.Hoe) { - if (player.payStamina(4 - tool.level)) { + if (player.payStamina(4 - tool.level) && tool.payDurability()) { level.setTile(xt, yt, Tiles.get("farmland")); Sound.monsterHurt.play(); return true; diff --git a/src/minicraft/level/tile/DoorTile.java b/src/minicraft/level/tile/DoorTile.java index 1fb3f6912..e504345ae 100644 --- a/src/minicraft/level/tile/DoorTile.java +++ b/src/minicraft/level/tile/DoorTile.java @@ -50,7 +50,7 @@ public boolean interact(Level level, int xt, int yt, Player player, Item item, D if (item instanceof ToolItem) { ToolItem tool = (ToolItem) item; if (tool.type == ToolType.Pickaxe) { - if (player.payStamina(4 - tool.level)) { + if (player.payStamina(4 - tool.level) && tool.payDurability()) { level.setTile(xt, yt, Tiles.get(id+3)); // will get the corresponding floor tile. level.dropItem(xt*16+8, yt*16+8, Items.get(type.name() + " Door")); Sound.monsterHurt.play(); @@ -61,11 +61,12 @@ public boolean interact(Level level, int xt, int yt, Player player, Item item, D return false; } - public void hurt(Level level, int x, int y, Mob source, int dmg, Direction attackDir) { + public boolean hurt(Level level, int x, int y, Mob source, int dmg, Direction attackDir) { if(source instanceof Player) { boolean closed = level.getData(x, y) == 0; level.setData(x, y, closed?1:0); } + return false; } public boolean mayPass(Level level, int x, int y, Entity e) { diff --git a/src/minicraft/level/tile/FarmTile.java b/src/minicraft/level/tile/FarmTile.java index 98c4f3139..d13042d1c 100644 --- a/src/minicraft/level/tile/FarmTile.java +++ b/src/minicraft/level/tile/FarmTile.java @@ -21,7 +21,7 @@ public boolean interact(Level level, int xt, int yt, Player player, Item item, D if (item instanceof ToolItem) { ToolItem tool = (ToolItem) item; if (tool.type == ToolType.Shovel) { - if (player.payStamina(4 - tool.level)) { + if (player.payStamina(4 - tool.level) && tool.payDurability()) { level.setTile(xt, yt, Tiles.get("dirt")); return true; } diff --git a/src/minicraft/level/tile/FloorTile.java b/src/minicraft/level/tile/FloorTile.java index 239028df4..b9ae90d98 100644 --- a/src/minicraft/level/tile/FloorTile.java +++ b/src/minicraft/level/tile/FloorTile.java @@ -36,7 +36,7 @@ public boolean interact(Level level, int xt, int yt, Player player, Item item, D if (item instanceof ToolItem) { ToolItem tool = (ToolItem) item; if (tool.type == ToolType.Pickaxe) { - if (player.payStamina(4 - tool.level)) { + if (player.payStamina(4 - tool.level) && tool.payDurability()) { level.setTile(xt, yt, Tiles.get("hole")); Item drop; switch(type) { diff --git a/src/minicraft/level/tile/FlowerTile.java b/src/minicraft/level/tile/FlowerTile.java index dadf6e9b5..bf45f9024 100644 --- a/src/minicraft/level/tile/FlowerTile.java +++ b/src/minicraft/level/tile/FlowerTile.java @@ -39,7 +39,7 @@ public boolean interact(Level level, int x, int y, Player player, Item item, Dir if (item instanceof ToolItem) { ToolItem tool = (ToolItem) item; if (tool.type == ToolType.Shovel) { - if (player.payStamina(2 - tool.level)) { + if (player.payStamina(2 - tool.level) && tool.payDurability()) { level.dropItem(x*16+8, y*16+8, Items.get("Flower")); level.dropItem(x*16+8, y*16+8, Items.get("Rose")); level.setTile(x, y, Tiles.get("grass")); @@ -50,9 +50,10 @@ public boolean interact(Level level, int x, int y, Player player, Item item, Dir return false; } - public void hurt(Level level, int x, int y, Mob source, int dmg, Direction attackDir) { + public boolean hurt(Level level, int x, int y, Mob source, int dmg, Direction attackDir) { level.dropItem(x*16+8, y*16+8, 1, 2, Items.get("Flower")); level.dropItem(x*16+8, y*16+8, 0, 1, Items.get("Rose")); level.setTile(x, y, Tiles.get("grass")); + return true; } } diff --git a/src/minicraft/level/tile/GrassTile.java b/src/minicraft/level/tile/GrassTile.java index bdea031d7..52407ede8 100644 --- a/src/minicraft/level/tile/GrassTile.java +++ b/src/minicraft/level/tile/GrassTile.java @@ -47,7 +47,7 @@ public boolean interact(Level level, int xt, int yt, Player player, Item item, D if (item instanceof ToolItem) { ToolItem tool = (ToolItem) item; if (tool.type == ToolType.Shovel) { - if (player.payStamina(4 - tool.level)) { + if (player.payStamina(4 - tool.level) && tool.payDurability()) { level.setTile(xt, yt, Tiles.get("dirt")); Sound.monsterHurt.play(); if (random.nextInt(5) == 0) { @@ -57,7 +57,7 @@ public boolean interact(Level level, int xt, int yt, Player player, Item item, D } } if (tool.type == ToolType.Hoe) { - if (player.payStamina(4 - tool.level)) { + if (player.payStamina(4 - tool.level) && tool.payDurability()) { Sound.monsterHurt.play(); if (random.nextInt(5) == 0) { level.dropItem(xt*16+8, yt*16+8, Items.get("seeds")); diff --git a/src/minicraft/level/tile/HardRockTile.java b/src/minicraft/level/tile/HardRockTile.java index 0f1e2f97b..7bb496c59 100644 --- a/src/minicraft/level/tile/HardRockTile.java +++ b/src/minicraft/level/tile/HardRockTile.java @@ -27,8 +27,9 @@ public boolean mayPass(Level level, int x, int y, Entity e) { return false; } - public void hurt(Level level, int x, int y, Mob source, int dmg, Direction attackDir) { + public boolean hurt(Level level, int x, int y, Mob source, int dmg, Direction attackDir) { hurt(level, x, y, 0); + return true; } public boolean interact(Level level, int xt, int yt, Player player, Item item, Direction attackDir) { @@ -36,7 +37,7 @@ public boolean interact(Level level, int xt, int yt, Player player, Item item, D ToolItem tool = (ToolItem) item; if (Game.isMode("creative")) return true; if (tool.type == ToolType.Pickaxe && tool.level == 4) { - if (player.payStamina(4 - tool.level)) { + if (player.payStamina(4 - tool.level) && tool.payDurability()) { hurt(level, xt, yt, random.nextInt(10) + (tool.level) * 5 + 10); return true; } @@ -44,7 +45,6 @@ public boolean interact(Level level, int xt, int yt, Player player, Item item, D else Game.notifications.add("Gem Pickaxe Required."); } return Game.isMode("creative"); - } public void hurt(Level level, int x, int y, int dmg) { diff --git a/src/minicraft/level/tile/LavaBrickTile.java b/src/minicraft/level/tile/LavaBrickTile.java index 33432c351..0f8901550 100644 --- a/src/minicraft/level/tile/LavaBrickTile.java +++ b/src/minicraft/level/tile/LavaBrickTile.java @@ -23,7 +23,7 @@ public boolean interact(Level level, int xt, int yt, Player player, Item item, D if (item instanceof ToolItem) { ToolItem tool = (ToolItem) item; if (tool.type == ToolType.Pickaxe) { - if (player.payStamina(4 - tool.level)) { + if (player.payStamina(4 - tool.level) && tool.payDurability()) { level.setTile(xt, yt, Tiles.get("lava")); Sound.monsterHurt.play(); return true; diff --git a/src/minicraft/level/tile/OreTile.java b/src/minicraft/level/tile/OreTile.java index 317d0d742..2de03512a 100644 --- a/src/minicraft/level/tile/OreTile.java +++ b/src/minicraft/level/tile/OreTile.java @@ -55,20 +55,21 @@ public boolean mayPass(Level level, int x, int y, Entity e) { return false; } - public void hurt(Level level, int x, int y, Mob source, int dmg, Direction attackDir) { + public boolean hurt(Level level, int x, int y, Mob source, int dmg, Direction attackDir) { int playHurt; if (Game.isMode("creative")) playHurt = random.nextInt(4); else { playHurt = 0; } hurt(level, x, y, playHurt); + return true; } public boolean interact(Level level, int xt, int yt, Player player, Item item, Direction attackDir) { if (item instanceof ToolItem) { ToolItem tool = (ToolItem) item; if (tool.type == ToolType.Pickaxe) { - if (player.payStamina(6 - tool.level)) { + if (player.payStamina(6 - tool.level) && tool.payDurability()) { hurt(level, xt, yt, 1); return true; } diff --git a/src/minicraft/level/tile/RockTile.java b/src/minicraft/level/tile/RockTile.java index c7600ec2c..0e9345fa4 100644 --- a/src/minicraft/level/tile/RockTile.java +++ b/src/minicraft/level/tile/RockTile.java @@ -44,14 +44,15 @@ public boolean mayPass(Level level, int x, int y, Entity e) { return false; } - public void hurt(Level level, int x, int y, Mob source, int dmg, Direction attackDir) { + public boolean hurt(Level level, int x, int y, Mob source, int dmg, Direction attackDir) { hurt(level, x, y, 1); + return true; } public boolean interact(Level level, int xt, int yt, Player player, Item item, Direction attackDir) { if (item instanceof ToolItem) { ToolItem tool = (ToolItem) item; - if (tool.type == ToolType.Pickaxe && player.payStamina(4 - tool.level)) { + if (tool.type == ToolType.Pickaxe && player.payStamina(4 - tool.level) && tool.payDurability()) { coallvl = 1; hurt(level, xt, yt, random.nextInt(10) + (tool.level) * 5 + 10); return true; diff --git a/src/minicraft/level/tile/SandTile.java b/src/minicraft/level/tile/SandTile.java index 0bf09f2bb..be21b591d 100644 --- a/src/minicraft/level/tile/SandTile.java +++ b/src/minicraft/level/tile/SandTile.java @@ -64,7 +64,7 @@ public boolean interact(Level level, int xt, int yt, Player player, Item item, D if (item instanceof ToolItem) { ToolItem tool = (ToolItem) item; if (tool.type == ToolType.Shovel) { - if (player.payStamina(4 - tool.level)) { + if (player.payStamina(4 - tool.level) && tool.payDurability()) { level.setTile(xt, yt, Tiles.get("dirt")); level.dropItem(xt*16+8, yt*16+8, Items.get("sand")); return true; diff --git a/src/minicraft/level/tile/SaplingTile.java b/src/minicraft/level/tile/SaplingTile.java index c58d493d2..e152e5152 100644 --- a/src/minicraft/level/tile/SaplingTile.java +++ b/src/minicraft/level/tile/SaplingTile.java @@ -39,7 +39,8 @@ public void tick(Level level, int x, int y) { } } - public void hurt(Level level, int x, int y, Mob source, int dmg, Direction attackDir) { + public boolean hurt(Level level, int x, int y, Mob source, int dmg, Direction attackDir) { level.setTile(x, y, onType); + return true; } } diff --git a/src/minicraft/level/tile/Tile.java b/src/minicraft/level/tile/Tile.java index 632c996ef..69bc2a898 100644 --- a/src/minicraft/level/tile/Tile.java +++ b/src/minicraft/level/tile/Tile.java @@ -99,7 +99,7 @@ public int getLightRadius(Level level, int x, int y) { return 0; } - public void hurt(Level level, int x, int y, Mob source, int dmg, Direction attackDir) {} + public boolean hurt(Level level, int x, int y, Mob source, int dmg, Direction attackDir) { return false; } public void hurt(Level level, int x, int y, int dmg) {} /** What happens when you run into the tile (ex: run into a cactus) */ diff --git a/src/minicraft/level/tile/TreeTile.java b/src/minicraft/level/tile/TreeTile.java index c030a0fd0..74c60d9c5 100644 --- a/src/minicraft/level/tile/TreeTile.java +++ b/src/minicraft/level/tile/TreeTile.java @@ -78,8 +78,9 @@ public boolean mayPass(Level level, int x, int y, Entity e) { } @Override - public void hurt(Level level, int x, int y, Mob source, int dmg, Direction attackDir) { + public boolean hurt(Level level, int x, int y, Mob source, int dmg, Direction attackDir) { hurt(level, x, y, dmg); + return true; } @Override @@ -87,7 +88,7 @@ public boolean interact(Level level, int xt, int yt, Player player, Item item, D if (item instanceof ToolItem) { ToolItem tool = (ToolItem) item; if (tool.type == ToolType.Axe) { - if (player.payStamina(4 - tool.level)) { + if (player.payStamina(4 - tool.level) && tool.payDurability()) { hurt(level, xt, yt, random.nextInt(10) + (tool.level) * 5 + 10); return true; } diff --git a/src/minicraft/level/tile/WallTile.java b/src/minicraft/level/tile/WallTile.java index e6c311a23..8bfcbfdb8 100644 --- a/src/minicraft/level/tile/WallTile.java +++ b/src/minicraft/level/tile/WallTile.java @@ -44,11 +44,14 @@ public boolean mayPass(Level level, int x, int y, Entity e) { } @Override - public void hurt(Level level, int x, int y, Mob source, int dmg, Direction attackDir) { - if(level.depth != -3 || type != Material.Obsidian || AirWizard.beaten) - hurt(level, x, y, random.nextInt(6)/6*dmg/2); - else + public boolean hurt(Level level, int x, int y, Mob source, int dmg, Direction attackDir) { + if(level.depth != -3 || type != Material.Obsidian || AirWizard.beaten) { + hurt(level, x, y, random.nextInt(6) / 6 * dmg / 2); + return true; + } else { Game.notifications.add(obrickMsg); + return false; + } } public boolean interact(Level level, int xt, int yt, Player player, Item item, Direction attackDir) { @@ -56,7 +59,7 @@ public boolean interact(Level level, int xt, int yt, Player player, Item item, D ToolItem tool = (ToolItem) item; if (tool.type == ToolType.Pickaxe) { if(level.depth != -3 || type != Material.Obsidian || AirWizard.beaten) { - if (player.payStamina(4 - tool.level)) { + if (player.payStamina(4 - tool.level) && tool.payDurability()) { hurt(level, xt, yt, random.nextInt(10) + (tool.level) * 5 + 10); return true; } diff --git a/src/minicraft/level/tile/WheatTile.java b/src/minicraft/level/tile/WheatTile.java index 43fa8eb59..0fddf42f8 100644 --- a/src/minicraft/level/tile/WheatTile.java +++ b/src/minicraft/level/tile/WheatTile.java @@ -65,7 +65,7 @@ public boolean interact(Level level, int xt, int yt, Player player, Item item, D if (item instanceof ToolItem) { ToolItem tool = (ToolItem) item; if (tool.type == ToolType.Shovel) { - if (player.payStamina(4 - tool.level)) { + if (player.payStamina(4 - tool.level) && tool.payDurability()) { level.setTile(xt, yt, Tiles.get("dirt")); return true; } @@ -81,8 +81,9 @@ public void steppedOn(Level level, int xt, int yt, Entity entity) { } @Override - public void hurt(Level level, int x, int y, Mob source, int dmg, Direction attackDir) { + public boolean hurt(Level level, int x, int y, Mob source, int dmg, Direction attackDir) { harvest(level, x, y, source); + return true; } private void harvest(Level level, int x, int y, Entity entity) { diff --git a/src/minicraft/level/tile/WoolTile.java b/src/minicraft/level/tile/WoolTile.java index 37df10cc5..24a68b94d 100644 --- a/src/minicraft/level/tile/WoolTile.java +++ b/src/minicraft/level/tile/WoolTile.java @@ -47,7 +47,7 @@ public boolean interact(Level level, int xt, int yt, Player player, Item item, D if (item instanceof ToolItem) { ToolItem tool = (ToolItem) item; if (tool.type == ToolType.Shovel) { - if (player.payStamina(3 - tool.level)) { + if (player.payStamina(3 - tool.level) && tool.payDurability()) { level.setTile(xt, yt, Tiles.get("hole")); level.dropItem(xt*16+8, yt*16+8, Items.get("Wool")); Sound.monsterHurt.play(); diff --git a/src/minicraft/saveload/Load.java b/src/minicraft/saveload/Load.java index 09d5a74a0..4e4fa9c00 100644 --- a/src/minicraft/saveload/Load.java +++ b/src/minicraft/saveload/Load.java @@ -472,7 +472,7 @@ public void loadInventory(Inventory inventory, List data) { //System.out.println("loading item: " + item); - if(item.contains(";")) { + if(worldVer.compareTo(new Version("2.0.4")) <= 0 && item.contains(";")) { String[] curData = item.split(";"); String itemName = curData[0]; diff --git a/src/minicraft/saveload/Save.java b/src/minicraft/saveload/Save.java index 7a91ee284..f864c9dc8 100644 --- a/src/minicraft/saveload/Save.java +++ b/src/minicraft/saveload/Save.java @@ -278,21 +278,13 @@ private void writeInventory(String filename, Player player) { public static void writeInventory(Player player, List data) { data.clear(); if(player.activeItem != null) { - if(player.activeItem instanceof StackableItem) { - data.add(player.activeItem.getName() + ";" + ((StackableItem)player.activeItem).count); - } else { - data.add(player.activeItem.getName()); - } + data.add(player.activeItem.getData()); } Inventory inventory = player.getInventory(); for(int i = 0; i < inventory.invSize(); i++) { - if(inventory.get(i) instanceof StackableItem) { - data.add(inventory.get(i).getName() + ";" + ((StackableItem)inventory.get(i)).count); - } else { - data.add(inventory.get(i).getName()); - } + data.add(inventory.get(i).getData()); } }