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