Skip to content

Commit d0088e0

Browse files
committed
- 统一了线程数判断,防止线程亲和修改实际 CPU 数。
- 新增实体强制更新功能。 - 优化了 ItemStackCapInitializer 的性能。
1 parent 1ec5e47 commit d0088e0

32 files changed

+566
-109
lines changed

src/main/java/github/kasuminova/stellarcore/StellarCore.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import github.kasuminova.stellarcore.client.hitokoto.HitokotoAPI;
44
import github.kasuminova.stellarcore.common.CommonProxy;
5+
import github.kasuminova.stellarcore.common.command.CommandStellarCore;
56
import github.kasuminova.stellarcore.common.config.StellarCoreConfig;
67
import github.kasuminova.stellarcore.common.util.StellarLog;
78
import net.minecraftforge.fml.common.Mod;
@@ -73,4 +74,10 @@ public void postInit(FMLPostInitializationEvent event) {
7374
public void loadComplete(FMLLoadCompleteEvent event) {
7475
proxy.loadComplete();
7576
}
77+
78+
@Mod.EventHandler
79+
public void onServerStart(FMLServerStartingEvent event) {
80+
event.registerServerCommand(CommandStellarCore.INSTANCE);
81+
}
82+
7683
}

src/main/java/github/kasuminova/stellarcore/client/ClientProxy.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,11 @@
66
import github.kasuminova.stellarcore.client.pool.StellarUnpackedDataPool;
77
import github.kasuminova.stellarcore.client.util.TitleUtils;
88
import github.kasuminova.stellarcore.common.CommonProxy;
9+
import github.kasuminova.stellarcore.common.command.CommandStellarCoreClient;
910
import github.kasuminova.stellarcore.common.config.StellarCoreConfig;
1011
import github.kasuminova.stellarcore.common.mod.Mods;
1112
import github.kasuminova.stellarcore.common.util.StellarLog;
13+
import net.minecraftforge.client.ClientCommandHandler;
1214
import net.minecraftforge.common.MinecraftForge;
1315

