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