RaycastAPI is the unique API on SpigotMC that allows you to creates raycast.
You can use it to make guns, tools. It can be use to get the towards entity/block.
RaycastAPI is able to say you if you hurt something or no.
------------------------------------------------------------------------------------
RaycastAPI can detect entity collision.
------------------------------------------------------------------------------------
RaycastAPI can detect block collision.
------------------------------------------------------------------------------------
RaycastAPI can passthrough desired blocks.
Example code:
Code (Java):
@EventHandler
public void whenClick ( PlayerInteractEvent e ) {
Player player = e. getPlayer ( ) ;
ItemStack i = e. getPlayer ( ) . getItemInHand ( ) ;
if ( i == null || i. getType ( ) == Material. AIR )
return ;
if ( e. getAction ( ) == Action . LEFT_CLICK_AIR && i. hasItemMeta ( ) && i. getItemMeta ( ) . hasDisplayName ( ) && i. getItemMeta ( ) . getDisplayName ( ) . equals ( "gun" ) ) {
Raycast raycast = new Raycast ( e. getPlayer ( ) . getEyeLocation ( ) , 100 ) ;
raycast. addPassthroughMaterial ( Material. LEAVES ) ;
raycast. setOwner ( player ) ;
raycast. setShowRayCast ( true ) ;
if ( raycast. compute ( RaycastType. ENTITY_AND_BLOCK ) ) {
player. sendMessage ( "§aRaycast hurt something" ) ;
Location hurtLocation = raycast. getHurtLocation ( ) ;
player. sendMessage ( "§cRaycast hurt " + ( ( raycast. getHurtBlock ( ) != null ) ? "a block " : "an entity" ) + " at X:" + hurtLocation. getBlockX ( ) + " Y: " + hurtLocation. getBlockY ( ) + " Z:" + hurtLocation. getBlockZ ( ) ) ;
} else {
player. sendMessage ( "§6Raycast hurt nothing" ) ;
}
e. setCancelled ( true ) ;
}
}
public void whenClick ( PlayerInteractEvent e ) {
Player player = e. getPlayer ( ) ;
ItemStack i = e. getPlayer ( ) . getItemInHand ( ) ;
if ( i == null || i. getType ( ) == Material. AIR )
return ;
if ( e. getAction ( ) == Action . LEFT_CLICK_AIR && i. hasItemMeta ( ) && i. getItemMeta ( ) . hasDisplayName ( ) && i. getItemMeta ( ) . getDisplayName ( ) . equals ( "gun" ) ) {
Raycast raycast = new Raycast ( e. getPlayer ( ) . getEyeLocation ( ) , 100 ) ;
raycast. addPassthroughMaterial ( Material. LEAVES ) ;
raycast. setOwner ( player ) ;
raycast. setShowRayCast ( true ) ;
if ( raycast. compute ( RaycastType. ENTITY_AND_BLOCK ) ) {
player. sendMessage ( "§aRaycast hurt something" ) ;
Location hurtLocation = raycast. getHurtLocation ( ) ;
player. sendMessage ( "§cRaycast hurt " + ( ( raycast. getHurtBlock ( ) != null ) ? "a block " : "an entity" ) + " at X:" + hurtLocation. getBlockX ( ) + " Y: " + hurtLocation. getBlockY ( ) + " Z:" + hurtLocation. getBlockZ ( ) ) ;
} else {
player. sendMessage ( "§6Raycast hurt nothing" ) ;
}
e. setCancelled ( true ) ;
}
}
Three types of raycast:
BLOCK -> If you want to detect block collision
ENTITY -> If you want to detect entity collision
ENTITY_AND_BLOCK -> If you want to detect entity or block collision.
--------------------------------------------------
Constructor: Location -> Start location of the ray | Size -> The length of the ray
Raycast#compute(raycastType)
-> Execute the raycast and return boolean (return true if collid with something)
Raycast#getPassthroughMaterials()
-> Return passthrough materials
Raycast#setPassthroughMaterials(ArrayList<Material> passthroughMaterials)
-> Set passthrough materials
Raycast#addPassthroughMaterial(Material mat)
-> Add passthrough material
Raycast#getTestedLocations()
-> Return returns all the locations where the ray has passed
Raycast#getHurtEntity()
-> Return hurted entity. Null if no entity hurted.
Raycast#getHurtBlock()
-> Return hurted block. Null if no block hurted.
Raycast#getHurtLocation()
-> Return the location where the ray hurt something. Null if nothing hurted
Raycast#setShowRayCast(boolean)
-> Show in the world the ray if true when compute() is executed.
Raycast#setOwner(entity)
-> If the ray is emitted by an entity you can set the entity at owner. The ray passthrough the owner.
Quick facts
- Edition: Minecraft Java
- File type: .jar
- Minecraft versions listed: 1.7, 1.8, 1.9
- How to install: Install the matching mod loader (Forge, Fabric or NeoForge) for your Minecraft version. → Download the .jar. → Put it in the .minecraft/mods folder and launch that loader profile.
- Where to get it: Opens on Spigot — not every file is mirrored on our own servers.
Install steps are the general flow for this file type — How to install Minecraft Java mods & modpacks walks through it step by step.
[API] RaycastAPI | Create guns, get towards entity/block is a free Minecraft Java mod. Compatible with Minecraft 1.7, 1.8, 1.9, 1.10 and newer. Downloaded 389 times (via Spigot). Download it and open it directly in the game.