Search in sources :

Example 1 with PlayerTracker

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

the class MixinAnvilChunkLoader method onReadChunkFromNBT.

@Inject(method = "readChunkFromNBT", at = @At(value = "INVOKE", target = "Lnet/minecraft/nbt/NBTTagCompound;getIntArray(Ljava/lang/String;)[I", shift = At.Shift.BEFORE), locals = LocalCapture.CAPTURE_FAILHARD)
public void onReadChunkFromNBT(World worldIn, NBTTagCompound compound, CallbackInfoReturnable<net.minecraft.world.chunk.Chunk> ci, int chunkX, int chunkZ, net.minecraft.world.chunk.Chunk chunkIn) {
    if (compound.hasKey(NbtDataUtil.SPONGE_DATA)) {
        Map<Integer, PlayerTracker> trackedIntPlayerPositions = Maps.newHashMap();
        Map<Short, PlayerTracker> trackedShortPlayerPositions = Maps.newHashMap();
        NBTTagList positions = compound.getCompoundTag(NbtDataUtil.SPONGE_DATA).getTagList(NbtDataUtil.SPONGE_BLOCK_POS_TABLE, 10);
        IMixinChunk chunk = (IMixinChunk) chunkIn;
        for (int i = 0; i < positions.tagCount(); i++) {
            NBTTagCompound valueNbt = positions.getCompoundTagAt(i);
            boolean isShortPos = valueNbt.hasKey("pos");
            PlayerTracker tracker = new PlayerTracker();
            if (valueNbt.hasKey("owner")) {
                tracker.ownerIndex = valueNbt.getInteger("owner");
            } else if (valueNbt.hasKey("uuid")) {
                // Migrate old data, remove in future
                tracker.ownerIndex = valueNbt.getInteger("uuid");
            }
            if (valueNbt.hasKey("notifier")) {
                tracker.notifierIndex = valueNbt.getInteger("notifier");
            }
            if (tracker.notifierIndex != -1 || tracker.ownerIndex != -1) {
                if (isShortPos) {
                    trackedShortPlayerPositions.put(valueNbt.getShort("pos"), tracker);
                } else {
                    trackedIntPlayerPositions.put(valueNbt.getInteger("ipos"), tracker);
                }
            }
        }
        chunk.setTrackedIntPlayerPositions(trackedIntPlayerPositions);
        chunk.setTrackedShortPlayerPositions(trackedShortPlayerPositions);
    }
}
Also used : NBTTagList(net.minecraft.nbt.NBTTagList) IMixinChunk(org.spongepowered.common.interfaces.IMixinChunk) PlayerTracker(org.spongepowered.common.entity.PlayerTracker) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) Inject(org.spongepowered.asm.mixin.injection.Inject)

Example 2 with PlayerTracker

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

the class MixinAnvilChunkLoader method onWriteChunkToNBT.

@Inject(method = "writeChunkToNBT", at = @At(value = "RETURN"))
public void onWriteChunkToNBT(net.minecraft.world.chunk.Chunk chunkIn, World worldIn, NBTTagCompound compound, CallbackInfo ci) {
    IMixinChunk chunk = (IMixinChunk) chunkIn;
    // Add tracked block positions
    if (chunk.getTrackedShortPlayerPositions().size() > 0 || chunk.getTrackedIntPlayerPositions().size() > 0) {
        NBTTagCompound trackedNbt = new NBTTagCompound();
        NBTTagList positions = new NBTTagList();
        trackedNbt.setTag(NbtDataUtil.SPONGE_BLOCK_POS_TABLE, positions);
        compound.setTag(NbtDataUtil.SPONGE_DATA, trackedNbt);
        for (Map.Entry<Short, PlayerTracker> mapEntry : chunk.getTrackedShortPlayerPositions().entrySet()) {
            Short pos = mapEntry.getKey();
            Integer ownerUniqueIdIndex = mapEntry.getValue().ownerIndex;
            Integer notifierUniqueIdIndex = mapEntry.getValue().notifierIndex;
            NBTTagCompound valueNbt = new NBTTagCompound();
            valueNbt.setInteger("owner", ownerUniqueIdIndex);
            valueNbt.setInteger("notifier", notifierUniqueIdIndex);
            valueNbt.setShort("pos", pos);
            positions.appendTag(valueNbt);
        }
        for (Map.Entry<Integer, PlayerTracker> mapEntry : chunk.getTrackedIntPlayerPositions().entrySet()) {
            Integer pos = mapEntry.getKey();
            Integer ownerUniqueIdIndex = mapEntry.getValue().ownerIndex;
            Integer notifierUniqueIdIndex = mapEntry.getValue().notifierIndex;
            NBTTagCompound valueNbt = new NBTTagCompound();
            valueNbt.setInteger("owner", ownerUniqueIdIndex);
            valueNbt.setInteger("notifier", notifierUniqueIdIndex);
            valueNbt.setInteger("ipos", pos);
            positions.appendTag(valueNbt);
        }
    }
}
Also used : NBTTagList(net.minecraft.nbt.NBTTagList) IMixinChunk(org.spongepowered.common.interfaces.IMixinChunk) PlayerTracker(org.spongepowered.common.entity.PlayerTracker) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) Map(java.util.Map) Inject(org.spongepowered.asm.mixin.injection.Inject)

