From 55bb2116f8cda684baabcd7898b2c4781c25bc0d Mon Sep 17 00:00:00 2001 From: Grider Date: Mon, 25 Jul 2022 21:23:58 +0100 Subject: [PATCH] 1.19 --- build.gradle | 4 +- gradle.properties | 6 +- .../mcmtfabric/DebugHookTerminator.java | 14 +- src/main/java/net/himeki/mcmtfabric/MCMT.java | 4 +- .../mcmtfabric/commands/ConfigCommand.java | 73 +++---- .../mcmtfabric/commands/DebugCommand.java | 195 ++++++++---------- .../mcmtfabric/commands/StatsCommand.java | 36 ++-- .../mcmtfabric/config/GeneralConfig.java | 4 +- .../ChainRestrictedNeighborUpdaterMixin.java | 22 ++ .../mcmtfabric/mixin/CheckedRandomMixin.java | 8 + .../mcmtfabric/mixin/ServerWorldMixin.java | 20 +- .../mcmtfabric/mixin/SynchronisePlugin.java | 4 +- .../himeki/mcmtfabric/mixin/WorldMixin.java | 7 +- .../parallelised/ConcurrentArrayDeque.java | 4 + .../parallelised/ParaServerChunkProvider.java | 40 ++-- src/main/resources/fabric.mod.json | 2 +- src/main/resources/mcmtfabric.accesswidener | 6 +- src/main/resources/mcmtfabric.mixins.json | 2 + 18 files changed, 224 insertions(+), 227 deletions(-) create mode 100644 src/main/java/net/himeki/mcmtfabric/mixin/ChainRestrictedNeighborUpdaterMixin.java create mode 100644 src/main/java/net/himeki/mcmtfabric/mixin/CheckedRandomMixin.java create mode 100644 src/main/java/net/himeki/mcmtfabric/parallelised/ConcurrentArrayDeque.java diff --git a/build.gradle b/build.gradle index 32f3be36..ee13028a 100644 --- a/build.gradle +++ b/build.gradle @@ -1,5 +1,5 @@ plugins { - id 'fabric-loom' version '0.10-SNAPSHOT' + id 'fabric-loom' version '0.12-SNAPSHOT' id 'maven-publish' } @@ -34,7 +34,7 @@ dependencies { // PSA: Some older mods, compiled on Loom 0.2.1, might have outdated Maven POMs. // You may need to force-disable transitiveness on them. - modImplementation "com.terraformersmc:modmenu:3.0.1" + modImplementation "com.terraformersmc:modmenu:4.0.4" implementation group: 'com.google.code.findbugs', name: 'jsr305', version: '3.0.2' modApi("me.shedaniel.cloth:cloth-config-fabric:6.2.57") { diff --git a/gradle.properties b/gradle.properties index aaf97d5a..2a4ed677 100644 --- a/gradle.properties +++ b/gradle.properties @@ -3,8 +3,8 @@ org.gradle.jvmargs=-Xmx1G # Fabric Properties # check these on https://fabricmc.net/use - minecraft_version=1.18.2 - yarn_mappings=1.18.2+build.3 + minecraft_version=1.19 + yarn_mappings=1.19+build.4 loader_version=0.14.8 # Mod Properties @@ -14,4 +14,4 @@ org.gradle.jvmargs=-Xmx1G # Dependencies # currently not on the main fabric site, check on the maven: https://maven.fabricmc.net/net/fabricmc/fabric-api/fabric-api - fabric_version=0.57.0+1.18.2 + fabric_version=0.58.0+1.19 diff --git a/src/main/java/net/himeki/mcmtfabric/DebugHookTerminator.java b/src/main/java/net/himeki/mcmtfabric/DebugHookTerminator.java index 116f7b7e..bf258222 100644 --- a/src/main/java/net/himeki/mcmtfabric/DebugHookTerminator.java +++ b/src/main/java/net/himeki/mcmtfabric/DebugHookTerminator.java @@ -1,9 +1,9 @@ package net.himeki.mcmtfabric; -import java.io.IOException; import java.util.ArrayList; import java.util.List; import java.util.concurrent.CompletableFuture; +import java.util.concurrent.ExecutionException; import java.util.concurrent.TimeoutException; import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicLong; @@ -41,7 +41,6 @@ * Handles chunk forcing in scenarios where world corruption has occured * * @author jediminer543 - * */ public class DebugHookTerminator { @@ -53,12 +52,14 @@ public static class BrokenChunkLocator { long chunkPos; CompletableFuture maincf; CompletableFuture brokecf; + public BrokenChunkLocator(long chunkPos, CompletableFuture maincf, CompletableFuture brokecf) { super(); this.chunkPos = chunkPos; this.maincf = maincf; this.brokecf = brokecf; } + public long getChunkPos() { return chunkPos; } @@ -75,8 +76,7 @@ public static boolean isBypassLoadTarget() { public static AtomicLong mainThreadChunkLoadCount = new AtomicLong(); public static String mainThread = "Server thread"; - public static void chunkLoadDrive(ServerChunkManager.MainThreadExecutor executor, BooleanSupplier isDone, ServerChunkManager scp, - CompletableFuture> completableFuture, long chunkpos) { + public static void chunkLoadDrive(ServerChunkManager.MainThreadExecutor executor, BooleanSupplier isDone, ServerChunkManager scp, CompletableFuture> completableFuture, long chunkpos) { /* if (!GeneralConfig.enableChunkTimeout) { bypassLoadTarget = false; @@ -92,7 +92,7 @@ public static void chunkLoadDrive(ServerChunkManager.MainThreadExecutor executor } while (!isDone.getAsBoolean()) { if (!executor.runTask()) { - if(isDone.getAsBoolean()) { + if (isDone.getAsBoolean()) { if (Thread.currentThread().getName().equals(mainThread)) { mainThreadChunkLoad.set(false); } @@ -131,12 +131,12 @@ public static void chunkLoadDrive(ServerChunkManager.MainThreadExecutor executor /* */ } else { try { - NbtCompound cnbt = scp.threadedAnvilChunkStorage.getNbt(new ChunkPos(chunkpos)); + NbtCompound cnbt = scp.threadedAnvilChunkStorage.getNbt(new ChunkPos(chunkpos)).get().get(); if (cnbt != null) { ProtoChunk cp = ChunkSerializer.deserialize((ServerWorld) scp.getWorld(), scp.threadedAnvilChunkStorage.pointOfInterestStorage, new ChunkPos(chunkpos), cnbt); completableFuture.complete(Either.left(new WorldChunk((ServerWorld) scp.getWorld(), cp, null))); } - } catch (IOException e) { + } catch (InterruptedException | ExecutionException e) { e.printStackTrace(); } completableFuture.complete(ChunkHolder.UNLOADED_CHUNK); diff --git a/src/main/java/net/himeki/mcmtfabric/MCMT.java b/src/main/java/net/himeki/mcmtfabric/MCMT.java index acca1589..8d1608fb 100644 --- a/src/main/java/net/himeki/mcmtfabric/MCMT.java +++ b/src/main/java/net/himeki/mcmtfabric/MCMT.java @@ -4,7 +4,7 @@ import me.shedaniel.autoconfig.ConfigHolder; import me.shedaniel.autoconfig.serializer.Toml4jConfigSerializer; import net.fabricmc.api.ModInitializer; -import net.fabricmc.fabric.api.command.v1.CommandRegistrationCallback; +import net.fabricmc.fabric.api.command.v2.CommandRegistrationCallback; import net.fabricmc.fabric.api.event.lifecycle.v1.ServerLifecycleEvents; import net.himeki.mcmtfabric.commands.ConfigCommand; import net.himeki.mcmtfabric.commands.StatsCommand; @@ -47,7 +47,7 @@ public void onInitialize() { // Listener reg begin ServerLifecycleEvents.SERVER_STARTED.register(server -> StatsCommand.resetAll()); - CommandRegistrationCallback.EVENT.register((dispatcher, dedicated) -> ConfigCommand.register(dispatcher)); + CommandRegistrationCallback.EVENT.register((dispatcher, registryAccess, environment) -> ConfigCommand.register(dispatcher)); } } diff --git a/src/main/java/net/himeki/mcmtfabric/commands/ConfigCommand.java b/src/main/java/net/himeki/mcmtfabric/commands/ConfigCommand.java index 675350d5..8ad5505d 100644 --- a/src/main/java/net/himeki/mcmtfabric/commands/ConfigCommand.java +++ b/src/main/java/net/himeki/mcmtfabric/commands/ConfigCommand.java @@ -3,7 +3,6 @@ import com.mojang.brigadier.CommandDispatcher; import com.mojang.brigadier.builder.ArgumentBuilder; import com.mojang.brigadier.builder.LiteralArgumentBuilder; -import com.mojang.brigadier.exceptions.CommandSyntaxException; import me.shedaniel.autoconfig.AutoConfig; import net.himeki.mcmtfabric.MCMT; import net.himeki.mcmtfabric.ParallelProcessor; @@ -12,7 +11,8 @@ import net.minecraft.block.entity.BlockEntity; import net.minecraft.block.entity.BlockEntityTicker; import net.minecraft.server.command.ServerCommandSource; -import net.minecraft.text.LiteralText; +import net.minecraft.text.MutableText; +import net.minecraft.text.Text; import net.minecraft.util.hit.BlockHitResult; import net.minecraft.util.hit.HitResult; import net.minecraft.util.math.BlockPos; @@ -35,38 +35,37 @@ public static void register(CommandDispatcher dispatcher) { return cmdSrc.hasPermissionLevel(2); }).executes(cmdCtx -> { config.disabled = !config.disabled; - LiteralText message = new LiteralText( + MutableText message = Text.literal( "MCMT is now " + (config.disabled ? "disabled" : "enabled")); cmdCtx.getSource().sendFeedback(message, true); return 1; }).then(literal("te").executes(cmdCtx -> { config.disableTileEntity = !config.disableTileEntity; - LiteralText message = new LiteralText("MCMT's tile entity threading is now " - + (config.disableTileEntity ? "disabled" : "enabled")) { - }; + MutableText message = Text.literal("MCMT's tile entity threading is now " + + (config.disableTileEntity ? "disabled" : "enabled")); cmdCtx.getSource().sendFeedback(message, true); return 1; })).then(literal("entity").executes(cmdCtx -> { config.disableEntity = !config.disableEntity; - LiteralText message = new LiteralText( + MutableText message = Text.literal( "MCMT's entity threading is now " + (config.disableEntity ? "disabled" : "enabled")); cmdCtx.getSource().sendFeedback(message, true); return 1; })).then(literal("environment").executes(cmdCtx -> { config.disableEnvironment = !config.disableEnvironment; - LiteralText message = new LiteralText("MCMT's environment threading is now " + MutableText message = Text.literal("MCMT's environment threading is now " + (config.disableEnvironment ? "disabled" : "enabled")); cmdCtx.getSource().sendFeedback(message, true); return 1; })).then(literal("world").executes(cmdCtx -> { config.disableWorld = !config.disableWorld; - LiteralText message = new LiteralText( + MutableText message = Text.literal( "MCMT's world threading is now " + (config.disableWorld ? "disabled" : "enabled")); cmdCtx.getSource().sendFeedback(message, true); return 1; })).then(literal("ops").executes(cmdCtx -> { config.opsTracing = !config.opsTracing; - LiteralText message = new LiteralText( + MutableText message = Text.literal( "MCMT's ops tracing is now " + (!config.opsTracing ? "disabled" : "enabled")); cmdCtx.getSource().sendFeedback(message, true); return 1; @@ -83,17 +82,17 @@ public static void register(CommandDispatcher dispatcher) { messageString.append(" Env:" + (config.disableEnvironment ? "disabled" : "enabled")); messageString.append(" SCP:" + (config.disableChunkProvider ? "disabled" : "enabled")); } - LiteralText message = new LiteralText(messageString.toString()); + MutableText message = Text.literal(messageString.toString()); cmdCtx.getSource().sendFeedback(message, true); return 1; })) .then(literal("save").requires(cmdSrc -> { return cmdSrc.hasPermissionLevel(2); }).executes(cmdCtx -> { - LiteralText message = new LiteralText("Saving MCMT config to disk..."); + MutableText message = Text.literal("Saving MCMT config to disk..."); cmdCtx.getSource().sendFeedback(message, true); AutoConfig.getConfigHolder(GeneralConfig.class).save(); - message = new LiteralText("Done!"); + message = Text.literal("Done!"); cmdCtx.getSource().sendFeedback(message, true); return 1; })) @@ -101,30 +100,26 @@ public static void register(CommandDispatcher dispatcher) { return cmdSrc.hasPermissionLevel(2); }).then(literal("list") .executes(cmdCtx -> { - LiteralText message = new LiteralText("NYI"); + MutableText message = Text.literal("NYI"); cmdCtx.getSource().sendFeedback(message, true); return 1; })).then(literal("target") .requires(cmdSrc -> { - try { - if (cmdSrc.getPlayer() != null) { - return true; - } - } catch (CommandSyntaxException e) { - e.printStackTrace(); + if (cmdSrc.getPlayer() != null) { + return true; } - LiteralText message = new LiteralText("Only runnable by player!"); + MutableText message = Text.literal("Only runnable by player!"); cmdSrc.sendError(message); return false; }).then(literal("whitelist").executes(cmdCtx -> { - LiteralText message; + MutableText message; HitResult htr = cmdCtx.getSource().getPlayer().raycast(20, 0.0F, false); if (htr.getType() == HitResult.Type.BLOCK) { BlockPos bp = ((BlockHitResult) htr).getBlockPos(); BlockEntity te = cmdCtx.getSource().getWorld().getBlockEntity(bp); if (te != null && isTickableBe(te)) { if (config.teWhiteListString.contains(te.getClass().getName())) { - message = new LiteralText("Class " + te.getClass().getName() + " already exists in TE Whitelist"); + message = Text.literal("Class " + te.getClass().getName() + " already exists in TE Whitelist"); cmdCtx.getSource().sendFeedback(message, true); return 0; } @@ -132,26 +127,26 @@ public static void register(CommandDispatcher dispatcher) { config.teWhiteListString.add(te.getClass().getName()); BlockEntityLists.teBlackList.remove(te.getClass()); config.teBlackListString.remove(te.getClass().getName()); - message = new LiteralText("Added " + te.getClass().getName() + " to TE Whitelist"); + message = Text.literal("Added " + te.getClass().getName() + " to TE Whitelist"); cmdCtx.getSource().sendFeedback(message, true); return 1; } - message = new LiteralText("That block doesn't contain a tickable TE!"); + message = Text.literal("That block doesn't contain a tickable TE!"); cmdCtx.getSource().sendError(message); return 0; } - message = new LiteralText("Only runable by player!"); + message = Text.literal("Only runable by player!"); cmdCtx.getSource().sendError(message); return 0; })).then(literal("blacklist").executes(cmdCtx -> { - LiteralText message; + MutableText message; HitResult htr = cmdCtx.getSource().getPlayer().raycast(20, 0.0F, false); if (htr.getType() == HitResult.Type.BLOCK) { BlockPos bp = ((BlockHitResult) htr).getBlockPos(); BlockEntity te = cmdCtx.getSource().getWorld().getBlockEntity(bp); if (te != null && isTickableBe(te)) { if (config.teBlackListString.contains(te.getClass().getName())) { - message = new LiteralText("Class " + te.getClass().getName() + " already exists in TE Blacklist"); + message = Text.literal("Class " + te.getClass().getName() + " already exists in TE Blacklist"); cmdCtx.getSource().sendFeedback(message, true); return 0; } @@ -159,19 +154,19 @@ public static void register(CommandDispatcher dispatcher) { config.teBlackListString.add(te.getClass().getName()); BlockEntityLists.teWhiteList.remove(te.getClass()); config.teWhiteListString.remove(te.getClass().getName()); - message = new LiteralText("Added " + te.getClass().getName() + " to TE Blacklist"); + message = Text.literal("Added " + te.getClass().getName() + " to TE Blacklist"); cmdCtx.getSource().sendFeedback(message, true); return 1; } - message = new LiteralText("That block doesn't contain a tickable TE!"); + message = Text.literal("That block doesn't contain a tickable TE!"); cmdCtx.getSource().sendError(message); return 0; } - message = new LiteralText("Only runnable by player!"); + message = Text.literal("Only runnable by player!"); cmdCtx.getSource().sendError(message); return 0; })).then(literal("remove").executes(cmdCtx -> { - LiteralText message; + MutableText message; HitResult htr = cmdCtx.getSource().getPlayer().raycast(20, 0.0F, false); if (htr.getType() == HitResult.Type.BLOCK) { BlockPos bp = ((BlockHitResult) htr).getBlockPos(); @@ -181,34 +176,34 @@ public static void register(CommandDispatcher dispatcher) { config.teBlackListString.remove(te.getClass().getName()); BlockEntityLists.teWhiteList.remove(te.getClass()); config.teWhiteListString.remove(te.getClass().getName()); - message = new LiteralText("Removed " + te.getClass().getName() + " from TE classlists"); + message = Text.literal("Removed " + te.getClass().getName() + " from TE classlists"); cmdCtx.getSource().sendFeedback(message, true); return 1; } - message = new LiteralText("That block doesn't contain a tickable TE!"); + message = Text.literal("That block doesn't contain a tickable TE!"); cmdCtx.getSource().sendError(message); return 0; } - message = new LiteralText("Only runable by player!"); + message = Text.literal("Only runable by player!"); cmdCtx.getSource().sendError(message); return 0; })).then(literal("willtick").executes(cmdCtx -> { - LiteralText message; + MutableText message; HitResult htr = cmdCtx.getSource().getPlayer().raycast(20, 0.0F, false); if (htr.getType() == HitResult.Type.BLOCK) { BlockPos bp = ((BlockHitResult) htr).getBlockPos(); BlockEntity te = cmdCtx.getSource().getWorld().getBlockEntity(bp); if (isTickableBe(te)) { boolean willSerial = ParallelProcessor.filterTE((BlockEntityTickInvoker) te); - message = new LiteralText("That TE " + (!willSerial ? "will" : "will not") + " tick fully parallelised"); + message = Text.literal("That TE " + (!willSerial ? "will" : "will not") + " tick fully parallelised"); cmdCtx.getSource().sendFeedback(message, true); return 1; } - message = new LiteralText("That block doesn't contain a tickable TE!"); + message = Text.literal("That block doesn't contain a tickable TE!"); cmdCtx.getSource().sendError(message); return 0; } - message = new LiteralText("Only runable by player!"); + message = Text.literal("Only runable by player!"); cmdCtx.getSource().sendError(message); return 0; })) diff --git a/src/main/java/net/himeki/mcmtfabric/commands/DebugCommand.java b/src/main/java/net/himeki/mcmtfabric/commands/DebugCommand.java index 8c7dca41..b22bf28d 100644 --- a/src/main/java/net/himeki/mcmtfabric/commands/DebugCommand.java +++ b/src/main/java/net/himeki/mcmtfabric/commands/DebugCommand.java @@ -1,25 +1,23 @@ package net.himeki.mcmtfabric.commands; import com.mojang.brigadier.builder.LiteralArgumentBuilder; +import com.mojang.datafixers.util.Pair; import net.minecraft.block.BlockState; import net.minecraft.block.entity.BlockEntity; import net.minecraft.command.argument.PosArgument; import net.minecraft.command.argument.Vec3ArgumentType; -import net.minecraft.entity.player.PlayerEntity; import net.minecraft.nbt.NbtCompound; -import net.minecraft.server.command.LocateCommand; import net.minecraft.server.command.ServerCommandSource; import net.minecraft.server.network.ServerPlayerEntity; import net.minecraft.server.world.ServerWorld; -import net.minecraft.tag.ConfiguredStructureFeatureTags; -import net.minecraft.tag.TagKey; -import net.minecraft.text.LiteralText; +import net.minecraft.text.MutableText; import net.minecraft.text.Text; import net.minecraft.util.math.BlockPos; import net.minecraft.util.registry.Registry; +import net.minecraft.util.registry.RegistryEntry; +import net.minecraft.util.registry.RegistryEntryList; import net.minecraft.world.chunk.BlockEntityTickInvoker; -import net.minecraft.world.gen.feature.ConfiguredStructureFeature; -import net.minecraft.world.gen.feature.StructureFeature; +import net.minecraft.world.gen.structure.Structure; import java.io.File; import java.io.IOException; @@ -28,6 +26,7 @@ import java.nio.file.Paths; import java.nio.file.StandardCopyOption; import java.util.Arrays; +import java.util.List; import java.util.Map; import java.util.UUID; import java.util.concurrent.ConcurrentHashMap; @@ -38,116 +37,103 @@ public class DebugCommand { public static LiteralArgumentBuilder registerDebug(LiteralArgumentBuilder root) { - return root.then(literal("getBlockState") - .then(argument("location", Vec3ArgumentType.vec3()).executes(cmdCtx -> { - PosArgument loc = Vec3ArgumentType.getPosArgument(cmdCtx, "location"); - BlockPos bp = loc.toAbsoluteBlockPos(cmdCtx.getSource()); - ServerWorld sw = cmdCtx.getSource().getWorld(); - BlockState bs = sw.getBlockState(bp); - LiteralText message = new LiteralText( - "Block at " + bp + " is " + bs.getBlock().getName()); - cmdCtx.getSource().sendFeedback(message, true); - System.out.println(message.toString()); - return 1; - }))).then(literal("nbtdump") - .then(argument("location", Vec3ArgumentType.vec3()).executes(cmdCtx -> { - PosArgument loc = Vec3ArgumentType.getPosArgument(cmdCtx, "location"); - BlockPos bp = loc.toAbsoluteBlockPos(cmdCtx.getSource()); - ServerWorld sw = cmdCtx.getSource().getWorld(); - BlockState bs = sw.getBlockState(bp); - BlockEntity te = sw.getBlockEntity(bp); - if (te == null) { - LiteralText message = new LiteralText( - "Block at " + bp + " is " + bs.getBlock().getName() + " has no NBT"); - cmdCtx.getSource().sendFeedback(message, true); - return 1; - } - NbtCompound nbt = te.toInitialChunkDataNbt(); - String nbtStr = nbt.toString(); - LiteralText message = new LiteralText( - "Block at " + bp + " is " + bs.getBlock().getName() + " with TE NBT:"); - cmdCtx.getSource().sendFeedback(message, true); - cmdCtx.getSource().sendFeedback(Text.of(nbtStr), true); - //System.out.println(message.toString()); - return 1; - }))).then(literal("tick").requires(cmdSrc -> { - return cmdSrc.hasPermissionLevel(2); - }).then(literal("te")) - .then(argument("location", Vec3ArgumentType.vec3()).executes(cmdCtx -> { - PosArgument loc = Vec3ArgumentType.getPosArgument(cmdCtx, "location"); - BlockPos bp = loc.toAbsoluteBlockPos(cmdCtx.getSource()); - ServerWorld sw = cmdCtx.getSource().getWorld(); - BlockEntity te = sw.getBlockEntity(bp); - if (te != null && ConfigCommand.isTickableBe(te)) { - ((BlockEntityTickInvoker) te).tick(); - LiteralText message = new LiteralText( - "Ticked " + te.getClass().getName() + " at " + bp); - cmdCtx.getSource().sendFeedback(message, true); - } else { - LiteralText message = new LiteralText("No tickable TE at " + bp); - cmdCtx.getSource().sendError(message); - } - return 1; - }))) - .then(literal("classpathDump").requires(cmdSrc -> { - return cmdSrc.hasPermissionLevel(2); - }).executes(cmdCtx -> { - java.nio.file.Path base = Paths.get("classpath_dump/"); - try { - Files.createDirectories(base); - } catch (IOException e1) { - e1.printStackTrace(); - } - // Copypasta from syncfu; - Arrays.stream(System.getProperty("java.class.path").split(File.pathSeparator)).flatMap(path -> { - File file = new File(path); - if (file.isDirectory()) { - return Arrays.stream(file.list((d, n) -> n.endsWith(".jar"))); - } - return Arrays.stream(new String[]{path}); - }).filter(s -> s.endsWith(".jar")) - .map(Paths::get).forEach(path -> { - Path name = path.getFileName(); - try { - Files.copy(path, Paths.get(base.toString(), name.toString()), StandardCopyOption.REPLACE_EXISTING); - } catch (IOException e) { - e.printStackTrace(); - } - }); + return root.then(literal("getBlockState").then(argument("location", Vec3ArgumentType.vec3()).executes(cmdCtx -> { + PosArgument loc = Vec3ArgumentType.getPosArgument(cmdCtx, "location"); + BlockPos bp = loc.toAbsoluteBlockPos(cmdCtx.getSource()); + ServerWorld sw = cmdCtx.getSource().getWorld(); + BlockState bs = sw.getBlockState(bp); + MutableText message = Text.literal("Block at " + bp + " is " + bs.getBlock().getName()); + cmdCtx.getSource().sendFeedback(message, true); + System.out.println(message); + return 1; + }))).then(literal("nbtdump").then(argument("location", Vec3ArgumentType.vec3()).executes(cmdCtx -> { + PosArgument loc = Vec3ArgumentType.getPosArgument(cmdCtx, "location"); + BlockPos bp = loc.toAbsoluteBlockPos(cmdCtx.getSource()); + ServerWorld sw = cmdCtx.getSource().getWorld(); + BlockState bs = sw.getBlockState(bp); + BlockEntity te = sw.getBlockEntity(bp); + if (te == null) { + MutableText message = Text.literal("Block at " + bp + " is " + bs.getBlock().getName() + " has no NBT"); + cmdCtx.getSource().sendFeedback(message, true); + return 1; + } + NbtCompound nbt = te.toInitialChunkDataNbt(); + String nbtStr = nbt.toString(); + MutableText message = Text.literal("Block at " + bp + " is " + bs.getBlock().getName() + " with TE NBT:"); + cmdCtx.getSource().sendFeedback(message, true); + cmdCtx.getSource().sendFeedback(Text.of(nbtStr), true); + return 1; + }))).then(literal("tick").requires(cmdSrc -> cmdSrc.hasPermissionLevel(2)).then(literal("te")).then(argument("location", Vec3ArgumentType.vec3()).executes(cmdCtx -> { + PosArgument loc = Vec3ArgumentType.getPosArgument(cmdCtx, "location"); + BlockPos bp = loc.toAbsoluteBlockPos(cmdCtx.getSource()); + ServerWorld sw = cmdCtx.getSource().getWorld(); + BlockEntity te = sw.getBlockEntity(bp); + if (te != null && ConfigCommand.isTickableBe(te)) { + ((BlockEntityTickInvoker) te).tick(); + MutableText message = Text.literal("Ticked " + te.getClass().getName() + " at " + bp); + cmdCtx.getSource().sendFeedback(message, true); + } else { + MutableText message = Text.literal("No tickable TE at " + bp); + cmdCtx.getSource().sendError(message); + } + return 1; + }))).then(literal("classpathDump").requires(cmdSrc -> cmdSrc.hasPermissionLevel(2)).executes(cmdCtx -> { + java.nio.file.Path base = Paths.get("classpath_dump/"); + try { + Files.createDirectories(base); + } catch (IOException e1) { + e1.printStackTrace(); + } + // Copypasta from syncfu; + Arrays.stream(System.getProperty("java.class.path").split(File.pathSeparator)).flatMap(path -> { + File file = new File(path); + if (file.isDirectory()) { + return Arrays.stream(file.list((d, n) -> n.endsWith(".jar"))); + } + return Arrays.stream(new String[]{path}); + }).filter(s -> s.endsWith(".jar")).map(Paths::get).forEach(path -> { + Path name = path.getFileName(); + try { + Files.copy(path, Paths.get(base.toString(), name.toString()), StandardCopyOption.REPLACE_EXISTING); + } catch (IOException e) { + e.printStackTrace(); + } + }); - LiteralText message = new LiteralText("Classpath Dumped to: " + base.toAbsolutePath().toString()); - cmdCtx.getSource().sendFeedback(message, true); - System.out.println(message.toString()); - return 1; - })) - /* 1.16.1 code; AKA the only thing that changed */ - .then(literal("test").requires(cmdSrc -> { - return cmdSrc.hasPermissionLevel(2); - })/*.then(literal("structures").executes(cmdCtx -> { + MutableText message = Text.literal("Classpath Dumped to: " + base.toAbsolutePath().toString()); + cmdCtx.getSource().sendFeedback(message, true); + System.out.println(message); + return 1; + })) + /* 1.16.1 code; AKA the only thing that changed */.then(literal("test").requires(cmdSrc -> cmdSrc.hasPermissionLevel(2)).then(literal("structures").executes(cmdCtx -> { ServerPlayerEntity p = cmdCtx.getSource().getPlayer(); + assert p != null; BlockPos srcPos = p.getBlockPos(); - UUID id = PlayerEntity.getUuidFromProfile(p.getGameProfile()); + UUID id = p.getUuid(); int index = structureIdx.computeIfAbsent(id.toString(), (s) -> new AtomicInteger()).getAndIncrement(); - StructureFeature[] targets = Registry.STRUCTURE_FEATURE.getEntrySet().toArray(new StructureFeature[10]); - StructureFeature target = null; - if (index >= targets.length) { - target = targets[0]; + Registry registry = cmdCtx.getSource().getWorld().getRegistryManager().get(Registry.STRUCTURE_KEY); + List> targets = registry.streamEntries().toList(); + RegistryEntry.Reference target; + if (index >= targets.size()) { + target = targets.get(0); structureIdx.computeIfAbsent(id.toString(), (s) -> new AtomicInteger()).set(0); } else { - target = targets[index]; + target = targets.get(index); } - BlockPos dst = cmdCtx.getSource().getWorld().locateStructure(ConfiguredStructureFeatureTags.of(target.toString()), srcPos, 100, false); + Pair> dst = cmdCtx.getSource().getWorld().getChunkManager().getChunkGenerator().locateStructure(cmdCtx.getSource().getWorld(), RegistryEntryList.of(target), srcPos, 100, false); if (dst == null) { - LiteralText message = new LiteralText("Failed locating " + target + " from " + srcPos); + MutableText message = Text.literal("Failed locating " + target.registryKey().getValue().toString() + " from " + srcPos); cmdCtx.getSource().sendFeedback(message, true); return 1; } - p.teleport(dst.getX(), srcPos.getY(), dst.getZ()); - LocateCommand.sendCoordinates(cmdCtx.getSource(), target, srcPos, dst, "commands.locate.success"); + MutableText message = Text.literal("Found target; loading now"); + cmdCtx.getSource().sendFeedback(message, true); + p.teleport(dst.getFirst().getX(), srcPos.getY(), dst.getFirst().getZ()); + //LocateCommand.showLocateResult(cmdCtx.getSource(), ResourceOrTagLocationArgument.getStructureFeature(p_207508_, "structure"), srcpos, dst, "commands.locate.success"); return 1; - })))*/ - /* */ + }))); + /* */ /* .then(literal("goinf").requires(cmdSrc -> { return cmdSrc.hasPermissionLevel(2); @@ -157,7 +143,6 @@ public static LiteralArgumentBuilder registerDebug(LiteralA return 1; })) */ - ); } private static Map structureIdx = new ConcurrentHashMap<>(); diff --git a/src/main/java/net/himeki/mcmtfabric/commands/StatsCommand.java b/src/main/java/net/himeki/mcmtfabric/commands/StatsCommand.java index 89652f75..acebe25f 100644 --- a/src/main/java/net/himeki/mcmtfabric/commands/StatsCommand.java +++ b/src/main/java/net/himeki/mcmtfabric/commands/StatsCommand.java @@ -1,13 +1,13 @@ package net.himeki.mcmtfabric.commands; import com.mojang.brigadier.builder.LiteralArgumentBuilder; -import me.shedaniel.autoconfig.AutoConfig; import net.himeki.mcmtfabric.MCMT; import net.himeki.mcmtfabric.ParallelProcessor; import net.himeki.mcmtfabric.config.GeneralConfig; import net.minecraft.server.MinecraftServer; import net.minecraft.server.command.ServerCommandSource; -import net.minecraft.text.LiteralText; +import net.minecraft.text.MutableText; +import net.minecraft.text.Text; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; @@ -24,37 +24,29 @@ public static LiteralArgumentBuilder registerStatus(Literal return 1; })).executes(cmdCtx -> { if (!threadStats) { - LiteralText message = new LiteralText("Stat calcs are disabled so stats are out of date"); + MutableText message = Text.literal("Stat calcs are disabled so stats are out of date"); cmdCtx.getSource().sendFeedback(message, true); } - StringBuilder messageString = new StringBuilder( - "Current max threads " + mean(maxThreads, liveValues) + " ("); + StringBuilder messageString = new StringBuilder("Current max threads " + mean(maxThreads, liveValues) + " ("); messageString.append("World:" + mean(maxWorlds, liveValues)); messageString.append(" Entity:" + mean(maxEntities, liveValues)); messageString.append(" TE:" + mean(maxTEs, liveValues)); messageString.append(" Env:" + mean(maxEnvs, liveValues) + ")"); - LiteralText message = new LiteralText(messageString.toString()); + MutableText message = Text.literal(messageString.toString()); cmdCtx.getSource().sendFeedback(message, true); return 1; - }).then(literal("toggle").requires(cmdSrc -> { - return cmdSrc.hasPermissionLevel(2); - }).executes(cmdCtx -> { + }).then(literal("toggle").requires(cmdSrc -> cmdSrc.hasPermissionLevel(2)).executes(cmdCtx -> { threadStats = !threadStats; - LiteralText message = new LiteralText("Stat calcs are " + - (!threadStats ? "disabled" : "enabled") + "!"); + MutableText message = Text.literal("Stat calcs are " + (!threadStats ? "disabled" : "enabled") + "!"); cmdCtx.getSource().sendFeedback(message, true); return 1; - })).then(literal("startlog").requires(cmdSrc -> { - return cmdSrc.hasPermissionLevel(2); - }).executes(cmdCtx -> { + })).then(literal("startlog").requires(cmdSrc -> cmdSrc.hasPermissionLevel(2)).executes(cmdCtx -> { doLogging = true; - LiteralText message = new LiteralText("Logging started!"); + MutableText message = Text.literal("Logging started!"); cmdCtx.getSource().sendFeedback(message, true); return 1; - })).then(literal("stoplog").requires(cmdSrc -> { - return cmdSrc.hasPermissionLevel(2); - }).executes(cmdCtx -> { - LiteralText message = new LiteralText("Logging stopping..."); + })).then(literal("stoplog").requires(cmdSrc -> cmdSrc.hasPermissionLevel(2)).executes(cmdCtx -> { + MutableText message = Text.literal("Logging stopping..."); cmdCtx.getSource().sendFeedback(message, true); doLogging = false; return 1; @@ -149,13 +141,11 @@ public static void runDataThread() { } int total = 0; int worlds = ParallelProcessor.currentWorlds.get(); - maxWorlds[currentPos] = Math.max(maxWorlds[currentPos], - worlds); + maxWorlds[currentPos] = Math.max(maxWorlds[currentPos], worlds); int tes = ParallelProcessor.currentTEs.get(); maxTEs[currentPos] = Math.max(maxTEs[currentPos], tes); int entities = ParallelProcessor.currentEnts.get(); - maxEntities[currentPos] = Math.max(maxEntities[currentPos], - entities); + maxEntities[currentPos] = Math.max(maxEntities[currentPos], entities); int envs = ParallelProcessor.currentEnvs.get(); maxEnvs[currentPos] = Math.max(maxEnvs[currentPos], envs); total = worlds + tes + entities + envs; diff --git a/src/main/java/net/himeki/mcmtfabric/config/GeneralConfig.java b/src/main/java/net/himeki/mcmtfabric/config/GeneralConfig.java index 01f7718e..4bb5872d 100644 --- a/src/main/java/net/himeki/mcmtfabric/config/GeneralConfig.java +++ b/src/main/java/net/himeki/mcmtfabric/config/GeneralConfig.java @@ -114,10 +114,10 @@ public enum ParaMaxMode { @Override public void validatePostLoad() throws ValidationException { - if (paraMax >= -1 && paraMax <= Integer.MAX_VALUE) + if (paraMax >= -1) if (paraMaxMode == ParaMaxMode.Standard || paraMaxMode == ParaMaxMode.Override || paraMaxMode == ParaMaxMode.Reduction) if (timeoutCount >= 500 && timeoutCount <= 500000) - if (logCap >= 15000 && logCap <= Integer.MAX_VALUE) + if (logCap >= 15000) return; throw new ValidationException("Failed to validate MCMT config."); } diff --git a/src/main/java/net/himeki/mcmtfabric/mixin/ChainRestrictedNeighborUpdaterMixin.java b/src/main/java/net/himeki/mcmtfabric/mixin/ChainRestrictedNeighborUpdaterMixin.java new file mode 100644 index 00000000..a9152633 --- /dev/null +++ b/src/main/java/net/himeki/mcmtfabric/mixin/ChainRestrictedNeighborUpdaterMixin.java @@ -0,0 +1,22 @@ +package net.himeki.mcmtfabric.mixin; + +import net.minecraft.world.block.ChainRestrictedNeighborUpdater; +import net.minecraft.world.block.NeighborUpdater; +import org.spongepowered.asm.mixin.Final; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Mutable; +import org.spongepowered.asm.mixin.Shadow; + +import java.util.List; +import java.util.concurrent.CopyOnWriteArrayList; + +@Mixin(ChainRestrictedNeighborUpdater.class) +public abstract class ChainRestrictedNeighborUpdaterMixin implements NeighborUpdater { + + @Shadow + @Final + @Mutable + List pending = new CopyOnWriteArrayList<>(); + + +} diff --git a/src/main/java/net/himeki/mcmtfabric/mixin/CheckedRandomMixin.java b/src/main/java/net/himeki/mcmtfabric/mixin/CheckedRandomMixin.java new file mode 100644 index 00000000..f050acd8 --- /dev/null +++ b/src/main/java/net/himeki/mcmtfabric/mixin/CheckedRandomMixin.java @@ -0,0 +1,8 @@ +package net.himeki.mcmtfabric.mixin; + +import net.minecraft.util.math.random.CheckedRandom; +import org.spongepowered.asm.mixin.Mixin; + +@Mixin(CheckedRandom.class) +public abstract class CheckedRandomMixin { +} diff --git a/src/main/java/net/himeki/mcmtfabric/mixin/ServerWorldMixin.java b/src/main/java/net/himeki/mcmtfabric/mixin/ServerWorldMixin.java index c6dcac1e..70e79822 100644 --- a/src/main/java/net/himeki/mcmtfabric/mixin/ServerWorldMixin.java +++ b/src/main/java/net/himeki/mcmtfabric/mixin/ServerWorldMixin.java @@ -11,16 +11,10 @@ import net.minecraft.server.world.BlockEvent; import net.minecraft.server.world.ServerChunkManager; import net.minecraft.server.world.ServerWorld; -import net.minecraft.structure.StructureManager; +import net.minecraft.structure.StructureTemplateManager; import net.minecraft.util.profiler.Profiler; -import net.minecraft.util.registry.RegistryEntry; -import net.minecraft.util.registry.RegistryKey; -import net.minecraft.world.EntityList; -import net.minecraft.world.MutableWorldProperties; -import net.minecraft.world.StructureWorldAccess; -import net.minecraft.world.World; +import net.minecraft.world.*; import net.minecraft.world.chunk.ChunkStatusChangeListener; -import net.minecraft.world.dimension.DimensionType; import net.minecraft.world.gen.chunk.ChunkGenerator; import net.minecraft.world.level.storage.LevelStorage; import org.objectweb.asm.Opcodes; @@ -45,11 +39,7 @@ import java.util.function.Supplier; @Mixin(ServerWorld.class) -public abstract class ServerWorldMixin extends World implements StructureWorldAccess { - - protected ServerWorldMixin(MutableWorldProperties properties, RegistryKey registryRef, RegistryEntry registryEntry, Supplier profiler, boolean isClient, boolean debugWorld, long seed) { - super(properties, registryRef, registryEntry, profiler, isClient, debugWorld, seed); - } +public abstract class ServerWorldMixin implements StructureWorldAccess { ConcurrentLinkedDeque syncedBlockEventCLinkedQueue = new ConcurrentLinkedDeque(); @@ -69,8 +59,8 @@ protected ServerWorldMixin(MutableWorldProperties properties, RegistryKey ServerWorld thisWorld = (ServerWorld) (Object) this; @Redirect(method = "", at = @At(value = "NEW", target = "net/minecraft/server/world/ServerChunkManager")) - private ServerChunkManager overwriteServerChunkManager(ServerWorld world, LevelStorage.Session session, DataFixer dataFixer, StructureManager structureManager, Executor workerExecutor, ChunkGenerator chunkGenerator, int viewDistance, int simulationDistance, boolean dsync, WorldGenerationProgressListener worldGenerationProgressListener, ChunkStatusChangeListener chunkStatusChangeListener, Supplier persistentStateManagerFactory) { - return new ParaServerChunkProvider(world, session, dataFixer, structureManager, workerExecutor, chunkGenerator, viewDistance, simulationDistance, dsync, worldGenerationProgressListener, chunkStatusChangeListener, persistentStateManagerFactory); + private ServerChunkManager overwriteServerChunkManager(ServerWorld world, LevelStorage.Session session, DataFixer dataFixer, StructureTemplateManager structureTemplateManager, Executor workerExecutor, ChunkGenerator chunkGenerator, int viewDistance, int simulationDistance, boolean dsync, WorldGenerationProgressListener worldGenerationProgressListener, ChunkStatusChangeListener chunkStatusChangeListener, Supplier persistentStateManagerFactory) { + return new ParaServerChunkProvider(world, session, dataFixer, structureTemplateManager, workerExecutor, chunkGenerator, viewDistance, simulationDistance, dsync, worldGenerationProgressListener, chunkStatusChangeListener, persistentStateManagerFactory); } @Inject(method = "tick", at = @At(value = "INVOKE", target = "Lnet/minecraft/util/profiler/Profiler;swap(Ljava/lang/String;)V", ordinal = 5)) diff --git a/src/main/java/net/himeki/mcmtfabric/mixin/SynchronisePlugin.java b/src/main/java/net/himeki/mcmtfabric/mixin/SynchronisePlugin.java index 894fd80f..4b4d4338 100644 --- a/src/main/java/net/himeki/mcmtfabric/mixin/SynchronisePlugin.java +++ b/src/main/java/net/himeki/mcmtfabric/mixin/SynchronisePlugin.java @@ -24,7 +24,7 @@ public class SynchronisePlugin implements IMixinConfigPlugin { @Override public void onLoad(String mixinPackage) { -// MappingResolver mappingResolver = FabricLoader.getInstance().getMappingResolver(); + MappingResolver mappingResolver = FabricLoader.getInstance().getMappingResolver(); // mixin2MethodsMap.put("net.himeki.mcmtfabric.mixin.ServerChunkManagerMixin", mappingResolver.mapMethodName("intermediary", "net.minecraft.class_3215", "method_14161", "()V")); // mixin2MethodsMap.put("net.himeki.mcmtfabric.mixin.ServerTickSchedulerMixin", mappingResolver.mapMethodName("intermediary", "net.minecraft.class_1949", "method_8670", "()V")); // mixin2MethodsMap.put("net.himeki.mcmtfabric.mixin.ServerTickSchedulerMixin", mappingResolver.mapMethodName("intermediary", "net.minecraft.class_1949", "method_20514", "(Lnet/minecraft/class_1954;)V")); @@ -32,11 +32,13 @@ public void onLoad(String mixinPackage) { // mixin2MethodsMap.put("net.himeki.mcmtfabric.mixin.ServerWorldMixin", mappingResolver.mapMethodName("intermediary", "net.minecraft.class_1937", "method_19282", "(Lnet/minecraft/class_2338;Lnet/minecraft/class_2680;Lnet/minecraft/class_2680;)V")); // mixin2MethodsMap.put("net.himeki.mcmtfabric.mixin.LevelPropagatorMixin", mappingResolver.mapMethodName("intermediary", "net.minecraft.class_3554", "method_15492", "(I)I")); // mixin2MethodsMap.put("net.himeki.mcmtfabric.mixin.LevelPropagatorMixin", mappingResolver.mapMethodName("intermediary", "net.minecraft.class_3554", "method_15478", "(JJIZ)V")); + mixin2MethodsMap.put("net.himeki.mcmtfabric.mixin.ChainRestrictedNeighborUpdaterMixin", mappingResolver.mapMethodName("intermediary", "net.minecraft.class_7159", "method_41706", "(Lnet/minecraft/class_2338;Lnet/minecraft/class_7159$class_7162;)V")); syncAllSet.add("net.himeki.mcmtfabric.mixin.FastUtilsMixin"); syncAllSet.add("net.himeki.mcmtfabric.mixin.SyncAllMixin"); + syncAllSet.add("net.himeki.mcmtfabric.mixin.CheckedRandomMixin"); // For some reason the mapping does not cover next() so sync all for now } diff --git a/src/main/java/net/himeki/mcmtfabric/mixin/WorldMixin.java b/src/main/java/net/himeki/mcmtfabric/mixin/WorldMixin.java index 6c47bcc4..18784a14 100644 --- a/src/main/java/net/himeki/mcmtfabric/mixin/WorldMixin.java +++ b/src/main/java/net/himeki/mcmtfabric/mixin/WorldMixin.java @@ -2,6 +2,7 @@ import net.himeki.mcmtfabric.ParallelProcessor; import net.minecraft.server.world.ServerWorld; +import net.minecraft.util.math.BlockPos; import net.minecraft.world.World; import net.minecraft.world.WorldAccess; import net.minecraft.world.chunk.BlockEntityTickInvoker; @@ -47,9 +48,9 @@ private boolean continueToArrivePhaser0(BlockEntityTickInvoker instance) { return bl; } - @Redirect(method = "tickBlockEntities", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/World;shouldTickBlocksInChunk(J)Z")) - private boolean continueToArrivePhaser1(World instance, long chunkPos) { - boolean bl = instance.shouldTickBlocksInChunk(chunkPos); + @Redirect(method = "tickBlockEntities", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/World;shouldTickBlockPos(Lnet/minecraft/util/math/BlockPos;)Z")) + private boolean continueToArrivePhaser1(World instance, BlockPos pos) { + boolean bl = instance.shouldTickBlockPos(pos); if ((Object) this instanceof ServerWorld) { if (!bl) { ParallelProcessor.arriveBlockEntityPhaser((ServerWorld) (Object) this); diff --git a/src/main/java/net/himeki/mcmtfabric/parallelised/ConcurrentArrayDeque.java b/src/main/java/net/himeki/mcmtfabric/parallelised/ConcurrentArrayDeque.java new file mode 100644 index 00000000..3c29129d --- /dev/null +++ b/src/main/java/net/himeki/mcmtfabric/parallelised/ConcurrentArrayDeque.java @@ -0,0 +1,4 @@ +package net.himeki.mcmtfabric.parallelised; + +public class ConcurrentArrayDeque { +} diff --git a/src/main/java/net/himeki/mcmtfabric/parallelised/ParaServerChunkProvider.java b/src/main/java/net/himeki/mcmtfabric/parallelised/ParaServerChunkProvider.java index 6b11375a..910200ff 100644 --- a/src/main/java/net/himeki/mcmtfabric/parallelised/ParaServerChunkProvider.java +++ b/src/main/java/net/himeki/mcmtfabric/parallelised/ParaServerChunkProvider.java @@ -1,14 +1,12 @@ package net.himeki.mcmtfabric.parallelised; import com.mojang.datafixers.DataFixer; -import me.shedaniel.autoconfig.AutoConfig; import net.himeki.mcmtfabric.MCMT; import net.himeki.mcmtfabric.ParallelProcessor; -import net.himeki.mcmtfabric.config.GeneralConfig; import net.minecraft.server.WorldGenerationProgressListener; import net.minecraft.server.world.ServerChunkManager; import net.minecraft.server.world.ServerWorld; -import net.minecraft.structure.StructureManager; +import net.minecraft.structure.StructureTemplateManager; import net.minecraft.util.math.ChunkPos; import net.minecraft.world.PersistentStateManager; import net.minecraft.world.World; @@ -57,8 +55,8 @@ public class ParaServerChunkProvider extends ServerChunkManager { private final World world; /* 1.16.1 code; AKA the only thing that changed */ - public ParaServerChunkProvider(ServerWorld world, LevelStorage.Session session, DataFixer dataFixer, StructureManager structureManager, Executor workerExecutor, ChunkGenerator chunkGenerator, int viewDistance, int simulationDistance, boolean dsync, WorldGenerationProgressListener worldGenerationProgressListener, ChunkStatusChangeListener chunkStatusChangeListener, Supplier persistentStateManagerFactory) { - super(world,session,dataFixer,structureManager,workerExecutor,chunkGenerator,viewDistance,simulationDistance,dsync,worldGenerationProgressListener, chunkStatusChangeListener,persistentStateManagerFactory); + public ParaServerChunkProvider(ServerWorld world, LevelStorage.Session session, DataFixer dataFixer, StructureTemplateManager structureManager, Executor workerExecutor, ChunkGenerator chunkGenerator, int viewDistance, int simulationDistance, boolean dsync, WorldGenerationProgressListener worldGenerationProgressListener, ChunkStatusChangeListener chunkStatusChangeListener, Supplier persistentStateManagerFactory) { + super(world, session, dataFixer, structureManager, workerExecutor, chunkGenerator, viewDistance, simulationDistance, dsync, worldGenerationProgressListener, chunkStatusChangeListener, persistentStateManagerFactory); this.world = world; cacheThread = new Thread(this::chunkCacheCleanup, "Chunk Cache Cleaner " + world.getRegistryKey().getValue().getPath()); cacheThread.start(); @@ -140,7 +138,7 @@ public Chunk getChunk(int chunkX, int chunkZ, ChunkStatus requiredStatus, boolea public Chunk lookupChunk(long chunkPos, ChunkStatus status, boolean compute) { int oldAccess = access.getAndIncrement(); if (access.get() < oldAccess) { // overflow - clearCache(); + clearCache(); return null; } ChunkCacheLine ccl; @@ -156,7 +154,7 @@ public Chunk lookupChunk(long chunkPos, ChunkStatus status, boolean compute) { public void cacheChunk(long chunkPos, Chunk chunk, ChunkStatus status) { long oldAccess = access.getAndIncrement(); if (access.get() < oldAccess) { // overflow - clearCache(); + clearCache(); } ChunkCacheLine ccl; @@ -184,17 +182,17 @@ public void chunkCacheCleanup() { e.printStackTrace(); } - clearCache(); + clearCache(); } log.debug(chunkCleaner, "ChunkCleaner terminating"); } public void clearCache() { - //log.info("Clearing Chunk Cache; Size: " + chunkCache.size()); + //log.info("Clearing Chunk Cache; Size: " + chunkCache.size()); chunkCache.clear(); // Doesn't resize but that's typically good } - protected class ChunkCacheAddress { + protected class ChunkCacheAddress { protected long chunk_pos; protected int status; protected int hash; @@ -208,24 +206,24 @@ public ChunkCacheAddress(long chunk_pos, ChunkStatus status) { @Override public int hashCode() { - return hash; + return hash; } @Override public boolean equals(Object obj) { - return (obj instanceof ChunkCacheAddress) - && ((ChunkCacheAddress) obj).status == this.status - && ((ChunkCacheAddress) obj).chunk_pos == this.chunk_pos; + return (obj instanceof ChunkCacheAddress) + && ((ChunkCacheAddress) obj).status == this.status + && ((ChunkCacheAddress) obj).chunk_pos == this.chunk_pos; } public int makeHash(long chunk_pos, int status) { - int hash = HASH_INIT; - hash ^= status; - for (int b = 56; b >= 0; b -= 8) { - hash ^= (chunk_pos >> b) & 0xff; - hash *= HASH_PRIME; - } - return hash; + int hash = HASH_INIT; + hash ^= status; + for (int b = 56; b >= 0; b -= 8) { + hash ^= (chunk_pos >> b) & 0xff; + hash *= HASH_PRIME; + } + return hash; } } diff --git a/src/main/resources/fabric.mod.json b/src/main/resources/fabric.mod.json index be746e08..94a3b224 100644 --- a/src/main/resources/fabric.mod.json +++ b/src/main/resources/fabric.mod.json @@ -29,7 +29,7 @@ "depends": { "fabricloader": ">=0.11.3", "fabric": "*", - "minecraft": "1.18.x", + "minecraft": "1.19.x", "java": ">=16", "cloth-config2": ">=5.0.34" }, diff --git a/src/main/resources/mcmtfabric.accesswidener b/src/main/resources/mcmtfabric.accesswidener index 66bd69f0..9a889afd 100644 --- a/src/main/resources/mcmtfabric.accesswidener +++ b/src/main/resources/mcmtfabric.accesswidener @@ -1,16 +1,16 @@ accessWidener v1 named Accessible field net/minecraft/server/world/ServerChunkManager mainThreadExecutor Lnet/minecraft/server/world/ServerChunkManager$MainThreadExecutor; Accessible field net/minecraft/server/world/ThreadedAnvilChunkStorage pointOfInterestStorage Lnet/minecraft/world/poi/PointOfInterestStorage; -Accessible field net/minecraft/server/world/ThreadedAnvilChunkStorage structureManager Lnet/minecraft/structure/StructureManager; +Accessible field net/minecraft/server/world/ThreadedAnvilChunkStorage structureTemplateManager Lnet/minecraft/structure/StructureTemplateManager; Accessible field net/minecraft/world/chunk/WorldChunk$WrappedBlockEntityTickInvoker wrapped Lnet/minecraft/world/chunk/BlockEntityTickInvoker; Accessible field net/minecraft/world/chunk/WorldChunk$DirectBlockEntityTickInvoker blockEntity Lnet/minecraft/block/entity/BlockEntity; Accessible method net/minecraft/server/world/ServerWorld processBlockEvent (Lnet/minecraft/server/world/BlockEvent;)Z Accessible method net/minecraft/server/world/ServerChunkManager getChunkHolder (J)Lnet/minecraft/server/world/ChunkHolder; Accessible method net/minecraft/server/world/ServerChunkManager$MainThreadExecutor runTask ()Z -Accessible method net/minecraft/tag/ConfiguredStructureFeatureTags of (Ljava/lang/String;)Lnet/minecraft/tag/TagKey; Accessible method net/minecraft/world/World tickBlockEntities ()V Accessible method net/minecraft/server/world/ThreadedAnvilChunkStorage shouldTick (Lnet/minecraft/util/math/ChunkPos;)Z Accessible class net/minecraft/server/world/ThreadedAnvilChunkStorage$EntityTracker Accessible class net/minecraft/server/world/ServerChunkManager$ChunkWithHolder Accessible class net/minecraft/world/chunk/WorldChunk$WrappedBlockEntityTickInvoker -Accessible class net/minecraft/world/chunk/WorldChunk$DirectBlockEntityTickInvoker \ No newline at end of file +Accessible class net/minecraft/world/chunk/WorldChunk$DirectBlockEntityTickInvoker +Accessible class net/minecraft/world/block/ChainRestrictedNeighborUpdater$Entry \ No newline at end of file diff --git a/src/main/resources/mcmtfabric.mixins.json b/src/main/resources/mcmtfabric.mixins.json index 33ad690e..53b6b767 100644 --- a/src/main/resources/mcmtfabric.mixins.json +++ b/src/main/resources/mcmtfabric.mixins.json @@ -4,6 +4,8 @@ "package": "net.himeki.mcmtfabric.mixin", "compatibilityLevel": "JAVA_16", "mixins": [ + "ChainRestrictedNeighborUpdaterMixin", + "CheckedRandomMixin", "ChunkHolderMixin", "ChunkMixin", "ChunkTicketManagerMixin",