-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
WIP: Improve Instrument and MusicVenueTool overlays.
- Loading branch information
Showing
6 changed files
with
104 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
80 changes: 80 additions & 0 deletions
80
src/main/java/aeronicamc/mods/mxtune/render/OverlayInst.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
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; | ||
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 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; | ||
|
||
private ItemStack sheetMusic; | ||
private ITextComponent titleText; | ||
private ITextComponent extraText; | ||
private ITextComponent infoText; | ||
|
||
|
||
private int offset; | ||
|
||
private OverlayInst() { | ||
this.itemStack = ItemStack.EMPTY; | ||
} | ||
|
||
public OverlayInst(ItemStack itemStack) { | ||
this.itemStack = itemStack; | ||
this.sheetMusic = SheetMusicHelper.getIMusicFromIInstrument(itemStack); | ||
this.titleText = SheetMusicHelper.getFormattedMusicTitle(sheetMusic); | ||
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()); | ||
} | ||
|
||
@Override | ||
public int offset() { | ||
return this.offset; | ||
} | ||
|
||
@SuppressWarnings("deprecation") | ||
@Override | ||
public Visibility render(MatrixStack pPoseStack, OverlayItemGui pOverlayComponent, long delta) { | ||
if (this.changed) { | ||
this.lastChanged = delta; | ||
this.changed = false; | ||
} | ||
mc.getTextureManager().bind(IToast.TEXTURE); | ||
RenderSystem.color3f(1.0F, 1.0F, 1.0F); | ||
RenderHelper.blit(pPoseStack, 0, 0, 0, 0, this.width(), this.height()); | ||
RenderHelper.blit(pPoseStack, ((offset - this.width())/2) + 5, 0, 10, 0, this.width() -10, this.height()); | ||
RenderHelper.blit(pPoseStack, offset - this.width() + 10, 0, 10, 0, this.width(), this.height()); | ||
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)); | ||
} | ||
|
||
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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters