Search in sources :

Example 6 with PlayerTracker

use of org.spongepowered.common.entity.PlayerTracker in project SpongeCommon by SpongePowered.

the class MixinChunk_Tracker method getBlockOwner.

@Override
public Optional<User> getBlockOwner(BlockPos pos) {
    final int intKey = blockPosToInt(pos);
    final PlayerTracker intTracker = this.trackedIntBlockPositions.get(intKey);
    if (intTracker != null) {
        final int notifierIndex = intTracker.ownerIndex;
        return getValidatedUser(intKey, notifierIndex);
    } else {
        final short shortKey = blockPosToShort(pos);
        if (this.trackedShortBlockPositions.get(shortKey) != null) {
            PlayerTracker tracker = this.trackedShortBlockPositions.get(shortKey);
            final int notifierIndex = tracker.ownerIndex;
            return getValidatedUser(shortKey, notifierIndex);
        }
    }
    return Optional.empty();
}
Also used : PlayerTracker(org.spongepowered.common.entity.PlayerTracker)

Example 7 with PlayerTracker

use of org.spongepowered.common.entity.PlayerTracker in project SpongeCommon by SpongePowered.

the class LevelChunkMixin method bridge$trackedUUID.

public Optional<UUID> bridge$trackedUUID(final BlockPos pos, final Function<PlayerTracker, Integer> func) {
    if (((LevelBridge) this.level).bridge$isFake()) {
        return Optional.empty();
    }
    final int key = Constants.Sponge.blockPosToInt(pos);
    final PlayerTracker intTracker = this.impl$trackedIntBlockPositions.get(key);
    if (intTracker != null) {
        final int ownerIndex = func.apply(intTracker);
        return this.impl$getValidatedUUID(key, ownerIndex);
    }
    final short shortKey = Constants.Sponge.blockPosToShort(pos);
    final PlayerTracker shortTracker = this.impl$trackedShortBlockPositions.get(shortKey);
    if (shortTracker != null) {
        final int ownerIndex = func.apply(shortTracker);
        return this.impl$getValidatedUUID(shortKey, ownerIndex);
    }
    return Optional.empty();
}
Also used : LevelBridge(org.spongepowered.common.bridge.world.level.LevelBridge) PlayerTracker(org.spongepowered.common.entity.PlayerTracker)

Example 8 with PlayerTracker

use of org.spongepowered.common.entity.PlayerTracker in project SpongeCommon by SpongePowered.

the class ChunkSerializerMixin_Tracker method impl$writeMap.

private static <T> void impl$writeMap(ListTag positions, Map<T, PlayerTracker> map, BiConsumer<CompoundTag, T> consumer) {
    for (final Map.Entry<T, PlayerTracker> mapEntry : map.entrySet()) {
        final T pos = mapEntry.getKey();
        final int ownerUniqueIdIndex = mapEntry.getValue().creatorindex;
        final int notifierUniqueIdIndex = mapEntry.getValue().notifierIndex;
        final CompoundTag valueNbt = new CompoundTag();
        valueNbt.putInt("owner", ownerUniqueIdIndex);
        valueNbt.putInt("notifier", notifierUniqueIdIndex);
        consumer.accept(valueNbt, pos);
        positions.add(valueNbt);
    }
}
Also used : PlayerTracker(org.spongepowered.common.entity.PlayerTracker) HashMap(java.util.HashMap) Map(java.util.Map) CompoundTag(net.minecraft.nbt.CompoundTag)

Example 9 with PlayerTracker

use of org.spongepowered.common.entity.PlayerTracker in project SpongeCommon by SpongePowered.

the class MixinChunk_Tracker method getBlockOwnerUUID.

@Override
public Optional<UUID> getBlockOwnerUUID(BlockPos pos) {
    final int key = blockPosToInt(pos);
    final PlayerTracker intTracker = this.trackedIntBlockPositions.get(key);
    if (intTracker != null) {
        final int ownerIndex = intTracker.ownerIndex;
        return getValidatedUUID(key, ownerIndex);
    } else {
        final short shortKey = blockPosToShort(pos);
        final PlayerTracker shortTracker = this.trackedShortBlockPositions.get(shortKey);
        if (shortTracker != null) {
            final int ownerIndex = shortTracker.ownerIndex;
            return getValidatedUUID(shortKey, ownerIndex);
        }
    }
    return Optional.empty();
}
Also used : PlayerTracker(org.spongepowered.common.entity.PlayerTracker)

