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;
}
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);
}
}
};
}
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));
}
Aggregations