Skip to content

Commit

Permalink
Merge pull request #99 from FTBTeam/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
desht authored Jul 23, 2024
2 parents aa0e6ac + 6c0d32c commit dd59b41
Show file tree
Hide file tree
Showing 8 changed files with 96 additions and 4 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ publishMods {

// TODO: Migrate to something else
def tag = providers.environmentVariable("TAG").getOrElse("release")
type = tag == "beta" ? BETA : (tag == "alpha" ? ALPHA : STABLE)
type = tag.endsWith("-beta") ? BETA : (tag.endsWith("-alpha") ? ALPHA : STABLE)

def createOptions = (String projectName) -> {
publishOptions {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package dev.ftb.mods.ftblibrary.snbt.config;

import dev.ftb.mods.ftblibrary.snbt.SNBTCompoundTag;
import org.jetbrains.annotations.Nullable;

import java.util.HashMap;
import java.util.Map;

public class StringMapValue extends BaseValue<Map<String, String>> {
public StringMapValue(@Nullable SNBTConfig c, String n, Map<String, String> def) {
super(c, n, def);
super.set(new HashMap<>(def));
}

@Override
public void write(SNBTCompoundTag tag) {
Map<String, String> map = get();
SNBTCompoundTag mapTag = new SNBTCompoundTag();

for (Map.Entry<String, String> entry : map.entrySet()) {
mapTag.putString(entry.getKey(), entry.getValue());
}

tag.put(key, mapTag);
}

@Override
public void read(SNBTCompoundTag tag) {
Map<String, String> map = new HashMap<>();

for (String key : tag.getAllKeys()) {
map.put(key, tag.getString(key));
}

set(map);
}
}
17 changes: 17 additions & 0 deletions common/src/main/java/dev/ftb/mods/ftblibrary/ui/BaseScreen.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ public abstract class BaseScreen extends Panel {
private long lastClickTime = 0L;
private final Deque<ModalPanel> modalPanels;
private Widget focusedWidget = null;
private boolean renderBlur = true;

public BaseScreen() {
super(null);
Expand Down Expand Up @@ -104,6 +105,20 @@ public boolean onInit() {
return true;
}

/**
* @return if the GUI should render a blur effect behind it
*/
public boolean shouldRenderBlur() {
return renderBlur;
}

/**
* @param renderBlur sets if the GUI should render a blur effect behind it
*/
public void setRenderBlur(boolean renderBlur) {
this.renderBlur = renderBlur;
}

/**
* Should the GUI automatically close when Escape (or the inventory key - E by default) is pressed? Override this
* to return false if you need to implement custom close behaviour, e.g. a confirmation screen for unsaved changes.
Expand Down Expand Up @@ -338,6 +353,8 @@ public void drawBackground(GuiGraphics graphics, Theme theme, int x, int y, int
theme.drawGui(graphics, x, y, w, h, WidgetType.NORMAL);
}



public boolean drawDefaultBackground(GuiGraphics graphics) {
return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,14 @@ public void renderBackground(GuiGraphics matrixStack, int x, int y, float partia
}
}


@Override
protected void renderBlurredBackground(float f) {
if(wrappedGui.shouldRenderBlur()) {
super.renderBlurredBackground(f);
}
}

@Override
public void tick() {
super.tick();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
import dev.architectury.injectables.annotations.ExpectPlatform;
import net.minecraft.ChatFormatting;
import net.minecraft.network.chat.Component;
import net.minecraft.resources.ResourceKey;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.level.Level;

public class TextComponentUtils {
@ExpectPlatform
Expand All @@ -15,4 +18,12 @@ public static Component hotkeyTooltip(String txt) {
.append(Component.literal(txt).withStyle(ChatFormatting.GRAY))
.append(Component.literal("]").withStyle(ChatFormatting.DARK_GRAY));
}

public static Component translatedDimension(ResourceKey<Level> key) {
return translatedDimension(key.location());
}

public static Component translatedDimension(ResourceLocation dimId) {
return Component.translatableWithFallback(dimId.toLanguageKey("dimension"), dimId.toString());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,16 @@
import dev.ftb.mods.ftblibrary.util.CustomComponentParser;
import dev.ftb.mods.ftblibrary.util.StringUtils;
import dev.ftb.mods.ftblibrary.util.TextComponentParser;
import net.minecraft.client.gui.Font;
import net.minecraft.client.resources.language.I18n;
import net.minecraft.network.chat.*;

import java.util.ArrayList;
import java.util.List;
import java.util.function.Function;

import static net.minecraft.network.chat.CommonComponents.ELLIPSIS;

public class ClientTextComponentUtils {
private static final Function<String, Component> DEFAULT_STRING_TO_COMPONENT = ClientTextComponentUtils::defaultStringToComponent;

Expand Down Expand Up @@ -59,4 +62,15 @@ private static Component defaultStringToComponent(String s) {

return parse(I18n.get(s));
}

public static FormattedText ellipsize(Font font, FormattedText text, int maxWidth) {
final int strWidth = font.width(text);
final int ellipsisWidth = font.width(ELLIPSIS);
if (strWidth > maxWidth) {
return ellipsisWidth >= maxWidth ?
font.substrByWidth(text, maxWidth) :
FormattedText.composite(font.substrByWidth(text, maxWidth - ellipsisWidth), ELLIPSIS);
}
return text;
}
}
7 changes: 6 additions & 1 deletion common/src/main/resources/assets/ftblibrary/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -93,5 +93,10 @@
"ftblibrary.panel.position.right": "Right",
"ftblibrary.panel.position.bottom_left": "Bottom Left",
"ftblibrary.panel.position.bottom": "Bottom",
"ftblibrary.panel.position.bottom_right": "Bottom Right"
"ftblibrary.panel.position.bottom_right": "Bottom Right",
"dimension.minecraft.overworld": "Overworld",
"dimension.minecraft.the_nether": "The Nether",
"dimension.minecraft.the_end": "The End",
"dimension.hyperbox.hyperbox": "Hyperbox",
"dimension.ae2.spatial_storage": "AE2 Spatial Storage"
}
4 changes: 2 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ org.gradle.daemon=false
# Mod
mod_id=ftblibrary
readable_name=FTB Library
mod_version=2100.1.2
mod_version=2100.1.3
mod_author=FTB Team

# Maven
Expand All @@ -16,7 +16,7 @@ minecraft_version=1.21

# Deps
forge_version=49.0.31
neoforge_version=21.0.40-beta
neoforge_version=21.0.109-beta
neoforge_loader_version=4
fabric_loader_version=0.15.11
fabric_api_version=0.100.1+1.21
Expand Down

0 comments on commit dd59b41

Please sign in to comment.