Java Code Examples for org.bukkit.Material#isSolid()

The following examples show how to use org.bukkit.Material#isSolid() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Materials.java    From PGM with GNU Affero General Public License v3.0 6 votes vote down vote up
static boolean isSolid(Material material) {
  if (material == null) {
    return false;
  }

  switch (material) {
      // Bukkit considers these "solid" for some reason
    case SIGN_POST:
    case WALL_SIGN:
    case WOOD_PLATE:
    case STONE_PLATE:
    case IRON_PLATE:
    case GOLD_PLATE:
      return false;

    default:
      return material.isSolid();
  }
}
 
Example 2
Source File: LocationUtil.java    From UHC with MIT License 6 votes vote down vote up
protected static boolean canStandOn(Material material) {
    switch (material) {
        // all of these are 'solid' according to Material but I'm treating them as 'unsolid'
        // as you can fall through them on teleport
        case TRAP_DOOR:
        case SPRUCE_DOOR:
        case BIRCH_DOOR:
        case JUNGLE_DOOR:
        case ACACIA_DOOR:
        case DARK_OAK_DOOR:
        case WOODEN_DOOR:
        case IRON_TRAPDOOR:
        // wtf bukkit you can't even stand on these, they have no hitbox
        case WALL_SIGN:
        case SIGN_POST:
        case STONE_PLATE:
        case WOOD_PLATE:
        case GOLD_PLATE:
        case WALL_BANNER:
        case STANDING_BANNER:
            return false;
        default:
            return material.isSolid();
    }
}
 
Example 3
Source File: Materials.java    From ProjectAres with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * Is the given {@link Material} a block that collides with entities?
 *
 * Note that this is not always 100% correct. There are a few blocks for which
 * solidness depends on state, such as fence gates.
 */
public static boolean isColliding(Material material) {
    if(material == null) {
        return false;
    }

    switch(material) {
        // Missing from Bukkit
        case CARPET:
        case WATER_LILY:
            return true;

        // Incorrectly included by Bukkit
        case SIGN_POST:
        case WALL_SIGN:
        case WOOD_PLATE:
        case STONE_PLATE:
        case IRON_PLATE:
        case GOLD_PLATE:
        case STANDING_BANNER:
        case WALL_BANNER:
            return false;

        default:
            return material.isSolid();
    }
}
 
Example 4
Source File: BlockCollisionUtil.java    From QualityArmory with GNU General Public License v3.0 5 votes vote down vote up
public static double getHeight(Block b){
	Material type = b.getType();
	if (b.getType().name().contains("SLAB") || b.getType().name().contains("STEP")) {
		if (b.getData() == 0)
			return 0.5;
		if (b.getData() == 1)
			return 1;
	}
	if(customBlockHeights.containsKey(type))
		return customBlockHeights.get(type);
	return type.isSolid()?1:0;
}
 
Example 5
Source File: PaperPatch.java    From ViaVersion with MIT License 5 votes vote down vote up
private boolean isPlacable(Material material) {
    if (!material.isSolid()) return true;
    // signs and banners
    switch (material.getId()) {
        case 63:
        case 68:
        case 176:
        case 177:
            return true;
        default:
            return false;
    }
}
 
Example 6
Source File: Esp.java    From AACAdditionPro with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Determines if two {@link User}s can see each other.
 */
private boolean canSee(final User observerUser, final User watchedUser)
{
    final Player observer = observerUser.getPlayer();
    final Player watched = watchedUser.getPlayer();

    // Not bypassed
    if (observerUser.isBypassed(this.getModuleType()) ||
        // Has not logged in recently to prevent bugs
        observerUser.hasLoggedInRecently(3000) ||
        // Glowing handling
        // Glowing does not exist in 1.8.8
        (ServerVersion.getActiveServerVersion() != ServerVersion.MC188 &&
         // If an entity is glowing it can always be seen.
         watched.hasPotionEffect(PotionEffectType.GLOWING)))
    {
        return true;
    }

    // ----------------------------------- Calculation ---------------------------------- //

    final Vector[] cameraVectors = VectorUtils.getCameraVectors(observer);

    // Get the Vectors of the hitbox to check.
    final Vector[] watchedHitboxVectors = (watched.isSneaking() ?
                                           Hitbox.ESP_SNEAKING_PLAYER :
                                           Hitbox.ESP_PLAYER).getCalculationVectors(watched.getLocation(), true);

    // The distance of the intersections in the same block is equal as of the
    // BlockIterator mechanics.
    final Set<Double> lastIntersectionsCache = new HashSet<>();

    for (Vector cameraVector : cameraVectors) {
        for (final Vector destinationVector : watchedHitboxVectors) {
            final Location start = cameraVector.toLocation(observer.getWorld());
            // The resulting Vector
            // The camera is not blocked by non-solid blocks
            // Vector is intersecting with some blocks
            //
            // Cloning IS needed as we are in a second loop.
            final Vector between = destinationVector.clone().subtract(cameraVector);

            // ---------------------------------------------- FOV ----------------------------------------------- //
            final Vector cameraRotation = cameraVector.clone().subtract(observer.getLocation().toVector());

            if (cameraRotation.angle(between) > MAX_FOV) {
                continue;
            }

            // ---------------------------------------- Cache Calculation --------------------------------------- //

            // Make sure the chunks are loaded.
            if (!ChunkUtils.areChunksLoadedBetweenLocations(start, start.clone().add(between))) {
                // If the chunks are not loaded assume the players can see each other.
                return true;
            }

            boolean cacheHit = false;

            Location cacheLocation;
            for (Double length : lastIntersectionsCache) {
                cacheLocation = start.clone().add(between.clone().normalize().multiply(length));

                // Not yet cached.
                if (length == 0) {
                    continue;
                }

                final Material type = cacheLocation.getBlock().getType();

                if (BlockUtils.isReallyOccluding(type) && type.isSolid()) {
                    cacheHit = true;
                    break;
                }
            }

            if (cacheHit) {
                continue;
            }

            // --------------------------------------- Normal Calculation --------------------------------------- //

            final double intersect = VectorUtils.getDistanceToFirstIntersectionWithBlock(start, between);

            // No intersection found
            if (intersect == 0) {
                return true;
            }

            lastIntersectionsCache.add(intersect);
        }
    }

    // Low probability to help after the camera view was changed. -> clearing
    lastIntersectionsCache.clear();
    return false;
}
 
