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