Files
src
autosell
build.gradle
gradle.properties
settings.gradle
Code
8 156
src/main/java/com/kodari/copperreminder/CopperReminderClient.java
package com.kodari.copperreminder;
import net.fabricmc.api.ClientModInitializer;
import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents;
import net.fabricmc.fabric.api.client.keybinding.v1.KeyBindingHelper;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.option.KeyBinding;
import net.minecraft.client.util.InputUtil;
import net.minecraft.text.Text;
public class CopperReminderClient implements ClientModInitializer {
private static final String CATEGORY = "category.copperreminder.controls";
private static final int TICKS_PER_MINUTE = 20 * 60;
private static final int MIN_INTERVAL_MINUTES = 1;
private static final int MAX_INTERVAL_MINUTES = 120;
private static final KeyBinding TOGGLE_KEY = KeyBindingHelper.registerKeyBinding(
new KeyBinding("key.copperreminder.toggle", InputUtil.Type.KEYSYM, 79, CATEGORY)
);
private static final KeyBinding INTERVAL_DOWN_KEY = KeyBindingHelper.registerKeyBinding(
new KeyBinding("key.copperreminder.interval_down", InputUtil.Type.KEYSYM, 75, CATEGORY)
);
private static final KeyBinding INTERVAL_UP_KEY = KeyBindingHelper.registerKeyBinding(
new KeyBinding("key.copperreminder.interval_up", InputUtil.Type.KEYSYM, 76, CATEGORY)
);
private static boolean enabled;
private static int intervalMinutes = 5;
private static int ticksUntilReminder = intervalMinutes * TICKS_PER_MINUTE;
@Override
public void onInitializeClient() {
ClientTickEvents.END_CLIENT_TICK.register(CopperReminderClient::onClientTick);
}
private static void onClientTick(MinecraftClient client) {
if (client.player == null) {
return;
}
if (TOGGLE_KEY.wasPressed()) {
enabled = !enabled;
ticksUntilReminder = intervalMinutes * TICKS_PER_MINUTE;
sendMessage(client, enabled
? "Przypomnienie włączone: co " + intervalMinutes + " min. Sprzedaż wykonaj ręcznie."
: "Przypomnienie wyłączone.");
}
if (INTERVAL_DOWN_KEY.wasPressed()) {
intervalMinutes = Math.max(MIN_INTERVAL_MINUTES, intervalMinutes - 1);
ticksUntilReminder = intervalMinutes * TICKS_PER_MINUTE;
sendMessage(client, "Odstęp przypomnienia: " + intervalMinutes + " min.");
}
if (INTERVAL_UP_KEY.wasPressed()) {
intervalMinutes = Math.min(MAX_INTERVAL_MINUTES, intervalMinutes + 1);
ticksUntilReminder = intervalMinutes * TICKS_PER_MINUTE;
sendMessage(client, "Odstęp przypomnienia: " + intervalMinutes + " min.");
}
if (enabled && --ticksUntilReminder <= 0) {
sendMessage(client, "Pora ręcznie sprzedać miedź w sklepie!");
ticksUntilReminder = intervalMinutes * TICKS_PER_MINUTE;
}
}
private static void sendMessage(MinecraftClient client, String message) {
client.player.sendMessage(Text.literal(message), false);
}
}