[API] RaycastAPI | Create guns, get towards entity/block
1.0RaycastAPi is the unique API on SpigotMC that allows you to create easily guns and some others.
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:
@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);
}
}
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.
Similar projects
Plugin →Let Me Despawn
Improves performance by tweaking mob despawn rules. Say bye to pesky unintentional persistent mobs.
25MSueta
JourneyMap
Real-time map used for mapping in-game or your browser as you explore.
14.7MSueta
Emotecraft
Create your own emotes in Minecraft.
7.5MSueta
Simple Tpa
A simple tpa plugin which sends requests
5.4MSueta
Common Network
Forge and Fabric Unified Networking Solution
3.9MSueta
Set Home
A lightweight plugin for players to set their homes.
3.8MSueta