diff options
| author | u9g <43508353+u9g@users.noreply.github.com> | 2022-10-02 14:48:39 -0400 |
|---|---|---|
| committer | nea <nea@nea.moe> | 2023-07-24 20:18:48 +0200 |
| commit | c61ed93aa03504dcf23eab3228191be93d331afd (patch) | |
| tree | ddca24ab28041d9a9280172db25326858dd7bac9 /spark-forge189 | |
| parent | 7e1fe4231d3b098f08ee9ebb68a551016e345a73 (diff) | |
| download | spark-c61ed93aa03504dcf23eab3228191be93d331afd.tar.gz spark-c61ed93aa03504dcf23eab3228191be93d331afd.tar.bz2 spark-c61ed93aa03504dcf23eab3228191be93d331afd.zip | |
1.8.9 support
Diffstat (limited to 'spark-forge189')
22 files changed, 1059 insertions, 0 deletions
diff --git a/spark-forge189/bin/main/mcmod.info b/spark-forge189/bin/main/mcmod.info new file mode 100644 index 0000000..50e5509 --- /dev/null +++ b/spark-forge189/bin/main/mcmod.info @@ -0,0 +1,8 @@ +[{ + "modid": "spark", + "name": "spark", + "description": "${pluginDescription}", + "version": "${pluginVersion}", + "authors": ["Luck"], + "mcversion": "1.8.9" +}] diff --git a/spark-forge189/bin/main/me/lucko/spark/forge/Forge189CommandSender.class b/spark-forge189/bin/main/me/lucko/spark/forge/Forge189CommandSender.class Binary files differnew file mode 100644 index 0000000..7d43775 --- /dev/null +++ b/spark-forge189/bin/main/me/lucko/spark/forge/Forge189CommandSender.class diff --git a/spark-forge189/bin/main/me/lucko/spark/forge/Forge189PlatformInfo.class b/spark-forge189/bin/main/me/lucko/spark/forge/Forge189PlatformInfo.class Binary files differnew file mode 100644 index 0000000..123c3cb --- /dev/null +++ b/spark-forge189/bin/main/me/lucko/spark/forge/Forge189PlatformInfo.class diff --git a/spark-forge189/bin/main/me/lucko/spark/forge/Forge189SparkMod.class b/spark-forge189/bin/main/me/lucko/spark/forge/Forge189SparkMod.class Binary files differnew file mode 100644 index 0000000..45bbd69 --- /dev/null +++ b/spark-forge189/bin/main/me/lucko/spark/forge/Forge189SparkMod.class diff --git a/spark-forge189/bin/main/me/lucko/spark/forge/Forge189TickHook.class b/spark-forge189/bin/main/me/lucko/spark/forge/Forge189TickHook.class Binary files differnew file mode 100644 index 0000000..60f9e75 --- /dev/null +++ b/spark-forge189/bin/main/me/lucko/spark/forge/Forge189TickHook.class diff --git a/spark-forge189/bin/main/me/lucko/spark/forge/Forge189TickReporter.class b/spark-forge189/bin/main/me/lucko/spark/forge/Forge189TickReporter.class Binary files differnew file mode 100644 index 0000000..73e467d --- /dev/null +++ b/spark-forge189/bin/main/me/lucko/spark/forge/Forge189TickReporter.class diff --git a/spark-forge189/bin/main/me/lucko/spark/forge/plugin/Forge189ClientSparkPlugin.class b/spark-forge189/bin/main/me/lucko/spark/forge/plugin/Forge189ClientSparkPlugin.class Binary files differnew file mode 100644 index 0000000..16965e1 --- /dev/null +++ b/spark-forge189/bin/main/me/lucko/spark/forge/plugin/Forge189ClientSparkPlugin.class diff --git a/spark-forge189/bin/main/me/lucko/spark/forge/plugin/Forge189ServerSparkPlugin.class b/spark-forge189/bin/main/me/lucko/spark/forge/plugin/Forge189ServerSparkPlugin.class Binary files differnew file mode 100644 index 0000000..03d22ed --- /dev/null +++ b/spark-forge189/bin/main/me/lucko/spark/forge/plugin/Forge189ServerSparkPlugin.class diff --git a/spark-forge189/bin/main/me/lucko/spark/forge/plugin/Forge189SparkPlugin.class b/spark-forge189/bin/main/me/lucko/spark/forge/plugin/Forge189SparkPlugin.class Binary files differnew file mode 100644 index 0000000..450a3fd --- /dev/null +++ b/spark-forge189/bin/main/me/lucko/spark/forge/plugin/Forge189SparkPlugin.class diff --git a/spark-forge189/build.gradle b/spark-forge189/build.gradle new file mode 100644 index 0000000..f3cb184 --- /dev/null +++ b/spark-forge189/build.gradle @@ -0,0 +1,91 @@ +import dev.architectury.pack200.java.Pack200Adapter + +plugins { + id 'idea' + id 'java' + id 'gg.essential.loom' version '0.10.0.+' + id 'dev.architectury.architectury-pack200' version '0.1.3' + id 'com.github.johnrengelman.shadow' version '7.1.2' +} + +sourceCompatibility = JavaVersion.VERSION_1_8 +targetCompatibility = JavaVersion.VERSION_1_8 +compileJava.options.encoding = 'UTF-8' + +sourceSets { + main { + output.resourcesDir = java.classesDirectory + } +} + +loom { + + forge { + pack200Provider = new Pack200Adapter() + } +} + +configurations { + embed + implementation.extendsFrom(embed) +} + +repositories { + mavenCentral() + maven { url = "https://repo.sk1er.club/repository/maven-public/" } + maven { url = "https://jitpack.io/" } + maven { url = "https://repo.spongepowered.org/repository/maven-public/" } +} + +dependencies { + minecraft 'com.mojang:minecraft:1.8.9' + mappings 'de.oceanlabs.mcp:mcp_stable:22-1.8.9' + forge 'net.minecraftforge:forge:1.8.9-11.15.1.2318-1.8.9' + + embed project(':spark-common') +} + +jar { + archiveClassifier.set("deobf") +} + +shadowJar { + archiveFileName.set("spark-forge189.jar") + configurations = [project.configurations.embed] + + duplicatesStrategy = DuplicatesStrategy.EXCLUDE +} + +remapJar { + archiveClassifier.set("USETHISONE") + from shadowJar + input.set(shadowJar.archiveFile) +} + +artifacts { + archives shadowJar + shadow shadowJar +} + +build.dependsOn(shadowJar) + +processResources { + duplicatesStrategy = DuplicatesStrategy.EXCLUDE + // this will ensure that this task is redone when the versions change. + inputs.property "version", project.version + + // replace stuff in mcmod.info, nothing else + from(sourceSets.main.resources.srcDirs) { + include 'mcmod.info' + + // replace version and mcversion + expand 'version': project.version + } + + // copy everything else, thats not the mcmod.info + from(sourceSets.main.resources.srcDirs) { + exclude 'mcmod.info' + } + + from(file("LICENSE")) +}
\ No newline at end of file diff --git a/spark-forge189/gradle.properties b/spark-forge189/gradle.properties new file mode 100644 index 0000000..38d70d1 --- /dev/null +++ b/spark-forge189/gradle.properties @@ -0,0 +1,2 @@ +loom.platform=forge
+org.gradle.jvmargs=-Xmx2g
\ No newline at end of file diff --git a/spark-forge189/src/main/java/me/lucko/spark/forge/Forge189CommandSender.java b/spark-forge189/src/main/java/me/lucko/spark/forge/Forge189CommandSender.java new file mode 100644 index 0000000..6c8bd5a --- /dev/null +++ b/spark-forge189/src/main/java/me/lucko/spark/forge/Forge189CommandSender.java @@ -0,0 +1,92 @@ +/* + * 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.forge; + +import me.lucko.spark.common.command.sender.AbstractCommandSender; +import me.lucko.spark.forge.plugin.Forge189SparkPlugin; +import net.kyori.adventure.text.Component; +import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer; +import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer; +import net.minecraft.command.ICommandSender; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.network.rcon.RConConsoleSource; +import net.minecraft.server.MinecraftServer; +import net.minecraft.util.ChatComponentText; +import net.minecraft.util.IChatComponent; +import net.minecraftforge.common.ForgeHooks; + +import java.util.UUID; + +public class Forge189CommandSender extends AbstractCommandSender<ICommandSender> { + private final Forge189SparkPlugin plugin; + + public Forge189CommandSender(ICommandSender source, Forge189SparkPlugin plugin) { + super(source); + this.plugin = plugin; + } + + @Override + public String getName() { + if (super.delegate instanceof EntityPlayer) { + return ((EntityPlayer) super.delegate).getGameProfile().getName(); + } else if (super.delegate instanceof MinecraftServer) { + return "Console"; + } else if (super.delegate instanceof RConConsoleSource) { + return "RCON Console"; + } else { + return "unknown:" + super.delegate.getClass().getSimpleName(); + } + } + + @Override + public UUID getUniqueId() { + if (super.delegate instanceof EntityPlayer) { + return ((EntityPlayer) super.delegate).getUniqueID(); + } + return null; + } + + @Override + public void sendMessage(Component message) { + /* + * Due to limitations in 1.7.10, messages with \n render incorrectly on the client. + * To work around this, we convert the message to a string first, split it by newline, + * and send each line individually. + * + * This adds a performance penalty, but avoids any weirdness with this old client. + */ + LegacyComponentSerializer serializer = LegacyComponentSerializer.builder() + .character(LegacyComponentSerializer.SECTION_CHAR) + .extractUrls() + .build(); + String output = serializer.serialize(message); + for(String line : output.split("\n")) { + Component deserialized = serializer.deserialize(line); + IChatComponent mcComponent = IChatComponent.Serializer.jsonToComponent(GsonComponentSerializer.gson().serialize(deserialized)); + super.delegate.addChatMessage(mcComponent); + } + } + + @Override + public boolean hasPermission(String permission) { + return this.plugin.hasPermission(super.delegate, permission); + } +} diff --git a/spark-forge189/src/main/java/me/lucko/spark/forge/Forge189PlatformInfo.java b/spark-forge189/src/main/java/me/lucko/spark/forge/Forge189PlatformInfo.java new file mode 100644 index 0000000..6058f51 --- /dev/null +++ b/spark-forge189/src/main/java/me/lucko/spark/forge/Forge189PlatformInfo.java @@ -0,0 +1,52 @@ +/* + * 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.forge; + +import me.lucko.spark.common.platform.PlatformInfo; +import net.minecraftforge.common.ForgeVersion; + +public class Forge189PlatformInfo implements PlatformInfo { + private final Type type; + + public Forge189PlatformInfo(Type type) { + this.type = type; + } + + @Override + public Type getType() { + return this.type; + } + + @Override + public String getName() { + return "Forge"; + } + + @Override + public String getVersion() { + return ForgeVersion.getVersion(); + } + + @Override + public String getMinecraftVersion() { + return "1.8.9"; + } +} diff --git a/spark-forge189/src/main/java/me/lucko/spark/forge/Forge189PlayerPingProvider.java b/spark-forge189/src/main/java/me/lucko/spark/forge/Forge189PlayerPingProvider.java new file mode 100644 index 0000000..149ca1a --- /dev/null +++ b/spark-forge189/src/main/java/me/lucko/spark/forge/Forge189PlayerPingProvider.java @@ -0,0 +1,48 @@ +/* + * 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.forge; + +import com.google.common.collect.ImmutableMap; + +import me.lucko.spark.common.monitor.ping.PlayerPingProvider; + +import net.minecraft.entity.player.EntityPlayerMP; +import net.minecraft.server.MinecraftServer; + +import java.util.List; +import java.util.Map; + +public class Forge189PlayerPingProvider implements PlayerPingProvider { + private final MinecraftServer server; + + public Forge189PlayerPingProvider(MinecraftServer server) { + this.server = server; + } + + @Override + public Map<String, Integer> poll() { + ImmutableMap.Builder<String, Integer> builder = ImmutableMap.builder(); + for (EntityPlayerMP player : (List<EntityPlayerMP>)this.server.getConfigurationManager().playerEntityList) { + builder.put(player.getGameProfile().getName(), player.ping); + } + return builder.build(); + } +} diff --git a/spark-forge189/src/main/java/me/lucko/spark/forge/Forge189SparkMod.java b/spark-forge189/src/main/java/me/lucko/spark/forge/Forge189SparkMod.java new file mode 100644 index 0000000..5fce36a --- /dev/null +++ b/spark-forge189/src/main/java/me/lucko/spark/forge/Forge189SparkMod.java @@ -0,0 +1,81 @@ +/* + * 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.forge; + +import me.lucko.spark.forge.plugin.Forge189ClientSparkPlugin; +import me.lucko.spark.forge.plugin.Forge189ServerSparkPlugin; +import net.minecraftforge.fml.common.FMLCommonHandler; +import net.minecraftforge.fml.common.Mod; +import net.minecraftforge.fml.common.event.FMLInitializationEvent; +import net.minecraftforge.fml.common.event.FMLPreInitializationEvent; +import net.minecraftforge.fml.common.event.FMLServerStartingEvent; +import net.minecraftforge.fml.common.event.FMLServerStoppingEvent; +import net.minecraftforge.fml.relauncher.Side; + +import java.nio.file.Path; + +@Mod( + modid = "spark", + name = "spark", + version = "@version@", + acceptableRemoteVersions = "*" +) +public class Forge189SparkMod { + + private Path configDirectory; + private Forge189ServerSparkPlugin activeServerPlugin; + + public String getVersion() { + return Forge189SparkMod.class.getAnnotation(Mod.class).version(); + } + + @Mod.EventHandler + public void preInit(FMLPreInitializationEvent e) { + this.configDirectory = e.getModConfigurationDirectory().toPath(); + } + + @Mod.EventHandler + public void clientInit(FMLInitializationEvent e) { + if (FMLCommonHandler.instance().getSide() == Side.CLIENT) { + Forge189ClientSparkPlugin.register(this); + } + } + + @Mod.EventHandler + public void serverInit(FMLServerStartingEvent e) { + this.activeServerPlugin = Forge189ServerSparkPlugin.register(this, e); + } + + @Mod.EventHandler + public void serverStop(FMLServerStoppingEvent e) { + if (this.activeServerPlugin != null) { + this.activeServerPlugin.disable(); + this.activeServerPlugin = null; + } + } + + public Path getConfigDirectory() { + if (this.configDirectory == null) { + throw new IllegalStateException("Config directory not set"); + } + return this.configDirectory; + } +} diff --git a/spark-forge189/src/main/java/me/lucko/spark/forge/Forge189TickHook.java b/spark-forge189/src/main/java/me/lucko/spark/forge/Forge189TickHook.java new file mode 100644 index 0000000..f375d56 --- /dev/null +++ b/spark-forge189/src/main/java/me/lucko/spark/forge/Forge189TickHook.java @@ -0,0 +1,59 @@ +/* + * 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.forge; + +import me.lucko.spark.common.tick.AbstractTickHook; +import me.lucko.spark.common.tick.TickHook; +import net.minecraftforge.fml.common.FMLCommonHandler; +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; +import net.minecraftforge.fml.common.gameevent.TickEvent; + +public class Forge189TickHook extends AbstractTickHook implements TickHook { + private final TickEvent.Type type; + + public Forge189TickHook(TickEvent.Type type) { + this.type = type; + } + + @SubscribeEvent + public void onTick(TickEvent e) { + if (e.phase != TickEvent.Phase.START) { + return; + } + + if (e.type != this.type) { + return; + } + + onTick(); + } + + @Override + public void start() { + FMLCommonHandler.instance().bus().register(this); + } + + @Override + public void close() { + FMLCommonHandler.instance().bus().unregister(this); + } + +} diff --git a/spark-forge189/src/main/java/me/lucko/spark/forge/Forge189TickReporter.java b/spark-forge189/src/main/java/me/lucko/spark/forge/Forge189TickReporter.java new file mode 100644 index 0000000..b489e8b --- /dev/null +++ b/spark-forge189/src/main/java/me/lucko/spark/forge/Forge189TickReporter.java @@ -0,0 +1,65 @@ +/* + * 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.forge; + +import me.lucko.spark.common.tick.SimpleTickReporter; +import me.lucko.spark.common.tick.TickReporter; +import net.minecraftforge.fml.common.FMLCommonHandler; +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; +import net.minecraftforge.fml.common.gameevent.TickEvent; + +public class Forge189TickReporter extends SimpleTickReporter implements TickReporter { + private final TickEvent.Type type; + + public Forge189TickReporter(TickEvent.Type type) { + this.type = type; + } + + @SubscribeEvent + public void onTick(TickEvent e) { + if (e.type != this.type) { + return; + } + + switch (e.phase) { + case START: + onStart(); + break; + case END: + onEnd(); + break; + default: + throw new AssertionError(e.phase); + } + } + + @Override + public void start() { + FMLCommonHandler.instance().bus().register(this); + } + + @Override + public void close() { + FMLCommonHandler.instance().bus().unregister(this); + super.close(); + } + +} diff --git a/spark-forge189/src/main/java/me/lucko/spark/forge/Forge189WorldInfoProvider.java b/spark-forge189/src/main/java/me/lucko/spark/forge/Forge189WorldInfoProvider.java new file mode 100644 index 0000000..d98fe41 --- /dev/null +++ b/spark-forge189/src/main/java/me/lucko/spark/forge/Forge189WorldInfoProvider.java @@ -0,0 +1,151 @@ +/* + * 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.forge; + +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 net.minecraft.client.Minecraft; +import net.minecraft.client.multiplayer.ChunkProviderClient; +import net.minecraft.client.multiplayer.WorldClient; +import net.minecraft.entity.Entity; +import net.minecraft.entity.EntityList; +import net.minecraft.server.MinecraftServer; +import net.minecraft.util.ClassInheritanceMultiMap; +import net.minecraft.world.WorldServer; +import net.minecraft.world.chunk.Chunk; +import net.minecraft.world.chunk.IChunkProvider; +import net.minecraftforge.fml.relauncher.ReflectionHelper; +import net.minecraftforge.fml.relauncher.Side; +import net.minecraftforge.fml.relauncher.SideOnly; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; + +public abstract class Forge189WorldInfoProvider implements WorldInfoProvider { + public static final class Server extends Forge189WorldInfoProvider { + private final MinecraftServer server; + + public Server(MinecraftServer server) { + this.server = server; + } + + @Override + public ChunksResult<ForgeChunkInfo> pollChunks() { + ChunksResult<ForgeChunkInfo> data = new ChunksResult<>(); + + for (WorldServer level : this.server.worldServers) { + ArrayList<ForgeChunkInfo> list = new ArrayList<>(); + for(Chunk chunk : (List<Chunk>)level.theChunkProviderServer.loadedChunks) { + list.add(new ForgeChunkInfo(chunk)); + } + data.put(level.provider.getDimensionName(), list); + } + + return data; + } + + @Override + public CountsResult pollCounts() { + int players = this.server.getCurrentPlayerCount(); + int entities = 0; + int chunks = 0; + + for (WorldServer level : this.server.worldServers) { + entities += level.loadedEntityList.size(); + chunks += level.getChunkProvider().getLoadedChunkCount(); + } + + return new CountsResult(players, entities, -1, chunks); + } + } + + @SideOnly(Side.CLIENT) + public static final class Client extends Forge189WorldInfoProvider { + private final Minecraft client; + + public Client(Minecraft client) { + this.client = client; + } + + @Override + public ChunksResult<ForgeChunkInfo> pollChunks() { + ChunksResult<ForgeChunkInfo> data = new ChunksResult<>(); + + WorldClient level = this.client.theWorld; + if (level == null) { + return null; + } + + ArrayList<ForgeChunkInfo> list = new ArrayList<>(); + IChunkProvider provider = level.getChunkProvider(); + if(provider instanceof ChunkProviderClient) { + List<Chunk> chunks = ReflectionHelper.getPrivateValue(ChunkProviderClient.class, (ChunkProviderClient)provider, "chunkListing", "field_73237_c"); + for(Chunk chunk : chunks) { + list.add(new ForgeChunkInfo(chunk)); + } + } + + data.put(level.provider.getDimensionName(), list); + + return data; + } + + @Override + public CountsResult pollCounts() { + WorldClient level = this.client.theWorld; + if (level == null) { + return null; + } + + return new CountsResult(-1, level.loadedEntityList.size(), -1, level.getChunkProvider().getLoadedChunkCount()); + } + } + + static final class ForgeChunkInfo extends AbstractChunkInfo<Class<? extends Entity>> { + private final CountMap<Class<? extends Entity>> entityCounts; + + ForgeChunkInfo(Chunk chunk) { + super(chunk.xPosition, chunk.zPosition); + + this.entityCounts = new CountMap.Simple<>(new HashMap<>()); + for(ClassInheritanceMultiMap<Entity> entityList : chunk.getEntityLists()) { + entityList.forEach(entity -> { + this.entityCounts.increment(entity.getClass()); + }); + } + } + + @Override + public CountMap<Class<? extends Entity>> getEntityCounts() { + return this.entityCounts; + } + + @Override + public String entityTypeName(Class<? extends Entity> type) { + return (String)EntityList.classToStringMapping.get(type); + } + } + + +} diff --git a/spark-forge189/src/main/java/me/lucko/spark/forge/plugin/Forge189ClientSparkPlugin.java b/spark-forge189/src/main/java/me/lucko/spark/forge/plugin/Forge189ClientSparkPlugin.java new file mode 100644 index 0000000..b2cef1d --- /dev/null +++ b/spark-forge189/src/main/java/me/lucko/spark/forge/plugin/Forge189ClientSparkPlugin.java @@ -0,0 +1,105 @@ +/* + * 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.forge.plugin; + +import me.lucko.spark.common.platform.PlatformInfo; +import me.lucko.spark.common.platform.world.WorldInfoProvider; +import me.lucko.spark.common.sampler.ThreadDumper; +import me.lucko.spark.common.tick.TickHook; +import me.lucko.spark.common.tick.TickReporter; +import me.lucko.spark.forge.*; +import net.minecraft.client.Minecraft; +import net.minecraft.command.ICommandSender; +import net.minecraftforge.client.ClientCommandHandler; +import net.minecraftforge.common.MinecraftForge; +import net.minecraftforge.fml.common.gameevent.TickEvent; +import net.minecraftforge.fml.relauncher.ReflectionHelper; + +import java.util.stream.Stream; + +public class Forge189ClientSparkPlugin extends Forge189SparkPlugin { + + public static void register(Forge189SparkMod mod) { + Forge189ClientSparkPlugin plugin = new Forge189ClientSparkPlugin(mod, Minecraft.getMinecraft()); + plugin.enable(); + + // register listeners + MinecraftForge.EVENT_BUS.register(plugin); + + // register commands + ClientCommandHandler.instance.registerCommand(plugin); + } + + private final Minecraft minecraft; + private final ThreadDumper gameThreadDumper; + + public Forge189ClientSparkPlugin(Forge189SparkMod mod, Minecraft minecraft) { + super(mod); + this.minecraft = minecraft; + this.gameThreadDumper = new ThreadDumper.Specific((Thread) ReflectionHelper.getPrivateValue(Minecraft.class, minecraft, "mcThread", "field_152352_aC", "aO")); + } + + @Override + public ThreadDumper getDefaultThreadDumper() { + return this.gameThreadDumper; + } + + @Override + public boolean hasPermissio |
