Search in sources :

Example 1 with BitmapHitBox

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

the class CollectionUtils method filter.

@NotNull
@Contract(pure = true)
@Deprecated
public static BitmapHitBox filter(@NotNull final HitBox collection, @NotNull final HitBox filter) {
    final BitmapHitBox returnList = new BitmapHitBox();
    int counter = filter.size();
    for (MovecraftLocation object : collection) {
        if (counter <= 0 || !filter.contains(object)) {
            returnList.add(object);
        } else {
            counter--;
        }
    }
    return returnList;
}
Also used : MovecraftLocation(net.countercraft.movecraft.MovecraftLocation) BitmapHitBox(net.countercraft.movecraft.util.hitboxes.BitmapHitBox) NotNull(org.jetbrains.annotations.NotNull) Contract(org.jetbrains.annotations.Contract)

Example 2 with BitmapHitBox

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

Example 3 with BitmapHitBox

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

the class DetectionTask method get.

@Override
public Effect get() {
    frontier();
    if (!illegal.isEmpty())
        return null;
    var result = COMPLETION_VALIDATORS.stream().reduce(DetectionPredicate::and).orElse((a, b, c, d) -> Result.fail()).validate(materials, type, movecraftWorld, player);
    result = result.isSucess() ? VISITED_VALIDATORS.stream().reduce(DetectionPredicate::and).orElse((a, b, c, d) -> Result.fail()).validate(visitedMaterials, type, movecraftWorld, player) : result;
    if (!result.isSucess()) {
        String message = result.getMessage();
        return () -> audience.sendMessage(Component.text(message));
    }
    var hitbox = new BitmapHitBox(legal);
    var parents = findParents(hitbox);
    var supplied = supplier.apply(type, world, player, parents);
    result = supplied.getLeft();
    Craft craft = supplied.getRight();
    if (type.getBoolProperty(CraftType.MUST_BE_SUBCRAFT) && !(craft instanceof SubCraft)) {
        result = Result.failWithMessage(I18nSupport.getInternationalisedString("Detection - Must Be Subcraft"));
    }
    if (!result.isSucess()) {
        String message = result.getMessage();
        return () -> audience.sendMessage(Component.text(message));
    }
    craft.setAudience(audience);
    craft.setHitBox(hitbox);
    craft.setFluidLocations(new BitmapHitBox(fluid));
    craft.setOrigBlockCount(craft.getHitBox().size());
    final CraftDetectEvent event = new CraftDetectEvent(craft, startLocation);
    WorldManager.INSTANCE.executeMain(() -> Bukkit.getPluginManager().callEvent(event));
    if (event.isCancelled())
        return () -> craft.getAudience().sendMessage(Component.text(event.getFailMessage()));
    return ((Effect) () -> {
        // Notify player and console
        craft.getAudience().sendMessage(Component.text(String.format("%s Size: %s", I18nSupport.getInternationalisedString("Detection - Successfully piloted craft"), craft.getHitBox().size())));
        Movecraft.getInstance().getLogger().info(String.format(I18nSupport.getInternationalisedString("Detection - Success - Log Output"), player == null ? "null" : player.getName(), craft.getType().getStringProperty(CraftType.NAME), craft.getHitBox().size(), craft.getHitBox().getMinX(), craft.getHitBox().getMinZ()));
    }).andThen(// TODO: Remove
    water(craft)).andThen(// Fire off pilot event
    () -> Bukkit.getServer().getPluginManager().callEvent(new CraftPilotEvent(craft, CraftPilotEvent.Reason.PLAYER))).andThen(// Apply post detection effect
    postDetection.apply(craft)).andThen(// Add craft to CraftManager
    () -> CraftManager.getInstance().add(craft));
}
Also used : AllowedBlockValidator(net.countercraft.movecraft.processing.tasks.detection.validators.AllowedBlockValidator) Arrays(java.util.Arrays) CraftDetectEvent(net.countercraft.movecraft.events.CraftDetectEvent) MovecraftWorld(net.countercraft.movecraft.processing.MovecraftWorld) Player(org.bukkit.entity.Player) Location(org.bukkit.Location) World(org.bukkit.World) Map(java.util.Map) FlyBlockValidator(net.countercraft.movecraft.processing.tasks.detection.validators.FlyBlockValidator) CraftManager(net.countercraft.movecraft.craft.CraftManager) Material(org.bukkit.Material) Effect(net.countercraft.movecraft.processing.effects.Effect) Bukkit(org.bukkit.Bukkit) Result(net.countercraft.movecraft.processing.functions.Result) CraftType(net.countercraft.movecraft.craft.type.CraftType) PilotSignValidator(net.countercraft.movecraft.processing.tasks.detection.validators.PilotSignValidator) Craft(net.countercraft.movecraft.craft.Craft) BitmapHitBox(net.countercraft.movecraft.util.hitboxes.BitmapHitBox) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Set(java.util.Set) AtomicLocationSet(net.countercraft.movecraft.util.AtomicLocationSet) Movecraft(net.countercraft.movecraft.Movecraft) I18nSupport(net.countercraft.movecraft.localisation.I18nSupport) Collectors(java.util.stream.Collectors) Nullable(org.jetbrains.annotations.Nullable) List(java.util.List) CraftSupplier(net.countercraft.movecraft.processing.functions.CraftSupplier) WaterContactValidator(net.countercraft.movecraft.processing.tasks.detection.validators.WaterContactValidator) Queue(java.util.Queue) DetectionPredicate(net.countercraft.movecraft.processing.functions.DetectionPredicate) NotNull(org.jetbrains.annotations.NotNull) MovecraftLocation(net.countercraft.movecraft.MovecraftLocation) SubCraft(net.countercraft.movecraft.craft.SubCraft) ConcurrentLinkedQueue(java.util.concurrent.ConcurrentLinkedQueue) LongAdder(java.util.concurrent.atomic.LongAdder) CollectionUtils(net.countercraft.movecraft.util.CollectionUtils) SolidHitBox(net.countercraft.movecraft.util.hitboxes.SolidHitBox) Deque(java.util.Deque) Function(java.util.function.Function) Supplier(java.util.function.Supplier) CraftPilotEvent(net.countercraft.movecraft.events.CraftPilotEvent) ArrayList(java.util.ArrayList) ConcurrentMap(java.util.concurrent.ConcurrentMap) HashSet(java.util.HashSet) Lists(com.google.common.collect.Lists) NameSignValidator(net.countercraft.movecraft.processing.tasks.detection.validators.NameSignValidator) Component(net.kyori.adventure.text.Component) WorldManager(net.countercraft.movecraft.processing.WorldManager) HitBox(net.countercraft.movecraft.util.hitboxes.HitBox) Functions(com.google.common.base.Functions) ForkJoinTask(java.util.concurrent.ForkJoinTask) ForbiddenSignStringValidator(net.countercraft.movecraft.processing.tasks.detection.validators.ForbiddenSignStringValidator) SetHitBox(net.countercraft.movecraft.util.hitboxes.SetHitBox) ForbiddenBlockValidator(net.countercraft.movecraft.processing.tasks.detection.validators.ForbiddenBlockValidator) ConcurrentLinkedDeque(java.util.concurrent.ConcurrentLinkedDeque) Tags(net.countercraft.movecraft.util.Tags) Audience(net.kyori.adventure.audience.Audience) ForkJoinPool(java.util.concurrent.ForkJoinPool) SizeValidator(net.countercraft.movecraft.processing.tasks.detection.validators.SizeValidator) Comparator(java.util.Comparator) Collections(java.util.Collections) Craft(net.countercraft.movecraft.craft.Craft) SubCraft(net.countercraft.movecraft.craft.SubCraft) CraftDetectEvent(net.countercraft.movecraft.events.CraftDetectEvent) SubCraft(net.countercraft.movecraft.craft.SubCraft) DetectionPredicate(net.countercraft.movecraft.processing.functions.DetectionPredicate) BitmapHitBox(net.countercraft.movecraft.util.hitboxes.BitmapHitBox) CraftPilotEvent(net.countercraft.movecraft.events.CraftPilotEvent)

Aggregations

MovecraftLocation (net.countercraft.movecraft.MovecraftLocation)3 BitmapHitBox (net.countercraft.movecraft.util.hitboxes.BitmapHitBox)3 NotNull (org.jetbrains.annotations.NotNull)3 HashSet (java.util.HashSet)2 Movecraft (net.countercraft.movecraft.Movecraft)2 HitBox (net.countercraft.movecraft.util.hitboxes.HitBox)2 SetHitBox (net.countercraft.movecraft.util.hitboxes.SetHitBox)2 SolidHitBox (net.countercraft.movecraft.util.hitboxes.SolidHitBox)2 Location (org.bukkit.Location)2 Functions (com.google.common.base.Functions)1 Lists (com.google.common.collect.Lists)1 ArrayList (java.util.ArrayList)1 Arrays (java.util.Arrays)1 Collections (java.util.Collections)1 Comparator (java.util.Comparator)1 Deque (java.util.Deque)1 List (java.util.List)1 Map (java.util.Map)1 Queue (java.util.Queue)1 Set (java.util.Set)1