Search in sources :

Example 1 with Vector3i

use of org.spongepowered.math.vector.Vector3i in project SpongeCommon by SpongePowered.

the class ObjectArrayMutableEntityBuffer method blockStateStream.

@Override
public VolumeStream<EntityVolume.Mutable, BlockState> blockStateStream(final Vector3i min, final Vector3i max, final StreamOptions options) {
    VolumeStreamUtils.validateStreamArgs(min, max, this.min(), this.max(), options);
    final ArrayMutableBlockBuffer buffer;
    if (options.carbonCopy()) {
        buffer = this.blockBuffer.copy();
    } else {
        buffer = this.blockBuffer;
    }
    final Stream<VolumeElement<EntityVolume.Mutable, BlockState>> stateStream = IntStream.range(min.x(), max.x() + 1).mapToObj(x -> IntStream.range(min.z(), max.z() + 1).mapToObj(z -> IntStream.range(min.y(), max.y() + 1).mapToObj(y -> VolumeElement.of((EntityVolume.Mutable) this, () -> buffer.block(x, y, z), new Vector3d(x, y, z)))).flatMap(Function.identity())).flatMap(Function.identity());
    return new SpongeVolumeStream<>(stateStream, () -> this);
}
Also used : IntStream(java.util.stream.IntStream) DataContainer(org.spongepowered.api.data.persistence.DataContainer) FluidState(org.spongepowered.api.fluid.FluidState) ArrayMutableBlockBuffer(org.spongepowered.common.world.volume.buffer.block.ArrayMutableBlockBuffer) VolumeElement(org.spongepowered.api.world.volume.stream.VolumeElement) AABB(org.spongepowered.api.util.AABB) Function(java.util.function.Function) ArrayList(java.util.ArrayList) EntityVolume(org.spongepowered.api.world.volume.entity.EntityVolume) ImmutableList(com.google.common.collect.ImmutableList) SpongeVolumeStream(org.spongepowered.common.world.volume.SpongeVolumeStream) StreamSupport(java.util.stream.StreamSupport) Nullable(org.checkerframework.checker.nullness.qual.Nullable) AbstractBlockBuffer(org.spongepowered.common.world.volume.buffer.block.AbstractBlockBuffer) VolumeStream(org.spongepowered.api.world.volume.stream.VolumeStream) Predicate(java.util.function.Predicate) Collection(java.util.Collection) StreamOptions(org.spongepowered.api.world.volume.stream.StreamOptions) Palette(org.spongepowered.api.world.schematic.Palette) UUID(java.util.UUID) Entity(org.spongepowered.api.entity.Entity) Collectors(java.util.stream.Collectors) BlockState(org.spongepowered.api.block.BlockState) Objects(java.util.Objects) List(java.util.List) Stream(java.util.stream.Stream) Vector3d(org.spongepowered.math.vector.Vector3d) VolumeStreamUtils(org.spongepowered.common.world.volume.VolumeStreamUtils) BlockType(org.spongepowered.api.block.BlockType) EntityType(org.spongepowered.api.entity.EntityType) Optional(java.util.Optional) Player(org.spongepowered.api.entity.living.player.Player) Vector3i(org.spongepowered.math.vector.Vector3i) EntityVolume(org.spongepowered.api.world.volume.entity.EntityVolume) Vector3d(org.spongepowered.math.vector.Vector3d) ArrayMutableBlockBuffer(org.spongepowered.common.world.volume.buffer.block.ArrayMutableBlockBuffer) VolumeElement(org.spongepowered.api.world.volume.stream.VolumeElement) SpongeVolumeStream(org.spongepowered.common.world.volume.SpongeVolumeStream)

Example 2 with Vector3i

use of org.spongepowered.math.vector.Vector3i in project SpongeCommon by SpongePowered.

the class VolumeStreamTest method onGamePreInitialization.

