Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import de.hysky.skyblocker.config.SkyblockerConfigManager;
import de.hysky.skyblocker.config.configs.GeneralConfig;
import de.hysky.skyblocker.mixins.accessors.AbstractContainerScreenAccessor;
import de.hysky.skyblocker.skyblock.garden.GardenPlots;
import de.hysky.skyblocker.skyblock.garden.visitor.VisitorHelper;
import de.hysky.skyblocker.skyblock.itemlist.ItemRepository;
import de.hysky.skyblocker.skyblock.itemlist.recipes.SkyblockCraftingRecipe;
Expand Down Expand Up @@ -137,9 +138,8 @@ public void registerExclusionZones(ExclusionZones zones) {
});

zones.register(InventoryScreen.class, screen -> {
if (!SkyblockerConfigManager.get().farming.plotsWidget.enabled || !Utils.isInGarden()) return List.of();
AbstractContainerScreenAccessor accessor = (AbstractContainerScreenAccessor) screen;
return List.of(new Rectangle(accessor.getX() + accessor.getImageWidth() + 4, accessor.getY(), 104, 127));
if (!SkyblockerConfigManager.get().farming.plotsWidget.enabled || !Utils.isInGarden() || GardenPlots.widget == null) return List.of();
return List.of(new Rectangle(GardenPlots.widget.getX(), GardenPlots.widget.getY(), GardenPlots.widget.getWidth(), GardenPlots.widget.getHeight()));
});

zones.register(Screen.class, screen -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ public static class PlotsWidget {
public boolean enabled = true;

public boolean closeScreenOnPlotClick = false;

public int x = 0;

public int y = 0;
}

public static class VisitorHelper {
Expand Down
23 changes: 16 additions & 7 deletions src/main/java/de/hysky/skyblocker/skyblock/garden/GardenPlots.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import net.fabricmc.fabric.api.client.screen.v1.Screens;
import net.minecraft.ChatFormatting;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.navigation.ScreenRectangle;
import net.minecraft.client.gui.screens.inventory.ContainerScreen;
import net.minecraft.client.gui.screens.inventory.InventoryScreen;
import net.minecraft.core.Holder;
Expand Down Expand Up @@ -46,6 +47,7 @@ public final class GardenPlots {
private static final Path FOLDER = SkyblockerMod.CONFIG_DIR.resolve("garden_plots");

public static final @Nullable GardenPlot[] GARDEN_PLOTS = new GardenPlot[25];
public static @Nullable GardenPlotsWidget widget;

@Init
public static void init() {
Expand Down Expand Up @@ -81,15 +83,22 @@ public static void init() {

});
} else if (screen instanceof InventoryScreen inventoryScreen && Utils.getLocation().equals(Location.GARDEN) && SkyblockerConfigManager.get().farming.plotsWidget.enabled) {
GardenPlotsWidget widget = new GardenPlotsWidget(
((AbstractContainerScreenAccessor) inventoryScreen).getX() + ((AbstractContainerScreenAccessor) inventoryScreen).getImageWidth() + 4,
((AbstractContainerScreenAccessor) inventoryScreen).getY());
ScreenEvents.remove(screen).register(_ -> widget = null);
AbstractContainerScreenAccessor accessor = (AbstractContainerScreenAccessor) inventoryScreen;
widget = new GardenPlotsWidget(new ScreenRectangle(
accessor.getX(),
accessor.getY(),
accessor.getImageWidth(),
accessor.getImageHeight()
));
Screens.getWidgets(inventoryScreen).add(widget);

inventoryScreen.registerRecipeBookToggleCallback(() -> widget.setPosition(
((AbstractContainerScreenAccessor) inventoryScreen).getX() + ((AbstractContainerScreenAccessor) inventoryScreen).getImageWidth() + 4,
((AbstractContainerScreenAccessor) inventoryScreen).getY()
));
inventoryScreen.registerRecipeBookToggleCallback(() -> widget.setInventoryRectangle(new ScreenRectangle(
accessor.getX(),
accessor.getY(),
accessor.getImageWidth(),
accessor.getImageHeight()
)));
}
});

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package de.hysky.skyblocker.skyblock.garden;

import com.mojang.blaze3d.platform.cursor.CursorTypes;
import de.hysky.skyblocker.SkyblockerMod;
import de.hysky.skyblocker.config.SkyblockerConfigManager;
import de.hysky.skyblocker.skyblock.itemlist.ItemRepository;
Expand All @@ -22,6 +23,8 @@
import net.minecraft.client.gui.components.AbstractScrollArea;
import net.minecraft.client.gui.components.events.GuiEventListener;
import net.minecraft.client.gui.narration.NarrationElementOutput;
import net.minecraft.client.gui.navigation.ScreenPosition;
import net.minecraft.client.gui.navigation.ScreenRectangle;
import net.minecraft.client.input.MouseButtonEvent;
import net.minecraft.client.input.MouseButtonInfo;
import net.minecraft.client.renderer.RenderPipelines;
Expand All @@ -39,8 +42,11 @@

