use of org.spongepowered.math.vector.Vector3d 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);
}
use of org.spongepowered.math.vector.Vector3d in project SpongeCommon by SpongePowered.
the class EntityMixin method bridge$setPosition.
@Override
public boolean bridge$setPosition(final Vector3d position) {
if (this.removed) {
return false;
}
try (final CauseStackManager.StackFrame frame = PhaseTracker.getCauseStackManager().pushCauseFrame()) {
frame.addContext(EventContextKeys.MOVEMENT_TYPE, MovementTypes.PLUGIN);
final Vector3d destinationPosition = this.impl$fireMoveEvent(PhaseTracker.SERVER, position);
if (destinationPosition == null) {
return false;
}
final ServerLevel level = (ServerLevel) this.level;
return this.impl$setLocation(false, level, level, destinationPosition);
}
}
use of org.spongepowered.math.vector.Vector3d in project SpongeCommon by SpongePowered.
the class EntityMixin method impl$teleportToWithTicket.
/*
* (non-Javadoc)
*
* This is a modified version of teleportToWithTicket, treat this as an overwrite
* see above.
*/
public final boolean impl$teleportToWithTicket(final double x, final double y, final double z, final boolean fireMoveEvent) {
if (this.level instanceof net.minecraft.server.level.ServerLevel) {
// Sponge start
final Vector3d destinationPosition;
if (ShouldFire.MOVE_ENTITY_EVENT && fireMoveEvent) {
destinationPosition = this.impl$fireMoveEvent(PhaseTracker.SERVER, new Vector3d(x, y, z));
} else {
destinationPosition = new Vector3d(x, y, z);
}
// Sponge end
final ChunkPos chunkpos = new ChunkPos(new BlockPos(destinationPosition.x(), destinationPosition.y(), destinationPosition.z()));
((net.minecraft.server.level.ServerLevel) this.level).getChunkSource().addRegionTicket(TicketType.POST_TELEPORT, chunkpos, 0, this.shadow$getId());
this.level.getChunk(chunkpos.x, chunkpos.z);
this.shadow$teleportTo(destinationPosition.x(), destinationPosition.y(), destinationPosition.z());
// Sponge: return success
return true;
}
// Sponge: return failure
return false;
}
use of org.spongepowered.math.vector.Vector3d in project SpongeCommon by SpongePowered.
the class EntityMixin method impl$onMoveCollide.
@Redirect(method = "move", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/Entity;collide(Lnet/minecraft/world/phys/Vec3;)Lnet/minecraft/world/phys/Vec3;"))
private Vec3 impl$onMoveCollide(final Entity entity, final Vec3 originalMove) {
final Vec3 afterCollide = this.shadow$collide(originalMove);
if (ShouldFire.COLLIDE_BLOCK_EVENT_MOVE && !originalMove.equals(afterCollide)) {
// We had a collision! Try to find the colliding block
// TODO this is not 100% accurate as the collision happens with the bb potentially colliding with multiple blocks
// TODO maybe actually check for blocks in bb?
BlockPos pos = new BlockPos(this.position.add(originalMove));
if (this.blockPosition.equals(pos)) {
// retry with bigger move for entities with big bounding box - e.g. minecart
pos = new BlockPos(this.position.add(originalMove.normalize()));
}
final BlockState state = this.level.getBlockState(pos);
final org.spongepowered.api.util.Direction dir = org.spongepowered.api.util.Direction.closest(new Vector3d(originalMove.x, originalMove.y, originalMove.z));
if (SpongeCommonEventFactory.handleCollideBlockEvent(state.getBlock(), this.level, pos, state, (Entity) (Object) this, dir, SpongeCommonEventFactory.CollisionType.MOVE)) {
return originalMove;
}
}
return afterCollide;
}
use of org.spongepowered.math.vector.Vector3d in project SpongeCommon by SpongePowered.
the class PlayerListMixin method impl$callRespawnPlayerRecreateEvent.
@Redirect(method = "respawn", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/network/ServerGamePacketListenerImpl;send(Lnet/minecraft/network/protocol/Packet;)V", ordinal = 1))
private void impl$callRespawnPlayerRecreateEvent(final ServerGamePacketListenerImpl serverPlayNetHandler, final Packet<?> packetIn, final net.minecraft.server.level.ServerPlayer originalPlayer, final boolean keepAllPlayerData) {
final net.minecraft.server.level.ServerPlayer recreatedPlayer = serverPlayNetHandler.player;
final Vector3d originalPosition = VecHelper.toVector3d(originalPlayer.position());
final Vector3d destinationPosition = VecHelper.toVector3d(recreatedPlayer.position());
final org.spongepowered.api.world.server.ServerWorld originalWorld = (org.spongepowered.api.world.server.ServerWorld) originalPlayer.level;
final org.spongepowered.api.world.server.ServerWorld originalDestinationWorld = (org.spongepowered.api.world.server.ServerWorld) this.server.getLevel(this.impl$originalDestination == null ? Level.OVERWORLD : this.impl$originalDestination);
final org.spongepowered.api.world.server.ServerWorld destinationWorld = (org.spongepowered.api.world.server.ServerWorld) this.server.getLevel(this.impl$newDestination == null ? Level.OVERWORLD : this.impl$newDestination);
final RespawnPlayerEvent.Recreate event = SpongeEventFactory.createRespawnPlayerEventRecreate(PhaseTracker.getCauseStackManager().currentCause(), destinationPosition, originalWorld, originalPosition, destinationWorld, originalDestinationWorld, destinationPosition, (ServerPlayer) originalPlayer, (ServerPlayer) recreatedPlayer, this.impl$isGameMechanicRespawn, !keepAllPlayerData);
SpongeCommon.post(event);
recreatedPlayer.setPos(event.destinationPosition().x(), event.destinationPosition().y(), event.destinationPosition().z());
this.impl$isGameMechanicRespawn = false;
this.impl$originalDestination = null;
this.impl$newDestination = null;
final ServerLevel targetWorld = (ServerLevel) event.destinationWorld();
((ServerPlayerBridge) recreatedPlayer).bridge$sendChangeDimension(targetWorld.dimensionType(), ((ClientboundRespawnPacketAccessor) packetIn).accessor$dimension(), ((ClientboundRespawnPacketAccessor) packetIn).accessor$seed(), recreatedPlayer.gameMode.getGameModeForPlayer(), recreatedPlayer.gameMode.getPreviousGameModeForPlayer(), targetWorld.isDebug(), targetWorld.isFlat(), keepAllPlayerData);
}
Aggregations