下面列出了org.bukkit.util.Vector#subtract ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
private void setDirectionalBlockFace(Location b, BlockData bd, Player p) {
if (bd instanceof Directional) {
Vector dir = new Vector(b.getX() + 0.5d, b.getY() + 0.5d, b.getZ() + 0.5d);
dir.subtract(p.getEyeLocation().toVector());
double absX = Math.abs(dir.getX());
double absY = Math.abs(dir.getY());
double absZ = Math.abs(dir.getZ());
if (((Directional) bd).getFaces().contains(BlockFace.UP) && ((Directional) bd).getFaces().contains(BlockFace.DOWN)) {
if (absX >= absY && absX >= absZ) {
((Directional) bd).setFacing(dir.getX() > 0 ? BlockFace.WEST : BlockFace.EAST);
} else if (absY >= absX && absY >= absZ) {
((Directional) bd).setFacing(dir.getY() > 0 ? BlockFace.DOWN : BlockFace.UP);
} else {
((Directional) bd).setFacing(dir.getZ() > 0 ? BlockFace.NORTH : BlockFace.SOUTH);
}
} else {
if (absX >= absZ) {
((Directional) bd).setFacing(dir.getX() > 0 ? BlockFace.WEST : BlockFace.EAST);
} else {
((Directional) bd).setFacing(dir.getZ() > 0 ? BlockFace.NORTH : BlockFace.SOUTH);
}
}
}
}
public boolean overlaps(AABB other) {
if (other == null) {
return false;
}
//this.showDebugBlocks(ItemManager.getId(Material.DIAMOND_BLOCK), ItemManager.getId(Material.DIAMOND_BLOCK));
//other.showDebugBlocks(ItemManager.getId(Material.GOLD_BLOCK), ItemManager.getId(Material.GOLD_BLOCK));
Vector t = new Vector();
t.copy(other.getPosition());
t.subtract(getPosition());
return (Math.abs(t.getX()) < (getExtents().getX() + other.getExtents().getX()) &&
Math.abs(t.getY()) < (getExtents().getY() + other.getExtents().getY()) &&
Math.abs(t.getZ()) < (getExtents().getZ() + other.getExtents().getZ()));
}
private Vector getVector(Location fromLoc, Location toLoc) {
if(fromLoc == null || toLoc == null) return null;
Vector fromVec = fromLoc.toVector();
Vector toVec = toLoc.toVector();
Vector subtract = fromVec.subtract(toVec);
Vector normal = subtract.normalize();
NoEntryHandler handler = getNoEntryHandler();
double strength = handler.getNoEntryKnockbackStrength();
Vector multiply = normal.multiply(strength);
return makeFinite(multiply);
}
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
public void onBlockBreak(BlockBreakEvent event) {
if (event == null || !terraformEnabled) {
return;
}
Block block = event.getBlock();
Player player = event.getPlayer();
if (!plugin.getWorldManager().isSkyNether(block.getWorld()) || !plugin.getWorldManager().isSkyNether(player.getWorld())) {
return; // Bail out, not our problem
}
if (player.getGameMode() != GameMode.SURVIVAL) {
return;
}
if (!plugin.playerIsOnIsland(player)) {
return;
}
if (!terraFormMap.containsKey(block.getType())) {
return; // Not a block we terra-form on.
}
// TODO: 10/07/2016 - R4zorax: Handle dual-wielding (would break 1.8 compatibility)
ItemStack tool = event.getPlayer().getItemInHand();
if (event.getBlock().getDrops(tool).isEmpty()) {
return; // Only terra-form when stuff is mined correctly
}
double toolWeight = getToolWeight(tool);
Location playerLocation = player.getEyeLocation();
Location blockLocation = LocationUtil.centerInBlock(block.getLocation());
Vector v = new Vector(blockLocation.getX(), blockLocation.getY(), blockLocation.getZ());
v.subtract(new Vector(playerLocation.getX(), playerLocation.getY(), playerLocation.getZ()));
v.normalize();
// Disable spawning above the player... enabling the player to clear a region
if (playerLocation.getPitch() >= minPitch && playerLocation.getPitch() <= maxPitch) {
ProtectedCuboidRegion islandRegion = WorldGuardHandler.getIslandRegion(playerLocation);
List<Material> yield = getYield(block.getType(), toolWeight);
for (Material mat : yield) {
spawnBlock(mat, blockLocation, v, islandRegion);
}
}
}