Search in sources :

Example 1 with EngineWorld

use of thpmc.vanilla_source.api.world.cache.EngineWorld in project VanillaSource by TheHollowPlanetMC.

the class EntityFollowGoal method run.

@Override
public void run(GoalSelector goalSelector, Navigator navigator) {
    tick++;
    if (tick % TRACK_INTERVAL != 0) {
        goalSelector.setFinished(true);
        return;
    }
    INMSHandler nmsHandler = VanillaSourceAPI.getInstance().getNMSHandler();
    EngineWorld world = navigator.getEntity().getWorld();
    if (!world.getName().equals(target.getWorld().getName()))
        return;
    Location location = target.getLocation();
    EngineChunk chunk = world.getChunkAt(location.getBlockX() >> 4, location.getBlockZ() >> 4);
    if (chunk == null)
        return;
    for (int dy = 0; dy < 5; dy++) {
        Location l = location.clone().add(new Vector(0, -dy, 0));
        Object nmsBlockData = world.getNMSBlockData(l.getBlockX(), l.getBlockY(), l.getBlockZ());
        if (nmsBlockData == null)
            continue;
        if (nmsHandler.hasCollision(new EngineBlock(world, chunk, l.getBlockX(), l.getBlockY(), l.getBlockZ(), nmsBlockData), navigator.getEntity().getMovementCollideOption())) {
            // Goal set
            navigator.setNavigationGoal(new BlockPosition(l.getBlockX(), l.getBlockY() + 1, l.getBlockZ()));
            break;
        }
    }
    goalSelector.setFinished(true);
}
Also used : EngineChunk(thpmc.vanilla_source.api.world.cache.EngineChunk) BlockPosition(thpmc.vanilla_source.api.entity.ai.pathfinding.BlockPosition) EngineBlock(thpmc.vanilla_source.api.world.block.EngineBlock) EngineWorld(thpmc.vanilla_source.api.world.cache.EngineWorld) INMSHandler(thpmc.vanilla_source.api.nms.INMSHandler) Vector(org.bukkit.util.Vector) Location(org.bukkit.Location)

Example 2 with EngineWorld

use of thpmc.vanilla_source.api.world.cache.EngineWorld in project VanillaSource by TheHollowPlanetMC.

the class NMSHandler method checkUpperBlockHasFluid.

private boolean checkUpperBlockHasFluid(Fluid fluid, EngineBlock block) {
    EngineWorld world = block.getWorld();
    IBlockData upperBlockData = (IBlockData) world.getNMSBlockData(block.getX(), block.getY() + 1, block.getZ());
    if (upperBlockData == null)
        return false;
    return fluid.getType().a(upperBlockData.getFluid().getType());
}
Also used : EngineWorld(thpmc.vanilla_source.api.world.cache.EngineWorld)

Aggregations

EngineWorld (thpmc.vanilla_source.api.world.cache.EngineWorld)2 Location (org.bukkit.Location)1 Vector (org.bukkit.util.Vector)1 BlockPosition (thpmc.vanilla_source.api.entity.ai.pathfinding.BlockPosition)1 INMSHandler (thpmc.vanilla_source.api.nms.INMSHandler)1 EngineBlock (thpmc.vanilla_source.api.world.block.EngineBlock)1 EngineChunk (thpmc.vanilla_source.api.world.cache.EngineChunk)1