Search in sources :

Example 1 with MutableHitBox

use of net.countercraft.movecraft.util.hitboxes.MutableHitBox in project Movecraft by APDevTeam.

the class TranslationTask method dropDistance.

private int dropDistance(HitBox hitBox) {
    MutableHitBox bottomLocs = new SetHitBox();
    MovecraftLocation corner1 = new MovecraftLocation(hitBox.getMinX(), 0, hitBox.getMinZ());
    MovecraftLocation corner2 = new MovecraftLocation(hitBox.getMaxX(), 0, hitBox.getMaxZ());
    for (MovecraftLocation location : new SolidHitBox(corner1, corner2)) {
        int test = hitBox.getMinYAt(location.getX(), location.getZ());
        if (test == -1) {
            continue;
        }
        bottomLocs.add(new MovecraftLocation(location.getX(), test, location.getZ()));
    }
    int dropDistance = 0;
    int minHeightLimit = (int) craft.getType().getPerWorldProperty(CraftType.PER_WORLD_MIN_HEIGHT_LIMIT, craft.getWorld());
    var passthroughBlocks = craft.getType().getMaterialSetProperty(CraftType.PASSTHROUGH_BLOCKS);
    var harvestBlocks = craft.getType().getMaterialSetProperty(CraftType.HARVEST_BLOCKS);
    var harvestBladeBlocks = craft.getType().getMaterialSetProperty(CraftType.HARVESTER_BLADE_BLOCKS);
    do {
        boolean hitGround = false;
        for (MovecraftLocation ml : bottomLocs) {
            final MovecraftLocation translated = ml.translate(dx, dy, dz);
            // This has to be subtracted by one, or non-passthrough blocks will be within the y drop path
            // obstructing the craft
            MovecraftLocation dropped = translated.translate(0, dropDistance - 1, 0);
            Material testType = dropped.toBukkit(craft.getWorld()).getBlock().getType();
            // Not air
            hitGround = !testType.isAir();
            // Not a passthrough block
            hitGround &= !passthroughBlocks.contains(testType);
            // Not part of the craft
            hitGround &= !hitBox.contains(dropped);
            if (minHeightLimit == translated.translate(0, dropDistance + 1, 0).getY())
                // Don't let the craft fall below the min height limit
                hitGround = true;
            if (harvestBlocks.contains(testType) && harvestBladeBlocks.contains(ml.toBukkit(craft.getWorld()).getBlock().getType()))
                // Allow gravity to harvest blocks on the way down
                hitGround = false;
            if (hitGround) {
                break;
            }
        }
        if (hitGround) {
            break;
        }
        dropDistance--;
    } while (dropDistance > craft.getType().getIntProperty(CraftType.GRAVITY_DROP_DISTANCE));
    return dropDistance;
}
Also used : MutableHitBox(net.countercraft.movecraft.util.hitboxes.MutableHitBox) SolidHitBox(net.countercraft.movecraft.util.hitboxes.SolidHitBox) SetHitBox(net.countercraft.movecraft.util.hitboxes.SetHitBox) Material(org.bukkit.Material) MovecraftLocation(net.countercraft.movecraft.MovecraftLocation)

Example 2 with MutableHitBox

use of net.countercraft.movecraft.util.hitboxes.MutableHitBox in project Movecraft by APDevTeam.

the class TranslationTask method isOnGround.

private boolean isOnGround(HitBox hitBox) {
    MutableHitBox bottomLocs = new SetHitBox();
    MutableHitBox translatedBottomLocs = new SetHitBox();
    if (hitBox.getMinY() <= (int) craft.getType().getPerWorldProperty(CraftType.PER_WORLD_MIN_HEIGHT_LIMIT, craft.getWorld())) {
        return true;
    }
    MovecraftLocation corner1 = new MovecraftLocation(hitBox.getMinX(), 0, hitBox.getMinZ());
    MovecraftLocation corner2 = new MovecraftLocation(hitBox.getMaxX(), 0, hitBox.getMaxZ());
    for (MovecraftLocation location : new SolidHitBox(corner1, corner2)) {
        int test = hitBox.getMinYAt(location.getX(), location.getZ());
        if (test == -1) {
            continue;
        }
        bottomLocs.add(new MovecraftLocation(location.getX(), test, location.getZ()));
    }
    boolean bottomLocsOnGround = false;
    for (MovecraftLocation bottomLoc : bottomLocs) {
        translatedBottomLocs.add(bottomLoc.translate(dx, dy, dz));
        Material testType = bottomLoc.translate(0, -1, 0).toBukkit(craft.getWorld()).getBlock().getType();
        // If the lowest part of the bottom locs touch the ground, return true anyways
        if (testType.isAir())
            continue;
        else if (craft.getType().getMaterialSetProperty(CraftType.PASSTHROUGH_BLOCKS).contains(testType))
            continue;
        else if (craft.getType().getMaterialSetProperty(CraftType.HARVEST_BLOCKS).contains(testType) && craft.getType().getMaterialSetProperty(CraftType.HARVESTER_BLADE_BLOCKS).contains(bottomLoc.toBukkit(craft.getWorld()).getBlock().getType()))
            continue;
        bottomLocsOnGround = true;
    }
    boolean translatedBottomLocsInAir = true;
    for (MovecraftLocation translatedBottomLoc : translatedBottomLocs) {
        MovecraftLocation beneath = translatedBottomLoc.translate(0, -1, 0);
        Material testType = beneath.toBukkit(craft.getWorld()).getBlock().getType();
        final CraftType type = craft.getType();
        if (hitBox.contains(beneath) || bottomLocs.contains(beneath) || testType.isAir() || type.getMaterialSetProperty(CraftType.PASSTHROUGH_BLOCKS).contains(testType) || (type.getMaterialSetProperty(CraftType.HARVEST_BLOCKS).contains(testType) && type.getMaterialSetProperty(CraftType.HARVESTER_BLADE_BLOCKS).contains(translatedBottomLoc.translate(-dx, -dy, -dz).toBukkit(craft.getWorld()).getBlock().getType()))) {
            continue;
        }
        translatedBottomLocsInAir = false;
        break;
    }
    if (Settings.Debug) {
        final Logger log = Movecraft.getInstance().getLogger();
        log.info("Translated bottom locs in air: " + translatedBottomLocsInAir);
        log.info("Bottom locs on ground: " + bottomLocsOnGround);
    }
    if (dy > 0) {
        return bottomLocsOnGround && translatedBottomLocsInAir;
    }
    return !translatedBottomLocsInAir;
}
Also used : MutableHitBox(net.countercraft.movecraft.util.hitboxes.MutableHitBox) SolidHitBox(net.countercraft.movecraft.util.hitboxes.SolidHitBox) SetHitBox(net.countercraft.movecraft.util.hitboxes.SetHitBox) Material(org.bukkit.Material) MovecraftLocation(net.countercraft.movecraft.MovecraftLocation) Logger(java.util.logging.Logger) CraftType(net.countercraft.movecraft.craft.type.CraftType)

Aggregations

MovecraftLocation (net.countercraft.movecraft.MovecraftLocation)2 MutableHitBox (net.countercraft.movecraft.util.hitboxes.MutableHitBox)2 SetHitBox (net.countercraft.movecraft.util.hitboxes.SetHitBox)2 SolidHitBox (net.countercraft.movecraft.util.hitboxes.SolidHitBox)2 Material (org.bukkit.Material)2 Logger (java.util.logging.Logger)1 CraftType (net.countercraft.movecraft.craft.type.CraftType)1