Skip to content
This repository has been archived by the owner on Mar 4, 2023. It is now read-only.

Commit

Permalink
New Option: Warn on last hit -> Warns you when the durability is at 0
Browse files Browse the repository at this point in the history
  • Loading branch information
RappyTV committed Aug 9, 2022
1 parent 255cf41 commit 7624d72
Show file tree
Hide file tree
Showing 6 changed files with 104 additions and 30 deletions.
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,15 @@
### You can customize these Settings:
- If the addon is enabled or not
- If durability numbers should be formatted (Formatted = 1.562 | Not Formatted = 1562)
- If the debug mode is enabled or not (not recommended)
- If you should be warned at durability 0
- If the debug mode is enabled or not (not recommended -> for developing purposes)
- The message that pops up, when your tool's durability is low
- At what percentage of durability the warning should come (customizable for each tooltype)
- At what percentage of durability the warning should be displayed (customizable for each tooltype)

### Installation
1. Press `Win` + `R`
2. Paste this into the window that popped up: `%appdata%/.minecraft/LabyMod/addons-1.12` and press enter
3. It should open your Labymod addon directory; Paste the [Toolbreak_Warning.jar](https://github.com/RappyTV/Toolbreak-Warning/releases/download/1.2.0/Toolbreak_Warning.jar) in there.
3. It should open your Labymod addon directory; Paste the [Toolbreak_Warning.jar](https://github.com/RappyTV/Toolbreak-Warning/releases/download/1.3.0/Toolbreak_Warning.jar) in there.
4. Launch your Labymod client.

If you have any problems with the addon/have update ideas, feel free to
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ apply plugin: 'net.minecraftforge.gradle.forge'
//Only edit below this line, the above code adds and enables the necessary things for Forge to be setup.


version = "1.2"
version = "3"
group = "com.rappytv.tbw" // http://maven.apache.org/guides/mini/guide-naming-conventions.html
archivesBaseName = "tbw"

Expand Down
59 changes: 50 additions & 9 deletions src/main/java/com/rappytv/tbw/main/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ public class Main extends LabyModAddon {
public static boolean format = true;
public static boolean debug = false;
public static String warnMsg = "\u00A7cDo you really want to continue using this tool? Its durability is {durability}%!";
public static String lastHitMsg = "\u00A7cYou should stop using this tool now, this is your last hit!";
public static boolean lastHitWarn = true;
public static int warnPercentageSword = 5;
public static int warnPercentagePickaxe = 5;
public static int warnPercentageAxe = 5;
Expand All @@ -41,6 +43,7 @@ public void loadConfig() {
debug = getConfig().has("debug") ? getConfig().get("debug").getAsBoolean() : debug;
warnMsg = getConfig().has("warnmsg") ? getConfig().get("warnmsg").getAsString() : warnMsg;

lastHitWarn = getConfig().has("lastHitWarn") ? getConfig().get("lastHitWarn").getAsBoolean() : lastHitWarn;
warnPercentageSword = getConfig().has("sword") ? getConfig().get("sword").getAsInt() : warnPercentageSword;
warnPercentagePickaxe = getConfig().has("pick") ? getConfig().get("pick").getAsInt() : warnPercentagePickaxe;
warnPercentageAxe = getConfig().has("axe") ? getConfig().get("axe").getAsInt() : warnPercentageAxe;
Expand All @@ -49,29 +52,29 @@ public void loadConfig() {

@Override
protected void fillSettings(List<SettingsElement> list) {
BooleanElement enabledBool = new BooleanElement("Enabled", new ControlElement.IconData(Material.LEVER), new Consumer<Boolean>() {
BooleanElement formatBool = new BooleanElement("Format Numbers", new ControlElement.IconData(new ResourceLocation("prevtb/textures/format.png")), new Consumer<Boolean>() {

@Override
public void accept(Boolean accepted) {
enabled = accepted;
format = accepted;

getConfig().addProperty("enabled", enabled);
getConfig().addProperty("format", format);
saveConfig();
}
}, enabled);
}, format);

BooleanElement formatBool = new BooleanElement("Format Numbers", new ControlElement.IconData(new ResourceLocation("prevtb/textures/format.png")), new Consumer<Boolean>() {
BooleanElement warnOnLastHit = new BooleanElement("Warn on last hit", new ControlElement.IconData(new ResourceLocation("prevtb/textures/0p.png")), new Consumer<Boolean>() {

@Override
public void accept(Boolean accepted) {
format = accepted;
lastHitWarn = accepted;

getConfig().addProperty("format", format);
getConfig().addProperty("lastHitWarn", lastHitWarn);
saveConfig();
}
}, format);
}, lastHitWarn);

BooleanElement debugBool = new BooleanElement("Debug Mode (not recommended)", new ControlElement.IconData(new ResourceLocation("prevtb/textures/matrix.png")), new Consumer<Boolean>() {
BooleanElement debugBool = new BooleanElement("Debug Mode (Development Feature)", new ControlElement.IconData(new ResourceLocation("prevtb/textures/matrix.png")), new Consumer<Boolean>() {

@Override
public void accept(Boolean accepted) {
Expand Down Expand Up @@ -102,6 +105,41 @@ public void accept(String accepted) {
SliderElement spadeSlider = new SliderElement( "Shovel Warn Percentage",
new ControlElement.IconData(Material.IRON_SPADE), warnPercentageShovel);


BooleanElement enabledBool = new BooleanElement("Enabled", new ControlElement.IconData(Material.LEVER), new Consumer<Boolean>() {

@Override
public void accept(Boolean accepted) {
enabled = accepted;

formatBool.setBlocked(!enabled);
formatBool.setHoverable(enabled);
warnOnLastHit.setBlocked(!enabled);
warnOnLastHit.setHoverable(enabled);
debugBool.setBlocked(!enabled);
debugBool.setHoverable(enabled);
warnmsg.setBlocked(!enabled);
warnmsg.setHoverable(enabled);
swordSlider.setBlocked(!enabled);
swordSlider.setHoverable(enabled);
pickSlider.setBlocked(!enabled);
pickSlider.setHoverable(enabled);
axeSlider.setBlocked(!enabled);
axeSlider.setHoverable(enabled);
spadeSlider.setBlocked(!enabled);
spadeSlider.setHoverable(enabled);

getConfig().addProperty("enabled", enabled);
saveConfig();
}
}, enabled);

formatBool.setDescriptionText("Unformatted Number: 1561\nFormatted Number: 1.561");

debugBool.setDescriptionText("Sends a message in the chat every tick you're holding a tool.");

warnOnLastHit.setDescriptionText("Warns you when your tool is at 0 durability");

{
// Setting the slider's min & max values
swordSlider.setRange(1, 25);
Expand Down Expand Up @@ -183,9 +221,12 @@ public void accept(Integer accepted) {
}

// Adding setting
list.add(new HeaderElement("General"));
list.add(enabledBool);
list.add(formatBool);
list.add(warnOnLastHit);
list.add(debugBool);
list.add(new HeaderElement("\u00A7cWarn Settings"));
list.add(warnmsg);
list.add(swordSlider);
list.add(pickSlider);
Expand Down
64 changes: 48 additions & 16 deletions src/main/java/com/rappytv/tbw/util/Util.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.rappytv.tbw.main.Main;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiChat;
import net.minecraft.init.Items;
import net.minecraft.init.SoundEvents;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
Expand All @@ -19,10 +20,10 @@ public class Util {
public static boolean axeWarned = false;
public static boolean shovelWarned = false;

private static int[] sword = {268, 272, 267, 283, 276};
private static int[] pick = {270, 274, 257, 285, 278};
private static int[] axe = {271, 275, 258, 286, 279};
private static int[] spade = {269, 273, 256, 284, 277};
private static final int[] sword = {268, 272, 267, 283, 276};
private static final int[] pick = {270, 274, 257, 285, 278};
private static final int[] axe = {271, 275, 258, 286, 279};
private static final int[] spade = {269, 273, 256, 284, 277};

public static void msg(String text, boolean prefix) {
Main.getMain().getApi().displayMessageInChat(prefix ? Main.prefix + text : text);
Expand All @@ -37,6 +38,11 @@ public static String formatNumber(int number) {
return formatter.format(number);
}

public static boolean isLastHit(ItemStack i) {
if(!Main.lastHitWarn) return false;
return (i.getMaxDamage() - i.getItemDamage()) == 0;
}

public static boolean isSword(ItemStack i) {
if(i.getItem().equals(Item.getItemById(sword[0]))) return true;
else if(i.getItem().equals(Item.getItemById(sword[1]))) return true;
Expand Down Expand Up @@ -69,9 +75,9 @@ public static boolean isShovel(ItemStack i) {
else return i.getItem().equals(Item.getItemById(spade[4]));
}

public static void swordUsed(ItemStack itemStack) {
int itemWarnInt = (Main.warnPercentageSword * itemStack.getMaxDamage()) / 100;
int itemUsedInt = itemStack.getMaxDamage() - itemStack.getItemDamage();
public static void swordUsed(ItemStack i) {
int itemWarnInt = (Main.warnPercentageSword * i.getMaxDamage()) / 100;
int itemUsedInt = i.getMaxDamage() - i.getItemDamage();
if(Main.debug) {
msg("\u00A7c\u00A7l------ Event triggered ------\n\u00A7eEvent: \u00A74Sword in main hand\n\u00A7eTool used: \u00A74" + (Main.format ? formatNumber(itemUsedInt) : itemUsedInt) + "\n\u00A7eTool warn: \u00A74" + (Main.format ? formatNumber(itemWarnInt) : itemWarnInt) + "\n\u00A7c\u00A7l---------------------------", false);
}
Expand All @@ -84,14 +90,22 @@ public static void swordUsed(ItemStack itemStack) {
Minecraft.getMinecraft().player.playSound(SoundEvents.BLOCK_ANVIL_USE, 100f, 0f);
swordWarned = true;
}
} else if(isLastHit(i)) {
if(!swordWarned) {
msg(Main.lastHitMsg, true);
msg(Main.lastHitMsg, true);
msg(Main.lastHitMsg, true);
Minecraft.getMinecraft().player.playSound(SoundEvents.BLOCK_ANVIL_USE, 100f, 0f);
swordWarned = true;
}
} else {
swordWarned = false;
}
}

public static void pickaxeUsed(ItemStack itemStack) {
int itemWarnInt = (Main.warnPercentagePickaxe * itemStack.getMaxDamage()) / 100;
int itemUsedInt = itemStack.getMaxDamage() - itemStack.getItemDamage();
public static void pickaxeUsed(ItemStack i) {
int itemWarnInt = (Main.warnPercentagePickaxe * i.getMaxDamage()) / 100;
int itemUsedInt = i.getMaxDamage() - i.getItemDamage();
if(Main.debug) {
msg("\u00A7c\u00A7l------ Event triggered ------\n\u00A7eEvent: \u00A74Pickaxe in main hand\n\u00A7eTool used: \u00A74" + (Main.format ? formatNumber(itemUsedInt) : itemUsedInt) + "\n\u00A7eTool warn: \u00A74" + (Main.format ? formatNumber(itemWarnInt) : itemWarnInt) + "\n\u00A7c\u00A7l---------------------------", false);
}
Expand All @@ -102,14 +116,20 @@ public static void pickaxeUsed(ItemStack itemStack) {
Minecraft.getMinecraft().displayGuiScreen(new GuiChat());
pickWarned = true;
}
} else if(isLastHit(i)) {
if(!pickWarned) {
msg(Main.lastHitMsg, true);
Minecraft.getMinecraft().displayGuiScreen(new GuiChat());
pickWarned = true;
}
} else {
pickWarned = false;
}
}

public static void axeUsed(ItemStack itemStack) {
int itemWarnInt = (Main.warnPercentageAxe * itemStack.getMaxDamage()) / 100;
int itemUsedInt = itemStack.getMaxDamage() - itemStack.getItemDamage();
public static void axeUsed(ItemStack i) {
int itemWarnInt = (Main.warnPercentageAxe * i.getMaxDamage()) / 100;
int itemUsedInt = i.getMaxDamage() - i.getItemDamage();
if(Main.debug) {
msg("\u00A7c\u00A7l------ Event triggered ------\n\u00A7eEvent: \u00A74Axe in main hand\n\u00A7eTool used: \u00A74" + (Main.format ? Util.formatNumber(itemUsedInt) : itemUsedInt) + "\n\u00A7eTool warn: \u00A74" + (Main.format ? Util.formatNumber(itemWarnInt) : itemWarnInt) + "\n\u00A7c\u00A7l---------------------------", false);
}
Expand All @@ -120,14 +140,20 @@ public static void axeUsed(ItemStack itemStack) {
Minecraft.getMinecraft().displayGuiScreen(new GuiChat());
axeWarned = true;
}
} else if(isLastHit(i)) {
if(!axeWarned) {
msg(Main.lastHitMsg, true);
Minecraft.getMinecraft().displayGuiScreen(new GuiChat());
axeWarned = true;
}
} else {
axeWarned = false;
}
}

public static void shovelUsed(ItemStack itemStack) {
int itemWarnInt = (Main.warnPercentageShovel * itemStack.getMaxDamage()) / 100;
int itemUsedInt = itemStack.getMaxDamage() - itemStack.getItemDamage();
public static void shovelUsed(ItemStack i) {
int itemWarnInt = (Main.warnPercentageShovel * i.getMaxDamage()) / 100;
int itemUsedInt = i.getMaxDamage() - i.getItemDamage();
if(Main.debug) {
msg("\u00A7c\u00A7l------ Event triggered ------\n\u00A7eEvent: \u00A74Shovel in main hand\n\u00A7eTool used: \u00A74" + (Main.format ? formatNumber(itemUsedInt) : itemUsedInt) + "\n\u00A7eTool warn: \u00A74" + (Main.format ? formatNumber(itemWarnInt) : itemWarnInt) + "\n\u00A7c\u00A7l---------------------------", false);
}
Expand All @@ -138,6 +164,12 @@ public static void shovelUsed(ItemStack itemStack) {
Minecraft.getMinecraft().displayGuiScreen(new GuiChat());
shovelWarned = true;
}
} else if(isLastHit(i)) {
if(!shovelWarned) {
msg(Main.lastHitMsg, true);
Minecraft.getMinecraft().displayGuiScreen(new GuiChat());
shovelWarned = true;
}
} else {
shovelWarned = false;
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/addon.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"name": "ToolBreak Warning",
"mainClass": "com.rappytv.tbw.main.Main",
"description": "Stops you from using your currently used tool when its almost destroyed.",
"version": 1.2,
"version": 3,
"author": "RappyTV#6969",
"category": 2,
"icon": "https://cdn.discordapp.com/attachments/962708390805655593/974731356137467995/icon.png"
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 7624d72

Please sign in to comment.