diff --git a/src/main/java/aeronicamc/mods/mxtune/render/IOverlayItem.java b/src/main/java/aeronicamc/mods/mxtune/render/IOverlayItem.java index 832bd208..a5b6b135 100644 --- a/src/main/java/aeronicamc/mods/mxtune/render/IOverlayItem.java +++ b/src/main/java/aeronicamc/mods/mxtune/render/IOverlayItem.java @@ -46,4 +46,6 @@ public void playSound(SoundHandler pHandler) { pHandler.play(SimpleSound.forUI(this.soundEvent, 1.0F, 1.0F)); } } + + enum Position { LEFT, CENTER, RIGHT } } \ No newline at end of file diff --git a/src/main/java/aeronicamc/mods/mxtune/render/OverlayItemGui.java b/src/main/java/aeronicamc/mods/mxtune/render/OverlayItemGui.java index ba3efe20..890ad877 100644 --- a/src/main/java/aeronicamc/mods/mxtune/render/OverlayItemGui.java +++ b/src/main/java/aeronicamc/mods/mxtune/render/OverlayItemGui.java @@ -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) { @@ -60,11 +60,11 @@ public T getOverlay(Class 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() { @@ -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; } @@ -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) { diff --git a/src/main/java/aeronicamc/mods/mxtune/render/OverlayVenueTool.java b/src/main/java/aeronicamc/mods/mxtune/render/OverlayVenueTool.java index 89f57d98..5a60571d 100644 --- a/src/main/java/aeronicamc/mods/mxtune/render/OverlayVenueTool.java +++ b/src/main/java/aeronicamc/mods/mxtune/render/OverlayVenueTool.java @@ -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 @@ -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()); @@ -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);