use of net.p3pp3rf1y.sophisticatedbackpacks.client.gui.BackpackScreen in project SophisticatedBackpacks by P3pp3rF1y.
the class ClientProxy method tryCallSort.
private static boolean tryCallSort(Screen gui) {
Minecraft mc = Minecraft.getInstance();
if (mc.player != null && mc.player.containerMenu instanceof BackpackContainer && gui instanceof BackpackScreen) {
BackpackScreen screen = (BackpackScreen) gui;
MouseHelper mh = mc.mouseHandler;
double mouseX = mh.xpos() * mc.getWindow().getGuiScaledWidth() / mc.getWindow().getScreenWidth();
double mouseY = mh.ypos() * mc.getWindow().getGuiScaledHeight() / mc.getWindow().getScreenHeight();
BackpackContainer container = (BackpackContainer) mc.player.containerMenu;
Slot selectedSlot = screen.findSlot(mouseX, mouseY);
if (selectedSlot != null && !container.isPlayersInventorySlot(selectedSlot.index)) {
container.sort();
return true;
}
}
return false;
}
use of net.p3pp3rf1y.sophisticatedbackpacks.client.gui.BackpackScreen in project SophisticatedBackpacks by P3pp3rF1y.
the class SBPPlugin method registerGuiHandlers.
@Override
public void registerGuiHandlers(IGuiHandlerRegistration registration) {
registration.addGuiContainerHandler(BackpackScreen.class, new IGuiContainerHandler<BackpackScreen>() {
@Override
public List<Rectangle2d> getGuiExtraAreas(BackpackScreen gui) {
List<Rectangle2d> ret = new ArrayList<>();
gui.getUpgradeSlotsRectangle().ifPresent(ret::add);
ret.addAll(gui.getUpgradeSettingsControl().getTabRectangles());
gui.getSortButtonsRectangle().ifPresent(ret::add);
return ret;
}
});
registration.addGuiContainerHandler(SettingsScreen.class, new IGuiContainerHandler<SettingsScreen>() {
@Override
public List<Rectangle2d> getGuiExtraAreas(SettingsScreen gui) {
return new ArrayList<>(gui.getSettingsTabControl().getTabRectangles());
}
});
registration.addGhostIngredientHandler(BackpackScreen.class, new IGhostIngredientHandler<BackpackScreen>() {
@Override
public <I> List<Target<I>> getTargets(BackpackScreen screen, I i, boolean b) {
List<Target<I>> targets = new ArrayList<>();
if (!(i instanceof ItemStack)) {
return targets;
}
ItemStack ghostStack = (ItemStack) i;
BackpackContainer container = screen.getMenu();
container.getOpenContainer().ifPresent(c -> c.getSlots().forEach(s -> {
if (s instanceof IFilterSlot && s.mayPlace(ghostStack)) {
targets.add(new Target<I>() {
@Override
public Rectangle2d getArea() {
return new Rectangle2d(screen.getGuiLeft() + s.x, screen.getGuiTop() + s.y, 17, 17);
}
@Override
public void accept(I i) {
PacketHandler.sendToServer(new SetGhostSlotMessage(ghostStack, s.index));
}
});
}
}));
return targets;
}
@Override
public void onComplete() {
// noop
}
});
}
use of net.p3pp3rf1y.sophisticatedbackpacks.client.gui.BackpackScreen in project SophisticatedBackpacks by P3pp3rF1y.
the class QuarkButtonReplacer method replace.
@Override
public Button replace(BackpackScreen screen, Button button) {
MiniInventoryButton miniInventoryButton = ((MiniInventoryButton) button);
int type = ObfuscationReflectionHelper.getPrivateValue(MiniInventoryButton.class, miniInventoryButton, "type");
Slot slot = screen.getMenu().getSlot(8);
int x = screen.getGuiLeft() + slot.x + 6;
int y = screen.getGuiTop() + slot.y - 13;
if (isBackpackSortButton(button, type, x, y)) {
return new MiniInventoryButton(screen, SORT_TYPE, button.x - screen.getGuiLeft(), button.y - screen.getGuiTop(), "quark.gui.button.sort_container", b -> screen.getMenu().sort());
} else if (isInsertButton(type)) {
return new MiniInventoryButton(screen, INSERT_TYPE, button.x - screen.getGuiLeft(), button.y - screen.getGuiTop(), "quark.gui.button.insert", b -> PacketHandler.sendToServer(new TransferMessage(false)));
} else if (isExtractButton(type)) {
return new MiniInventoryButton(screen, EXTRACT_TYPE, button.x - screen.getGuiLeft(), button.y - screen.getGuiTop(), "quark.gui.button.extract", b -> PacketHandler.sendToServer(new TransferMessage(true)));
}
return button;
}
use of net.p3pp3rf1y.sophisticatedbackpacks.client.gui.BackpackScreen in project SophisticatedBackpacks by P3pp3rF1y.
the class ClientProxy method sendBackpackOpenOrCloseMessage.
@SuppressWarnings({ "java:S2440", "InstantiationOfUtilityClass" })
private static void sendBackpackOpenOrCloseMessage() {
if (!GUI.isActive()) {
PacketHandler.sendToServer(new BackpackOpenMessage());
return;
}
Screen screen = Minecraft.getInstance().screen;
if (screen instanceof BackpackScreen) {
BackpackScreen backpackScreen = (BackpackScreen) screen;
Slot slot = backpackScreen.getSlotUnderMouse();
if (slot != null && slot.getItem().getItem() instanceof BackpackItem) {
if (slot.getItem().getCount() == 1) {
PacketHandler.sendToServer(new BackpackOpenMessage(slot.index, true));
}
} else {
PacketHandler.sendToServer(new BackpackCloseMessage());
}
} else if (screen instanceof InventoryScreen) {
Slot slot = ((InventoryScreen) screen).getSlotUnderMouse();
if (slot != null && isSupportedPlayerInventorySlot(slot.index) && slot.getItem().getItem() instanceof BackpackItem) {
PacketHandler.sendToServer(new BackpackOpenMessage(slot.getSlotIndex(), false));
}
}
}
Aggregations