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 Mar 6, 2024
1 parent 39edf5b commit 415e416
Show file tree
Hide file tree
Showing 9 changed files with 53 additions and 17 deletions.
6 changes: 3 additions & 3 deletions src/main/java/aeronicamc/mods/mxtune/events/ClientEvents.java
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

Expand All @@ -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());
}
}
2 changes: 1 addition & 1 deletion src/main/java/aeronicamc/mods/mxtune/gui/TestScreen.java
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/aeronicamc/mods/mxtune/render/IOverlayItem.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -17,6 +18,8 @@ default Object getToken() {
return NO_TOKEN;
}

ItemStack getItemStack();

default int baseWidth() {
return 160;
}
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/aeronicamc/mods/mxtune/render/MXOverlay.java
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
8 changes: 6 additions & 2 deletions src/main/java/aeronicamc/mods/mxtune/render/OverlayInst.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<IOverlayItem> queued = Queues.newArrayDeque();

public OverlayItemGui(Minecraft pMinecraft) {
Expand All @@ -35,7 +35,6 @@ public void render(MatrixStack pPoseStack) {
this.visible[i] = new OverlayInstance<>(this.queued.removeFirst());
}
}

}
}

Expand Down
32 changes: 32 additions & 0 deletions src/main/java/aeronicamc/mods/mxtune/render/OverlayVenueTool.java
Original file line number Diff line number Diff line change
@@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public static void init() {
overlayItem = new OverlayItemGui(mc);
}

public static OverlayItemGui getOverlayItem() {
public static OverlayItemGui getOverlayItemGui() {
return overlayItem;
}

Expand Down

0 comments on commit 415e416

Please sign in to comment.