Search in sources :

Example 31 with Vector3i

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

the class BlockEvent_BreakEventMixin_Forge method bridge$syncFrom.

@Override
public void bridge$syncFrom(final Event event) {
    if (event instanceof ChangeBlockEvent.All) {
        final ChangeBlockEvent.All changeBlockEventAll = (ChangeBlockEvent.All) event;
        final Vector3i pos = VecHelper.toVector3i(this.shadow$getPos());
        if (changeBlockEventAll.isCancelled() || changeBlockEventAll.transactions().stream().filter(x -> x.original().position().equals(pos)).anyMatch(x -> !x.isValid() || x.operation() != Operations.BREAK.get() || x.custom().isPresent())) {
            ((net.minecraftforge.eventbus.api.Event) (Object) this).setCanceled(true);
        }
    }
}
Also used : ChangeBlockEvent(org.spongepowered.api.event.block.ChangeBlockEvent) BlockEvent(net.minecraftforge.event.world.BlockEvent) ServerWorld(org.spongepowered.api.world.server.ServerWorld) ChangeBlockEvent(org.spongepowered.api.event.block.ChangeBlockEvent) Event(org.spongepowered.api.event.Event) ForgeEventBridge_Forge(org.spongepowered.forge.launch.bridge.event.ForgeEventBridge_Forge) BlockTypes(org.spongepowered.api.block.BlockTypes) Operations(org.spongepowered.api.block.transaction.Operations) SpongeEventFactory(org.spongepowered.api.event.SpongeEventFactory) SpongeBlockSnapshot(org.spongepowered.common.block.SpongeBlockSnapshot) PhaseTracker(org.spongepowered.common.event.tracking.PhaseTracker) BlockState(org.spongepowered.api.block.BlockState) Mixin(org.spongepowered.asm.mixin.Mixin) BlockTransaction(org.spongepowered.api.block.transaction.BlockTransaction) VecHelper(org.spongepowered.common.util.VecHelper) LevelAccessor(net.minecraft.world.level.LevelAccessor) Collections(java.util.Collections) Nullable(org.checkerframework.checker.nullness.qual.Nullable) Vector3i(org.spongepowered.math.vector.Vector3i) Vector3i(org.spongepowered.math.vector.Vector3i) BlockEvent(net.minecraftforge.event.world.BlockEvent) ChangeBlockEvent(org.spongepowered.api.event.block.ChangeBlockEvent) Event(org.spongepowered.api.event.Event)

Example 32 with Vector3i

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

the class DataUtil method getPosition3i.

public static Vector3i getPosition3i(final DataView view) {
    DataUtil.checkDataExists(view, Constants.Sponge.SNAPSHOT_WORLD_POSITION);
    final DataView internal = view.getView(Constants.Sponge.SNAPSHOT_WORLD_POSITION).orElseThrow(DataUtil.dataNotFound());
    final int x = internal.getInt(Queries.POSITION_X).orElseThrow(DataUtil.dataNotFound());
    final int y = internal.getInt(Queries.POSITION_Y).orElseThrow(DataUtil.dataNotFound());
    final int z = internal.getInt(Queries.POSITION_Z).orElseThrow(DataUtil.dataNotFound());
    return new Vector3i(x, y, z);
}
Also used : DataView(org.spongepowered.api.data.persistence.DataView) Vector3i(org.spongepowered.math.vector.Vector3i)

Example 33 with Vector3i

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

the class LevelMixin_API method createArchetypeVolume.

