Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Repair Bench #3

Merged
merged 12 commits into from
Jan 20, 2025
2 changes: 1 addition & 1 deletion src/client/java/minicraft/core/Renderer.java
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,7 @@ private static void renderGui() {
if (player.activeItem instanceof ToolItem) {
// Draws the text
ToolItem tool = (ToolItem) player.activeItem;
int dura = tool.dur * 100 / (tool.type.durability * (tool.level + 1));
int dura = tool.dur * 100 / tool.MAX_DUR;
int green = (int) (dura * 2.55f); // Let duration show as normal.
Font.drawBackground(dura + "%", screen, 164, Screen.h - 16, Color.get(1, 255 - green, green, 0));
}
Expand Down
27 changes: 27 additions & 0 deletions src/client/java/minicraft/entity/furniture/RepairBench.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package minicraft.entity.furniture;

import minicraft.core.Game;
import minicraft.entity.mob.Player;
import minicraft.gfx.SpriteLinker;
import minicraft.screen.RepairBenchDisplay;
import org.jetbrains.annotations.NotNull;

public class RepairBench extends Furniture {
private static final SpriteLinker.LinkedSprite sprite = new SpriteLinker.LinkedSprite(SpriteLinker.SpriteType.Entity, "repair_bench");
private static final SpriteLinker.LinkedSprite itemSprite = new SpriteLinker.LinkedSprite(SpriteLinker.SpriteType.Item, "repair_bench");

public RepairBench() {
super("Repair Bench", sprite, itemSprite);
}

@Override
public boolean use(Player player) {
Game.setDisplay(new RepairBenchDisplay(this, player));
return true;
}

@Override
public @NotNull Furniture copy() {
return new RepairBench();
}
}
4 changes: 2 additions & 2 deletions src/client/java/minicraft/item/FishingRodItem.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ protected static ArrayList<Item> getAllInstances() {
return items;
}

private int uses = 0; // The more uses, the higher the chance of breaking
public int uses = 0; // The more uses, the higher the chance of breaking
public int level; // The higher the level the lower the chance of breaking

private Random random = new Random();
Expand All @@ -40,7 +40,7 @@ protected static ArrayList<Item> getAllInstances() {
{ 79, 69, 59, 4 } // Gem has very high chance of rare items
};

private static final String[] LEVEL_NAMES = {
public static final String[] LEVEL_NAMES = {
"Wood",
"Iron",
"Gold",
Expand Down
2 changes: 2 additions & 0 deletions src/client/java/minicraft/item/FurnitureItem.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import minicraft.entity.furniture.DungeonChest;
import minicraft.entity.furniture.Furniture;
import minicraft.entity.furniture.Lantern;
import minicraft.entity.furniture.RepairBench;
import minicraft.entity.furniture.Spawner;
import minicraft.entity.furniture.Tnt;
import minicraft.entity.mob.Cow;
Expand Down Expand Up @@ -64,6 +65,7 @@ protected static ArrayList<Item> getAllInstances() {

items.add(new FurnitureItem(new Tnt()));
items.add(new FurnitureItem(new Composter()));
items.add(new FurnitureItem(new RepairBench()));

return items;
}
Expand Down
2 changes: 2 additions & 0 deletions src/client/java/minicraft/item/Recipes.java
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,8 @@ public class Recipes {
anvilRecipes.add(new Recipe("Gem Bow_1", "Wood_5", "gem_50", "string_2"));
anvilRecipes.add(new Recipe("Shears_1", "Iron_4"));
anvilRecipes.add(new Recipe("Watering Can_1", "Iron_3"));
anvilRecipes.add(new Recipe("Dark Anvil_1", "Cloud Ore_5", "Shard_10", "Iron_5", "Raw Obsidian_4"));
anvilRecipes.add(new Recipe("Repair Bench_1", "Wood_12", "Iron_8", "Lapis_2", "Stone_4"));

furnaceRecipes.add(new Recipe("iron_1", "iron Ore_3", "coal_1"));
furnaceRecipes.add(new Recipe("gold_1", "gold Ore_3", "coal_1"));
Expand Down
5 changes: 3 additions & 2 deletions src/client/java/minicraft/item/ToolItem.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ protected static ArrayList<Item> getAllInstances() {
private Random random = new Random();

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 final int MAX_DUR;

public ToolType type; // Type of tool (Sword, hoe, axe, pickaxe, shovel)
public int level; // Level of said tool
Expand All @@ -52,14 +53,14 @@ public ToolItem(ToolType type, int level) {
this.level = level;
this.damage = level * 5 + 10;

dur = type.durability * (level + 1); // Initial durability fetched from the ToolType
dur = MAX_DUR = type.durability * (level + 1); // Initial durability fetched from the ToolType
}

public ToolItem(ToolType type) {
super(type.name(), new LinkedSprite(SpriteType.Item, getSpriteName(type.toString(), "")));

this.type = type;
dur = type.durability;
dur = MAX_DUR = type.durability;
}

/**
Expand Down
2 changes: 2 additions & 0 deletions src/client/java/minicraft/saveload/Load.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import minicraft.entity.furniture.DungeonChest;
import minicraft.entity.furniture.KnightStatue;
import minicraft.entity.furniture.Lantern;
import minicraft.entity.furniture.RepairBench;
import minicraft.entity.furniture.Spawner;
import minicraft.entity.furniture.Tnt;
import minicraft.entity.mob.AirWizard;
Expand Down Expand Up @@ -1383,6 +1384,7 @@ private static Entity getEntity(String string, int mobLevel) {
return new ObsidianKnight(0);
case "DyeVat":
return new Crafter(Crafter.Type.DyeVat);
case "RepairBench": return new RepairBench();
default:
Logging.SAVELOAD.error("LOAD ERROR: Unknown or outdated entity requested: " + string);
return null;
Expand Down
2 changes: 0 additions & 2 deletions src/client/java/minicraft/screen/Menu.java
Original file line number Diff line number Diff line change
Expand Up @@ -658,8 +658,6 @@ else if (c.xIndex == 2) // must be center right
int width = titleDim.width;
for (ListEntry entry : menu.entries) {
int entryWidth = entry.getWidth();
if (menu.isSelectable() && !entry.isSelectable())
entryWidth = Math.max(0, entryWidth - MinicraftImage.boxWidth * 4);
width = Math.max(width, entryWidth);
}

Expand Down
Loading
Loading