I've been trying something similar to that, however it just crashes my minecraft whenever I toggle my mod.
@SubscribeEvent
public void onPlayerTick(TickEvent.PlayerTickEvent e) {
if (AutoClickerKeyBind.isOn == true) {
//FMLClientHandler.instance().getClient().playerController.attackEntity(thePlayer, objectMouseOver.entityHit);
mc.getMinecraft().playerController.attackEntity(mc.thePlayer, mc.objectMouseOver.entityHit);
}
}
In future, post crash reports if your code is crashing. Knowing what the error is makes it much easier to find the solution.
In this case,
TickEvent.PlayerTickEvent
is fired on both the client and server threads. You should check
world.isRemote
to make sure you're only attacking from the client thread.
The event is also fired twice per tick, so check the event's
phase
field and only attack in one phase.
I'm really struggling with this. Thank you for your help however, I really appreciate it.
---- Minecraft Crash Report ----
// Ouch. That hurt
Time: 18/12/15 00:33
Description: Unexpected error
java.lang.NullPointerException: Unexpected error
at com.bond.tech.AutoClickerTickEvent.onClientTick(AutoClickerTickEvent.java:50)
at net.minecraftforge.fml.common.eventhandler.ASMEventHandler_8_AutoClickerTickEvent_onClientTick_ClientTickEvent.invoke(.dynamic)
at net.minecraftforge.fml.common.eventhandler.ASMEventHandler.invoke(ASMEventHandler.java:55)
at net.minecraftforge.fml.common.eventhandler.EventBus.post(EventBus.java:138)
at net.minecraftforge.fml.common.FMLCommonHandler.onPreClientTick(FMLCommonHandler.java:366)
at net.minecraft.client.Minecraft.runTick(Minecraft.java:1707)
at net.minecraft.client.Minecraft.runGameLoop(Minecraft.java:1087)
at net.minecraft.client.Minecraft.run(Minecraft.java:376)
at net.minecraft.client.main.Main.main(Main.java:117)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at net.minecraft.launchwrapper.Launch.launch(Launch.java:135)
at net.minecraft.launchwrapper.Launch.main(Launch.java:28)
at net.minecraftforge.gradle.GradleStartCommon.launch(Unknown Source)
at GradleStart.main(Unknown Source)
A detailed walkthrough of the error, its code path and all known details is as follows:
---------------------------------------------------------------------------------------
-- System Details --
Details:
Minecraft Version: 1.8
Operating System: Windows 8.1 (amd64) version 6.3
Java Version: 1.7.0_79, Oracle Corporation
Java VM Version: Java HotSpot(TM) 64-Bit Server VM (mixed mode), Oracle Corporation
Memory: 827033816 bytes (788 MB) / 1038876672 bytes (990 MB) up to 1038876672 bytes (990 MB)
JVM Flags: 3 total; -Xincgc -Xmx1024M -Xms1024M
IntCache: cache: 0, tcache: 0, allocated: 0, tallocated: 0
FML: MCP v9.10 FML v8.0.99.99 Minecraft Forge 11.14.3.1450 4 mods loaded, 4 mods active
States: 'U' = Unloaded 'L' = Loaded 'C' = Constructed 'H' = Pre-initialized 'I' = Initialized 'J' = Post-initialized 'A' = Available 'D' = Disabled 'E' = Errored
UCHIJA mcp{9.05} [Minecraft Coder Pack] (minecraft.jar)
UCHIJA FML{8.0.99.99} [Forge Mod Loader] (forgeSrc-1.8-11.14.3.1450.jar)
UCHIJA Forge{11.14.3.1450} [Minecraft Forge] (forgeSrc-1.8-11.14.3.1450.jar)
UCHIJA bondtech{1.0} [bondTech - Autoclicker] (bin)
Loaded coremods (and transformers):
GL info: ' Vendor: 'NVIDIA Corporation' Version: '4.5.0 NVIDIA 353.82' Renderer: 'GeForce GTX 750 Ti/PCIe/SSE2'
Launched Version: 1.8
LWJGL: 2.9.1
OpenGL: GeForce GTX 750 Ti/PCIe/SSE2 GL version 4.5.0 NVIDIA 353.82, NVIDIA Corporation
GL Caps: Using GL 1.3 multitexturing.
Using GL 1.3 texture combiners.
Using framebuffer objects because OpenGL 3.0 is supported and separate blending is supported.
Shaders are available because OpenGL 2.1 is supported.
VBOs are available because OpenGL 1.5 is supported.
Using VBOs: No
Is Modded: Definitely; Client brand changed to 'fml,forge'
Type: Client (map_client.txt)
Resource Packs: []
Current Language: English (US)
Profiler Position: N/A (disabled)
The code the error is coming from.
@SubscribeEvent
public void onClientTick(TickEvent.ClientTickEvent event) {
if(event.phase == TickEvent.Phase.START) {
if(theWorld.isRemote) {
if (AutoClickerKeyBind.isOn == true) {
mc.getMinecraft().thePlayer.swingItem();
mc.getMinecraft().playerController.attackEntity(mc.thePlayer, mc.objectMouseOver.entityHit);
}
}
}
}