diff --git a/README.md b/README.md index fd96346f4..b56578d46 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,5 @@ +Port to 1.17 + # Fabric Example Mod ## Setup diff --git a/build.gradle b/build.gradle index 9a377dfdf..07df42538 100644 --- a/build.gradle +++ b/build.gradle @@ -24,9 +24,6 @@ dependencies { mappings "net.fabricmc:yarn:${project.yarn_mappings}:v2" modImplementation "net.fabricmc:fabric-loader:${project.loader_version}" - // Fabric API. This is technically optional, but you probably want it anyway. - modImplementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}" - // PSA: Some older mods, compiled on Loom 0.2.1, might have outdated Maven POMs. // You may need to force-disable transitiveness on them. } diff --git a/gradle.properties b/gradle.properties index d239f3f5d..337b94c85 100644 --- a/gradle.properties +++ b/gradle.properties @@ -3,15 +3,11 @@ org.gradle.jvmargs=-Xmx1G # Fabric Properties # check these on https://fabricmc.net/versions.html - minecraft_version=1.16.5 - yarn_mappings=1.16.5+build.9 - loader_version=0.11.3 + minecraft_version=1.17.1 + yarn_mappings=1.17.1+build.61 + loader_version=0.12.0 # Mod Properties mod_version = 1.0.0 maven_group = com.example - archives_base_name = fabric-example-mod - -# Dependencies - # currently not on the main fabric site, check on the maven: https://maven.fabricmc.net/net/fabricmc/fabric-api/fabric-api (or https://fabricmc.net/versions.html) - fabric_version=0.34.2+1.16 + archives_base_name = chunkmod diff --git a/src/main/java/net/fabricmc/example/mixin/MinecraftServerMixin.java b/src/main/java/net/fabricmc/example/mixin/MinecraftServerMixin.java new file mode 100644 index 000000000..955236e9b --- /dev/null +++ b/src/main/java/net/fabricmc/example/mixin/MinecraftServerMixin.java @@ -0,0 +1,95 @@ +package net.fabricmc.example.mixin; + +import com.google.common.collect.Maps; +import java.util.Map; +import net.minecraft.entity.boss.BossBarManager; +import net.minecraft.server.MinecraftServer; +import net.minecraft.server.PlayerManager; +import net.minecraft.server.world.ServerWorld; +import net.minecraft.util.registry.DynamicRegistryManager; +import net.minecraft.util.registry.RegistryKey; +import net.minecraft.world.level.ServerWorldProperties; +import net.minecraft.world.level.storage.LevelStorage; +import net.minecraft.world.SaveProperties; +import net.minecraft.world.World; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; +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.callback.CallbackInfo; + +@Mixin(MinecraftServer.class) +public class MinecraftServerMixin { + @Shadow + @Final + private static Logger LOGGER = LogManager.getLogger(); + + @Shadow + @Final + protected LevelStorage.Session session; + + @Shadow + protected DynamicRegistryManager.Impl registryManager; + + @Shadow + @Final + private Map, ServerWorld> worlds = Maps.newLinkedHashMap(); + + @Shadow + private PlayerManager playerManager; + + @Shadow + @Final + private BossBarManager bossBarManager = new BossBarManager(); + + @Shadow + @Final + protected SaveProperties saveProperties; + + @Inject(at = @At("TAIL"), method = "prepareStartRegion") + private void onPrepareStartRegion(CallbackInfo info) { + this.save(false,false,false); + } + + @Shadow + public boolean save(boolean bl, boolean bl2, boolean bl3) { + boolean bl4 = false; + for (ServerWorld lv : this.getWorlds()) { + if (!bl) { + LOGGER.info("Saving chunks for level '{}'/{}", (Object)lv, (Object)lv.getRegistryKey().getValue()); + } + lv.save(null, bl2, lv.savingDisabled && !bl3); + bl4 = true; + } + ServerWorld lv2 = this.getOverworld(); + ServerWorldProperties lv3 = this.saveProperties.getMainWorldProperties(); + lv3.setWorldBorder(lv2.getWorldBorder().write()); + this.saveProperties.setCustomBossEvents(this.getBossBarManager().toNbt()); + this.session.backupLevelDataFile(this.registryManager, this.saveProperties, this.getPlayerManager().getUserData()); + return bl4; + } + + @Shadow + public Iterable getWorlds() { + return this.worlds.values(); + } + + @Shadow + @Final + public ServerWorld getOverworld() { + return this.worlds.get(World.OVERWORLD); + } + + @Shadow + public PlayerManager getPlayerManager() { + return this.playerManager; + } + + @Shadow + public BossBarManager getBossBarManager() { + return this.bossBarManager; + } +} diff --git a/src/main/java/net/fabricmc/example/mixin/ServerChunkManagerMixin.java b/src/main/java/net/fabricmc/example/mixin/ServerChunkManagerMixin.java new file mode 100644 index 000000000..8efba0754 --- /dev/null +++ b/src/main/java/net/fabricmc/example/mixin/ServerChunkManagerMixin.java @@ -0,0 +1,15 @@ +package net.fabricmc.example.mixin; + +import net.minecraft.server.world.ServerChunkManager; +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; + +@Mixin({ServerChunkManager.class}) +public class ServerChunkManagerMixin { + @Inject(method = {"getTotalChunksLoadedCount"}, at = {@At("RETURN")}, cancellable = true) + private void onGetTotalChunksLoadedCount(CallbackInfoReturnable cir) { + cir.setReturnValue(Integer.valueOf(441)); + } +} diff --git a/src/main/resources/chunkmod.mixins.json b/src/main/resources/chunkmod.mixins.json new file mode 100644 index 000000000..f7f13698a --- /dev/null +++ b/src/main/resources/chunkmod.mixins.json @@ -0,0 +1,15 @@ +{ + "required": true, + "minVersion": "0.8", + "package": "net.fabricmc.example.mixin", + "compatibilityLevel": "JAVA_16", + "mixins": [ + ], + "client": [ + "MinecraftServerMixin", + "ServerChunkManagerMixin" + ], + "injectors": { + "defaultRequire": 1 + } +} diff --git a/src/main/resources/chunkmod/icon.png b/src/main/resources/chunkmod/icon.png new file mode 100644 index 000000000..047b91f23 Binary files /dev/null and b/src/main/resources/chunkmod/icon.png differ diff --git a/src/main/resources/fabric.mod.json b/src/main/resources/fabric.mod.json index df92d8b13..390b79490 100644 --- a/src/main/resources/fabric.mod.json +++ b/src/main/resources/fabric.mod.json @@ -1,37 +1,27 @@ { "schemaVersion": 1, - "id": "modid", + "id": "chunkmod", "version": "${version}", - "name": "Example Mod", - "description": "This is an example description! Tell everyone what your mod is about!", + "name": "Chunk Mod", + "description": "Allows the player to join the world during world generation.", "authors": [ - "Me!" + "mario_51" ], "contact": { - "homepage": "https://fabricmc.net/", - "sources": "https://github.com/FabricMC/fabric-example-mod" + "sources": "https://github.com/Mario0051/chunk-mod", + "issues": "https://github.com/Mario0051/chunk-mod/issues" }, - - "license": "CC0-1.0", - "icon": "assets/modid/icon.png", + + "license": "LGPL-3.0-only", + "icon": "assets/chunkmod/icon.png", "environment": "*", - "entrypoints": { - "main": [ - "net.fabricmc.example.ExampleMod" - ] - }, "mixins": [ - "modid.mixins.json" + "chunkmod.mixins.json" ], "depends": { - "fabricloader": ">=0.7.4", - "fabric": "*", - "minecraft": "1.16.x" - }, - "suggests": { - "another-mod": "*" + "minecraft": "1.17", } }