diff --git a/src/main/java/aeronicamc/mods/mxtune/render/ActiveAudioOverlay.java b/src/main/java/aeronicamc/mods/mxtune/render/ActiveAudioOverlay.java new file mode 100644 index 00000000..cd6f3b38 --- /dev/null +++ b/src/main/java/aeronicamc/mods/mxtune/render/ActiveAudioOverlay.java @@ -0,0 +1,43 @@ +package aeronicamc.mods.mxtune.render; + +import aeronicamc.mods.mxtune.init.ModItems; +import aeronicamc.mods.mxtune.sound.ClientAudio; +import com.mojang.blaze3d.matrix.MatrixStack; +import com.mojang.blaze3d.systems.RenderSystem; +import net.minecraft.item.ItemStack; +import net.minecraft.util.text.ITextComponent; +import net.minecraft.util.text.StringTextComponent; +import net.minecraft.util.text.TextFormatting; +import net.minecraftforge.client.event.RenderGameOverlayEvent; + +import static aeronicamc.mods.mxtune.render.RenderHelper.getPlayer; +import static aeronicamc.mods.mxtune.render.RenderHelper.mc; + +public class ActiveAudioOverlay { + private static final ItemStack PLACARD_ITEM = new ItemStack(ModItems.PLACARD_ITEM.get()); + + @SuppressWarnings("deprecation") + public static void render(RenderGameOverlayEvent.Post event) { + // Display basic info about the instrument and tune. Optionally, displays some debug info depending on MXTune.isDevEnv flag. + // Based on the toast renderer for testing some ideas. + if (isPlacardInHotBar()) { + final MatrixStack pPoseStack = event.getMatrixStack(); + RenderSystem.color3f(1.0F, 1.0F, 1.0F); + + final ITextComponent infoText = new StringTextComponent("") + .append(String.format("%s, %s", mc.getSoundManager().getDebugString(), ClientAudio.getDebugString())).withStyle(TextFormatting.WHITE); + final int[] posY = { 0 }; + posY[0] = (25); + mc.font.drawShadow(pPoseStack, infoText, 5.0F, posY[0] += 10, -11534256); + ClientAudio.getAudioData().forEach(audioData -> mc.font.drawShadow(pPoseStack, audioData.getInfo(), 5, posY[0] += 10, -11534256)); + } + } + + /** + * @return true if mxtune:placard_item is on the hot-bar, and the player is not in a portal. + */ + private static boolean isPlacardInHotBar() { + int slot = getPlayer().inventory.findSlotMatchingItem(PLACARD_ITEM); + return slot >= 0 && slot < 9 && !(getPlayer().portalTime > 0); + } +} diff --git a/src/main/java/aeronicamc/mods/mxtune/render/InstrumentOverlayRenderer.java b/src/main/java/aeronicamc/mods/mxtune/render/InstrumentOverlayRenderer.java index 3533b2b1..56931541 100644 --- a/src/main/java/aeronicamc/mods/mxtune/render/InstrumentOverlayRenderer.java +++ b/src/main/java/aeronicamc/mods/mxtune/render/InstrumentOverlayRenderer.java @@ -1,7 +1,5 @@ package aeronicamc.mods.mxtune.render; -import aeronicamc.mods.mxtune.init.ModItems; -import aeronicamc.mods.mxtune.sound.ClientAudio; import aeronicamc.mods.mxtune.util.IInstrument; import aeronicamc.mods.mxtune.util.SheetMusicHelper; import com.mojang.blaze3d.matrix.MatrixStack; @@ -9,16 +7,11 @@ import net.minecraft.client.gui.toasts.IToast; import net.minecraft.item.ItemStack; import net.minecraft.util.text.ITextComponent; -import net.minecraft.util.text.StringTextComponent; -import net.minecraft.util.text.TextFormatting; import net.minecraftforge.client.event.RenderGameOverlayEvent; -import static aeronicamc.mods.mxtune.render.RenderHelper.getPlayer; import static aeronicamc.mods.mxtune.render.RenderHelper.mc; public class InstrumentOverlayRenderer { - private static final ItemStack PLACARD_ITEM = new ItemStack(ModItems.PLACARD_ITEM.get()); - public static void render(ItemStack itemStack, RenderGameOverlayEvent.Post event) { // Display basic info about the instrument and tune. Optionally, displays some debug info depending on MXTune.isDevEnv flag. // Based on the toast renderer for testing some ideas. @@ -26,10 +19,8 @@ public static void render(ItemStack itemStack, RenderGameOverlayEvent.Post event final ItemStack sheetMusic = SheetMusicHelper.getIMusicFromIInstrument(itemStack); final ITextComponent titleText = SheetMusicHelper.getFormattedMusicTitle(sheetMusic); final ITextComponent extraText = SheetMusicHelper.getFormattedExtraText(sheetMusic); - final ITextComponent infoText = new StringTextComponent("").append(SheetMusicHelper.getFormattedMusicDuration(sheetMusic)) - .append(String.format(" %s %s", mc.getSoundManager().getDebugString(), ClientAudio.getDebugString())).withStyle(TextFormatting.WHITE); - final int offset = Math.max(Math.max(mc.font.width(titleText), mc.font.width(isPlacardInHotBar() ? infoText : extraText)) + 40, RenderHelper.WIDTH); + final int offset = Math.max(Math.max(mc.font.width(titleText), mc.font.width(extraText)) + 40, RenderHelper.WIDTH); final MatrixStack pPoseStack = event.getMatrixStack(); mc.getTextureManager().bind(IToast.TEXTURE); @@ -40,19 +31,7 @@ public static void render(ItemStack itemStack, RenderGameOverlayEvent.Post event mc.getItemRenderer().renderAndDecorateItem(itemStack, 8, 8); mc.font.draw(pPoseStack, titleText, 30.0F, 7.0F, -11534256); - mc.font.draw(pPoseStack, isPlacardInHotBar() ? infoText : extraText, 30.0F, 17.0F, -11534256); - - if (isPlacardInHotBar()) { - final int[] posY = { 0 }; - posY[0] = (25); - ClientAudio.getAudioData() - .forEach(audioData -> mc.font.drawShadow(pPoseStack, audioData.getInfo(), 5, posY[0] += 10, -11534256)); - } + mc.font.draw(pPoseStack, extraText, 30.0F, 17.0F, -11534256); } } - - private static boolean isPlacardInHotBar() { - int slot = getPlayer().inventory.findSlotMatchingItem(PLACARD_ITEM); - return slot >= 0 && slot < 9; - } } diff --git a/src/main/java/aeronicamc/mods/mxtune/render/OverlayInst.java b/src/main/java/aeronicamc/mods/mxtune/render/OverlayInst.java index fbd3d314..bc8f9221 100644 --- a/src/main/java/aeronicamc/mods/mxtune/render/OverlayInst.java +++ b/src/main/java/aeronicamc/mods/mxtune/render/OverlayInst.java @@ -1,6 +1,5 @@ package aeronicamc.mods.mxtune.render; -import aeronicamc.mods.mxtune.init.ModItems; import aeronicamc.mods.mxtune.sound.ClientAudio; import aeronicamc.mods.mxtune.util.SheetMusicHelper; import com.mojang.blaze3d.matrix.MatrixStack; @@ -11,11 +10,9 @@ import net.minecraft.util.text.StringTextComponent; import net.minecraft.util.text.TextFormatting; -import static aeronicamc.mods.mxtune.render.RenderHelper.getPlayer; import static aeronicamc.mods.mxtune.render.RenderHelper.mc; public class OverlayInst implements IOverlayItem { - private static final ItemStack PLACARD_ITEM = new ItemStack(ModItems.PLACARD_ITEM.get()); private final ItemStack itemStack; private long lastChanged; private boolean changed; @@ -39,7 +36,7 @@ public OverlayInst(ItemStack itemStack) { this.extraText = SheetMusicHelper.getFormattedExtraText(sheetMusic); this.infoText = new StringTextComponent("").append(SheetMusicHelper.getFormattedMusicDuration(sheetMusic)) .append(String.format(" %s %s", mc.getSoundManager().getDebugString(), ClientAudio.getDebugString())).withStyle(TextFormatting.WHITE); - offset = Math.max(Math.max(mc.font.width(titleText), mc.font.width(isPlacardInHotBar() ? infoText : extraText)) + 40, this.width()); + offset = Math.max(Math.max(mc.font.width(titleText), mc.font.width(extraText)) + 40, this.width()); } @Override @@ -62,19 +59,8 @@ public Visibility render(MatrixStack pPoseStack, OverlayItemGui pOverlayComponen mc.getItemRenderer().renderAndDecorateItem(itemStack, 8, 8); mc.font.draw(pPoseStack, titleText, 30.0F, 7.0F, -11534256); - mc.font.draw(pPoseStack, isPlacardInHotBar() ? infoText : extraText, 30.0F, 17.0F, -11534256); - - if (isPlacardInHotBar()) { - final int[] posY = { 0 }; - posY[0] = (25); - ClientAudio.getAudioData() - .forEach(audioData -> mc.font.drawShadow(pPoseStack, audioData.getInfo(), 5, posY[0] += 10, -11534256)); - } + mc.font.draw(pPoseStack, extraText, 30.0F, 17.0F, -11534256); return delta - this.lastChanged >= 5000L ? Visibility.HIDE : Visibility.SHOW; } - private static boolean isPlacardInHotBar() { - int slot = getPlayer().inventory.findSlotMatchingItem(PLACARD_ITEM); - return slot >= 0 && slot < 9; - } } diff --git a/src/main/java/aeronicamc/mods/mxtune/render/RenderEvents.java b/src/main/java/aeronicamc/mods/mxtune/render/RenderEvents.java index a1deed40..8f1008c7 100644 --- a/src/main/java/aeronicamc/mods/mxtune/render/RenderEvents.java +++ b/src/main/java/aeronicamc/mods/mxtune/render/RenderEvents.java @@ -138,6 +138,7 @@ public static void event(RenderGameOverlayEvent.Post event) final ItemStack itemStack = getPlayer().inventory.getSelected(); InstrumentOverlayRenderer.render(itemStack, event); MusicVenueToolOverlayRenderer.render(getPlayer(), itemStack, event); + ActiveAudioOverlay.render(event); } @SubscribeEvent diff --git a/src/main/java/aeronicamc/mods/mxtune/sound/ClientAudio.java b/src/main/java/aeronicamc/mods/mxtune/sound/ClientAudio.java index b520cb71..305b8528 100644 --- a/src/main/java/aeronicamc/mods/mxtune/sound/ClientAudio.java +++ b/src/main/java/aeronicamc/mods/mxtune/sound/ClientAudio.java @@ -66,7 +66,7 @@ private ClientAudio() { /* NOP */ } public static String getDebugString() { - return String.format("AudioData %d/%d/%d", ActiveAudio.getDistanceSortedSources().size(), ActiveAudio.getDeleteQueueSize(), ActiveAudio.getCachedMidiSequenceCount()); + return String.format("AudioData numSources: %d, deleteQ: %d, seqQ: %d", ActiveAudio.getDistanceSortedSources().size(), ActiveAudio.getDeleteQueueSize(), ActiveAudio.getCachedMidiSequenceCount()); } public static List getAudioData()