Skip to content

Commit

Permalink
Fix 1.19.3 build
Browse files Browse the repository at this point in the history
  • Loading branch information
zbx1425 committed Sep 1, 2023
1 parent 3d9ee3d commit 1c337b5
Show file tree
Hide file tree
Showing 7 changed files with 235 additions and 104 deletions.
6 changes: 3 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -34,19 +34,19 @@ rootProject.ext.architectury_id = minecraft_main_version == 16 ? "me.shedaniel"
rootProject.ext.supports_minecraft_version = [
"1.16.5": "1.16.x",
"1.17.1": "1.17.x", "1.18.2": "1.18.x",
"1.19.2": "1.19.2", "1.19.4": "1.19.4",
"1.19.2": "1.19.2", "1.19.3": "1.19.3", "1.19.4": "1.19.4",
"1.20.1": "1.20.x"
][minecraft_version]
rootProject.ext.supports_minecraft_version_range = [
"1.16.5": "[1.16, 1.17)",
"1.17.1": "[1.17, 1.18)", "1.18.2": "[1.18, 1.19)",
"1.19.2": "1.19.2", "1.19.4": "1.19.4",
"1.19.2": "1.19.2", "1.19.3": "1.19.3", "1.19.4": "1.19.4",
"1.20.1": "[1.20, 1.21)"
][minecraft_version]
rootProject.ext.cloth_config_version = [
"1.16.5": "4.17.101",
"1.17.1": "5.3.63", "1.18.2": "6.5.102",
"1.19.2": "8.3.103", "1.19.4": "10.1.105",
"1.19.2": "8.3.103", "1.19.3": "9.1.104", "1.19.4": "10.1.105",
"1.20.1": "11.1.106"
][minecraft_version]
rootProject.ext.mtr_min_version = minecraft_version + "-" + rootProject.mtr_min_version
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
package cn.zbx1425.mtrsteamloco.gui;

import cn.zbx1425.mtrsteamloco.ClientConfig;
import cn.zbx1425.mtrsteamloco.render.ShadersModHandler;
import me.shedaniel.clothconfig2.api.ConfigBuilder;
import me.shedaniel.clothconfig2.api.ConfigCategory;
import me.shedaniel.clothconfig2.api.ConfigEntryBuilder;
import mtr.mappings.Text;
import net.minecraft.client.Minecraft;
#if MC_VERSION >= "12000"
#endif
import net.minecraft.client.gui.screens.Screen;

