Skip to content

Commit

Permalink
add tooltip to unsupported items in the cell workbench
Browse files Browse the repository at this point in the history
  • Loading branch information
shartte committed Mar 14, 2024
1 parent 89f53aa commit 2873505
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 3 deletions.
1 change: 1 addition & 0 deletions src/generated/resources/assets/ae2/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -365,6 +365,7 @@
"gui.ae2.ImportBusFluids": "ME Fluid Import Bus",
"gui.ae2.InWorldCrafting": "AE2 In World Crafting",
"gui.ae2.Included": "Included",
"gui.ae2.IncompatibleWithCell": "Incompatible with cell",
"gui.ae2.IncreasedEnergyUseFromEnchants": "Enchants increase energy use",
"gui.ae2.Inscriber": "Inscriber",
"gui.ae2.Installed": "Installed: %s",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,9 +159,10 @@ private void configChanged() {
public static void copy(GenericStackInv from, GenericStackInv to) {
for (int i = 0; i < Math.min(from.size(), to.size()); ++i) {
var fromStack = from.getStack(i);
if (fromStack == null || to.isAllowedIn(i, fromStack.what())) {
to.setStack(i, fromStack);
if (fromStack != null && !to.isAllowedIn(i, fromStack.what())) {
fromStack = null; // Thing is not allowed in slot
}
to.setStack(i, fromStack);
}
for (int i = from.size(); i < to.size(); i++) {
to.setStack(i, null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,21 @@

package appeng.client.gui.implementations;

import java.util.ArrayList;
import java.util.List;

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.AEKey;
import appeng.api.stacks.GenericStack;
import appeng.client.gui.Icon;
import appeng.client.gui.style.ScreenStyle;
import appeng.client.gui.widgets.ActionButton;
Expand Down Expand Up @@ -67,4 +75,58 @@ private void toggleFuzzyMode(SettingToggleButton<FuzzyMode> button, boolean back
var fz = button.getNextValue(backwards);
menu.setCellFuzzyMode(fz);
}

@Override
protected List<Component> getTooltipFromContainerItem(ItemStack stack) {
var cell = getMenu().getWorkbenchItem();
if (cell.isEmpty()) {
return super.getTooltipFromContainerItem(stack);
}

// Don't show the tooltip for the cell itself
if (cell == stack) {
return super.getTooltipFromContainerItem(stack);
}

AEKey what;
var genericStack = GenericStack.unwrapItemStack(stack);
if (genericStack != null) {
what = genericStack.what();
} else {
what = AEItemKey.of(stack);
}

if (what == null) {
return super.getTooltipFromContainerItem(stack);
}

// Is it allowed in any slot?
var configInventory = getMenu().getHost().getCell().getConfigInventory(cell);

// Check if the type is supported at all
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) {
boolean anySlotMatches = false;
for (int 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);
}
}
1 change: 1 addition & 0 deletions src/main/java/appeng/core/localization/GuiText.java
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ public enum GuiText implements LocalizationEnum {
IOPort("ME IO Port"),
ImportBus("ME Import Bus"),
ImportBusFluids("ME Fluid Import Bus"),
IncompatibleWithCell("Incompatible with cell"),
InWorldCrafting("AE2 In World Crafting"),
Included("Included"),
IncreasedEnergyUseFromEnchants("Enchants increase energy use"),
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/appeng/menu/AEBaseMenu.java
Original file line number Diff line number Diff line change
Expand Up @@ -549,7 +549,7 @@ public void setFilter(int slotIndex, ItemStack item) {
return;
}

if (s instanceof FakeSlot fakeSlot && !fakeSlot.canSetFilterTo(item)) {
if (s instanceof FakeSlot fakeSlot && fakeSlot.canSetFilterTo(item)) {
s.set(item);
}
}
Expand Down

0 comments on commit 2873505

Please sign in to comment.