Search in sources :

Example 41 with IMixinChunk

use of org.spongepowered.common.interfaces.IMixinChunk 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 42 with IMixinChunk

use of org.spongepowered.common.interfaces.IMixinChunk 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 43 with IMixinChunk

use of org.spongepowered.common.interfaces.IMixinChunk 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)

Example 44 with IMixinChunk

use of org.spongepowered.common.interfaces.IMixinChunk in project SpongeCommon by SpongePowered.

the class SpongeMessageHandler method handleRequest.

public static void handleRequest(MessageTrackerDataRequest message, RemoteConnection connection, Platform.Type side) {
    if (!(connection instanceof PlayerConnection)) {
        return;
    }
    Player player = ((PlayerConnection) connection).getPlayer();
    if (!player.hasPermission("sponge.debug.block-tracking")) {
        return;
    }
    EntityPlayerMP sender = (EntityPlayerMP) player;
    BlockPos pos = new BlockPos(message.x, message.y, message.z);
    if (!sender.world.isBlockLoaded(pos)) {
        return;
    }
    String ownerName;
    String notifierName;
    Optional<User> owner = Optional.empty();
    Optional<User> notifier = Optional.empty();
    if (message.type == 0) {
        // block
        IMixinChunk spongeChunk = (IMixinChunk) sender.world.getChunkFromBlockCoords(pos);
        owner = spongeChunk.getBlockOwner(pos);
        notifier = spongeChunk.getBlockNotifier(pos);
    } else if (message.type == 1) {
        // entity
        Entity entity = sender.world.getEntityByID(message.entityId);
        if (entity != null) {
            IMixinEntity spongeEntity = (IMixinEntity) entity;
            owner = spongeEntity.getCreatorUser();
            notifier = spongeEntity.getNotifierUser();
        }
    }
    ownerName = owner.map(User::getName).orElse("");
    notifierName = notifier.map(User::getName).orElse("");
    channel.sendTo(player, new MessageTrackerDataResponse(ownerName, notifierName));
}
Also used : Entity(net.minecraft.entity.Entity) IMixinEntity(org.spongepowered.common.interfaces.entity.IMixinEntity) Player(org.spongepowered.api.entity.living.player.Player) User(org.spongepowered.api.entity.living.player.User) IMixinChunk(org.spongepowered.common.interfaces.IMixinChunk) EntityPlayerMP(net.minecraft.entity.player.EntityPlayerMP) BlockPos(net.minecraft.util.math.BlockPos) IMixinEntity(org.spongepowered.common.interfaces.entity.IMixinEntity) PlayerConnection(org.spongepowered.api.network.PlayerConnection)

Example 45 with IMixinChunk

use of org.spongepowered.common.interfaces.IMixinChunk in project SpongeCommon by SpongePowered.

the class MixinWorld method getIntersectingEntities.

private Set<EntityHit> getIntersectingEntities(Vector3d start, double yDirection, double distance, Predicate<EntityHit> filter) {
    final Set<EntityHit> intersecting = new HashSet<>();
    // Current chunk
    final Vector3d direction = yDirection < 0 ? Vector3d.UNIT_Y.negate() : Vector3d.UNIT_Y;
    final double endY = start.getY() + yDirection * distance;
    final Vector3i chunkPos = SpongeChunkLayout.instance.forceToChunk(start.toInt());
    ((IMixinChunk) getChunk(chunkPos).get()).getIntersectingEntities(start, direction, distance, filter, start.getY(), endY, intersecting);
    // Check adjacent chunks if near them
    final int nearDistance = 2;
    // Neighbour -x chunk
    final Vector3i chunkBlockPos = SpongeChunkLayout.instance.forceToWorld(chunkPos);
    if (start.getX() - chunkBlockPos.getX() <= nearDistance) {
        ((IMixinChunk) getChunk(chunkPos.add(-1, 0, 0)).get()).getIntersectingEntities(start, direction, distance, filter, start.getY(), endY, intersecting);
    }
    // Neighbour -z chunk
    if (start.getZ() - chunkBlockPos.getZ() <= nearDistance) {
        ((IMixinChunk) getChunk(chunkPos.add(0, 0, -1)).get()).getIntersectingEntities(start, direction, distance, filter, start.getY(), endY, intersecting);
    }
    // Neighbour +x chunk
    final int chunkWidth = SpongeChunkLayout.CHUNK_SIZE.getX();
    if (chunkBlockPos.getX() + chunkWidth - start.getX() <= nearDistance) {
        ((IMixinChunk) getChunk(chunkPos.add(1, 0, 0)).get()).getIntersectingEntities(start, direction, distance, filter, start.getY(), endY, intersecting);
    }
    // Neighbour +z chunk
    if (chunkBlockPos.getZ() + chunkWidth - start.getZ() <= nearDistance) {
        ((IMixinChunk) getChunk(chunkPos.add(0, 0, 1)).get()).getIntersectingEntities(start, direction, distance, filter, start.getY(), endY, intersecting);
    }
    return intersecting;
}
Also used : IMixinChunk(org.spongepowered.common.interfaces.IMixinChunk) Vector3d(com.flowpowered.math.vector.Vector3d) Vector3i(com.flowpowered.math.vector.Vector3i) HashSet(java.util.HashSet)

Aggregations

IMixinChunk (org.spongepowered.common.interfaces.IMixinChunk)49 Chunk (net.minecraft.world.chunk.Chunk)21 BlockPos (net.minecraft.util.math.BlockPos)18 IMixinChunkProviderServer (org.spongepowered.common.interfaces.world.gen.IMixinChunkProviderServer)12 User (org.spongepowered.api.entity.living.player.User)11 Inject (org.spongepowered.asm.mixin.injection.Inject)8 IBlockState (net.minecraft.block.state.IBlockState)7 World (org.spongepowered.api.world.World)7 IMixinEntity (org.spongepowered.common.interfaces.entity.IMixinEntity)7 LocatableBlock (org.spongepowered.api.world.LocatableBlock)6 Vector3i (com.flowpowered.math.vector.Vector3i)5 Block (net.minecraft.block.Block)5 StackFrame (org.spongepowered.api.event.CauseStackManager.StackFrame)5 Direction (org.spongepowered.api.util.Direction)5 PhaseTracker (org.spongepowered.common.event.tracking.PhaseTracker)5 Overwrite (org.spongepowered.asm.mixin.Overwrite)4 PhaseData (org.spongepowered.common.event.tracking.PhaseData)4 IMixinTileEntity (org.spongepowered.common.interfaces.block.tile.IMixinTileEntity)4 IMixinWorldServer (org.spongepowered.common.interfaces.world.IMixinWorldServer)4 Vector3d (com.flowpowered.math.vector.Vector3d)3