Skip to content

Commit

Permalink
Merge pull request #117 from FTBTeam/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
desht authored Aug 30, 2024
2 parents e354608 + f6db43f commit 5f0ad8c
Show file tree
Hide file tree
Showing 10 changed files with 146 additions and 51 deletions.
25 changes: 25 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Changelog
All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [2101.1.2]

### Fixed
* Fixed `/ftblibrary clientconfig` command not being usable without op perms

## [2101.1.1]

### Fixed
* Fixed a couple of minor GUI drawing artifacts in some screens

## [2101.1.0]

### Changed
* Updated to MC 1.21.1

### Added
* Sidebar buttons (from FTB Library and all mods which add buttons) are now all repositionable and toggleable
* New sidebar button to open client config for FTB Library (can be used to hide sidebar entirely)
* Client config can also be opened via `/ftblibrary clientconfig` command
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package dev.ftb.mods.ftblibrary;

import com.mojang.brigadier.Command;
import com.mojang.brigadier.CommandDispatcher;
import com.mojang.brigadier.context.CommandContext;
import com.mojang.brigadier.exceptions.CommandSyntaxException;
Expand Down Expand Up @@ -39,29 +40,32 @@ public class FTBLibraryCommands {

public static void registerCommands(CommandDispatcher<CommandSourceStack> dispatcher, CommandBuildContext commandBuildContext, Commands.CommandSelection type) {
var command = Commands.literal("ftblibrary")
.requires(commandSource -> commandSource.hasPermission(2))
.then(Commands.literal("gamemode")
.requires(commandSource -> commandSource.hasPermission(Commands.LEVEL_GAMEMASTERS))
.executes(context -> {
if (!context.getSource().getPlayerOrException().isCreative()) {
context.getSource().getPlayerOrException().setGameMode(GameType.CREATIVE);
} else {
context.getSource().getPlayerOrException().setGameMode(GameType.SURVIVAL);
}

return 1;
return Command.SINGLE_SUCCESS;
})
)
.then(Commands.literal("rain")
.requires(commandSource -> commandSource.hasPermission(Commands.LEVEL_GAMEMASTERS))
.executes(context -> {
if (context.getSource().getLevel().isRaining()) {
context.getSource().getLevel().setWeatherParameters(6000, 0, false, false); // clear
//Use overworld as that controls the weather for the whole server
if (context.getSource().getServer().overworld().isRaining()) {
context.getSource().getServer().overworld().setWeatherParameters(6000, 0, false, false); // clear
} else {
context.getSource().getLevel().setWeatherParameters(0, 6000, true, false);// rain
context.getSource().getServer().overworld().setWeatherParameters(0, 6000, true, false);// rain
}
return 1;
return Command.SINGLE_SUCCESS;
})
)
.then(Commands.literal("day")
.requires(commandSource -> commandSource.hasPermission(Commands.LEVEL_GAMEMASTERS))
.executes(context -> {
var addDay = (24000L - (context.getSource().getLevel().getDayTime() % 24000L) + 6000L) % 24000L;

Expand All @@ -71,10 +75,11 @@ public static void registerCommands(CommandDispatcher<CommandSourceStack> dispat
}
}

return 1;
return Command.SINGLE_SUCCESS;
})
)
.then(Commands.literal("night")
.requires(commandSource -> commandSource.hasPermission(Commands.LEVEL_GAMEMASTERS))
.executes(context -> {
var addDay = (24000L - (context.getSource().getLevel().getDayTime() % 24000L) + 18000L) % 24000L;

Expand All @@ -84,10 +89,11 @@ public static void registerCommands(CommandDispatcher<CommandSourceStack> dispat
}
}

return 1;
return Command.SINGLE_SUCCESS;
})
)
.then(Commands.literal("nbtedit")
.requires(commandSource -> commandSource.hasPermission(Commands.LEVEL_GAMEMASTERS))
.then(Commands.literal("block")
.then(Commands.argument("pos", BlockPosArgument.blockPos())
.executes(context -> editNBT(context, (info, tag) -> editBlockNBT(context, info, tag)))
Expand All @@ -111,7 +117,7 @@ public static void registerCommands(CommandDispatcher<CommandSourceStack> dispat
.requires(CommandSourceStack::isPlayer)
.executes(context -> {
NetworkManager.sendToPlayer(context.getSource().getPlayerOrException(), new EditConfigPacket(true));
return 1;
return Command.SINGLE_SUCCESS;
})
);

Expand All @@ -123,7 +129,7 @@ public static void registerCommands(CommandDispatcher<CommandSourceStack> dispat
} else {
UITesting.openTestScreen();
}
return 1;
return Command.SINGLE_SUCCESS;
})
);
}
Expand All @@ -140,7 +146,7 @@ private static int editNBT(CommandContext<CommandSourceStack> context, NBTEditCa
if (!info.isEmpty()) {
EDITING_NBT.put(player.getUUID(), info);
NetworkManager.sendToPlayer(player, new EditNBTPacket(info, tag));
return 1;
return Command.SINGLE_SUCCESS;
}

return 0;
Expand Down
14 changes: 12 additions & 2 deletions common/src/main/java/dev/ftb/mods/ftblibrary/ui/Button.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
public abstract class Button extends Widget {
protected Component title;
protected Icon icon;
private boolean forceButtonSize;

public Button(Panel panel, Component t, Icon i) {
super(panel);
Expand Down Expand Up @@ -38,6 +39,11 @@ public Button setIcon(Icon i) {
return this;
}

public Button setForceButtonSize(boolean forceButtonSize) {
this.forceButtonSize = forceButtonSize;
return this;
}

public void drawBackground(GuiGraphics graphics, Theme theme, int x, int y, int w, int h) {
theme.drawButton(graphics, x, y, w, h, getWidgetType());
}
Expand All @@ -49,9 +55,13 @@ public void drawIcon(GuiGraphics graphics, Theme theme, int x, int y, int w, int
@Override
public void draw(GuiGraphics graphics, Theme theme, int x, int y, int w, int h) {
GuiHelper.setupDrawing();
var s = h >= 16 ? 16 : 8;
drawBackground(graphics, theme, x, y, w, h);
drawIcon(graphics, theme, x + (w - s) / 2, y + (h - s) / 2, s, s);
if (forceButtonSize) {
var s = h >= 16 ? 16 : 8;
drawIcon(graphics, theme, x + (w - s) / 2, y + (h - s) / 2, s, s);
}else {
drawIcon(graphics, theme, x, y, w, h);
}
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@
import java.util.List;

public class SimpleButton extends Button {
private final Callback consumer;
private Callback consumer;
private final List<Component> tooltip;

public SimpleButton(Panel panel, Component text, Icon icon, Callback c) {
super(panel, text, icon);
consumer = c;
Expand All @@ -32,14 +33,20 @@ public void addMouseOverText(TooltipList list) {
}
}

public void setConsumer(Callback consumer) {
this.consumer = consumer;
}

@Override
public void drawBackground(GuiGraphics graphics, Theme theme, int x, int y, int w, int h) {
}

@Override
public void onClicked(MouseButton button) {
playClickSound();
consumer.onClicked(this, button);
if (consumer != null) {
consumer.onClicked(this, button);
}
}

public interface Callback {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package dev.ftb.mods.ftblibrary.ui;

import dev.ftb.mods.ftblibrary.icon.Icon;
import net.minecraft.ChatFormatting;
import net.minecraft.network.chat.Component;

public class ToggleableButton extends SimpleButton {

private Component enabledText;
private Component disabledText;

private boolean state;

public ToggleableButton(Panel panel, boolean defaultState, Icon enabled, Icon disabled, ToggleableCallback toggleableCallback) {
super(panel, Component.empty(), defaultState ? enabled : disabled, null);
this.state = defaultState;
this.setConsumer((widget, button) -> {
this.state = !this.state;
widget.setIcon(this.state ? enabled : disabled);
updateTitle();
toggleableCallback.onClicked(widget, this.state);
});
this.enabledText = Component.translatable("ftblibrary.gui.enabled").withStyle(ChatFormatting.GREEN);
this.disabledText = Component.translatable("ftblibrary.gui.disabled").withStyle(ChatFormatting.RED);
updateTitle();
}

public Component getEnabledText() {
return enabledText;
}

public ToggleableButton setEnabledText(Component enabledText) {
this.enabledText = enabledText;
updateTitle();
return this;
}

public Component getDisabledText() {
return disabledText;
}

public ToggleableButton setDisabledText(Component disabledText) {
this.disabledText = disabledText;
updateTitle();
return this;
}

private void updateTitle() {
setTitle(state ? enabledText : disabledText);
}

public interface ToggleableCallback {
void onClicked(SimpleButton widget, boolean newState);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,21 +19,24 @@ public abstract class AbstractThreePanelScreen<T extends Panel> extends BaseScre
protected final PanelScrollBar scrollBar;
private boolean showBottomPanel = true;
private boolean showCloseButton = false;
private boolean showScrollBar = true;

protected AbstractThreePanelScreen() {
super();

topPanel = createTopPanel();
mainPanel = createMainPanel();
bottomPanel = new BottomPanel();
bottomPanel = createBottomPanel();
scrollBar = new PanelScrollBar(this, ScrollBar.Plane.VERTICAL, mainPanel);
}

@Override
public void addWidgets() {
add(topPanel);
add(mainPanel);
add(scrollBar);
if (showScrollBar) {
add(scrollBar);
}
if (showBottomPanel) {
add(bottomPanel);
}
Expand All @@ -47,18 +50,20 @@ public void alignWidgets() {
topPanel.alignWidgets();

var inset = mainPanelInset();
int bottomPanelHeight = showBottomPanel ? BOTTOM_PANEL_H + inset.getSecond() : 0;
int bottomPanelHeight = showBottomPanel ? getBottomPanelHeight() + inset.getSecond() : 0;

mainPanel.setPosAndSize(inset.getFirst(), topPanelHeight + inset.getSecond(),
width - inset.getFirst() * 2, height - topPanelHeight - inset.getSecond() * 2 - bottomPanelHeight);
mainPanel.alignWidgets();

if (showBottomPanel) {
bottomPanel.setPosAndSize(0, height - BOTTOM_PANEL_H, width, BOTTOM_PANEL_H);
bottomPanel.setPosAndSize(0, height - getBottomPanelHeight(), width, getBottomPanelHeight());
bottomPanel.alignWidgets();
}

scrollBar.setPosAndSize(mainPanel.getPosX() + mainPanel.getWidth() - getScrollbarWidth(), mainPanel.getPosY(), getScrollbarWidth(), mainPanel.getHeight());
if (showScrollBar) {
scrollBar.setPosAndSize(mainPanel.getPosX() + mainPanel.getWidth() - getScrollbarWidth(), mainPanel.getPosY(), getScrollbarWidth(), mainPanel.getHeight());
}
}

@Override
Expand All @@ -72,7 +77,7 @@ public void tick() {
super.tick();

int prevWidth = mainPanel.width;
int newWidth = (scrollBar.shouldDraw() ? getGui().width - getScrollbarWidth() - 2 : getGui().width) - mainPanelInset().getFirst() * 2;
int newWidth = (showScrollBar && scrollBar.shouldDraw() ? getGui().width - getScrollbarWidth() - 2 : getGui().width) - mainPanelInset().getFirst() * 2;
if (prevWidth != newWidth) {
mainPanel.setWidth(newWidth);
mainPanel.alignWidgets();
Expand All @@ -91,6 +96,10 @@ protected Pair<Integer, Integer> mainPanelInset() {
return NO_INSET;
}

protected int getBottomPanelHeight() {
return BOTTOM_PANEL_H;
}

protected int getScrollbarWidth() {
return SCROLLBAR_WIDTH;
}
Expand All @@ -99,6 +108,10 @@ protected Panel createTopPanel() {
return new TopPanel();
}

protected Panel createBottomPanel() {
return new BottomPanel();
}

public void showBottomPanel(boolean show) {
showBottomPanel = show;
}
Expand All @@ -107,6 +120,10 @@ public void showCloseButton(boolean show) {
showCloseButton = show;
}

public void showScrollBar(boolean show) {
showScrollBar = show;
}

protected class TopPanel extends Panel {
private final SimpleButton closeButton;

Expand Down
2 changes: 2 additions & 0 deletions common/src/main/resources/assets/ftblibrary/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@
"ftblibrary.gui.edit_tag_value": "Edit Tag Value",
"ftblibrary.gui.no_selection": "Nothing Selected",
"ftblibrary.gui.key_reference": "Key Reference",
"ftblibrary.gui.enabled": "Enabled",
"ftblibrary.gui.disabled": "Disabled",
"ftblibrary.client_settings": "Client Config",
"ftblibrary.client_settings.tooltips": "Tooltips",
"ftblibrary.client_settings.tooltips.item_modname": "Show Mod Name in Item Select GUI",
Expand Down

This file was deleted.

1 change: 0 additions & 1 deletion fabric/src/main/resources/ftblibrary-fabric.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
"PlayerMixin"
],
"client": [
"AbstractContainerScreenMixin",
"KeyMappingAccessor"
],
"injectors": {
Expand Down
Loading

0 comments on commit 5f0ad8c

Please sign in to comment.