public final class ClothConfigScreen {

public static Screen createScreen(Screen parent) {
ConfigBuilder builder = ConfigBuilder.create()
.setParentScreen(parent)
.setTitle(Text.translatable("gui.mtrsteamloco.config.client.title"))
.transparentBackground();
ConfigEntryBuilder entryBuilder = builder.entryBuilder();
ConfigCategory common = builder.getOrCreateCategory(
Text.translatable("gui.mtrsteamloco.config.client.category.common")
);
common.addEntry(entryBuilder
.startBooleanToggle(
Text.translatable("gui.mtrsteamloco.config.client.hideridingtrain"),
ClientConfig.hideRidingTrain
).setSaveConsumer(checked -> ClientConfig.hideRidingTrain = checked).setDefaultValue(false).build()
);
if (!ShadersModHandler.canDrawWithBuffer()) {
common.addEntry(entryBuilder.startTextDescription(
Text.literal("gui.mtrsteamloco.config.client.shaderactive")
).build());
}
common.addEntry(entryBuilder
.startBooleanToggle(
Text.translatable("gui.mtrsteamloco.config.client.rail3d"),
ClientConfig.enableRail3D
).setSaveConsumer(checked -> {
ClientConfig.enableRail3D = checked;
Minecraft.getInstance().levelRenderer.allChanged();
}).setDefaultValue(true).build()
);
common.addEntry(entryBuilder.startTextDescription(
Text.translatable("gui.mtrsteamloco.config.client.rail3d.description")
).build()
);
common.addEntry(entryBuilder
.startBooleanToggle(
Text.translatable("gui.mtrsteamloco.config.client.preloadbbmodel"),
ClientConfig.enableBbModelPreload
).setSaveConsumer(checked -> {
ClientConfig.enableBbModelPreload = checked;
Minecraft.getInstance().execute(() -> Minecraft.getInstance().reloadResourcePacks());
}).setDefaultValue(false).build()
);
common.addEntry(entryBuilder.startTextDescription(
Text.translatable("gui.mtrsteamloco.config.client.preloadbbmodel.description")
).build()
);

ConfigCategory misc = builder.getOrCreateCategory(
Text.translatable("gui.mtrsteamloco.config.client.category.misc")
);
misc.addEntry(entryBuilder
.startBooleanToggle(
Text.translatable("gui.mtrsteamloco.config.client.shadercompat"),
ClientConfig.disableOptimization
).setTooltip(
Text.translatable("gui.mtrsteamloco.config.client.shadercompat.description")
).setSaveConsumer(checked -> ClientConfig.disableOptimization = checked).setDefaultValue(false).build()
);
misc.addEntry(entryBuilder.startTextDescription(
Text.translatable("gui.mtrsteamloco.config.client.railrender.description")
).build()
);
misc.addEntry(entryBuilder
.startBooleanToggle(
Text.translatable("gui.mtrsteamloco.config.client.trainrender"),
ClientConfig.enableTrainRender
).setSaveConsumer(checked -> ClientConfig.enableTrainRender = checked).setDefaultValue(true).build()
);
misc.addEntry(entryBuilder
.startBooleanToggle(
Text.translatable("gui.mtrsteamloco.config.client.railrender"),
ClientConfig.enableRailRender
).setSaveConsumer(checked -> ClientConfig.enableRailRender = checked).setDefaultValue(true).build()
);
misc.addEntry(entryBuilder
.startBooleanToggle(
Text.translatable("gui.mtrsteamloco.config.client.slsmoke"),
ClientConfig.enableSmoke
).setSaveConsumer(checked -> ClientConfig.enableSmoke = checked).setDefaultValue(true).build()
);
return builder.build();
}
}
210 changes: 133 additions & 77 deletions common/src/main/java/cn/zbx1425/mtrsteamloco/gui/ConfigScreen.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@
import cn.zbx1425.mtrsteamloco.ClientConfig;
import cn.zbx1425.mtrsteamloco.render.ShadersModHandler;
import com.mojang.blaze3d.vertex.PoseStack;
import me.shedaniel.clothconfig2.api.ConfigBuilder;
import me.shedaniel.clothconfig2.api.ConfigCategory;
import me.shedaniel.clothconfig2.api.ConfigEntryBuilder;
import mtr.client.IDrawing;
import mtr.mappings.Text;
import mtr.mappings.UtilitiesClient;
Expand All @@ -18,88 +15,147 @@
import net.minecraft.client.gui.screens.Screen;
import net.minecraft.network.chat.CommonComponents;

