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);
}
}
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);
}
}
}
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();
}
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));
}
}
}
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();
}
Aggregations