Fix 1.12.2 not compiling

This commit is contained in:
Vojtěch Šokala
2026-06-06 11:09:09 +02:00
parent 17af90d4e8
commit f64072eeab
12 changed files with 436 additions and 78 deletions
@@ -21,7 +21,7 @@ package com.seibel.distanthorizons.cleanroom.mixins.client;
import com.seibel.distanthorizons.common.wrappers.world.ClientLevelWrapper;
import com.seibel.distanthorizons.core.api.internal.ClientApi;
import com.seibel.distanthorizons.core.util.math.Mat4f;
import com.seibel.distanthorizons.core.util.math.DhMat4f;
import net.minecraft.client.multiplayer.WorldClient;
import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.client.renderer.RenderGlobal;
@@ -49,12 +49,12 @@ public class MixinRenderGlobal
{
float[] mcProjMatrixRaw = new float[16];
GL11.glGetFloatv(GL11.GL_PROJECTION_MATRIX, mcProjMatrixRaw);
ClientApi.RENDER_STATE.mcProjectionMatrix = new Mat4f(mcProjMatrixRaw);
ClientApi.RENDER_STATE.mcProjectionMatrix = new DhMat4f(mcProjMatrixRaw);
ClientApi.RENDER_STATE.mcProjectionMatrix.transpose();
float[] mcModelViewRaw = new float[16];
GL11.glGetFloatv(GL11.GL_MODELVIEW_MATRIX, mcModelViewRaw);
ClientApi.RENDER_STATE.mcModelViewMatrix = new Mat4f(mcModelViewRaw);
ClientApi.RENDER_STATE.mcModelViewMatrix = new DhMat4f(mcModelViewRaw);
ClientApi.RENDER_STATE.mcModelViewMatrix.transpose();
ClientApi.RENDER_STATE.partialTickTime = (float) partialTicks;
@@ -1,6 +1,8 @@
package com.seibel.distanthorizons.common;
import com.seibel.distanthorizons.api.enums.config.EDhApiMcRenderingFadeMode;
import com.seibel.distanthorizons.api.enums.config.EDhApiRenderingEngine;
import com.seibel.distanthorizons.api.enums.worldGeneration.EDhApiDistantGeneratorMode;
import com.seibel.distanthorizons.api.methods.events.abstractEvents.DhApiAfterDhInitEvent;
import com.seibel.distanthorizons.api.methods.events.abstractEvents.DhApiBeforeDhInitEvent;
import com.seibel.distanthorizons.common.commands.CommandInitializer;
@@ -82,8 +82,8 @@ public class DhUpdateScreenBase
try
{
#if MC_VER <= MC_1_12_2
DhScreenUtil.showScreen(new UpdateModScreen(
new TitleScreen(false),
DhScreenUtil.setScreen(new UpdateModScreen(
new GuiMainMenu(),
versionId
));
#else
@@ -1,7 +1,11 @@
package com.seibel.distanthorizons.common.wrappers.gui;
import net.minecraft.client.Minecraft;
#if MC_VER <= MC_1_12_2
import net.minecraft.client.gui.GuiScreen;
#else
import net.minecraft.client.gui.screens.Screen;
#endif
import java.util.Objects;
@@ -12,7 +16,11 @@ public class DhScreenUtil
//================//
//region
#if MC_VER <= MC_1_12_2
public static void setScreen(GuiScreen screen)
#else
public static void setScreen(Screen screen)
#endif
{
#if MC_VER <= MC_1_12_2
Objects.requireNonNull(Minecraft.getMinecraft()).displayGuiScreen(screen);
@@ -3,41 +3,55 @@ package com.seibel.distanthorizons.common.wrappers.gui.classicConfig;
import java.util.AbstractMap;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.function.Function;
import java.util.function.Predicate;
import java.util.regex.Pattern;
import com.seibel.distanthorizons.api.enums.config.DisallowSelectingViaConfigGui;
import com.seibel.distanthorizons.common.wrappers.gui.DhScreen;
import com.seibel.distanthorizons.common.wrappers.gui.DhScreenUtil;
import com.seibel.distanthorizons.common.wrappers.gui.TexturedButtonWidget;
import com.seibel.distanthorizons.common.wrappers.gui.*;
import com.seibel.distanthorizons.common.wrappers.gui.config.ConfigGuiInfo;
import com.seibel.distanthorizons.common.wrappers.minecraft.MinecraftClientWrapper;
import com.seibel.distanthorizons.core.config.Config;
import com.seibel.distanthorizons.core.config.ConfigHandler;
import com.seibel.distanthorizons.core.config.types.*;
import com.seibel.distanthorizons.common.wrappers.gui.updater.ChangelogScreen;
import com.seibel.distanthorizons.core.config.types.enums.EConfigCommentTextPosition;
import com.seibel.distanthorizons.core.config.types.enums.EConfigValidity;
import com.seibel.distanthorizons.core.dependencyInjection.SingletonInjector;
import com.seibel.distanthorizons.core.jar.updater.SelfUpdater;
import com.seibel.distanthorizons.core.logging.DhLoggerBuilder;
import com.seibel.distanthorizons.core.util.AnnotationUtil;
import com.seibel.distanthorizons.core.wrapperInterfaces.config.IConfigGui;
import com.seibel.distanthorizons.core.wrapperInterfaces.config.ILangWrapper;
import com.seibel.distanthorizons.coreapi.ModInfo;
import net.minecraft.client.Minecraft;
#if MC_VER <= MC_1_12_2
import net.minecraft.client.gui.*;
import net.minecraft.client.renderer.Tessellator;
import net.minecraft.util.text.ITextComponent;
import net.minecraft.util.text.Style;
import net.minecraft.util.text.TextFormatting;
#else
import net.minecraft.ChatFormatting;
import net.minecraft.client.gui.Font;
import net.minecraft.client.gui.components.AbstractWidget;
import net.minecraft.client.gui.components.Button;
import net.minecraft.client.gui.components.ContainerObjectSelectionList;
import net.minecraft.client.gui.components.EditBox;
import net.minecraft.client.gui.components.events.GuiEventListener;
import net.minecraft.client.gui.screens.Screen;
import net.minecraft.network.chat.Component;
#endif
import com.seibel.distanthorizons.core.logging.DhLogger;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
#if MC_VER < MC_1_20_1
#if MC_VER <= MC_1_12_2
#elif MC_VER < MC_1_20_1
import com.mojang.blaze3d.vertex.PoseStack;
import net.minecraft.client.gui.GuiComponent;
#elif MC_VER <= MC_1_21_11
@@ -47,16 +61,21 @@ import net.minecraft.client.gui.GuiGraphicsExtractor;
#endif
#if MC_VER >= MC_1_17_1
import net.minecraft.client.gui.narration.NarratableEntry;
#endif
#if MC_VER <= MC_1_21_10
#if MC_VER <= MC_1_12_2
import net.minecraft.util.ResourceLocation;
#elif MC_VER <= MC_1_21_10
import net.minecraft.resources.ResourceLocation;
#else
import net.minecraft.resources.Identifier;
#endif
import org.lwjgl.glfw.GLFW;
#if MC_VER > MC_1_12_2
import com.mojang.blaze3d.platform.InputConstants;
#endif
import static com.seibel.distanthorizons.common.wrappers.gui.GuiHelper.*;
import static com.seibel.distanthorizons.common.wrappers.gui.GuiHelper.Translatable;
@@ -70,21 +89,38 @@ class DhConfigScreen extends DhScreen
private static final MinecraftClientWrapper MC_CLIENT = MinecraftClientWrapper.INSTANCE;
#if MC_VER <= MC_1_12_2
private static final int changelogButton_id = 101;
#endif
#if MC_VER <= MC_1_12_2
private final GuiScreen parent;
#else
private final Screen parent;
#endif
private final String category;
private ClassicConfigGUI.ConfigListWidget configListWidget;
private boolean reload = false;
#if MC_VER <= MC_1_12_2
private GuiButton doneButton;
#else
private Button doneButton;
#endif
//=============//
// constructor //
//=============//
//region
#if MC_VER <= MC_1_12_2
protected DhConfigScreen(GuiScreen parent, String category)
#else
protected DhConfigScreen(Screen parent, String category)
#endif
{
super(Translatable(
LANG_WRAPPER.langExists(ModInfo.ID + ".config" + (category.isEmpty() ? "." + category : "") + ".title") ?
@@ -95,20 +131,44 @@ class DhConfigScreen extends DhScreen
this.category = category;
}
//endregion
//===================//
// menu UI lifecycle //
//===================//
//region
@Override
#if MC_VER <= MC_1_12_2
public void updateScreen() { super.updateScreen(); }
#else
public void tick() { super.tick(); }
#endif
//endregion
//==================//
// menu UI creation //
//==================//
//region
@Override
#if MC_VER <= MC_1_12_2
public void initGui()
#else
protected void init()
#endif
{
#if MC_VER <= MC_1_12_2
super.initGui();
#else
super.init();
#endif
if (!this.reload)
{
ConfigHandler.INSTANCE.configFileHandler.loadFromFile();
@@ -120,6 +180,9 @@ class DhConfigScreen extends DhScreen
&& !ModInfo.IS_DEV_BUILD)
{
this.addBtn(new TexturedButtonWidget(
#if MC_VER <= MC_1_12_2
changelogButton_id,
#endif
// Where the button is on the screen
this.width - 28, this.height - 28,
// Width and height of the button
@@ -137,6 +200,7 @@ class DhConfigScreen extends DhScreen
#endif
20, 20,
// Create the button and tell it where to go
#if MC_VER > MC_1_12_2
(buttonWidget) -> {
ChangelogScreen changelogScreen = new ChangelogScreen(this);
if (changelogScreen.usable)
@@ -148,8 +212,13 @@ class DhConfigScreen extends DhScreen
LOGGER.warn("Changelog was not able to open");
}
},
#endif
// Add a title to the button
#if MC_VER <= MC_1_12_2
Translatable(ModInfo.ID + ".updater.title").getFormattedText()
#else
Translatable(ModInfo.ID + ".updater.title")
#endif
));
}
@@ -175,16 +244,23 @@ class DhConfigScreen extends DhScreen
DhScreenUtil.setScreen(this.parent);
}));
#if MC_VER <= MC_1_12_2
this.configListWidget = new ClassicConfigGUI.ConfigListWidget(this.mc, this.width * 2, this.height, 32, 32, 25);
#else
this.configListWidget = new ClassicConfigGUI.ConfigListWidget(this.minecraft, this.width * 2, this.height, 32, 32, 25);
#endif
#if MC_VER < MC_1_20_6 // no background is rendered in MC 1.20.6+
#if MC_VER <= MC_1_12_2
#elif MC_VER < MC_1_20_6 // no background is rendered in MC 1.20.6+
if (this.minecraft != null && this.minecraft.level != null)
{
this.configListWidget.setRenderBackground(false);
}
#endif
#if MC_VER > MC_1_12_2
this.addWidget(this.configListWidget);
#endif
for (AbstractConfigBase<?> configEntry : ConfigHandler.INSTANCE.configBaseList)
{
@@ -347,18 +423,35 @@ class DhConfigScreen extends DhScreen
private static void setupBooleanMenuOption(ConfigEntry<Boolean> booleanConfigEntry)
{
// For boolean
#if MC_VER <= MC_1_12_2
Function<Object, ITextComponent> func = value -> Translatable("distanthorizons.general."+((Boolean) value ? "true" : "false")).setStyle(new Style().setColor((Boolean) value ? TextFormatting.GREEN : TextFormatting.RED));
#else
Function<Object, Component> func = value -> Translatable("distanthorizons.general." + ((Boolean) value ? "true" : "false")).withStyle((Boolean) value ? ChatFormatting.GREEN : ChatFormatting.RED);
#endif
final ConfigGuiInfo configGuiInfo = ((ConfigGuiInfo) booleanConfigEntry.guiValue);
configGuiInfo.buttonOptionMap =
#if MC_VER <= MC_1_12_2
new AbstractMap.SimpleEntry<OnPressed, Function<Object, ITextComponent>>(
#else
new AbstractMap.SimpleEntry<Button.OnPress, Function<Object, Component>>(
#endif
(button) ->
{
#if MC_VER <= MC_1_12_2
button.enabled = !booleanConfigEntry.apiIsOverriding();
#else
button.active = !booleanConfigEntry.apiIsOverriding();
#endif
booleanConfigEntry.uiSetWithoutSaving(!booleanConfigEntry.get());
#if MC_VER <= MC_1_12_2
button.displayString = func.apply(booleanConfigEntry.get()).getFormattedText();
#else
button.setMessage(func.apply(booleanConfigEntry.get()));
#endif
}, func);
}
private static void setupEnumMenuOption(ConfigEntry<Enum<?>> enumConfigEntry, Class<? extends Enum<?>> enumClass)
@@ -367,20 +460,29 @@ class DhConfigScreen extends DhScreen
final ConfigGuiInfo configGuiInfo = ((ConfigGuiInfo) enumConfigEntry.guiValue);
#if MC_VER <= MC_1_12_2
Function<Object, ITextComponent > getEnumTranslatableFunc = (value) -> Translatable(TRANSLATION_PREFIX + "enum." + enumClass.getSimpleName() + "." + enumConfigEntry.get().toString());
#else
Function<Object, Component> getEnumTranslatableFunc = (value) -> Translatable(TRANSLATION_PREFIX + "enum." + enumClass.getSimpleName() + "." + enumConfigEntry.get().toString());
#endif
configGuiInfo.buttonOptionMap =
#if MC_VER <= MC_1_12_2
new AbstractMap.SimpleEntry<OnPressed, Function<Object, ITextComponent>>(
#else
new AbstractMap.SimpleEntry<Button.OnPress, Function<Object, Component>>(
#endif
(button) ->
{
// get the currently selected enum and enum index
int startingIndex = enumList.indexOf(enumConfigEntry.get());
Enum<?> enumValue = enumList.get(startingIndex);
boolean shiftPressed =
InputConstants.isKeyDown(MC_CLIENT.getGlfwWindowId(), GLFW.GLFW_KEY_LEFT_SHIFT)
|| InputConstants.isKeyDown(MC_CLIENT.getGlfwWindowId(), GLFW.GLFW_KEY_RIGHT_SHIFT);
#if MC_VER <= MC_1_12_2
boolean shiftPressed = GuiScreen.isShiftKeyDown();
#else
boolean shiftPressed = InputConstants.isKeyDown(MC_CLIENT.getGlfwWindowId(), GLFW.GLFW_KEY_LEFT_SHIFT) || InputConstants.isKeyDown(MC_CLIENT.getGlfwWindowId(), GLFW.GLFW_KEY_RIGHT_SHIFT);
#endif
// move forward or backwards depending on if the shift key is pressed
int index = shiftPressed ? startingIndex - 1 : startingIndex + 1;
@@ -432,9 +534,13 @@ class DhConfigScreen extends DhScreen
enumConfigEntry.uiSetWithoutSaving(enumValue);
#if MC_VER <= MC_1_12_2
button.enabled = !enumConfigEntry.apiIsOverriding();
button.displayString = getEnumTranslatableFunc.apply(enumConfigEntry.get()).getFormattedText();
#else
button.active = !enumConfigEntry.apiIsOverriding();
button.setMessage(getEnumTranslatableFunc.apply(enumConfigEntry.get()));
#endif
}, getEnumTranslatableFunc);
}
@@ -450,8 +556,9 @@ class DhConfigScreen extends DhScreen
//==============//
// reset button //
//==============//
//region
Button.OnPress btnAction = (button) ->
#if MC_VER <= MC_1_12_2 OnPressed #else Button.OnPress #endif btnAction = (button) ->
{
configEntry.uiSetWithoutSaving(configEntry.getDefaultValue());
this.reload = true;
@@ -463,29 +570,60 @@ class DhConfigScreen extends DhScreen
- ClassicConfigGUI.ConfigScreenConfigs.SPACE_FROM_RIGHT_SCREEN;
int resetButtonPosZ = 0;
Button resetButton = MakeBtn(
#if MC_VER <= MC_1_12_2 GuiButton #else Button #endif resetButton = MakeBtn(
#if MC_VER <= MC_1_12_2
Translatable("distanthorizons.general.reset").setStyle(new Style().setColor(TextFormatting.RED)),
#else
Translatable("distanthorizons.general.reset").withStyle(ChatFormatting.RED),
#endif
resetButtonPosX, resetButtonPosZ,
ClassicConfigGUI.ConfigScreenConfigs.RESET_BUTTON_WIDTH, ClassicConfigGUI.ConfigScreenConfigs.RESET_BUTTON_HEIGHT,
btnAction);
if (configEntry.apiIsOverriding())
if (configEntry.mcVersionOverridePresent())
{
#if MC_VER <= MC_1_12_2
resetButton.enabled = false;
resetButton.displayString = Translatable("distanthorizons.general.unsupportedMcVersion").setStyle(new Style().setColor(TextFormatting.DARK_GRAY)).getFormattedText();
#else
resetButton.active = false;
resetButton.setMessage(Translatable("distanthorizons.general.unsupportedMcVersion").withStyle(ChatFormatting.DARK_GRAY));
#endif
}
else if (configEntry.apiIsOverriding())
{
#if MC_VER <= MC_1_12_2
resetButton.enabled = false;
resetButton.displayString = Translatable("distanthorizons.general.apiOverride").setStyle(new Style().setColor(TextFormatting.DARK_GRAY)).getFormattedText();
#else
resetButton.active = false;
resetButton.setMessage(Translatable("distanthorizons.general.apiOverride").withStyle(ChatFormatting.DARK_GRAY));
#endif
}
else
{
#if MC_VER <= MC_1_12_2
resetButton.enabled = true;
#else
resetButton.active = true;
#endif
}
//endregion
//==============//
// option field //
//==============//
//region
#if MC_VER <= MC_1_12_2
ITextComponent textComponent = this.GetTranslatableTextComponentForConfig(configEntry);
#else
Component textComponent = this.GetTranslatableTextComponentForConfig(configEntry);
#endif
int optionFieldPosX = this.width
- ClassicConfigGUI.ConfigScreenConfigs.SPACE_FROM_RIGHT_SCREEN
@@ -497,21 +635,40 @@ class DhConfigScreen extends DhScreen
if (configGuiInfo.buttonOptionMap != null)
{
// enum/multi option input button
#if MC_VER <= MC_1_12_2
Map.Entry<OnPressed, Function<Object,ITextComponent>> widget = configGuiInfo.buttonOptionMap;
#else
Map.Entry<Button.OnPress, Function<Object, Component>> widget = configGuiInfo.buttonOptionMap;
#endif
if (configEntry.getType().isEnum())
{
widget.setValue((value) -> Translatable(TRANSLATION_PREFIX + "enum." + configEntry.getType().getSimpleName() + "." + configEntry.get().toString()));
}
#if MC_VER <= MC_1_12_2
GuiButton button = MakeBtn(
#else
Button button = MakeBtn(
#endif
widget.getValue().apply(configEntry.get()),
optionFieldPosX, optionFieldPosZ,
ClassicConfigGUI.ConfigScreenConfigs.OPTION_FIELD_WIDTH, ClassicConfigGUI.ConfigScreenConfigs.CATEGORY_BUTTON_HEIGHT,
widget.getKey());
// deactivate the button if the API is overriding it
button.active = !configEntry.apiIsOverriding();
// or the MC version doesn't support it
if (configEntry.mcVersionOverridePresent()
|| configEntry.apiIsOverriding())
{
#if MC_VER <= MC_1_12_2
button.enabled = false;
#else
button.active = false;
#endif
}
this.configListWidget.addButton(this, configEntry,
@@ -525,16 +682,25 @@ class DhConfigScreen extends DhScreen
else
{
// text box input
#if MC_VER <= MC_1_12_2
GuiTextField widget = new GuiTextField(0, this.fontRenderer,
optionFieldPosX, optionFieldPosZ,
ClassicConfigGUI.ConfigScreenConfigs.OPTION_FIELD_WIDTH - 4, ClassicConfigGUI.ConfigScreenConfigs.CATEGORY_BUTTON_HEIGHT);
widget.setMaxStringLength(3_000_000); // hopefully 3 million characters should be enough for any normal use-case, lol
widget.setText(String.valueOf(configEntry.get()));
#else
EditBox widget = new EditBox(this.font,
optionFieldPosX, optionFieldPosZ,
ClassicConfigGUI.ConfigScreenConfigs.OPTION_FIELD_WIDTH - 4, ClassicConfigGUI.ConfigScreenConfigs.CATEGORY_BUTTON_HEIGHT,
Translatable(""));
widget.setMaxLength(3_000_000); // hopefully 3 million characters should be enough for any normal use-case, lol
widget.insertText(String.valueOf(configEntry.get()));
#endif
Predicate<String> processor = configGuiInfo.tooltipFunction.apply(widget, this.doneButton);
#if MC_VER <= MC_1_21_11
#if MC_VER <= MC_1_12_2
widget.setValidator(processor::test);
#elif MC_VER <= MC_1_21_11
widget.setFilter(processor);
#else
widget.setResponder(processor::test);
@@ -544,6 +710,8 @@ class DhConfigScreen extends DhScreen
return true;
}
//endregion
}
return false;
@@ -554,12 +722,21 @@ class DhConfigScreen extends DhScreen
{
ConfigCategory configCategory = (ConfigCategory) configType;
#if MC_VER <= MC_1_12_2
ITextComponent textComponent = this.GetTranslatableTextComponentForConfig(configCategory);
#else
Component textComponent = this.GetTranslatableTextComponentForConfig(configCategory);
#endif
int categoryPosX = this.width - ClassicConfigGUI.ConfigScreenConfigs.CATEGORY_BUTTON_WIDTH - ClassicConfigGUI.ConfigScreenConfigs.SPACE_FROM_RIGHT_SCREEN;
int categoryPosZ = this.height - ClassicConfigGUI.ConfigScreenConfigs.CATEGORY_BUTTON_HEIGHT; // Note: the posZ value here seems to be ignored
Button widget = MakeBtn(textComponent,
#if MC_VER <= MC_1_12_2
GuiButton widget = MakeBtn(
#else
Button widget = MakeBtn(
#endif
textComponent,
categoryPosX, categoryPosZ,
ClassicConfigGUI.ConfigScreenConfigs.CATEGORY_BUTTON_WIDTH, ClassicConfigGUI.ConfigScreenConfigs.CATEGORY_BUTTON_HEIGHT,
((button) ->
@@ -580,11 +757,20 @@ class DhConfigScreen extends DhScreen
{
ConfigUIButton configUiButton = (ConfigUIButton) configType;
#if MC_VER <= MC_1_12_2
ITextComponent textComponent = this.GetTranslatableTextComponentForConfig(configUiButton);
#else
Component textComponent = this.GetTranslatableTextComponentForConfig(configUiButton);
#endif
int buttonPosX = this.width - ClassicConfigGUI.ConfigScreenConfigs.CATEGORY_BUTTON_WIDTH - ClassicConfigGUI.ConfigScreenConfigs.SPACE_FROM_RIGHT_SCREEN;
Button widget = MakeBtn(textComponent,
#if MC_VER <= MC_1_12_2
GuiButton widget = MakeBtn(
#else
Button widget = MakeBtn(
#endif
textComponent,
buttonPosX, this.height - 28,
ClassicConfigGUI.ConfigScreenConfigs.CATEGORY_BUTTON_WIDTH, ClassicConfigGUI.ConfigScreenConfigs.CATEGORY_BUTTON_HEIGHT,
(button) -> ((ConfigUIButton) configType).runAction());
@@ -601,7 +787,11 @@ class DhConfigScreen extends DhScreen
{
ConfigUIComment configUiComment = (ConfigUIComment) configType;
#if MC_VER <= MC_1_12_2
ITextComponent textComponent = this.GetTranslatableTextComponentForConfig(configUiComment);
#else
Component textComponent = this.GetTranslatableTextComponentForConfig(configUiComment);
#endif
if (configUiComment.parentConfigPath != null)
{
textComponent = Translatable(TRANSLATION_PREFIX + configUiComment.parentConfigPath);
@@ -618,7 +808,12 @@ class DhConfigScreen extends DhScreen
{
if (configType instanceof ConfigUISpacer)
{
Button spacerButton = MakeBtn(Translatable("distanthorizons.general.spacer"),
#if MC_VER <= MC_1_12_2
GuiButton spacerButton = MakeBtn(
#else
Button spacerButton = MakeBtn(
#endif
Translatable("distanthorizons.general.spacer"),
10, 10, // having too small of a size causes division by 0 errors in older MC versions (IE 1.20.1)
1, 1,
(button) -> { });
@@ -643,25 +838,36 @@ class DhConfigScreen extends DhScreen
return false;
}
#if MC_VER <= MC_1_12_2
private ITextComponent GetTranslatableTextComponentForConfig(AbstractConfigBase<?> configType)
#else
private Component GetTranslatableTextComponentForConfig(AbstractConfigBase<?> configType)
#endif
{ return Translatable(TRANSLATION_PREFIX + configType.getNameAndCategory()); }
//endregion
//===========//
// rendering //
//===========//
//region
@Override
#if MC_VER < MC_1_20_1
#if MC_VER <= MC_1_12_2
public void drawScreen(int mouseX, int mouseY, float delta)
#elif MC_VER < MC_1_20_1
public void render(PoseStack matrices, int mouseX, int mouseY, float delta)
#elif MC_VER <= MC_1_21_11
#elif MC_VER <= MC_1_21_11
public void render(GuiGraphics matrices, int mouseX, int mouseY, float delta)
#else
#else
public void extractRenderState(GuiGraphicsExtractor matrices, int mouseX, int mouseY, float delta)
#endif
{
#if MC_VER < MC_1_20_2 // 1.20.2 now enables this by default in the `this.list.render` function
#if MC_VER <= MC_1_12_2
this.drawDefaultBackground();
#elif MC_VER < MC_1_20_2 // 1.20.2 now enables this by default in the `this.list.render` function
this.renderBackground(matrices);
#elif MC_VER <= MC_1_21_11
super.render(matrices, mouseX, mouseY, delta);
@@ -670,7 +876,9 @@ class DhConfigScreen extends DhScreen
#endif
// Render buttons
#if MC_VER <= MC_1_21_11
#if MC_VER <= MC_1_12_2
this.configListWidget.drawScreen(mouseX, mouseY, delta);
#elif MC_VER <= MC_1_21_11
this.configListWidget.render(matrices, mouseX, mouseY, delta);
#else
this.configListWidget.extractRenderState(matrices, mouseX, mouseY, delta);
@@ -678,51 +886,74 @@ class DhConfigScreen extends DhScreen
// Render config title
this.DhDrawCenteredString(matrices, this.font, this.title,
this.DhDrawCenteredString(
#if MC_VER > MC_1_12_2
matrices, this.font,
#endif
this.title,
this.width / 2, 15,
#if MC_VER < MC_1_21_6
0xFFFFFF // RGB white
#else
0xFFFFFFFF // ARGB white
#endif );
#endif);
// render DH version
this.DhDrawString(matrices, this.font, TextOrLiteral(ModInfo.VERSION), 2, this.height - 10,
this.DhDrawString(
#if MC_VER > MC_1_12_2
matrices, this.font,
#endif
TextOrLiteral(ModInfo.VERSION), 2, this.height - 10,
#if MC_VER < MC_1_21_6
0xAAAAAA // RGB white
#else
0xFFAAAAAA // ARGB white
#endif );
#endif);
// If the update is pending, display this message to inform the user that it will apply when the game restarts
if (SelfUpdater.deleteOldJarOnJvmShutdown)
{
this.DhDrawString(matrices, this.font, Translatable(ModInfo.ID + ".updater.waitingForClose"), 4, this.height - 42,
this.DhDrawString(
#if MC_VER > MC_1_12_2
matrices, this.font,
#endif
Translatable(ModInfo.ID + ".updater.waitingForClose"), 4, this.height - 42,
#if MC_VER < MC_1_21_6
0xFFFFFF // RGB white
#else
0xFFFFFFFF // ARGB white
#endif );
#endif);
}
#if MC_VER <= MC_1_12_2
this.renderTooltip(mouseX, mouseY, delta);
#else
this.renderTooltip(matrices, mouseX, mouseY, delta);
#endif
#if MC_VER < MC_1_20_2
#if MC_VER <= MC_1_12_2
super.drawScreen(mouseX, mouseY, delta);
#elif MC_VER < MC_1_20_2
super.render(matrices, mouseX, mouseY, delta);
#endif
}
#if MC_VER < MC_1_20_1
#if MC_VER <= MC_1_12_2
private void renderTooltip(int mouseX, int mouseY, float delta)
#elif MC_VER < MC_1_20_1
private void renderTooltip(PoseStack matrices, int mouseX, int mouseY, float delta)
#elif MC_VER <= MC_1_21_11
private void renderTooltip(GuiGraphics matrices, int mouseX, int mouseY, float delta)
#else
#else
private void renderTooltip(GuiGraphicsExtractor matrices, int mouseX, int mouseY, float delta)
#endif
{
#if MC_VER <= MC_1_12_2
Gui hoveredWidget = this.configListWidget.getHoveredButton(mouseX, mouseY);
#else
AbstractWidget hoveredWidget = this.configListWidget.getHoveredButton(mouseX, mouseY);
#endif
if (hoveredWidget == null)
{
return;
@@ -738,14 +969,20 @@ class DhConfigScreen extends DhScreen
button.dhConfigType;
boolean apiOverrideActive = false;
boolean unsupportedMcVersion = false;
if (configBase instanceof ConfigEntry)
{
apiOverrideActive = ((ConfigEntry<?>) configBase).apiIsOverriding();
unsupportedMcVersion = ((ConfigEntry<?>) configBase).mcVersionOverridePresent();
}
String key = TRANSLATION_PREFIX + (configBase.category.isEmpty() ? "" : configBase.category + ".") + configBase.getName() + ".@tooltip";
if (apiOverrideActive)
if (unsupportedMcVersion)
{
key = "distanthorizons.general.unsupportedMcVersion.@tooltip";
}
else if (apiOverrideActive)
{
key = "distanthorizons.general.disabledByApi.@tooltip";
}
@@ -754,37 +991,136 @@ class DhConfigScreen extends DhScreen
final ConfigGuiInfo configGuiInfo = ((ConfigGuiInfo) configBase.guiValue);
if (configGuiInfo.errorMessage != null)
{
#if MC_VER <= MC_1_12_2
this.DhRenderTooltip(configGuiInfo.errorMessage, mouseX, mouseY);
#else
this.DhRenderTooltip(matrices, this.font, configGuiInfo.errorMessage, mouseX, mouseY);
#endif
}
// display the tooltip if present
else if (LANG_WRAPPER.langExists(key))
{
#if MC_VER <= MC_1_12_2
List<ITextComponent> list = new ArrayList<>();
#else
List<Component> list = new ArrayList<>();
#endif
String lang = LANG_WRAPPER.getLang(key);
for (String langLine : lang.split("\n"))
{
list.add(TextOrTranslatable(langLine));
}
#if MC_VER <= MC_1_12_2
this.DhRenderComponentTooltip(list, mouseX, mouseY);
#else
this.DhRenderComponentTooltip(matrices, this.font, list, mouseX, mouseY);
#endif
}
}
#if MC_VER <= MC_1_12_2
@Override
protected void actionPerformed(GuiButton button)
{
super.actionPerformed(button);
if(button.id == changelogButton_id)
{
ChangelogScreen changelogScreen = new ChangelogScreen(this);
if (changelogScreen.usable)
{
Minecraft.getMinecraft().displayGuiScreen(changelogScreen);
}
else
{
LOGGER.warn("Changelog was not able to open");
}
}
}
@Override
protected void mouseClicked(int mouseX, int mouseY, int mouseButton) throws java.io.IOException
{
super.mouseClicked(mouseX, mouseY, mouseButton);
if (mouseY >= this.configListWidget.top && mouseY <= this.configListWidget.bottom)
{
for (ClassicConfigGUI.DhButtonEntry entry : this.configListWidget.children)
{
if (entry.button instanceof GuiButton btn && btn.visible)
{
if (btn.mousePressed(this.mc, mouseX, mouseY))
{
btn.playPressSound(this.mc.getSoundHandler());
OnPressed handler = GuiHelper.HANDLER_BY_BUTTON.get(btn);
if (handler != null) handler.pressed(btn);
}
}
else if (entry.button instanceof GuiTextField field && field.getVisible())
{
field.mouseClicked(mouseX, mouseY, mouseButton);
}
if (entry.resetButton instanceof GuiButton reset && reset.visible)
{
if (reset.mousePressed(this.mc, mouseX, mouseY))
{
reset.playPressSound(this.mc.getSoundHandler());
OnPressed handler = GuiHelper.HANDLER_BY_BUTTON.get(reset);
if (handler != null) handler.pressed(reset);
}
}
}
}
}
@Override
protected void keyTyped(char typedChar, int keyCode) throws java.io.IOException
{
super.keyTyped(typedChar, keyCode);
for (ClassicConfigGUI.DhButtonEntry entry : this.configListWidget.children)
{
if (entry.button instanceof GuiTextField field)
{
field.textboxKeyTyped(typedChar, keyCode);
}
}
}
@Override
public void handleMouseInput() throws java.io.IOException
{
super.handleMouseInput();
this.configListWidget.handleMouseInput();
}
#endif
//endregion
//==========//
// shutdown //
//==========//
//region
/** When you close it, it goes to the previous screen and saves */
@Override
#if MC_VER <= MC_1_12_2
public void onGuiClosed()
#else
public void onClose()
#endif
{
ConfigHandler.INSTANCE.configFileHandler.saveToFile();
#if MC_VER <= MC_1_12_2
// Handled by button to avoid recursive loop
#else
DhScreenUtil.setScreen(this.parent);
#endif
ClassicConfigGUI.CONFIG_CORE_INTERFACE.onScreenChangeListenerList.forEach((listener) -> listener.run());
}
//endregion
}
@@ -188,7 +188,7 @@ public class UpdateModScreen extends DhScreen
MakeBtn(Translatable(ModInfo.ID + ".updater.update"), this.width / 2 - 75, this.height / 2 + 8, 150, 20, (btn) -> {
SelfUpdater.updateMod();
#if MC_VER <= MC_1_12_2
Objects.requireNonNull(this.mc).displayGuiScreen(this.parent);
DhScreenUtil.setScreen(this.parent);
#else
this.onClose();
#endif
@@ -199,7 +199,7 @@ public class UpdateModScreen extends DhScreen
Config.Client.Advanced.AutoUpdater.enableSilentUpdates.set(true);
SelfUpdater.updateMod();
#if MC_VER <= MC_1_12_2
Objects.requireNonNull(this.mc).displayGuiScreen(this.parent);
DhScreenUtil.setScreen(this.parent);
#else
this.onClose();
#endif
@@ -208,7 +208,7 @@ public class UpdateModScreen extends DhScreen
this.addBtn( // Later (not now)
MakeBtn(Translatable(ModInfo.ID + ".updater.later"), this.width / 2 + 2, this.height / 2 + 70, 100, 20, (btn) -> {
#if MC_VER <= MC_1_12_2
Objects.requireNonNull(this.mc).displayGuiScreen(this.parent);
DhScreenUtil.setScreen(this.parent);
#else
this.onClose();
#endif
@@ -218,7 +218,7 @@ public class UpdateModScreen extends DhScreen
MakeBtn(Translatable(ModInfo.ID + ".updater.never"), this.width / 2 - 102, this.height / 2 + 70, 100, 20, (btn) -> {
Config.Client.Advanced.AutoUpdater.enableAutoUpdater.set(false);
#if MC_VER <= MC_1_12_2
Objects.requireNonNull(this.mc).displayGuiScreen(this.parent);
DhScreenUtil.setScreen(this.parent);
#else
this.onClose();
#endif
@@ -8,8 +8,6 @@ import org.jetbrains.annotations.Nullable;
import net.minecraft.resources.ResourceKey;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.world.level.Level;
#else
import net.minecraft.world.WorldServer;
#endif
#if MC_VER <= MC_1_12_2
@@ -29,13 +27,16 @@ public abstract class AbstractMinecraftSharedWrapper implements IMinecraftShared
{
@Nullable
#if MC_VER <= MC_1_12_2
protected Integer deserializeDimensionResourceKey(String dimensionResourceLocation)
#else
protected ResourceKey<Level> deserializeDimensionResourceKey(String dimensionResourceLocation)
#endif
{
#if MC_VER <= MC_1_12_2
int dimensionID;
try
{
dimensionID = Integer.parseInt(dimensionResourceLocation.substring(dimensionResourceLocation.indexOf(":")+1));
return Integer.parseInt(dimensionResourceLocation.substring(dimensionResourceLocation.indexOf(":")+1));
}
catch (NumberFormatException ignored)
{
@@ -57,9 +58,9 @@ public abstract class AbstractMinecraftSharedWrapper implements IMinecraftShared
#else
ResourceKey<Level> dimensionKey = ResourceKey.create(Registry.DIMENSION_REGISTRY, dimResourceLocation);
#endif
#endif
return dimensionKey;
#endif
}
}
@@ -648,11 +648,16 @@ public class MinecraftClientWrapper extends AbstractMinecraftSharedWrapper imple
return null;
}
ResourceKey<Level> dimensionKey = this.deserializeDimensionResourceKey(dimensionResourceLocation);
#if MC_VER <= MC_1_12_2
Integer dimensionKey = this.deserializeDimensionResourceKey(dimensionResourceLocation);
if (dimensionKey == null || MINECRAFT.getIntegratedServer() == null)
{
return null;
}
WorldServer mcLevel = MINECRAFT.getIntegratedServer().getWorld(dimensionKey);
#else
ResourceKey<Level> dimensionKey = this.deserializeDimensionResourceKey(dimensionResourceLocation);
ServerLevel mcLevel = MINECRAFT.getSingleplayerServer().getLevel(dimensionKey);
#endif
return ServerLevelWrapper.getWrapper(mcLevel);
@@ -28,8 +28,8 @@ import org.jetbrains.annotations.Nullable;
#if MC_VER > MC_1_12_2
import com.mojang.blaze3d.pipeline.RenderTarget;
import com.mojang.blaze3d.platform.NativeImage;
#endif
import com.mojang.blaze3d.systems.RenderSystem;
#endif
import com.seibel.distanthorizons.api.enums.config.EDhApiLodShading;
import com.seibel.distanthorizons.common.wrappers.McObjectConverter;
import com.seibel.distanthorizons.common.wrappers.misc.LightMapWrapper;
@@ -236,8 +236,9 @@ public class MinecraftRenderWrapper implements IMinecraftRenderWrapper
#if MC_VER <= MC_1_12_2
RenderManager rm = MC.getRenderManager();
return new Vec3d(rm.viewerPosX, rm.viewerPosY, rm.viewerPosZ);
#elif MC_VER <= MC_26_1_2
return new DhVec3d(rm.viewerPosX, rm.viewerPosY, rm.viewerPosZ);
#else
#if MC_VER <= MC_26_1_2
Camera camera = MC.gameRenderer.getMainCamera();
#else
Camera camera = MC.gameRenderer.mainCamera();
@@ -249,6 +250,7 @@ public class MinecraftRenderWrapper implements IMinecraftRenderWrapper
Vec3 projectedView = camera.position();
#endif
return new DhVec3d(projectedView.x, projectedView.y, projectedView.z);
#endif
}
@Override
@@ -95,11 +95,15 @@ public class MinecraftServerWrapper extends AbstractMinecraftSharedWrapper
throw new IllegalStateException("Trying to get the server mcLevel before dedicated server completed initialization!");
}
ResourceKey<Level> dimensionKey = this.deserializeDimensionResourceKey(dimensionResourceLocation);
#if MC_VER <= MC_1_12_2
Integer dimensionKey = this.deserializeDimensionResourceKey(dimensionResourceLocation);
if (dimensionKey == null)
{
return null;
}
WorldServer mcLevel = dedicatedServer.getWorld(dimensionKey);
#else
ResourceKey<Level> dimensionKey = this.deserializeDimensionResourceKey(dimensionResourceLocation);
ServerLevel mcLevel = dedicatedServer.getLevel(dimensionKey);
#endif
return ServerLevelWrapper.getWrapper(mcLevel);
@@ -129,7 +129,7 @@ public class ServerPlayerWrapper implements IServerPlayerWrapper
{
#if MC_VER <= MC_1_12_2
BlockPos position = this.getServerPlayer().getPosition();
return new Vec3d(position.getX(), position.getY(), position.getZ());
return new DhVec3d(position.getX(), position.getY(), position.getZ());
#else
Vec3 position = this.getServerPlayer().position();
return new DhVec3d(position.x, position.y, position.z);
@@ -56,7 +56,6 @@ import java.util.concurrent.*;
import java.util.function.Consumer;
import com.seibel.distanthorizons.coreapi.ModInfo;
import net.minecraft.world.level.levelgen.Heightmap;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@@ -78,6 +77,7 @@ import net.minecraft.world.level.chunk.*;
import net.minecraft.world.level.levelgen.DebugLevelSource;
import net.minecraft.world.level.levelgen.FlatLevelSource;
import net.minecraft.world.level.levelgen.NoiseBasedChunkGenerator;
import net.minecraft.world.level.levelgen.Heightmap;
#endif