From 415e4166c26615bc95657533589b60100911236e Mon Sep 17 00:00:00 2001 From: Aeronica Date: Tue, 5 Mar 2024 20:53:47 -0600 Subject: [PATCH] WIP: Improve Instrument and MusicVenueTool overlays. --- .../mods/mxtune/events/ClientEvents.java | 6 ++-- .../mods/mxtune/gui/TestScreen.java | 2 +- .../mods/mxtune/render/IOverlayItem.java | 3 ++ .../mods/mxtune/render/MXOverlay.java | 5 +++ .../mods/mxtune/render/OverlayInst.java | 8 +++-- .../mods/mxtune/render/OverlayItemGui.java | 3 +- .../mods/mxtune/render/OverlayVenueTool.java | 32 +++++++++++++++++++ .../mods/mxtune/render/RenderEvents.java | 9 +----- .../mods/mxtune/render/RenderHelper.java | 2 +- 9 files changed, 53 insertions(+), 17 deletions(-) create mode 100644 src/main/java/aeronicamc/mods/mxtune/render/OverlayVenueTool.java diff --git a/src/main/java/aeronicamc/mods/mxtune/events/ClientEvents.java b/src/main/java/aeronicamc/mods/mxtune/events/ClientEvents.java index b9c72e3f..df50e78e 100644 --- a/src/main/java/aeronicamc/mods/mxtune/events/ClientEvents.java +++ b/src/main/java/aeronicamc/mods/mxtune/events/ClientEvents.java @@ -21,14 +21,14 @@ private ClientEvents() { /* NOOP */ } public static void event(ClientPlayerNetworkEvent.LoggedInEvent event) { GroupClient.clear(); - RenderHelper.getOverlayItem().clear(); + RenderHelper.getOverlayItemGui().clear(); PacketDispatcher.sendToServer(new SyncRequestMessage()); } @SubscribeEvent public static void event(ClientPlayerNetworkEvent.LoggedOutEvent event) { - RenderHelper.getOverlayItem().clear(); + RenderHelper.getOverlayItemGui().clear(); InfoRenderer.getInstance().clearInfoRendererInstances(); } @@ -37,7 +37,7 @@ public static void event(ClientPlayerNetworkEvent.RespawnEvent event) { GroupClient.clear(); ClientAudio.stopAll(); - RenderHelper.getOverlayItem().clear(); + RenderHelper.getOverlayItemGui().clear(); PacketDispatcher.sendToServer(new SyncRequestMessage()); } } diff --git a/src/main/java/aeronicamc/mods/mxtune/gui/TestScreen.java b/src/main/java/aeronicamc/mods/mxtune/gui/TestScreen.java index d4bd95d5..bf5c6e01 100644 --- a/src/main/java/aeronicamc/mods/mxtune/gui/TestScreen.java +++ b/src/main/java/aeronicamc/mods/mxtune/gui/TestScreen.java @@ -98,7 +98,7 @@ public void onButtonOpen() m.setItem(0, Objects.requireNonNull(getMinecraft().player).inventory.getSelected()); m.setChanged(); ModItems.MULTI_INST.get().setPatch(itemStack, RandomUtils.nextInt(0, SoundFontProxyManager.getProxies().size())); - RenderHelper.getOverlayItem().addOverlay(new OverlayInst(itemStack)); + RenderHelper.getOverlayItemGui().addOverlay(new OverlayInst(itemStack)); } public void onButtonFile() diff --git a/src/main/java/aeronicamc/mods/mxtune/render/IOverlayItem.java b/src/main/java/aeronicamc/mods/mxtune/render/IOverlayItem.java index 371cfa13..832bd208 100644 --- a/src/main/java/aeronicamc/mods/mxtune/render/IOverlayItem.java +++ b/src/main/java/aeronicamc/mods/mxtune/render/IOverlayItem.java @@ -3,6 +3,7 @@ import com.mojang.blaze3d.matrix.MatrixStack; import net.minecraft.client.audio.SimpleSound; import net.minecraft.client.audio.SoundHandler; +import net.minecraft.item.ItemStack; import net.minecraft.util.ResourceLocation; import net.minecraft.util.SoundEvent; import net.minecraft.util.SoundEvents; @@ -17,6 +18,8 @@ default Object getToken() { return NO_TOKEN; } + ItemStack getItemStack(); + default int baseWidth() { return 160; } diff --git a/src/main/java/aeronicamc/mods/mxtune/render/MXOverlay.java b/src/main/java/aeronicamc/mods/mxtune/render/MXOverlay.java index d1ffe769..7d5394c5 100644 --- a/src/main/java/aeronicamc/mods/mxtune/render/MXOverlay.java +++ b/src/main/java/aeronicamc/mods/mxtune/render/MXOverlay.java @@ -30,6 +30,11 @@ public Visibility render(MatrixStack pPoseStack, OverlayItemGui pOverlayComponen return delta - this.lastChanged >= 5000L ? IOverlayItem.Visibility.HIDE : IOverlayItem.Visibility.SHOW; } + @Override + public ItemStack getItemStack() { + return itemStack; + } + @Override public int totalHeight() { return this.baseWidth(); diff --git a/src/main/java/aeronicamc/mods/mxtune/render/OverlayInst.java b/src/main/java/aeronicamc/mods/mxtune/render/OverlayInst.java index 41b6659c..d01edda3 100644 --- a/src/main/java/aeronicamc/mods/mxtune/render/OverlayInst.java +++ b/src/main/java/aeronicamc/mods/mxtune/render/OverlayInst.java @@ -13,7 +13,6 @@ public class OverlayInst implements IOverlayItem { private final ItemStack itemStack; private long lastChanged; private boolean changed; - private ItemStack sheetMusic; private ITextComponent titleText; private ITextComponent extraText; private int totalWidth; @@ -24,12 +23,17 @@ private OverlayInst() { public OverlayInst(ItemStack itemStack) { this.itemStack = itemStack; - this.sheetMusic = SheetMusicHelper.getIMusicFromIInstrument(itemStack); + ItemStack sheetMusic = SheetMusicHelper.getIMusicFromIInstrument(itemStack); this.titleText = SheetMusicHelper.getFormattedMusicTitle(sheetMusic); this.extraText = SheetMusicHelper.getFormattedExtraText(sheetMusic); this.totalWidth = Math.max(Math.max(mc.font.width(titleText), mc.font.width(extraText)) + 40, this.baseWidth()); } + @Override + public ItemStack getItemStack() { + return itemStack; + } + @Override public int totalHeight() { return this.baseHeight(); diff --git a/src/main/java/aeronicamc/mods/mxtune/render/OverlayItemGui.java b/src/main/java/aeronicamc/mods/mxtune/render/OverlayItemGui.java index 81378821..12716e68 100644 --- a/src/main/java/aeronicamc/mods/mxtune/render/OverlayItemGui.java +++ b/src/main/java/aeronicamc/mods/mxtune/render/OverlayItemGui.java @@ -16,7 +16,7 @@ public class OverlayItemGui extends AbstractGui { private final Minecraft minecraft; - private final OverlayInstance[] visible = new OverlayInstance[1]; + private final OverlayInstance[] visible = new OverlayInstance[4]; private final Deque queued = Queues.newArrayDeque(); public OverlayItemGui(Minecraft pMinecraft) { @@ -35,7 +35,6 @@ public void render(MatrixStack pPoseStack) { this.visible[i] = new OverlayInstance<>(this.queued.removeFirst()); } } - } } diff --git a/src/main/java/aeronicamc/mods/mxtune/render/OverlayVenueTool.java b/src/main/java/aeronicamc/mods/mxtune/render/OverlayVenueTool.java new file mode 100644 index 00000000..dbeec975 --- /dev/null +++ b/src/main/java/aeronicamc/mods/mxtune/render/OverlayVenueTool.java @@ -0,0 +1,32 @@ +package aeronicamc.mods.mxtune.render; + +import com.mojang.blaze3d.matrix.MatrixStack; +import net.minecraft.item.ItemStack; + +public class OverlayVenueTool implements IOverlayItem { + private final ItemStack itemStack; + + public OverlayVenueTool(ItemStack itemStack) { + this.itemStack = itemStack; + } + + @Override + public Visibility render(MatrixStack pPoseStack, OverlayItemGui pOverlayComponent, long delta) { + return null; + } + + @Override + public ItemStack getItemStack() { + return null; + } + + @Override + public int totalHeight() { + return this.baseHeight(); + } + + @Override + public int totalWidth() { + return 0; + } +} diff --git a/src/main/java/aeronicamc/mods/mxtune/render/RenderEvents.java b/src/main/java/aeronicamc/mods/mxtune/render/RenderEvents.java index 8f1008c7..648a9162 100644 --- a/src/main/java/aeronicamc/mods/mxtune/render/RenderEvents.java +++ b/src/main/java/aeronicamc/mods/mxtune/render/RenderEvents.java @@ -32,7 +32,6 @@ import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.client.event.DrawHighlightEvent; import net.minecraftforge.client.event.RenderGameOverlayEvent; -import net.minecraftforge.event.TickEvent; import net.minecraftforge.event.entity.player.ItemTooltipEvent; import net.minecraftforge.eventbus.api.SubscribeEvent; import net.minecraftforge.fml.common.Mod; @@ -138,16 +137,10 @@ public static void event(RenderGameOverlayEvent.Post event) final ItemStack itemStack = getPlayer().inventory.getSelected(); InstrumentOverlayRenderer.render(itemStack, event); MusicVenueToolOverlayRenderer.render(getPlayer(), itemStack, event); + RenderHelper.getOverlayItemGui().render(event.getMatrixStack()); ActiveAudioOverlay.render(event); } - @SubscribeEvent - public static void event(TickEvent.RenderTickEvent event) { - if (TickEvent.Phase.END.equals(event.phase)) { - RenderHelper.getOverlayItem().render(new MatrixStack()); - } - } - static void renderGroupStatusPlacard(MatrixStack pMatrixStack, IRenderTypeBuffer.Impl pBuffer, ActiveRenderInfo pActiveRenderInfo, float pPartialTicks, ClippingHelper pClippingHelper) { if (GroupClient.hasGroups()) diff --git a/src/main/java/aeronicamc/mods/mxtune/render/RenderHelper.java b/src/main/java/aeronicamc/mods/mxtune/render/RenderHelper.java index cbc0c971..a3987591 100644 --- a/src/main/java/aeronicamc/mods/mxtune/render/RenderHelper.java +++ b/src/main/java/aeronicamc/mods/mxtune/render/RenderHelper.java @@ -36,7 +36,7 @@ public static void init() { overlayItem = new OverlayItemGui(mc); } - public static OverlayItemGui getOverlayItem() { + public static OverlayItemGui getOverlayItemGui() { return overlayItem; }