Skip to content

Commit

Permalink
Moves stuff off thread. Adds support for 1.16.2+
Browse files Browse the repository at this point in the history
  • Loading branch information
Haven-King committed Nov 2, 2020
1 parent 4382669 commit 1a4b8e5
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 33 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
plugins {
id 'fabric-loom' version '0.4-SNAPSHOT'
id 'fabric-loom' version '0.5-SNAPSHOT'
id 'maven-publish'
}

Expand Down
10 changes: 5 additions & 5 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@
org.gradle.jvmargs=-Xmx1G

# Fabric Properties
minecraft_version = 1.16.2
yarn_mappings = 1.16.2+build.43
loader_version = 0.9.2+build.206
minecraft_version = 1.16.4
yarn_mappings = 1.16.4+build.1
loader_version = 0.10.6+build.214

# Mod Properties
mod_version = 0.0.2
mod_version = 0.0.3
maven_group = dev.hephaestus
archives_base_name = sax

# Dependencies
fabric_version = fabric-api:0.19.0+build.398-1.16
fabric_version = 0.25.1+build.416-1.16
fiblib_version = 0.1.5-1.16.2
mod_menu_version = 1.14.6+build.31
59 changes: 33 additions & 26 deletions src/main/java/dev/hephaestus/sax/server/DeObfuscator.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,45 +20,52 @@ public class DeObfuscator {

private final ServerPlayerEntity player;
private final HashSet<Vec3i> revealed = new HashSet<>();
private final BlockPos.Mutable mutable = new BlockPos.Mutable();

private Thread thread = null;

public DeObfuscator(ServerPlayerEntity player) {
this.player = player;
}

public void tick() {
Vec3d origin = this.player.getCameraPosVec(1F);
if (thread == null || !thread.isAlive()) {
thread = new Thread(() -> {
Vec3d origin = this.player.getCameraPosVec(1F);

for (Vec3i pos : this.revealed) {
if (!pos.isWithinDistance(origin, SEARCH_RADIUS)) {
this.sendBlockUpdate(new BlockPos(pos), this.player.networkHandler::sendPacket);
}
}
for (Vec3i pos : this.revealed) {
if (!pos.isWithinDistance(origin, SEARCH_RADIUS)) {
this.sendBlockUpdate(new BlockPos(pos), this.player.networkHandler::sendPacket);
}
}

this.revealed.removeIf(pos -> !pos.isWithinDistance(origin, SEARCH_RADIUS));
BlockPos.Mutable mutable = new BlockPos.Mutable();

int i = 0;
for (byte x = -SEARCH_RADIUS; x <= SEARCH_RADIUS; ++x) {
for (byte y = -SEARCH_RADIUS; y <= SEARCH_RADIUS; ++y) {
for (byte z = -SEARCH_RADIUS; z <= SEARCH_RADIUS; ++z) {
if (x * x + y * y + z * z <= SEARCH_RADIUS * SEARCH_RADIUS) {
++i;
mutable.set(origin.x, origin.y, origin.z);
mutable.move(x, y, z);

if (Config.HIDDEN.containsKey(this.player.world.getBlockState(mutable).getBlock())) {
Vec3i pos = mutable.toImmutable();

if (!this.revealed.contains(pos)) {
if (this.traceForBlock(this.player, pos)) {
this.revealed.add(pos);
this.sendBlockUpdate(new BlockPos(pos), this.player.networkHandler.connection::send);
this.revealed.removeIf(pos -> !pos.isWithinDistance(origin, SEARCH_RADIUS));

for (byte x = -SEARCH_RADIUS; x <= SEARCH_RADIUS; ++x) {
for (byte y = -SEARCH_RADIUS; y <= SEARCH_RADIUS; ++y) {
for (byte z = -SEARCH_RADIUS; z <= SEARCH_RADIUS; ++z) {
if (x * x + y * y + z * z <= SEARCH_RADIUS * SEARCH_RADIUS) {
mutable.set(origin.x, origin.y, origin.z);
mutable.move(x, y, z);

if (Config.HIDDEN.containsKey(this.player.world.getBlockState(mutable).getBlock())) {
Vec3i pos = mutable.toImmutable();

if (!this.revealed.contains(pos)) {
if (this.traceForBlock(this.player, pos)) {
this.revealed.add(pos);
this.sendBlockUpdate(new BlockPos(pos), this.player.networkHandler.connection::send);
}
}
}
}
}
}
}
}
});

thread.setDaemon(true);
thread.start();
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/fabric.mod.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@
"depends": {
"fabricloader": ">=0.8.9+build.203",
"fabric": "*",
"minecraft": "1.16.2"
"minecraft": ">=1.16.2"
}
}

0 comments on commit 1a4b8e5

Please sign in to comment.