1416
public class ClientProxy extends CommonProxy {
@@ -44,6 +46,8 @@ public void init() {
4446
public void postInit() {
4547
super.postInit();
4648

49+
ClientCommandHandler.instance.registerCommand(CommandStellarCoreClient.INSTANCE);
50+
4751
TitleUtils.setRandomTitle("*PostInit*");
4852
}
4953

src/main/java/github/kasuminova/stellarcore/client/model/ParallelModelLoaderAsyncBlackList.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
package github.kasuminova.stellarcore.client.model;
22

3-
import github.kasuminova.stellarcore.client.util.ClassBlackList;
3+
import github.kasuminova.stellarcore.client.util.ClassSet;
44
import github.kasuminova.stellarcore.common.config.StellarCoreConfig;
55

66
import java.util.Arrays;
77

8-
public class ParallelModelLoaderAsyncBlackList extends ClassBlackList {
8+
public class ParallelModelLoaderAsyncBlackList extends ClassSet {
99

1010
public static final ParallelModelLoaderAsyncBlackList INSTANCE = new ParallelModelLoaderAsyncBlackList();
1111

1212
public void reload() {
13-
blackList.clear();
13+
classSet.clear();
1414
Arrays.stream(StellarCoreConfig.PERFORMANCE.vanilla.parallelModelLoaderBlackList)
1515
.forEach(className -> findClass(className).ifPresent(this::add));
1616
}

src/main/java/github/kasuminova/stellarcore/client/util/ClassBlackList.java renamed to src/main/java/github/kasuminova/stellarcore/client/util/ClassSet.java

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,23 +5,22 @@
55
import java.util.Optional;
66
import java.util.Set;
77

8-
public abstract class ClassBlackList {
8+
public abstract class ClassSet {
99

10+
protected final Set<Class<?>> classSet = new ReferenceOpenHashSet<>();
1011

11-
protected final Set<Class<?>> blackList = new ReferenceOpenHashSet<>();
12-
13-
public ClassBlackList() {
12+
public ClassSet() {
1413
reload();
1514
}
1615

1716
public abstract void reload();
1817

1918
public void add(Class<?> clazz) {
20-
blackList.add(clazz);
19+
classSet.add(clazz);
2120
}
2221

23-
public boolean isInBlackList(Class<?> clazz) {
24-
return blackList.contains(clazz);
22+
public boolean isInSet(Class<?> clazz) {
23+
return !classSet.isEmpty() && classSet.contains(clazz);
2524
}
2625

2726
public static Optional<Class<?>> findClass(String name) {

src/main/java/github/kasuminova/stellarcore/common/CommonProxy.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
package github.kasuminova.stellarcore.common;
22

3+
import github.kasuminova.stellarcore.common.config.StellarCoreConfig;
4+
import github.kasuminova.stellarcore.common.entity.EntityForceUpdateManager;
5+
import github.kasuminova.stellarcore.common.itemstack.ItemStackCapInitializer;
36
import github.kasuminova.stellarcore.common.pool.ResourceLocationPool;
47
import github.kasuminova.stellarcore.common.bugfix.TileEntityContainerFixes;
58
import github.kasuminova.stellarcore.common.handler.StellarCoreTickHandler;
@@ -23,6 +26,7 @@ public void preInit() {
2326
}
2427
MinecraftForge.EVENT_BUS.register(TileEntityContainerFixes.INSTANCE);
2528
MinecraftForge.EVENT_BUS.register(StellarCoreTickHandler.class);
29+
MinecraftForge.EVENT_BUS.register(EntityForceUpdateManager.INSTANCE);
2630
}
2731

2832
public void init() {
@@ -35,6 +39,9 @@ public void postInit() {
3539

3640
public void loadComplete() {
3741
ResourceLocationPool.INSTANCE.clear();
42+
if (StellarCoreConfig.PERFORMANCE.vanilla.asyncItemStackCapabilityInit) {
43+
ItemStackCapInitializer.resetStatus();
44+
}
3845
}
3946

4047
}
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
package github.kasuminova.stellarcore.common.command;
2+
3+
import github.kasuminova.stellarcore.common.itemstack.ItemStackCapInitializer;
4+
import github.kasuminova.stellarcore.common.mod.Mods;
5+
import github.kasuminova.stellarcore.common.util.NumberUtils;
6+
import net.minecraft.command.CommandBase;
7+
import net.minecraft.command.ICommandSender;
8+
import net.minecraft.server.MinecraftServer;
9+
import net.minecraft.util.math.BlockPos;
10+
import net.minecraft.util.text.TextComponentString;
11+
import net.minecraft.util.text.TextFormatting;
12+
13+
import javax.annotation.Nonnull;
14+
import javax.annotation.Nullable;
15+
import java.util.List;
16+
import java.util.concurrent.TimeUnit;
17+
18+
public class CommandStellarCore extends CommandBase {
19+
20+
public static final CommandStellarCore INSTANCE = new CommandStellarCore();
21+
22+
private CommandStellarCore() {
23+
}
24+
25+
@Nonnull
26+
@Override
27+
public String getName() {
28+
return "stellarcore";
29+
}
30+
31+
@Nonnull
32+
@Override
33+
public List<String> getTabCompletions(@Nonnull final MinecraftServer server,
34+
@Nonnull final ICommandSender sender,
35+
@Nonnull final String[] args,
36+
@Nullable final BlockPos targetPos) {
37+
if (args.length == 1) {
38+
return getListOfStringsMatchingLastWord(args, "ItemStackCapInitStatus");
39+
}
40+
return super.getTabCompletions(server, sender, args, targetPos);
41+
}
42+
43+
@Nonnull
44+
@Override
45+
public String getUsage(@Nonnull final ICommandSender sender) {
46+
return "Usage: /stellarcore <ItemStackCapInitStatus>";
47+
}
48+
49+
@Override
50+
public int getRequiredPermissionLevel() {
51+
return 2;
52+
}
53+
54+
@Override
55+
public void execute(@Nonnull final MinecraftServer server, @Nonnull final ICommandSender sender, @Nonnull final String[] args) {
56+
if (args.length == 1 && args[0].equals("ItemStackCapInitStatus")) {
57+
printItemStackCapInitStatus(sender);
58+
}
59+
}
60+
61+
protected static void printItemStackCapInitStatus(final ICommandSender sender) {
62+
final long existedMillis = ItemStackCapInitializer.getExistedMillis();
63+
final long completedTasks = ItemStackCapInitializer.getCompletedTasks();
64+
final int queueSize = ItemStackCapInitializer.getQueueSize();
65+
final int maxQueueSize = ItemStackCapInitializer.getMaxQueueSize();
66+
67+
sender.sendMessage(new TextComponentString(String.format("%s<Stellar%sCore>%s - ItemStack Cap Initializer Status:",
68+
Mods.RGB_CHAT.loaded() ? "#66CCFF-FF99CC" : TextFormatting.AQUA,
69+
Mods.RGB_CHAT.loaded() ? "" : TextFormatting.LIGHT_PURPLE,
70+
TextFormatting.RESET
71+
)));
72+
sender.sendMessage(new TextComponentString(String.format("Existed Time: %s%ss",
73+
TextFormatting.GREEN,
74+
TimeUnit.MILLISECONDS.toSeconds(existedMillis)
75+
)));
76+
sender.sendMessage(new TextComponentString(String.format("Completed Tasks: %s%s", TextFormatting.GREEN,
77+
NumberUtils.formatDecimal(completedTasks)
78+
)));
79+
sender.sendMessage(new TextComponentString(String.format("Workers: %s%s%s / %s%s",
80+
TextFormatting.GREEN, ItemStackCapInitializer.getWorkers(), TextFormatting.RESET,
81+
TextFormatting.YELLOW, ItemStackCapInitializer.getMaxWorkers()
82+
)));
83+
sender.sendMessage(new TextComponentString(String.format("Queue Status: %s%s%s / %s%s%s (%s%s%s)",
84+
TextFormatting.YELLOW, NumberUtils.formatDecimal(queueSize), TextFormatting.RESET,
85+
TextFormatting.GOLD, NumberUtils.formatDecimal(maxQueueSize), TextFormatting.RESET,
86+
TextFormatting.YELLOW, NumberUtils.formatPercent(queueSize, maxQueueSize), TextFormatting.RESET
87+
)));
88+
sender.sendMessage(new TextComponentString(String.format("Task Execution Per Second: %s%s/s",
89+
TextFormatting.AQUA, NumberUtils.formatDecimal(completedTasks > 0 ? completedTasks / ((double) existedMillis / 1000) : completedTasks)
90+
)));
91+
}
92+
93+
}
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
package github.kasuminova.stellarcore.common.command;
2+
3+
import net.minecraft.command.CommandBase;
4+
import net.minecraft.command.ICommandSender;
5+
import net.minecraft.server.MinecraftServer;
6+
import net.minecraft.util.math.BlockPos;
7+
8+
import javax.annotation.Nonnull;
9+
import javax.annotation.Nullable;
10+
import java.util.List;
11+
12+
public class CommandStellarCoreClient extends CommandBase {
13+
14+
public static final CommandStellarCoreClient INSTANCE = new CommandStellarCoreClient();
15+
16+
private CommandStellarCoreClient() {
17+
}
18+
19+
@Nonnull
20+
@Override
21+
public String getName() {
22+
return "stellarcore_client";
23+
}
24+
25+
@Nonnull
26+
@Override
27+
public List<String> getTabCompletions(@Nonnull final MinecraftServer server,
28+
@Nonnull final ICommandSender sender,
29+
@Nonnull final String[] args,
30+
@Nullable final BlockPos targetPos) {
31+
if (args.length == 1) {
32+
return getListOfStringsMatchingLastWord(args, "ItemStackCapInitStatus");
33+
}
34+
return super.getTabCompletions(server, sender, args, targetPos);
35+
}
36+
37+
@Nonnull
38+
@Override
39+
public String getUsage(@Nonnull final ICommandSender sender) {
40+
return "Usage: /stellarcore_client <ItemStackCapInitStatus>";
41+
}
42+
43+
@Override
44+
public int getRequiredPermissionLevel() {
45+
return 2;
46+
}
47+
48+
@Override
49+
public void execute(@Nonnull final MinecraftServer server, @Nonnull final ICommandSender sender, @Nonnull final String[] args) {
50+
if (args.length == 1 && args[0].equals("ItemStackCapInitStatus")) {
51+
CommandStellarCore.printItemStackCapInitStatus(sender);
52+
}
53+
}
54+
55+
}

src/main/java/github/kasuminova/stellarcore/common/config/StellarCoreConfig.java

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import github.kasuminova.stellarcore.StellarCore;
55
import github.kasuminova.stellarcore.client.model.ParallelModelLoaderAsyncBlackList;
66
import github.kasuminova.stellarcore.client.pool.StellarUnpackedDataPool;
7+
import github.kasuminova.stellarcore.common.entity.EntityForceUpdateManager;
78
import net.minecraftforge.common.config.Config;
89
import net.minecraftforge.common.config.ConfigManager;
910
import net.minecraftforge.fml.client.event.ConfigChangedEvent;
@@ -979,7 +980,10 @@ public static class CustomLoadingScreen {
979980

980981
public static class EBWizardry {
981982

982-
@Config.Comment("(Server Performance) Improved event listening performance for DispenserCastingData, required mc restart.")
983+
@Config.Comment({
984+
"(Server Performance) Improved event listening performance for DispenserCastingData, required mc restart.",
985+
"Incompatible with TickCentral mod, alternative optimisations are used when installing with this mod.",
986+
})
983987
@Config.RequiresMcRestart
984988
@Config.Name("DispenserCastingDataImprovements")
985989
public boolean dispenserCastingData = false;
@@ -1299,6 +1303,25 @@ public static class Vanilla {
12991303
@Config.Name("HandleClientWorldLoad")
13001304
public boolean handleClientWorldLoad = true;
13011305

1306+
@Config.Comment({
1307+
"(Server) Define which entities will be forced to be updated.",
1308+
"The update to stop when there are no players near the entity, which may cause some projectiles to pile up.",
1309+
"This feature allows certain entities to be forced to be updated.",
1310+
"Note: Entity classes must be explicitly defined and their superclasses cannot be retrieved, this is for performance reasons."
1311+
})
1312+
@Config.RequiresMcRestart
1313+
@Config.Name("ForceUpdateEntityClasses")
1314+
public String[] forceUpdateEntityClasses = {
1315+
"cofh.redstonearsenal.entity.projectile.EntityArrowFlux",
1316+
"com.brandon3055.draconicevolution.entity.EntityCustomArrow",
1317+
"hellfirepvp.astralsorcery.common.entities.EntityFlare",
1318+
"hellfirepvp.astralsorcery.common.entities.EntityLiquidSpark",
1319+
"mekanism.weapons.common.entity.EntityMekaArrow", // MEKCEu
1320+
"net.minecraft.entity.projectile.EntitySpectralArrow",
1321+
"thundr.redstonerepository.entity.projectile.EntityArrowGelid",
1322+
"xyz.phanta.tconevo.entity.EntityMagicMissile",
1323+
};
1324+
13021325
}
13031326

13041327
public static class FontScale {
@@ -1459,6 +1482,7 @@ public static void onConfigChanged(ConfigChangedEvent.OnConfigChangedEvent event
14591482
if (event.getModID().equals(StellarCore.MOD_ID)) {
14601483
ConfigManager.sync(StellarCore.MOD_ID, Config.Type.INSTANCE);
14611484

1485+
EntityForceUpdateManager.INSTANCE.reload();
14621486
if (FMLLaunchHandler.side().isClient()) {
14631487
ParallelModelLoaderAsyncBlackList.INSTANCE.reload();
14641488
// Pool does not reference minecraft class, so is safety.
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package github.kasuminova.stellarcore.common.entity;
2+
3+
import github.kasuminova.stellarcore.client.util.ClassSet;
4+
import github.kasuminova.stellarcore.common.config.StellarCoreConfig;
5+
import net.minecraftforge.event.entity.EntityEvent;
6+
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
7+
8+
import java.util.Arrays;
9+
10+
public class EntityForceUpdateManager extends ClassSet {
11+
12+
public static final EntityForceUpdateManager INSTANCE = new EntityForceUpdateManager();
13+
14+
@SubscribeEvent
15+
public void onEntityCanUpdate(final EntityEvent.CanUpdate event) {
16+
if (isInSet(event.getEntity().getClass())) {
17+
event.setCanUpdate(true);
18+
}
19+
}
20+
21+
@Override
22+
public void reload() {
23+
classSet.clear();
24+
Arrays.stream(StellarCoreConfig.FEATURES.vanilla.forceUpdateEntityClasses)
25+
.forEach(className -> findClass(className).ifPresent(this::add));
26+
}
27+
28+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package github.kasuminova.stellarcore.common.integration.ebwizardry;
2+
3+
import electroblob.wizardry.data.DispenserCastingData;
4+
import net.minecraft.tileentity.TileEntityDispenser;
5+
import net.minecraftforge.fml.common.Optional;
6+
7+
public class DispenserCastingCompat {
8+
9+
@Optional.Method(modid = "ebwizardry")
10+
public static void handleEBWizardryUpdate(final TileEntityDispenser dispenser) {
11+
DispenserCastingData data = DispenserCastingData.get(dispenser);
12+
if (data != null) {
13+
data.update();
14+
}
15+
}
16+
17+
}

0 commit comments

Comments
 (0)