Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dev #113

Merged
merged 29 commits into from
Aug 14, 2024
Merged

Dev #113

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
88fa6e0
Update Sidebar Icons to use Codecs & Grid Alignment Code
UnRealDinnerbone Jul 31, 2024
92fb861
Save changes made in gui, add option to remove buttons
UnRealDinnerbone Jul 31, 2024
e7c4eb6
More work on gui dragging and a little code clenaup
UnRealDinnerbone Jul 31, 2024
fa20cec
Fix Rei Integration, Cleanup Code, Better Add Button handling
UnRealDinnerbone Aug 1, 2024
8408947
Merge remote-tracking branch 'origin/dev' into feature/1.21/better-wi…
UnRealDinnerbone Aug 1, 2024
6db8e7a
More work moving stuff in grid
UnRealDinnerbone Aug 3, 2024
46b8406
Fix Grid Code, and more code comments
UnRealDinnerbone Aug 3, 2024
e7f6728
Start on work on moving grid
UnRealDinnerbone Aug 5, 2024
b7d0985
build: updated some deps, use arch loom 1.7
desht Aug 6, 2024
67526db
Hopefully finish grid alignment code
UnRealDinnerbone Aug 6, 2024
a15cf57
Fix rendering of tooltip and Sidebar buttons on the right
UnRealDinnerbone Aug 6, 2024
249e905
Remove Groups, Info Button, Remove REI Integration for buttons
UnRealDinnerbone Aug 7, 2024
5fe38df
Add REI exclude zone, more code comments
UnRealDinnerbone Aug 7, 2024
a8b4f64
Add Setting sidebar button, Change edit mode enable to right click
UnRealDinnerbone Aug 8, 2024
26d627d
Fix todo messages
UnRealDinnerbone Aug 8, 2024
34b746b
Resolve a bunch of formatting issues
UnRealDinnerbone Aug 8, 2024
9f7f207
Another pass at formatting issues
UnRealDinnerbone Aug 8, 2024
6ba93c6
move SidebarCreatedEvent and Code Cleanup
UnRealDinnerbone Aug 8, 2024
2507d84
chore: added extra-mods-* stuff, including .gitignore
desht Aug 9, 2024
b6fb15e
Convert to SimpleJsonResourceReloadListener and basic code cleanup
UnRealDinnerbone Aug 9, 2024
88efc67
Merge pull request #110 from FTBTeam/feature/1.21/better-widget-controll
desht Aug 9, 2024
8c6c993
Merge remote-tracking branch 'origin/dev' into dev
desht Aug 9, 2024
e4ae63e
Fix widget alignment code
UnRealDinnerbone Aug 9, 2024
5715a0b
Fixed comments
UnRealDinnerbone Aug 9, 2024
9a6a61b
Merge pull request #111 from FTBTeam/bugfix/1.21/fix-widget-alignment
desht Aug 9, 2024
7122da2
Merge remote-tracking branch 'origin/dev' into dev
desht Aug 9, 2024
b3d5b47
chore: added NetworkHelper.composite stream codec compositors
desht Aug 13, 2024
ce0be71
[1.21] Sidebar Fixes (#112)
UnRealDinnerbone Aug 13, 2024
2eb6c70
build: update to MC 1.21.1, Neo 21.1.9
desht Aug 14, 2024
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
/run
/classes
logs/
**/extra-mods-*/

# IDE nonsense that could go in source control but really shouldn't
*.ipr
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
plugins {
id "architectury-plugin" version "3.4-SNAPSHOT"
id "dev.architectury.loom" version "1.6-SNAPSHOT" apply false
id "dev.architectury.loom" version "1.7-SNAPSHOT" apply false
id "me.modmuss50.mod-publish-plugin" version "0.5.1"
}

Expand Down
4 changes: 2 additions & 2 deletions common/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ dependencies {
exclude group: "dev.architectury"
}

modCompileOnly("mezz.jei:jei-${minecraft_version}-common-api:${jei_version}")
modCompileOnly("mezz.jei:jei-1.21-common-api:${jei_version}")

modCompileOnly "dev.emi:emi-xplat-intermediary:${emi_version}+${minecraft_version}:api"
modCompileOnly "dev.emi:emi-xplat-intermediary:${emi_version}+1.21:api"
}

