Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,13 @@ private static void performPingAction(float tickDelta) {
cameraEntity.isCrouching());

if (hitResult == null || hitResult.getType() == HitResult.Type.MISS) {
if (ModContext.HasVoxy) {
var voxyHitResult = Raycast.traceVoxy(cameraDirection, tickDelta, CLIENT_CONFIG.getPingDistance());
if (voxyHitResult != null && voxyHitResult.getType() != HitResult.Type.MISS) {
IPlatformNetworkService.INSTANCE.sendToServer(new PingLocationC2SPacket(CLIENT_CONFIG.getChannel(), voxyHitResult.getLocation(), null, pingSequence, GameContext.getDimension()));
return;
}
}
if (ModContext.HasDistantHorizons) {
Raycast.traceDistantAsync(cameraDirection, tickDelta, (distantHitResult) -> {
IPlatformNetworkService.INSTANCE.sendToServer(new PingLocationC2SPacket(CLIENT_CONFIG.getChannel(), distantHitResult.getLocation(), null, pingSequence, GameContext.getDimension()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,13 @@ public class ModContext {
private ModContext() {}

public static boolean HasDistantHorizons = false;
public static boolean HasVoxy = false;
public static boolean HasVoiceChat = false;
public static boolean HasFTBTeams = false;

public static void indexMods() {
HasDistantHorizons = IPlatformContextService.INSTANCE.isModLoaded("distanthorizons");
HasVoxy = IPlatformContextService.INSTANCE.isModLoaded("voxy");
HasVoiceChat = IPlatformContextService.INSTANCE.isModLoaded("voicechat");
HasFTBTeams = IPlatformContextService.INSTANCE.isModLoaded("ftbteams");

Expand Down
38 changes: 38 additions & 0 deletions common/src/main/java/nx/pingwheel/common/math/Raycast.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import net.minecraft.world.level.ClipContext;
import net.minecraft.world.phys.*;

import java.lang.reflect.Method;
import java.time.Duration;
import java.time.Instant;
import java.util.Optional;
Expand Down Expand Up @@ -69,6 +70,43 @@ public static void traceDistantAsync(Vec3 direction, float tickDelta, Consumer<B
ft.thenAccept(result -> Optional.ofNullable(result).ifPresent(callback));
}

public static BlockHitResult traceVoxy(Vec3 direction, float tickDelta, double maxDistance) {
try {
var cameraEntity = Game.getCameraEntity();

if (cameraEntity == null || cameraEntity.level() == null) {
return null;
}

var rayStartVec = cameraEntity.getEyePosition(tickDelta);

var apiClass = Class.forName("me.cortex.voxy.client.api.VoxyRaycastAPI");
var raycastMethod = apiClass.getMethod("raycast",
net.minecraft.world.level.Level.class,
Vec3.class,
Vec3.class,
double.class);
var result = raycastMethod.invoke(null,
cameraEntity.level(),
rayStartVec,
direction,
maxDistance);

if (result == null) {
return null;
}

var resultClass = result.getClass();
var pos = (BlockPos) resultClass.getMethod("blockPos").invoke(result);
var hitLoc = (Vec3) resultClass.getMethod("hitLocation").invoke(result);
var face = (Direction) resultClass.getMethod("face").invoke(result);

return new BlockHitResult(hitLoc, face, pos, true);
} catch (Exception e) {
return null;
}
}

public static HitResult traceDirectional(Vec3 direction,
float tickDelta,
double maxDistance,
Expand Down