Search in sources :

Example 16 with IMixinChunkProviderServer

use of org.spongepowered.common.interfaces.world.gen.IMixinChunkProviderServer in project SpongeCommon by SpongePowered.

the class SpongeTeleportHelper method getSafeLocation.

@Override
public Optional<Location<World>> getSafeLocation(Location<World> location, int height, int width, int distanceToDrop, TeleportHelperFilter filter, TeleportHelperFilter... additionalFilters) {
    final World world = location.getExtent();
    final Set<TeleportHelperFilter> filters = Sets.newHashSet(additionalFilters);
    filters.add(filter);
    if (SpongeImpl.getGlobalConfig().getConfig().getTeleportHelper().isForceBlacklistOn()) {
        // Always force this into the set if the user has requested it.
        filters.add(TeleportHelperFilters.CONFIG);
    }
    IMixinChunkProviderServer chunkProviderServer = (IMixinChunkProviderServer) ((net.minecraft.world.WorldServer) world).getChunkProvider();
    chunkProviderServer.setForceChunkRequests(true);
    try {
        // Get the vectors to check, and get the block types with them.
        // The vectors should be sorted by distance from the centre of the checking region, so
        // this makes it easier to try to get close, because we can just iterate and get progressively further out.
        Optional<Vector3i> result = getSafeLocation(world, getBlockLocations(location, height, width), distanceToDrop, filters);
        return result.map(vector3i -> new Location<>(world, vector3i.toDouble().add(0.5, 0, 0.5)));
    } finally {
        // Just in case some exception occurs, we want this to disable again.
        chunkProviderServer.setForceChunkRequests(false);
    }
}
Also used : TeleportHelperFilter(org.spongepowered.api.world.teleport.TeleportHelperFilter) Vector3i(com.flowpowered.math.vector.Vector3i) World(org.spongepowered.api.world.World) IMixinChunkProviderServer(org.spongepowered.common.interfaces.world.gen.IMixinChunkProviderServer)

Example 17 with IMixinChunkProviderServer

use of org.spongepowered.common.interfaces.world.gen.IMixinChunkProviderServer in project SpongeCommon by SpongePowered.

the class MixinChunk_Async_Lighting method onRelightChecksGetBlockState.

