- Выберите загрузчик игры
- Fabric
мб комуто над дебуда реворк спащено доработано на 1.21.4
ыххыхы пааскарбляйте миня ыыыы 1.21.4 пэрэнес дибуда рэворк э дэээл эиы
potiontracker:
package com.example.potiontracker;
import com.darkmagician6.eventapi.EventTarget;
import com.example.potiontracker.base.events.impl.player.EventUpdate;
import com.example.potiontracker.client.modules.api.Category;
import com.example.potiontracker.client.modules.api.Module;
import com.example.potiontracker.client.modules.api.ModuleAnnotation;
import com.example.potiontracker.client.modules.api.setting.impl.BooleanSetting;
import com.example.potiontracker.client.modules.api.setting.impl.NumberSetting;
import com.example.potiontracker.utility.game.other.MessageUtil;
import com.example.potiontracker.utility.interfaces.IMinecraft;
import net.minecraft.component.DataComponentTypes;
import net.minecraft.component.type.PotionContentsComponent;
import net.minecraft.entity.Entity;
import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.entity.projectile.thrown.PotionEntity;
import net.minecraft.item.ItemStack;
import net.minecraft.util.Formatting;
import net.minecraft.util.math.Box;
import java.util.*;
@ModuleAnnotation(name = "PotionTracker", category = Category.MISC, description = "Отслеживает зелья")
public final class PotionTracker extends Module implements IMinecraft {
public static final PotionTracker INSTANCE = new PotionTracker();
private final NumberSetting radius = new NumberSetting("Радиус", 50, 10, 100, 1);
private final BooleanSetting showHitChance = new BooleanSetting("Шанс попадания", true);
private final BooleanSetting showEffects = new BooleanSetting("Эффекты", true);
private final Map<Integer, PotionData> trackedPotions = new HashMap<>();
private PotionTracker() {
}
@EventTarget
public void onTick(EventUpdate event) {
if (mc.world == null || mc.player == null) return;
Set<Integer> currentPotions = new HashSet<>();
for (Entity entity : mc.world.getEntities()) {
if (entity instanceof PotionEntity potion) {
int entityId = entity.getId();
if (mc.player.distanceTo(entity) > radius.getCurrent()) continue;
currentPotions.add(entityId);
if (!trackedPotions.containsKey(entityId)) {
trackedPotions.put(entityId, new PotionData(potion.getStack().copy(), entity.getX(), entity.getY(), entity.getZ()));
} else {
PotionData data = trackedPotions.get(entityId);
data.lastX = entity.getX(); data.lastY = entity.getY(); data.lastZ = entity.getZ();
}
}
}
Set<Integer> removedPotions = new HashSet<>(trackedPotions.keySet());
removedPotions.removeAll(currentPotions);
for (int entityId : removedPotions) {
PotionData data = trackedPotions.get(entityId);
Box potionBB = new Box(data.lastX - 4, data.lastY - 2, data.lastZ - 4, data.lastX + 4, data.lastY + 2, data.lastZ + 4);
for (LivingEntity hitEntity : mc.world.getEntitiesByClass(LivingEntity.class, potionBB, e -> e instanceof PlayerEntity)) {
PlayerEntity player = (PlayerEntity) hitEntity;
double distance = Math.sqrt(Math.pow(player.getX() - data.lastX, 2) + Math.pow(player.getZ() - data.lastZ, 2));
if (distance <= 4.0) {
double hitChance = Math.max(0.0, 1.0 - distance / 4.0) * 100.0;
String potionName = data.stack.getName().getString();
Formatting potionColor = getPotionColor(data.stack);
MessageUtil.displayInfo(Formatting.WHITE + player.getName().getString() + Formatting.GRAY + " получил " + potionColor + potionName);
if (showHitChance.isEnabled()) {
MessageUtil.displayInfo(Formatting.DARK_GRAY + "• " + Formatting.WHITE + "Успешность: " + Formatting.GREEN + String.format("%.0f%%", hitChance));
}
if (showEffects.isEnabled()) {
PotionContentsComponent contents = data.stack.get(DataComponentTypes.POTION_CONTENTS);
if (contents != null) {
contents.potion().ifPresent(potion -> {
potion.value().getEffects().forEach(effect -> {
String name = effect.getEffectType().value().getName().getString();
int amp = effect.getAmplifier() + 1;
int dur = (int)(effect.getDuration() / 20 * (hitChance / 100.0));
int min = dur / 60, sec = dur % 60;
Formatting color = effect.getEffectType().value().isBeneficial() ? Formatting.GREEN : Formatting.RED;
MessageUtil.displayInfo(Formatting.DARK_GRAY + "• " + color + name + " " + toRoman(amp) + Formatting.GRAY + " (" + min + ":" + String.format("%02d", sec) + ")");
});
});
contents.customEffects().forEach(effect -> {
String name = effect.getEffectType().value().getName().getString();
int amp = effect.getAmplifier() + 1;
int dur = (int)(effect.getDuration() / 20 * (hitChance / 100.0));
int min = dur / 60, sec = dur % 60;
Formatting color = effect.getEffectType().value().isBeneficial() ? Formatting.GREEN : Formatting.RED;
MessageUtil.displayInfo(Formatting.DARK_GRAY + "• " + Formatting.LIGHT_PURPLE + name + " " + toRoman(amp) + Formatting.GRAY + " (" + min + ":" + String.format("%02d", sec) + ")");
});
}
}
}
}
trackedPotions.remove(entityId);
}
}
private Formatting getPotionColor(ItemStack stack) {
PotionContentsComponent contents = stack.get(DataComponentTypes.POTION_CONTENTS);
if (contents == null) return Formatting.GOLD;
var effects = contents.potion().isPresent() ?
contents.potion().get().value().getEffects() :
java.util.List.of();
if (!effects.isEmpty()) {
var firstEffect = effects.get(0);
return firstEffect.getEffectType().value().isBeneficial() ? Formatting.GREEN : Formatting.RED;
}
if (!contents.customEffects().isEmpty()) {
var firstCustom = contents.customEffects().get(0);
return firstCustom.getEffectType().value().isBeneficial() ? Formatting.GREEN : Formatting.RED;
}
return Formatting.GOLD;
}
private String toRoman(int number) {
return switch (number) {
case 1 -> "I"; case 2 -> "II"; case 3 -> "III";
case 4 -> "IV"; case 5 -> "V"; case 6 -> "VI";
case 7 -> "VII"; case 8 -> "VIII"; case 9 -> "IX";
case 10 -> "X"; default -> String.valueOf(number);
};
}
@Override
public void onDisable() {
trackedPotions.clear();
super.onDisable();
}
private static class PotionData {
final ItemStack stack;
double lastX, lastY, lastZ;
PotionData(ItemStack stack, double x, double y, double z) {
this.stack = stack; this.lastX = x; this.lastY = y; this.lastZ = z;
}
}
}
ыххыхы пааскарбляйте миня ыыыы 1.21.4 пэрэнес дибуда рэворк э дэээл эиы