
CoalOres
Members-
Posts
86 -
Joined
-
Last visited
Converted
-
Gender
Undisclosed
-
Personal Text
I am new!
Recent Profile Visitors
The recent visitors block is disabled and is not being shown to other users.
CoalOres's Achievements

Stone Miner (3/8)
0
Reputation
-
[1.8.9] More effective replacement for thread.sleep?
CoalOres replied to CoalOres's topic in Modder Support
I have discovered the source of the problem, now I am getting an array index out of bounds exception: Command: package com.megaparties; import java.io.BufferedReader; import java.io.FileReader; import java.io.IOException; import net.minecraft.command.CommandBase; import net.minecraft.command.CommandException; import net.minecraft.command.ICommandSender; public class wparty extends CommandBase { public String getCommandName() { return "wparty"; } public String getCommandUsage(ICommandSender sender) { return "wparty"; } public boolean canCommandSenderUseCommand(ICommandSender icommandsender) { return true; } public void processCommand(ICommandSender sender, String[] args) throws CommandException { com.megaparties.Events.cont = true; String path = "config/whitelist.txt"; String line; try { FileReader file = new FileReader(path); BufferedReader buffered = new BufferedReader(file); while ((line = buffered.readLine()) != null) { com.megaparties.Events.list.add(line); } buffered.close(); } catch (IOException e) { e.printStackTrace(); } } } Event: @SubscribeEvent public void onClientTick(TickEvent.ClientTickEvent event) { if (cont){ if(this.count < 5) { this.count++; } else { this.count = 0; String path = "config/whitelist.txt"; String line; if(i < list.size()){ Minecraft.getMinecraft().thePlayer.sendChatMessage("/party invite " + list.get(i)); i ++; System.out.println(i); System.out.println(list.size()); } else{ com.megaparties.Events.cont = false; i = 0; } } } -
[1.8.9] More effective replacement for thread.sleep?
CoalOres replied to CoalOres's topic in Modder Support
Also tried a ListIterator, still didn't work. -
[1.8.9] More effective replacement for thread.sleep?
CoalOres replied to CoalOres's topic in Modder Support
I don't think that would quite work. You see I also have commands which write to the file and clear it whenever you activate them, so it needs to be re-read. I probably misunderstood that. Isn't there anything simpler I could do? Like if(i <= list.size()){ Minecraft.getMinecraft().thePlayer.sendChatMessage("/party invite " + list.get(i)); i ++; } I tried that and it still didn't work. -
[1.8.9] More effective replacement for thread.sleep?
CoalOres replied to CoalOres's topic in Modder Support
Ok, I've done that, it works, save for the fact that the loop never ends... i never equals null and so it doesn't close. I can't put it at 0 because 0 still has a value, I need to detect when it has gone through the whole list. -
[1.8.9] More effective replacement for thread.sleep?
CoalOres replied to CoalOres's topic in Modder Support
My New Code: @SubscribeEvent public void onClientTick(TickEvent.ClientTickEvent event) { if (cont == true){ if(this.count < 5) { this.count++; } else { this.count = 0; String path = "config/whitelist.txt"; String line; try { FileReader file = new FileReader(path); BufferedReader buffered = new BufferedReader(file); while ((line = buffered.readLine()) != null) { list.add(line); } int i = 0; if(list.get(i) != null){ Minecraft.getMinecraft().thePlayer.sendChatMessage("/party invite " + line); i ++; } else{ buffered.close(); com.megaparties.Events.cont = false; } } catch (IOException e) { e.printStackTrace(); } } } I can already see that it isn't going to work because i is set back to 0 every time it loops over. -
[1.8.9] More effective replacement for thread.sleep?
CoalOres replied to CoalOres's topic in Modder Support
Got it confused with Python, I need to use list.get don't I? -
[1.8.9] More effective replacement for thread.sleep?
CoalOres replied to CoalOres's topic in Modder Support
Yes we do, but it's your mod, and we are not going to write your mod for you. I've attempted to copy the data in the txt file to an arrayList but it is just resulting in a "The type of expression must be an array type but it is resolved to List<String>". This is the only way I can think of keeping track: @SubscribeEvent public void onClientTick(TickEvent.ClientTickEvent event) { if (cont == true){ if(this.count < 5) { this.count++; } else { this.count = 0; String path = "config/whitelist.txt"; String line; try { FileReader file = new FileReader(path); BufferedReader buffered = new BufferedReader(file); while ((line = buffered.readLine()) != null) { list.add(line); } int i = 0; if(list[i] != null){ Minecraft.getMinecraft().thePlayer.sendChatMessage("/party invite " + line); i ++; } else{ buffered.close(); com.megaparties.Events.cont = false; } } catch (IOException e) { e.printStackTrace(); } } } } There error is on the if(list != null) -
[1.8.9] More effective replacement for thread.sleep?
CoalOres replied to CoalOres's topic in Modder Support
You don't know how to? -
[1.8.9] More effective replacement for thread.sleep?
CoalOres replied to CoalOres's topic in Modder Support
The "Null" was caused by my setting it to "Null" at the start. But now it only reads the first line and keeps reading only the first line, how would I resolve this? -
[1.8.9] More effective replacement for thread.sleep?
CoalOres replied to CoalOres's topic in Modder Support
I set it to client and now it spams the chat relentlessly with "Invited null to the party" without stopping. -
[1.8.9] More effective replacement for thread.sleep?
CoalOres replied to CoalOres's topic in Modder Support
package com.megaparties; import java.io.BufferedReader; import java.io.FileReader; import java.io.IOException; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; import java.util.concurrent.FutureTask; import net.minecraft.client.Minecraft; import net.minecraft.command.CommandBase; import net.minecraft.command.CommandException; import net.minecraft.command.ICommandSender; import net.minecraft.util.ChatComponentText; import net.minecraft.util.EnumChatFormatting; import net.minecraft.util.IChatComponent; public class wparty extends CommandBase { private long waitTime; int time = 0; public boolean onTickInGame(float time, Minecraft minecraftInstance){ time++; return true; } public String getCommandName() { return "wparty"; } public String getCommandUsage(ICommandSender sender) { return "wparty"; } public boolean canCommandSenderUseCommand(ICommandSender icommandsender) { return true; } public void processCommand(ICommandSender sender, String[] args) throws CommandException { com.megaparties.Events.cont = true; } } The ontick in game is there for some reason, probably from old code, that the problem? EDIT: Removed it, not the problem. Still gives errors. -
[1.8.9] More effective replacement for thread.sleep?
CoalOres replied to CoalOres's topic in Modder Support
Alright, this is my new code: package com.megaparties; import java.io.BufferedReader; import java.io.FileReader; import java.io.IOException; import net.minecraft.client.Minecraft; import net.minecraft.util.ChatComponentText; import net.minecraft.util.EnumChatFormatting; import net.minecraft.util.IChatComponent; import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; import net.minecraftforge.fml.common.gameevent.TickEvent; public class Events { public static boolean cont = false; private int count = 0; //Called whenever the player is updated or ticked. @SubscribeEvent public void onPlayerTick(TickEvent.PlayerTickEvent event) { } //Called when the client ticks. @SubscribeEvent public void onClientTick(TickEvent.ClientTickEvent event) { } //Called when the server ticks. Usually 20 ticks a second. @SubscribeEvent public void onServerTick(TickEvent.ServerTickEvent event) { if (cont == true){ if(this.count < 2) { this.count++; } else { this.count = 0; String path = "config/whitelist.txt"; String line = null; try { FileReader file = new FileReader(path); BufferedReader buffered = new BufferedReader(file); if(buffered.readLine() != null){ Minecraft.getMinecraft().thePlayer.sendChatMessage("/party invite " + line); } else{ buffered.close(); com.megaparties.Events.cont = false; } } catch (IOException e) { e.printStackTrace(); } } } } //Called when a new frame is displayed (See fps) @SubscribeEvent public void onRenderTick(TickEvent.RenderTickEvent event) { } //Called when the world ticks @SubscribeEvent public void onWorldTick(TickEvent.WorldTickEvent event) { } } When I run it, it does not execute the invite and spams the console with this error: What's up with this? -
[1.8.9] More effective replacement for thread.sleep?
CoalOres replied to CoalOres's topic in Modder Support
I see... Do I need to create a boolean which is changed every time I operate the command so it will fire the reading? -
[1.8.9] More effective replacement for thread.sleep?
CoalOres replied to CoalOres's topic in Modder Support
I'm not quite understanding you... I just need an integer to increase every tick, so that I can detect when it reaches a certain amount of ticks. How do I "tell the tick handler" to start counting? -
[1.8.9] More effective replacement for thread.sleep?
CoalOres replied to CoalOres's topic in Modder Support
How do I register onServerTick if it is included in my command class though?