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

Actual complete overhaul #19

Merged
merged 53 commits into from
Mar 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
53 commits
Select commit Hold shift + click to select a range
62ec836
Add empty tool config activity
RappyTV Feb 1, 2024
b51f5ce
Add setting which opens ToolConfigActivity
RappyTV Feb 1, 2024
86cb507
Add empty lss files
RappyTV Feb 1, 2024
b58a8b0
Add tool widget
RappyTV Feb 1, 2024
b60cdb5
Link config activity to lss file
RappyTV Feb 1, 2024
34aceea
Add warn sound to ToolWidget
RappyTV Feb 1, 2024
1837177
Add new translation
RappyTV Feb 1, 2024
15d1c18
Some other changes - and a lot of errors
RappyTV Feb 1, 2024
75b7841
Progress - 03.02.2024 00:35
RappyTV Feb 2, 2024
90242a8
Delete own tool lss file
RappyTV Feb 3, 2024
f2701d3
Add own tool spritesheet, fix ToolWidget meta line
RappyTV Feb 3, 2024
4adb3f6
Fix WarnTool SpriteTextures
RappyTV Feb 3, 2024
3cfe4ae
Add gui translations
RappyTV Feb 3, 2024
a139c22
Another Activity structure update
RappyTV Feb 3, 2024
5998ef2
pretty hacky only half working lss code (i'm gonna kms)
RappyTV Feb 3, 2024
3e68932
Add change Interaction for slider value, remove out-commented code
RappyTV Feb 3, 2024
a490f67
Implement TbwConfiguration#removeInvalidTools
RappyTV Feb 3, 2024
9a3ce2a
Make remove confirmation round and background darker
RappyTV Feb 3, 2024
7ec3a69
Move tool icon more to the center
RappyTV Feb 3, 2024
d61f31e
Change WarnTool.Type enum to SCREAMING_SNAKE_CASE
RappyTV Feb 3, 2024
e65b0c9
Add another condition to TbwConfiguration#removeInvalidTools
RappyTV Feb 3, 2024
91a1f39
Add translations for sound and tool enum
RappyTV Feb 3, 2024
393b59e
Fix conflicting tool-icon properties
RappyTV Feb 3, 2024
feeec2e
Complete manageContainer structure and lss style
RappyTV Feb 4, 2024
73cfac6
Use correct item type title
RappyTV Feb 4, 2024
92f14e0
Show item instantly when added
RappyTV Feb 4, 2024
34620f6
Copy files for fancy theme
RappyTV Feb 4, 2024
072eab2
Implement vanilla theme
RappyTV Feb 4, 2024
ee7c0b4
Remove redundant config options, deprecate GameTickListener
RappyTV Feb 4, 2024
58607a5
Add some empty events and listeners
RappyTV Feb 4, 2024
1c43d72
Register empty listeners
RappyTV Feb 4, 2024
9caadad
Add german translations, improve config
RappyTV Feb 4, 2024
625cc80
Deprecate WarnTool.Type#getWarnPercentage
RappyTV Feb 4, 2024
15aaca6
Remove some warnings
RappyTV Feb 4, 2024
b850a9f
Add missing NotNull annotations on ITbwSounds implementations
RappyTV Feb 4, 2024
a205baa
Return NONE in WarnTool.Type#getByItem if itemStack is null
RappyTV Feb 4, 2024
c34f6d5
Write ToolUseEvent prototype
RappyTV Feb 4, 2024
1a02683
Add some event boilerplate code in ItemEquipListener
RappyTV Feb 4, 2024
891286d
Debug ToolUseListener
RappyTV Feb 4, 2024
3c8fb33
Only register ItemEquipListener and ToolUseListener
RappyTV Feb 4, 2024
6cc6b8f
fuck mixins, use old method instead
RappyTV Feb 4, 2024
2297f6d
Remove all unused slots
RappyTV Mar 9, 2024
09eec59
Add SpriteSlot to tool manager config
RappyTV Mar 9, 2024
a7fd7a4
Support hoes, remove deprecated WarnTool#getWarnPercentage
RappyTV Mar 9, 2024
d0df6cc
Bump version
RappyTV Mar 9, 2024
7231f53
Register 1.4.0 revision
RappyTV Mar 9, 2024
b7921b1
Rearrange config a bit, add commented IntroducedIn annotation
RappyTV Mar 10, 2024
cbc7ac7
Implement half-finished config migrator
RappyTV Mar 10, 2024
5325817
Set config version to 2
RappyTV Mar 11, 2024
73684d6
Write a ConfigMigrator
RappyTV Mar 11, 2024
fcf9acd
Remove old config migrator, register new one
RappyTV Mar 11, 2024
2d30a60
The annotation finally works :D
RappyTV Mar 14, 2024
c5c6689
Change v1.4.0 release date
RappyTV Mar 14, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ labyMod {
author = "RappyTV"
description = "Stops you from using your currently used tool when its almost destroyed."
minecraftVersion = "1.8<1.20.4"
version = System.getenv().getOrDefault("VERSION", "1.3.4")
version = System.getenv().getOrDefault("VERSION", "1.4.0")
}

minecraft {
Expand Down
11 changes: 10 additions & 1 deletion core/src/main/java/com/rappytv/toolwarn/TbwAddon.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.rappytv.toolwarn.config.TbwConfiguration;
import com.rappytv.toolwarn.core.generated.DefaultReferenceStorage;
import com.rappytv.toolwarn.listener.ConfigMigrationListener;
import com.rappytv.toolwarn.listener.GameTickListener;
import com.rappytv.toolwarn.util.ITbwSounds;
import net.labymod.api.Laby;
Expand All @@ -19,10 +20,13 @@ public class TbwAddon extends LabyAddon<TbwConfiguration> {

public static Component prefix;
private static ITbwSounds sounds;
private static TbwAddon instance;

@Override
protected void preConfigurationLoad() {
Laby.references().revisionRegistry().register(new SimpleRevision("toolwarn", new SemanticVersion("1.4.3"), "2024-01-26"));
Laby.references().revisionRegistry().register(new SimpleRevision("toolwarn", new SemanticVersion("1.3.4"), "2024-01-26"));
Laby.references().revisionRegistry().register(new SimpleRevision("toolwarn", new SemanticVersion("1.4.0"), "2024-03-14"));
registerListener(new ConfigMigrationListener());
}

@Override
Expand All @@ -32,10 +36,15 @@ protected void enable() {
.append(Component.text("» ", NamedTextColor.DARK_GRAY));
sounds = ((DefaultReferenceStorage) this.referenceStorageAccessor()).iTbwSounds();
registerSettingCategory();
instance = this;

registerListener(new GameTickListener(this));
}

public static TbwAddon get() {
return instance;
}

public static ITbwSounds getSounds() {
return sounds;
}
Expand Down
105 changes: 30 additions & 75 deletions core/src/main/java/com/rappytv/toolwarn/config/TbwConfiguration.java
Original file line number Diff line number Diff line change
@@ -1,105 +1,60 @@
package com.rappytv.toolwarn.config;

import com.rappytv.toolwarn.config.subconfig.TbwSoundSubConfig;
import com.rappytv.toolwarn.ui.ToolConfigActivity;
import com.rappytv.toolwarn.util.WarnTool;
import net.labymod.api.addon.AddonConfig;
import net.labymod.api.client.gui.screen.widget.widgets.input.SliderWidget.SliderSetting;
import net.labymod.api.client.gui.screen.activity.Activity;
import net.labymod.api.client.gui.screen.widget.widgets.activity.settings.ActivitySettingWidget.ActivitySetting;
import net.labymod.api.client.gui.screen.widget.widgets.input.SwitchWidget.SwitchSetting;
import net.labymod.api.configuration.loader.annotation.ConfigName;
import net.labymod.api.configuration.loader.annotation.Exclude;
import net.labymod.api.configuration.loader.annotation.IntroducedIn;
import net.labymod.api.configuration.loader.annotation.SpriteSlot;
import net.labymod.api.configuration.loader.annotation.SpriteTexture;
import net.labymod.api.configuration.loader.annotation.VersionCompatibility;
import net.labymod.api.configuration.loader.property.ConfigProperty;
import net.labymod.api.configuration.settings.annotation.SettingSection;
import net.labymod.api.util.MethodOrder;
import java.util.ArrayList;
import java.util.List;

@ConfigName("settings")
@SpriteTexture(value = "settings")
public class TbwConfiguration extends AddonConfig {

@SwitchSetting
@SpriteSlot(size = 32)
private final ConfigProperty<Boolean> enabled = new ConfigProperty<>(true);
@SettingSection("general")
@SwitchSetting
@SpriteSlot(size = 32, x = 1)
private final ConfigProperty<Boolean> openChat = new ConfigProperty<>(true);
@SwitchSetting
@SpriteSlot(size = 32, x = 3)
private final ConfigProperty<Boolean> lastHit = new ConfigProperty<>(true);
private final ConfigProperty<Boolean> enabled = new ConfigProperty<>(true);

@SettingSection("sounds")
@SpriteSlot(size = 32, y = 1)
private final TbwSoundSubConfig sounds = new TbwSoundSubConfig();
@Exclude
private final List<WarnTool> tools = new ArrayList<>();

@SettingSection("tools")
@SliderSetting(steps = 1, min = 1, max = 25)
@SpriteSlot(size = 32, y = 2)
private final ConfigProperty<Integer> swordPercentage = new ConfigProperty<>(5);
@SliderSetting(steps = 1, min = 1, max = 25)
@SpriteSlot(size = 32, y = 2, x = 1)
private final ConfigProperty<Integer> pickaxePercentage = new ConfigProperty<>(5);
@SliderSetting(steps = 1, min = 1, max = 25)
@SpriteSlot(size = 32, y = 2, x = 2)
private final ConfigProperty<Integer> axePercentage = new ConfigProperty<>(5);
@SliderSetting(steps = 1, min = 1, max = 25)
@SpriteSlot(size = 32, y = 2, x = 3)
private final ConfigProperty<Integer> shovelPercentage = new ConfigProperty<>(5);
@SliderSetting(steps = 1, min = 1, max = 25)
@SpriteSlot(size = 32, y = 3)
@VersionCompatibility("1.14<*")
@IntroducedIn(namespace = "globaltags", value = "1.4.3")
private final ConfigProperty<Integer> crossbowPercentage = new ConfigProperty<>(5);
@SliderSetting(steps = 1, min = 1, max = 25)
@SpriteSlot(size = 32, y = 3, x = 1)
@IntroducedIn(namespace = "globaltags", value = "1.4.3")
private final ConfigProperty<Integer> lighterPercentage = new ConfigProperty<>(5);
@SliderSetting(steps = 1, min = 1, max = 25)
@SpriteSlot(size = 32, y = 3, x = 2)
@IntroducedIn(namespace = "globaltags", value = "1.4.3")
private final ConfigProperty<Integer> shearsPercentage = new ConfigProperty<>(5);
@SliderSetting(steps = 1, min = 1, max = 25)
@SpriteSlot(size = 32, y = 3, x = 3)
@VersionCompatibility("1.13<*")
@IntroducedIn(namespace = "globaltags", value = "1.4.3")
private final ConfigProperty<Integer> tridentPercentage = new ConfigProperty<>(5);
@IntroducedIn(namespace = "toolwarn", value = "1.4.0")
@SpriteSlot(size = 32, x = 1)
@MethodOrder(after = "enabled")
@ActivitySetting
public Activity toolConfig() {
return new ToolConfigActivity();
}

@Override
public ConfigProperty<Boolean> enabled() {
return enabled;
}
public ConfigProperty<Boolean> openChat() {
return openChat;
}
public ConfigProperty<Boolean> lastHit() {
return lastHit;
}

public TbwSoundSubConfig sounds() {
return sounds;
public List<WarnTool> getTools() {
return tools;
}

public ConfigProperty<Integer> swordPercentage() {
return swordPercentage;
}
public ConfigProperty<Integer> pickAxePercentage() {
return pickaxePercentage;
}
public ConfigProperty<Integer> axePercentage() {
return axePercentage;
}
public ConfigProperty<Integer> shovelPercentage() {
return shovelPercentage;
}
public ConfigProperty<Integer> crossbowPercentage() {
return crossbowPercentage;
public void removeInvalidTools() {
this.tools.removeIf(entry ->
entry.getWarnAt() < 1
|| entry.getWarnAt() > 25
|| entry.getType() == null
);
}
public ConfigProperty<Integer> lighterPercentage() {
return lighterPercentage;
}
public ConfigProperty<Integer> shearsPercentage() {
return shearsPercentage;
}
public ConfigProperty<Integer> tridentPercentage() {
return tridentPercentage;

@Override
public int getConfigVersion() {
return 2;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
package com.rappytv.toolwarn.listener;

import com.google.gson.Gson;
import com.google.gson.JsonArray;
import com.google.gson.JsonObject;
import com.rappytv.toolwarn.config.TbwConfiguration;
import com.rappytv.toolwarn.util.WarnSound;
import com.rappytv.toolwarn.util.WarnTool;
import com.rappytv.toolwarn.util.WarnTool.Type;
import net.labymod.api.configuration.loader.Config;
import net.labymod.api.event.Subscribe;
import net.labymod.api.event.labymod.config.ConfigurationVersionUpdateEvent;

@SuppressWarnings("FieldCanBeLocal")
public class ConfigMigrationListener {

private final Gson gson = new Gson();
private final int defaultPercentage = 5;

@Subscribe
public void onConfigVersionUpdate(ConfigurationVersionUpdateEvent event) {
Class<? extends Config> configClass = event.getConfigClass();
int usedVersion = event.getUsedVersion();

if(configClass == TbwConfiguration.class) {
if(usedVersion == 1) migrateFromOne(event);
}
}

private void migrateFromOne(ConfigurationVersionUpdateEvent event) {
JsonObject config = event.getJsonObject();
if(!config.has("sounds")) return;

JsonObject sounds = config.get("sounds").getAsJsonObject();

WarnSound warnSound = WarnSound.NONE;
WarnSound lastHitSound = WarnSound.NONE;
boolean openChat = true;
boolean lastHitWarn = true;
int sword = defaultPercentage;
int pickaxe = defaultPercentage;
int axe = defaultPercentage;
int shovel = defaultPercentage;
int crossbow = defaultPercentage;
int lighter = defaultPercentage;
int shears = defaultPercentage;
int trident = defaultPercentage;

try {
warnSound = WarnSound.valueOf(sounds.get("warnSound").getAsString());
lastHitSound = WarnSound.valueOf(sounds.get("lastHitSound").getAsString());
openChat = config.get("openChat").getAsBoolean();
lastHitWarn = config.get("lastHit").getAsBoolean();
sword = config.get("swordPercentage").getAsInt();
pickaxe = config.get("pickaxePercentage").getAsInt();
axe = config.get("axePercentage").getAsInt();
shovel = config.get("shovelPercentage").getAsInt();
crossbow = config.get("crossbowPercentage").getAsInt();
lighter = config.get("lighterPercentage").getAsInt();
shears = config.get("shearsPercentage").getAsInt();
trident = config.get("tridentPercentage").getAsInt();
} catch (IllegalArgumentException e) {
e.printStackTrace();
}

JsonArray tools = new JsonArray();
tools.add(gson.toJsonTree(new WarnTool(Type.SWORD, warnSound, lastHitSound, sword, openChat, lastHitWarn)));
tools.add(gson.toJsonTree(new WarnTool(Type.PICKAXE, warnSound, lastHitSound, pickaxe, openChat, lastHitWarn)));
tools.add(gson.toJsonTree(new WarnTool(Type.AXE, warnSound, lastHitSound, axe, openChat, lastHitWarn)));
tools.add(gson.toJsonTree(new WarnTool(Type.SHOVEL, warnSound, lastHitSound, shovel, openChat, lastHitWarn)));
tools.add(gson.toJsonTree(new WarnTool(Type.CROSSBOW, warnSound, lastHitSound, crossbow, openChat, lastHitWarn)));
tools.add(gson.toJsonTree(new WarnTool(Type.LIGHTER, warnSound, lastHitSound, lighter, openChat, lastHitWarn)));
tools.add(gson.toJsonTree(new WarnTool(Type.SHEARS, warnSound, lastHitSound, shears, openChat, lastHitWarn)));
tools.add(gson.toJsonTree(new WarnTool(Type.TRIDENT, warnSound, lastHitSound, trident, openChat, lastHitWarn)));

config.add("tools", tools);
event.setJsonObject(config);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@

import com.rappytv.toolwarn.TbwAddon;
import com.rappytv.toolwarn.config.TbwConfiguration;
import com.rappytv.toolwarn.util.ToolType;
import com.rappytv.toolwarn.util.Util;
import com.rappytv.toolwarn.util.WarnSound;
import com.rappytv.toolwarn.util.WarnTool;
import com.rappytv.toolwarn.util.WarnTool.Type;
import net.labymod.api.Laby;
import net.labymod.api.client.component.Component;
import net.labymod.api.client.component.format.NamedTextColor;
Expand Down Expand Up @@ -38,51 +39,56 @@ public void onTick(GameTickEvent event) {
if(itemStack.getMaximumDamage() == 0) return;
if(player.gameMode() != GameMode.SURVIVAL && player.gameMode() != GameMode.ADVENTURE) return;

toolUsed(itemStack, ToolType.getByItem(itemStack));
checkForWarn(itemStack, Type.getByItem(itemStack));
}

public void toolUsed(ItemStack itemStack, ToolType toolType) {
if(toolType == ToolType.None) return;
private void checkForWarn(ItemStack itemStack, WarnTool.Type type) {
if(type == Type.NONE) return;
if(Laby.labyAPI().minecraft().minecraftWindow().isScreenOpened()) return;

int itemWarnInt = (toolType.getWarnPercentage(config) * itemStack.getMaximumDamage()) / 100;
int itemUsedInt = itemStack.getMaximumDamage() - itemStack.getCurrentDamageValue();

if(itemUsedInt == itemWarnInt) {
if(!warns.contains(itemStack)) {
if(this.config.openChat().get()) Laby.labyAPI().minecraft().openChat("");
Util.msg(Component.translatable("toolwarn.messages.warning", NamedTextColor.RED, Component.text(toolType.getWarnPercentage(config))), true);
warns.add(itemStack);
for(WarnTool tool : config.getTools()) {
if(tool.getType() != type) continue;
int itemWarnInt = (tool.getWarnAt() * itemStack.getMaximumDamage()) / 100;

if(config.sounds().enabled().get() && config.sounds().warnSound().get() != WarnSound.NONE) {
Laby.labyAPI().minecraft().sounds().playSound(
config.sounds().warnSound().get().getResourceLocation(),
1f,
1f
);
}
}
} else if(isLastHit(itemStack)) {
if(!warns.contains(itemStack)) {
if(this.config.openChat().get()) Laby.labyAPI().minecraft().openChat("");
Util.msg(Component.translatable("toolwarn.messages.lastHit", NamedTextColor.RED), true);
warns.add(itemStack);
if(itemUsedInt == itemWarnInt) {
if(!warns.contains(itemStack)) {
if(tool.openChat()) Laby.labyAPI().minecraft().openChat("");
Util.msg(Component.translatable(
"toolwarn.messages.warning",
NamedTextColor.RED,
Component.text(tool.getWarnAt())
), true);
warns.add(itemStack);

if(config.sounds().enabled().get() && config.sounds().lastHitSound().get() != WarnSound.NONE) {
Laby.labyAPI().minecraft().sounds().playSound(
config.sounds().lastHitSound().get().getResourceLocation(),
1f,
1f
if(tool.getSound() != WarnSound.NONE) {
Laby.labyAPI().minecraft().sounds().playSound(
tool.getSound().getResourceLocation(),
1f,
1f
);
}
}
} else if(tool.lastHitWarn() && itemUsedInt <= 1) {
if(!warns.contains(itemStack)) {
if(tool.openChat()) Laby.labyAPI().minecraft().openChat("");
Util.msg(
Component.translatable("toolwarn.messages.lastHit", NamedTextColor.RED),
true
);
warns.add(itemStack);
if(tool.getLastSound() != WarnSound.NONE) {
Laby.labyAPI().minecraft().sounds().playSound(
tool.getLastSound().getResourceLocation(),
1f,
1f
);
}
}
} else {
warns.remove(itemStack);
}
} else {
warns.remove(itemStack);
}
}

public boolean isLastHit(ItemStack i) {
if (!addon.configuration().lastHit().get()) return false;
return (i.getMaximumDamage() - i.getCurrentDamageValue()) <= 1;
}
}
Loading
Loading