Example 3 with PlayerTracker

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

the class MixinChunk_Tracker method getBlockNotifierUUID.

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

Example 4 with PlayerTracker

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

the class MixinChunk_Tracker method addTrackedBlockPosition.

@Override
public void addTrackedBlockPosition(Block block, BlockPos pos, User user, PlayerTracker.Type trackerType) {
    if (this.world.isRemote) {
        return;
    }
    if (PhaseTracker.getInstance().getCurrentState().ignoresBlockTracking()) {
        // Don't track chunk gen
        return;
    }
    // Don't track fake players
    if (user instanceof EntityPlayerMP && SpongeImplHooks.isFakePlayer((EntityPlayerMP) user)) {
        return;
    }
    if (!SpongeHooks.getActiveConfig((WorldServer) this.world).getConfig().getBlockTracking().getBlockBlacklist().contains(((BlockType) block).getId())) {
        SpongeHooks.logBlockTrack(this.world, block, pos, user, true);
    } else {
        SpongeHooks.logBlockTrack(this.world, block, pos, user, false);
    }
    final IMixinWorldInfo worldInfo = (IMixinWorldInfo) this.world.getWorldInfo();
    final int indexForUniqueId = worldInfo.getIndexForUniqueId(user.getUniqueId());
    if (pos.getY() <= 255) {
        short blockPos = blockPosToShort(pos);
        final PlayerTracker playerTracker = this.trackedShortBlockPositions.get(blockPos);
        if (playerTracker != null) {
            if (trackerType == PlayerTracker.Type.OWNER) {
                playerTracker.ownerIndex = indexForUniqueId;
                playerTracker.notifierIndex = indexForUniqueId;
            } else {
                playerTracker.notifierIndex = indexForUniqueId;
            }
        } else {
            this.trackedShortBlockPositions.put(blockPos, new PlayerTracker(indexForUniqueId, trackerType));
        }
    } else {
        int blockPos = blockPosToInt(pos);
        final PlayerTracker playerTracker = this.trackedIntBlockPositions.get(blockPos);
        if (playerTracker != null) {
            if (trackerType == PlayerTracker.Type.OWNER) {
                playerTracker.ownerIndex = indexForUniqueId;
            } else {
                playerTracker.notifierIndex = indexForUniqueId;
            }
        } else {
            this.trackedIntBlockPositions.put(blockPos, new PlayerTracker(indexForUniqueId, trackerType));
        }
    }
}
Also used : BlockType(org.spongepowered.api.block.BlockType) PlayerTracker(org.spongepowered.common.entity.PlayerTracker) IMixinWorldInfo(org.spongepowered.common.interfaces.world.IMixinWorldInfo) EntityPlayerMP(net.minecraft.entity.player.EntityPlayerMP) WorldServer(net.minecraft.world.WorldServer)

Example 5 with PlayerTracker

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

the class MixinChunk_Tracker method getBlockNotifier.

@Override
public Optional<User> getBlockNotifier(BlockPos pos) {
    final int intKey = blockPosToInt(pos);
    final PlayerTracker intTracker = this.trackedIntBlockPositions.get(intKey);
    if (intTracker != null) {
        final int notifierIndex = intTracker.notifierIndex;
        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.notifierIndex;
            return getValidatedUser(shortKey, notifierIndex);
        }
    }
    return Optional.empty();
}
Also used : PlayerTracker(org.spongepowered.common.entity.PlayerTracker)

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