Files
fabric-carpet/src/main/java/carpet/mixins/ServerChunkManager_tickMixin.java
T
altrisiandgnembon ba1071a8d1 Javadocs, cleanup, extension's client rules, built-in BundledModules generators, etc (#544)
* Add javadocs to many methods

* Added built-in ways to generate BundledModules and documented them

* Add Eclipse launch files to .gitignore and fix 11 warnings

* Remove many unused imports

* Remove some dead and unused code around app loading

* Allow extensions to have client-side rules in their SettingsManager

Also change tabs to spaces when those changed

* Remove unnecessary classloader param in BundledModule

* Change max tickwarp duration to Integer.MAX_VALUE

* Move RulePrinter into the source so it can be managed by the IDE

* Properly reset hopperCounters when changing worlds

Also change tabs to spaces again and minor tweaks to javadocs

* Run mergedocs even if Full.md was modified

* Update src/main/java/carpet/commands/TickCommand.java

Co-authored-by: gnembon <41132274+gnembon@users.noreply.github.com>
2020-11-16 09:30:59 -04:00

80 lines
2.7 KiB
Java

package carpet.mixins;
import carpet.fakes.ThreadedAnvilChunkStorageInterface;
import carpet.helpers.TickSpeed;
import carpet.utils.CarpetProfiler;
import net.minecraft.server.world.ChunkHolder;
import net.minecraft.server.world.ServerChunkManager;
import net.minecraft.server.world.ServerWorld;
import net.minecraft.server.world.ThreadedAnvilChunkStorage;
import net.minecraft.world.chunk.WorldChunk;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.Redirect;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import java.util.Collections;
import java.util.List;
import java.util.Optional;
import com.google.common.collect.Lists;
@Mixin(ServerChunkManager.class)
public abstract class ServerChunkManager_tickMixin
{
@Shadow @Final private ServerWorld world;
@Shadow @Final
public ThreadedAnvilChunkStorage threadedAnvilChunkStorage;
CarpetProfiler.ProfilerToken currentSection;
@Inject(method = "tickChunks", at = @At("HEAD"))
private void startSpawningSection(CallbackInfo ci)
{
currentSection = CarpetProfiler.start_section(world, "Spawning and Random Ticks", CarpetProfiler.TYPE.GENERAL);
}
@Inject(method = "tickChunks", at = @At("RETURN"))
private void stopSpawningSection(CallbackInfo ci)
{
if (currentSection != null)
{
CarpetProfiler.end_current_section(currentSection);
}
}
//// Tick freeze
@Redirect(method = "tickChunks", at = @At(
value = "INVOKE",
target = "Lnet/minecraft/server/world/ServerWorld;isDebugWorld()Z"
))
private boolean skipChunkTicking(ServerWorld serverWorld)
{
boolean debug = serverWorld.isDebugWorld();
if (!TickSpeed.process_entities)
{
// simplified chunk tick iteration assuming world is frozen otherwise as suggested by Hadron67
// to be kept in sync with the original injection source
if (!debug){
List<ChunkHolder> holders = Lists.newArrayList(((ThreadedAnvilChunkStorageInterface)threadedAnvilChunkStorage).getChunks());
Collections.shuffle(holders);
for (ChunkHolder holder: holders){
Optional<WorldChunk> optional = holder.getTickingFuture().getNow(ChunkHolder.UNLOADED_WORLD_CHUNK).left();
if (optional.isPresent()){
holder.flushUpdates(optional.get());
}
}
}
return true;
}
return debug;
}
}