mirror of
https://github.com/PuzzleMC/Puzzle.git
synced 2025-12-16 03:45:10 +01:00
Port to 1.21.4
- Improved error handling - Update LambDynamicLights - Fix splash screen background blending once again
This commit is contained in:
@@ -16,7 +16,6 @@ public class LDLCompat {
|
||||
PuzzleApi.addToGraphicsOptions(new PuzzleWidget(Text.of("LambDynamicLights")));
|
||||
PuzzleApi.addToGraphicsOptions(new PuzzleWidget(Text.translatable("lambdynlights.option.mode"), (button) -> button.setMessage(ldlConfig.getDynamicLightsMode().getTranslatedText()), (button) -> ldlConfig.setDynamicLightsMode(ldlConfig.getDynamicLightsMode().next())));
|
||||
PuzzleApi.addToGraphicsOptions(new PuzzleWidget(Text.empty().append("DynLights: ").append(Text.translatable("lambdynlights.option.light_sources.entities")), (button) -> button.setMessage(ldlConfig.getEntitiesLightSource().get() ? YES : NO), (button) -> ldlConfig.getEntitiesLightSource().set(!ldlConfig.getEntitiesLightSource().get())));
|
||||
PuzzleApi.addToGraphicsOptions(new PuzzleWidget(Text.empty().append("DynLights: ").append(Text.translatable("lambdynlights.option.light_sources.block_entities")), (button) -> button.setMessage(ldlConfig.getBlockEntitiesLightSource().get() ? YES : NO), (button) -> ldlConfig.getBlockEntitiesLightSource().set(!ldlConfig.getBlockEntitiesLightSource().get())));
|
||||
PuzzleApi.addToGraphicsOptions(new PuzzleWidget(Text.empty().append("DynLights: ").append(Text.translatable("entity.minecraft.creeper")), (button) -> button.setMessage(ldlConfig.getCreeperLightingMode().getTranslatedText()), (button) -> ldlConfig.setCreeperLightingMode(ldlConfig.getCreeperLightingMode().next())));
|
||||
PuzzleApi.addToGraphicsOptions(new PuzzleWidget(Text.empty().append("DynLights: ").append(Text.translatable("block.minecraft.tnt")), (button) -> button.setMessage(ldlConfig.getTntLightingMode().getTranslatedText()), (button) -> ldlConfig.setTntLightingMode(ldlConfig.getTntLightingMode().next())));
|
||||
PuzzleApi.addToGraphicsOptions(new PuzzleWidget(Text.empty().append("DynLights: ").append(Text.translatable("lambdynlights.option.light_sources.water_sensitive_check")), (button) -> button.setMessage(ldlConfig.getWaterSensitiveCheck().get() ? YES : NO), (button) -> ldlConfig.getWaterSensitiveCheck().set(!ldlConfig.getWaterSensitiveCheck().get())));
|
||||
|
||||
@@ -86,7 +86,7 @@ public class PuzzleOptionsScreen extends Screen {
|
||||
prevTab = tabManager.getCurrentTab();
|
||||
this.list.clear();
|
||||
fillList();
|
||||
list.setScrollAmount(0);
|
||||
list.setScrollY(0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -31,16 +31,22 @@ public class PuzzleOptionListWidget extends MidnightConfig.MidnightConfigListWid
|
||||
public void addAll(List<PuzzleWidget> buttons) {
|
||||
int buttonX = this.width - 160;
|
||||
for (PuzzleWidget button : buttons) {
|
||||
if (button.buttonType == ButtonType.TEXT)
|
||||
this.addButton(List.of(), Text.literal(" ").append(button.descriptionText).formatted(Formatting.BOLD));
|
||||
else if (button.buttonType == ButtonType.BUTTON)
|
||||
this.addButton(List.of(new PuzzleButtonWidget(buttonX, 0, 150, 20, button.buttonTextAction, button.onPress)), button.descriptionText);
|
||||
else if (button.buttonType == ButtonType.SLIDER)
|
||||
this.addButton(List.of(new PuzzleSliderWidget(button.min, button.max, buttonX, 0, 150, 20, button.defaultSliderValue.getAsInt(), button.buttonTextAction, button.changeSliderValue)), button.descriptionText);
|
||||
else if (button.buttonType == ButtonType.TEXT_FIELD)
|
||||
this.addButton(List.of(new PuzzleTextFieldWidget(textRenderer, buttonX, 0, 150, 20, button.setTextValue, button.changeTextValue)), button.descriptionText);
|
||||
else
|
||||
LOGGER.warn("Button {} is missing the buttonType variable. This shouldn't happen!", button);
|
||||
try {
|
||||
if (button.buttonType == ButtonType.TEXT)
|
||||
this.addButton(List.of(), Text.literal(" ").append(button.descriptionText).formatted(Formatting.BOLD));
|
||||
else if (button.buttonType == ButtonType.BUTTON)
|
||||
this.addButton(List.of(new PuzzleButtonWidget(buttonX, 0, 150, 20, button.buttonTextAction, button.onPress)), button.descriptionText);
|
||||
else if (button.buttonType == ButtonType.SLIDER)
|
||||
this.addButton(List.of(new PuzzleSliderWidget(button.min, button.max, buttonX, 0, 150, 20, button.defaultSliderValue.getAsInt(), button.buttonTextAction, button.changeSliderValue)), button.descriptionText);
|
||||
else if (button.buttonType == ButtonType.TEXT_FIELD)
|
||||
this.addButton(List.of(new PuzzleTextFieldWidget(textRenderer, buttonX, 0, 150, 20, button.setTextValue, button.changeTextValue)), button.descriptionText);
|
||||
else
|
||||
LOGGER.warn("Button {} is missing the buttonType variable. This shouldn't happen!", button);
|
||||
}
|
||||
catch (Exception e) {
|
||||
LOGGER.error("Failed to add button {}. Likely caused by an update of the specific mod.", button.descriptionText);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
public void addButton(List<ClickableWidget> buttons, Text text) {
|
||||
|
||||
@@ -3,6 +3,7 @@ package net.puzzlemc.splashscreen;
|
||||
import eu.midnightdust.lib.util.MidnightColorUtil;
|
||||
import eu.midnightdust.lib.util.PlatformFunctions;
|
||||
import net.minecraft.client.texture.NativeImageBackedTexture;
|
||||
import net.minecraft.client.texture.TextureContents;
|
||||
import net.minecraft.resource.*;
|
||||
import net.minecraft.util.Util;
|
||||
import net.puzzlemc.core.config.PuzzleConfig;
|
||||
@@ -137,14 +138,15 @@ public class PuzzleSplashScreen {
|
||||
public static class LogoTexture extends ResourceTexture {
|
||||
public LogoTexture(Identifier logo) { super(logo); }
|
||||
|
||||
protected TextureData loadTextureData(ResourceManager resourceManager) {
|
||||
@Override
|
||||
public TextureContents loadContents(ResourceManager resourceManager) {
|
||||
MinecraftClient minecraftClient = MinecraftClient.getInstance();
|
||||
DefaultResourcePack defaultResourcePack = minecraftClient.getDefaultResourcePack();
|
||||
try {
|
||||
InputStream inputStream = Objects.requireNonNull(defaultResourcePack.open(ResourceType.CLIENT_RESOURCES, LOGO)).get();
|
||||
TextureData var6;
|
||||
TextureContents var6;
|
||||
try {
|
||||
var6 = new TextureData(new TextureResourceMetadata(true, true), NativeImage.read(inputStream));
|
||||
var6 = new TextureContents(NativeImage.read(inputStream), new TextureResourceMetadata(true, true));
|
||||
} finally {
|
||||
if (inputStream != null) {
|
||||
inputStream.close();
|
||||
@@ -152,7 +154,7 @@ public class PuzzleSplashScreen {
|
||||
}
|
||||
return var6;
|
||||
} catch (IOException var18) {
|
||||
return new TextureData(var18);
|
||||
return TextureContents.createMissing();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -161,13 +163,18 @@ public class PuzzleSplashScreen {
|
||||
public DynamicLogoTexture() {
|
||||
super(LOGO);
|
||||
}
|
||||
protected TextureData loadTextureData(ResourceManager resourceManager) {
|
||||
@Override
|
||||
public TextureContents loadContents(ResourceManager resourceManager) {
|
||||
try {
|
||||
InputStream input = new FileInputStream(String.valueOf(PuzzleSplashScreen.LOGO_TEXTURE));
|
||||
return new TextureData(new TextureResourceMetadata(true, true), NativeImage.read(input));
|
||||
return new TextureContents(NativeImage.read(input), new TextureResourceMetadata(true, true));
|
||||
} catch (IOException e) {
|
||||
LOGGER.error("Encountered an error during logo loading: ", e);
|
||||
return TextureData.load(resourceManager, LOGO);
|
||||
try {
|
||||
return TextureContents.load(resourceManager, LOGO);
|
||||
} catch (IOException ex) {
|
||||
return TextureContents.createMissing();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,6 +9,7 @@ import net.minecraft.client.gui.screen.SplashOverlay;
|
||||
import net.minecraft.client.render.*;
|
||||
import net.minecraft.client.texture.NativeImage;
|
||||
import net.minecraft.client.texture.NativeImageBackedTexture;
|
||||
import net.minecraft.client.texture.TextureManager;
|
||||
import net.minecraft.util.Identifier;
|
||||
import net.minecraft.util.Util;
|
||||
import net.minecraft.util.math.ColorHelper;
|
||||
@@ -42,16 +43,16 @@ public abstract class MixinSplashScreen extends Overlay {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Inject(method = "init(Lnet/minecraft/client/MinecraftClient;)V", at = @At("TAIL"))
|
||||
private static void puzzle$initSplashscreen(MinecraftClient client, CallbackInfo ci) { // Load our custom textures at game start //
|
||||
@Inject(method = "init", at = @At("TAIL"))
|
||||
private static void puzzle$initSplashscreen(TextureManager textureManager, CallbackInfo ci) { // Load our custom textures at game start //
|
||||
if (PuzzleConfig.resourcepackSplashScreen) {
|
||||
if (PuzzleSplashScreen.LOGO_TEXTURE.toFile().exists()) {
|
||||
client.getTextureManager().registerTexture(LOGO, new PuzzleSplashScreen.DynamicLogoTexture());
|
||||
textureManager.registerTexture(LOGO, new PuzzleSplashScreen.DynamicLogoTexture());
|
||||
}
|
||||
if (PuzzleSplashScreen.BACKGROUND_TEXTURE.toFile().exists()) {
|
||||
try {
|
||||
InputStream input = new FileInputStream(String.valueOf(PuzzleSplashScreen.BACKGROUND_TEXTURE));
|
||||
client.getTextureManager().registerTexture(BACKGROUND, new NativeImageBackedTexture(NativeImage.read(input)));
|
||||
textureManager.registerTexture(BACKGROUND, new NativeImageBackedTexture(NativeImage.read(input)));
|
||||
} catch (IOException ignored) {}
|
||||
}
|
||||
}
|
||||
@@ -93,6 +94,7 @@ public abstract class MixinSplashScreen extends Overlay {
|
||||
RenderSystem.enableBlend();
|
||||
RenderSystem.blendEquation(32774);
|
||||
RenderSystem.defaultBlendFunc();
|
||||
context.getMatrices().translate(0, 0, 1f);
|
||||
context.drawTexture(RenderLayer::getGuiTextured, BACKGROUND, 0, 0, 0, 0, width, height, width, height, ColorHelper.getWhite(s));
|
||||
RenderSystem.defaultBlendFunc();
|
||||
RenderSystem.disableBlend();
|
||||
|
||||
Reference in New Issue
Block a user