use of org.spongepowered.common.event.tracking.phase.plugin.BasicPluginContext in project SpongeCommon by SpongePowered.
the class SpongeBlockVolumeWorker method iterate.
@Override
public void iterate(BlockVolumeVisitor<V> visitor) {
final int xMin = this.volume.getBlockMin().getX();
final int yMin = this.volume.getBlockMin().getY();
final int zMin = this.volume.getBlockMin().getZ();
final int xMax = this.volume.getBlockMax().getX();
final int yMax = this.volume.getBlockMax().getY();
final int zMax = this.volume.getBlockMax().getZ();
try (CauseStackManager.StackFrame frame = Sponge.getCauseStackManager().pushCauseFrame();
BasicPluginContext context = PluginPhase.State.BLOCK_WORKER.createPhaseContext().source(this).buildAndSwitch()) {
for (int z = zMin; z <= zMax; z++) {
for (int y = yMin; y <= yMax; y++) {
for (int x = xMin; x <= xMax; x++) {
visitor.visit(this.volume, x, y, z);
}
}
}
}
}
use of org.spongepowered.common.event.tracking.phase.plugin.BasicPluginContext in project SpongeCommon by SpongePowered.
the class MixinEntity method setLocation.
@Override
public boolean setLocation(Location<World> location) {
checkNotNull(location, "The location was null!");
if (isRemoved()) {
return false;
}
try (final BasicPluginContext context = PluginPhase.State.TELEPORT.createPhaseContext().buildAndSwitch()) {
// TODO Add a 'Move' plugin phase or just keep it under Teleport?
try (final CauseStackManager.StackFrame frame = Sponge.getCauseStackManager().pushCauseFrame()) {
if (!Sponge.getCauseStackManager().getCurrentContext().containsKey(EventContextKeys.TELEPORT_TYPE)) {
Sponge.getCauseStackManager().addContext(EventContextKeys.TELEPORT_TYPE, TeleportTypes.PLUGIN);
}
// TODO These methods need a Cause (maybe wait till Cause PR)
// TODO Need to not fire Teleport in all cases (especially when movement is local)
MoveEntityEvent.Teleport event = EntityUtil.handleDisplaceEntityTeleportEvent((net.minecraft.entity.Entity) (Object) this, location);
if (event.isCancelled()) {
return false;
}
location = event.getToTransform().getLocation();
this.rotationPitch = (float) event.getToTransform().getPitch();
this.rotationYaw = (float) event.getToTransform().getYaw();
}
final IMixinChunkProviderServer chunkProviderServer = (IMixinChunkProviderServer) ((WorldServer) this.world).getChunkProvider();
chunkProviderServer.setForceChunkRequests(true);
final net.minecraft.entity.Entity thisEntity = (net.minecraft.entity.Entity) (Object) this;
final List<net.minecraft.entity.Entity> passengers = thisEntity.getPassengers();
boolean isTeleporting = true;
if (location.getExtent().getUniqueId() != ((World) this.world).getUniqueId()) {
final net.minecraft.world.World nmsWorld = (net.minecraft.world.World) location.getExtent();
if ((net.minecraft.entity.Entity) (Object) this instanceof EntityPlayerMP) {
// Close open containers
final EntityPlayerMP entityPlayerMP = (EntityPlayerMP) (Object) this;
if (entityPlayerMP.openContainer != entityPlayerMP.inventoryContainer) {
// Call API method to make sure we capture it
((Player) entityPlayerMP).closeInventory();
}
}
EntityUtil.changeWorld((net.minecraft.entity.Entity) (Object) this, location, ((IMixinWorldServer) this.world).getDimensionId(), ((IMixinWorldServer) nmsWorld).getDimensionId());
} else {
double distance = location.getPosition().distance(this.getPosition());
if (distance <= 4) {
isTeleporting = false;
}
if (thisEntity instanceof EntityPlayerMP && ((EntityPlayerMP) thisEntity).connection != null) {
final EntityPlayerMP entityPlayerMP = (EntityPlayerMP) thisEntity;
// No reason to attempt to load chunks unless we're teleporting
if (isTeleporting) {
// Close open containers
if (entityPlayerMP.openContainer != entityPlayerMP.inventoryContainer) {
// Call API method to make sure we capture it
((Player) entityPlayerMP).closeInventory();
}
((WorldServer) location.getExtent()).getChunkProvider().loadChunk(location.getChunkPosition().getX(), location.getChunkPosition().getZ());
}
entityPlayerMP.connection.setPlayerLocation(location.getX(), location.getY(), location.getZ(), thisEntity.rotationYaw, thisEntity.rotationPitch);
// Set last move to teleport target
((IMixinNetHandlerPlayServer) entityPlayerMP.connection).setLastMoveLocation(null);
} else {
setPosition(location.getPosition().getX(), location.getPosition().getY(), location.getPosition().getZ());
}
}
if (isTeleporting) {
// Re-attach passengers
for (net.minecraft.entity.Entity passenger : passengers) {
passenger.startRiding(thisEntity, true);
}
}
chunkProviderServer.setForceChunkRequests(false);
return true;
}
}
use of org.spongepowered.common.event.tracking.phase.plugin.BasicPluginContext in project SpongeCommon by SpongePowered.
the class SpongeBlockVolumeWorker method map.
@Override
public void map(BlockVolumeMapper mapper, MutableBlockVolume destination) {
final Vector3i offset = align(destination);
final int xOffset = offset.getX();
final int yOffset = offset.getY();
final int zOffset = offset.getZ();
final UnmodifiableBlockVolume unmodifiableVolume = this.volume.getUnmodifiableBlockView();
final int xMin = unmodifiableVolume.getBlockMin().getX();
final int yMin = unmodifiableVolume.getBlockMin().getY();
final int zMin = unmodifiableVolume.getBlockMin().getZ();
final int xMax = unmodifiableVolume.getBlockMax().getX();
final int yMax = unmodifiableVolume.getBlockMax().getY();
final int zMax = unmodifiableVolume.getBlockMax().getZ();
// a single go, requiring only one event
try (BasicPluginContext phaseState = PluginPhase.State.BLOCK_WORKER.createPhaseContext().source(this).buildAndSwitch()) {
for (int z = zMin; z <= zMax; z++) {
for (int y = yMin; y <= yMax; y++) {
for (int x = xMin; x <= xMax; x++) {
final BlockState block = mapper.map(unmodifiableVolume, x, y, z);
destination.setBlock(x + xOffset, y + yOffset, z + zOffset, block);
}
}
}
}
}
use of org.spongepowered.common.event.tracking.phase.plugin.BasicPluginContext in project SpongeCommon by SpongePowered.
the class SpongeBlockVolumeWorker method merge.
@Override
public void merge(BlockVolume second, BlockVolumeMerger merger, MutableBlockVolume destination) {
final Vector3i offsetSecond = align(second);
final int xOffsetSecond = offsetSecond.getX();
final int yOffsetSecond = offsetSecond.getY();
final int zOffsetSecond = offsetSecond.getZ();
final Vector3i offsetDestination = align(destination);
final int xOffsetDestination = offsetDestination.getX();
final int yOffsetDestination = offsetDestination.getY();
final int zOffsetDestination = offsetDestination.getZ();
final UnmodifiableBlockVolume firstUnmodifiableVolume = this.volume.getUnmodifiableBlockView();
final int xMin = firstUnmodifiableVolume.getBlockMin().getX();
final int yMin = firstUnmodifiableVolume.getBlockMin().getY();
final int zMin = firstUnmodifiableVolume.getBlockMin().getZ();
final int xMax = firstUnmodifiableVolume.getBlockMax().getX();
final int yMax = firstUnmodifiableVolume.getBlockMax().getY();
final int zMax = firstUnmodifiableVolume.getBlockMax().getZ();
final UnmodifiableBlockVolume secondUnmodifiableVolume = second.getUnmodifiableBlockView();
try (BasicPluginContext context = PluginPhase.State.BLOCK_WORKER.createPhaseContext().source(this).buildAndSwitch()) {
for (int z = zMin; z <= zMax; z++) {
for (int y = yMin; y <= yMax; y++) {
for (int x = xMin; x <= xMax; x++) {
final BlockState block = merger.merge(firstUnmodifiableVolume, x, y, z, secondUnmodifiableVolume, x + xOffsetSecond, y + yOffsetSecond, z + zOffsetSecond);
destination.setBlock(x + xOffsetDestination, y + yOffsetDestination, z + zOffsetDestination, block);
}
}
}
}
}
use of org.spongepowered.common.event.tracking.phase.plugin.BasicPluginContext in project SpongeCommon by SpongePowered.
the class MixinWorldServer method spawnEntity.
@Override
public boolean spawnEntity(Entity entity) {
checkNotNull(entity, "The entity cannot be null!");
if (!PhaseTracker.validateEntitySpawn(this, entity)) {
return true;
}
final PhaseTracker phaseTracker = PhaseTracker.getInstance();
final IPhaseState state = phaseTracker.getCurrentState();
if (!state.alreadyCapturingEntitySpawns()) {
try (final BasicPluginContext context = PluginPhase.State.CUSTOM_SPAWN.createPhaseContext().addCaptures().buildAndSwitch()) {
phaseTracker.spawnEntityWithCause(this, entity);
return true;
}
}
return phaseTracker.spawnEntityWithCause(this, entity);
}
Aggregations