@Override
public ArchetypeVolume createArchetypeVolume(final Vector3i min, final Vector3i max, final Vector3i origin) {
    final Vector3i rawVolMin = Objects.requireNonNull(min, "min").min(Objects.requireNonNull(max, "max"));
    final Vector3i volMax = max.max(min);
    final Vector3i size = volMax.sub(rawVolMin).add(1, 1, 1);
    final Vector3i relativeMin = rawVolMin.sub(Objects.requireNonNull(origin, "origin"));
    final SpongeArchetypeVolume volume = new SpongeArchetypeVolume(relativeMin, size, this);
    this.blockStateStream(min, max, StreamOptions.lazily()).apply(VolumeCollectors.of(volume, VolumePositionTranslators.offset(origin), VolumeApplicators.applyBlocks()));
    this.blockEntityStream(min, max, StreamOptions.lazily()).map((world, blockEntity, x, y, z) -> blockEntity.get().createArchetype()).apply(VolumeCollectors.of(volume, VolumePositionTranslators.offset(origin), VolumeApplicators.applyBlockEntityArchetypes()));
    this.biomeStream(min, max, StreamOptions.lazily()).apply(VolumeCollectors.of(volume, VolumePositionTranslators.offset(origin), VolumeApplicators.applyBiomes()));
    this.entityStream(min, max, StreamOptions.lazily()).filter((world, entity, x, y, z) -> ((EntityAccessor) entity.get()).invoker$getEncodeId() != null || entity.get().type() == HumanEntity.TYPE).map((world, entity, x, y, z) -> entity.get().createArchetype()).apply(VolumeCollectors.of(volume, VolumePositionTranslators.offset(origin), VolumeApplicators.applyEntityArchetypes()));
    return volume;
}
Also used : ResourceLocation(net.minecraft.resources.ResourceLocation) MusicDisc(org.spongepowered.api.effect.sound.music.MusicDisc) WorldChunk(org.spongepowered.api.world.chunk.WorldChunk) Random(java.util.Random) SpongeAdventure(org.spongepowered.common.adventure.SpongeAdventure) ClientboundCustomSoundPacket(net.minecraft.network.protocol.game.ClientboundCustomSoundPacket) VolumeApplicators(org.spongepowered.api.world.volume.stream.VolumeApplicators) Registry(net.minecraft.core.Registry) ChunkSource(net.minecraft.world.level.chunk.ChunkSource) MonotonicNonNull(org.checkerframework.checker.nullness.qual.MonotonicNonNull) Biome(org.spongepowered.api.world.biome.Biome) MinecraftServer(net.minecraft.server.MinecraftServer) ParticleEffect(org.spongepowered.api.effect.particle.ParticleEffect) Mixin(org.spongepowered.asm.mixin.Mixin) ImposterProtoChunk(net.minecraft.world.level.chunk.ImposterProtoChunk) ArchetypeVolume(org.spongepowered.api.world.volume.archetype.ArchetypeVolume) RegistryHolderLogic(org.spongepowered.common.registry.RegistryHolderLogic) BiomeVolume(org.spongepowered.api.world.volume.biome.BiomeVolume) Location(org.spongepowered.api.world.Location) Predicate(java.util.function.Predicate) Collection(java.util.Collection) SpongeRegistryHolder(org.spongepowered.common.registry.SpongeRegistryHolder) StreamOptions(org.spongepowered.api.world.volume.stream.StreamOptions) ChunkMapAccessor(org.spongepowered.common.accessor.server.level.ChunkMapAccessor) UUID(java.util.UUID) LevelReader(net.minecraft.world.level.LevelReader) Final(org.spongepowered.asm.mixin.Final) ObjectArrayMutableEntityBuffer(org.spongepowered.common.world.volume.buffer.entity.ObjectArrayMutableEntityBuffer) ChunkAccess(net.minecraft.world.level.chunk.ChunkAccess) Objects(java.util.Objects) List(java.util.List) Sound(net.kyori.adventure.sound.Sound) Stream(java.util.stream.Stream) SpongeArchetypeVolume(org.spongepowered.common.world.volume.buffer.archetype.SpongeArchetypeVolume) BlockPos(net.minecraft.core.BlockPos) SoundEvent(net.minecraft.sounds.SoundEvent) VolumeStreamUtils(org.spongepowered.common.world.volume.VolumeStreamUtils) World(org.spongepowered.api.world.World) LevelAccessor(net.minecraft.world.level.LevelAccessor) HeightTypes(org.spongepowered.api.world.HeightTypes) Shadow(org.spongepowered.asm.mixin.Shadow) Optional(java.util.Optional) Player(org.spongepowered.api.entity.living.player.Player) VolumeCollectors(org.spongepowered.api.world.volume.stream.VolumeCollectors) Level(net.minecraft.world.level.Level) HumanEntity(org.spongepowered.common.entity.living.human.HumanEntity) SoundSource(net.minecraft.sounds.SoundSource) BlockEntity(org.spongepowered.api.block.entity.BlockEntity) LevelChunk(net.minecraft.world.level.chunk.LevelChunk) DataContainer(org.spongepowered.api.data.persistence.DataContainer) ServerChunkCache(net.minecraft.server.level.ServerChunkCache) Constants(org.spongepowered.common.util.Constants) BlockState(net.minecraft.world.level.block.state.BlockState) AABB(org.spongepowered.api.util.AABB) LevelData(net.minecraft.world.level.storage.LevelData) ArrayList(java.util.ArrayList) ClientboundBlockUpdatePacket(net.minecraft.network.protocol.game.ClientboundBlockUpdatePacket) ServerPlayer(net.minecraft.server.level.ServerPlayer) EntityAccessor(org.spongepowered.common.accessor.world.entity.EntityAccessor) Nullable(org.checkerframework.checker.nullness.qual.Nullable) VolumeStream(org.spongepowered.api.world.volume.stream.VolumeStream) LevelBridge(org.spongepowered.common.bridge.world.level.LevelBridge) Context(org.spongepowered.api.service.context.Context) VolumePositionTranslators(org.spongepowered.api.world.volume.stream.VolumePositionTranslators) Tuple(net.minecraft.util.Tuple) ResourceKey(net.minecraft.resources.ResourceKey) Entity(org.spongepowered.api.entity.Entity) WorldLike(org.spongepowered.api.world.WorldLike) SpongeChunkLayout(org.spongepowered.common.world.storage.SpongeChunkLayout) Vector3d(org.spongepowered.math.vector.Vector3d) VecHelper(org.spongepowered.common.util.VecHelper) EntityType(org.spongepowered.api.entity.EntityType) ChunkStatus(net.minecraft.world.level.chunk.ChunkStatus) SpongeParticleHelper(org.spongepowered.common.effect.particle.SpongeParticleHelper) Collections(java.util.Collections) SpongeMusicDisc(org.spongepowered.common.effect.record.SpongeMusicDisc) Vector3i(org.spongepowered.math.vector.Vector3i) SpongeArchetypeVolume(org.spongepowered.common.world.volume.buffer.archetype.SpongeArchetypeVolume) Vector3i(org.spongepowered.math.vector.Vector3i)