test {
Expand Down
27 changes: 5 additions & 22 deletions common/src/main/java/dev/ftb/mods/ftblibrary/FTBLibraryClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import dev.architectury.event.events.client.ClientGuiEvent;
import dev.architectury.event.events.client.ClientTickEvent;
import dev.architectury.hooks.client.screen.ScreenAccess;
import dev.architectury.platform.Platform;
import dev.architectury.registry.ReloadListenerRegistry;
import dev.ftb.mods.ftblibrary.config.FTBLibraryClientConfig;
import dev.ftb.mods.ftblibrary.config.ui.EditConfigScreen;
Expand All @@ -13,33 +12,22 @@
import dev.ftb.mods.ftblibrary.ui.CursorType;
import dev.ftb.mods.ftblibrary.ui.IScreenWrapper;
import dev.ftb.mods.ftblibrary.util.client.ClientUtils;
import me.shedaniel.rei.api.client.config.ConfigObject;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.components.events.GuiEventListener;
import net.minecraft.client.gui.screens.Screen;
import net.minecraft.client.gui.screens.inventory.AbstractContainerScreen;
import net.minecraft.client.gui.screens.inventory.EffectRenderingInventoryScreen;
import net.minecraft.server.packs.PackType;
import org.jetbrains.annotations.Nullable;

import java.util.ArrayList;

public class FTBLibraryClient {
/**
* Meaning of the different values: 0 = No, 1 = Yes, 2 = Only in inventory, 3 = Managed by integration
* (should this be an enum instead at this point?)
*/
public static int showButtons = 1;

public static CursorType lastCursorType = null;

public static void init() {
FTBLibraryClientConfig.load();

// when using REI >= 6, disable the regular sidebar buttons,
// we'll be using REI's system favourites instead.
if (Platform.isModLoaded("roughlyenoughitems")) {
showButtons = 3;
}

// Datagens hahayes
if (Minecraft.getInstance() == null) {
return;
Expand Down Expand Up @@ -73,24 +61,19 @@ private static void clientTick(Minecraft client) {

ClientUtils.RUN_LATER.clear();
}

}

public static boolean areButtonsVisible(@Nullable Screen gui) {
if (Minecraft.getInstance().level == null || Minecraft.getInstance().player == null) {
return false;
}

if (showButtons == 0 || showButtons == 2 && !(gui instanceof EffectRenderingInventoryScreen)) {
if (!FTBLibraryClientConfig.SIDEBAR_ENABLED.get()) {
return false;
}

if(showButtons == 3 && Platform.isModLoaded("roughlyenoughitems")) {
if (ConfigObject.getInstance().isFavoritesEnabled()) {
return false;
}
}

return gui instanceof AbstractContainerScreen && !SidebarButtonManager.INSTANCE.getGroups().isEmpty();
return gui instanceof AbstractContainerScreen && !SidebarButtonManager.INSTANCE.getButtons().isEmpty();
}

public static void editConfig(boolean isClientConfig) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package dev.ftb.mods.ftblibrary.api.sidebar;

import com.mojang.blaze3d.systems.RenderSystem;
import dev.ftb.mods.ftblibrary.icon.Color4I;
import net.minecraft.client.gui.Font;
import net.minecraft.client.gui.GuiGraphics;

import java.util.function.Supplier;

public interface ButtonOverlayRender {

/**
* Called when the button is rendering
* graphics is aligned so that 0, 0 is the top left corner of the button
* @param graphics The graphics object
* @param font The font object
* @param buttonSize The size of the button
*/
void render(GuiGraphics graphics, Font font, int buttonSize);

static ButtonOverlayRender ofSimpleString(Supplier<String> customTextHandler) {
return (graphics, font, buttonSize) -> {
String text = customTextHandler.get();
if (!text.isEmpty()) {
var nw = font.width(text);
Color4I.LIGHT_RED.draw(graphics, buttonSize - nw, -1, nw + 1, 9);
graphics.drawString(font, text, buttonSize - nw + 1, 0, 0xFFFFFFFF);
RenderSystem.setShaderColor(1F, 1F, 1F, 1F);
}
};
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package dev.ftb.mods.ftblibrary.api.sidebar;

import net.minecraft.network.chat.Component;
import net.minecraft.resources.ResourceLocation;

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

public interface SidebarButton {

/**
* @return the id of the button used for saving config data created from the location button in resource path
*/
ResourceLocation getId();

/**
* Register a condition that must be met for the button to be visible
* @param condition a condition that must be met for the button to be visible
*/
void addVisibilityCondition(BooleanSupplier condition);

/**
* Register a custom overlay renderer to render on top of the button icon
* @param renderer the renderer to render on top of the button icon
*/
void addOverlayRender(ButtonOverlayRender renderer);

/**
* Override the default tooltip displayed when hovering over the button
* @param tooltipOverride a supplier that returns the tooltip to be displayed when hovering over the button
*/
void setTooltipOverride(Supplier<List<Component>> tooltipOverride);

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package dev.ftb.mods.ftblibrary.api.sidebar;

import dev.architectury.event.Event;
import dev.architectury.event.EventFactory;
import dev.ftb.mods.ftblibrary.sidebar.RegisteredSidebarButton;

import java.util.function.Consumer;

public class SidebarButtonCreatedEvent {
public static final Event<Consumer<SidebarButtonCreatedEvent>> EVENT = EventFactory.createConsumerLoop(SidebarButtonCreatedEvent.class);

private final RegisteredSidebarButton button;

public SidebarButtonCreatedEvent(RegisteredSidebarButton button) {
this.button = button;
}

public RegisteredSidebarButton getButton() {
return button;
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package dev.ftb.mods.ftblibrary.config;

import dev.ftb.mods.ftblibrary.snbt.config.BooleanValue;
import dev.ftb.mods.ftblibrary.snbt.config.IntArrayValue;
import dev.ftb.mods.ftblibrary.snbt.config.SNBTConfig;
import dev.ftb.mods.ftblibrary.snbt.config.*;

import java.util.HashMap;

import static dev.ftb.mods.ftblibrary.FTBLibrary.MOD_ID;
import static dev.ftb.mods.ftblibrary.snbt.config.ConfigUtil.LOCAL_DIR;
Expand All @@ -26,6 +26,14 @@ public interface FTBLibraryClientConfig {
IntArrayValue RECENT = COLOR.addIntArray("recents", new int[0])
.comment("Colors recently selected in the color selector");

SNBTConfig SIDEBAR = CONFIG.addGroup("sidebar");
BooleanValue SIDEBAR_ENABLED = SIDEBAR.addBoolean("enabled", true)
.comment("Enable the sidebar");
EnumValue<SidebarPosition> SIDEBAR_POSITION = SIDEBAR.addEnum("position", SidebarPosition.NAME_MAP, SidebarPosition.TOP_LEFT)
.comment("Position of the sidebar");

StringSidebarMapValue SIDEBAR_BUTTONS = SIDEBAR.add(new StringSidebarMapValue(SIDEBAR, "buttons", new HashMap<>()));

static void load() {
loadDefaulted(CONFIG, LOCAL_DIR, MOD_ID);
}
Expand All @@ -44,4 +52,29 @@ static ConfigGroup getConfigGroup() {

return group;
}

public enum SidebarPosition {
TOP_LEFT(false, false),
TOP_RIGHT(false, true),
BOTTOM_LEFT(true, false),
BOTTOM_RIGHT(true, true);

private final boolean isBottom;
private final boolean isRight;

SidebarPosition(boolean isBottom, boolean isRight) {
this.isBottom = isBottom;
this.isRight = isRight;
}

public boolean isBottom() {
return isBottom;
}

public boolean isRight() {
return isRight;
}

public static final NameMap<SidebarPosition> NAME_MAP = NameMap.of(TOP_LEFT, SidebarPosition.values()).baseNameKey("ftblibrary.panel.position").create();
}
}
11 changes: 11 additions & 0 deletions common/src/main/java/dev/ftb/mods/ftblibrary/icon/Icon.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,20 @@

import com.google.gson.JsonElement;
import com.google.gson.JsonPrimitive;
import com.mojang.datafixers.FunctionType;
import com.mojang.datafixers.util.Pair;
import com.mojang.serialization.Codec;
import com.mojang.serialization.DataResult;
import com.mojang.serialization.Decoder;
import com.mojang.serialization.DynamicOps;
import com.mojang.serialization.Encoder;
import dev.ftb.mods.ftblibrary.config.ImageResourceConfig;
import dev.ftb.mods.ftblibrary.math.PixelBuffer;
import net.minecraft.network.FriendlyByteBuf;
import net.minecraft.network.codec.StreamCodec;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.util.ExtraCodecs;
import org.jetbrains.annotations.Nullable;

import java.net.URI;
Expand All @@ -20,6 +29,8 @@ public static Color4I empty() {
return Color4I.EMPTY_ICON;
}

public static final Codec<Icon> CODEC = ExtraCodecs.JSON.xmap(Icon::getIcon, Icon::getJson);

public static final StreamCodec<FriendlyByteBuf,Icon> STREAM_CODEC = new StreamCodec<>() {
@Override
public Icon decode(FriendlyByteBuf buf) {
Expand Down
Loading
Loading