@Listener
public void onGamePreInitialization(final RegisterCommandEvent<Command.Parameterized> event) throws IOException, CommandException {
    this.schematicsDir = this.config.resolve("schematics");
    Files.createDirectories(this.config);
    final Parameter.Value<Biome> biomeKey = Parameter.registryElement(TypeToken.get(Biome.class), ImmutableList.of(VariableValueParameters.RegistryEntryBuilder.WORLD_FROM_LOCATABLE_HOLDER_PROVIDER, VariableValueParameters.RegistryEntryBuilder.WORLD_FROM_CAUSE_HOLDER_PROVIDER), RegistryTypes.BIOME, "minecraft").key("format").build();
    event.register(this.plugin, Command.builder().shortDescription(Component.text("Sets the biome in a selected region")).permission(this.plugin.metadata().id() + ".command.setbiome").addParameter(biomeKey).executor(src -> {
        if (!(src.cause().root() instanceof ServerPlayer)) {
            src.sendMessage(Identity.nil(), Component.text("Player only.", NamedTextColor.RED));
            return CommandResult.success();
        }
        final ServerPlayer player = (ServerPlayer) src.cause().root();
        final PlayerData data = VolumeStreamTest.get(player);
        if (data.getPos1() == null || data.getPos2() == null) {
            player.sendMessage(Identity.nil(), Component.text("You must set both positions before copying", NamedTextColor.RED));
            return CommandResult.success();
        }
        final Vector3i min = data.getPos1().min(data.getPos2());
        final Vector3i max = data.getPos1().max(data.getPos2());
        final Biome target = src.requireOne(biomeKey);
        player.world().biomeStream(min, max, StreamOptions.forceLoadedAndCopied()).map((world, biome, x, y, z) -> target).apply(VolumeCollectors.of(player.world(), VolumePositionTranslators.identity(), VolumeApplicators.applyBiomes()));
        return CommandResult.success();
    }).build(), "setBiome");
    event.register(this.plugin, Command.builder().shortDescription(Component.text("Copies a region of the world to your clipboard")).permission(this.plugin.metadata().id() + ".command.copy").executor(src -> {
        if (!(src.cause().root() instanceof Player)) {
            src.sendMessage(Identity.nil(), Component.text("Player only.", NamedTextColor.RED));
            return CommandResult.success();
        }
        final Player player = (Player) src.cause().root();
        final PlayerData data = VolumeStreamTest.get(player);
        if (data.getPos1() == null || data.getPos2() == null) {
            player.sendMessage(Identity.nil(), Component.text("You must set both positions before copying", NamedTextColor.RED));
            return CommandResult.success();
        }
        final Vector3i min = data.getPos1().min(data.getPos2());
        final Vector3i max = data.getPos1().max(data.getPos2());
        data.setOrigin(player.blockPosition());
        final ArchetypeVolume archetypeVolume = player.world().createArchetypeVolume(min, max, player.blockPosition());
        data.setClipboard(archetypeVolume);
        player.sendMessage(Identity.nil(), Component.text("Saved to clipboard.", VolumeStreamTest.GREEN));
        return CommandResult.success();
    }).build(), "copy");
    event.register(this.plugin, Command.builder().shortDescription(Component.text("Pastes your clipboard to where you are standing")).permission(this.plugin.metadata().id() + ".command.paste").executor(src -> {
        if (!(src.cause().root() instanceof ServerPlayer)) {
            src.sendMessage(Identity.nil(), Component.text("Player only.", NamedTextColor.RED));
            return CommandResult.success();
        }
        final ServerPlayer player = (ServerPlayer) src.cause().root();
        final PlayerData data = VolumeStreamTest.get(player);
        final ArchetypeVolume volume = data.getClipboard();
        if (volume == null) {
            player.sendMessage(Identity.nil(), Component.text("You must copy something before pasting", NamedTextColor.RED));
            return CommandResult.success();
        }
        try (final CauseStackManager.StackFrame frame = Sponge.server().causeStackManager().pushCauseFrame()) {
            frame.pushCause(this.plugin);
            volume.applyToWorld(player.world(), player.blockPosition(), SpawnTypes.PLACEMENT::get);
        }
        src.sendMessage(Identity.nil(), Component.text("Pasted clipboard into world.", VolumeStreamTest.GREEN));
        return CommandResult.success();
    }).build(), "paste");
    final Parameter.Value<String> fileName = Parameter.string().key("fileName").build();
    event.register(this.plugin, Command.builder().shortDescription(Component.text("Pastes your clipboard to where you are standing")).permission(this.plugin.metadata().id() + ".command.paste").addParameter(fileName).executor(src -> {
        if (!(src.cause().root() instanceof ServerPlayer)) {
            src.sendMessage(Identity.nil(), Component.text("Player only.", NamedTextColor.RED));
            return CommandResult.success();
        }
        final String file = src.requireOne(fileName);
        final Path desiredFilePath = this.schematicsDir.resolve(file + VolumeStreamTest.FILE_ENDING);
        if (Files.exists(desiredFilePath)) {
            throw new CommandException(Component.text(file + " already exists, please delete the file first", NamedTextColor.RED));
        }
        if (Files.isDirectory(desiredFilePath)) {
            throw new CommandException(Component.text(file + "is a directory, please use a file name", NamedTextColor.RED));
        }
        final ServerPlayer player = (ServerPlayer) src.cause().root();
        final PlayerData data = VolumeStreamTest.get(player);
        final ArchetypeVolume volume = data.getClipboard();
        if (volume == null) {
            player.sendMessage(Identity.nil(), Component.text("You must copy something before pasting", NamedTextColor.RED));
            return CommandResult.success();
        }
        final Schematic schematic = Schematic.builder().volume(data.getClipboard()).metaValue(Schematic.METADATA_AUTHOR, player.name()).metaValue(Schematic.METADATA_NAME, file).build();
        final DataContainer schematicData = Sponge.dataManager().translator(Schematic.class).orElseThrow(() -> new IllegalStateException("Sponge doesn't have a DataTranslator for Schematics!")).translate(schematic);
        try {
            final Path output = Files.createFile(desiredFilePath);
            DataFormats.NBT.get().writeTo(new GZIPOutputStream(Files.newOutputStream(output)), schematicData);
            player.sendMessage(Identity.nil(), Component.text("Saved schematic to " + output.toAbsolutePath(), VolumeStreamTest.SAVE));
        } catch (final Exception e) {
            e.printStackTrace();
            final StringWriter writer = new StringWriter();
            e.printStackTrace(new PrintWriter(writer));
            final Component errorText = Component.text(writer.toString().replace("\t", "    ").replace("\r\n", "\n").replace("\r", "\n"));
            final TextComponent text = Component.text("Error saving schematic: " + e.getMessage(), NamedTextColor.RED).hoverEvent(HoverEvent.showText(errorText));
            return CommandResult.builder().error(text).build();
        }
        return CommandResult.success();
    }).build(), "save");
    event.register(this.plugin, Command.builder().shortDescription(Component.text("Load a schematic from file")).permission(this.plugin.metadata().id() + ".command.load").addParameter(fileName).executor(src -> {
        if (!(src.cause().root() instanceof ServerPlayer)) {
            src.sendMessage(Identity.nil(), Component.text("Player only.", NamedTextColor.RED));
            return CommandResult.success();
        }
        final ServerPlayer player = (ServerPlayer) src.cause().root();
        final String file = src.requireOne(fileName);
        final Path desiredFilePath = this.schematicsDir.resolve(file + VolumeStreamTest.FILE_ENDING);
        if (!Files.isRegularFile(desiredFilePath)) {
            throw new CommandException(Component.text("File " + file + " was not a normal schemaic file"));
        }
        final Schematic schematic;
        final DataContainer schematicContainer;
        try (final GZIPInputStream stream = new GZIPInputStream(Files.newInputStream(desiredFilePath))) {
            schematicContainer = DataFormats.NBT.get().readFrom(stream);
        } catch (IOException e) {
            e.printStackTrace();
            final StringWriter writer = new StringWriter();
            e.printStackTrace(new PrintWriter(writer));
            final Component errorText = Component.text(writer.toString().replace("\t", "    ").replace("\r\n", "\n").replace("\r", "\n"));
            final TextComponent text = Component.text("Error loading schematic: " + e.getMessage(), NamedTextColor.RED).hoverEvent(HoverEvent.showText(errorText));
            return CommandResult.builder().error(text).build();
        }
        schematic = Sponge.dataManager().translator(Schematic.class).orElseThrow(() -> new IllegalStateException("Expected a DataTranslator for a Schematic")).translate(schematicContainer);
        src.sendMessage(Identity.nil(), Component.text("Loaded schematic from " + file, TextColor.color(0x003434)));
        final PlayerData data = VolumeStreamTest.get(player);
        data.setClipboard(schematic);
        data.setOrigin(player.blockPosition());
        return CommandResult.success();
    }).build(), "load");
    final Parameter.Value<Rotation> rotation = Parameter.registryElement(TypeToken.get(Rotation.class), RegistryTypes.ROTATION).key("rotation").build();
    event.register(this.plugin, Command.builder().shortDescription(Component.text("Rotate clipboard")).permission(this.plugin.metadata().id() + ".command.rotate").addParameter(rotation).executor(src -> {
        if (!(src.cause().root() instanceof ServerPlayer)) {
            src.sendMessage(Identity.nil(), Component.text("Player only.", NamedTextColor.RED));
            return CommandResult.success();
        }
        final ServerPlayer player = (ServerPlayer) src.cause().root();
        final Rotation desiredRotation = src.requireOne(rotation);
        final Schematic schematic;
        final PlayerData data = VolumeStreamTest.get(player);
        if (data.clipboard == null) {
            throw new CommandException(Component.text("Load a clipboard first before trying to rotate it"));
        }
        final ArchetypeVolume newClipboard = data.clipboard.transform(Transformation.builder().origin(data.clipboard.min().toDouble().add(data.clipboard.size().toDouble().div(2))).rotate(desiredRotation).build());
        src.sendMessage(Identity.nil(), Component.text("Rotated clipboard " + desiredRotation.angle().degrees() + " degrees"));
        data.setClipboard(newClipboard);
        return CommandResult.success();
    }).build(), "rotate");
}
Also used : GZIPInputStream(java.util.zip.GZIPInputStream) Command(org.spongepowered.api.command.Command) Inject(com.google.inject.Inject) Level(org.apache.logging.log4j.Level) VolumeApplicators(org.spongepowered.api.world.volume.stream.VolumeApplicators) Biome(org.spongepowered.api.world.biome.Biome) Map(java.util.Map) ArchetypeVolume(org.spongepowered.api.world.volume.archetype.ArchetypeVolume) Path(java.nio.file.Path) PrintWriter(java.io.PrintWriter) TextComponent(net.kyori.adventure.text.TextComponent) Plugin(org.spongepowered.plugin.builtin.jvm.Plugin) TextColor(net.kyori.adventure.text.format.TextColor) Sponge(org.spongepowered.api.Sponge) StreamOptions(org.spongepowered.api.world.volume.stream.StreamOptions) StoppingEngineEvent(org.spongepowered.api.event.lifecycle.StoppingEngineEvent) UUID(java.util.UUID) TypeToken(io.leangen.geantyref.TypeToken) NamedTextColor(net.kyori.adventure.text.format.NamedTextColor) Root(org.spongepowered.api.event.filter.cause.Root) Transformation(org.spongepowered.api.util.transformation.Transformation) Logger(org.apache.logging.log4j.Logger) Cancellable(org.spongepowered.api.event.Cancellable) GZIPOutputStream(java.util.zip.GZIPOutputStream) Player(org.spongepowered.api.entity.living.player.Player) VolumeCollectors(org.spongepowered.api.world.volume.stream.VolumeCollectors) HoverEvent(net.kyori.adventure.text.event.HoverEvent) BlockSnapshot(org.spongepowered.api.block.BlockSnapshot) NonNull(org.checkerframework.checker.nullness.qual.NonNull) DataContainer(org.spongepowered.api.data.persistence.DataContainer) EventContextKeys(org.spongepowered.api.event.EventContextKeys) Schematic(org.spongepowered.api.world.schematic.Schematic) ItemTypes(org.spongepowered.api.item.ItemTypes) HashMap(java.util.HashMap) Rotation(org.spongepowered.api.util.rotation.Rotation) ImmutableList(com.google.common.collect.ImmutableList) Parameter(org.spongepowered.api.command.parameter.Parameter) DataFormats(org.spongepowered.api.data.persistence.DataFormats) Component(net.kyori.adventure.text.Component) Server(org.spongepowered.api.Server) InteractBlockEvent(org.spongepowered.api.event.block.InteractBlockEvent) CauseStackManager(org.spongepowered.api.event.CauseStackManager) RegisterCommandEvent(org.spongepowered.api.event.lifecycle.RegisterCommandEvent) CommandResult(org.spongepowered.api.command.CommandResult) LoadableModule(org.spongepowered.test.LoadableModule) VolumePositionTranslators(org.spongepowered.api.world.volume.stream.VolumePositionTranslators) Files(java.nio.file.Files) Identity(net.kyori.adventure.identity.Identity) StringWriter(java.io.StringWriter) ConfigDir(org.spongepowered.api.config.ConfigDir) IOException(java.io.IOException) RegistryTypes(org.spongepowered.api.registry.RegistryTypes) VariableValueParameters(org.spongepowered.api.command.parameter.managed.standard.VariableValueParameters) PluginContainer(org.spongepowered.plugin.PluginContainer) CommandContext(org.spongepowered.api.command.parameter.CommandContext) Listener(org.spongepowered.api.event.Listener) SpawnTypes(org.spongepowered.api.event.cause.entity.SpawnTypes) CommandException(org.spongepowered.api.command.exception.CommandException) ServerPlayer(org.spongepowered.api.entity.living.player.server.ServerPlayer) Vector3i(org.spongepowered.math.vector.Vector3i) GZIPInputStream(java.util.zip.GZIPInputStream) DataContainer(org.spongepowered.api.data.persistence.DataContainer) Biome(org.spongepowered.api.world.biome.Biome) StringWriter(java.io.StringWriter) GZIPOutputStream(java.util.zip.GZIPOutputStream) CauseStackManager(org.spongepowered.api.event.CauseStackManager) TextComponent(net.kyori.adventure.text.TextComponent) Component(net.kyori.adventure.text.Component) PrintWriter(java.io.PrintWriter) Path(java.nio.file.Path) TextComponent(net.kyori.adventure.text.TextComponent) Player(org.spongepowered.api.entity.living.player.Player) ServerPlayer(org.spongepowered.api.entity.living.player.server.ServerPlayer) CommandException(org.spongepowered.api.command.exception.CommandException) IOException(java.io.IOException) Rotation(org.spongepowered.api.util.rotation.Rotation) IOException(java.io.IOException) CommandException(org.spongepowered.api.command.exception.CommandException) ArchetypeVolume(org.spongepowered.api.world.volume.archetype.ArchetypeVolume) ServerPlayer(org.spongepowered.api.entity.living.player.server.ServerPlayer) Vector3i(org.spongepowered.math.vector.Vector3i) Parameter(org.spongepowered.api.command.parameter.Parameter) Schematic(org.spongepowered.api.world.schematic.Schematic) Listener(org.spongepowered.api.event.Listener)

