Начинающий
- Статус
- Оффлайн
- Регистрация
- 6 Янв 2024
- Сообщения
- 75
- Реакции
- 1
- Выберите загрузчик игры
- Fabric
Типо короче автоматически ловит момент когда ты выпил шард бустер
Показывает таймер на 24 часа прямо в панели эффектов
Помнит время между перезапусками игры
чут-чут ИИ но вроде все ок
SS - хз зачем нужен, это просто таймер
Показывает таймер на 24 часа прямо в панели эффектов
Помнит время между перезапусками игры
чут-чут ИИ но вроде все ок
jaava:
package com.donutmod;
import net.fabricmc.api.ClientModInitializer;
import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents;
import net.fabricmc.fabric.api.client.message.v1.ClientReceiveMessageEvents;
import net.minecraft.client.MinecraftClient;
import net.minecraft.entity.effect.StatusEffect;
import net.minecraft.entity.effect.StatusEffectCategory;
import net.minecraft.registry.Registries;
import net.minecraft.registry.Registry;
import net.minecraft.util.Identifier;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Date;
public class DonutMod implements ClientModInitializer {
public static final String MOD_ID = "donutmod";
public static final Logger LOGGER = LoggerFactory.getLogger(MOD_ID);
private static StatusEffect SHARD_BOOSTER_EFFECT;
private static long expiryTime = 0;
private static boolean debugMode = false;
private static Path CONFIG_FILE;
public static void main(String[] args) {
initializeMod();
}
private static void initializeMod() {
LOGGER.info("Shard Booster Timer initializing...");
SHARD_BOOSTER_EFFECT = Registry.register(
Registries.STATUS_EFFECT,
new Identifier(MOD_ID, "shard_booster"),
new ShardBoosterEffect()
);
LOGGER.info("Shard Booster effect registered");
CONFIG_FILE = MinecraftClient.getInstance().runDirectory.toPath()
.resolve("config")
.resolve("shard_booster.txt");
loadConfig();
ClientTickEvents.END_CLIENT_TICK.register(client -> {
if (isActive() && System.currentTimeMillis() >= expiryTime) {
deactivate();
}
});
ClientReceiveMessageEvents.GAME.register((message, overlay) -> {
if (debugMode) {
LOGGER.info("Received message: " + message.getString());
}
detectShardBoosterMessage(message.getString());
});
LOGGER.info("Shard Booster Timer ready!");
}
@Override
public void onInitializeClient() {
initializeMod();
}
private static void detectShardBoosterMessage(String message) {
if (message.contains("shard booster") || message.contains("Shard Booster")) {
if (message.contains("activated") || message.contains("enabled")) {
activate();
} else if (message.contains("deactivated") || message.contains("disabled")) {
deactivate();
}
}
}
public static void activate() {
activateCustom(86400000L);
}
public static void activateCustom(long duration) {
expiryTime = System.currentTimeMillis() + duration;
saveConfig();
LOGGER.info("Shard Booster activated until: " + new Date(expiryTime));
}
public static void deactivate() {
expiryTime = 0;
saveConfig();
LOGGER.info("Шард бустер выключен ");
MinecraftClient client = MinecraftClient.getInstance();
if (client.player != null && SHARD_BOOSTER_EFFECT != null) {
client.player.removeStatusEffect(SHARD_BOOSTER_EFFECT);
}
}
public static boolean isActive() {
if (expiryTime == 0) return false;
if (System.currentTimeMillis() >= expiryTime) {
deactivate();
return false;
}
return true;
}
public static long getRemainingTime() {
if (!isActive()) return 0;
return expiryTime - System.currentTimeMillis();
}
public static int getRemainingTicks() {
return (int) (getRemainingTime() / 50);
}
public static String getFormattedTime() {
long remaining = getRemainingTime();
if (remaining <= 0) return "00:00:00";
long seconds = remaining / 1000;
long hours = seconds / 3600;
long minutes = (seconds % 3600) / 60;
long secs = seconds % 60;
return String.format("%02d:%02d:%02d", hours, minutes, secs);
}
private static void loadConfig() {
try {
if (Files.exists(CONFIG_FILE)) {
String content = Files.readString(CONFIG_FILE);
expiryTime = Long.parseLong(content.trim());
LOGGER.info("Loaded config: " + new Date(expiryTime));
}
} catch (IOException | NumberFormatException e) {
LOGGER.error("Failed to load config", e);
expiryTime = 0;
}
}
private static void saveConfig() {
try {
Files.createDirectories(CONFIG_FILE.getParent());
Files.writeString(CONFIG_FILE, String.valueOf(expiryTime));
} catch (IOException e) {
LOGGER.error("Failed to save config", e);
}
}
public static void setDebugMode(boolean enabled) {
debugMode = enabled;
LOGGER.info("Shard Booster debug mode " + (enabled ? "enabled" : "disabled"));
}
private static class ShardBoosterEffect extends StatusEffect {
public ShardBoosterEffect() {
super(StatusEffectCategory.BENEFICIAL, 15040767);
}
@Override
public boolean canApplyUpdateEffect(int duration, int amplifier) {
return false;
}
@Override
public boolean isBeneficial() {
return true;
}
}
}
SS - хз зачем нужен, это просто таймер