MinecartStashDetector
unknown
java
9 months ago
2.9 kB
6
Indexable
package me.blindedbythesun.nya.modules;
import meteordevelopment.meteorclient.systems.modules.Module;
import meteordevelopment.meteorclient.events.world.TickEvent;
import meteordevelopment.meteorclient.settings.IntSetting;
import meteordevelopment.meteorclient.settings.Setting;
import meteordevelopment.meteorclient.settings.SettingGroup;
import meteordevelopment.orbit.EventHandler;
import net.minecraft.entity.Entity;
import net.minecraft.entity.vehicle.ChestMinecartEntity;
import net.minecraft.util.math.BlockPos;
import java.util.HashMap;
import me.blindedbythesun.nya.modules.notifications.NotificationType;
import java.util.Map;
import java.util.concurrent.TimeUnit;
import static me.blindedbythesun.nya.Addon.CATEGORY;
import static me.blindedbythesun.nya.Addon.notifications;
public class MinecartStashDetector extends Module {
private final SettingGroup sgGeneral = settings.getDefaultGroup();
private final Setting<Integer> minMinecarts = sgGeneral.add(new IntSetting.Builder()
.name("minimum-minecarts")
.description("The minimum number of chest minecarts stacked on one block to trigger a notification")
.defaultValue(3)
.min(1)
.max(20)
.sliderMin(1)
.sliderMax(10)
.build()
);
private final Map<BlockPos, Long> detectedStashes = new HashMap<>();
public MinecartStashDetector() {
super(CATEGORY, "minecart-stash-detector", "Detects chest minecart stashes");
}
@Override
public void onActivate() {
detectedStashes.clear();
}
@EventHandler
private void onTick(TickEvent.Post event) {
if (mc.world == null || mc.player == null) return;
Map<BlockPos, Integer> minecartCounts = new HashMap<>();
for (Entity entity : mc.world.getEntities()) {
if (entity instanceof ChestMinecartEntity) {
BlockPos pos = entity.getBlockPos();
minecartCounts.put(pos, minecartCounts.getOrDefault(pos, 0) + 1);
}
}
for (Map.Entry<BlockPos, Integer> entry : minecartCounts.entrySet()) {
BlockPos pos = entry.getKey();
int count = entry.getValue();
if (count >= minMinecarts.get() && !detectedStashes.containsKey(pos)) {
notifyPlayer(pos, count);
detectedStashes.put(pos, System.currentTimeMillis());
}
}
detectedStashes.entrySet().removeIf(entry ->
System.currentTimeMillis() - entry.getValue() > TimeUnit.SECONDS.toMillis(10)
);
}
private void notifyPlayer(BlockPos pos, int count) {
String message = String.format("Found %d stacked chest minecarts at %d, %d, %d", count, pos.getX(), pos.getY(), pos.getZ());
notifications.addNotification(message, 5000, NotificationType.WARNING);
}
}Editor is loading...
Leave a Comment