Skip to content

Commit

Permalink
Small changes made to the thread
Browse files Browse the repository at this point in the history
  • Loading branch information
TheF1xer committed Sep 24, 2022
1 parent 0504e69 commit 35f9037
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 40 deletions.
Original file line number Diff line number Diff line change
@@ -1,23 +1,16 @@
package me.thef1xer.gateclient.events;

import net.minecraft.util.math.BlockPos;
import net.minecraft.world.chunk.Chunk;
import net.minecraftforge.fml.common.eventhandler.Event;

public class CheckBlockInChunkEvent extends Event {
private final BlockPos blockPos;
private final Chunk chunk;

public CheckBlockInChunkEvent(BlockPos blockPos, Chunk chunk) {
public CheckBlockInChunkEvent(BlockPos blockPos) {
this.blockPos = blockPos;
this.chunk = chunk;
}

public BlockPos getBlockPos() {
return blockPos;
}

public Chunk getChunk() {
return chunk;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,12 @@
import net.minecraftforge.client.event.ClientChatEvent;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import net.minecraftforge.fml.common.gameevent.InputEvent;
import net.minecraftforge.fml.common.gameevent.TickEvent;
import org.lwjgl.input.Keyboard;

public class CommonEventHandler {
private final Minecraft mc = Minecraft.getMinecraft();
private final GateClient gate = GateClient.getGate();


@SubscribeEvent
public void onClientTick(TickEvent.ClientTickEvent event) {
if (!gate.threadManager.clientThread.isAlive()) {
ChatUtil.clientMessage("An error occurred with the Client Thread, please restart your Client");
}
}

@SubscribeEvent
public void onKeyInput(InputEvent.KeyInputEvent event) {
if (Keyboard.isCreated() && mc.world != null && mc.player != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import me.thef1xer.gateclient.modules.movement.*;
import me.thef1xer.gateclient.modules.player.*;
import me.thef1xer.gateclient.modules.render.*;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.GlStateManager;
import net.minecraftforge.client.event.InputUpdateEvent;
import net.minecraftforge.client.event.RenderGameOverlayEvent;
Expand Down Expand Up @@ -245,6 +246,8 @@ public void onSearchChunks(SearchChunksEvent event) {

@SubscribeEvent
public void onCheckBlockInChunk(CheckBlockInChunkEvent event) {
if (Minecraft.getMinecraft().world == null) return;

if (Search.INSTANCE.isEnabled()) {
Search.INSTANCE.onCheckBlockInChunkEvent(event);
}
Expand Down
50 changes: 29 additions & 21 deletions src/main/java/me/thef1xer/gateclient/managers/ThreadManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import me.thef1xer.gateclient.events.CheckChunkEvent;
import me.thef1xer.gateclient.events.ThreadTickEvent;
import me.thef1xer.gateclient.events.SearchChunksEvent;
import me.thef1xer.gateclient.util.ChatUtil;
import net.minecraft.client.Minecraft;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.chunk.Chunk;
Expand All @@ -23,41 +24,48 @@ public ThreadManager() {

// Run method override
while (true) {
// I don't know why, but if I remove this, the Thread won't work anymore
MinecraftForge.EVENT_BUS.post(new ThreadTickEvent());
try {

// Do I really need Events to do this? I feel like I'm just using a lot of memory just to make everything more readable
// But other people with more experience than me have done it this way
// I think I really hate event systems, they kinda feel unnecessary, can't we do this with methods anyway?
// I don't know why, but if I remove this, the Thread won't work anymore
MinecraftForge.EVENT_BUS.post(new ThreadTickEvent());

// Check loaded Chunks
if (!chunksToCheck.isEmpty() && MinecraftForge.EVENT_BUS.post(new SearchChunksEvent())) {
for (int i = 0; i < chunksToCheck.size(); i++) {
Chunk chunk = chunksToCheck.get(i);
// Do I really need Events to do this? I feel like I'm just using a lot of memory just to make everything more readable
// But other people with more experience than me have done it this way
// I think I really hate event systems, they kinda feel unnecessary, can't we do this with methods anyway?

if (mc.world == null) continue;
// Check loaded Chunks
if (!chunksToCheck.isEmpty() && MinecraftForge.EVENT_BUS.post(new SearchChunksEvent())) {
for (int i = 0; i < chunksToCheck.size(); i++) {
Chunk chunk = chunksToCheck.get(i);

boolean isLoaded = mc.world.isChunkGeneratedAt(chunk.x, chunk.z);
MinecraftForge.EVENT_BUS.post(new CheckChunkEvent(chunk, isLoaded));
if (mc.world == null) continue;

// Don't check blocks in chunk if chunk isn't loaded
if (!isLoaded) continue;
boolean isLoaded = mc.world.isChunkGeneratedAt(chunk.x, chunk.z);
MinecraftForge.EVENT_BUS.post(new CheckChunkEvent(chunk, isLoaded));

for (int x = chunk.getPos().getXStart(); x <= chunk.getPos().getXEnd(); x++) {
for (int y = 1; y <= 256; y++) {
for (int z = chunk.getPos().getZStart(); z <= chunk.getPos().getZEnd(); z++) {
// Don't check blocks in chunk if chunk isn't loaded
if (!isLoaded) continue;

// Post new event with BlockPos and Chunk, I hate events so much
MinecraftForge.EVENT_BUS.post(new CheckBlockInChunkEvent(new BlockPos(x, y, z), chunk));
for (int x = chunk.getPos().getXStart(); x <= chunk.getPos().getXEnd(); x++) {
for (int y = 1; y <= 256; y++) {
for (int z = chunk.getPos().getZStart(); z <= chunk.getPos().getZEnd(); z++) {

// Post new event with BlockPos and Chunk, I hate events so much
MinecraftForge.EVENT_BUS.post(new CheckBlockInChunkEvent(new BlockPos(x, y, z)));
}
}
}

}

chunksToCheck.clear();
}

chunksToCheck.clear();
} catch (Exception e) {
if (mc.player != null) {
ChatUtil.clientMessage("A small bug occurred, you might want to send your logs to the developer");
}
}

}
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
import net.minecraft.init.Blocks;
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.chunk.Chunk;
import net.minecraftforge.client.event.RenderWorldLastEvent;

import java.util.ArrayList;
Expand Down Expand Up @@ -79,7 +78,6 @@ public void onSetBlockState(SetBlockStateEvent event) {

public void onCheckBlockInChunkEvent(CheckBlockInChunkEvent event) {
BlockPos pos = event.getBlockPos();
Chunk chunk = event.getChunk();

if (searchedBlocks.getBlockList().contains(mc.world.getBlockState(pos).getBlock()) && !foundBlocksPos.contains(pos)) {
foundBlocksPos.add(pos);
Expand Down

0 comments on commit 35f9037

Please sign in to comment.