use of org.spongepowered.math.vector.Vector3d in project SpongeCommon by SpongePowered.
the class LevelReaderMixin_API method containsAnyLiquids.
@Override
default boolean containsAnyLiquids(final AABB aabb) {
final Vector3d max = Objects.requireNonNull(aabb, "aabb").max();
final Vector3d min = aabb.min();
return this.shadow$containsAnyLiquid(new net.minecraft.world.phys.AABB(min.x(), min.y(), min.z(), max.x(), max.y(), max.z()));
}
use of org.spongepowered.math.vector.Vector3d in project SpongeCommon by SpongePowered.
the class SpongeCommonEventFactory method throwDropItemAndConstructEvent.
/**
* @author gabizou - April 19th, 2018
* Creates two events here:
* - {@link DropItemEvent}
* - {@link ConstructEntityEvent}
*
* This is to reduce the code size from normal entity drops and player drops.
* While player drops usually require performing position and motion modifications,
* we return the item stack if it is to be thrown (this allows the event to have a
* say in what item is dropped).
*
* @param entity The entity throwing the item
* @param posX The position x for the item stack to spawn
* @param posY The position y for the item stack to spawn
* @param posZ The position z for the item stack to spawn
* @param snapshot The item snapshot of the item to drop
* @param original The original list to be used
* @param frame
* @return The item if it is to be spawned, null if to be ignored
*/
@Nullable
public static ItemStack throwDropItemAndConstructEvent(final net.minecraft.world.entity.Entity entity, final double posX, final double posY, final double posZ, final ItemStackSnapshot snapshot, final List<ItemStackSnapshot> original, final CauseStackManager.StackFrame frame) {
final ItemStack item;
frame.pushCause(entity);
// FIRST we want to throw the DropItemEvent.PRE
final DropItemEvent.Pre dropEvent = SpongeEventFactory.createDropItemEventPre(frame.currentCause(), ImmutableList.of(snapshot), original);
SpongeCommon.post(dropEvent);
if (dropEvent.isCancelled()) {
return null;
}
if (dropEvent.droppedItems().isEmpty()) {
return null;
}
// SECOND throw the ConstructEntityEvent
frame.addContext(EventContextKeys.SPAWN_TYPE, SpawnTypes.DROPPED_ITEM);
final ConstructEntityEvent.Pre event = SpongeEventFactory.createConstructEntityEventPre(frame.currentCause(), ServerLocation.of((ServerWorld) entity.level, posX, posY, posZ), new Vector3d(0, 0, 0), EntityTypes.ITEM.get());
frame.removeContext(EventContextKeys.SPAWN_TYPE);
SpongeCommon.post(event);
if (event.isCancelled()) {
return null;
}
item = event.isCancelled() ? null : ItemStackUtil.fromSnapshotToNative(dropEvent.droppedItems().get(0));
if (item == null) {
return null;
}
return item;
}
use of org.spongepowered.math.vector.Vector3d in project SpongeCommon by SpongePowered.
the class AbstractReferentArchetypeVolume method transformBlockSizes.
protected Vector3i transformBlockSizes(final Vector3i min, final Vector3i max, final BiFunction<Vector3i, Vector3i, Vector3i> minmax) {
final Vector3d rawBlockMin = min.toDouble().add(VolumePositionTranslators.BLOCK_OFFSET);
final Vector3i transformedMin = this.transformation.transformPosition(rawBlockMin).sub(VolumePositionTranslators.BLOCK_OFFSET).toInt();
final Vector3d rawBlockMax = max.toDouble().add(VolumePositionTranslators.BLOCK_OFFSET);
final Vector3i transformedMax = this.transformation.transformPosition(rawBlockMax).sub(VolumePositionTranslators.BLOCK_OFFSET).toInt();
return minmax.apply(transformedMin, transformedMax);
}
use of org.spongepowered.math.vector.Vector3d in project SpongeCommon by SpongePowered.
the class AbstractMutableBlockEntityBuffer method blockStateStream.
@Override
public VolumeStream<BlockEntityVolume.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<BlockEntityVolume.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((BlockEntityVolume.Mutable) this, () -> buffer.block(x, y, z), new Vector3d(x, y, z)))).flatMap(Function.identity())).flatMap(Function.identity());
return new SpongeVolumeStream<>(stateStream, () -> this);
}
use of org.spongepowered.math.vector.Vector3d in project SpongeCommon by SpongePowered.
the class ByteArrayMutableBiomeBuffer method biomeStream.
@Override
public VolumeStream<BiomeVolume.Mutable, Biome> biomeStream(final Vector3i min, final Vector3i max, final StreamOptions options) {
final Vector3i blockMin = this.min();
final Vector3i blockMax = this.max();
VolumeStreamUtils.validateStreamArgs(min, max, blockMin, blockMax, options);
final byte[] biomes;
if (options.carbonCopy()) {
biomes = Arrays.copyOf(this.biomes, this.biomes.length);
} else {
biomes = this.biomes;
}
final Stream<VolumeElement<BiomeVolume.Mutable, Biome>> 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((BiomeVolume.Mutable) this, () -> {
final byte biomeId = biomes[this.getIndex(x, y, z)];
return this.palette.get(biomeId & 255, Sponge.server()).orElseGet(() -> Sponge.server().registry(RegistryTypes.BIOME).value(Biomes.OCEAN));
}, new Vector3d(x, y, z)))).flatMap(Function.identity())).flatMap(Function.identity());
return new SpongeVolumeStream<>(stateStream, () -> this);
}
Aggregations