-
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.
- Loading branch information
Showing
19 changed files
with
895 additions
and
6 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
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-15T19:31:29.757213749 Language | ||
01c5e0e544a51a97c1494a283b0c34a0e73b3f14 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
6 changes: 6 additions & 0 deletions
6
src/generated/resources/assets/megacells/models/item/portable_cell_workbench.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"parent": "minecraft:item/generated", | ||
"textures": { | ||
"layer0": "megacells:item/portable_cell_workbench" | ||
} | ||
} |
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; | ||
} | ||
} | ||
} | ||
} | ||
} |
111 changes: 111 additions & 0 deletions
111
src/main/java/gripe/_90/megacells/client/screen/PortableCellWorkbenchScreen.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,111 @@ | ||
package gripe._90.megacells.client.screen; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
import org.jetbrains.annotations.NotNull; | ||
|
||
import net.minecraft.ChatFormatting; | ||
import net.minecraft.network.chat.Component; | ||
import net.minecraft.world.entity.player.Inventory; | ||
import net.minecraft.world.item.ItemStack; | ||
|
||
import appeng.api.config.ActionItems; | ||
import appeng.api.config.CopyMode; | ||
import appeng.api.config.FuzzyMode; | ||
import appeng.api.config.Settings; | ||
import appeng.api.stacks.AEItemKey; | ||
import appeng.api.stacks.GenericStack; | ||
import appeng.client.gui.Icon; | ||
import appeng.client.gui.implementations.UpgradeableScreen; | ||
import appeng.client.gui.style.ScreenStyle; | ||
import appeng.client.gui.widgets.ActionButton; | ||
import appeng.client.gui.widgets.SettingToggleButton; | ||
import appeng.client.gui.widgets.ToggleButton; | ||
import appeng.core.definitions.AEItems; | ||
import appeng.core.localization.GuiText; | ||
|
||
import gripe._90.megacells.menu.PortableCellWorkbenchMenu; | ||
|
||
/** | ||
* See {@link appeng.client.gui.implementations.CellWorkbenchScreen} | ||
*/ | ||
public class PortableCellWorkbenchScreen extends UpgradeableScreen<PortableCellWorkbenchMenu> { | ||
private final ToggleButton copyMode; | ||
private final SettingToggleButton<FuzzyMode> fuzzyMode; | ||
|
||
public PortableCellWorkbenchScreen( | ||
PortableCellWorkbenchMenu menu, Inventory playerInventory, Component title, ScreenStyle style) { | ||
super(menu, playerInventory, title, style); | ||
fuzzyMode = addToLeftToolbar(new SettingToggleButton<>( | ||
Settings.FUZZY_MODE, | ||
FuzzyMode.IGNORE_ALL, | ||
(button, backwards) -> menu.setCellFuzzyMode(button.getNextValue(backwards)))); | ||
addToLeftToolbar(new ActionButton(ActionItems.COG, act -> menu.partition())); | ||
addToLeftToolbar(new ActionButton(ActionItems.CLOSE, act -> menu.clear())); | ||
copyMode = addToLeftToolbar(new ToggleButton( | ||
Icon.COPY_MODE_ON, | ||
Icon.COPY_MODE_OFF, | ||
GuiText.CopyMode.text(), | ||
GuiText.CopyModeDesc.text(), | ||
act -> menu.nextWorkBenchCopyMode())); | ||
} | ||
|
||
@Override | ||
protected void updateBeforeRender() { | ||
super.updateBeforeRender(); | ||
copyMode.setState(menu.getCopyMode() == CopyMode.CLEAR_ON_REMOVE); | ||
fuzzyMode.set(menu.getFuzzyMode()); | ||
fuzzyMode.setVisibility(menu.getUpgrades().isInstalled(AEItems.FUZZY_CARD)); | ||
} | ||
|
||
@NotNull | ||
@Override | ||
protected List<Component> getTooltipFromContainerItem(@NotNull ItemStack stack) { | ||
var cell = getMenu().getWorkbenchItem(); | ||
|
||
if (cell.isEmpty()) { | ||
return super.getTooltipFromContainerItem(stack); | ||
} | ||
|
||
if (cell == stack) { | ||
return super.getTooltipFromContainerItem(stack); | ||
} | ||
|
||
var genericStack = GenericStack.unwrapItemStack(stack); | ||
var what = genericStack != null ? genericStack.what() : AEItemKey.of(stack); | ||
|
||
if (what == null) { | ||
return super.getTooltipFromContainerItem(stack); | ||
} | ||
|
||
var configInventory = getMenu().getHost().getCell().getConfigInventory(cell); | ||
|
||
if (!configInventory.isSupportedType(what.getType())) { | ||
var lines = new ArrayList<>(super.getTooltipFromContainerItem(stack)); | ||
lines.add(GuiText.IncompatibleWithCell.text().withStyle(ChatFormatting.RED)); | ||
return lines; | ||
} | ||
|
||
var filter = configInventory.getFilter(); | ||
|
||
if (filter != null) { | ||
var anySlotMatches = false; | ||
|
||
for (var i = 0; i < configInventory.size(); i++) { | ||
if (configInventory.isAllowedIn(i, what)) { | ||
anySlotMatches = true; | ||
break; | ||
} | ||
} | ||
|
||
if (!anySlotMatches) { | ||
var lines = new ArrayList<>(super.getTooltipFromContainerItem(stack)); | ||
lines.add(GuiText.IncompatibleWithCell.text().withStyle(ChatFormatting.RED)); | ||
return lines; | ||
} | ||
} | ||
|
||
return super.getTooltipFromContainerItem(stack); | ||
} | ||
} |
Oops, something went wrong.