版本更新至:3.76
调整:开发框架改为 Gradle 新增:Language2 工具新增 [book] 类型
This commit is contained in:
51
src/main/java/me/skymc/taboolib/inventory/DropUtils.java
Normal file
51
src/main/java/me/skymc/taboolib/inventory/DropUtils.java
Normal file
@@ -0,0 +1,51 @@
|
||||
package me.skymc.taboolib.inventory;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Item;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.util.Vector;
|
||||
|
||||
import me.skymc.taboolib.other.NumberUtils;
|
||||
|
||||
public class DropUtils {
|
||||
|
||||
public static Item drop(Player player, ItemStack itemStack, double bulletSpread, double radius) {
|
||||
Location location = player.getLocation();
|
||||
location.setY(location.getY() + 1.5);
|
||||
|
||||
Item item = player.getWorld().dropItem(location, itemStack);
|
||||
|
||||
double yaw = Math.toRadians(-player.getLocation().getYaw() - 90.0F);
|
||||
double pitch = Math.toRadians(-player.getLocation().getPitch());
|
||||
|
||||
double x = 0;
|
||||
double y = 0;
|
||||
double z = 0;
|
||||
|
||||
if (bulletSpread > 0) {
|
||||
double[] spread = { 1.0D, 1.0D, 1.0D };
|
||||
for (int t = 0; t < 3; t++) {
|
||||
spread[t] = ((NumberUtils.getRand().nextDouble() - NumberUtils.getRand().nextDouble()) * bulletSpread * 0.1D);
|
||||
}
|
||||
|
||||
x = Math.cos(pitch) * Math.cos(yaw) + spread[0];
|
||||
y = Math.sin(pitch) + spread[1];
|
||||
z = -Math.sin(yaw) * Math.cos(pitch) + spread[2];
|
||||
}
|
||||
else {
|
||||
x = Math.cos(pitch) * Math.cos(yaw);
|
||||
y = Math.sin(pitch);
|
||||
z = -Math.sin(yaw) * Math.cos(pitch);
|
||||
}
|
||||
Vector dirVel = new Vector(x, y, z);
|
||||
dirVel.normalize().multiply(radius);
|
||||
|
||||
item.setVelocity(dirVel);
|
||||
return item;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user