HomeJavaMods[API] RaycastAPI | Create guns, get towards entity/block
ModsJava

[API] RaycastAPI | Create guns, get towards entity/block

⬇ Download on Spigot
[​IMG]
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.

[​IMG]
RaycastAPI is able to say you if you hurt something or no.
[​IMG]
------------------------------------------------------------------------------------
RaycastAPI can detect entity collision.
[​IMG]
------------------------------------------------------------------------------------
RaycastAPI can detect block collision.
[​IMG]
------------------------------------------------------------------------------------
RaycastAPI can passthrough desired blocks.
[​IMG]

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. addBypassedMaterial (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 ) ;
        }
    }
[​IMG]
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

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 217 times (via Spigot). Download it and open it directly in the game.

Explore more