aboutsummaryrefslogtreecommitdiff
path: root/spark-fabric/src/main/java
diff options
context:
space:
mode:
authorlucko <git@lucko.me>2022-12-27 09:17:54 +0000
committerGitHub <noreply@github.com>2022-12-27 09:17:54 +0000
commite5b278047ccb7bc6b301d787474c51d162911867 (patch)
tree11bba64e8f28ce8b83adc05252b75f17e2ccbf6a /spark-fabric/src/main/java
parent4a16a1a2f4eb09f706b4a541e3d31618de29420b (diff)
parent1075665def4a41cf0064255a6da1d1a652f5d473 (diff)
downloadspark-e5b278047ccb7bc6b301d787474c51d162911867.tar.gz
spark-e5b278047ccb7bc6b301d787474c51d162911867.tar.bz2
spark-e5b278047ccb7bc6b301d787474c51d162911867.zip
Merge pull request #284 from embeddedt/forge-1.7.10
Align 1.7.10 with master
Diffstat (limited to 'spark-fabric/src/main/java')
-rw-r--r--spark-fabric/src/main/java/me/lucko/spark/fabric/FabricClassSourceLookup.java161
-rw-r--r--spark-fabric/src/main/java/me/lucko/spark/fabric/FabricExtraMetadataProvider.java75
-rw-r--r--spark-fabric/src/main/java/me/lucko/spark/fabric/FabricServerConfigProvider.java57
-rw-r--r--spark-fabric/src/main/java/me/lucko/spark/fabric/FabricWorldInfoProvider.java178
-rw-r--r--spark-fabric/src/main/java/me/lucko/spark/fabric/mixin/ClientEntityManagerAccessor.java40
-rw-r--r--spark-fabric/src/main/java/me/lucko/spark/fabric/mixin/ClientWorldAccessor.java36
-rw-r--r--spark-fabric/src/main/java/me/lucko/spark/fabric/mixin/MinecraftClientAccessor.java34
-rw-r--r--spark-fabric/src/main/java/me/lucko/spark/fabric/mixin/ServerEntityManagerAccessor.java40
-rw-r--r--spark-fabric/src/main/java/me/lucko/spark/fabric/mixin/ServerWorldAccessor.java36
-rw-r--r--spark-fabric/src/main/java/me/lucko/spark/fabric/placeholder/SparkFabricPlaceholderApi.java183
-rw-r--r--spark-fabric/src/main/java/me/lucko/spark/fabric/plugin/FabricClientSparkPlugin.java29
-rw-r--r--spark-fabric/src/main/java/me/lucko/spark/fabric/plugin/FabricServerSparkPlugin.java52
-rw-r--r--spark-fabric/src/main/java/me/lucko/spark/fabric/plugin/FabricSparkMixinPlugin.java71
-rw-r--r--spark-fabric/src/main/java/me/lucko/spark/fabric/plugin/FabricSparkPlugin.java24
-rw-r--r--spark-fabric/src/main/java/me/lucko/spark/fabric/smap/MixinUtils.java52
-rw-r--r--spark-fabric/src/main/java/me/lucko/spark/fabric/smap/SourceDebugCache.java87
-rw-r--r--spark-fabric/src/main/java/me/lucko/spark/fabric/smap/SourceMap.java133
-rw-r--r--spark-fabric/src/main/java/me/lucko/spark/fabric/smap/SourceMapProvider.java53
18 files changed, 1170 insertions, 171 deletions
diff --git a/spark-fabric/src/main/java/me/lucko/spark/fabric/FabricClassSourceLookup.java b/spark-fabric/src/main/java/me/lucko/spark/fabric/FabricClassSourceLookup.java
index 7030680..51834fc 100644
--- a/spark-fabric/src/main/java/me/lucko/spark/fabric/FabricClassSourceLookup.java
+++ b/spark-fabric/src/main/java/me/lucko/spark/fabric/FabricClassSourceLookup.java
@@ -22,18 +22,35 @@ package me.lucko.spark.fabric;
import com.google.common.collect.ImmutableMap;
-import me.lucko.spark.common.util.ClassSourceLookup;
+import me.lucko.spark.common.sampler.source.ClassSourceLookup;
+import me.lucko.spark.common.util.ClassFinder;
+import me.lucko.spark.fabric.smap.MixinUtils;
+import me.lucko.spark.fabric.smap.SourceMap;
+import me.lucko.spark.fabric.smap.SourceMapProvider;
import net.fabricmc.loader.api.FabricLoader;
import net.fabricmc.loader.api.ModContainer;
+import org.checkerframework.checker.nullness.qual.Nullable;
+import org.objectweb.asm.Type;
+import org.spongepowered.asm.mixin.FabricUtil;
+import org.spongepowered.asm.mixin.extensibility.IMixinConfig;
+import org.spongepowered.asm.mixin.transformer.Config;
+import org.spongepowered.asm.mixin.transformer.meta.MixinMerged;
+
+import java.lang.reflect.Method;
+import java.net.URI;
import java.nio.file.Path;
import java.util.Collection;
import java.util.Map;
public class FabricClassSourceLookup extends ClassSourceLookup.ByCodeSource {
+
+ private final ClassFinder classFinder = new ClassFinder();
+ private final SourceMapProvider smapProvider = new SourceMapProvider();
+
private final Path modsDirectory;
- private final Map<Path, String> pathToModMap;
+ private final Map<String, String> pathToModMap;
public FabricClassSourceLookup() {
FabricLoader loader = FabricLoader.getInstance();
@@ -43,7 +60,7 @@ public class FabricClassSourceLookup extends ClassSourceLookup.ByCodeSource {
@Override
public String identifyFile(Path path) {
- String id = this.pathToModMap.get(path);
+ String id = this.pathToModMap.get(path.toAbsolutePath().normalize().toString());
if (id != null) {
return id;
}
@@ -55,11 +72,141 @@ public class FabricClassSourceLookup extends ClassSourceLookup.ByCodeSource {
return super.identifyFileName(this.modsDirectory.relativize(path).toString());
}
- private static Map<Path, String> constructPathToModIdMap(Collection<ModContainer> mods) {
- ImmutableMap.Builder<Path, String> builder = ImmutableMap.builder();
+ @Override
+ public @Nullable String identify(MethodCall methodCall) throws Exception {
+ String className = methodCall.getClassName();
+ String methodName = methodCall.getMethodName();
+ String methodDesc = methodCall.getMethodDescriptor();
+
+ if (className.equals("native") || methodName.equals("<init>") || methodName.equals("<clinit>")) {
+ return null;
+ }
+
+ Class<?> clazz = this.classFinder.findClass(className);
+ if (clazz == null) {
+ return null;
+ }
+
+ Class<?>[] params = getParameterTypesForMethodDesc(methodDesc);
+ Method reflectMethod = clazz.getDeclaredMethod(methodName, params);
+
+ MixinMerged mixinMarker = reflectMethod.getDeclaredAnnotation(MixinMerged.class);
+ if (mixinMarker == null) {
+ return null;
+ }
+
+ return modIdFromMixinClass(mixinMarker.mixin());
+ }
+
+ @Override
+ public @Nullable String identify(MethodCallByLine methodCall) throws Exception {
+ String className = methodCall.getClassName();
+ String methodName = methodCall.getMethodName();
+ int lineNumber = methodCall.getLineNumber();
+
+ if (className.equals("native") || methodName.equals("<init>") || methodName.equals("<clinit>")) {
+ return null;
+ }
+
+ SourceMap smap = this.smapProvider.getSourceMap(className);
+ if (smap == null) {
+ return null;
+ }
+
+ int[] inputLineInfo = smap.getReverseLineMapping().get(lineNumber);
+ if (inputLineInfo == null || inputLineInfo.length == 0) {
+ return null;
+ }
+
+ for (int fileInfoIds : inputLineInfo) {
+ SourceMap.FileInfo inputFileInfo = smap.getFileInfo().get(fileInfoIds);
+ if (inputFileInfo == null) {
+ continue;
+ }
+
+ String path = inputFileInfo.path();
+ if (path.endsWith(".java")) {
+ path = path.substring(0, path.length() - 5);
+ }
+
+ String possibleMixinClassName = path.replace('/', '.');
+ if (possibleMixinClassName.equals(className)) {
+ continue;
+ }
+
+ return modIdFromMixinClass(possibleMixinClassName);
+ }
+
+ return null;
+ }
+
+ private static String modIdFromMixinClass(String mixinClassName) {
+ for (Config config : MixinUtils.getMixinConfigs().values()) {
+ IMixinConfig mixinConfig = config.getConfig();
+ if (mixinClassName.startsWith(mixinConfig.getMixinPackage())) {
+ return mixinConfig.getDecoration(FabricUtil.KEY_MOD_ID);
+ }
+ }
+ return null;
+ }
+
+ private Class<?>[] getParameterTypesForMethodDesc(String methodDesc) {
+ Type methodType = Type.getMethodType(methodDesc);
+ Class<?>[] params = new Class[methodType.getArgumentTypes().length];
+ Type[] argumentTypes = methodType.getArgumentTypes();
+
+ for (int i = 0, argumentTypesLength = argumentTypes.length; i < argumentTypesLength; i++) {
+ Type argumentType = argumentTypes[i];
+ params[i] = getClassFromType(argumentType);
+ }
+
+ return params;
+ }
+
+ private Class<?> getClassFromType(Type type) {
+ return switch (type.getSort()) {
+ case Type.VOID -> void.class;
+ case Type.BOOLEAN -> boolean.class;
+ case Type.CHAR -> char.class;
+ case Type.BYTE -> byte.class;
+ case Type.SHORT -> short.class;
+ case Type.INT -> int.class;
+ case Type.FLOAT -> float.class;
+ case Type.LONG -> long.class;
+ case Type.DOUBLE -> double.class;
+ case Type.ARRAY -> {
+ final Class<?> classFromType = getClassFromType(type.getElementType());
+ Class<?> result = classFromType;
+ if (classFromType != null) {
+ for (int i = 0; i < type.getDimensions(); i++) {
+ result = result.arrayType();
+ }
+ }
+ yield result;
+ }
+ case Type.OBJECT -> this.classFinder.findClass(type.getClassName());
+ default -> null;
+ };
+ }
+
+ private static Map<String, String> constructPathToModIdMap(Collection<ModContainer> mods) {
+ ImmutableMap.Builder<String, String> builder = ImmutableMap.builder();
for (ModContainer mod : mods) {
- Path path = mod.getRootPath().toAbsolutePath().normalize();
- builder.put(path, mod.getMetadata().getId());
+ String modId = mod.getMetadata().getId();
+ if (modId.equals("java")) {
+ continue;
+ }
+
+ for (Path path : mod.getRootPaths()) {
+ URI uri = path.toUri();
+ if (uri.getScheme().equals("jar") && path.toString().equals("/")) { // ZipFileSystem
+ String zipFilePath = path.getFileSystem().toString();
+ builder.put(zipFilePath, modId);
+ } else {
+ builder.put(path.toAbsolutePath().normalize().toString(), modId);
+ }
+
+ }
}
return builder.build();
}
diff --git a/spark-fabric/src/main/java/me/lucko/spark/fabric/FabricExtraMetadataProvider.java b/spark-fabric/src/main/java/me/lucko/spark/fabric/FabricExtraMetadataProvider.java
new file mode 100644
index 0000000..22794c2
--- /dev/null
+++ b/spark-fabric/src/main/java/me/lucko/spark/fabric/FabricExtraMetadataProvider.java
@@ -0,0 +1,75 @@
+/*
+ * This file is part of spark.
+ *
+ * Copyright (c) lucko (Luck) <luck@lucko.me>
+ * Copyright (c) contributors
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+package me.lucko.spark.fabric;
+
+import com.google.gson.JsonElement;
+import com.google.gson.JsonObject;
+
+import me.lucko.spark.common.platform.MetadataProvider;
+
+import net.minecraft.resource.ResourcePackManager;
+import net.minecraft.resource.ResourcePackProfile;
+import net.minecraft.resource.ResourcePackSource;
+
+import java.util.LinkedHashMap;
+import java.util.Map;
+
+public class FabricExtraMetadataProvider implements MetadataProvider {
+
+ private final ResourcePackManager resourcePackManager;
+
+ public FabricExtraMetadataProvider(ResourcePackManager resourcePackManager) {
+ this.resourcePackManager = resourcePackManager;
+ }
+
+ @Override
+ public Map<String, JsonElement> get() {
+ Map<String, JsonElement> metadata = new LinkedHashMap<>();
+ metadata.put("datapacks", datapackMetadata());
+ return metadata;
+ }
+
+ private JsonElement datapackMetadata() {
+ JsonObject datapacks = new JsonObject();
+ for (ResourcePackProfile profile : this.resourcePackManager.getEnabledProfiles()) {
+ JsonObject obj = new JsonObject();
+ obj.addProperty("name", profile.getDisplayName().getString());
+ obj.addProperty("description", profile.getDescription().getString());
+ obj.addProperty("source", resourcePackSource(profile.getSource()));
+ datapacks.add(profile.getName(), obj);
+ }
+ return datapacks;
+ }
+
+ private static String resourcePackSource(ResourcePackSource source) {
+ if (source == ResourcePackSource.NONE) {
+ return "none";
+ } else if (source == ResourcePackSource.BUILTIN) {
+ return "builtin";
+ } else if (source == ResourcePackSource.WORLD) {
+ return "world";
+ } else if (source == ResourcePackSource.SERVER) {
+ return "server";
+ } else {
+ return "unknown";
+ }
+ }
+}
diff --git a/spark-fabric/src/main/java/me/lucko/spark/fabric/FabricServerConfigProvider.java b/spark-fabric/src/main/java/me/lucko/spark/fabric/FabricServerConfigProvider.java
new file mode 100644
index 0000000..325a324
--- /dev/null
+++ b/spark-fabric/src/main/java/me/lucko/spark/fabric/FabricServerConfigProvider.java
@@ -0,0 +1,57 @@
+/*
+ * This file is part of spark.
+ *
+ * Copyright (c) lucko (Luck) <luck@lucko.me>
+ * Copyright (c) contributors
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+package me.lucko.spark.fabric;
+
+import com.google.common.collect.ImmutableMap;
+import com.google.common.collect.ImmutableSet;
+
+import me.lucko.spark.common.platform.serverconfig.ConfigParser;
+import me.lucko.spark.common.platform.serverconfig.PropertiesConfigParser;
+import me.lucko.spark.common.platform.serverconfig.ServerConfigProvider;
+
+import java.util.Collection;
+import java.util.Map;
+
+public class FabricServerConfigProvider extends ServerConfigProvider {
+
+ /** A map of provided files and their type */
+ private static final Map<String, ConfigParser> FILES;
+ /** A collection of paths to be excluded from the files */
+ private static final Collection<String> HIDDEN_PATHS;
+
+ public FabricServerConfigProvider() {
+ super(FILES, HIDDEN_PATHS);
+ }
+
+ static {
+ ImmutableSet.Builder<String> hiddenPaths = ImmutableSet.<String>builder()
+ .add("server-ip")
+ .add("motd")
+ .add("resource-pack")
+ .add("rcon<dot>password")
+ .add("level-seed")
+ .addAll(getSystemPropertyList("spark.serverconfigs.hiddenpaths"));
+
+ FILES = ImmutableMap.of("server.properties", PropertiesConfigParser.INSTANCE);
+ HIDDEN_PATHS = hiddenPaths.build();
+ }
+
+}
diff --git a/spark-fabric/src/main/java/me/lucko/spark/fabric/FabricWorldInfoProvider.java b/spark-fabric/src/main/java/me/lucko/spark/fabric/FabricWorldInfoProvider.java
new file mode 100644
index 0000000..156db89
--- /dev/null
+++ b/spark-fabric/src/main/java/me/lucko/spark/fabric/FabricWorldInfoProvider.java
@@ -0,0 +1,178 @@
+/*
+ * This file is part of spark.
+ *
+ * Copyright (c) lucko (Luck) <luck@lucko.me>
+ * Copyright (c) contributors
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+package me.lucko.spark.fabric;
+
+import it.unimi.dsi.fastutil.longs.LongIterator;
+import it.unimi.dsi.fastutil.longs.LongSet;
+
+import me.lucko.spark.common.platform.world.AbstractChunkInfo;
+import me.lucko.spark.common.platform.world.CountMap;
+import me.lucko.spark.common.platform.world.WorldInfoProvider;
+import me.lucko.spark.fabric.mixin.ClientEntityManagerAccessor;
+import me.lucko.spark.fabric.mixin.ClientWorldAccessor;
+import me.lucko.spark.fabric.mixin.ServerEntityManagerAccessor;
+import me.lucko.spark.fabric.mixin.ServerWorldAccessor;
+
+import net.minecraft.client.MinecraftClient;
+import net.minecraft.client.world.ClientEntityManager;
+import net.minecraft.client.world.ClientWorld;
+import net.minecraft.entity.Entity;
+import net.minecraft.entity.EntityType;
+import net.minecraft.server.MinecraftServer;
+import net.minecraft.server.world.ServerEntityManager;
+import net.minecraft.server.world.ServerWorld;
+import net.minecraft.util.math.ChunkPos;
+import net.minecraft.world.entity.EntityIndex;
+import net.minecraft.world.entity.EntityTrackingSection;
+import net.minecraft.world.entity.SectionedEntityCache;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.stream.Stream;
+
+public abstract class FabricWorldInfoProvider implements WorldInfoProvider {
+
+ protected List<FabricChunkInfo> getChunksFromCache(SectionedEntityCache<Entity> cache) {
+ LongSet loadedChunks = cache.getChunkPositions();
+ List<FabricChunkInfo> list = new ArrayList<>(loadedChunks.size());
+
+ for (LongIterator iterator = loadedChunks.iterator(); iterator.hasNext(); ) {
+ long chunkPos = iterator.nextLong();
+ Stream<EntityTrackingSection<Entity>> sections = cache.getTrackingSections(chunkPos);
+
+ list.add(new FabricChunkInfo(chunkPos, sections));
+ }
+
+ return list;
+ }
+
+ public static final class Server extends FabricWorldInfoProvider {
+ private final MinecraftServer server;
+
+ public Server(MinecraftServer server) {
+ this.server = server;
+ }
+
+ @Override
+ public CountsResult pollCounts() {
+ int players = this.server.getCurrentPlayerCount();
+ int entities = 0;
+ int chunks = 0;
+
+ for (ServerWorld world : this.server.getWorlds()) {
+ ServerEntityManager<Entity> entityManager = ((ServerWorldAccessor) world).getEntityManager();
+ EntityIndex<?> entityIndex = ((ServerEntityManagerAccessor) entityManager).getIndex();
+
+ entities += entityIndex.size();
+ chunks += world.getChunkManager().getLoadedChunkCount();
+ }
+
+ return new CountsResult(players, entities, -1, chunks);
+ }
+
+ @Override
+ public ChunksResult<FabricChunkInfo> pollChunks() {
+ ChunksResult<FabricChunkInfo> data = new ChunksResult<>();
+
+ for (ServerWorld world : this.server.getWorlds()) {
+ ServerEntityManager<Entity> entityManager = ((ServerWorldAccessor) world).getEntityManager();
+ SectionedEntityCache<Entity> cache = ((ServerEntityManagerAccessor) entityManager).getCache();
+
+ List<FabricChunkInfo> list = getChunksFromCache(cache);
+ data.put(world.getRegistryKey().getValue().getPath(), list);
+ }
+
+ return data;
+ }
+ }
+
+ public static final class Client extends FabricWorldInfoProvider {
+ private final MinecraftClient client;
+
+ public Client(MinecraftClient client) {
+ this.client = client;
+ }
+
+ @Override
+ public CountsResult pollCounts() {
+ ClientWorld world = this.client.world;
+ if (world == null) {
+ return null;
+ }
+
+ ClientEntityManager<Entity> entityManager = ((ClientWorldAccessor) world).getEntityManager();
+ EntityIndex<?> entityIndex = ((ClientEntityManagerAccessor) entityManager).getIndex();
+
+ int entities = entityIndex.size();
+ int chunks = world.getChunkManager().getLoadedChunkCount();
+
+ return new CountsResult(-1, entities, -1, chunks);
+ }
+
+ @Override
+ public ChunksResult<FabricChunkInfo> pollChunks() {
+ ChunksResult<FabricChunkInfo> data = new ChunksResult<>();
+
+ ClientWorld world = this.client.world;
+ if (world == null) {
+ return null;
+ }
+
+ ClientEntityManager<Entity> entityManager = ((ClientWorldAccessor) world).getEntityManager();
+ SectionedEntityCache<Entity> cache = ((ClientEntityManagerAccessor) entityManager).getCache();
+
+ List<FabricChunkInfo> list = getChunksFromCache(cache);
+ data.put(world.getRegistryKey().getValue().getPath(), list);
+
+ return data;
+ }
+ }
+
+ static final class FabricChunkInfo extends AbstractChunkInfo<EntityType<?>> {
+ private final CountMap<EntityType<?>> entityCounts;
+
+ FabricChunkInfo(long chunkPos, Stream<EntityTrackingSection<Entity>> entities) {
+ super(ChunkPos.getPackedX(chunkPos), ChunkPos.getPackedZ(chunkPos));
+
+ this.entityCounts = new CountMap.Simple<>(new HashMap<>());
+ entities.forEach(section -> {
+ if (section.getStatus().shouldTrack()) {
+ section.stream().forEach(entity ->
+ this.entityCounts.increment(entity.getType())
+ );
+ }
+ });
+ }
+
+ @Override
+ public CountMap<EntityType<?>> getEntityCounts() {
+ return this.entityCounts;
+ }
+
+ @Override
+ public String entityTypeName(EntityType<?> type) {
+ return EntityType.getId(type).toString();
+ }
+ }
+
+}
+
diff --git a/spark-fabric/src/main/java/me/lucko/spark/fabric/mixin/ClientEntityManagerAccessor.java b/spark-fabric/src/main/java/me/lucko/spark/fabric/mixin/ClientEntityManagerAccessor.java
new file mode 100644
index 0000000..994c9a3
--- /dev/null
+++ b/spark-fabric/src/main/java/me/lucko/spark/fabric/mixin/ClientEntityManagerAccessor.java
@@ -0,0 +1,40 @@
+/*
+ * This file is part of spark.
+ *
+ * Copyright (c) lucko (Luck) <luck@lucko.me>
+ * Copyright (c) contributors
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+package me.lucko.spark.fabric.mixin;
+
+import net.minecraft.client.world.ClientEntityManager;
+import net.minecraft.entity.Entity;
+import net.minecraft.world.entity.EntityIndex;
+import net.minecraft.world.entity.SectionedEntityCache;
+
+import org.spongepowered.asm.mixin.Mixin;
+import org.spongepowered.asm.mixin.gen.Accessor;
+
+@Mixin(ClientEntityManager.class)
+public interface ClientEntityManagerAccessor {
+
+ @Accessor
+ SectionedEntityCache<Entity> getCache();
+
+ @Accessor
+ EntityIndex<?> getIndex();
+
+}
diff --git a/spark-fabric/src/main/java/me/lucko/spark/fabric/mixin/ClientWorldAccessor.java b/spark-fabric/src/main/java/me/lucko/spark/fabric/mixin/ClientWorldAccessor.java
new file mode 100644
index 0000000..01562ef
--- /dev/null
+++ b/spark-fabric/src/main/java/me/lucko/spark/fabric/mixin/ClientWorldAccessor.java
@@ -0,0 +1,36 @@
+/*
+ * This file is part of spark.
+ *
+ * Copyright (c) lucko (Luck) <luck@lucko.me>
+ * Copyright (c) contributors
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+package me.lucko.spark.fabric.mixin;
+
+import net.minecraft.client.world.ClientEntityManager;
+import net.minecraft.client.world.ClientWorld;
+import net.minecraft.entity.Entity;
+
+import org.spongepowered.asm.mixin.Mixin;
+import org.spongepowered.asm.mixin.gen.Accessor;
+
+@Mixin(ClientWorld.class)
+public interface ClientWorldAccessor {
+
+ @Accessor
+ ClientEntityManager<Entity> getEntityManager();
+
+}
diff --git a/spark-fabric/src/main/java/me/lucko/spark/fabric/mixin/MinecraftClientAccessor.java b/spark-fabric/src/main/java/me/lucko/spark/fabric/mixin/MinecraftClientAccessor.java
new file mode 100644
index 0000000..7a4fb78
--- /dev/null
+++ b/spark-fabric/src/main/java/me/lucko/spark/fabric/mixin/MinecraftClientAccessor.java
@@ -0,0 +1,34 @@
+/*
+ * This file is part of spark.
+ *
+ * Copyright (c) lucko (Luck) <luck@lucko.me>
+ * Copyright (c) contributors
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+package me.lucko.spark.fabric.mixin;
+
+import net.minecraft.client.MinecraftClient;
+
+import org.spongepowered.asm.mixin.Mixin;
+import org.spongepowered.asm.mixin.gen.Accessor;
+
+@Mixin(MinecraftClient.class)
+public interface MinecraftClientAccessor {
+
+ @Accessor
+ Thread getThread();
+
+}
diff --git a/spark-fabric/src/main/java/me/lucko/spark/fabric/mixin/ServerEntityManagerAccessor.java b/spark-fabric/src/main/java/me/lucko/spark/fabric/mixin/ServerEntityManagerAccessor.java
new file mode 100644
index 0000000..2c67502
--- /dev/null
+++ b/spark-fabric/src/main/java/me/lucko/spark/fabric/mixin/ServerEntityManagerAccessor.java
@@ -0,0 +1,40 @@
+/*
+ * This file is part of spark.
+ *
+ * Copyright (c) lucko (Luck) <luck@lucko.me>
+ * Copyright (c) contributors
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+package me.lucko.spark.fabric.mixin;
+
+import net.minecraft.entity.Entity;
+import net.minecraft.server.world.ServerEntityManager;
+import net.minecraft.world.entity.EntityIndex;
+import net.minecraft.world.entity.SectionedEntityCache;
+
+import org.spongepowered.asm.mixin.Mixin;
+import org.spongepowered.asm.mixin.gen.Accessor;
+
+@Mixin(ServerEntityManager.class)
+public interface ServerEntityManagerAccessor {
+
+ @Accessor
+ SectionedEntityCache<Entity> getCache();
+
+ @Accessor
+ EntityIndex<?> getIndex();
+
+}
diff --git a/spark-fabric/src/main/java/me/lucko/spark/fabric/mixin/ServerWorldAccessor.java b/spark-fabric/src/main/java/me/lucko/spark/fabric/mixin/ServerWorldAccessor.java
new file mode 100644
index 0000000..cf2e7e8
--- /dev/null
+++ b/spark-fabric/src/main/java/me/lucko/spark/fabric/mixin/ServerWorldAccessor.java
@@ -0,0 +1,36 @@
+/*
+ * This file is part of spark.
+ *
+ * Copyright (c) lucko (Luck) <luck@lucko.me>
+ * Copyright (c) contributors
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+package me.lucko.spark.fabric.mixin;
+
+import net.minecraft.entity.Entity;
+import net.minecraft.server.world.ServerEntityManager;
+import net.minecraft.server.world.ServerWorld;
+
+import org.spongepowered.asm.mixin.Mixin;
+import org.spongepowered.asm.mixin.gen.Accessor;
+
+@Mixin(ServerWorld.class)
+public interface ServerWorldAccessor {
+
+ @Accessor
+ ServerEntityManager<Entity> getEntityManager();
+
+}
diff --git a/spark-fabric/src/main/java/me/lucko/spark/fabric/placeholder/SparkFabricPlaceholderApi.java b/spark-fabric/src/main/java/me/lucko/spark/fabric/placeholder/SparkFabricPlaceholderApi.java
index dc2e7d9..69303e3 100644
--- a/spark-fabric/src/main/java/me/lucko/spark/fabric/placeholder/SparkFabricPlaceholderApi.java
+++ b/spark-fabric/src/main/java/me/lucko/spark/fabric/placeholder/SparkFabricPlaceholderApi.java
@@ -20,169 +20,48 @@
package me.lucko.spark.fabric.placeholder;
-import eu.pb4.placeholders.PlaceholderAPI;
-import eu.pb4.placeholders.PlaceholderResult;
+import eu.pb4.placeholders.api.PlaceholderContext;
+import eu.pb4.placeholders.api.PlaceholderHandler;
+import eu.pb4.placeholders.api.PlaceholderResult;
+import eu.pb4.placeholders.api.Placeholders;
import me.lucko.spark.common.SparkPlatform;
-import me.lucko.spark.common.monitor.cpu.CpuMonitor;
-import me.lucko.spark.common.monitor.tick.TickStatistics;
-import me.lucko.spark.common.util.RollingAverage;
-import me.lucko.spark.common.util.StatisticFormatter;
+import me.lucko.spark.common.util.SparkPlaceholder;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer;
import net.minecraft.text.Text;
import net.minecraft.util.Identifier;
-public class SparkFabricPlaceholderApi {
- private final SparkPlatform platform;
+import org.jetbrains.annotations.Nullable;