Skip to content

Commit

Permalink
- 新增 EBWizardry 的一项物品复制修复。
Browse files Browse the repository at this point in the history
- 优化 NBT 原始类型的复制。
- 优化 EnderIO 的能量网络优化的性能开销。
- 新增几个内部兼容。
  • Loading branch information
KasumiNova committed Oct 14, 2024
1 parent 5824650 commit 2a10492
Show file tree
Hide file tree
Showing 25 changed files with 307 additions and 188 deletions.
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ plugins {

// Project properties
group = "github.kasuminova.stellarcore"
version = "1.5.6"
version = "1.5.9"

// Set the toolchain version to decouple the Java we run Gradle with from the Java used to compile and run the mod
java {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ public class BugFixes {
@Config.Name("DraconicEvolution")
public final DraconicEvolution draconicEvolution = new DraconicEvolution();

@Config.Name("EBWizardry")
public final EBWizardry ebWizardry = new EBWizardry();

@Config.Name("EnderIOConduits")
public final EnderIOConduits enderIOConduits = new EnderIOConduits();

Expand Down Expand Up @@ -252,6 +255,14 @@ public static class DraconicEvolution {
public boolean craftingInjector = true;

}

public static class EBWizardry {

@Config.Comment("Fix an issue where Imbuement Altar could copy items using a special interact method.")
@Config.Name("BlockImbuementAltarDupeFixes")
public boolean blockImbuementAltar = true;

}

public static class EnderIOConduits {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -596,9 +596,9 @@ public static class IndustrialCraft2 {
@Config.Name("EnergyNetLocalImprovements")
public boolean energyNetLocal = true;

@Config.Comment("(Server Performance) Improve EnergyNetLocal#getIoTile and EnergyNetLocal#getSubTile fetching speed to optimise performance to some extent.")
@Config.Name("GetIoAndSubTileEnergyNetLocalImprovements")
public boolean getIoAndSubTile = true;
// @Config.Comment("(Server Performance) Improve EnergyNetLocal#getIoTile and EnergyNetLocal#getSubTile fetching speed to optimise performance to some extent.")
// @Config.Name("GetIoAndSubTileEnergyNetLocalImprovements")
// public boolean getIoAndSubTile = true;

@Config.Comment("(Server Performance) Improved some data structures, slight performance improvements.")
@Config.Name("GridImprovements")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import github.kasuminova.stellarcore.common.util.StellarEnvironment;
import github.kasuminova.stellarcore.common.util.StellarLog;
import github.kasuminova.stellarcore.shaded.org.jctools.queues.unpadded.MpmcUnpaddedArrayQueue;
import github.kasuminova.stellarcore.shaded.org.jctools.queues.atomic.unpadded.MpmcAtomicUnpaddedArrayQueue;

import java.util.List;
import java.util.Queue;
Expand All @@ -15,6 +15,7 @@ public class ItemStackCapInitializer implements Runnable {

public static final ItemStackCapInitializer INSTANCE = new ItemStackCapInitializer();

private static final ThreadLocal<Boolean> SHOULD_ADD_TASK = ThreadLocal.withInitial(() -> true);
private static final int QUEUE_BOUND_SIZE = 50_000;
private static final int MAX_WORKERS = Math.min(StellarEnvironment.getConcurrency(), 8);

Expand All @@ -33,6 +34,10 @@ private ItemStackCapInitializer() {
createWorkerInternal();
}

public static void setShouldAddTask(final boolean shouldAddTask) {
SHOULD_ADD_TASK.set(shouldAddTask);
}

public static void resetStatus() {
INSTANCE.completedTasksOffset = -INSTANCE.completedTasks.get();
INSTANCE.start = System.currentTimeMillis();
Expand Down Expand Up @@ -80,6 +85,9 @@ private void createWorkerInternal() {
}

public void addTask(final ItemStackCapInitTask task) {
if (!SHOULD_ADD_TASK.get()) {
return;
}
while (!taskQueue.offer(task)) {
if (taskQueue.offer(task)) {
break;
Expand Down Expand Up @@ -143,7 +151,7 @@ private static void park() {
}

private static <E> Queue<E> createConcurrentQueue() {
return new MpmcUnpaddedArrayQueue<>(QUEUE_BOUND_SIZE * (MAX_WORKERS + 1));
return new MpmcAtomicUnpaddedArrayQueue<>(QUEUE_BOUND_SIZE * (MAX_WORKERS + 1));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,15 @@ public class StellarCoreEarlyMixinLoader implements IFMLLoadingPlugin {
addMixinCFG("mixins.stellar_core_minecraft_statemapperbase.json", () -> StellarCoreConfig.PERFORMANCE.vanilla.parallelModelLoader || StellarCoreConfig.PERFORMANCE.vanilla.stateMapperBase);
addMixinCFG("mixins.stellar_core_minecraft_stitcher.json", () -> StellarCoreConfig.PERFORMANCE.vanilla.stitcherCache);
// addMixinCFG("mixins.stellar_core_minecraft_texturemap.json", () -> StellarCoreConfig.PERFORMANCE.vanilla.parallelTextureMapLoad);
addMixinCFG("mixins.stellar_core_minecraft_texture_load.json", () -> StellarCoreConfig.PERFORMANCE.vanilla.parallelTextureLoad);
addMixinCFG("mixins.stellar_core_forge.json", () -> StellarCoreConfig.PERFORMANCE.customLoadingScreen.splashProgress);
addMixinCFG("mixins.stellar_core_forge_asmdatatable.json", () -> StellarCoreConfig.PERFORMANCE.forge.asmDataTable);
addMixinCFG("mixins.stellar_core_forge_bakedquad.json", () -> StellarCoreConfig.PERFORMANCE.forge.unpackedBakedQuadDataCanonicalization);
addMixinCFG("mixins.stellar_core_forge_bakedquad_vertexdata.json", () -> StellarCoreConfig.PERFORMANCE.forge.unpackedBakedQuadVertexDataCanonicalization);
addMixinCFG("mixins.stellar_core_forge_modelloader.json", () -> StellarCoreConfig.PERFORMANCE.vanilla.parallelModelLoader);
addMixinCFG("mixins.stellar_core_forge_registry.json", () -> StellarCoreConfig.FEATURES.vanilla.forgeRegistryRemoveList.length > 0);
addMixinCFG("mixins.stellar_core_hudcaching.json", () -> StellarCoreConfig.PERFORMANCE.vanilla.hudCaching);
addMixinCFG("mixins.stellar_core_ebwizardry_early.json", () -> StellarCoreConfig.PERFORMANCE.ebWizardry.dispenserCastingData && !Mods.TICK_CENTRAL.loaded());
addMixinCFG("mixins.stellar_core_minecraft_texture_load.json", () -> StellarCoreConfig.PERFORMANCE.vanilla.parallelTextureLoad);
addMixinCFG("mixins.stellar_core_forge.json", () -> StellarCoreConfig.PERFORMANCE.customLoadingScreen.splashProgress);
addMixinCFG("mixins.stellar_core_forge_asmdatatable.json", () -> StellarCoreConfig.PERFORMANCE.forge.asmDataTable);
addMixinCFG("mixins.stellar_core_forge_bakedquad.json", () -> StellarCoreConfig.PERFORMANCE.forge.unpackedBakedQuadDataCanonicalization);
addMixinCFG("mixins.stellar_core_forge_bakedquad_vertexdata.json", () -> StellarCoreConfig.PERFORMANCE.forge.unpackedBakedQuadVertexDataCanonicalization);
addMixinCFG("mixins.stellar_core_forge_modelloader.json", () -> StellarCoreConfig.PERFORMANCE.vanilla.parallelModelLoader);
addMixinCFG("mixins.stellar_core_forge_registry.json", () -> StellarCoreConfig.FEATURES.vanilla.forgeRegistryRemoveList.length > 0);
addMixinCFG("mixins.stellar_core_hudcaching.json", () -> StellarCoreConfig.PERFORMANCE.vanilla.hudCaching);
addMixinCFG("mixins.stellar_core_ebwizardry_early.json", () -> StellarCoreConfig.PERFORMANCE.ebWizardry.dispenserCastingData && !Mods.TICK_CENTRAL.loaded());
}

private static void addMixinCFG(final String mixinConfig) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package github.kasuminova.stellarcore.mixin.appeng;

import appeng.me.cache.CraftingGridCache;
import github.kasuminova.stellarcore.common.config.StellarCoreConfig;
import github.kasuminova.stellarcore.common.itemstack.ItemStackCapInitializer;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

@SuppressWarnings("MethodMayBeStatic")
@Mixin(value = CraftingGridCache.class, remap = false)
public class MixinCraftingGridCache {

/**
* Prevents a large number of ItemStacks from loading.
*/
@Inject(method = "onUpdateTick", at = @At("HEAD"))
private void injectOnUpdateTickStart(final CallbackInfo ci) {
if (!StellarCoreConfig.PERFORMANCE.vanilla.asyncItemStackCapabilityInit) {
return;
}
ItemStackCapInitializer.setShouldAddTask(false);
}

/**
* Prevents a large number of ItemStacks from loading.
*/
@Inject(method = "onUpdateTick", at = @At("RETURN"))
private void injectOnUpdateTickEnd(final CallbackInfo ci) {
if (!StellarCoreConfig.PERFORMANCE.vanilla.asyncItemStackCapabilityInit) {
return;
}
ItemStackCapInitializer.setShouldAddTask(true);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package github.kasuminova.stellarcore.mixin.draconicevolution;

import com.brandon3055.draconicevolution.blocks.tileentity.TileEnergyPylon;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.ChunkPos;
import net.minecraft.world.World;
import net.minecraft.world.chunk.Chunk;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Redirect;

@SuppressWarnings("MethodMayBeStatic")
@Mixin(TileEnergyPylon.class)
public class MixinTileEnergyPylon {

/**
* Prevent chunk load.
*/
@Redirect(
method = "getCore",
at = @At(
value = "INVOKE",
target = "Lnet/minecraft/world/World;getChunk(Lnet/minecraft/util/math/BlockPos;)Lnet/minecraft/world/chunk/Chunk;"
),
remap = false
)
private Chunk redirectGetCore(final World instance, final BlockPos pos) {
ChunkPos chunkPos = new ChunkPos(pos);
return instance.getChunkProvider().getLoadedChunk(chunkPos.x, chunkPos.z);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package github.kasuminova.stellarcore.mixin.ebwizardry;

import com.llamalad7.mixinextras.sugar.Local;
import electroblob.wizardry.block.BlockImbuementAltar;
import github.kasuminova.stellarcore.common.config.StellarCoreConfig;
import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.EnumHand;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;

@SuppressWarnings("MethodMayBeStatic")
@Mixin(BlockImbuementAltar.class)
public class MixinBlockImbuementAltar {

@Inject(method = "onBlockActivated", at = @At(value = "INVOKE", target = "Lnet/minecraft/item/ItemStack;copy()Lnet/minecraft/item/ItemStack;"), cancellable = true)
private void injectOnBlockActivated(final World world, final BlockPos pos, final IBlockState block, final EntityPlayer player,
final EnumHand hand, final EnumFacing side,
final float hitX, final float hitY, final float hitZ,
final CallbackInfoReturnable<Boolean> cir,
@Local(name = "toInsert") final ItemStack toInsert)
{
if (!StellarCoreConfig.BUG_FIXES.ebWizardry.blockImbuementAltar) {
return;
}
if (toInsert.isEmpty()) {
cir.setReturnValue(true);
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ private static void injectOnWorldTickTickListenerEnd(final Profiler profiler, fi

@Inject(method = "onWorldTick", at = @At("RETURN"))
private static void injectOnWorldTickEnd(final TickEvent.WorldTickEvent event, final CallbackInfo ci) {
FINAL_TICK_LISTENERS.forEach(IStellarServerTickListener::tickFinal);
FINAL_TICK_LISTENERS.parallelStream().forEach(IStellarServerTickListener::stellar_core$tickParallel);
FINAL_TICK_LISTENERS.forEach(IStellarServerTickListener::stellar_core$tickFinal);
FINAL_TICK_LISTENERS.clear();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,6 @@ public abstract class MixinNetworkPowerManager implements IStellarNetworkPowerMa
@Unique
private final List<ReceptorPowerInterface> stellar_core$collectedPowerInterface = new ObjectArrayList<>();

@Unique
private ForkJoinTask<?> stellar_core$parallelTask = null;

@Unique
private volatile boolean stellar_core$shouldFinalApply = false;

Expand All @@ -96,48 +93,44 @@ public void doApplyRecievedPower(final Profiler theProfiler, final CallbackInfo

trackerStartTick();
checkReceptors();
}

stellar_core$parallelTask = ForkJoinPool.commonPool().submit(() -> {
// Update our energy stored based on what's in our conduits
updateNetworkStorage();
networkPowerTracker.tickStart(energyStored);
@Override
public void stellar_core$parallelTick() {
// Update our energy stored based on what's in our conduits
updateNetworkStorage();
networkPowerTracker.tickStart(energyStored);

ICapBankSupply capSupply = stellar_core$getCapSupply();
capSupply.invokeInit();
ICapBankSupply capSupply = stellar_core$getCapSupply();
capSupply.invokeInit();

long available = energyStored + capSupply.getCanExtract();
long available = energyStored + capSupply.getCanExtract();

if (available <= 0 || (receptors.isEmpty() && storageReceptors.isEmpty())) {
trackerEndTick();
networkPowerTracker.tickEnd(energyStored);
stellar_core$shouldFinalApply = false;
return;
}
if (available <= 0 || (receptors.isEmpty() && storageReceptors.isEmpty())) {
trackerEndTick();
networkPowerTracker.tickEnd(energyStored);
stellar_core$shouldFinalApply = false;
return;
}

stellar_core$collectedPowerInterface.clear();
receptors.forEach(receptor -> {
AccessorReceptorEntry accessorReceptorEntry = (AccessorReceptorEntry) receptor;
IPowerInterface pp = accessorReceptorEntry.invokeGetPowerInterface();
if (pp != null) {
stellar_core$collectedPowerInterface.add(new ReceptorPowerInterface(pp, accessorReceptorEntry));
}
});
stellar_core$shouldFinalApply = true;
stellar_core$collectedPowerInterface.clear();
receptors.forEach(receptor -> {
AccessorReceptorEntry accessorReceptorEntry = (AccessorReceptorEntry) receptor;
IPowerInterface pp = accessorReceptorEntry.invokeGetPowerInterface();
if (pp != null) {
stellar_core$collectedPowerInterface.add(new ReceptorPowerInterface(pp, accessorReceptorEntry));
}
});
stellar_core$shouldFinalApply = true;
}

@Unique
@Override
@SuppressWarnings("AddedMixinMembersNamePattern")
public void finalApplyReceivedPower() {
public void stellar_core$finalApplyReceivedPower() {
if (!StellarCoreConfig.PERFORMANCE.enderIOConduits.networkPowerManager) {
return;
}

if (stellar_core$parallelTask != null && !stellar_core$parallelTask.isDone()) {
stellar_core$parallelTask.join();
}
stellar_core$parallelTask = null;
if (!stellar_core$shouldFinalApply) {
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,15 @@ protected MixinPowerConduitNetwork() {
super(null, null);
}

@Override
public void stellar_core$tickParallel() {
((IStellarNetworkPowerManager) powerManager).stellar_core$parallelTick();
}

@Unique
@Override
@SuppressWarnings("AddedMixinMembersNamePattern")
public void tickFinal() {
((IStellarNetworkPowerManager) powerManager).finalApplyReceivedPower();
public void stellar_core$tickFinal() {
((IStellarNetworkPowerManager) powerManager).stellar_core$finalApplyReceivedPower();
}

}
Loading

0 comments on commit 2a10492

Please sign in to comment.