Example 34 with Vector3i

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

the class LevelMixin_API method entityStream.

@SuppressWarnings("unchecked")
@Override
public VolumeStream<W, Entity> entityStream(final Vector3i min, final Vector3i max, final StreamOptions options) {
    VolumeStreamUtils.validateStreamArgs(Objects.requireNonNull(min, "min"), Objects.requireNonNull(max, "max"), Objects.requireNonNull(options, "options"));
    final boolean shouldCarbonCopy = options.carbonCopy();
    final Vector3i size = max.sub(min).add(1, 1, 1);
    @MonotonicNonNull final ObjectArrayMutableEntityBuffer backingVolume;
    if (shouldCarbonCopy) {
        backingVolume = new ObjectArrayMutableEntityBuffer(min, size);
    } else {
        backingVolume = null;
    }
    return VolumeStreamUtils.<W, Entity, net.minecraft.world.entity.Entity, ChunkAccess, UUID>generateStream(min, max, options, // Ref
    (W) this, // IdentityFunction
    VolumeStreamUtils.getOrCloneEntityWithVolume(shouldCarbonCopy, backingVolume, (Level) (Object) this), // ChunkAccessor
    VolumeStreamUtils.getChunkAccessorByStatus((LevelReader) (Object) this, options.loadingStyle().generateArea()), // Entity -> UniqueID
    (key, entity) -> entity.getUUID(), // Entity Accessor
    (chunk) -> chunk instanceof LevelChunk ? VolumeStreamUtils.getEntitiesFromChunk(min, max, (LevelChunk) chunk) : Stream.empty(), // Filtered Position Entity Accessor
    (entityUuid, world) -> {
        final net.minecraft.world.entity.@Nullable Entity entity = shouldCarbonCopy ? (net.minecraft.world.entity.Entity) backingVolume.entity(entityUuid).orElse(null) : (net.minecraft.world.entity.Entity) ((WorldLike) world).entity(entityUuid).orElse(null);
        if (entity == null) {
            return null;
        }
        return new Tuple<>(entity.blockPosition(), entity);
    });
}
Also used : HumanEntity(org.spongepowered.common.entity.living.human.HumanEntity) BlockEntity(org.spongepowered.api.block.entity.BlockEntity) Entity(org.spongepowered.api.entity.Entity) LevelReader(net.minecraft.world.level.LevelReader) ChunkAccess(net.minecraft.world.level.chunk.ChunkAccess) LevelChunk(net.minecraft.world.level.chunk.LevelChunk) MonotonicNonNull(org.checkerframework.checker.nullness.qual.MonotonicNonNull) Vector3i(org.spongepowered.math.vector.Vector3i) ObjectArrayMutableEntityBuffer(org.spongepowered.common.world.volume.buffer.entity.ObjectArrayMutableEntityBuffer) Level(net.minecraft.world.level.Level) UUID(java.util.UUID) Nullable(org.checkerframework.checker.nullness.qual.Nullable) Tuple(net.minecraft.util.Tuple)

Example 35 with Vector3i

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

the class LevelAccessorMixin_API method setBlock.

// MutableBlockVolume
default boolean setBlock(final int x, final int y, final int z, final org.spongepowered.api.block.BlockState blockState, final BlockChangeFlag flag) {
    Objects.requireNonNull(blockState, "blockState");
    Objects.requireNonNull(flag, "flag");
    if (!Level.isInWorldBounds(new BlockPos(x, y, z))) {
        throw new PositionOutOfBoundsException(new Vector3i(x, y, z), Constants.World.BLOCK_MIN, Constants.World.BLOCK_MAX);
    }
    try (@Nullable final PhaseContext<@NonNull ?> context = PluginPhase.State.BLOCK_WORKER.switchIfNecessary(PhaseTracker.SERVER)) {
        if (context != null) {
            context.buildAndSwitch();
        }
        return ((LevelAccessor) this).setBlock(new BlockPos(x, y, z), (BlockState) blockState, ((SpongeBlockChangeFlag) flag).getRawFlag());
    }
}
Also used : LevelAccessor(net.minecraft.world.level.LevelAccessor) Vector3i(org.spongepowered.math.vector.Vector3i) PositionOutOfBoundsException(org.spongepowered.api.util.PositionOutOfBoundsException) BlockPos(net.minecraft.core.BlockPos) Nullable(org.checkerframework.checker.nullness.qual.Nullable)

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