Example 3 with Vector3i

use of org.spongepowered.math.vector.Vector3i in project SpongeCommon by SpongePowered.

the class BlockEventBasedTransaction method markCancelledTransactions.

@Override
public final boolean markCancelledTransactions(final ChangeBlockEvent.All event, final ImmutableList<? extends GameTransaction<ChangeBlockEvent.All>> blockTransactions) {
    boolean cancelledAny = false;
    if (event.isCancelled()) {
        event.transactions().forEach(BlockTransaction::invalidate);
    }
    for (final Transaction<BlockSnapshot> transaction : event.transactions()) {
        if (!transaction.isValid()) {
            cancelledAny = true;
            for (final GameTransaction<ChangeBlockEvent.All> gameTransaction : blockTransactions) {
                final BlockEventBasedTransaction blockTransaction = (BlockEventBasedTransaction) gameTransaction;
                final Vector3i position = transaction.original().position();
                final BlockPos affectedPosition = blockTransaction.affectedPosition;
                if (position.x() == affectedPosition.getX() && position.y() == affectedPosition.getY() && position.z() == affectedPosition.getZ()) {
                    gameTransaction.markCancelled();
                }
            }
        }
    }
    return cancelledAny;
}
Also used : SpongeBlockSnapshot(org.spongepowered.common.block.SpongeBlockSnapshot) BlockSnapshot(org.spongepowered.api.block.BlockSnapshot) Vector3i(org.spongepowered.math.vector.Vector3i) BlockPos(net.minecraft.core.BlockPos) BlockTransaction(org.spongepowered.api.block.transaction.BlockTransaction)

