Skip to content

Commit

Permalink
Fixes for older Minecraft version
Browse files Browse the repository at this point in the history
  • Loading branch information
MacaylaMarvelous81 committed Aug 5, 2024
1 parent aa89388 commit e30a0e9
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,26 +18,26 @@ public abstract class CreateWorldScreenMixin {
private static final Logger LOGGER = LogManager.getLogger(CreateWorldScreenMixin.class);
@Shadow
@Nullable
private Path dataPackTempDir;
private Path field_25477;

/**
* @author Jomar Milan - July 31st, 2024 - Minecraft 1.20.5
* @reason Use persistent mod directory instead of vanilla temporary directory
*/
@Overwrite
@Nullable
private Path getDataPackTempDir() {
this.dataPackTempDir = DatapackInstallerClient.MAIN_PATH;
public Path method_29693() {
this.field_25477 = DatapackInstallerClient.MAIN_PATH;

return this.dataPackTempDir;
return this.field_25477;
}

/**
* @author Jomar Milan - July 31st, 2024 - Minecraft 1.20.5
* @reason Because dataPackTempDir is now persistent and not temporary, the directory should no longer be cleared.
*/
@Overwrite
private void clearDataPackTempDir() {
private void method_29695() {
LOGGER.info("Suppressing attempt to clear data pack directory");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,16 @@
import ml.unbreakinggold.datapackinstaller.mixin.MinecraftServerAccessor;
import net.minecraft.client.gui.screen.GameMenuScreen;
import net.minecraft.client.gui.screen.Screen;
import net.minecraft.client.gui.screen.pack.PackScreen;
import net.minecraft.client.gui.screen.pack.DataPackScreen;
import net.minecraft.client.gui.widget.ButtonWidget;
import net.minecraft.client.gui.widget.GridWidget;
import net.minecraft.resource.*;
import net.minecraft.text.Text;
import net.minecraft.text.TranslatableText;
import net.minecraft.util.WorldSavePath;
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.Shadow;
import org.spongepowered.asm.mixin.Unique;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
Expand All @@ -24,24 +24,21 @@
import java.io.IOException;
import java.nio.file.Path;
import java.util.Collection;
import java.util.function.Supplier;

@Mixin(GameMenuScreen.class)
public abstract class GameMenuScreenMixin extends Screen {
@Unique private final Logger LOGGER = LogManager.getLogger(GameMenuScreenMixin.class);
@Unique private static final Text DATA_PACK_TEXT = Text.translatable("dataPack.title");

@Shadow private ButtonWidget createButton(Text text, Supplier<Screen> screenSupplier) { return null; };
@Unique private static final Text DATA_PACK_TEXT = new TranslatableText("dataPack.title");

private GameMenuScreenMixin(Text title) {
super(title);
}

@Inject(at = @At(value = "INVOKE", target = "Lnet/minecraft/client/MinecraftClient;isInSingleplayer()Z"), method = "initWidgets", locals = LocalCapture.CAPTURE_FAILHARD)
private void onInitWidgets(CallbackInfo ci, GridWidget gridWidget, GridWidget.Adder adder) {
private void onInitWidgets(CallbackInfo ci) {
if (!this.client.isIntegratedServerRunning() || this.client.getServer().isRemote()) return;

adder.add(this.createButton(DATA_PACK_TEXT, () -> {
this.addButton(new ButtonWidget(this.width / 2 - 102, this.height / 4 + 144 - 16, 204, 20, DATA_PACK_TEXT, (widget) -> {
Path worldDataPackPath = ((MinecraftServerAccessor)this.client.getServer()).getSession().getDirectory(WorldSavePath.DATAPACKS);
File modDatapackDir = DatapackInstallerClient.MAIN_PATH.toFile();
File worldDataPackDir = worldDataPackPath.toFile();
Expand All @@ -51,13 +48,17 @@ private void onInitWidgets(CallbackInfo ci, GridWidget gridWidget, GridWidget.Ad
LOGGER.error("Unable to install new data packs to world. Data packs not yet seen by this world may be missing.", exception);
}

return new PackScreen(this.client.getServer().getDataPackManager(), (dataPackManager) -> {
Collection<String> enabledProfiles = dataPackManager.getEnabledIds();
ResourcePackManager<ResourcePackProfile> newManager = new ResourcePackManager(ResourcePackProfile::new, new VanillaDataPackProvider(), new FileResourcePackProvider(worldDataPackDir, ResourcePackSource.PACK_SOURCE_WORLD));
newManager.scanPacks();
newManager.setEnabledProfiles(this.client.getServer().getDataPackManager().getEnabledNames());

this.client.openScreen(new DataPackScreen(this, newManager, (dataPackManager) -> {
Collection<String> enabledProfiles = dataPackManager.getEnabledNames();

this.client.getServer().reloadResources(enabledProfiles);

this.client.setScreen(this);
}, DatapackInstallerClient.MAIN_PATH, DATA_PACK_TEXT);
this.client.openScreen(this);
}, worldDataPackDir));
}));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ 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")
@Inject(at = @At(value = "INVOKE", target = "Lnet/minecraft/resource/ResourcePackManager;<init>(Lnet/minecraft/resource/ResourcePackProfile$Factory;[Lnet/minecraft/resource/ResourcePackProvider;)V"), method = "main")
private static void onMain(CallbackInfo ci, @Local LevelStorage.Session session) {
Path worldDataPackPath = session.getDirectory(WorldSavePath.DATAPACKS);
File worldDataPackDir = worldDataPackPath.toFile();
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/fabric.mod.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,6 @@
],
"depends": {
"fabricloader": ">=0.15.0",
"minecraft": ">=1.20.5"
"minecraft": ">=1.16"
}
}

0 comments on commit e30a0e9

Please sign in to comment.