Skip to content

Commit

Permalink
Merge pull request #4 from telvarost/b1.7.3
Browse files Browse the repository at this point in the history
  • Loading branch information
calmilamsy authored May 4, 2024
2 parents 2e95f78 + 1cc17a4 commit 59bac46
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 8 deletions.
9 changes: 9 additions & 0 deletions src/main/java/io/github/prospector/modmenu/ModMenu.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import net.fabricmc.loader.api.ModContainer;
import net.fabricmc.loader.api.metadata.CustomValue;
import net.fabricmc.loader.api.metadata.ModMetadata;
import net.minecraft.class_285;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.screen.Screen;
import net.minecraft.client.gui.screen.option.OptionsScreen;
Expand All @@ -32,6 +33,7 @@ public class ModMenu implements ClientModInitializer {
public static final LinkedListMultimap<ModContainer, ModContainer> PARENT_MAP = LinkedListMultimap.create();
private static ImmutableMap<String, Function<Screen, ? extends Screen>> configScreenFactories = ImmutableMap.of();
private static int libraryCount = 0;
public static class_285 currentTexturePack;

public static boolean hasConfigScreenFactory(String modid) {
return configScreenFactories.containsKey(modid);
Expand Down Expand Up @@ -73,9 +75,16 @@ public void onInitializeClient() {
for (ModContainer mod : mods) {
ModMetadata metadata = mod.getMetadata();
String id = metadata.getId();

if (metadata.containsCustomValue("modmenu:api") && metadata.getCustomValue("modmenu:api").getAsBoolean()) {
addLibraryMod(id);
}
if (!id.equals("minecraft") && mod.getMetadata().getType().equals("builtin")) {
addLibraryMod(id);
}
for (ModContainer containedMod : mod.getContainedMods()) {
addLibraryMod(containedMod.getMetadata().getId());
}
if (metadata.containsCustomValue("modmenu:clientsideOnly") && metadata.getCustomValue("modmenu:clientsideOnly").getAsBoolean()) {
CLIENTSIDE_MODS.add(id);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public void render(int mouseX, int mouseY, float delta) {
}
if (lastSelected != null && description != null && !description.isEmpty()) {
for (String line : RenderUtils.INSTANCE.wrapStringToWidthAsList(textRenderer, description.replaceAll("\n", "\n\n"), getRowWidth())) {
children().add(new DescriptionEntry(line));
children().add(new DescriptionEntry(textRenderer, line));
}
}
}
Expand All @@ -60,15 +60,17 @@ protected void renderHoleBackground(int y1, int y2, int startAlpha, int endAlpha
}

protected class DescriptionEntry extends EntryListWidget.Entry<DescriptionEntry> {
protected TextRenderer _textRenderer;
protected String text;

public DescriptionEntry(String text) {
public DescriptionEntry(TextRenderer textRenderer1, String text) {
this._textRenderer = textRenderer1;
this.text = text;
}

@Override
public void render(int index, int y, int x, int itemWidth, int itemHeight, int mouseX, int mouseY, boolean isSelected, float delta) {
textRenderer.drawWithShadow(text, x, y, 0xAAAAAA);
_textRenderer.draw(text, x, y, 0xAAAAAA);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,12 @@
import io.github.prospector.modmenu.ModMenu;
import io.github.prospector.modmenu.gui.ModListScreen;
import io.github.prospector.modmenu.gui.ModMenuButtonWidget;
import net.fabricmc.loader.api.FabricLoader;
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.widget.ButtonWidget;
import net.minecraft.client.resource.language.TranslationStorage;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
Expand All @@ -17,12 +20,30 @@ public class MixinGameMenuScreen extends Screen {
@SuppressWarnings("unchecked")
@Inject(at = @At("RETURN"), method = "init")
public void drawMenuButton(CallbackInfo info) {
this.buttons.add(new ModMenuButtonWidget(100, this.width / 2 - 100, this.height / 4 + 72 - 16, 200, 20, "Mods (" + ModMenu.getFormattedModCount() + " loaded)"));
if (FabricLoader.getInstance().isModLoaded("legacytranslations")) {
TranslationStorage var2 = TranslationStorage.getInstance();
this.buttons.add(new ButtonWidget(100, this.width / 2 - 100, this.height / 4 + 72 - 16, 98, 20, var2.get("menu.texturepacks")));
String strLoaded = (var2.get("menu.mods.loaded").equals("menu.mods.loaded")) ? "loaded" : var2.get("menu.mods.loaded");
this.buttons.add(new ModMenuButtonWidget(101, this.width / 2 + 2, this.height / 4 + 72 - 16, 98, 20, var2.get("menu.mods") + " (" + ModMenu.getFormattedModCount() + " " + strLoaded + ")"));

} else {
this.buttons.add(new ButtonWidget(100, this.width / 2 - 100, this.height / 4 + 72 - 16, 98, 20, "Texture Packs"));
this.buttons.add(new ModMenuButtonWidget(101, this.width / 2 + 2, this.height / 4 + 72 - 16, 98, 20, "Mods (" + ModMenu.getFormattedModCount() + " loaded)"));
}

if (ModMenu.currentTexturePack != this.minecraft.field_2768.field_1175) {
ModMenu.currentTexturePack = this.minecraft.field_2768.field_1175;
this.minecraft.worldRenderer.method_1537();
}
}

@Inject(method = "buttonClicked", at = @At("HEAD"))
private void onActionPerformed(ButtonWidget button, CallbackInfo ci) {
if (button.id == 100) {
ModMenu.currentTexturePack = this.minecraft.field_2768.field_1175;
minecraft.setScreen(new PackScreen(this));
}
if (button.id == 101) {
minecraft.setScreen(new ModListScreen(this));
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@
import io.github.prospector.modmenu.ModMenu;
import io.github.prospector.modmenu.gui.ModListScreen;
import io.github.prospector.modmenu.gui.ModMenuButtonWidget;
import net.fabricmc.loader.api.FabricLoader;
import net.minecraft.client.gui.screen.Screen;
import net.minecraft.client.gui.screen.TitleScreen;
import net.minecraft.client.gui.widget.ButtonWidget;
import net.minecraft.client.resource.language.TranslationStorage;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
Expand All @@ -18,14 +20,27 @@ public class MixinTitleScreen extends Screen {
@Inject(at = @At("RETURN"), method = "init")
public void drawMenuButton(CallbackInfo info) {
ButtonWidget texturePackButton = minecraft.isApplet ? (ButtonWidget) this.buttons.get(this.buttons.size() - 2) : (ButtonWidget) this.buttons.get(2);
texturePackButton.text = "Texture Packs";
int newWidth = ((MixinGuiButton) texturePackButton).getWidth() / 2 - 1;
((MixinGuiButton) texturePackButton).setWidth(newWidth);
this.buttons.add(new ModMenuButtonWidget(100, this.width / 2 + 2, texturePackButton.y, newWidth, 20, "Mods (" + ModMenu.getFormattedModCount() + " loaded)"));

if (FabricLoader.getInstance().isModLoaded("legacytranslations")) {
TranslationStorage var2 = TranslationStorage.getInstance();
texturePackButton.text = var2.get("menu.texturepacks");
int newWidth = ((MixinGuiButton) texturePackButton).getWidth() / 2 - 1;
((MixinGuiButton) texturePackButton).setWidth(newWidth);
String strLoaded = (var2.get("menu.mods.loaded").equals("menu.mods.loaded")) ? "loaded" : var2.get("menu.mods.loaded");
this.buttons.add(new ModMenuButtonWidget(100, this.width / 2 + 2, texturePackButton.y, newWidth, 20, var2.get("menu.mods") + " (" + ModMenu.getFormattedModCount() + " " + strLoaded + ")"));
} else {
texturePackButton.text = "Texture Packs";
int newWidth = ((MixinGuiButton) texturePackButton).getWidth() / 2 - 1;
((MixinGuiButton) texturePackButton).setWidth(newWidth);
this.buttons.add(new ModMenuButtonWidget(100, this.width / 2 + 2, texturePackButton.y, newWidth, 20, "Mods (" + ModMenu.getFormattedModCount() + " loaded)"));
}
}

@Inject(method = "buttonClicked", at = @At("HEAD"))
private void onActionPerformed(ButtonWidget button, CallbackInfo ci) {
if (button.id == 1 || button.id == 2) {
ModMenu.currentTexturePack = this.minecraft.field_2768.field_1175;
}
if (button.id == 100) {
minecraft.setScreen(new ModListScreen(this));
}
Expand Down

0 comments on commit 59bac46

Please sign in to comment.