-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement server data pack installing
- Loading branch information
1 parent
1c72eed
commit 85d7490
Showing
4 changed files
with
41 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
src/main/java/ml/unbreakinggold/datapackinstaller/mixin/server/ServerMainMixin.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,40 @@ | ||
package ml.unbreakinggold.datapackinstaller.mixin.server; | ||
|
||
import com.llamalad7.mixinextras.sugar.Local; | ||
import ml.unbreakinggold.datapackinstaller.server.DatapackInstallerServer; | ||
import net.fabricmc.api.EnvType; | ||
import net.fabricmc.api.Environment; | ||
import net.minecraft.server.Main; | ||
import net.minecraft.util.WorldSavePath; | ||
import net.minecraft.world.level.storage.LevelStorage; | ||
import org.apache.commons.io.FileUtils; | ||
import org.apache.logging.log4j.LogManager; | ||
import org.apache.logging.log4j.Logger; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.Unique; | ||
import org.spongepowered.asm.mixin.injection.At; | ||
import org.spongepowered.asm.mixin.injection.Inject; | ||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; | ||
|
||
import java.io.File; | ||
import java.io.IOException; | ||
import java.nio.file.Path; | ||
|
||
@Mixin(Main.class) | ||
@Environment(EnvType.SERVER) | ||
public class ServerMainMixin { | ||
@Unique | ||
private static final Logger LOGGER = LogManager.getLogger(ServerMainMixin.class); | ||
|
||
@Inject(at = @At(value = "INVOKE", target = "Lnet/minecraft/resource/VanillaDataPackProvider;createManager(Lnet/minecraft/world/level/storage/LevelStorage$Session;)Lnet/minecraft/resource/ResourcePackManager;"), method = "main") | ||
private static void onMain(CallbackInfo ci, @Local LevelStorage.Session session) { | ||
Path worldDataPackPath = session.getDirectory(WorldSavePath.DATAPACKS); | ||
File worldDataPackDir = worldDataPackPath.toFile(); | ||
File modDataPackDir = DatapackInstallerServer.MAIN_PATH.toFile(); | ||
try { | ||
FileUtils.copyDirectory(modDataPackDir, worldDataPackDir); | ||
} catch(IOException exception) { | ||
LOGGER.error("Failed to copy data packs to the world.", exception); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters