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 9, 2024
1 parent 2d5a99e commit e763a79
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 11 deletions.
2 changes: 2 additions & 0 deletions src/main/java/aeronicamc/mods/mxtune/render/IOverlayItem.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,6 @@ public void playSound(SoundHandler pHandler) {
pHandler.play(SimpleSound.forUI(this.soundEvent, 1.0F, 1.0F));
}
}

enum Position { LEFT, CENTER, RIGHT }
}
35 changes: 26 additions & 9 deletions src/main/java/aeronicamc/mods/mxtune/render/OverlayItemGui.java
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 = { null, null, null, null };
private final OverlayInstance<?>[] visible = { null };
private int lastSlot = -1;

public OverlayItemGui(Minecraft pMinecraft) {
Expand Down Expand Up @@ -60,11 +60,11 @@ public <T extends IOverlayItem> T getOverlay(Class<? extends T> pIOverlayItem, O
return (T)overlayInstance.getOverlayItem();
}
}
return (T)null;
return null;
}

public void clear() {
Arrays.fill(this.visible, (Object)null);
Arrays.fill(this.visible, null);
}

public Minecraft getMinecraft() {
Expand All @@ -85,8 +85,8 @@ public T getOverlayItem() {
return this.overlayItem;
}

private float getVisibility(long p_193686_1_) {
float f = MathHelper.clamp((float)(p_193686_1_ - this.animationTime) / 600.0F, 0.0F, 1.0F);
private float getVisibility(long milliseconds) {
float f = MathHelper.clamp((float)(milliseconds - this.animationTime) / 600.0F, 0.0F, 1.0F);
f = f * f;
return this.visibility == IOverlayItem.Visibility.HIDE ? 1.0F - f : f;
}
Expand All @@ -110,11 +110,28 @@ public boolean render(int x, int y, MatrixStack pPoseStack) {
this.visibleTime = i;
}

float right = (float)x - (float)this.overlayItem.totalHeight();
float center = (x * 0.5F) - this.overlayItem.totalHeight() * 0.5F;
float left = 0F;
IOverlayItem.Position position = IOverlayItem.Position.LEFT;
float xPos;
float yPos;
switch (position) {
case LEFT:
xPos = 0F - this.overlayItem.totalWidth() + ((float)this.overlayItem.totalWidth() * this.getVisibility(i));
yPos = 0F;
break;
case CENTER:
xPos = (x * 0.5F) - this.overlayItem.totalWidth() * 0.5F;
yPos = 0F - this.overlayItem.totalHeight() + ((float) this.overlayItem.totalHeight() * this.getVisibility(i));
// yPos = 0F - this.overlayItem.totalHeight() + (getMinecraft().getWindow().getGuiScaledHeight() * 0.5F + this.overlayItem.totalHeight() * 0.5F) * this.getVisibility(i);
break;
case RIGHT:
xPos = (float)x - (float)this.overlayItem.totalWidth() * this.getVisibility(i);
yPos = 0F;
break;
default:
throw new IllegalStateException("Unexpected value: " + position);
}
RenderSystem.pushMatrix();
RenderSystem.translatef(left, ((float)0 * this.overlayItem.baseHeight() - this.overlayItem.baseHeight()) + ((float)(this.overlayItem.baseHeight()) * this.getVisibility(i)), (float)(800 + y));
RenderSystem.translatef(xPos, yPos, 800F + y);
IOverlayItem.Visibility overlayVisibility = this.overlayItem.render(pPoseStack, OverlayItemGui.this, i - this.visibleTime);
RenderSystem.popMatrix();
if (overlayVisibility != this.visibility) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ public class OverlayVenueTool implements IOverlayItem {
public OverlayVenueTool(ItemStack itemStack) {
this.lastSlot = RenderHelper.getSelectedSlot();
this.itemStack = itemStack;
this.totalWidth = this.baseWidth();
}

@Override
Expand All @@ -53,7 +54,6 @@ private boolean isNotToolItem() {
@SuppressWarnings("deprecation")
@Override
public Visibility render(MatrixStack pPoseStack, OverlayItemGui pOverlayComponent, long delta) {

final RayTraceResult raytraceresult = mc.hitResult;
final Vector3d vector3d;
final EntityVenueState evs = MusicVenueHelper.getEntityVenueState(getPlayer().level, getPlayer().getId());
Expand All @@ -74,7 +74,7 @@ else if (raytraceresult instanceof EntityRayTraceResult)
ToolManager.getToolOpl(getPlayer()).ifPresent(tool-> stateName[0] = tool.getToolState());

ITextComponent testText = new TranslationTextComponent(stateName[0].getTranslationKey()).withStyle(TextFormatting.WHITE).append(" ").append(evs.inVenue() ? evs.getVenue().getVenueAABB().getCenter().toString() : "");
totalWidth = Math.max(mc.font.width(testText) + 40, RenderHelper.WIDTH);
totalWidth = Math.max(mc.font.width(testText) + 40, this.baseWidth());

if (mc.level != null && raytraceresult instanceof BlockRayTraceResult)
blockName = mc.level.getBlockState(blockpos).getBlock().getName().withStyle(TextFormatting.YELLOW);
Expand Down

0 comments on commit e763a79

Please sign in to comment.