Example 4 with Vector3i

use of org.spongepowered.math.vector.Vector3i in project SpongeCommon by SpongePowered.

the class NeighborNotification method markCancelledTransactions.

@Override
public boolean markCancelledTransactions(final NotifyNeighborBlockEvent event, final ImmutableList<? extends GameTransaction<NotifyNeighborBlockEvent>> blockTransactions) {
    boolean cancelledAny = false;
    for (final NotificationTicket transaction : event.tickets()) {
        if (!transaction.valid()) {
            cancelledAny = true;
            for (final GameTransaction<NotifyNeighborBlockEvent> gameTransaction : blockTransactions) {
                final NeighborNotification blockTransaction = (NeighborNotification) gameTransaction;
                final Vector3i position = transaction.targetPosition();
                final BlockPos affectedPosition = blockTransaction.affectedPosition;
                if (position.x() == affectedPosition.getX() && position.y() == affectedPosition.getY() && position.z() == affectedPosition.getZ()) {
                    gameTransaction.markCancelled();
                }
            }
        }
    }
    return cancelledAny;
}
Also used : NotifyNeighborBlockEvent(org.spongepowered.api.event.block.NotifyNeighborBlockEvent) Vector3i(org.spongepowered.math.vector.Vector3i) SpongeNotificationTicket(org.spongepowered.common.block.SpongeNotificationTicket) NotificationTicket(org.spongepowered.api.block.transaction.NotificationTicket) BlockPos(net.minecraft.core.BlockPos)

Example 5 with Vector3i

use of org.spongepowered.math.vector.Vector3i in project SpongeCommon by SpongePowered.

the class AbstractSpongeRayTrace method execute.

@Override
@NonNull
public Optional<RayTraceResult<@NonNull T>> execute() {
    this.setupEnd();
    // get the direction
    final Vector3d directionWithLength = this.end.sub(this.start);
    final double length = directionWithLength.length();
    final Vector3d direction = directionWithLength.normalize();
    if (direction.lengthSquared() == 0) {
        throw new IllegalStateException("The start and end must be two different vectors");
    }
    final ServerWorld serverWorld = Sponge.server().worldManager().world(this.world).orElseThrow(() -> new IllegalStateException("World with key " + this.world.formatted() + " is not loaded!"));
    Vector3i currentBlock = this.initialBlock(direction);
    final Vector3i steps = this.createSteps(direction);
    // The ray equation is, vec(u) + t vec(d). From a point (x, y), there is a t
    // that we need to traverse to get to a boundary. We work that out now...
    TData tData = this.createInitialTData(direction);
    Vector3d currentLocation = new Vector3d(this.start.x(), this.start.y(), this.start.z());
    final boolean requiresEntityTracking = this.requiresEntityTracking();
    boolean requireAdvancement = true;
    while (requireAdvancement) {
        final net.minecraft.world.phys.Vec3 vec3dstart = VecHelper.toVanillaVector3d(currentLocation);
        // As this iteration is for the CURRENT block location, we need to check where we are with the filter.
        if (this.continueWhileLocation != null && !this.continueWhileLocation.test(ServerLocation.of(serverWorld, currentBlock))) {
            return Optional.empty();
        }
        final Vector3d nextLocation;
        final net.minecraft.world.phys.Vec3 vec3dend;
        if (tData.getTotalTWithNextStep() > length) {
            // This is the last step, we break out of the loop after this set of checks.
            requireAdvancement = false;
            nextLocation = this.end;
            vec3dend = VecHelper.toVanillaVector3d(this.end);
        } else {
            nextLocation = currentLocation.add(direction.x() * tData.getNextStep(), direction.y() * tData.getNextStep(), direction.z() * tData.getNextStep());
            vec3dend = VecHelper.toVanillaVector3d(nextLocation);
        }
        // Get the selection result.
        final Optional<RayTraceResult<@NonNull T>> result = this.testSelectLocation(serverWorld, vec3dstart, vec3dend);
        if (result.isPresent() && !this.shouldCheckFailures()) {
            // that's blocking the view.
            return result;
        }
        // Ensure that the block can be travelled through.
        if (!this.shouldAdvanceThroughBlock(serverWorld, vec3dstart, vec3dend)) {
            return Optional.empty();
        }
        // Ensure that the entities in the block can be travelled through.
        if (requiresEntityTracking && this.continueWhileEntity != null) {
            final double resultDistance;
            if (result.isPresent()) {
                resultDistance = result.get().hitPosition().distanceSquared(currentLocation);
            } else {
                resultDistance = Double.MAX_VALUE;
            }
            final AABB targetAABB = this.getBlockAABB(currentBlock);
            for (final net.minecraft.world.entity.Entity entity : this.getFailingEntities(serverWorld, targetAABB)) {
                final Optional<net.minecraft.world.phys.Vec3> vec3d = entity.getBoundingBox().clip(vec3dstart, vec3dend);
                if (vec3d.isPresent()) {
                    final net.minecraft.world.phys.Vec3 hitPosition = vec3d.get();
                    final double sqdist = hitPosition.distanceToSqr(vec3dstart);
                    if (sqdist < resultDistance) {
                        // We have a failure, so at this point we just bail out and end the trace.
                        return Optional.empty();
                    }
                }
            }
        }
        // If we still have a result at this point, return it.
        if (result.isPresent()) {
            return result;
        }
        if (requireAdvancement) {
            currentLocation = nextLocation;
            currentBlock = this.getNextBlock(currentBlock, tData, steps);
            tData = this.advance(tData, steps, direction);
        }
    }
    return Optional.empty();
}
Also used : RayTraceResult(org.spongepowered.api.util.blockray.RayTraceResult) ServerWorld(org.spongepowered.api.world.server.ServerWorld) Vector3d(org.spongepowered.math.vector.Vector3d) NonNull(org.checkerframework.checker.nullness.qual.NonNull) Vector3i(org.spongepowered.math.vector.Vector3i) AABB(net.minecraft.world.phys.AABB) NonNull(org.checkerframework.checker.nullness.qual.NonNull)

Aggregations

Vector3i (org.spongepowered.math.vector.Vector3i)59 Vector3d (org.spongepowered.math.vector.Vector3d)22 Nullable (org.checkerframework.checker.nullness.qual.Nullable)15 BlockPos (net.minecraft.core.BlockPos)14 BlockState (org.spongepowered.api.block.BlockState)14 Stream (java.util.stream.Stream)13 ChunkAccess (net.minecraft.world.level.chunk.ChunkAccess)12 StreamOptions (org.spongepowered.api.world.volume.stream.StreamOptions)12 MonotonicNonNull (org.checkerframework.checker.nullness.qual.MonotonicNonNull)11 VolumeElement (org.spongepowered.api.world.volume.stream.VolumeElement)11 Tuple (net.minecraft.util.Tuple)10 LevelChunk (net.minecraft.world.level.chunk.LevelChunk)10 VolumeStream (org.spongepowered.api.world.volume.stream.VolumeStream)10 Function (java.util.function.Function)9 Biome (org.spongepowered.api.world.biome.Biome)9 Collection (java.util.Collection)8 Objects (java.util.Objects)8 Optional (java.util.Optional)8 UUID (java.util.UUID)8 Entity (org.spongepowered.api.entity.Entity)8