-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Better capping in /smite + raycast when no args
- Loading branch information
Showing
2 changed files
with
92 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package me.alexdevs.solstice.util; | ||
|
||
import net.minecraft.server.network.ServerPlayerEntity; | ||
import net.minecraft.util.hit.BlockHitResult; | ||
import net.minecraft.util.math.BlockPos; | ||
import net.minecraft.util.math.Vec3d; | ||
import net.minecraft.world.RaycastContext; | ||
|
||
public class Raycast { | ||
public static BlockHitResult cast(ServerPlayerEntity player, double maxDistance) { | ||
var world = player.getServerWorld(); | ||
var eyePos = player.getEyePos(); | ||
var rotVec = player.getRotationVector(); | ||
|
||
var raycastEnd = eyePos.add(rotVec.multiply(maxDistance)); | ||
|
||
var rcContext = new RaycastContext( | ||
eyePos, | ||
raycastEnd, | ||
RaycastContext.ShapeType.OUTLINE, | ||
RaycastContext.FluidHandling.NONE, | ||
player | ||
); | ||
|
||
return world.raycast(rcContext); | ||
} | ||
|
||
public static BlockPos getBlockPos(ServerPlayerEntity player, double maxDistance) { | ||
var result = cast(player, maxDistance); | ||
if(result.getType() == BlockHitResult.Type.BLOCK) { | ||
return result.getBlockPos(); | ||
} | ||
return null; | ||
} | ||
|
||
public static Vec3d getEntityPos(ServerPlayerEntity player, double maxDistance) { | ||
var result = cast(player, maxDistance); | ||
if(result.getType() == BlockHitResult.Type.ENTITY) { | ||
return result.getPos(); | ||
} | ||
return null; | ||
} | ||
|
||
public static Vec3d getPos(ServerPlayerEntity player, double maxDistance) { | ||
var result = cast(player, maxDistance); | ||
if(result.getType() != BlockHitResult.Type.MISS) { | ||
return result.getPos(); | ||
} | ||
return null; | ||
} | ||
} |