Skip to content

Commit

Permalink
Concurrent fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
samolego committed Oct 25, 2022
1 parent 2a49248 commit 875aa7d
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,11 @@ public void onInitializeClient() {
ClientLoginConnectionEvents.INIT.register(evtHandler::onLogin);

UseBlockCallback.EVENT.register(ContainerDiscovery::onUseBlock);
WorldRenderEvents.LAST.register(context -> ESPRender.onRender(context));

if (config.allowSyncServer()) {
ClientPlayNetworking.registerGlobalReceiver(SERVER_CONFIG_CHANNEL, (client, handler, buf, responseSender) -> config.unpack(buf));
}

WorldRenderEvents.LAST.register(ESPRender::onRender);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@
import net.minecraft.server.network.ServerGamePacketListenerImpl;
import org.jetbrains.annotations.Nullable;
import org.samo_lego.clientstorage.fabric_client.network.PacketLimiter;
import org.samo_lego.clientstorage.fabric_client.util.ESPRender;
import org.samo_lego.clientstorage.fabric_client.util.ItemDataTooltip;
import org.samo_lego.clientstorage.fabric_client.util.ItemDisplayType;

import static org.samo_lego.clientstorage.fabric_client.ClientStorageFabric.config;
import static org.samo_lego.clientstorage.fabric_client.util.ESPRender.BLOCK_ESPS;

public class ConfigScreen {
public static Screen createConfigScreen(@Nullable Screen parent) {
Expand Down Expand Up @@ -105,7 +105,7 @@ public static Screen createConfigScreen(@Nullable Screen parent) {
.name(Component.translatable("settings.clientstorage.clear_esps"))
.tooltip(Component.translatable("tooltip.clientstorage.clear_esps"))
.action((yaclScreen, buttonOption) -> {
BLOCK_ESPS.clear();
ESPRender.reset();
})
.controller(ActionController::new)
.build());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import org.samo_lego.clientstorage.fabric_client.inventory.RemoteInventory;
import org.samo_lego.clientstorage.fabric_client.mixin.accessor.AMultiPlayerGamemode;
import org.samo_lego.clientstorage.fabric_client.mixin.accessor.AShulkerBoxBlock;
import org.samo_lego.clientstorage.fabric_client.util.ESPRender;
import org.samo_lego.clientstorage.fabric_client.util.PlayerLookUtil;

import java.util.HashMap;
Expand All @@ -42,7 +43,6 @@
import java.util.concurrent.LinkedBlockingDeque;

import static org.samo_lego.clientstorage.fabric_client.ClientStorageFabric.config;
import static org.samo_lego.clientstorage.fabric_client.util.ESPRender.BLOCK_ESPS;

/**
* The heart of the mod.
Expand Down Expand Up @@ -154,7 +154,7 @@ public static InteractionResult onUseBlock(Player player, Level world, Interacti
RemoteInventory.getInstance().sort();
}
} else {
BLOCK_ESPS.remove(craftingPos);
ESPRender.remove(craftingPos);
}
}
return InteractionResult.PASS;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@
import org.lwjgl.glfw.GLFW;
import org.samo_lego.clientstorage.fabric_client.ClientStorageFabric;
import org.samo_lego.clientstorage.fabric_client.config.ConfigScreen;
import org.samo_lego.clientstorage.fabric_client.util.ESPRender;

import static org.samo_lego.clientstorage.fabric_client.ClientStorageFabric.config;
import static org.samo_lego.clientstorage.fabric_client.ClientStorageFabric.displayMessage;
import static org.samo_lego.clientstorage.fabric_client.event.ContainerDiscovery.resetFakePackets;
import static org.samo_lego.clientstorage.fabric_client.util.ESPRender.BLOCK_ESPS;

public class SimpleEventHandler {

Expand All @@ -39,7 +39,7 @@ public SimpleEventHandler() {

public void onLogin(ClientHandshakePacketListenerImpl listener, Minecraft minecraft) {
resetFakePackets();
BLOCK_ESPS.clear();
ESPRender.reset();
if (config.allowSyncServer()) {
config.clearServerSettings();
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
*/
public class ESPRender {

public static final Set<BlockPos> BLOCK_ESPS = new HashSet<>();
private static final Set<BlockPos> BLOCK_ESPS = new HashSet<>();
private static final ModelPart.Cube CUBE = new ModelPart.Cube(0, 0, 0, 0, 0, 16, 16, 16, 0, 0, 0, false, 0, 0);
private static final RenderType RENDER_TYPE = RenderType.outline(new ResourceLocation("textures/misc/white.png"));

Expand All @@ -40,7 +40,7 @@ public static void renderBlockOutlines(PoseStack matrices, Vec3 playerPos, Outli
for (BlockPos pos : BLOCK_ESPS) {
double squareDist = playerPos.distanceToSqr(pos.getX(), pos.getY(), pos.getZ());
if (squareDist > 8 * 8) {

BLOCK_ESPS.remove(pos);
continue;
}

Expand Down Expand Up @@ -72,4 +72,16 @@ public static void markPos(BlockPos blockPos) {
BLOCK_ESPS.add(blockPos);
}
}

public static void reset() {
synchronized (BLOCK_ESPS) {
BLOCK_ESPS.clear();
}
}

public static void remove(BlockPos pos) {
synchronized (BLOCK_ESPS) {
BLOCK_ESPS.remove(pos);
}
}
}

0 comments on commit 875aa7d

Please sign in to comment.