Example 10 with PlayerTracker

use of org.spongepowered.common.entity.PlayerTracker in project SpongeCommon by SpongePowered.

the class ChunkSerializerMixin_Tracker method impl$readSpongeLevelData.

@Redirect(method = "read", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/level/chunk/ChunkAccess;setLightCorrect(Z)V"))
private static void impl$readSpongeLevelData(final ChunkAccess chunkAccess, final boolean var1, final ServerLevel param0, final StructureManager param1, final PoiManager param2, final ChunkPos param3, final CompoundTag param4) {
    if (!(chunkAccess instanceof LevelChunk)) {
        return;
    }
    final CompoundTag level = (CompoundTag) param4.get("Level");
    final CompoundTag spongeData = level.getCompound(Constants.Sponge.Data.V2.SPONGE_DATA);
    if (spongeData.isEmpty()) {
        return;
    }
    final Map<Integer, PlayerTracker> trackedIntPlayerPositions = new HashMap<>();
    final Map<Short, PlayerTracker> trackedShortPlayerPositions = new HashMap<>();
    final ListTag list = spongeData.getList(Constants.Sponge.SPONGE_BLOCK_POS_TABLE, 10);
    final LevelChunkBridge chunk = (LevelChunkBridge) chunkAccess;
    for (Tag tag : list) {
        final PlayerTracker tracker = new PlayerTracker();
        final CompoundTag data = (CompoundTag) tag;
        final boolean isShortPos = data.contains("pos");
        if (data.contains("owner")) {
            tracker.creatorindex = data.getInt("owner");
        }
        if (data.contains("notifier")) {
            tracker.notifierIndex = data.getInt("notifier");
        }
        if (tracker.notifierIndex != -1 || tracker.creatorindex != -1) {
            if (isShortPos) {
                trackedShortPlayerPositions.put(data.getShort("pos"), tracker);
            } else {
                trackedIntPlayerPositions.put(data.getInt("ipos"), tracker);
            }
        }
    }
    chunk.bridge$setTrackedIntPlayerPositions(trackedIntPlayerPositions);
    chunk.bridge$setTrackedShortPlayerPositions(trackedShortPlayerPositions);
}
Also used : LevelChunk(net.minecraft.world.level.chunk.LevelChunk) HashMap(java.util.HashMap) PlayerTracker(org.spongepowered.common.entity.PlayerTracker) LevelChunkBridge(org.spongepowered.common.bridge.world.level.chunk.LevelChunkBridge) Tag(net.minecraft.nbt.Tag) CompoundTag(net.minecraft.nbt.CompoundTag) ListTag(net.minecraft.nbt.ListTag) ListTag(net.minecraft.nbt.ListTag) CompoundTag(net.minecraft.nbt.CompoundTag) Redirect(org.spongepowered.asm.mixin.injection.Redirect)

Aggregations

PlayerTracker (org.spongepowered.common.entity.PlayerTracker)10 HashMap (java.util.HashMap)2 Map (java.util.Map)2 CompoundTag (net.minecraft.nbt.CompoundTag)2 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)2 NBTTagList (net.minecraft.nbt.NBTTagList)2 Inject (org.spongepowered.asm.mixin.injection.Inject)2 IMixinChunk (org.spongepowered.common.interfaces.IMixinChunk)2 EntityPlayerMP (net.minecraft.entity.player.EntityPlayerMP)1 ListTag (net.minecraft.nbt.ListTag)1 Tag (net.minecraft.nbt.Tag)1 WorldServer (net.minecraft.world.WorldServer)1 LevelChunk (net.minecraft.world.level.chunk.LevelChunk)1 BlockType (org.spongepowered.api.block.BlockType)1 Redirect (org.spongepowered.asm.mixin.injection.Redirect)1 LevelBridge (org.spongepowered.common.bridge.world.level.LevelBridge)1 LevelChunkBridge (org.spongepowered.common.bridge.world.level.chunk.LevelChunkBridge)1 IMixinWorldInfo (org.spongepowered.common.interfaces.world.IMixinWorldInfo)1