Skip to content

Commit

Permalink
WIP: Improve Instrument and MusicVenueTool overlays.
Browse files Browse the repository at this point in the history
  • Loading branch information
Aeronica committed Feb 28, 2024
1 parent abec3f7 commit 05c54d0
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 39 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
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()) {
ITextComponent infoText = new StringTextComponent("")
.append(String.format("%s %s", mc.getSoundManager().getDebugString(), ClientAudio.getDebugString())).withStyle(TextFormatting.WHITE);
final MatrixStack pPoseStack = event.getMatrixStack();
RenderSystem.color3f(1.0F, 1.0F, 1.0F);

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));
}
}

private static boolean isPlacardInHotBar() {
int slot = getPlayer().inventory.findSlotMatchingItem(PLACARD_ITEM);
return slot >= 0 && slot < 9;
}
}
Original file line number Diff line number Diff line change
@@ -1,35 +1,26 @@
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;
import com.mojang.blaze3d.systems.RenderSystem;
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.
if (event.getType() == RenderGameOverlayEvent.ElementType.ALL && (mc.screen == null) && itemStack.getItem() instanceof IInstrument) {
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);

Expand All @@ -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;
}
}
18 changes: 2 additions & 16 deletions src/main/java/aeronicamc/mods/mxtune/render/OverlayInst.java
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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;
Expand All @@ -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
Expand All @@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 05c54d0

Please sign in to comment.