import java.util.Arrays;
import java.util.List;
import java.util.function.Supplier;

public class GardenPlotsWidget extends AbstractContainerWidget {
private static final Supplier<ScreenPosition> POSITION = () -> new ScreenPosition(SkyblockerConfigManager.get().farming.plotsWidget.x, SkyblockerConfigManager.get().farming.plotsWidget.y);
private static final int SPACING = 4;
private static final Identifier SLOT_HIGHLIGHT_BACK_SPRITE = Identifier.withDefaultNamespace("container/slot_highlight_back");
private static final Identifier SLOT_HIGHLIGHT_FRONT_SPRITE = Identifier.withDefaultNamespace("container/slot_highlight_front");

Expand Down Expand Up @@ -105,10 +111,14 @@ public class GardenPlotsWidget extends AbstractContainerWidget {
private int editingSlotIcon = -1;
private long updateFromTabTime = System.currentTimeMillis();
private ItemStack[] customIconOptionsItems = new ItemStack[0];
private boolean dragAreaHovered;
private @Nullable ScreenPosition dragging;
private ScreenRectangle inventoryRectangle;


public GardenPlotsWidget(int x, int y) {
super(x, y, 104, 132, Component.translatable("skyblocker.gardenPlots"), AbstractScrollArea.defaultSettings(8));
public GardenPlotsWidget(ScreenRectangle inventoryRectangle) {
super(0, 0, 104, 132, Component.translatable("skyblocker.gardenPlots"), AbstractScrollArea.defaultSettings(0));
this.inventoryRectangle = inventoryRectangle;
updatePlotItems();
updateInfestedFromTab();

Expand All @@ -129,6 +139,7 @@ public GardenPlotsWidget(int x, int y) {
_ -> MessageScheduler.INSTANCE.sendMessageAfterCooldown("/setspawn", true)
);
widgets = new ItemButtonWidget[]{deskButton, spawnButton, setSpawnButton};
setPositionFromConfig();
}

private void updatePlotItems() {
Expand Down Expand Up @@ -245,6 +256,9 @@ protected void extractWidgetRenderState(GuiGraphicsExtractor graphics, int mouse
updateFromTabTime = timeMillis;
updateInfestedFromTab();
}

dragAreaHovered = getX() + 4 < mouseX && getY() + 4 < mouseY && mouseX < getRight() - 4 && mouseY < getY() + 15;
if (dragAreaHovered) graphics.requestCursor(CursorTypes.RESIZE_ALL);
}

private void updateInfestedFromTab() {
Expand All @@ -263,9 +277,21 @@ private void updateInfestedFromTab() {
}
}

private void setPositionFromConfig() {
setPosition(inventoryRectangle.right() + SPACING + POSITION.get().x(), inventoryRectangle.top() + POSITION.get().y());
}

public void setInventoryRectangle(ScreenRectangle inventoryRectangle) {
this.inventoryRectangle = inventoryRectangle;
setPositionFromConfig();
}

@Override
public void onClick(MouseButtonEvent click, boolean doubled) {
super.onClick(click, doubled);
if (dragAreaHovered) {
dragging = new ScreenPosition((int) click.x() - getX(), (int) click.y() - getY());
}
if (hoveredSlot == -1) return;

if (editingSlotIcon >= 0) {
Expand Down Expand Up @@ -294,9 +320,27 @@ public void onClick(MouseButtonEvent click, boolean doubled) {
else MessageScheduler.INSTANCE.sendMessageAfterCooldown("/plottp " + GardenPlots.GARDEN_PLOTS[hoveredSlot].name(), true);
}

@Override
public void onRelease(MouseButtonEvent event) {
super.onRelease(event);
dragging = null;
SkyblockerConfigManager.update(config -> {
config.farming.plotsWidget.x = getX() - inventoryRectangle.right() - SPACING;
config.farming.plotsWidget.y = getY() - inventoryRectangle.top();
});
}

@Override
protected void onDrag(MouseButtonEvent event, double dx, double dy) {
if (dragging == null) return;
setPosition(
Math.max((int) event.x() - dragging.x(), inventoryRectangle.right() + SPACING),
(int) event.y() - dragging.y());
}

@Override
protected boolean isValidClickButton(MouseButtonInfo input) {
return (super.isValidClickButton(input) || input.button() == 1) && hoveredSlot != -1;
return (super.isValidClickButton(input) || input.button() == 1) && (hoveredSlot != -1 || dragAreaHovered);
}

@Override
Expand All @@ -313,11 +357,6 @@ protected int contentHeight() {
return getHeight();
}

@Override
protected double scrollRate() {
return 0;
}

@Override
public void setX(int x) {
int prevX = getX();
Expand Down
Loading