interact with villagers in range
This commit is contained in:
@@ -5,6 +5,7 @@ import com.github.sebseb7.autotrade.event.InputHandler;
|
||||
import com.github.sebseb7.autotrade.event.KeybindCallbacks;
|
||||
import fi.dy.masa.malilib.config.ConfigManager;
|
||||
import fi.dy.masa.malilib.event.InputEventHandler;
|
||||
import fi.dy.masa.malilib.event.TickHandler;
|
||||
import fi.dy.masa.malilib.interfaces.IInitializationHandler;
|
||||
|
||||
public class InitHandler implements IInitializationHandler {
|
||||
@@ -15,6 +16,8 @@ public class InitHandler implements IInitializationHandler {
|
||||
InputHandler handler = new InputHandler();
|
||||
InputEventHandler.getKeybindManager().registerKeybindProvider(handler);
|
||||
|
||||
TickHandler.getInstance().registerClientTickHandler(KeybindCallbacks.getInstance());
|
||||
|
||||
KeybindCallbacks.getInstance().setCallbacks();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,7 +14,7 @@ public class Hotkeys {
|
||||
public static final ConfigHotkey SET_INPUT_KEY = new ConfigHotkey("setInputContainer", "",
|
||||
"Sets the input (item to sell) container");
|
||||
public static final ConfigHotkey SET_OUTPUT_KEY = new ConfigHotkey("setOutputContainer", "",
|
||||
"Sets the output (item bought) container");
|
||||
"Sets the output (item to buy) container");
|
||||
public static final ConfigHotkey SET_EMERALD_KEY = new ConfigHotkey("setEmeraldContainer", "",
|
||||
"Set the emerald container");
|
||||
public static final ConfigHotkey OPEN_GUI_SETTINGS = new ConfigHotkey("openGuiSettings", "", "Open the Config GUI");
|
||||
|
||||
@@ -9,14 +9,21 @@ import fi.dy.masa.malilib.gui.Message;
|
||||
import fi.dy.masa.malilib.hotkeys.IHotkeyCallback;
|
||||
import fi.dy.masa.malilib.hotkeys.IKeybind;
|
||||
import fi.dy.masa.malilib.hotkeys.KeyAction;
|
||||
import fi.dy.masa.malilib.interfaces.IClientTickHandler;
|
||||
import fi.dy.masa.malilib.util.GuiUtils;
|
||||
import fi.dy.masa.malilib.util.InfoUtils;
|
||||
import java.util.Vector;
|
||||
import net.minecraft.client.MinecraftClient;
|
||||
import net.minecraft.client.gui.screen.ingame.HandledScreen;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.passive.VillagerEntity;
|
||||
import net.minecraft.util.Hand;
|
||||
|
||||
public class KeybindCallbacks implements IHotkeyCallback {
|
||||
public class KeybindCallbacks implements IHotkeyCallback, IClientTickHandler {
|
||||
private static final KeybindCallbacks INSTANCE = new KeybindCallbacks();
|
||||
|
||||
private Vector<Entity> villagersInRange = new Vector<Entity>();
|
||||
|
||||
public static KeybindCallbacks getInstance() {
|
||||
return INSTANCE;
|
||||
}
|
||||
@@ -65,4 +72,40 @@ public class KeybindCallbacks implements IHotkeyCallback {
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClientTick(MinecraftClient mc) {
|
||||
if (this.functionalityEnabled() == false || mc.player == null) {
|
||||
return;
|
||||
}
|
||||
mc.inGameHud.getChatHud().addToMessageHistory("here");
|
||||
|
||||
if (GuiUtils.getCurrentScreen() instanceof HandledScreen) {
|
||||
return;
|
||||
}
|
||||
|
||||
boolean found = false;
|
||||
|
||||
Vector<Entity> newVillagersInRange = new Vector<Entity>(villagersInRange);
|
||||
|
||||
for (Entity entity : mc.player.clientWorld.getEntities()) {
|
||||
if (entity instanceof VillagerEntity) {
|
||||
if (entity.getPos().distanceTo(mc.player.getPos()) < 3) {
|
||||
if (found == false) {
|
||||
if (newVillagersInRange.contains(entity) == false) {
|
||||
found = true;
|
||||
newVillagersInRange.add(entity);
|
||||
mc.interactionManager.interactEntity(mc.player, entity, Hand.MAIN_HAND);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
for (Entity entity : villagersInRange) {
|
||||
if ((entity.getPos().distanceTo(mc.player.getPos()) < 4) == false) {
|
||||
newVillagersInRange.remove(entity);
|
||||
}
|
||||
}
|
||||
villagersInRange = newVillagersInRange;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user