Skip to content

Commit

Permalink
Add "unlearn" button to Transmutation Terminal
Browse files Browse the repository at this point in the history
  • Loading branch information
62832 committed Jul 15, 2024
1 parent 6f1658d commit 4176425
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,15 @@ protected void updateBeforeRender() {
toggleShiftButton.setState(menu.shiftToTransmute);
learnAllButton.setState(attemptingToLearn);
setTextHidden("learned", menu.learnedLabelTicks <= 0);
setTextHidden("unlearned", menu.unlearnedLabelTicks <= 0);

if (menu.learnedLabelTicks > 0) {
menu.decrementLearnedTicks();
}

if (menu.unlearnedLabelTicks > 0) {
menu.decrementUnlearnedTicks();
}
}

private void learnAll(boolean learned) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package gripe._90.appliede.menu;

import moze_intel.projecte.api.ItemInfo;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.world.entity.player.Inventory;
import net.minecraft.world.entity.player.Player;
Expand Down Expand Up @@ -27,19 +28,25 @@ public class TransmutationTerminalMenu extends MEStorageMenu {
TransmutationTerminalMenu::new, TransmutationTerminalHost.class)
.build("transmutation_terminal");
protected static final SlotSemantic TRANSMUTE = SlotSemantics.register("APPLIEDE_TRANSMUTE", false);
protected static final SlotSemantic UNLEARN = SlotSemantics.register("APPLIEDE_UNLEARN", false);

private static final String ACTION_SET_SHIFT = "setShiftDestination";
private static final String ACTION_HIDE_LEARNED = "hideLearnedText";
private static final String ACTION_HIDE_UNLEARNED = "hideUnlearnedText";

private final TransmutationTerminalHost host;
private final Slot transmuteSlot = new FakeSlot(InternalInventory.empty(), 0);
private final Slot unlearnSlot = new FakeSlot(InternalInventory.empty(), 0);

@GuiSync(1)
public boolean shiftToTransmute;

@GuiSync(2)
public int learnedLabelTicks;

@GuiSync(3)
public int unlearnedLabelTicks;

public TransmutationTerminalMenu(int id, Inventory ip, TransmutationTerminalHost host) {
this(TYPE, id, ip, host, true);
}
Expand All @@ -50,7 +57,9 @@ public TransmutationTerminalMenu(
this.host = host;
registerClientAction(ACTION_SET_SHIFT, Boolean.class, host::setShiftToTransmute);
registerClientAction(ACTION_HIDE_LEARNED, () -> learnedLabelTicks--);
registerClientAction(ACTION_HIDE_UNLEARNED, () -> unlearnedLabelTicks--);
addSlot(transmuteSlot, TRANSMUTE);
addSlot(unlearnSlot, UNLEARN);
}

@Override
Expand All @@ -64,6 +73,23 @@ public void doAction(ServerPlayer player, InventoryAction action, int slot, long
reduced.setCount(reduced.getCount() - transmuted);
setCarried(reduced.getCount() <= 0 ? ItemStack.EMPTY : reduced);
}

if (s.equals(unlearnSlot) && !getCarried().isEmpty()) {
var node = host.getActionableNode();

if (node != null) {
var knowledge = node.getGrid().getService(KnowledgeService.class);

if (knowledge.isTrackingPlayer(player)) {
var provider = knowledge.getProviderFor(player.getUUID()).get();
provider.removeKnowledge(getCarried());
provider.syncKnowledgeChange(player, ItemInfo.fromStack(getCarried()), false);
unlearnedLabelTicks = 300;
learnedLabelTicks = 0;
broadcastChanges();
}
}
}
}

private int transmuteItem(ItemStack stack, boolean singleItem, Player player) {
Expand All @@ -74,13 +100,7 @@ private int transmuteItem(ItemStack stack, boolean singleItem, Player player) {
return 0;
}

var grid = node.getGrid();

if (grid == null) {
return 0;
}

var knowledge = grid.getService(KnowledgeService.class);
var knowledge = node.getGrid().getService(KnowledgeService.class);

if (!knowledge.isTrackingPlayer(player)) {
return 0;
Expand Down Expand Up @@ -112,6 +132,7 @@ public void setShiftToTransmute(boolean transmute) {

public void showLearned() {
learnedLabelTicks = 300;
unlearnedLabelTicks = 0;
broadcastChanges();
}

Expand All @@ -121,6 +142,12 @@ public void decrementLearnedTicks() {
}
}

public void decrementUnlearnedTicks() {
if (isClientSide()) {
sendClientAction(ACTION_HIDE_UNLEARNED);
}
}

@Override
public ItemStack quickMoveStack(Player player, int idx) {
if (shiftToTransmute) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
{
"includes": ["../terminals/terminal.json"],
"slots": {
"APPLIEDE_UNLEARN": {
"left": 71,
"bottom": 118
},
"APPLIEDE_TRANSMUTE": {
"left": 80,
"left": 89,
"bottom": 118
}
},
Expand Down Expand Up @@ -31,7 +35,17 @@
},
"color": "MUTED_TEXT_COLOR",
"position": {
"left": 18,
"left": 8,
"bottom": 114
}
},
"unlearned": {
"text": {
"translate": "gui.appliede.unlearned"
},
"color": "MUTED_TEXT_COLOR",
"position": {
"left": 8,
"bottom": 114
}
}
Expand Down
Binary file modified src/main/resources/assets/ae2/textures/guis/appliede/terminal.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions src/main/resources/assets/appliede/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"gui.appliede.shift_transmuting": "Shift-Click set to Transmute.",
"gui.appliede.toggle_storage": "Click to switch to Storage mode.",
"gui.appliede.toggle_transmutation": "Click to switch to Transmutation mode.",
"gui.appliede.unlearned": "Unlearned!",
"key.appliede.emc": "EMC",
"key.appliede.emc_tiered": "EMC^%s",
"tooltip.appliede.transmutable": "Transmutable from EMC (Shift+Click/Scroll)",
Expand Down

0 comments on commit 4176425

Please sign in to comment.