Example 7
Source File: ForceField.java    From CombatLogX with GNU General Public License v3.0 4 votes vote down vote up
static boolean canPlace(Location location) {
    Block block = location.getBlock();
    Material type = block.getType();
    return (type == Material.AIR || !type.isSolid());
}
 
Example 8
Source File: DPortal.java    From DungeonsXL with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Create a new DPortal
 *
 * @param player the creator
 */
public void create(DGlobalPlayer player) {
    if (block1 == null || block2 == null) {
        delete();
        return;
    }

    if (player != null && material == VanillaItem.NETHER_PORTAL) {
        float yaw = player.getPlayer().getLocation().getYaw();
        if (yaw >= 45 & yaw < 135 || yaw >= 225 & yaw < 315) {
            zAxis = true;
        } else if (yaw >= 315 | yaw < 45 || yaw >= 135 & yaw < 225) {
            zAxis = false;
        }
    }

    int x1 = block1.getX(), y1 = block1.getY(), z1 = block1.getZ();
    int x2 = block2.getX(), y2 = block2.getY(), z2 = block2.getZ();
    int xcount = 0, ycount = 0, zcount = 0;

    if (x1 > x2) {
        xcount = -1;
    } else if (x1 < x2) {
        xcount = 1;
    }
    if (y1 > y2) {
        ycount = -1;
    } else if (y1 < y2) {
        ycount = 1;
    }
    if (z1 > z2) {
        zcount = -1;
    } else if (z1 < z2) {
        zcount = 1;
    }

    int xx = x1;
    do {
        int yy = y1;

        do {
            int zz = z1;

            do {
                Material type = getWorld().getBlockAt(xx, yy, zz).getType();
                if (!type.isSolid()) {
                    Block block = getWorld().getBlockAt(xx, yy, zz);
                    block.setType(material.getMaterial(), false);
                    if (material == VanillaItem.NETHER_PORTAL) {
                        DungeonsXL.BLOCK_ADAPTER.setAxis(block, zAxis);
                    }
                }

                zz = zz + zcount;
            } while (zz != z2 + zcount);

            yy = yy + ycount;
        } while (yy != y2 + ycount);

        xx = xx + xcount;
    } while (xx != x2 + xcount);

    if (player == null) {
        return;
    }
    player.getPlayer().getInventory().setItemInHand(player.getCachedItem());
    player.setCachedItem(null);

    if (material != VanillaItem.NETHER_PORTAL) {
        player.sendMessage(DMessage.PLAYER_PORTAL_CREATED.getMessage());
        player.setCreatingPortal(null);

    } else {
        ClickEvent onClickYes = new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/dungeonsxl portal NETHER_PORTAL -rotate");
        TextComponent yes = new TextComponent(DMessage.BUTTON_ACCEPT.getMessage());
        yes.setClickEvent(onClickYes);

        ClickEvent onClickNo = new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/dungeonsxl portal NETHER_PORTAL -norotate");
        TextComponent no = new TextComponent(DMessage.BUTTON_DENY.getMessage());
        no.setClickEvent(onClickNo);

        player.sendMessage(DMessage.PLAYER_PORTAL_ROTATE.getMessage());
        MessageUtil.sendMessage(player.getPlayer(), yes, new TextComponent(" "), no);
    }
}
 
Example 9
Source File: Util.java    From ObsidianDestroyer with GNU General Public License v3.0 4 votes vote down vote up
public static boolean isSolid(Material material) {
    return material.isSolid();
}
 
Example 10
Source File: Util.java    From ObsidianDestroyer with GNU General Public License v3.0 4 votes vote down vote up
public static boolean isNonSolid(Material type) {
    return !type.isSolid();
}
 
Example 11
Source File: GenericSuperAxe.java    From NBTEditor with GNU General Public License v3.0 4 votes vote down vote up
private boolean isGround(Material mat) {
	return (!isLog(mat) && !isLeaves(mat) && mat.isSolid());
}