From e26191aaf715045e7201dfeb021ce24621dad4d6 Mon Sep 17 00:00:00 2001 From: zelophed Date: Thu, 25 Mar 2021 02:27:10 +0100 Subject: [PATCH] GuiGameReposition - adjust the position of the item renderer for gui elements - include a warning when joining a world while fabulous graphics are enabled --- .../com/simibubi/create/CreateClient.java | 29 +++++++++++++++++++ .../create/compat/jei/DoubleItemIcon.java | 4 +-- .../category/BlockzapperUpgradeCategory.java | 2 +- .../category/MechanicalCraftingCategory.java | 6 ++-- .../jei/category/PolishingCategory.java | 10 +++---- .../goggles/GoggleConfigScreen.java | 5 ++-- .../goggles/GoggleOverlayRenderer.java | 6 +--- .../sequencer/SequencedGearshiftScreen.java | 2 +- .../curiosities/zapper/ZapperScreen.java | 2 +- .../inventories/AdjustableCrateScreen.java | 2 +- .../block/redstone/StockpileSwitchScreen.java | 2 +- .../block/SchematicTableScreen.java | 2 +- .../block/SchematicannonScreen.java | 6 ++-- .../client/SchematicEditScreen.java | 8 ++--- .../client/SchematicPromptScreen.java | 7 ++--- .../simibubi/create/events/ClientEvents.java | 6 ++++ .../foundation/command/AllCommands.java | 1 + .../command/ConfigureConfigPacket.java | 8 +++++ .../command/FabulousWarningCommand.java | 29 +++++++++++++++++++ .../create/foundation/config/CClient.java | 1 + .../gui/AbstractSimiContainerScreen.java | 6 ++++ .../create/foundation/gui/GuiGameElement.java | 2 +- .../create/foundation/ponder/PonderUI.java | 4 +-- .../ponder/content/PonderTagScreen.java | 2 +- .../ponder/elements/TextWindowElement.java | 9 ++---- .../foundation/ponder/ui/PonderButton.java | 4 +-- .../create/foundation/utility/FontHelper.java | 5 ++-- 27 files changed, 118 insertions(+), 52 deletions(-) create mode 100644 src/main/java/com/simibubi/create/foundation/command/FabulousWarningCommand.java diff --git a/src/main/java/com/simibubi/create/CreateClient.java b/src/main/java/com/simibubi/create/CreateClient.java index cd696310b..9a7038edb 100644 --- a/src/main/java/com/simibubi/create/CreateClient.java +++ b/src/main/java/com/simibubi/create/CreateClient.java @@ -9,6 +9,7 @@ import com.simibubi.create.content.schematics.client.SchematicHandler; import com.simibubi.create.foundation.ResourceReloadHandler; import com.simibubi.create.foundation.block.render.CustomBlockModels; import com.simibubi.create.foundation.block.render.SpriteShifter; +import com.simibubi.create.foundation.config.AllConfigs; import com.simibubi.create.foundation.gui.UIRenderHelper; import com.simibubi.create.foundation.item.CustomItemModels; import com.simibubi.create.foundation.item.CustomRenderedItems; @@ -28,11 +29,19 @@ import net.minecraft.client.Minecraft; import net.minecraft.client.renderer.BlockModelShapes; import net.minecraft.client.renderer.model.IBakedModel; import net.minecraft.client.renderer.model.ModelResourceLocation; +import net.minecraft.client.settings.GraphicsFanciness; import net.minecraft.inventory.container.PlayerContainer; import net.minecraft.item.Item; import net.minecraft.resources.IReloadableResourceManager; import net.minecraft.resources.IResourceManager; import net.minecraft.util.ResourceLocation; +import net.minecraft.util.text.ChatType; +import net.minecraft.util.text.IFormattableTextComponent; +import net.minecraft.util.text.StringTextComponent; +import net.minecraft.util.text.TextComponentUtils; +import net.minecraft.util.text.TextFormatting; +import net.minecraft.util.text.event.ClickEvent; +import net.minecraft.util.text.event.HoverEvent; import net.minecraft.world.IWorld; import net.minecraftforge.client.event.ModelBakeEvent; import net.minecraftforge.client.event.ModelRegistryEvent; @@ -212,4 +221,24 @@ public class CreateClient { ContraptionRenderDispatcher.invalidateAll(); } + + public static void checkGraphicsFanciness() { + Minecraft mc = Minecraft.getInstance(); + if (mc.player == null) + return; + + if (mc.gameSettings.graphicsMode != GraphicsFanciness.FABULOUS) + return; + + if (AllConfigs.CLIENT.ignoreFabulousWarning.get()) + return; + + IFormattableTextComponent text = TextComponentUtils.bracketed(new StringTextComponent("WARN")).formatted(TextFormatting.GOLD) + .append(new StringTextComponent(" Some of Create's visual features will not be available while Fabulous graphics are enabled!")) + .styled(style -> style + .withClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/create dismissFabulousWarning")) + .withHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new StringTextComponent("Click here to disable this warning")))); + + mc.ingameGUI.addChatMessage(ChatType.CHAT, text, mc.player.getUniqueID()); + } } diff --git a/src/main/java/com/simibubi/create/compat/jei/DoubleItemIcon.java b/src/main/java/com/simibubi/create/compat/jei/DoubleItemIcon.java index 7d5bb125c..2771ecc7f 100644 --- a/src/main/java/com/simibubi/create/compat/jei/DoubleItemIcon.java +++ b/src/main/java/com/simibubi/create/compat/jei/DoubleItemIcon.java @@ -46,12 +46,12 @@ public class DoubleItemIcon implements IDrawable { matrixStack.translate(xOffset, yOffset, 0); matrixStack.push(); - matrixStack.translate(1, 17, 0); + matrixStack.translate(1, 1, 0); GuiGameElement.of(primaryStack).render(matrixStack); matrixStack.pop(); matrixStack.push(); - matrixStack.translate(10, 19, 100); + matrixStack.translate(10, 10, 100); matrixStack.scale(.5f, .5f, .5f); GuiGameElement.of(secondaryStack).render(matrixStack); matrixStack.pop(); diff --git a/src/main/java/com/simibubi/create/compat/jei/category/BlockzapperUpgradeCategory.java b/src/main/java/com/simibubi/create/compat/jei/category/BlockzapperUpgradeCategory.java index b7e28375a..581ebc9cd 100644 --- a/src/main/java/com/simibubi/create/compat/jei/category/BlockzapperUpgradeCategory.java +++ b/src/main/java/com/simibubi/create/compat/jei/category/BlockzapperUpgradeCategory.java @@ -88,7 +88,7 @@ public class BlockzapperUpgradeCategory extends CreateRecipeCategory Actions::overlayReset), experimentalRendering(() -> Actions::experimentalRendering), openPonder(() -> Actions::openPonder), + fabulousWarning(() -> Actions::fabulousWarning) ; @@ -161,6 +163,12 @@ public class ConfigureConfigPacket extends SimplePacketBase { } + @OnlyIn(Dist.CLIENT) + private static void fabulousWarning(String value) { + AllConfigs.CLIENT.ignoreFabulousWarning.set(true); + Minecraft.getInstance().ingameGUI.addChatMessage(ChatType.CHAT, new StringTextComponent("Disabled Fabulous graphics warning"), Minecraft.getInstance().player.getUniqueID()); + } + private static IFormattableTextComponent boolToText(boolean b) { return b ? new StringTextComponent("enabled").formatted(TextFormatting.DARK_GREEN) diff --git a/src/main/java/com/simibubi/create/foundation/command/FabulousWarningCommand.java b/src/main/java/com/simibubi/create/foundation/command/FabulousWarningCommand.java new file mode 100644 index 000000000..9a417a1a4 --- /dev/null +++ b/src/main/java/com/simibubi/create/foundation/command/FabulousWarningCommand.java @@ -0,0 +1,29 @@ +package com.simibubi.create.foundation.command; + +import net.minecraft.command.CommandSource; +import net.minecraft.command.Commands; +import net.minecraft.entity.player.ServerPlayerEntity; +import net.minecraftforge.fml.network.PacketDistributor; + +import com.mojang.brigadier.Command; +import com.mojang.brigadier.builder.ArgumentBuilder; +import com.simibubi.create.foundation.networking.AllPackets; + +public class FabulousWarningCommand { + + public static ArgumentBuilder register() { + return Commands.literal("dismissFabulousWarning") + .requires(AllCommands.sourceIsPlayer) + .executes(ctx -> { + ServerPlayerEntity player = ctx.getSource().asPlayer(); + + AllPackets.channel.send( + PacketDistributor.PLAYER.with(() -> player), + new ConfigureConfigPacket(ConfigureConfigPacket.Actions.fabulousWarning.name(), "") + ); + + return Command.SINGLE_SUCCESS; + }); + + } +} diff --git a/src/main/java/com/simibubi/create/foundation/config/CClient.java b/src/main/java/com/simibubi/create/foundation/config/CClient.java index fbd8c1d7a..7b084d986 100644 --- a/src/main/java/com/simibubi/create/foundation/config/CClient.java +++ b/src/main/java/com/simibubi/create/foundation/config/CClient.java @@ -19,6 +19,7 @@ public class CClient extends ConfigBase { public ConfigInt overlayOffsetX = i(20, Integer.MIN_VALUE, Integer.MAX_VALUE, "overlayOffsetX", "Offset the overlay from goggle- and hover- information by this many pixels on the X axis; Use /create overlay"); public ConfigInt overlayOffsetY = i(0, Integer.MIN_VALUE, Integer.MAX_VALUE, "overlayOffsetY", "Offset the overlay from goggle- and hover- information by this many pixels on the Y axis; Use /create overlay"); public ConfigBool smoothPlacementIndicator = b(false, "smoothPlacementIndicator", "Use an alternative indicator when showing where the assisted placement ends up relative to your crosshair"); + public ConfigBool ignoreFabulousWarning = b(false, "ignoreFabulousWarning", "Setting this to true will prevent Create from sending you a warning when playing with Fabulous graphics enabled"); @Override public String getName() { diff --git a/src/main/java/com/simibubi/create/foundation/gui/AbstractSimiContainerScreen.java b/src/main/java/com/simibubi/create/foundation/gui/AbstractSimiContainerScreen.java index 726dbb8c3..13096722a 100644 --- a/src/main/java/com/simibubi/create/foundation/gui/AbstractSimiContainerScreen.java +++ b/src/main/java/com/simibubi/create/foundation/gui/AbstractSimiContainerScreen.java @@ -43,6 +43,12 @@ public abstract class AbstractSimiContainerScreen extends C this.ySize = height; } + @Override + protected void drawForeground(MatrixStack p_230451_1_, int p_230451_2_, int p_230451_3_) { + //no-op to prevent screen- and inventory-title from being rendered at incorrect location + //could also set this.titleX/Y and this.playerInventoryTitleX/Y to the proper values instead + } + @Override public void render(MatrixStack matrixStack, int mouseX, int mouseY, float partialTicks) { partialTicks = Minecraft.getInstance().getRenderPartialTicks(); diff --git a/src/main/java/com/simibubi/create/foundation/gui/GuiGameElement.java b/src/main/java/com/simibubi/create/foundation/gui/GuiGameElement.java index 57a0b8f1c..e87bb3457 100644 --- a/src/main/java/com/simibubi/create/foundation/gui/GuiGameElement.java +++ b/src/main/java/com/simibubi/create/foundation/gui/GuiGameElement.java @@ -304,7 +304,7 @@ public class GuiGameElement { GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA); RenderSystem.color4f(1.0F, 1.0F, 1.0F, 1.0F); matrixStack.translate((float) 0, (float) 0, 100.0F + renderer.zLevel); - matrixStack.translate(8.0F, 8.0F, 0.0F); + matrixStack.translate(8.0F, -8.0F, 0.0F); matrixStack.scale(16.0F, 16.0F, 16.0F); IRenderTypeBuffer.Impl irendertypebuffer$impl = Minecraft.getInstance() .getBufferBuilders() diff --git a/src/main/java/com/simibubi/create/foundation/ponder/PonderUI.java b/src/main/java/com/simibubi/create/foundation/ponder/PonderUI.java index a69ba1377..75631f3ff 100644 --- a/src/main/java/com/simibubi/create/foundation/ponder/PonderUI.java +++ b/src/main/java/com/simibubi/create/foundation/ponder/PonderUI.java @@ -491,7 +491,7 @@ public class PonderUI extends NavigatableSimiScreen { { // Chapter title ms.push(); - ms.translate(0, 0, 800); + ms.translate(0, 0, 100); int x = 31 + 20 + 8; int y = 31; @@ -515,7 +515,7 @@ public class PonderUI extends NavigatableSimiScreen { ms.translate(x, y, 0); ms.multiply(Vector3f.NEGATIVE_X.getDegreesQuaternion(indexDiff * -75)); ms.translate(0, 0, 5); - FontHelper.drawSplitString(textRenderer, title, 0, 0, left.x - 51, + FontHelper.drawSplitString(ms, textRenderer, title, 0, 0, left.x - 51, ColorHelper.applyAlpha(textColor, 1 - indexDiff)); ms.pop(); diff --git a/src/main/java/com/simibubi/create/foundation/ponder/content/PonderTagScreen.java b/src/main/java/com/simibubi/create/foundation/ponder/content/PonderTagScreen.java index 3303055cb..2a27efe66 100644 --- a/src/main/java/com/simibubi/create/foundation/ponder/content/PonderTagScreen.java +++ b/src/main/java/com/simibubi/create/foundation/ponder/content/PonderTagScreen.java @@ -220,7 +220,7 @@ public class PonderTagScreen extends NavigatableSimiScreen { PonderUI.renderBox(ms, x - 3, y - 3, w + 6, h + 6, false); ms.translate(0, 0, 100); - FontHelper.drawSplitString(textRenderer, desc, x, y, w, 0xeeeeee); + FontHelper.drawSplitString(ms, textRenderer, desc, x, y, w, 0xeeeeee); ms.pop(); } diff --git a/src/main/java/com/simibubi/create/foundation/ponder/elements/TextWindowElement.java b/src/main/java/com/simibubi/create/foundation/ponder/elements/TextWindowElement.java index 4c98c7450..d46f93b05 100644 --- a/src/main/java/com/simibubi/create/foundation/ponder/elements/TextWindowElement.java +++ b/src/main/java/com/simibubi/create/foundation/ponder/elements/TextWindowElement.java @@ -9,6 +9,7 @@ import com.simibubi.create.foundation.ponder.PonderScene; import com.simibubi.create.foundation.ponder.PonderUI; import com.simibubi.create.foundation.ponder.content.PonderPalette; import com.simibubi.create.foundation.utility.ColorHelper; +import com.simibubi.create.foundation.utility.FontHelper; import net.minecraft.util.math.MathHelper; import net.minecraft.util.math.vector.Matrix4f; @@ -124,12 +125,8 @@ public class TextWindowElement extends AnimatedOverlayElement { ms.pop(); } - for (int i = 0; i < lines.size(); i++) { - ITextProperties s = lines.get(i); - // FIXME: Probably completely broken - screen.getFontRenderer() - .drawTrimmed(s, 20, targetX - 10, 3 + 9 * i, ColorHelper.applyAlpha(brighterColor, fade)); - } + FontHelper.drawSplitString(ms, screen.getFontRenderer(), bakedText, targetX - 10, 3, textWidth, + ColorHelper.applyAlpha(brighterColor, fade)); ms.pop(); } diff --git a/src/main/java/com/simibubi/create/foundation/ponder/ui/PonderButton.java b/src/main/java/com/simibubi/create/foundation/ponder/ui/PonderButton.java index b100a4a6f..08c85e309 100644 --- a/src/main/java/com/simibubi/create/foundation/ponder/ui/PonderButton.java +++ b/src/main/java/com/simibubi/create/foundation/ponder/ui/PonderButton.java @@ -111,7 +111,7 @@ public class PonderButton extends AbstractSimiWidget { borderColorEnd = ColorHelper.applyAlpha(borderColorEnd, fade); PonderUI.renderBox(ms, x, y, width, height, backgroundColor, borderColorStart, borderColorEnd); - ms.translate(0, 0, 800); + ms.translate(0, 0, 100); if (icon != null) { RenderSystem.enableBlend(); @@ -124,7 +124,7 @@ public class PonderButton extends AbstractSimiWidget { } if (item != null) { ms.push(); - ms.translate(0, 0, -800); + ms.translate(0, 0, -100); GuiGameElement.of(item) .at(x - 2, y - 2) .scale(1.5f) diff --git a/src/main/java/com/simibubi/create/foundation/utility/FontHelper.java b/src/main/java/com/simibubi/create/foundation/utility/FontHelper.java index 22bccb551..f6f01be5e 100644 --- a/src/main/java/com/simibubi/create/foundation/utility/FontHelper.java +++ b/src/main/java/com/simibubi/create/foundation/utility/FontHelper.java @@ -4,6 +4,7 @@ import java.text.BreakIterator; import java.util.LinkedList; import java.util.List; +import com.mojang.blaze3d.matrix.MatrixStack; import net.minecraft.client.gui.FontRenderer; import net.minecraft.client.renderer.IRenderTypeBuffer; import net.minecraft.client.renderer.Tessellator; @@ -52,9 +53,9 @@ public final class FontHelper { return lines; } - public static void drawSplitString(FontRenderer font, String text, int x, int y, int width, int color) { + public static void drawSplitString(MatrixStack ms, FontRenderer font, String text, int x, int y, int width, int color) { List list = cutString(font, text, width); - Matrix4f matrix4f = TransformationMatrix.identity().getMatrix(); + Matrix4f matrix4f = ms.peek().getModel(); for (String s : list) { float f = (float) x;