Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
Port to 1.17

# Fabric Example Mod

## Setup
Expand Down
3 changes: 0 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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.
}
Expand Down
12 changes: 4 additions & 8 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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
95 changes: 95 additions & 0 deletions src/main/java/net/fabricmc/example/mixin/MinecraftServerMixin.java
Original file line number Diff line number Diff line change
@@ -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<RegistryKey<World>, 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<ServerWorld> 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;
}
}
Original file line number Diff line number Diff line change
@@ -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<Integer> cir) {
cir.setReturnValue(Integer.valueOf(441));
}
}
15 changes: 15 additions & 0 deletions src/main/resources/chunkmod.mixins.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"required": true,
"minVersion": "0.8",
"package": "net.fabricmc.example.mixin",
"compatibilityLevel": "JAVA_16",
"mixins": [
],
"client": [
"MinecraftServerMixin",
"ServerChunkManagerMixin"
],
"injectors": {
"defaultRequire": 1
}
}
Binary file added src/main/resources/chunkmod/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
32 changes: 11 additions & 21 deletions src/main/resources/fabric.mod.json
Original file line number Diff line number Diff line change
@@ -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",
}
}