AutoFrameMap
user_4036049
java
a year ago
5.3 kB
6
Indexable
package me.blindedbythesun.nya.modules;
import meteordevelopment.meteorclient.events.world.TickEvent;
import meteordevelopment.meteorclient.settings.DoubleSetting;
import meteordevelopment.meteorclient.settings.Setting;
import meteordevelopment.meteorclient.settings.SettingGroup;
import meteordevelopment.meteorclient.systems.modules.Module;
import meteordevelopment.orbit.EventHandler;
import me.blindedbythesun.nya.Addon;
import me.blindedbythesun.nya.modules.notifications.NotificationType;
import net.minecraft.entity.decoration.ItemFrameEntity;
import net.minecraft.item.Item;
import net.minecraft.item.Items;
import net.minecraft.util.Hand;
import net.minecraft.util.hit.BlockHitResult;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Box;
import java.util.List;
public class AutoFrameMap extends Module {
private final SettingGroup sgGeneral = this.settings.getDefaultGroup();
private final Setting<Double> actionDelay = sgGeneral.add(new DoubleSetting.Builder()
.name("action-delay")
.description("Delay between completing a frame-and-map placement cycle and starting the next one")
.defaultValue(2.0)
.min(0.0)
.sliderMax(10.0)
.build());
private final Setting<Double> mapInsertionDelay = sgGeneral.add(new DoubleSetting.Builder()
.name("map-insertion-delay")
.description("Delay between placing a frame and inserting a map")
.defaultValue(0.0)
.min(0.0)
.sliderMax(1.0)
.build());
private long lastFramePlaceTime = 0;
private long lastMapInsertTime = 0;
private BlockPos targetPos;
private boolean framePlaced = false;
private boolean hasNotified = false;
public AutoFrameMap() {
super(Addon.CATEGORY, "auto-frame-map", "Automatically places item frames and inserts maps into them");
}
@EventHandler
public void onTick(TickEvent.Pre event) {
if (mc.player == null || mc.world == null) return;
int frameSlot = findHotbarSlot(Items.ITEM_FRAME);
int mapSlot = findHotbarSlot(Items.FILLED_MAP);
if (frameSlot == -1 && mapSlot == -1) {
showNotification("No item frames and no maps found in the hotbar!");
return;
}
if (frameSlot == -1) {
showNotification("No item frames found in the hotbar!");
return;
}
if (mapSlot == -1) {
showNotification("No filled maps found in the hotbar!");
return;
}
hasNotified = false;
if (!framePlaced) {
if (System.currentTimeMillis() - lastFramePlaceTime >= actionDelay.get() * 1000) {
if (tryPlaceFrame(frameSlot)) {
framePlaced = true;
lastFramePlaceTime = System.currentTimeMillis();
}
}
} else {
if (System.currentTimeMillis() - lastMapInsertTime >= mapInsertionDelay.get() * 1000) {
tryInsertMap(mapSlot);
framePlaced = false;
lastMapInsertTime = System.currentTimeMillis();
}
}
}
private void showNotification(String message) {
if (!hasNotified && Addon.notifications.isActive()) {
Addon.notifications.addNotification("AutoFrameMap", message, 4000, NotificationType.WARNING);
hasNotified = true;
}
}
private boolean tryPlaceFrame(int frameSlot) {
BlockHitResult targetBlock = getBlockLookingAt();
if (targetBlock == null) return false;
targetPos = targetBlock.getBlockPos();
mc.player.getInventory().selectedSlot = frameSlot;
mc.interactionManager.interactBlock(mc.player, Hand.MAIN_HAND, targetBlock);
List<ItemFrameEntity> frames = mc.world.getEntitiesByClass(
ItemFrameEntity.class,
new Box(targetPos).expand(0.1),
entity -> entity.isAlive() && entity.isInRange(mc.player, 5)
);
return !frames.isEmpty();
}
private void tryInsertMap(int mapSlot) {
List<ItemFrameEntity> frames = mc.world.getEntitiesByClass(
ItemFrameEntity.class,
new Box(targetPos).expand(0.1),
entity -> entity.isAlive() && entity.isInRange(mc.player, 5)
);
if (frames.isEmpty()) return;
ItemFrameEntity frame = frames.get(0);
if (!frame.getHeldItemStack().isEmpty()) return;
mc.player.getInventory().selectedSlot = mapSlot;
mc.interactionManager.interactEntity(mc.player, frame, Hand.MAIN_HAND);
}
private int findHotbarSlot(Item item) {
for (int i = 0; i < 9; i++) {
if (mc.player.getInventory().getStack(i).getItem() == item) return i;
}
return -1;
}
private BlockHitResult getBlockLookingAt() {
return mc.world.raycast(new net.minecraft.world.RaycastContext(
mc.player.getCameraPosVec(1.0F),
mc.player.getCameraPosVec(1.0F).add(mc.player.getRotationVec(1.0F).multiply(5.0D)),
net.minecraft.world.RaycastContext.ShapeType.OUTLINE,
net.minecraft.world.RaycastContext.FluidHandling.NONE,
mc.player
));
}
}Editor is loading...
Leave a Comment