Search in sources :

Example 1 with SolidHitBox

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

the class TreeHitBoxTest method testSinglePointIterator.

@Test
public void testSinglePointIterator() {
    for (var location : new SolidHitBox(new MovecraftLocation(-3, -3, -3), new MovecraftLocation(3, 3, 3))) {
        SetHitBox box = new SetHitBox();
        box.add(location);
        assertEquals(location, box.iterator().next());
    }
}
Also used : SolidHitBox(net.countercraft.movecraft.util.hitboxes.SolidHitBox) SetHitBox(net.countercraft.movecraft.util.hitboxes.SetHitBox) Test(org.junit.Test)

Example 2 with SolidHitBox

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

the class TreeHitBoxTest method testLargeHitBox.

@Test
@Ignore
public void testLargeHitBox() {
    SolidHitBox solid = new SolidHitBox(new MovecraftLocation(-100, -100, -100), new MovecraftLocation(100, 100, 100));
    SetHitBox hitBox = new SetHitBox();
    hitBox.addAll(solid);
    assertEquals(solid.size(), hitBox.size());
    assertEquals(solid.size(), Iterators.size(hitBox.iterator()));
    assertTrue(hitBox.containsAll(solid.asSet()));
}
Also used : SolidHitBox(net.countercraft.movecraft.util.hitboxes.SolidHitBox) SetHitBox(net.countercraft.movecraft.util.hitboxes.SetHitBox) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 3 with SolidHitBox

use of net.countercraft.movecraft.util.hitboxes.SolidHitBox 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 4 with SolidHitBox

use of net.countercraft.movecraft.util.hitboxes.SolidHitBox 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)

Example 5 with SolidHitBox

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

the class DetectionTask method water.

@Deprecated
@NotNull
private Effect water(@NotNull Craft craft) {
    final int waterLine = WorldManager.INSTANCE.executeMain(craft::getWaterLine);
    if (craft.getType().getBoolProperty(CraftType.BLOCKED_BY_WATER) || craft.getHitBox().getMinY() > waterLine)
        return () -> {
        };
    var badWorld = WorldManager.INSTANCE.executeMain(craft::getWorld);
    // The subtraction of the set of coordinates in the HitBox cube and the HitBox itself
    final HitBox invertedHitBox = new BitmapHitBox(craft.getHitBox().boundingHitBox()).difference(craft.getHitBox());
    // A set of locations that are confirmed to be "exterior" locations
    final SetHitBox confirmed = new SetHitBox();
    final SetHitBox entireHitbox = new SetHitBox(craft.getHitBox());
    // place phased blocks
    final Set<Location> overlap = new HashSet<>(craft.getPhaseBlocks().keySet());
    overlap.retainAll(craft.getHitBox().asSet().stream().map(l -> l.toBukkit(badWorld)).collect(Collectors.toSet()));
    final int minX = craft.getHitBox().getMinX();
    final int maxX = craft.getHitBox().getMaxX();
    final int minY = craft.getHitBox().getMinY();
    final int maxY = overlap.isEmpty() ? craft.getHitBox().getMaxY() : Collections.max(overlap, Comparator.comparingInt(Location::getBlockY)).getBlockY();
    final int minZ = craft.getHitBox().getMinZ();
    final int maxZ = craft.getHitBox().getMaxZ();
    final HitBox[] surfaces = { new SolidHitBox(new MovecraftLocation(minX, minY, minZ), new MovecraftLocation(minX, maxY, maxZ)), new SolidHitBox(new MovecraftLocation(minX, minY, minZ), new MovecraftLocation(maxX, maxY, minZ)), new SolidHitBox(new MovecraftLocation(maxX, minY, maxZ), new MovecraftLocation(minX, maxY, maxZ)), new SolidHitBox(new MovecraftLocation(maxX, minY, maxZ), new MovecraftLocation(maxX, maxY, minZ)), new SolidHitBox(new MovecraftLocation(minX, minY, minZ), new MovecraftLocation(maxX, minY, maxZ)) };
    final SetHitBox validExterior = new SetHitBox();
    for (HitBox hitBox : surfaces) {
        validExterior.addAll(new BitmapHitBox(hitBox).difference(craft.getHitBox()));
    }
    // Check to see which locations in the from set are actually outside of the craft
    // use a modified BFS for multiple origin elements
    SetHitBox visited = new SetHitBox();
    Queue<MovecraftLocation> queue = Lists.newLinkedList(validExterior);
    while (!queue.isEmpty()) {
        MovecraftLocation node = queue.poll();
        if (visited.contains(node))
            continue;
        visited.add(node);
        // If the node is already a valid member of the exterior of the HitBox, continued search is unitary.
        for (MovecraftLocation neighbor : CollectionUtils.neighbors(invertedHitBox, node)) {
            queue.add(neighbor);
        }
    }
    confirmed.addAll(visited);
    entireHitbox.addAll(invertedHitBox.difference(confirmed));
    var waterData = Bukkit.createBlockData(Material.WATER);
    return () -> {
        for (MovecraftLocation location : entireHitbox) {
            if (location.getY() <= waterLine) {
                craft.getPhaseBlocks().put(location.toBukkit(badWorld), waterData);
            }
        }
    };
}
Also used : BitmapHitBox(net.countercraft.movecraft.util.hitboxes.BitmapHitBox) SolidHitBox(net.countercraft.movecraft.util.hitboxes.SolidHitBox) HitBox(net.countercraft.movecraft.util.hitboxes.HitBox) SetHitBox(net.countercraft.movecraft.util.hitboxes.SetHitBox) SolidHitBox(net.countercraft.movecraft.util.hitboxes.SolidHitBox) Movecraft(net.countercraft.movecraft.Movecraft) SetHitBox(net.countercraft.movecraft.util.hitboxes.SetHitBox) BitmapHitBox(net.countercraft.movecraft.util.hitboxes.BitmapHitBox) MovecraftLocation(net.countercraft.movecraft.MovecraftLocation) Location(org.bukkit.Location) MovecraftLocation(net.countercraft.movecraft.MovecraftLocation) HashSet(java.util.HashSet) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

SolidHitBox (net.countercraft.movecraft.util.hitboxes.SolidHitBox)11 SetHitBox (net.countercraft.movecraft.util.hitboxes.SetHitBox)10 MovecraftLocation (net.countercraft.movecraft.MovecraftLocation)6 HashSet (java.util.HashSet)5 HitBox (net.countercraft.movecraft.util.hitboxes.HitBox)4 Material (org.bukkit.Material)4 Test (org.junit.Test)4 Logger (java.util.logging.Logger)3 Location (org.bukkit.Location)3 LinkedList (java.util.LinkedList)2 Movecraft (net.countercraft.movecraft.Movecraft)2 WorldHandler (net.countercraft.movecraft.WorldHandler)2 Craft (net.countercraft.movecraft.craft.Craft)2 SinkingCraft (net.countercraft.movecraft.craft.SinkingCraft)2 CraftType (net.countercraft.movecraft.craft.type.CraftType)2 MutableHitBox (net.countercraft.movecraft.util.hitboxes.MutableHitBox)2 Waterlogged (org.bukkit.block.data.Waterlogged)2 NotNull (org.jetbrains.annotations.NotNull)2 Lists (com.google.common.collect.Lists)1 Sets (com.google.common.collect.Sets)1