diff --git a/build.gradle.kts b/build.gradle.kts index c4c42dd..7ffc728 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -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 { diff --git a/src/main/java/github/kasuminova/stellarcore/common/config/category/BugFixes.java b/src/main/java/github/kasuminova/stellarcore/common/config/category/BugFixes.java index d348056..0566182 100644 --- a/src/main/java/github/kasuminova/stellarcore/common/config/category/BugFixes.java +++ b/src/main/java/github/kasuminova/stellarcore/common/config/category/BugFixes.java @@ -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(); @@ -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 { diff --git a/src/main/java/github/kasuminova/stellarcore/common/config/category/Performance.java b/src/main/java/github/kasuminova/stellarcore/common/config/category/Performance.java index 6f46b8b..627a108 100644 --- a/src/main/java/github/kasuminova/stellarcore/common/config/category/Performance.java +++ b/src/main/java/github/kasuminova/stellarcore/common/config/category/Performance.java @@ -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") diff --git a/src/main/java/github/kasuminova/stellarcore/common/itemstack/ItemStackCapInitializer.java b/src/main/java/github/kasuminova/stellarcore/common/itemstack/ItemStackCapInitializer.java index 028cfc7..2c5fd5b 100644 --- a/src/main/java/github/kasuminova/stellarcore/common/itemstack/ItemStackCapInitializer.java +++ b/src/main/java/github/kasuminova/stellarcore/common/itemstack/ItemStackCapInitializer.java @@ -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; @@ -15,6 +15,7 @@ public class ItemStackCapInitializer implements Runnable { public static final ItemStackCapInitializer INSTANCE = new ItemStackCapInitializer(); + private static final ThreadLocal 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); @@ -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(); @@ -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; @@ -143,7 +151,7 @@ private static void park() { } private static Queue createConcurrentQueue() { - return new MpmcUnpaddedArrayQueue<>(QUEUE_BOUND_SIZE * (MAX_WORKERS + 1)); + return new MpmcAtomicUnpaddedArrayQueue<>(QUEUE_BOUND_SIZE * (MAX_WORKERS + 1)); } } diff --git a/src/main/java/github/kasuminova/stellarcore/mixin/StellarCoreEarlyMixinLoader.java b/src/main/java/github/kasuminova/stellarcore/mixin/StellarCoreEarlyMixinLoader.java index 7ec18e2..11f2ad5 100644 --- a/src/main/java/github/kasuminova/stellarcore/mixin/StellarCoreEarlyMixinLoader.java +++ b/src/main/java/github/kasuminova/stellarcore/mixin/StellarCoreEarlyMixinLoader.java @@ -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) { diff --git a/src/main/java/github/kasuminova/stellarcore/mixin/appeng/MixinCraftingGridCache.java b/src/main/java/github/kasuminova/stellarcore/mixin/appeng/MixinCraftingGridCache.java new file mode 100644 index 0000000..a53380e --- /dev/null +++ b/src/main/java/github/kasuminova/stellarcore/mixin/appeng/MixinCraftingGridCache.java @@ -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); + } + +} diff --git a/src/main/java/github/kasuminova/stellarcore/mixin/draconicevolution/MixinTileEnergyPylon.java b/src/main/java/github/kasuminova/stellarcore/mixin/draconicevolution/MixinTileEnergyPylon.java new file mode 100644 index 0000000..7a704d7 --- /dev/null +++ b/src/main/java/github/kasuminova/stellarcore/mixin/draconicevolution/MixinTileEnergyPylon.java @@ -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); + } + +} diff --git a/src/main/java/github/kasuminova/stellarcore/mixin/ebwizardry/MixinBlockImbuementAltar.java b/src/main/java/github/kasuminova/stellarcore/mixin/ebwizardry/MixinBlockImbuementAltar.java new file mode 100644 index 0000000..3605fb6 --- /dev/null +++ b/src/main/java/github/kasuminova/stellarcore/mixin/ebwizardry/MixinBlockImbuementAltar.java @@ -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 cir, + @Local(name = "toInsert") final ItemStack toInsert) + { + if (!StellarCoreConfig.BUG_FIXES.ebWizardry.blockImbuementAltar) { + return; + } + if (toInsert.isEmpty()) { + cir.setReturnValue(true); + } + } + +} diff --git a/src/main/java/github/kasuminova/stellarcore/mixin/enderio/MixinServerTickHandler.java b/src/main/java/github/kasuminova/stellarcore/mixin/enderio/MixinServerTickHandler.java index 358e08e..581b066 100644 --- a/src/main/java/github/kasuminova/stellarcore/mixin/enderio/MixinServerTickHandler.java +++ b/src/main/java/github/kasuminova/stellarcore/mixin/enderio/MixinServerTickHandler.java @@ -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(); } diff --git a/src/main/java/github/kasuminova/stellarcore/mixin/enderioconduits_energy/MixinNetworkPowerManager.java b/src/main/java/github/kasuminova/stellarcore/mixin/enderioconduits_energy/MixinNetworkPowerManager.java index 320e355..85cb738 100644 --- a/src/main/java/github/kasuminova/stellarcore/mixin/enderioconduits_energy/MixinNetworkPowerManager.java +++ b/src/main/java/github/kasuminova/stellarcore/mixin/enderioconduits_energy/MixinNetworkPowerManager.java @@ -72,9 +72,6 @@ public abstract class MixinNetworkPowerManager implements IStellarNetworkPowerMa @Unique private final List stellar_core$collectedPowerInterface = new ObjectArrayList<>(); - @Unique - private ForkJoinTask stellar_core$parallelTask = null; - @Unique private volatile boolean stellar_core$shouldFinalApply = false; @@ -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; } diff --git a/src/main/java/github/kasuminova/stellarcore/mixin/enderioconduits_energy/MixinPowerConduitNetwork.java b/src/main/java/github/kasuminova/stellarcore/mixin/enderioconduits_energy/MixinPowerConduitNetwork.java index 8b679ad..845da48 100644 --- a/src/main/java/github/kasuminova/stellarcore/mixin/enderioconduits_energy/MixinPowerConduitNetwork.java +++ b/src/main/java/github/kasuminova/stellarcore/mixin/enderioconduits_energy/MixinPowerConduitNetwork.java @@ -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(); } } diff --git a/src/main/java/github/kasuminova/stellarcore/mixin/ic2/MixinEnergyNetLocal.java b/src/main/java/github/kasuminova/stellarcore/mixin/ic2/MixinEnergyNetLocal.java index b70e202..0ac5a52 100644 --- a/src/main/java/github/kasuminova/stellarcore/mixin/ic2/MixinEnergyNetLocal.java +++ b/src/main/java/github/kasuminova/stellarcore/mixin/ic2/MixinEnergyNetLocal.java @@ -24,121 +24,121 @@ @Mixin(value = EnergyNetLocal.class, remap = false) public abstract class MixinEnergyNetLocal { - @Final - @Shadow - @Mutable - Map registeredTiles; - - @Unique - private final BlockPos2ValueMap> stellar_core$gridChangesMap = new BlockPos2ValueMap<>(); - - @Unique - private static final Object STELLAR_CORE$QUEUE_DELAY_CHANGE = stellar_core$getQueueDelayChange(); - - @Inject(method = "", at = @At("RETURN")) - private void injectInit(final CallbackInfo ci) { - if (!StellarCoreConfig.PERFORMANCE.industrialCraft2.energyNetLocal) { - return; - } - this.registeredTiles = new BlockPos2ValueMap<>(); - } - - @Inject(method = "getIoTile", at = @At(value = "INVOKE", target = "Ljava/util/Queue;iterator()Ljava/util/Iterator;"), cancellable = true) - private void injectGetIOTileBeforeScanQueue(final BlockPos pos, final CallbackInfoReturnable cir) { - if (!StellarCoreConfig.PERFORMANCE.industrialCraft2.getIoAndSubTile) { - return; - } - - List gridChanges = stellar_core$gridChangesMap.get(pos); - if (gridChanges == null) { - cir.setReturnValue(null); - return; - } - - gridChanges.stream() - .filter(gridChange -> gridChange.getPos().equals(pos)) - .findFirst() - .ifPresent(gridChange -> cir.setReturnValue(gridChange.getIoTile())); - } - - @Inject(method = "getSubTile", at = @At(value = "INVOKE", target = "Ljava/util/Queue;iterator()Ljava/util/Iterator;"), cancellable = true) - private void injectGetSubTileBeforeScan(final BlockPos pos, final CallbackInfoReturnable cir) { - if (!StellarCoreConfig.PERFORMANCE.industrialCraft2.getIoAndSubTile) { - return; - } - - List gridChanges = stellar_core$gridChangesMap.get(pos); - if (gridChanges == null) { - cir.setReturnValue(null); - return; - } - - for (AccessorGridChange gridChange : gridChanges) { - if (!gridChange.getPos().equals(pos)) { - continue; - } - - List subTiles = gridChange.getSubTiles(); - if (subTiles == null) { - subTiles = Collections.singletonList(gridChange.getIoTile()); - } - - for (final IEnergyTile subTile : subTiles) { - if (EnergyNet.instance.getPos(subTile).equals(pos)) { - cir.setReturnValue(subTile); - return; - } - } - } - } - - @Redirect(method = {"addTile", "removeTile"}, at = @At(value = "INVOKE", target = "Ljava/util/Queue;add(Ljava/lang/Object;)Z")) - private boolean redirectQueueAdd(final Queue instance, final Object e) { - if (e != STELLAR_CORE$QUEUE_DELAY_CHANGE && e instanceof AccessorGridChange gridChange) { - stellar_core$gridChangesMap.computeIfAbsent(gridChange.getPos(), (key) -> new ObjectArrayList<>()).add(gridChange); - } - return instance.add(e); - } - - @Redirect(method = "removeTile", at = @At(value = "INVOKE", target = "Ljava/util/Queue;remove(Ljava/lang/Object;)Z")) - private boolean redirectQueueRemove(final Queue instance, final Object e) { - boolean removed = instance.remove(e); - if (removed && e != STELLAR_CORE$QUEUE_DELAY_CHANGE && e instanceof AccessorGridChange gridChange) { - List gridChanges = stellar_core$gridChangesMap.get(gridChange.getPos()); - if (gridChanges != null) { - gridChanges.remove(gridChange); - if (gridChanges.isEmpty()) { - stellar_core$gridChangesMap.remove(gridChange.getPos()); - } - } - } - return removed; - } - - @Redirect(method = "onTickEnd", at = @At(value = "INVOKE", target = "Ljava/util/Queue;poll()Ljava/lang/Object;")) - private Object redirectQueuePoll(final Queue instance) { - Object polled = instance.poll(); - if (polled != STELLAR_CORE$QUEUE_DELAY_CHANGE && polled instanceof AccessorGridChange gridChange) { - List gridChanges = stellar_core$gridChangesMap.get(gridChange.getPos()); - if (gridChanges != null) { - gridChanges.remove(gridChange); - if (gridChanges.isEmpty()) { - stellar_core$gridChangesMap.remove(gridChange.getPos()); - } - } - } - return polled; - } - - @Unique - private static Object stellar_core$getQueueDelayChange() { - try { - Field queueDelayChange = EnergyNetLocal.class.getDeclaredField("QUEUE_DELAY_CHANGE"); - queueDelayChange.setAccessible(true); - return queueDelayChange.get(null); - } catch (Throwable e) { - throw new RuntimeException(e); - } - } +// @Final +// @Shadow +// @Mutable +// Map registeredTiles; +// +// @Unique +// private final BlockPos2ValueMap> stellar_core$gridChangesMap = new BlockPos2ValueMap<>(); +// +// @Unique +// private static final Object STELLAR_CORE$QUEUE_DELAY_CHANGE = stellar_core$getQueueDelayChange(); +// +// @Inject(method = "", at = @At("RETURN")) +// private void injectInit(final CallbackInfo ci) { +// if (!StellarCoreConfig.PERFORMANCE.industrialCraft2.energyNetLocal) { +// return; +// } +// this.registeredTiles = new BlockPos2ValueMap<>(); +// } +// +// @Inject(method = "getIoTile", at = @At(value = "INVOKE", target = "Ljava/util/Queue;iterator()Ljava/util/Iterator;"), cancellable = true) +// private void injectGetIOTileBeforeScanQueue(final BlockPos pos, final CallbackInfoReturnable cir) { +// if (!StellarCoreConfig.PERFORMANCE.industrialCraft2.getIoAndSubTile) { +// return; +// } +// +// List gridChanges = stellar_core$gridChangesMap.get(pos); +// if (gridChanges == null) { +// cir.setReturnValue(null); +// return; +// } +// +// gridChanges.stream() +// .filter(gridChange -> gridChange.getPos().equals(pos)) +// .findFirst() +// .ifPresent(gridChange -> cir.setReturnValue(gridChange.getIoTile())); +// } +// +// @Inject(method = "getSubTile", at = @At(value = "INVOKE", target = "Ljava/util/Queue;iterator()Ljava/util/Iterator;"), cancellable = true) +// private void injectGetSubTileBeforeScan(final BlockPos pos, final CallbackInfoReturnable cir) { +// if (!StellarCoreConfig.PERFORMANCE.industrialCraft2.getIoAndSubTile) { +// return; +// } +// +// List gridChanges = stellar_core$gridChangesMap.get(pos); +// if (gridChanges == null) { +// cir.setReturnValue(null); +// return; +// } +// +// for (AccessorGridChange gridChange : gridChanges) { +// if (!gridChange.getPos().equals(pos)) { +// continue; +// } +// +// List subTiles = gridChange.getSubTiles(); +// if (subTiles == null) { +// subTiles = Collections.singletonList(gridChange.getIoTile()); +// } +// +// for (final IEnergyTile subTile : subTiles) { +// if (EnergyNet.instance.getPos(subTile).equals(pos)) { +// cir.setReturnValue(subTile); +// return; +// } +// } +// } +// } +// +// @Redirect(method = {"addTile", "removeTile"}, at = @At(value = "INVOKE", target = "Ljava/util/Queue;add(Ljava/lang/Object;)Z")) +// private boolean redirectQueueAdd(final Queue instance, final Object e) { +// if (e != STELLAR_CORE$QUEUE_DELAY_CHANGE && e instanceof AccessorGridChange gridChange) { +// stellar_core$gridChangesMap.computeIfAbsent(gridChange.getPos(), (key) -> new ObjectArrayList<>()).add(gridChange); +// } +// return instance.add(e); +// } +// +// @Redirect(method = "removeTile", at = @At(value = "INVOKE", target = "Ljava/util/Queue;remove(Ljava/lang/Object;)Z")) +// private boolean redirectQueueRemove(final Queue instance, final Object e) { +// boolean removed = instance.remove(e); +// if (removed && e != STELLAR_CORE$QUEUE_DELAY_CHANGE && e instanceof AccessorGridChange gridChange) { +// List gridChanges = stellar_core$gridChangesMap.get(gridChange.getPos()); +// if (gridChanges != null) { +// gridChanges.remove(gridChange); +// if (gridChanges.isEmpty()) { +// stellar_core$gridChangesMap.remove(gridChange.getPos()); +// } +// } +// } +// return removed; +// } +// +// @Redirect(method = "onTickEnd", at = @At(value = "INVOKE", target = "Ljava/util/Queue;poll()Ljava/lang/Object;")) +// private Object redirectQueuePoll(final Queue instance) { +// Object polled = instance.poll(); +// if (polled != STELLAR_CORE$QUEUE_DELAY_CHANGE && polled instanceof AccessorGridChange gridChange) { +// List gridChanges = stellar_core$gridChangesMap.get(gridChange.getPos()); +// if (gridChanges != null) { +// gridChanges.remove(gridChange); +// if (gridChanges.isEmpty()) { +// stellar_core$gridChangesMap.remove(gridChange.getPos()); +// } +// } +// } +// return polled; +// } +// +// @Unique +// private static Object stellar_core$getQueueDelayChange() { +// try { +// Field queueDelayChange = EnergyNetLocal.class.getDeclaredField("QUEUE_DELAY_CHANGE"); +// queueDelayChange.setAccessible(true); +// return queueDelayChange.get(null); +// } catch (Throwable e) { +// throw new RuntimeException(e); +// } +// } } diff --git a/src/main/java/github/kasuminova/stellarcore/mixin/ic2_energynet/MixinGridUpdater.java b/src/main/java/github/kasuminova/stellarcore/mixin/ic2_energynet/MixinGridUpdater.java index 3294bd4..f3ccbac 100644 --- a/src/main/java/github/kasuminova/stellarcore/mixin/ic2_energynet/MixinGridUpdater.java +++ b/src/main/java/github/kasuminova/stellarcore/mixin/ic2_energynet/MixinGridUpdater.java @@ -111,7 +111,6 @@ void startTransferCalc(final CallbackInfo ci) { @Unique private void stellar_core$executeSyncTasks(final int totalTasks, final IStellarEnergyCalculatorLeg stellarCalculator, final Queue calculateQueue, final ForkJoinTask parallelFuture) { - int completedTask = 0; IC2EnergySyncCalcTask task; boolean syncBusy; while (!parallelFuture.isDone()) { @@ -119,12 +118,10 @@ void startTransferCalc(final CallbackInfo ci) { while ((task = stellar_core$syncTaskQueue.poll()) != null) { stellarCalculator.doSyncCalc(task); - completedTask++; syncBusy = false; } if (stellar_core$helpComplete(stellarCalculator, calculateQueue)) { - completedTask++; syncBusy = false; } @@ -133,16 +130,13 @@ void startTransferCalc(final CallbackInfo ci) { } } - while (stellar_core$helpComplete(stellarCalculator, calculateQueue)) { - completedTask++; + while (true) { + if (!stellar_core$helpComplete(stellarCalculator, calculateQueue)) { + break; + } } while ((task = stellar_core$syncTaskQueue.poll()) != null) { stellarCalculator.doSyncCalc(task); - completedTask++; - } - - if (completedTask < totalTasks) { - StellarLog.LOG.warn("[StellarCore-IC2GridUpdater] Unable to complete all tasks, {} tasks left.", totalTasks - completedTask); } } diff --git a/src/main/java/github/kasuminova/stellarcore/mixin/minecraft/nbtpool/MixinNBTTagByte.java b/src/main/java/github/kasuminova/stellarcore/mixin/minecraft/nbtpool/MixinNBTTagByte.java index 1480a3b..ed8cb58 100644 --- a/src/main/java/github/kasuminova/stellarcore/mixin/minecraft/nbtpool/MixinNBTTagByte.java +++ b/src/main/java/github/kasuminova/stellarcore/mixin/minecraft/nbtpool/MixinNBTTagByte.java @@ -2,7 +2,6 @@ import github.kasuminova.stellarcore.common.pool.NBTTagPrimitivePool; import github.kasuminova.stellarcore.mixin.util.StellarPooledNBT; -import net.minecraft.nbt.NBTBase; import net.minecraft.nbt.NBTTagByte; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Overwrite; @@ -13,7 +12,7 @@ import javax.annotation.Nonnull; @Mixin(NBTTagByte.class) -public abstract class MixinNBTTagByte extends NBTBase implements StellarPooledNBT { +public abstract class MixinNBTTagByte implements StellarPooledNBT { @Override public Object stellar_core$getPooledNBT() { @@ -27,7 +26,7 @@ public abstract class MixinNBTTagByte extends NBTBase implements StellarPooledNB @Nonnull @Overwrite public NBTTagByte copy() { - return (NBTTagByte) (Object) this; + return stellar_core$isPooled() ? (NBTTagByte) (Object) this : NBTTagPrimitivePool.getTagByte((NBTTagByte) (Object) this); } /** diff --git a/src/main/java/github/kasuminova/stellarcore/mixin/minecraft/nbtpool/MixinNBTTagDouble.java b/src/main/java/github/kasuminova/stellarcore/mixin/minecraft/nbtpool/MixinNBTTagDouble.java index 09baf64..bc78d23 100644 --- a/src/main/java/github/kasuminova/stellarcore/mixin/minecraft/nbtpool/MixinNBTTagDouble.java +++ b/src/main/java/github/kasuminova/stellarcore/mixin/minecraft/nbtpool/MixinNBTTagDouble.java @@ -2,7 +2,6 @@ import github.kasuminova.stellarcore.common.pool.NBTTagPrimitivePool; import github.kasuminova.stellarcore.mixin.util.StellarPooledNBT; -import net.minecraft.nbt.NBTBase; import net.minecraft.nbt.NBTTagDouble; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Overwrite; diff --git a/src/main/java/github/kasuminova/stellarcore/mixin/minecraft/nbtpool/MixinNBTTagFloat.java b/src/main/java/github/kasuminova/stellarcore/mixin/minecraft/nbtpool/MixinNBTTagFloat.java index 465330c..37399bf 100644 --- a/src/main/java/github/kasuminova/stellarcore/mixin/minecraft/nbtpool/MixinNBTTagFloat.java +++ b/src/main/java/github/kasuminova/stellarcore/mixin/minecraft/nbtpool/MixinNBTTagFloat.java @@ -2,7 +2,6 @@ import github.kasuminova.stellarcore.common.pool.NBTTagPrimitivePool; import github.kasuminova.stellarcore.mixin.util.StellarPooledNBT; -import net.minecraft.nbt.NBTBase; import net.minecraft.nbt.NBTTagFloat; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Overwrite; diff --git a/src/main/java/github/kasuminova/stellarcore/mixin/minecraft/nbtpool/MixinNBTTagInt.java b/src/main/java/github/kasuminova/stellarcore/mixin/minecraft/nbtpool/MixinNBTTagInt.java index 5286a83..ee60312 100644 --- a/src/main/java/github/kasuminova/stellarcore/mixin/minecraft/nbtpool/MixinNBTTagInt.java +++ b/src/main/java/github/kasuminova/stellarcore/mixin/minecraft/nbtpool/MixinNBTTagInt.java @@ -2,7 +2,6 @@ import github.kasuminova.stellarcore.common.pool.NBTTagPrimitivePool; import github.kasuminova.stellarcore.mixin.util.StellarPooledNBT; -import net.minecraft.nbt.NBTBase; import net.minecraft.nbt.NBTTagInt; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Overwrite; diff --git a/src/main/java/github/kasuminova/stellarcore/mixin/minecraft/nbtpool/MixinNBTTagLong.java b/src/main/java/github/kasuminova/stellarcore/mixin/minecraft/nbtpool/MixinNBTTagLong.java index 87dafc2..c2d84d0 100644 --- a/src/main/java/github/kasuminova/stellarcore/mixin/minecraft/nbtpool/MixinNBTTagLong.java +++ b/src/main/java/github/kasuminova/stellarcore/mixin/minecraft/nbtpool/MixinNBTTagLong.java @@ -2,7 +2,6 @@ import github.kasuminova.stellarcore.common.pool.NBTTagPrimitivePool; import github.kasuminova.stellarcore.mixin.util.StellarPooledNBT; -import net.minecraft.nbt.NBTBase; import net.minecraft.nbt.NBTTagLong; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Overwrite; diff --git a/src/main/java/github/kasuminova/stellarcore/mixin/minecraft/nbtpool/MixinNBTTagShort.java b/src/main/java/github/kasuminova/stellarcore/mixin/minecraft/nbtpool/MixinNBTTagShort.java index 6c295d4..39668db 100644 --- a/src/main/java/github/kasuminova/stellarcore/mixin/minecraft/nbtpool/MixinNBTTagShort.java +++ b/src/main/java/github/kasuminova/stellarcore/mixin/minecraft/nbtpool/MixinNBTTagShort.java @@ -2,7 +2,6 @@ import github.kasuminova.stellarcore.common.pool.NBTTagPrimitivePool; import github.kasuminova.stellarcore.mixin.util.StellarPooledNBT; -import net.minecraft.nbt.NBTBase; import net.minecraft.nbt.NBTTagShort; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Overwrite; @@ -27,7 +26,7 @@ public abstract class MixinNBTTagShort implements StellarPooledNBT { @Nonnull @Overwrite public NBTTagShort copy() { - return (NBTTagShort) (Object) this; + return stellar_core$isPooled() ? (NBTTagShort) (Object) this : NBTTagPrimitivePool.getTagShort((NBTTagShort) (Object) this); } /** diff --git a/src/main/java/github/kasuminova/stellarcore/mixin/util/IStellarNetworkPowerManager.java b/src/main/java/github/kasuminova/stellarcore/mixin/util/IStellarNetworkPowerManager.java index d3bb230..1924646 100644 --- a/src/main/java/github/kasuminova/stellarcore/mixin/util/IStellarNetworkPowerManager.java +++ b/src/main/java/github/kasuminova/stellarcore/mixin/util/IStellarNetworkPowerManager.java @@ -2,6 +2,8 @@ public interface IStellarNetworkPowerManager { - void finalApplyReceivedPower(); + void stellar_core$parallelTick(); + + void stellar_core$finalApplyReceivedPower(); } diff --git a/src/main/java/github/kasuminova/stellarcore/mixin/util/IStellarServerTickListener.java b/src/main/java/github/kasuminova/stellarcore/mixin/util/IStellarServerTickListener.java index ef2c5a9..60176d1 100644 --- a/src/main/java/github/kasuminova/stellarcore/mixin/util/IStellarServerTickListener.java +++ b/src/main/java/github/kasuminova/stellarcore/mixin/util/IStellarServerTickListener.java @@ -2,6 +2,8 @@ public interface IStellarServerTickListener { - void tickFinal(); + void stellar_core$tickParallel(); + + void stellar_core$tickFinal(); } diff --git a/src/main/resources/mixins.stellar_core_ae.json b/src/main/resources/mixins.stellar_core_ae.json index 08ac987..9f8aa1e 100644 --- a/src/main/resources/mixins.stellar_core_ae.json +++ b/src/main/resources/mixins.stellar_core_ae.json @@ -7,5 +7,8 @@ "client": [ "MixinFluidStackSizeRenderer", "MixinStackSizeRenderer" + ], + "mixins": [ + "MixinCraftingGridCache" ] } \ No newline at end of file diff --git a/src/main/resources/mixins.stellar_core_draconicevolution.json b/src/main/resources/mixins.stellar_core_draconicevolution.json index f4c63b1..be01834 100644 --- a/src/main/resources/mixins.stellar_core_draconicevolution.json +++ b/src/main/resources/mixins.stellar_core_draconicevolution.json @@ -6,6 +6,7 @@ "compatibilityLevel": "JAVA_8", "mixins": [ "MixinTileCraftingInjector", + "MixinTileEnergyPylon", "MixinTileFusionCraftingCore" ] } \ No newline at end of file diff --git a/src/main/resources/mixins.stellar_core_ebwizardry.json b/src/main/resources/mixins.stellar_core_ebwizardry.json index 554c3ef..cee230b 100644 --- a/src/main/resources/mixins.stellar_core_ebwizardry.json +++ b/src/main/resources/mixins.stellar_core_ebwizardry.json @@ -5,6 +5,7 @@ "minVersion": "0.8", "compatibilityLevel": "JAVA_8", "mixins": [ + "MixinBlockImbuementAltar", "MixinDispenserCastingData", "MixinWizardSpell" ] diff --git a/src/main/resources/mixins.stellar_core_ic2.json b/src/main/resources/mixins.stellar_core_ic2.json index 0909393..a13fe75 100644 --- a/src/main/resources/mixins.stellar_core_ic2.json +++ b/src/main/resources/mixins.stellar_core_ic2.json @@ -12,7 +12,6 @@ "MixinBaseElectricItem", "MixinElectricItemManager", "MixinEnergyCalculatorLegGridData", - "MixinEnergyNetLocal", "MixinGradualRecipe", "MixinGrid", "MixinItemArmorElectric",