diff --git a/src/main/java/tudbut/mod/client/yac/Yac.java b/src/main/java/tudbut/mod/client/yac/YAC.java similarity index 74% rename from src/main/java/tudbut/mod/client/yac/Yac.java rename to src/main/java/tudbut/mod/client/yac/YAC.java index a564a02..04b100d 100644 --- a/src/main/java/tudbut/mod/client/yac/Yac.java +++ b/src/main/java/tudbut/mod/client/yac/YAC.java @@ -19,21 +19,21 @@ import java.io.IOException; import java.util.Map; -@Mod(modid = Yac.MODID, name = Yac.NAME, version = Yac.VERSION) -public class Yac { +@Mod(modid = YAC.MODID, name = YAC.NAME, version = YAC.VERSION) +public class YAC { public static final String MODID = "yac"; public static final String NAME = "YAC Client"; - public static final String VERSION = "vB0.2.5a"; + public static final String VERSION = "vB1.0.0a"; - public static Module[] modules; + public static Module[] modules ; public static EntityPlayerSP player; public static Minecraft mc = Minecraft.getMinecraft(); public static FileRW file; public static Map cfg; public static String prefix = ","; - + public static Logger logger; - + @EventHandler public void preInit(FMLPreInitializationEvent event) { logger = event.getModLog(); @@ -44,12 +44,12 @@ public void preInit(FMLPreInitializationEvent event) { e.printStackTrace(); } } - + @EventHandler public void init(FMLInitializationEvent event) { - logger.info("YAC by TudbuT, public version"); + logger.info("YAC by TudbuT"); ThreadManager.run(() -> { - JOptionPane.showMessageDialog(null, "YAC by TudbuT, public version"); + JOptionPane.showMessageDialog(null, "YAC by TudbuT"); }); player = Minecraft.getMinecraft().player; try { @@ -58,34 +58,48 @@ public void init(FMLInitializationEvent event) { catch (Exception e) { e.printStackTrace(); } - modules = new Module[]{ + modules = new Module[] { new AutoTotem(), new TPAParty(), + new SafeTotem(), new Prefix(), - new ClickGUI(), new Team(), - new AutoConfig(), new TPATools(), - new Trap() + new ChatSuffix(), + new AutoConfig(), + new ChatColor(), + new Trap(), + new LeavePos(), + new ClickGUI(), }; + + for (Module module : modules) { + module.cfg = Utils.stringToMap(module.saveConfig()); + } + MinecraftForge.EVENT_BUS.register(new FMLEventHandler()); for (int i = 0; i < modules.length; i++) { - logger.info(modules[i].toString()); - modules[i].saveConfig(); - if (cfg.containsKey(modules[i].toString())) { - modules[i].loadConfig(Utils.stringToMap(cfg.get(modules[i].getClass().getSimpleName()))); + try { + logger.info(modules[i].toString()); + modules[i].saveConfig(); + if (cfg.containsKey(modules[i].toString())) { + modules[i].loadConfig(Utils.stringToMap(cfg.get(modules[i].getClass().getSimpleName()))); + } + } catch (Exception e) { + logger.warn("Couldn't load config of module " + modules[i].toString() + "!"); + logger.warn(e); } } prefix = cfg.getOrDefault("prefix", ","); - + try { Thread.sleep(2000); } catch (InterruptedException e) { e.printStackTrace(); } - + ThreadManager.run(() -> { while (true) { try { @@ -94,7 +108,7 @@ public void init(FMLInitializationEvent event) { cfg.put(modules[i].getClass().getSimpleName(), modules[i].saveConfig()); } cfg.put("prefix", prefix); - + file.setContent(Utils.mapToString(cfg)); } catch (IOException e) { diff --git a/src/main/java/tudbut/mod/client/yac/events/FMLEventHandler.java b/src/main/java/tudbut/mod/client/yac/events/FMLEventHandler.java index 93e135b..fb16fc0 100644 --- a/src/main/java/tudbut/mod/client/yac/events/FMLEventHandler.java +++ b/src/main/java/tudbut/mod/client/yac/events/FMLEventHandler.java @@ -2,138 +2,114 @@ import net.minecraft.client.Minecraft; import net.minecraft.client.entity.EntityPlayerSP; +import net.minecraft.entity.player.EntityPlayer; import net.minecraftforge.client.event.ClientChatEvent; import net.minecraftforge.client.event.ClientChatReceivedEvent; import net.minecraftforge.event.entity.EntityJoinWorldEvent; +import net.minecraftforge.event.entity.living.LivingDeathEvent; import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; import net.minecraftforge.fml.common.gameevent.TickEvent; -import net.minecraftforge.fml.common.network.FMLNetworkEvent; -import tudbut.mod.client.yac.Yac; +import tudbut.mod.client.yac.YAC; +import tudbut.mod.client.yac.mods.ChatColor; +import tudbut.mod.client.yac.mods.ChatSuffix; +import tudbut.mod.client.yac.mods.TPAParty; import tudbut.mod.client.yac.utils.ChatUtils; -import java.io.BufferedReader; -import java.io.IOException; -import java.io.InputStream; -import java.io.InputStreamReader; -import java.net.URL; - public class FMLEventHandler { private int chatHelper = 0; @SubscribeEvent public void onChat(ClientChatEvent event) { - if (event.getOriginalMessage().startsWith(Yac.prefix)) { + if(event.getOriginalMessage().startsWith(YAC.prefix)) { + event.setCanceled(true); ChatUtils.print("Blocked message"); ChatUtils.history(event.getOriginalMessage()); - String s = event.getOriginalMessage().substring(Yac.prefix.length()); + String s = event.getOriginalMessage().substring(YAC.prefix.length()); try { if (s.startsWith("t ")) { - for (int i = 0; i < Yac.modules.length; i++) { - if (Yac.modules[i].getClass().getSimpleName().equalsIgnoreCase(s.substring("t ".length()))) { - ChatUtils.print(String.valueOf(!Yac.modules[i].enabled)); + for (int i = 0; i < YAC.modules.length; i++) { + if (YAC.modules[i].getClass().getSimpleName().equalsIgnoreCase(s.substring("t ".length()))) { + ChatUtils.print(String.valueOf(!YAC.modules[i].enabled)); - if (Yac.modules[i].enabled = !Yac.modules[i].enabled) - Yac.modules[i].onEnable(); + if(YAC.modules[i].enabled = !YAC.modules[i].enabled) + YAC.modules[i].onEnable(); else - Yac.modules[i].onDisable(); + YAC.modules[i].onDisable(); } } } if (s.startsWith("say ")) { - Yac.player.sendChatMessage(s.substring("say ".length())); + YAC.player.sendChatMessage(s.substring("say ".length())); ChatUtils.history(event.getOriginalMessage()); } - - for (int i = 0; i < Yac.modules.length; i++) { - if (Yac.modules[i].enabled) - if (s.toLowerCase().startsWith(Yac.modules[i].getClass().getSimpleName().toLowerCase())) { - String args = s.substring(Yac.modules[i].getClass().getSimpleName().length() + 1); - Yac.modules[i].onChat(args, args.split(" ")); + + for (int i = 0; i < YAC.modules.length; i++) { + if(YAC.modules[i].enabled) + if (s.toLowerCase().startsWith(YAC.modules[i].getClass().getSimpleName().toLowerCase())) { + String args = s.substring(YAC.modules[i].getClass().getSimpleName().length() + 1); + YAC.modules[i].onChat(args, args.split(" ")); } } - } - catch (Exception e) { + } catch (Exception e) { ChatUtils.print("Command failed!"); } - - } else if (!event.getOriginalMessage().startsWith("/") && !event.getOriginalMessage().startsWith(".") && !event.getOriginalMessage().startsWith("#")) { + + } + else if(!event.getOriginalMessage().startsWith("/") && !event.getOriginalMessage().startsWith(".") && !event.getOriginalMessage().startsWith("#")) { event.setCanceled(true); - Yac.player.sendChatMessage(">" + event.getMessage() + (chatHelper == 0 ? " ›YAC‹" : "")); + YAC.player.sendChatMessage(ChatColor.getInstance().get() + event.getMessage() + (chatHelper == 0 && ChatSuffix.getInstance().enabled ? " ›YAC‹" : "")); chatHelper++; - if (chatHelper == 6) + if(chatHelper == 6) chatHelper = 0; ChatUtils.history(event.getOriginalMessage()); } } - - @SubscribeEvent - public void onJoin(FMLNetworkEvent.ClientConnectedToServerEvent event) { - try { - URL updateCheckURL = new URL("https://raw.githubusercontent.com/TudbuT/yacpub/master/version.txt"); - InputStream stream = updateCheckURL.openConnection().getInputStream(); - BufferedReader reader = new BufferedReader(new InputStreamReader(stream)); - - String s; - StringBuilder builder = new StringBuilder(); - while ((s = reader.readLine()) != null) { - builder.append(s); - } - - s = builder.toString(); - if (!s.equals(Yac.VERSION)) { - ChatUtils.print( - "§a§lA new YAC version was found! Current: " + - Yac.VERSION + - ", New: " + - s + - "! Please consider updating at " + - "https://github.com/TudbuT/yacpub/releases/tag/" + - s - ); - } - } - catch (IOException e) { - ChatUtils.print("Unable to check for a new version!"); - e.printStackTrace(); - } - } - @SubscribeEvent public void onServerChat(ClientChatReceivedEvent event) { - if (event.getMessage().getUnformattedText().startsWith("BayMax") && event.getMessage().getUnformattedText().contains("Please type '")) { + if(event.getMessage().getUnformattedText().startsWith("BayMax") && event.getMessage().getUnformattedText().contains("Please type '")) { String key = event.getMessage().getUnformattedText().substring("BayMax _ Please type '".length(), "BayMax _ Please type '".length() + 4); - Yac.player.sendChatMessage(key); + YAC.player.sendChatMessage(key); ChatUtils.print("Auto-solved"); } - for (int i = 0; i < Yac.modules.length; i++) { - if (Yac.modules[i].enabled) - Yac.modules[i].onServerChat(event.getMessage().getUnformattedText(), event.getMessage().getFormattedText()); + for (int i = 0; i < YAC.modules.length; i++) { + if(YAC.modules[i].enabled) + YAC.modules[i].onServerChat(event.getMessage().getUnformattedText(), event.getMessage().getFormattedText()); } } @SubscribeEvent public void onJoin(EntityJoinWorldEvent event) { - Yac.player = Minecraft.getMinecraft().player; + YAC.player = Minecraft.getMinecraft().player; + } + + @SubscribeEvent + public void onDeath(LivingDeathEvent event) { + try { + if (event.getEntity().getName().equals(YAC.player.getName()) && event.getEntity() instanceof EntityPlayer) { + TPAParty.getInstance().enabled = false; + TPAParty.getInstance().onDisable(); + YAC.player = Minecraft.getMinecraft().player; + } + } catch (Exception ignore) { } } @SubscribeEvent public void onTick(TickEvent event) { - EntityPlayerSP player = Yac.player; - if (player == null) + EntityPlayerSP player = YAC.player; + if(player == null) return; - for (int i = 0; i < Yac.modules.length; i++) { - if (Yac.modules[i].enabled) + for (int i = 0; i < YAC.modules.length; i++) { + if(YAC.modules[i].enabled) try { - Yac.modules[i].onTick(); - } - catch (Exception ignore) {} - Yac.modules[i].onEveryTick(); + YAC.modules[i].onTick(); + } catch (Exception ignore) {} + YAC.modules[i].onEveryTick(); } } } diff --git a/src/main/java/tudbut/mod/client/yac/gui/GuiYAC.java b/src/main/java/tudbut/mod/client/yac/gui/GuiYAC.java index d742970..c69d646 100644 --- a/src/main/java/tudbut/mod/client/yac/gui/GuiYAC.java +++ b/src/main/java/tudbut/mod/client/yac/gui/GuiYAC.java @@ -1,8 +1,7 @@ package tudbut.mod.client.yac.gui; -import net.minecraft.client.gui.GuiButton; import net.minecraft.client.gui.GuiScreen; -import tudbut.mod.client.yac.Yac; +import tudbut.mod.client.yac.YAC; import tudbut.mod.client.yac.mods.ClickGUI; import tudbut.mod.client.yac.utils.Module; @@ -20,7 +19,7 @@ public class GuiYAC extends GuiScreen { public GuiYAC(GuiScreen parentScreenIn) { - this.mc = Yac.mc; + this.mc = YAC.mc; this.parentGuiScreen = parentScreenIn; } @@ -69,20 +68,20 @@ public void updateScreen() { } private void resetButtons() { - for (int x = 0; x < Yac.modules.length; x++) { - for (int y = 0; y < 5 && y + (x * 5) < Yac.modules.length; y++) { + for (int x = 0; x < YAC.modules.length; x++) { + for (int y = 0; y < 5 && y + (x * 5) < YAC.modules.length; y++) { int r = y + (x * 5); Button b = new Button( - 10 + (210 * x), 10 + (y * 40), Yac.modules[r].getClass().getSimpleName() + ": " + Yac.modules[r].enabled, + 10 + (210 * x), 10 + (y * 40), YAC.modules[r].getClass().getSimpleName() + ": " + YAC.modules[r].enabled, (text) -> { - if(Yac.modules[r].enabled = !Yac.modules[r].enabled) - Yac.modules[r].onEnable(); + if(YAC.modules[r].enabled = !YAC.modules[r].enabled) + YAC.modules[r].onEnable(); else - Yac.modules[r].onDisable(); - - }, Yac.modules[r] + YAC.modules[r].onDisable(); + + }, YAC.modules[r] ); - + buttons[r] = b; } } @@ -100,10 +99,10 @@ private void updateButtons() { if(buttons == null) resetButtons(); } - for (int i = 0; i < Yac.modules.length; i++) { + for (int i = 0; i < YAC.modules.length; i++) { if(buttons[i] == null) return; - buttons[i].text.set(Yac.modules[i].getClass().getSimpleName() + ": " + Yac.modules[i].enabled); + buttons[i].text.set(YAC.modules[i].getClass().getSimpleName() + ": " + YAC.modules[i].enabled); } } @@ -113,10 +112,10 @@ private void updateButtons() { protected void mouseClicked(int mouseX, int mouseY, int mouseButton) throws IOException { super.mouseClicked(mouseX, mouseY, mouseButton); - + cx = mouseX; cy = mouseY; - + for (Button button : buttons) { if(button != null) if(button.mouseClicked(mouseX, mouseY, mouseButton)) @@ -136,8 +135,8 @@ protected void mouseClickMove(int mouseX, int mouseY, int clickedMouseButton, lo protected void mouseReleased(int mouseX, int mouseY, int state) { super.mouseReleased(mouseX, mouseY, state); - - + + for (Button button : buttons) { if(button != null) button.mouseReleased(); @@ -152,12 +151,7 @@ public void drawScreen(int mouseX, int mouseY, float partialTicks) updateButtons(); this.drawDefaultBackground(); - //this.drawCenteredString(this.fontRenderer, this.screenTitle, this.width / 2, 5, 16777215); - - //for (int i = 0; i < Yac.modules.length; i++) { - //drawRect(10, 10 + (i * 40), 10 + 200, 10 + (i * 40) + 30, 0x8000ff00); - //} - + for (int i = 0; i < buttons.length; i++) { if(buttons[i] != null) buttons[i].draw(this); @@ -198,10 +192,10 @@ public Button(int x, int y, String text, ButtonClickEvent event, Module module) public void draw(GuiYAC gui) { drawRect(x, y, x + 200, y + 30, color); gui.drawString(gui.fontRenderer, text.get(), x + 10, y + 11, 0xffffffff); - + if(module != null && module.enabled) { subButtons = module.subButtons.toArray(new Button[0]); - + for (int i = 0; i < subButtons.length; i++) { Button b = subButtons[i]; b.x = x; @@ -209,7 +203,7 @@ public void draw(GuiYAC gui) { b.color = 0x4000ff00; b.draw(gui); } - + } } @@ -224,7 +218,7 @@ public boolean mouseClicked(int clickX, int clickY, int button) { } if(module != null && module.enabled) { subButtons = module.subButtons.toArray(new Button[0]); - + for (int i = 0; i < subButtons.length; i++) { if(subButtons[i].mouseClicked(clickX, clickY, button)) return true; @@ -232,19 +226,19 @@ public boolean mouseClicked(int clickX, int clickY, int button) { } return false; } - + public void mouseReleased() { mouseDown = false; if(module != null && module.enabled) { subButtons = module.subButtons.toArray(new Button[0]); - + for (int i = 0; i < subButtons.length; i++) { subButtons[i].mouseReleased(); } } } - + protected void click(int button) { if(button == 0) event.run(text); diff --git a/src/main/java/tudbut/mod/client/yac/mods/AutoConfig.java b/src/main/java/tudbut/mod/client/yac/mods/AutoConfig.java index 1e9f35a..e0ac424 100644 --- a/src/main/java/tudbut/mod/client/yac/mods/AutoConfig.java +++ b/src/main/java/tudbut/mod/client/yac/mods/AutoConfig.java @@ -5,8 +5,6 @@ import tudbut.mod.client.yac.utils.Module; import tudbut.mod.client.yac.utils.ThreadManager; -import java.io.Serializable; - public class AutoConfig extends Module { private boolean mode = false; @@ -18,9 +16,26 @@ public class AutoConfig extends Module { private Server server = Server._8b8t; private enum Server { - _8b8t("8b8t.xyz", true , true , true ), - _5b5t("5b5t.net", false, false, false), - _0t0t("0b0t.org", false, false, true ), + _8b8t + ("8b8t.xyz", + true , true , true ), + + _5b5t + ("5b5t.net", + false, false, false), + + _0t0t + ("0b0t.org", + false, false, true ), + + _2b2t + ("2b2t.org", + false, false, false), + + crystalpvp + ("crystalpvp.cc", + false, false, false), + ; String name; @@ -97,7 +112,7 @@ public void updateButtons() { if(!tpa) TPAParty.getInstance().enabled = false; TPATools.getInstance().enabled = tpa; - + ThreadManager.run(() -> { text.set("Done"); try { @@ -141,5 +156,7 @@ public void loadConfig() { tpa = Boolean.parseBoolean(cfg.get("tpa")); server = Server.values()[Integer.parseInt(cfg.get("server"))]; + + updateButtons(); } } diff --git a/src/main/java/tudbut/mod/client/yac/mods/AutoTotem.java b/src/main/java/tudbut/mod/client/yac/mods/AutoTotem.java index 4d324e6..0d970cf 100644 --- a/src/main/java/tudbut/mod/client/yac/mods/AutoTotem.java +++ b/src/main/java/tudbut/mod/client/yac/mods/AutoTotem.java @@ -4,7 +4,7 @@ import net.minecraft.init.Items; import net.minecraft.item.ItemStack; import org.lwjgl.input.Keyboard; -import tudbut.mod.client.yac.Yac; +import tudbut.mod.client.yac.YAC; import tudbut.mod.client.yac.gui.GuiYAC; import tudbut.mod.client.yac.utils.ChatUtils; import tudbut.mod.client.yac.utils.InventoryUtils; @@ -13,19 +13,28 @@ public class AutoTotem extends Module { static AutoTotem instance; - public int orig_min_count = 0; + + public static AutoTotem getInstance() { + return instance; + } + + public AutoTotem() { + instance = this; + } + public int min_count = 0; + public int orig_min_count = 0; private boolean isRestockingAfterRespawn = false; { subButtons.add(new GuiYAC.Button("Count: " + orig_min_count, text -> { - if (Keyboard.isKeyDown(Keyboard.KEY_LSHIFT)) + if(Keyboard.isKeyDown(Keyboard.KEY_LSHIFT)) orig_min_count = min_count = orig_min_count - 1; else orig_min_count = min_count = orig_min_count + 1; - if (orig_min_count > 12) + if(orig_min_count > 12) orig_min_count = min_count = 0; - if (orig_min_count < 0) + if(orig_min_count < 0) orig_min_count = min_count = 12; text.set("Count: " + orig_min_count); })); @@ -34,14 +43,6 @@ public class AutoTotem extends Module { }, null)); } - public AutoTotem() { - instance = this; - } - - public static AutoTotem getInstance() { - return instance; - } - public void updateButtons() { subButtons.get(0).text.set("Count: " + orig_min_count); subButtons.get(1).text.set("Actual count: " + min_count); @@ -50,59 +51,62 @@ public void updateButtons() { @Override public void onTick() { - EntityPlayerSP player = Yac.player; + EntityPlayerSP player = YAC.player; updateTotCount(); - - if (min_count < 0) { + + if(min_count < 0) { min_count = 0; } updateButtons(); - if (Yac.mc.currentScreen == null) + if(YAC.mc.currentScreen == null) isRestockingAfterRespawn = false; - if (isRestockingAfterRespawn() || isRestockingAfterRespawn) + if((isRestockingAfterRespawn || isRestockingAfterRespawn()) && YAC.mc.currentScreen != null) { + System.out.println(isRestockingAfterRespawn); return; + } ItemStack stack = player.getHeldItemOffhand(); - if (stack.getCount() <= min_count) { + if(stack.getCount() <= min_count) { + Integer slot = InventoryUtils.getSlotWithItem( player.inventoryContainer, Items.TOTEM_OF_UNDYING, - new int[]{InventoryUtils.OFFHAND_SLOT}, + new int[] {InventoryUtils.OFFHAND_SLOT}, min_count + 1, 64 ); - if (slot == null) + if(slot == null) return; InventoryUtils.inventorySwap(slot, InventoryUtils.OFFHAND_SLOT); } } public boolean isRestockingAfterRespawn() { - EntityPlayerSP player = Yac.player; + EntityPlayerSP player = YAC.player; Integer slot0 = InventoryUtils.getSlotWithItem( player.inventoryContainer, Items.TOTEM_OF_UNDYING, - new int[]{}, + new int[] {}, 1, 64 ); - if (slot0 == null) { + if(slot0 == null) { isRestockingAfterRespawn = true; return true; } Integer slot1 = InventoryUtils.getSlotWithItem( player.inventoryContainer, Items.TOTEM_OF_UNDYING, - new int[]{slot0}, + new int[] {slot0}, 1, 64 ); - if (slot1 == null) { + if(slot1 == null) { isRestockingAfterRespawn = true; return true; } @@ -111,12 +115,11 @@ public boolean isRestockingAfterRespawn() { @Override public void onChat(String s, String[] args) { - if (s.startsWith("count ")) + if(s.startsWith("count ")) try { orig_min_count = min_count = Integer.parseInt(s.substring("count ".length())); ChatUtils.print("Set!"); - } - catch (Exception e) { + } catch (Exception e) { ChatUtils.print("ERROR: NaN"); } updateButtons(); @@ -124,7 +127,7 @@ public void onChat(String s, String[] args) { @Override public void onEnable() { - Yac.modules[2].enabled = false; + YAC.modules[2].enabled = false; } @Override @@ -139,14 +142,14 @@ public void updateConfig() { } public void updateTotCount() { - EntityPlayerSP player = Yac.player; + EntityPlayerSP player = YAC.player; - if ( + if( InventoryUtils.getSlotWithItem( player.inventoryContainer, Items.TOTEM_OF_UNDYING, - new int[]{InventoryUtils.OFFHAND_SLOT}, + new int[] {InventoryUtils.OFFHAND_SLOT}, orig_min_count + 1, 64 ) != null @@ -156,12 +159,12 @@ public void updateTotCount() { Integer i = InventoryUtils.getSlotWithItem( player.inventoryContainer, Items.TOTEM_OF_UNDYING, - new int[]{InventoryUtils.OFFHAND_SLOT}, + new int[] {InventoryUtils.OFFHAND_SLOT}, min_count + 1, 64 ); - while (i == null) { - if (min_count < 0) { + while(i == null) { + if(min_count < 0) { min_count = 0; break; } @@ -169,12 +172,12 @@ public void updateTotCount() { i = InventoryUtils.getSlotWithItem( player.inventoryContainer, Items.TOTEM_OF_UNDYING, - new int[]{InventoryUtils.OFFHAND_SLOT}, + new int[] {InventoryUtils.OFFHAND_SLOT}, min_count + 1, 64 ); } - if (min_count < 0) { + if(min_count < 0) { min_count = 0; } } diff --git a/src/main/java/tudbut/mod/client/yac/mods/ChatColor.java b/src/main/java/tudbut/mod/client/yac/mods/ChatColor.java new file mode 100644 index 0000000..49595a1 --- /dev/null +++ b/src/main/java/tudbut/mod/client/yac/mods/ChatColor.java @@ -0,0 +1,53 @@ +package tudbut.mod.client.yac.mods; + +import tudbut.mod.client.yac.gui.GuiYAC; +import tudbut.mod.client.yac.utils.Module; + +public class ChatColor extends Module { + + private boolean useSpace = false; + + static ChatColor instance; + + public ChatColor() { + instance = this; + } + + public static ChatColor getInstance() { + return instance; + } + + public String get() { + return (enabled ? (useSpace ? "> " : ">") : ""); + } + + public void updateButtons() { + subButtons.clear(); + subButtons.add(new GuiYAC.Button("Add space: " + useSpace, text -> { + useSpace = !useSpace; + text.set("Add space: " + useSpace); + })); + } + + @Override + public void onTick() { + + } + + @Override + public void onChat(String s, String[] args) { + + } + + @Override + public void updateConfig() { + cfg.put("space", useSpace + ""); + } + + @Override + public void loadConfig() { + useSpace = Boolean.parseBoolean(cfg.get("space")); + + updateButtons(); + } +} diff --git a/src/main/java/tudbut/mod/client/yac/mods/ChatSuffix.java b/src/main/java/tudbut/mod/client/yac/mods/ChatSuffix.java new file mode 100644 index 0000000..874e545 --- /dev/null +++ b/src/main/java/tudbut/mod/client/yac/mods/ChatSuffix.java @@ -0,0 +1,30 @@ +package tudbut.mod.client.yac.mods; + +import tudbut.mod.client.yac.utils.Module; + +public class ChatSuffix extends Module { + public static ChatSuffix getInstance() { + return instance; + } + + private static ChatSuffix instance; + + public ChatSuffix() { + instance = this; + } + + @Override + public boolean defaultEnabled() { + return true; + } + + @Override + public void onTick() { + + } + + @Override + public void onChat(String s, String[] args) { + + } +} diff --git a/src/main/java/tudbut/mod/client/yac/mods/ClickGUI.java b/src/main/java/tudbut/mod/client/yac/mods/ClickGUI.java index 7b22476..6f7f038 100644 --- a/src/main/java/tudbut/mod/client/yac/mods/ClickGUI.java +++ b/src/main/java/tudbut/mod/client/yac/mods/ClickGUI.java @@ -1,7 +1,7 @@ package tudbut.mod.client.yac.mods; import org.lwjgl.input.Keyboard; -import tudbut.mod.client.yac.Yac; +import tudbut.mod.client.yac.YAC; import tudbut.mod.client.yac.gui.GuiYAC; import tudbut.mod.client.yac.utils.ChatUtils; import tudbut.mod.client.yac.utils.Module; @@ -11,12 +11,25 @@ public class ClickGUI extends Module { static ClickGUI instance; + public static ClickGUI getInstance() { + return instance; + } + public ClickGUI() { instance = this; } - public static ClickGUI getInstance() { - return instance; + { + subButtons.add(new GuiYAC.Button("Reset layout", text -> { + enabled = false; + onDisable(); + for (Module module : YAC.modules) { + module.clickGuiX = null; + module.clickGuiY = null; + } + enabled = true; + onEnable(); + })); } @Override @@ -29,14 +42,14 @@ public void onEnable() { e.printStackTrace(); } ChatUtils.print("Showing ClickGUI"); - Yac.mc.displayGuiScreen(new GuiYAC(Yac.mc.currentScreen)); + YAC.mc.displayGuiScreen(new GuiYAC(YAC.mc.currentScreen)); }); } @Override public void onDisable() { - if (Yac.mc.currentScreen != null && Yac.mc.currentScreen.getClass() == GuiYAC.class) - Yac.mc.displayGuiScreen(null); + if (YAC.mc.currentScreen != null && YAC.mc.currentScreen.getClass() == GuiYAC.class) + YAC.mc.displayGuiScreen(null); } @Override @@ -45,8 +58,8 @@ public void onTick() { @Override public void onEveryTick() { - if (Keyboard.isKeyDown(Keyboard.KEY_COMMA) && Yac.mc.currentScreen == null) { - if (!enabled) { + if(Keyboard.isKeyDown(Keyboard.KEY_COMMA) && YAC.mc.currentScreen == null) { + if(!enabled) { enabled = true; onEnable(); } diff --git a/src/main/java/tudbut/mod/client/yac/mods/LeavePos.java b/src/main/java/tudbut/mod/client/yac/mods/LeavePos.java new file mode 100644 index 0000000..972c9b3 --- /dev/null +++ b/src/main/java/tudbut/mod/client/yac/mods/LeavePos.java @@ -0,0 +1,78 @@ +package tudbut.mod.client.yac.mods; + +import net.minecraft.client.network.NetworkPlayerInfo; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.util.math.Vec3d; +import tudbut.mod.client.yac.YAC; +import tudbut.mod.client.yac.utils.ChatUtils; +import tudbut.mod.client.yac.utils.Module; + +public class LeavePos extends Module { + NetworkPlayerInfo[] playersLastTick; + EntityPlayer[] visiblePlayersLastTick; + + @Override + public void onTick() { + if(YAC.mc.getConnection() == null) + return; + if(playersLastTick == null) { + playersLastTick = YAC.mc.getConnection().getPlayerInfoMap().toArray(new NetworkPlayerInfo[0]); + } + EntityPlayer[] visiblePlayersThisTick = YAC.mc.world.playerEntities.toArray(new EntityPlayer[0]); + NetworkPlayerInfo[] playersThisTick = YAC.mc.getConnection().getPlayerInfoMap().toArray(new NetworkPlayerInfo[0]); + + try { + + if (playersThisTick.length < playersLastTick.length) { + for (int i = 0; i < playersLastTick.length; i++) { + try { + boolean b = true; + String name = playersLastTick[i].getGameProfile().getName(); + for (int j = 0; j < playersThisTick.length; j++) { + if(playersThisTick[j].getGameProfile().getName().equals(name)) + b = false; + } + if(b) { + ChatUtils.print(name + " left!"); + for (int j = 0; j < visiblePlayersLastTick.length; j++) { + if (visiblePlayersLastTick[j].getGameProfile().getName().equals(name)) { + Vec3d vec = visiblePlayersLastTick[j].getPositionVector(); + ChatUtils.print( + "§c§l§c§lThe player §r" + + visiblePlayersLastTick[j].getName() + + "§c§l left at " + (int) (vec.x * 100) / 100 + + "!" + ); + } + } + } + } catch (Exception ignore) { } + } + } + + if (playersThisTick.length > playersLastTick.length) { + for (int i = 0; i < playersThisTick.length; i++) { + try { + boolean b = true; + String name = playersThisTick[i].getGameProfile().getName(); + for (int j = 0; j < playersLastTick.length; j++) { + if(playersLastTick[j].getGameProfile().getName().equals(name)) + b = false; + } + if(b) { + ChatUtils.print(name + " joined!"); + } + } catch (Exception ignore) { } + } + } + } catch (Exception ignore) { } + + playersLastTick = playersThisTick; + visiblePlayersLastTick = visiblePlayersThisTick; + } + + @Override + public void onChat(String s, String[] args) { + + } +} diff --git a/src/main/java/tudbut/mod/client/yac/mods/Prefix.java b/src/main/java/tudbut/mod/client/yac/mods/Prefix.java index 0af2cfc..0af77ee 100644 --- a/src/main/java/tudbut/mod/client/yac/mods/Prefix.java +++ b/src/main/java/tudbut/mod/client/yac/mods/Prefix.java @@ -1,5 +1,6 @@ package tudbut.mod.client.yac.mods; +import tudbut.mod.client.yac.YAC; import tudbut.mod.client.yac.utils.Module; public class Prefix extends Module { @@ -9,11 +10,15 @@ public class Prefix extends Module { @Override public void onTick() { + } + @Override + public void onEveryTick() { + enabled = true; } @Override public void onChat(String s, String[] args) { - + YAC.prefix = s; } } diff --git a/src/main/java/tudbut/mod/client/yac/mods/SafeTotem.java b/src/main/java/tudbut/mod/client/yac/mods/SafeTotem.java new file mode 100644 index 0000000..187f29d --- /dev/null +++ b/src/main/java/tudbut/mod/client/yac/mods/SafeTotem.java @@ -0,0 +1,81 @@ +package tudbut.mod.client.yac.mods; + +import net.minecraft.client.entity.EntityPlayerSP; +import net.minecraft.client.gui.*; +import net.minecraft.client.gui.inventory.GuiInventory; +import net.minecraft.init.Items; +import net.minecraft.item.ItemStack; +import tudbut.mod.client.yac.YAC; +import tudbut.mod.client.yac.gui.GuiYAC; +import tudbut.mod.client.yac.utils.InventoryUtils; +import tudbut.mod.client.yac.utils.Module; +import tudbut.mod.client.yac.utils.ThreadManager; + +public class SafeTotem extends Module { + + @Override + public void onTick() { + EntityPlayerSP player = YAC.player; + + ((AutoTotem) YAC.modules[0]).updateTotCount(); + + ItemStack stack = player.getHeldItemOffhand(); + if(stack.getCount() <= ((AutoTotem) YAC.modules[0]).min_count) { + Integer slot = InventoryUtils.getSlotWithItem( + player.inventoryContainer, + Items.TOTEM_OF_UNDYING, + new int[] {InventoryUtils.OFFHAND_SLOT}, + ((AutoTotem) YAC.modules[0]).min_count + 1, + 64 + ); + if(slot == null) { + ((AutoTotem) YAC.modules[0]).min_count--; + if(((AutoTotem) YAC.modules[0]).min_count >= 0) + onTick(); + return; + } + ThreadManager.run(() -> safeInventorySwap(slot, InventoryUtils.OFFHAND_SLOT)); + } + } + + @Override + public void onEnable() { + YAC.modules[0].enabled = false; + } + + private static boolean swapping = false; + public static void safeInventorySwap(int from, int to) { + if(swapping) + return; + + swapping = true; + ThreadManager.run(() -> { + try { + int bSlot = YAC.player.inventory.currentItem; + + GuiScreen screen = YAC.mc.currentScreen; + if(screen != null && screen.getClass() != GuiChat.class && screen.getClass() != GuiInventory.class && screen.getClass().getComponentType() != GuiNewChat.class.getComponentType() && screen.getClass() != GuiIngameMenu.class && screen.getClass() != GuiYAC.class) { + Thread.sleep(200); + YAC.player.closeScreen(); + Thread.sleep(300); + } + //Thread.sleep(10); + InventoryUtils.swap(from, bSlot); + //Thread.sleep(100); + InventoryUtils.swap(to, bSlot); + //Thread.sleep(200); + InventoryUtils.swap(from, bSlot); + //Thread.sleep(200); + YAC.mc.displayGuiScreen(screen); + } + catch (InterruptedException e) { + e.printStackTrace(); + } + swapping = false; + }); + } + + @Override + public void onChat(String s, String[] args) { + } +} diff --git a/src/main/java/tudbut/mod/client/yac/mods/TPAParty.java b/src/main/java/tudbut/mod/client/yac/mods/TPAParty.java index ae32ebd..da2ad3d 100644 --- a/src/main/java/tudbut/mod/client/yac/mods/TPAParty.java +++ b/src/main/java/tudbut/mod/client/yac/mods/TPAParty.java @@ -1,20 +1,20 @@ package tudbut.mod.client.yac.mods; -import tudbut.mod.client.yac.Yac; +import tudbut.mod.client.yac.YAC; import tudbut.mod.client.yac.utils.Module; public class TPAParty extends Module { static TPAParty instance; - public TPAParty() { - instance = this; - } - public static TPAParty getInstance() { return instance; } + public TPAParty() { + instance = this; + } + @Override public void onTick() { @@ -27,8 +27,8 @@ public void onChat(String s, String[] args) { @Override public void onServerChat(String s, String formatted) { - if (s.contains("has requested to teleport to you.") && !s.startsWith("<")) { - Yac.player.sendChatMessage("/tpaccept"); + if(s.contains("has requested to teleport to you.") && !s.startsWith("<")) { + YAC.player.sendChatMessage("/tpaccept"); } } } diff --git a/src/main/java/tudbut/mod/client/yac/mods/TPATools.java b/src/main/java/tudbut/mod/client/yac/mods/TPATools.java index 0b18bf9..516bbfa 100644 --- a/src/main/java/tudbut/mod/client/yac/mods/TPATools.java +++ b/src/main/java/tudbut/mod/client/yac/mods/TPATools.java @@ -2,7 +2,7 @@ import net.minecraft.client.network.NetworkPlayerInfo; import org.lwjgl.input.Keyboard; -import tudbut.mod.client.yac.Yac; +import tudbut.mod.client.yac.YAC; import tudbut.mod.client.yac.gui.GuiYAC; import tudbut.mod.client.yac.utils.ChatUtils; import tudbut.mod.client.yac.utils.Module; @@ -11,10 +11,19 @@ import java.util.Objects; public class TPATools extends Module { - static TPATools instance; private int delay = 1000; private boolean stop = false; + static TPATools instance; + + public static TPATools getInstance() { + return instance; + } + + public TPATools() { + instance = this; + } + { subButtons.add(new GuiYAC.Button("Send /tpa to everyone", text -> { onChat("tpa", null); @@ -23,14 +32,14 @@ public class TPATools extends Module { onChat("tpahere", null); })); subButtons.add(new GuiYAC.Button("Delay: " + delay, text -> { - if (Keyboard.isKeyDown(Keyboard.KEY_LSHIFT)) + if(Keyboard.isKeyDown(Keyboard.KEY_LSHIFT)) delay -= 1000; else delay += 1000; - if (delay > 5000) + if(delay > 5000) delay = 1000; - if (delay < 1000) + if(delay < 1000) delay = 5000; text.set("Delay: " + delay); })); @@ -51,14 +60,6 @@ public class TPATools extends Module { })); } - public TPATools() { - instance = this; - } - - public static TPATools getInstance() { - return instance; - } - public void updateButtons() { subButtons.get(2).text.set("Delay: " + delay); } @@ -73,19 +74,19 @@ public void onEveryTick() { } @Override public void onChat(String s, String[] args) { - if (s.equalsIgnoreCase("delay")) { + if(s.equalsIgnoreCase("delay")) { delay = Integer.parseInt(args[1]); ChatUtils.print("Set!"); } - if (s.equalsIgnoreCase("tpa")) { + if(s.equalsIgnoreCase("tpa")) { ChatUtils.print("Sending..."); ThreadManager.run(() -> { - for (NetworkPlayerInfo info : Objects.requireNonNull(Yac.mc.getConnection()).getPlayerInfoMap()) { + for (NetworkPlayerInfo info : Objects.requireNonNull(YAC.mc.getConnection()).getPlayerInfoMap()) { if(stop) return; try { - Yac.mc.player.sendChatMessage("/tpa " + info.getGameProfile().getName()); + YAC.mc.player.sendChatMessage("/tpa " + info.getGameProfile().getName()); ChatUtils.print("Sent to " + info.getGameProfile().getName()); } catch (Throwable e) { } @@ -99,14 +100,14 @@ public void onChat(String s, String[] args) { ChatUtils.print("Done!"); }); } - if (s.equalsIgnoreCase("tpahere")) { + if(s.equalsIgnoreCase("tpahere")) { ChatUtils.print("Sending..."); ThreadManager.run(() -> { - for (NetworkPlayerInfo info : Objects.requireNonNull(Yac.mc.getConnection()).getPlayerInfoMap()) { + for (NetworkPlayerInfo info : Objects.requireNonNull(YAC.mc.getConnection()).getPlayerInfoMap()) { if(stop) return; try { - Yac.mc.player.sendChatMessage("/tpahere " + info.getGameProfile().getName()); + YAC.mc.player.sendChatMessage("/tpahere " + info.getGameProfile().getName()); ChatUtils.print("Sent to " + info.getGameProfile().getName()); } catch (Throwable e) { } @@ -124,7 +125,7 @@ public void onChat(String s, String[] args) { } public void loadConfig() { - delay = Integer.parseInt(cfg.getOrDefault("delay", "1000")); + delay = Integer.parseInt(cfg.get("delay")); updateButtons(); } diff --git a/src/main/java/tudbut/mod/client/yac/mods/Team.java b/src/main/java/tudbut/mod/client/yac/mods/Team.java index 3f1f469..e54b153 100644 --- a/src/main/java/tudbut/mod/client/yac/mods/Team.java +++ b/src/main/java/tudbut/mod/client/yac/mods/Team.java @@ -1,7 +1,7 @@ package tudbut.mod.client.yac.mods; import net.minecraft.client.network.NetworkPlayerInfo; -import tudbut.mod.client.yac.Yac; +import tudbut.mod.client.yac.YAC; import tudbut.mod.client.yac.gui.GuiYAC; import tudbut.mod.client.yac.utils.ChatUtils; import tudbut.mod.client.yac.utils.Module; @@ -16,10 +16,19 @@ public class Team extends Module { static Team instance; - private final ArrayList names = new ArrayList<>(); + + public static Team getInstance() { + return instance; + } + + public Team() { + instance = this; + } + + public final ArrayList names = new ArrayList<>(); private boolean tpa = true; private boolean tpaHere = false; - + { subButtons.add(new GuiYAC.Button("Accept /tpa: " + tpa, text -> { tpa = !tpa; @@ -30,23 +39,16 @@ public class Team extends Module { text.set("Accept /tpahere: " + tpaHere); })); subButtons.add(new GuiYAC.Button("Send /tpahere", text -> { - onChat("", new String[]{ + onChat("", new String[] { "tpahere" }); })); subButtons.add(new GuiYAC.Button("Show list", text -> { - onChat("", new String[]{ + onChat("", new String[] { "list" }); })); } - public Team() { - instance = this; - } - - public static Team getInstance() { - return instance; - } public void updateButtons() { subButtons.get(0).text.set("Accept /tpa: " + tpa); @@ -81,10 +83,10 @@ public void onChat(String s, String[] args) { case "tpahere": ChatUtils.print("Sending..."); ThreadManager.run(() -> { - for (NetworkPlayerInfo info : Objects.requireNonNull(Yac.mc.getConnection()).getPlayerInfoMap()) { - if (names.contains(info.getGameProfile().getName())) { + for (NetworkPlayerInfo info : Objects.requireNonNull(YAC.mc.getConnection()).getPlayerInfoMap()) { + if(names.contains(info.getGameProfile().getName())) { try { - Yac.mc.player.sendChatMessage("/tpahere " + info.getGameProfile().getName()); + YAC.mc.player.sendChatMessage("/tpahere " + info.getGameProfile().getName()); ChatUtils.print("Sent to " + info.getGameProfile().getName()); } catch (Throwable e) { } @@ -107,21 +109,23 @@ public void onChat(String s, String[] args) { for (String name : names) { toPrint.append(name).append(", "); } - if (names.size() >= 1) + if(names.size() >= 1) toPrint.delete(toPrint.length() - 2, toPrint.length() - 1); ChatUtils.print(toPrint.toString()); break; } updateButtons(); + names.remove(YAC.player.getName()); + names.add(YAC.player.getName()); } @Override public void onServerChat(String s, String formatted) { - if (tpa && s.contains("has requested to teleport to you.") && names.stream().anyMatch(name -> s.startsWith(name + " ") || s.startsWith("~" + name + " "))) { - Yac.player.sendChatMessage("/tpaccept"); + if(tpa && s.contains("has requested to teleport to you.") && names.stream().anyMatch(name -> s.startsWith(name + " ") || s.startsWith("~" + name + " "))) { + YAC.player.sendChatMessage("/tpaccept"); } - if (tpaHere && s.contains("has requested that you teleport to them.") && names.stream().anyMatch(name -> s.startsWith(name + " ") || s.startsWith("~" + name + " "))) { - Yac.player.sendChatMessage("/tpaccept"); + if(tpaHere && s.contains("has requested that you teleport to them.") && names.stream().anyMatch(name -> s.startsWith(name + " ") || s.startsWith("~" + name + " "))) { + YAC.player.sendChatMessage("/tpaccept"); } } diff --git a/src/main/java/tudbut/mod/client/yac/mods/Trap.java b/src/main/java/tudbut/mod/client/yac/mods/Trap.java index 03b0dce..adfbfe1 100644 --- a/src/main/java/tudbut/mod/client/yac/mods/Trap.java +++ b/src/main/java/tudbut/mod/client/yac/mods/Trap.java @@ -2,33 +2,47 @@ import net.minecraft.entity.player.EntityPlayer; import net.minecraft.util.math.BlockPos; -import tudbut.mod.client.yac.Yac; +import tudbut.mod.client.yac.YAC; import tudbut.mod.client.yac.utils.BlockUtils; -import tudbut.mod.client.yac.utils.ChatUtils; import tudbut.mod.client.yac.utils.Module; import tudbut.mod.client.yac.utils.ThreadManager; public class Trap extends Module { - { - enabled = true; + private boolean ticked = false; + + @Override + public void onEnable() { + ThreadManager.run(() -> { + while (enabled) { + try { + if (YAC.mc.world != null) { + for (EntityPlayer player : YAC.mc.world.playerEntities) { + if (!Team.getInstance().names.contains(player.getName())) { + trap(player); + } + } + } + } catch (Exception e) { + + } + } + }); } @Override public void onTick() { + ticked = true; + } + public void waitForTick() throws InterruptedException { + while (!ticked); + Thread.sleep(1); + ticked = false; } @Override public void onChat(String s, String[] args) { - ChatUtils.print("Finding player"); - for (EntityPlayer player : Yac.mc.world.playerEntities) { - if (player.getName().equalsIgnoreCase(s)) { - ThreadManager.run(() -> trap(player)); - return; - } - } - ChatUtils.print("Player not found!"); } public void add(BlockPos[] positions, int i, int x, int y, int z) { @@ -36,7 +50,6 @@ public void add(BlockPos[] positions, int i, int x, int y, int z) { } public void trap(EntityPlayer player) { - ChatUtils.print("Trapping " + player.getName() + "..."); BlockPos[] positions = new BlockPos[18]; for (int i = 0; i < positions.length; i++) { positions[i] = new BlockPos(player.getPositionVector()); @@ -64,10 +77,9 @@ public void trap(EntityPlayer player) { add(positions, 16, +0, +2, +1); add(positions, 17, +0, +2, -1); - ChatUtils.print("Constructed positions. Placing blocks..."); - for (int i = 0; i < positions.length; i++) { try { + waitForTick(); BlockUtils.placeBlock(positions[i], false); System.out.println(positions[i]); Thread.sleep(50); @@ -76,7 +88,5 @@ public void trap(EntityPlayer player) { e.printStackTrace(); } } - - ChatUtils.print("Blocks placed."); } } diff --git a/src/main/java/tudbut/mod/client/yac/utils/BlockUtils.java b/src/main/java/tudbut/mod/client/yac/utils/BlockUtils.java index 1584117..2eafa3f 100644 --- a/src/main/java/tudbut/mod/client/yac/utils/BlockUtils.java +++ b/src/main/java/tudbut/mod/client/yac/utils/BlockUtils.java @@ -10,7 +10,6 @@ import net.minecraft.network.play.client.CPacketPlayer; import net.minecraft.util.EnumFacing; import net.minecraft.util.EnumHand; -import net.minecraft.util.math.AxisAlignedBB; import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.MathHelper; import net.minecraft.util.math.Vec3d; @@ -57,7 +56,7 @@ public class BlockUtils { public static void placeBlock(BlockPos pos, boolean rotate) { EnumFacing side = getPlaceableSide(pos); if (side == null) { - ChatUtils.print("Couldn't place a block"); + //ChatUtils.print("Couldn't place a block"); return; } BlockPos neighbour = pos.offset(side); @@ -70,6 +69,9 @@ public static void placeBlock(BlockPos pos, boolean rotate) { if (rotate) BlockUtils.faceVectorPacketInstant(hitVec); mc.playerController.processRightClickBlock(mc.player, mc.world, neighbour, opposite, hitVec, EnumHand.MAIN_HAND); mc.player.swingArm(EnumHand.MAIN_HAND); + if ((BlockUtils.blackList.contains(neighbourBlock) || BlockUtils.shulkerList.contains(neighbourBlock))) { + mc.player.connection.sendPacket(new CPacketEntityAction(mc.player, CPacketEntityAction.Action.STOP_SNEAKING)); + } } private static EnumFacing getPlaceableSide(BlockPos pos) { diff --git a/src/main/java/tudbut/mod/client/yac/utils/FileRW.java b/src/main/java/tudbut/mod/client/yac/utils/FileRW.java index 9d31c8c..3b9d13a 100644 --- a/src/main/java/tudbut/mod/client/yac/utils/FileRW.java +++ b/src/main/java/tudbut/mod/client/yac/utils/FileRW.java @@ -22,13 +22,6 @@ public FileRW(String path) throws IOException { rereadFile(); } - public String getContent() { - StringBuilder builder = new StringBuilder(); - for (String line : lines) - builder.append(line); - return builder.toString(); - } - public void setContent(String content) throws IOException { this.lines.clear(); this.lines.addAll(Arrays.asList(content.split("\n"))); @@ -38,6 +31,13 @@ public void setContent(String content) throws IOException { writer.close(); } + public String getContent() { + StringBuilder builder = new StringBuilder(); + for (String line : lines) + builder.append(line); + return builder.toString(); + } + public void rereadFile() throws IOException { BufferedReader stream = new BufferedReader(new InputStreamReader(new FileInputStream(file))); lines.clear(); diff --git a/src/main/java/tudbut/mod/client/yac/utils/InventoryUtils.java b/src/main/java/tudbut/mod/client/yac/utils/InventoryUtils.java index 0b0cd8d..9ae2385 100644 --- a/src/main/java/tudbut/mod/client/yac/utils/InventoryUtils.java +++ b/src/main/java/tudbut/mod/client/yac/utils/InventoryUtils.java @@ -1,21 +1,19 @@ package tudbut.mod.client.yac.utils; -import net.minecraft.client.gui.GuiChat; import net.minecraft.client.gui.GuiIngameMenu; -import net.minecraft.client.gui.GuiNewChat; import net.minecraft.client.gui.GuiScreen; +import net.minecraft.client.gui.inventory.GuiContainerCreative; import net.minecraft.client.gui.inventory.GuiInventory; import net.minecraft.inventory.ClickType; import net.minecraft.inventory.Container; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; -import tudbut.mod.client.yac.Yac; +import tudbut.mod.client.yac.YAC; import tudbut.mod.client.yac.gui.GuiYAC; public class InventoryUtils { public static final int OFFHAND_SLOT = 45; - private static boolean swapping = false; public static Integer getSlotWithItem(Container inv, Item item, int amount) { return getSlotWithItem(inv, item, new int[0], amount, amount); @@ -26,7 +24,7 @@ public static Integer getSlotWithItem(Container inv, Item item, int[] not, int a a: { for (int j = 0; j < not.length; j++) { - if (i == not[j]) + if(i == not[j]) break a; } @@ -38,31 +36,48 @@ public static Integer getSlotWithItem(Container inv, Item item, int[] not, int a return null; } + private static boolean swapping = false; + public static void swap(int slot, int hotbarSlot) { - Yac.mc.playerController.windowClick(Yac.mc.player.inventoryContainer.windowId, slot, hotbarSlot, ClickType.SWAP, Yac.mc.player); + YAC.mc.playerController.windowClick(YAC.mc.player.inventoryContainer.windowId, slot, hotbarSlot, ClickType.SWAP, YAC.mc.player); } public static void inventorySwap(int from, int to) { - if (swapping) + if(swapping) return; - + swapping = true; ThreadManager.run(() -> { try { - GuiScreen screen = Yac.mc.currentScreen; - if (screen != null && screen.getClass() != GuiChat.class && screen.getClass() != GuiInventory.class && screen.getClass().getComponentType() != GuiNewChat.class.getComponentType() && screen.getClass() != GuiIngameMenu.class && screen.getClass() != GuiYAC.class) { + GuiScreen screen = YAC.mc.currentScreen; + boolean doResetScreen = false; + if( + screen != null && + !( + screen instanceof GuiYAC || + screen.getClass().getSimpleName().contains("Chat") || + screen instanceof GuiContainerCreative || + screen instanceof GuiIngameMenu || + screen instanceof GuiInventory + ) + ) { Thread.sleep(200); - Yac.player.closeScreen(); + YAC.player.closeScreen(); Thread.sleep(300); + doResetScreen = true; } - Yac.mc.playerController.windowClick(Yac.mc.player.inventoryContainer.windowId, from, 8, ClickType.SWAP, Yac.mc.player); - Thread.sleep(30); - Yac.mc.playerController.windowClick(Yac.mc.player.inventoryContainer.windowId, to, 8, ClickType.SWAP, Yac.mc.player); - Thread.sleep(30); - Yac.mc.playerController.windowClick(Yac.mc.player.inventoryContainer.windowId, from, 8, ClickType.SWAP, Yac.mc.player); - Thread.sleep(30); - Yac.mc.displayGuiScreen(screen); + //Thread.sleep(10); + YAC.mc.playerController.windowClick(YAC.mc.player.inventoryContainer.windowId, from, 8, ClickType.SWAP, YAC.mc.player); + //Thread.sleep(100); + YAC.mc.playerController.windowClick(YAC.mc.player.inventoryContainer.windowId, to, 8, ClickType.SWAP, YAC.mc.player); + //Thread.sleep(200); + YAC.mc.playerController.windowClick(YAC.mc.player.inventoryContainer.windowId, from, 8, ClickType.SWAP, YAC.mc.player); + + Thread.sleep(20); + + if(doResetScreen) + YAC.mc.displayGuiScreen(screen); } catch (InterruptedException e) { e.printStackTrace(); diff --git a/src/main/java/tudbut/mod/client/yac/utils/Module.java b/src/main/java/tudbut/mod/client/yac/utils/Module.java index c615230..d250a9f 100644 --- a/src/main/java/tudbut/mod/client/yac/utils/Module.java +++ b/src/main/java/tudbut/mod/client/yac/utils/Module.java @@ -8,24 +8,25 @@ public abstract class Module { - private static int cIndex = 0; public Map cfg = new HashMap<>(); + + private static int cIndex = 0; public int index; + + public boolean defaultEnabled() { + return false; + } public boolean enabled = defaultEnabled(); public Integer clickGuiX; public Integer clickGuiY; public ArrayList subButtons = new ArrayList<>(); + public Module() { index = cIndex; cIndex++; } - public boolean defaultEnabled() { - return false; - } - public abstract void onTick(); - public void onEveryTick() { } @@ -49,14 +50,14 @@ public void loadConfig(Map map) { enabled = Boolean.parseBoolean(cfg.get("enabled")); clickGuiX = null; clickGuiY = null; - if (cfg.containsKey("cgx") && cfg.containsKey("cgy")) { + if(cfg.containsKey("cgx") && cfg.containsKey("cgy")) { clickGuiX = Integer.parseInt(cfg.get("cgx")); clickGuiY = Integer.parseInt(cfg.get("cgy")); } loadConfig(); - if (enabled) + if(enabled) onEnable(); else onDisable(); @@ -74,7 +75,7 @@ public String saveConfig() { updateConfig(); cfg.put("enabled", String.valueOf(enabled)); - if (clickGuiX != null && clickGuiY != null) { + if(clickGuiX != null && clickGuiY != null) { cfg.put("cgx", clickGuiX + ""); cfg.put("cgy", clickGuiY + ""); } diff --git a/src/main/resources/mcmod.info b/src/main/resources/mcmod.info index c022f3c..d940011 100644 --- a/src/main/resources/mcmod.info +++ b/src/main/resources/mcmod.info @@ -1,9 +1,9 @@ [ { "modid": "yac", - "name": "YAC Client (Public version)", + "name": "YAC Client", "description": "", - "version": "vB0.2.5a (Public)", + "version": "vB1.0.0a", "mcversion": "${mcversion}", "url": "", "updateUrl": "", diff --git a/src/main/resources/pack.mcmeta b/src/main/resources/pack.mcmeta index 4018267..7382d37 100644 --- a/src/main/resources/pack.mcmeta +++ b/src/main/resources/pack.mcmeta @@ -1,7 +1,6 @@ { "pack": { - "description": "examplemod resources", - "pack_format": 3, - "_comment": "A pack_format of 3 should be used starting with Minecraft 1.11. All resources, including language files, should be lowercase (eg: en_us.lang). A pack_format of 2 will load your mod resources with LegacyV2Adapter, which requires language files to have uppercase letters (eg: en_US.lang)." + "description": "TTC resources", + "pack_format": 3 } } diff --git a/version.txt b/version.txt index a8d2e0e..cb5e446 100644 --- a/version.txt +++ b/version.txt @@ -1 +1 @@ -vB0.2.5a \ No newline at end of file +vB1.0.0a \ No newline at end of file