-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add tooltip information to Portable Cell Workbench
- Loading branch information
Showing
8 changed files
with
223 additions
and
9 deletions.
There are no files selected for viewing
4 changes: 2 additions & 2 deletions
4
src/generated/resources/.cache/89b86ab0e66f527166d98df92ddbcf5416ed58f6
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 |
---|---|---|
@@ -1,2 +1,2 @@ | ||
// 1.21.1 2024-11-15T20:14:53.378044013 Language | ||
a77898c0ee75796bccabca2cf157f495702102d1 assets/megacells/lang/en_us.json | ||
// 1.21.1 2024-11-17T14:07:31.916554252 Language | ||
79f2bdffe2659a931e47c3e340144ada20c70b08 assets/megacells/lang/en_us.json |
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
161 changes: 161 additions & 0 deletions
161
...n/java/gripe/_90/megacells/client/render/PortableCellWorkbenchClientTooltipComponent.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,161 @@ | ||
package gripe._90.megacells.client.render; | ||
|
||
import org.jetbrains.annotations.NotNull; | ||
import org.joml.Matrix4f; | ||
|
||
import net.minecraft.client.Minecraft; | ||
import net.minecraft.client.gui.Font; | ||
import net.minecraft.client.gui.GuiGraphics; | ||
import net.minecraft.client.gui.screens.inventory.tooltip.ClientTooltipComponent; | ||
import net.minecraft.client.renderer.LightTexture; | ||
import net.minecraft.client.renderer.MultiBufferSource; | ||
import net.minecraft.network.chat.Component; | ||
|
||
import appeng.api.client.AEKeyRendering; | ||
import appeng.items.storage.StorageCellTooltipComponent; | ||
|
||
import gripe._90.megacells.definition.MEGATranslations; | ||
import gripe._90.megacells.item.cell.PortableCellWorkbenchTooltipComponent; | ||
|
||
public class PortableCellWorkbenchClientTooltipComponent implements ClientTooltipComponent { | ||
private static final Component CELL_LABEL = MEGATranslations.WorkbenchCell.text(); | ||
private static final Component CONFIG_LABEL = MEGATranslations.WorkbenchConfig.text(); | ||
|
||
private final PortableCellWorkbenchTooltipComponent tooltipComponent; | ||
|
||
public PortableCellWorkbenchClientTooltipComponent(PortableCellWorkbenchTooltipComponent tooltipComponent) { | ||
this.tooltipComponent = tooltipComponent; | ||
} | ||
|
||
@Override | ||
public int getHeight() { | ||
var height = 0; | ||
|
||
if (!tooltipComponent.config().isEmpty()) { | ||
height += 17; | ||
} | ||
|
||
var cellOpt = tooltipComponent.cell().getTooltipImage(); | ||
|
||
if (cellOpt.isPresent() && cellOpt.get() instanceof StorageCellTooltipComponent) { | ||
height += 17; | ||
} | ||
return height; | ||
} | ||
|
||
@Override | ||
public int getWidth(@NotNull Font font) { | ||
var width = 0; | ||
|
||
if (!tooltipComponent.config().isEmpty()) { | ||
var configWidth = tooltipComponent.config().size() * 17; | ||
|
||
if (tooltipComponent.hasMoreConfig()) { | ||
configWidth += 10; | ||
} | ||
|
||
width = font.width(CONFIG_LABEL) + 2 + Math.max(width, configWidth); | ||
} | ||
|
||
var cellOpt = tooltipComponent.cell().getTooltipImage(); | ||
|
||
if (cellOpt.isPresent() && cellOpt.get() instanceof StorageCellTooltipComponent cellComponent) { | ||
width = Math.max( | ||
width, | ||
font.width(CELL_LABEL) + 2 + 17 * (cellComponent.upgrades().size() + 1)); | ||
} | ||
|
||
return width; | ||
} | ||
|
||
@Override | ||
public void renderText( | ||
@NotNull Font font, | ||
int x, | ||
int y, | ||
@NotNull Matrix4f matrix, | ||
@NotNull MultiBufferSource.BufferSource bufferSource) { | ||
y += (16 - font.lineHeight) / 2; | ||
|
||
if (!tooltipComponent.config().isEmpty()) { | ||
font.drawInBatch( | ||
CONFIG_LABEL, | ||
x, | ||
y, | ||
0x7E7E7E, | ||
false, | ||
matrix, | ||
bufferSource, | ||
Font.DisplayMode.NORMAL, | ||
0, | ||
LightTexture.FULL_BRIGHT); | ||
|
||
if (tooltipComponent.hasMoreConfig()) { | ||
font.drawInBatch( | ||
"…", | ||
x | ||
+ font.width(CONFIG_LABEL) | ||
+ 4 | ||
+ tooltipComponent.config().size() * 17, | ||
y + 2, | ||
-1, | ||
false, | ||
matrix, | ||
bufferSource, | ||
Font.DisplayMode.NORMAL, | ||
0, | ||
LightTexture.FULL_BRIGHT); | ||
} | ||
|
||
y += 17; | ||
} | ||
|
||
if (!tooltipComponent.cell().isEmpty()) { | ||
font.drawInBatch( | ||
CELL_LABEL, | ||
x, | ||
y, | ||
0x7E7E7E, | ||
false, | ||
matrix, | ||
bufferSource, | ||
Font.DisplayMode.NORMAL, | ||
0, | ||
LightTexture.FULL_BRIGHT); | ||
} | ||
} | ||
|
||
@Override | ||
public void renderImage(@NotNull Font font, int x, int y, @NotNull GuiGraphics guiGraphics) { | ||
var config = tooltipComponent.config(); | ||
|
||
if (!config.isEmpty()) { | ||
var xOff = font.width(CONFIG_LABEL) + 2; | ||
|
||
for (var stack : config) { | ||
AEKeyRendering.drawInGui(Minecraft.getInstance(), guiGraphics, x + xOff, y, stack.what()); | ||
xOff += 17; | ||
} | ||
|
||
y += 17; | ||
} | ||
|
||
var cellOpt = tooltipComponent.cell().getTooltipImage(); | ||
|
||
if (cellOpt.isPresent() && cellOpt.get() instanceof StorageCellTooltipComponent cellComponent) { | ||
var xOff = font.width(CELL_LABEL) + 2; | ||
guiGraphics.renderItem(tooltipComponent.cell(), x + xOff, y); | ||
|
||
var upgrades = cellComponent.upgrades(); | ||
|
||
if (!upgrades.isEmpty()) { | ||
xOff += 17; | ||
|
||
for (var upgrade : upgrades) { | ||
guiGraphics.renderItem(upgrade, x + xOff, y); | ||
xOff += 17; | ||
} | ||
} | ||
} | ||
} | ||
} |
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
11 changes: 11 additions & 0 deletions
11
src/main/java/gripe/_90/megacells/item/cell/PortableCellWorkbenchTooltipComponent.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,11 @@ | ||
package gripe._90.megacells.item.cell; | ||
|
||
import java.util.List; | ||
|
||
import net.minecraft.world.inventory.tooltip.TooltipComponent; | ||
import net.minecraft.world.item.ItemStack; | ||
|
||
import appeng.api.stacks.GenericStack; | ||
|
||
public record PortableCellWorkbenchTooltipComponent(List<GenericStack> config, ItemStack cell, boolean hasMoreConfig) | ||
implements TooltipComponent {} |