public final class ConfigScreen {
public final class ConfigScreen extends Screen {
/**
* Distance between this GUI's title and the top of the screen
*/
private static final int TITLE_HEIGHT = 8;

/** Distance from top of the screen to the options row list's top */
private static final int OPTIONS_LIST_TOP_HEIGHT = 24;
/** Distance from bottom of the screen to the options row list's bottom */
private static final int OPTIONS_LIST_BOTTOM_OFFSET = 32;
/** Height of each item in the options row list */
private static final int OPTIONS_LIST_ITEM_HEIGHT = 20;

/** Width of a button */
private static final int BUTTON_WIDTH = 200;
/** Height of a button */
private static final int BUTTON_HEIGHT = 20;
/** Distance from bottom of the screen to the "Done" button's top */
private static final int DONE_BUTTON_TOP_OFFSET = 26;

private final Screen parentScreen;

public static Screen createScreen(Screen parent) {
ConfigBuilder builder = ConfigBuilder.create()
.setParentScreen(parent)
.setTitle(Text.translatable("gui.mtrsteamloco.config.client.title"))
.transparentBackground();
ConfigEntryBuilder entryBuilder = builder.entryBuilder();
ConfigCategory common = builder.getOrCreateCategory(
Text.translatable("gui.mtrsteamloco.config.client.category.common")
);
common.addEntry(entryBuilder
.startBooleanToggle(
Text.translatable("gui.mtrsteamloco.config.client.hideridingtrain"),
ClientConfig.hideRidingTrain
).setSaveConsumer(checked -> ClientConfig.hideRidingTrain = checked).setDefaultValue(false).build()
);
if (!ShadersModHandler.canDrawWithBuffer()) {
common.addEntry(entryBuilder.startTextDescription(
Text.literal("gui.mtrsteamloco.config.client.shaderactive")
).build());
try {
Class.forName("me.shedaniel.clothconfig2.api.ConfigBuilder");
return ClothLogic.createClothScreen(parent);
} catch (Exception ignored) {
return new ConfigScreen(parent);
}
common.addEntry(entryBuilder
.startBooleanToggle(
Text.translatable("gui.mtrsteamloco.config.client.rail3d"),
ClientConfig.enableRail3D
).setSaveConsumer(checked -> {
ClientConfig.enableRail3D = checked;
Minecraft.getInstance().levelRenderer.allChanged();
}).setDefaultValue(true).build()
);
common.addEntry(entryBuilder.startTextDescription(
Text.translatable("gui.mtrsteamloco.config.client.rail3d.description")
).build()
);
common.addEntry(entryBuilder
.startBooleanToggle(
Text.translatable("gui.mtrsteamloco.config.client.preloadbbmodel"),
ClientConfig.enableBbModelPreload
).setSaveConsumer(checked -> {
ClientConfig.enableBbModelPreload = checked;
Minecraft.getInstance().execute(() -> Minecraft.getInstance().reloadResourcePacks());
}).setDefaultValue(false).build()
);
common.addEntry(entryBuilder.startTextDescription(
Text.translatable("gui.mtrsteamloco.config.client.preloadbbmodel.description")
).build()
);
}

private static class ClothLogic {

public static Screen createClothScreen(Screen parent) {
return ClothConfigScreen.createScreen(parent);
}
}

public ConfigScreen(Screen parentScreen) {
super(Text.translatable("gui.mtrsteamloco.config.client.title"));
this.parentScreen = parentScreen;
}

ConfigCategory misc = builder.getOrCreateCategory(
Text.translatable("gui.mtrsteamloco.config.client.category.misc")
@Override
public void onClose() {
ClientConfig.save();
this.minecraft.setScreen(parentScreen);
}

@Override
protected void init() {
this.clearWidgets();

int listLeft = (this.width - 400) / 2;
WidgetBetterCheckbox enableRail3D = new WidgetBetterCheckbox(
listLeft, OPTIONS_LIST_TOP_HEIGHT + 1 * OPTIONS_LIST_ITEM_HEIGHT, 400, OPTIONS_LIST_ITEM_HEIGHT,
Text.translatable("gui.mtrsteamloco.config.client.rail3d"), checked -> {
ClientConfig.enableRail3D = checked;
Minecraft.getInstance().levelRenderer.allChanged();
}
);
misc.addEntry(entryBuilder
.startBooleanToggle(
Text.translatable("gui.mtrsteamloco.config.client.shadercompat"),
ClientConfig.disableOptimization
).setTooltip(
Text.translatable("gui.mtrsteamloco.config.client.shadercompat.description")
).setSaveConsumer(checked -> ClientConfig.disableOptimization = checked).setDefaultValue(false).build()
WidgetLabel labelEnableRail3D = new WidgetLabel(
listLeft + 24, OPTIONS_LIST_TOP_HEIGHT + 2 * OPTIONS_LIST_ITEM_HEIGHT, 400,
Text.translatable("gui.mtrsteamloco.config.client.rail3d.description")
);
misc.addEntry(entryBuilder.startTextDescription(
Text.translatable("gui.mtrsteamloco.config.client.railrender.description")
).build()
WidgetBetterCheckbox shaderCompatMode = new WidgetBetterCheckbox(
listLeft, OPTIONS_LIST_TOP_HEIGHT + 0 * OPTIONS_LIST_ITEM_HEIGHT,400, OPTIONS_LIST_ITEM_HEIGHT,
Text.translatable("gui.mtrsteamloco.config.client.shadercompat"), checked -> {
ClientConfig.disableOptimization = checked;
labelEnableRail3D.visible = enableRail3D.visible = ClientConfig.useRenderOptimization();
});
WidgetBetterCheckbox enableTrainRender = new WidgetBetterCheckbox(
listLeft, OPTIONS_LIST_TOP_HEIGHT + 5 * OPTIONS_LIST_ITEM_HEIGHT, 200, OPTIONS_LIST_ITEM_HEIGHT,
Text.translatable("gui.mtrsteamloco.config.client.trainrender"), checked -> ClientConfig.enableTrainRender = checked
);
misc.addEntry(entryBuilder
.startBooleanToggle(
Text.translatable("gui.mtrsteamloco.config.client.trainrender"),
ClientConfig.enableTrainRender
).setSaveConsumer(checked -> ClientConfig.enableTrainRender = checked).setDefaultValue(true).build()
WidgetBetterCheckbox enableRailRender = new WidgetBetterCheckbox(
listLeft + 200, OPTIONS_LIST_TOP_HEIGHT + 5 * OPTIONS_LIST_ITEM_HEIGHT, 200, OPTIONS_LIST_ITEM_HEIGHT,
Text.translatable("gui.mtrsteamloco.config.client.railrender"), checked -> ClientConfig.enableRailRender = checked
);
misc.addEntry(entryBuilder
.startBooleanToggle(
Text.translatable("gui.mtrsteamloco.config.client.railrender"),
ClientConfig.enableRailRender
).setSaveConsumer(checked -> ClientConfig.enableRailRender = checked).setDefaultValue(true).build()
WidgetBetterCheckbox hideRidingTrain = new WidgetBetterCheckbox(
listLeft, OPTIONS_LIST_TOP_HEIGHT + 6 * OPTIONS_LIST_ITEM_HEIGHT, 400, OPTIONS_LIST_ITEM_HEIGHT,
Text.translatable("gui.mtrsteamloco.config.client.hideridingtrain"), checked -> ClientConfig.hideRidingTrain = checked
);
misc.addEntry(entryBuilder
.startBooleanToggle(
Text.translatable("gui.mtrsteamloco.config.client.slsmoke"),
ClientConfig.enableSmoke
).setSaveConsumer(checked -> ClientConfig.enableSmoke = checked).setDefaultValue(true).build()
WidgetBetterCheckbox enableSmoke = new WidgetBetterCheckbox(
listLeft, OPTIONS_LIST_TOP_HEIGHT + 3 * OPTIONS_LIST_ITEM_HEIGHT, 400, OPTIONS_LIST_ITEM_HEIGHT,
Text.translatable("gui.mtrsteamloco.config.client.slsmoke"), checked -> ClientConfig.enableSmoke = checked
);
return builder.build();
shaderCompatMode.setChecked(ClientConfig.disableOptimization);
enableRail3D.setChecked(ClientConfig.enableRail3D);
enableRailRender.setChecked(ClientConfig.enableRailRender);
enableTrainRender.setChecked(ClientConfig.enableTrainRender);
enableSmoke.setChecked(ClientConfig.enableSmoke);
hideRidingTrain.setChecked(ClientConfig.hideRidingTrain);
labelEnableRail3D.visible = enableRail3D.visible = ClientConfig.useRenderOptimization();
this.addRenderableWidget(shaderCompatMode);
this.addRenderableWidget(enableRail3D);
this.addRenderableWidget(enableRailRender);
this.addRenderableWidget(enableTrainRender);
this.addRenderableWidget(hideRidingTrain);
this.addRenderableWidget(enableSmoke);

if (!ShadersModHandler.canDrawWithBuffer()) {
this.addRenderableWidget(new WidgetLabel(
listLeft + 24, OPTIONS_LIST_TOP_HEIGHT + 1 * OPTIONS_LIST_ITEM_HEIGHT, 400,
Text.translatable("gui.mtrsteamloco.config.client.shaderactive")
));
}

this.addRenderableWidget(labelEnableRail3D);
this.addRenderableWidget(new WidgetLabel(
listLeft, OPTIONS_LIST_TOP_HEIGHT + 4 * OPTIONS_LIST_ITEM_HEIGHT, 400,
Text.translatable("gui.mtrsteamloco.config.client.railrender.description")
));

// Add the "Done" button
Button btnDone = UtilitiesClient.newButton(CommonComponents.GUI_DONE, button -> this.onClose());
IDrawing.setPositionAndWidth(btnDone, (this.width - BUTTON_WIDTH) / 2, this.height - DONE_BUTTON_TOP_OFFSET, BUTTON_WIDTH);
this.addRenderableWidget(btnDone);
}

@Override
#if MC_VERSION >= "12000"
public void render(GuiGraphics guiGraphics, int mouseX, int mouseY, float partialTicks) {
#else
public void render(PoseStack guiGraphics, int mouseX, int mouseY, float partialTicks) {
#endif
this.renderBackground(guiGraphics);
// Options row list must be rendered here,
// otherwise the GUI will be broken
#if MC_VERSION >= "12000"
guiGraphics.drawCenteredString(this.font, this.title.getString(),
this.width / 2, TITLE_HEIGHT, 0xFFFFFF);
#else
drawCenteredString(guiGraphics, this.font, this.title.getString(),
this.width / 2, TITLE_HEIGHT, 0xFFFFFF);
#endif
super.render(guiGraphics, mouseX, mouseY, partialTicks);
}

@Override
public boolean isPauseScreen() {
return false;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
import cn.zbx1425.mtrsteamloco.gui.ConfigScreen;
import cn.zbx1425.mtrsteamloco.render.RenderUtil;
import cn.zbx1425.mtrsteamloco.render.train.SteamSmokeParticle;
import cn.zbx1425.sowcerext.model.RawModel;
import cn.zbx1425.sowcerext.model.loader.NmbModelLoader;
import mtr.mappings.Text;
import net.fabricmc.api.ClientModInitializer;
#if MC_VERSION >= "11900"
Expand All @@ -19,19 +17,7 @@
#if MC_VERSION < "11903"
import net.fabricmc.fabric.api.event.client.ClientSpriteRegistryCallback;
#endif
import net.fabricmc.loader.api.FabricLoader;
import net.minecraft.client.Minecraft;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.inventory.InventoryMenu;
import org.apache.commons.io.FilenameUtils;
import net.minecraft.Util;

import java.io.FileOutputStream;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Map;

public class MainFabricClient implements ClientModInitializer {

Expand Down
3 changes: 1 addition & 2 deletions fabric/src/main/resources/fabric.mod.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,7 @@
"depends": {
"fabric": "*",
"minecraft": "${minecraft_version}",
"mtr": ">=${mtr_min_version}",
"cloth-config": "*"
"mtr": ">=${mtr_min_version}"
},
"accessWidener" : "mtrsteamloco.accesswidener"
}
Loading

0 comments on commit 1c337b5

Please sign in to comment.