@Redirect(method = "enqueueRelightChecks", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/World;getBlockState(Lnet/minecraft/util/math/BlockPos;)Lnet/minecraft/block/state/IBlockState;"))
private IBlockState onRelightChecksGetBlockState(World world, BlockPos pos) {
    Chunk chunk = ((IMixinChunkProviderServer) world.getChunkProvider()).getLoadedChunkWithoutMarkingActive(pos.getX() >> 4, pos.getZ() >> 4);
    final IMixinChunk spongeChunk = (IMixinChunk) chunk;
    if (chunk == null || chunk.unloadQueued || !spongeChunk.areNeighborsLoaded()) {
        return Blocks.AIR.getDefaultState();
    }
    return chunk.getBlockState(pos);
}
Also used : IMixinChunk(org.spongepowered.common.interfaces.IMixinChunk) IMixinChunk(org.spongepowered.common.interfaces.IMixinChunk) Chunk(net.minecraft.world.chunk.Chunk) IMixinChunkProviderServer(org.spongepowered.common.interfaces.world.gen.IMixinChunkProviderServer) Redirect(org.spongepowered.asm.mixin.injection.Redirect)

Example 18 with IMixinChunkProviderServer

use of org.spongepowered.common.interfaces.world.gen.IMixinChunkProviderServer in project SpongeCommon by SpongePowered.

the class MixinWorld_Tracker method setCreator.

@Override
public void setCreator(int x, int y, int z, @Nullable UUID uuid) {
    final Chunk chunk = ((IMixinChunkProviderServer) this.chunkProvider).getLoadedChunkWithoutMarkingActive(x >> 4, z >> 4);
    if (chunk == null) {
        return;
    }
    BlockPos pos = new BlockPos(x, y, z);
    ((IMixinChunk) chunk).setBlockCreator(pos, uuid);
}
Also used : IMixinChunk(org.spongepowered.common.interfaces.IMixinChunk) BlockPos(net.minecraft.util.math.BlockPos) IMixinChunk(org.spongepowered.common.interfaces.IMixinChunk) Chunk(net.minecraft.world.chunk.Chunk) IMixinChunkProviderServer(org.spongepowered.common.interfaces.world.gen.IMixinChunkProviderServer)

Example 19 with IMixinChunkProviderServer

use of org.spongepowered.common.interfaces.world.gen.IMixinChunkProviderServer in project SpongeCommon by SpongePowered.

the class MixinWorld_Tracker method getCreator.

@Override
public Optional<UUID> getCreator(int x, int y, int z) {
    final Chunk chunk = ((IMixinChunkProviderServer) this.chunkProvider).getLoadedChunkWithoutMarkingActive(x >> 4, z >> 4);
    if (chunk == null) {
        return Optional.empty();
    }
    BlockPos pos = new BlockPos(x, y, z);
    // blocks changing with potentially n block notifiers and n block owners.
    return ((IMixinChunk) chunk).getBlockOwnerUUID(pos);
}
Also used : IMixinChunk(org.spongepowered.common.interfaces.IMixinChunk) BlockPos(net.minecraft.util.math.BlockPos) IMixinChunk(org.spongepowered.common.interfaces.IMixinChunk) Chunk(net.minecraft.world.chunk.Chunk) IMixinChunkProviderServer(org.spongepowered.common.interfaces.world.gen.IMixinChunkProviderServer)

Example 20 with IMixinChunkProviderServer

use of org.spongepowered.common.interfaces.world.gen.IMixinChunkProviderServer in project SpongeCommon by SpongePowered.

the class MixinWorld_Tracker method getNotifier.

@Override
public Optional<UUID> getNotifier(int x, int y, int z) {
    final Chunk chunk = ((IMixinChunkProviderServer) this.chunkProvider).getLoadedChunkWithoutMarkingActive(x >> 4, z >> 4);
    if (chunk == null) {
        return Optional.empty();
    }
    BlockPos pos = new BlockPos(x, y, z);
    // blocks changing with potentially n block notifiers and n block owners.
    return ((IMixinChunk) chunk).getBlockNotifierUUID(pos);
}
Also used : IMixinChunk(org.spongepowered.common.interfaces.IMixinChunk) BlockPos(net.minecraft.util.math.BlockPos) IMixinChunk(org.spongepowered.common.interfaces.IMixinChunk) Chunk(net.minecraft.world.chunk.Chunk) IMixinChunkProviderServer(org.spongepowered.common.interfaces.world.gen.IMixinChunkProviderServer)

Aggregations

IMixinChunkProviderServer (org.spongepowered.common.interfaces.world.gen.IMixinChunkProviderServer)24 Chunk (net.minecraft.world.chunk.Chunk)16 IMixinChunk (org.spongepowered.common.interfaces.IMixinChunk)15 BlockPos (net.minecraft.util.math.BlockPos)9 IMixinWorldServer (org.spongepowered.common.interfaces.world.IMixinWorldServer)5 Direction (org.spongepowered.api.util.Direction)4 PhaseTracker (org.spongepowered.common.event.tracking.PhaseTracker)4 Vector3i (com.flowpowered.math.vector.Vector3i)3 WorldServer (net.minecraft.world.WorldServer)3 World (org.spongepowered.api.world.World)3 Overwrite (org.spongepowered.asm.mixin.Overwrite)3 Inject (org.spongepowered.asm.mixin.injection.Inject)3 IMixinWorld (org.spongepowered.common.interfaces.world.IMixinWorld)3 EntityPlayer (net.minecraft.entity.player.EntityPlayer)2 EnumFacing (net.minecraft.util.EnumFacing)2 World (net.minecraft.world.World)2 NotifyNeighborBlockEvent (org.spongepowered.api.event.block.NotifyNeighborBlockEvent)2 Chunk (org.spongepowered.api.world.Chunk)2 Redirect (org.spongepowered.asm.mixin.injection.Redirect)2 WorldTimingsHandler (co.aikar.timings.WorldTimingsHandler)1