Skip to content

Commit

Permalink
refactor: Move missing from server message to hint system
Browse files Browse the repository at this point in the history
  • Loading branch information
BlayTheNinth committed Sep 15, 2023
1 parent ed44209 commit 0f0182a
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 17 deletions.
1 change: 1 addition & 0 deletions shared/src/main/java/net/blay09/mods/trashslot/Hints.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@
public class Hints {
public static final String TOGGLED_OFF = "toggledOff";
public static final String TOGGLE_ON = "toggleOn";
public static final String SERVER_NOT_INSTALLED = "serverNotInstalled";
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package net.blay09.mods.trashslot.client;

import com.google.common.collect.Lists;
import com.mojang.blaze3d.platform.InputConstants;
import com.mojang.blaze3d.platform.Window;
import net.blay09.mods.balm.api.Balm;
Expand Down Expand Up @@ -29,8 +28,6 @@
import net.minecraft.world.inventory.Slot;
import net.minecraft.world.item.ItemStack;

import java.util.Optional;

public class TrashSlotGuiHandler {

private static final TrashSlotSlot trashSlot = new TrashSlotSlot();
Expand All @@ -39,7 +36,6 @@ public class TrashSlotGuiHandler {
private static boolean ignoreMouseUp;

private static boolean sentMissingMessage;
private static long missingMessageTime;
private static boolean isLeftMouseDown;

private static Hint currentHint;
Expand Down Expand Up @@ -73,7 +69,9 @@ private static void onScreenInit(ScreenInitEvent.Post event) {
if (event.getScreen() instanceof AbstractContainerScreen<?> screen) {
if (!TrashSlot.isServerSideInstalled && !sentMissingMessage) {
TrashSlot.logger.info("TrashSlot is not installed on the server and thus will be unavailable.");
missingMessageTime = System.currentTimeMillis();
MutableComponent noHabloEspanol = Component.translatable("trashslot.serverNotInstalled");
noHabloEspanol.withStyle(ChatFormatting.RED);
showHint(Hints.SERVER_NOT_INSTALLED, noHabloEspanol, 5000, true);
sentMissingMessage = true;
return;
}
Expand Down Expand Up @@ -233,8 +231,12 @@ private static boolean runKeyBindings(Screen screen, InputConstants.Type type, i
}

private static void showHint(String id, MutableComponent message, int timeToDisplay) {
showHint(id, message, timeToDisplay, false);
}

private static void showHint(String id, MutableComponent message, int timeToDisplay, boolean force) {
var saveState = TrashSlotSaveState.getInstance();
if (!saveState.hasSeenHint(id) && TrashSlotConfig.getActive().enableHints) {
if (force || (!saveState.hasSeenHint(id) && TrashSlotConfig.getActive().enableHints)) {
currentHint = new Hint(id, message, timeToDisplay);
}
}
Expand All @@ -260,17 +262,6 @@ public static void onBackgroundDrawn(ContainerScreenDrawEvent.Background event)
}

public static void onScreenDrawn(ContainerScreenDrawEvent.Background event) {
if (missingMessageTime != 0 && System.currentTimeMillis() - missingMessageTime < 3000 && event.getScreen() instanceof AbstractContainerScreen<?> screen) {
MutableComponent noHabloEspanol = Component.translatable("trashslot.serverNotInstalled");
noHabloEspanol.withStyle(ChatFormatting.RED);
event.getGuiGraphics().renderTooltip(
Minecraft.getInstance().font,
Lists.newArrayList(noHabloEspanol),
Optional.empty(),
((AbstractContainerScreenAccessor) screen).getLeftPos() + ((AbstractContainerScreenAccessor) screen).getImageWidth() / 2 - Minecraft.getInstance().font.width(
noHabloEspanol) / 2, 25);
}

if (currentHint != null) {
currentHint.render(event.getScreen(), event.getGuiGraphics());
if (currentHint.isComplete()) {
Expand Down

0 comments on commit 0f0182a

Please sign in to comment.