Skip to content

Commit

Permalink
chore: ported to 1.20.4
Browse files Browse the repository at this point in the history
Basically working; no JEI, and no REI for Forge
Also Icon and all subclasses could use proper codec support due to ImageComponent
  • Loading branch information
desht committed Dec 11, 2023
1 parent 82d56dc commit aed8c95
Show file tree
Hide file tree
Showing 12 changed files with 112 additions and 48 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public SidebarGroupGuiButton() {
}

@Override
public void render(GuiGraphics graphics, int mx, int my, float partialTicks) {
public void renderWidget(GuiGraphics graphics, int mx, int my, float partialTicks) {
buttons.clear();
mouseOver = null;
int rx, ry = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import net.minecraft.ChatFormatting;
import net.minecraft.client.gui.GuiGraphics;
import net.minecraft.network.chat.ComponentContents;
import net.minecraft.network.chat.contents.PlainTextContents;
import net.minecraft.util.Mth;

public class ScrollBar extends Widget {
Expand Down Expand Up @@ -99,7 +100,7 @@ public boolean mouseScrolled(double scroll) {
public void addMouseOverText(TooltipList list) {
if (showValueOnMouseOver()) {
var t = getTitle();
list.string(t.getContents() == ComponentContents.EMPTY ? (Double.toString(getValue())) : (t + ": " + getValue()));
list.string(t.getContents() == PlainTextContents.EMPTY ? (Double.toString(getValue())) : (t + ": " + getValue()));
}

if (Theme.renderDebugBoxes) {
Expand Down
3 changes: 2 additions & 1 deletion common/src/main/java/dev/ftb/mods/ftblibrary/ui/Widget.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import net.minecraft.client.gui.screens.Screen;
import net.minecraft.network.chat.Component;
import net.minecraft.network.chat.ComponentContents;
import net.minecraft.network.chat.contents.PlainTextContents;
import net.minecraft.sounds.SoundEvents;
import org.jetbrains.annotations.Nullable;
import org.lwjgl.glfw.GLFW;
Expand Down Expand Up @@ -123,7 +124,7 @@ public WidgetType getWidgetType() {
public void addMouseOverText(TooltipList list) {
var title = getTitle();

if (title.getContents() != ComponentContents.EMPTY) {
if (title.getContents() != PlainTextContents.EMPTY) {
list.add(title);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import net.minecraft.client.resources.language.I18n;
import net.minecraft.network.chat.Component;
import net.minecraft.network.chat.ComponentContents;
import net.minecraft.network.chat.contents.PlainTextContents;

/**
* Base class for a screen which displays a scrollable list of buttons, with an optional search text box.
Expand Down Expand Up @@ -101,7 +102,7 @@ public void drawBackground(GuiGraphics graphics, Theme theme, int x, int y, int

var title = getTitle();

if (title.getContents() != ComponentContents.EMPTY) {
if (title.getContents() != PlainTextContents.EMPTY) {
theme.drawString(graphics, title, x + (width - theme.getStringWidth(title)) / 2, y - theme.getFontHeight() - 2, Theme.SHADOW);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import it.unimi.dsi.fastutil.chars.Char2ObjectOpenHashMap;
import net.minecraft.ChatFormatting;
import net.minecraft.network.chat.*;
import net.minecraft.network.chat.contents.PlainTextContents;
import org.jetbrains.annotations.Nullable;

import java.util.function.Function;
Expand Down Expand Up @@ -49,7 +50,7 @@ public static Component parse(String text, @Nullable Function<String, Component>
return c;
}

while (c.getContents() == ComponentContents.EMPTY && c.getStyle().equals(Style.EMPTY) && c.getSiblings().size() == 1) {
while (c.getContents() == PlainTextContents.EMPTY && c.getStyle().equals(Style.EMPTY) && c.getSiblings().size() == 1) {
c = c.getSiblings().get(0);
}

Expand Down Expand Up @@ -131,7 +132,7 @@ private Component parse() throws BadFormatException {
rrggbb[0] = '#';
System.arraycopy(c, i + 1, rrggbb, 1, 6);
i += 6;
style = style.withColor(TextColor.parseColor(new String(rrggbb)));
style = style.withColor(TextColor.parseColor(new String(rrggbb)).result().orElse(TextColor.fromRgb(0xFFFFFF)));
} else {
if (c[i] == ' ') {
throw new BadFormatException("Invalid formatting! You must escape whitespace after & with \\&!");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package dev.ftb.mods.ftblibrary.util.client;

import dev.ftb.mods.ftblibrary.icon.Icon;
import dev.ftb.mods.ftblibrary.util.CustomComponentParser;
import dev.ftb.mods.ftblibrary.util.StringUtils;
import dev.ftb.mods.ftblibrary.util.TextComponentParser;
Expand Down Expand Up @@ -41,25 +40,12 @@ private static Component defaultStringToComponent(String s) {
}

if (map.containsKey("image")) {
var c = new ImageComponent();
c.image = Icon.getIcon(map.get("image"));

if (map.containsKey("width")) {
c.width = Integer.parseInt(map.get("width"));
}

if (map.containsKey("height")) {
c.height = Integer.parseInt(map.get("height"));
}

switch (map.getOrDefault("align", "center").toLowerCase()) {
case "left" -> c.align = 0;
case "center" -> c.align = 1;
case "right" -> c.align = 2;
}

c.fit = map.getOrDefault("fit", "false").equals("true");

var c = ImageComponent.create(map.get("image"),
Integer.parseInt(map.getOrDefault("width", "100")),
Integer.parseInt(map.getOrDefault("height", "100")),
ImageComponent.ImageAlign.byName(map.getOrDefault("align", "center")),
map.getOrDefault("fit", "false").equals("true")
);
var output = MutableComponent.create(c);
if (map.containsKey("text")) {
output.withStyle(Style.EMPTY.withHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, parse(map.get("text")))));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,64 @@
package dev.ftb.mods.ftblibrary.util.client;

import com.mojang.serialization.Codec;
import com.mojang.serialization.MapCodec;
import com.mojang.serialization.codecs.RecordCodecBuilder;
import dev.ftb.mods.ftblibrary.config.NameMap;
import dev.ftb.mods.ftblibrary.icon.Icon;
import net.minecraft.network.chat.ComponentContents;
import net.minecraft.util.StringRepresentable;

// TODO: Fix me
public class ImageComponent implements ComponentContents {
public Icon image = Icon.empty();
public int width = 100;
public int height = 100;
public int align = 1;
public boolean fit = false;
public static final MapCodec<ImageComponent> CODEC = RecordCodecBuilder.mapCodec(instance -> instance.group(
Codec.STRING.fieldOf("image_id").forGetter(ImageComponent::imageStr),
Codec.INT.optionalFieldOf("width", 100).forGetter(ImageComponent::getWidth),
Codec.INT.optionalFieldOf("height", 100).forGetter(ImageComponent::getHeight),
ImageAlign.CODEC.optionalFieldOf("align", ImageAlign.CENTER).forGetter(ImageComponent::getAlign),
Codec.BOOL.optionalFieldOf("fit", false).forGetter(ImageComponent::isFit)
).apply(instance, ImageComponent::create));

private static final ComponentContents.Type<ImageComponent> TYPE = new ComponentContents.Type<>(CODEC, "image");

private Icon image = Icon.empty();
private int width = 100;
private int height = 100;
private ImageAlign align = ImageAlign.CENTER;
private boolean fit = false;

public ImageComponent() {
super();
}

public static ImageComponent create(String id, int width, int height, ImageAlign align, boolean fit) {
ImageComponent c = new ImageComponent();
c.image = Icon.getIcon(id);
c.width = width;
c.height = height;
c.align = align;
c.fit = fit;
return c;
}

public String imageStr() {
return image.toString();
}

public int getWidth() {
return width;
}

public int getHeight() {
return height;
}

public ImageAlign getAlign() {
return align;
}

public boolean isFit() {
return fit;
}

@Override
public String toString() {
Expand All @@ -33,4 +76,33 @@ public String toString() {
sb.append('}');
return sb.toString();
}

@Override
public Type<?> type() {
return TYPE;
}

public enum ImageAlign implements StringRepresentable {
LEFT("left"),
CENTER("center"),
RIGHT("right");

public static final Codec<ImageAlign> CODEC = StringRepresentable.fromEnum(ImageAlign::values);
public static final NameMap<ImageAlign> NAME_MAP = NameMap.of(CENTER, values()).id(v -> v.name).create();

private final String name;

ImageAlign(String name) {
this.name = name;
}

public static ImageAlign byName(String name) {
return NAME_MAP.get(name);
}

@Override
public String getSerializedName() {
return name;
}
}
}
9 changes: 6 additions & 3 deletions forge/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,12 @@ dependencies {
modApi "dev.architectury:architectury-forge:${rootProject.architectury_version}"

// modCompileOnly "me.shedaniel:RoughlyEnoughItems-plugin-compatibilities-forge:${rootProject.rei_plugin_compat_version}"
modCompileOnlyApi("mezz.jei:jei-${rootProject.minecraft_version}-common-api:${rootProject.jei_version}")
modCompileOnlyApi("mezz.jei:jei-${rootProject.minecraft_version}-forge-api:${rootProject.jei_version}")
modCompileOnly "me.shedaniel:RoughlyEnoughItems-forge:${rootProject.rei_version}"
// modCompileOnlyApi("mezz.jei:jei-${rootProject.minecraft_version}-common-api:${rootProject.jei_version}")
// modCompileOnlyApi("mezz.jei:jei-${rootProject.minecraft_version}-forge-api:${rootProject.jei_version}")

modCompileOnlyApi("mezz.jei:jei-1.20.2-common-api:${rootProject.jei_version}")
modCompileOnlyApi("mezz.jei:jei-1.20.2-forge-api:${rootProject.jei_version}")
// modCompileOnly "me.shedaniel:RoughlyEnoughItems-forge:${rootProject.rei_version}"

common(project(path: ":common", configuration: "dev")) { transitive false }
shadowCommon(project(path: ":common", configuration: "transformProductionForge")) { transitive false }
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
package dev.ftb.mods.ftblibrary.integration.forge;

import dev.ftb.mods.ftblibrary.integration.REIIntegration;
import me.shedaniel.rei.forge.REIPluginCommon;

@REIPluginCommon
public class REIForgePluginStub extends REIIntegration {
//@REIPluginCommon
public class REIForgePluginStub /*extends REIIntegration*/ {
}
16 changes: 8 additions & 8 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,25 @@ org.gradle.daemon=false

# Mod
mod_id=ftblibrary
mod_version=2002.1.1
mod_version=2004.1.0
mod_author=FTB Team

# Maven
archives_base_name=ftb-library
maven_group=dev.ftb.mods

# MC
minecraft_version=1.20.2
minecraft_version=1.20.4

# Deps
forge_version=48.0.37
neoforge_version=20.2.86
forge_version=49.0.3
neoforge_version=20.4.11-beta
neoforge_loader_version=1
fabric_loader_version=0.14.24
fabric_api_version=0.90.7+1.20.2
fabric_loader_version=0.15.1
fabric_api_version=0.91.2+1.20.4

architectury_version=10.0.16
rei_version=13.0.678
architectury_version=11.0.8
rei_version=14.0.680
jei_version=16.0.0.28

# mod_menu_version=1.14.6+
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ public boolean equals(Object o) {
if (o == null || getClass() != o.getClass()) {
return false;
}
var itemKey = (ItemKey) o;
return stack.getItem() == itemKey.stack.getItem() && stack.areShareTagsEqual(itemKey.stack);

return ItemStack.isSameItemSameTags(stack, ((ItemKey) o).stack);
}

@Override
Expand Down
2 changes: 1 addition & 1 deletion settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ pluginManagement {

include "common", "fabric", "forge", "neoforge"

rootProject.name = 'FTB-Library-1.20.2'
rootProject.name = 'FTB-Library-1.20.4'

0 comments on commit aed8c95

Please sign in to comment.