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

Support for Block and Item List config options #228

Closed
wants to merge 12 commits into from
10 changes: 7 additions & 3 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,20 @@ on:
- v11
- v12
- v13
- v14
- v14-24w14potato
- v15

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- name: Set up JDK 17
uses: actions/setup-java@v1
- name: Set up JDK 21
uses: actions/setup-java@v2
with:
java-version: 17
java-version: 21
distribution: 'temurin'
- name: Upload to Maven
run: ./gradlew publish modPublish --stacktrace
if: |
Expand Down
12 changes: 10 additions & 2 deletions 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.4-SNAPSHOT" apply false
id "dev.architectury.loom" version "1.6-SNAPSHOT" apply false
id "me.shedaniel.unified-publishing" version "0.1.+" apply false
id "maven-publish"
id "org.cadixdev.licenser" version "0.6.1" apply false
Expand All @@ -19,6 +19,14 @@ subprojects {

repositories {
maven { url "https://maven.neoforged.net/releases/" }
if (rootProject.neoforge_pr != "") {
maven {
url "https://prmaven.neoforged.net/NeoForge/pr$rootProject.neoforge_pr"
content {
includeModule("net.neoforged", "neoforge")
}
}
}
}
}

Expand All @@ -40,7 +48,7 @@ allprojects {
// The Minecraft launcher currently installs Java 8 for users, so your mod probably wants to target Java 8 too
// JDK 9 introduced a new way of specifying this that will make sure no newer classes or methods are used.
// We'll use that if it's available, but otherwise we'll use the older option.
options.release = 17
options.release = 21
}

license {
Expand Down
4 changes: 2 additions & 2 deletions common/build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
plugins {
id "com.github.johnrengelman.shadow" version "7.0.0"
id "com.github.johnrengelman.shadow" version "8.1.1"
id "maven-publish"
}

Expand Down Expand Up @@ -31,7 +31,7 @@ dependencies {
}

architectury {
common("fabric", "forge", "neoforge")
common("fabric", "neoforge")
}

task sourcesJar(type: Jar, dependsOn: classes) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
@SuppressWarnings({"unused", "FieldMayBeFinal"})
@ApiStatus.Internal
@Config(name = "autoconfig1u_example")
@Config.Gui.Background("minecraft:textures/block/oak_planks.png")
@Config.Gui.Background(Config.Gui.Background.TRANSPARENT)
@Config.Gui.CategoryBackground(category = "b", background = "minecraft:textures/block/stone.png")
public class ExampleConfig extends PartitioningSerializer.GlobalData {
@ConfigEntry.Category("a")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
@Environment(EnvType.CLIENT)
public class ConfigScreenProvider<T extends ConfigData> implements Supplier<Screen> {

private static final ResourceLocation TRANSPARENT_BACKGROUND = new ResourceLocation(Config.Gui.Background.TRANSPARENT);
private static final ResourceLocation TRANSPARENT_BACKGROUND = ResourceLocation.parse(Config.Gui.Background.TRANSPARENT);

private final ConfigManager<T> manager;
private final GuiRegistryAccess registry;
Expand Down Expand Up @@ -100,17 +100,17 @@ public Screen get() {
String bg = configClass.getAnnotation(Config.Gui.Background.class).value();
ResourceLocation bgId = ResourceLocation.tryParse(bg);
if (TRANSPARENT_BACKGROUND.equals(bgId))
builder.transparentBackground();
builder.transparentBackground().setDefaultBackgroundTexture(null);
else
builder.setDefaultBackgroundTexture(bgId);
builder.solidBackground().setDefaultBackgroundTexture(bgId);
}

Map<String, ResourceLocation> categoryBackgrounds =
Arrays.stream(configClass.getAnnotationsByType(Config.Gui.CategoryBackground.class))
.collect(
toMap(
Config.Gui.CategoryBackground::category,
ann -> new ResourceLocation(ann.background())
ann -> ResourceLocation.parse(ann.background())
)
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,10 @@
import me.shedaniel.clothconfig2.impl.builders.SubCategoryBuilder;
import net.minecraft.ChatFormatting;
import net.minecraft.Util;
import net.minecraft.core.component.DataComponents;
import net.minecraft.core.registries.BuiltInRegistries;
import net.minecraft.core.registries.Registries;
import net.minecraft.data.registries.VanillaRegistries;
import net.minecraft.network.chat.ClickEvent;
import net.minecraft.network.chat.Component;
import net.minecraft.network.chat.HoverEvent;
Expand Down Expand Up @@ -84,7 +87,6 @@ enum DependencyDemoEnum {
}

ConfigBuilder builder = ConfigBuilder.create().setTitle(Component.translatable("title.cloth-config.config"));
builder.setDefaultBackgroundTexture(new ResourceLocation("minecraft:textures/block/oak_planks.png"));
builder.setGlobalized(true);
builder.setGlobalizedExpanded(false);
ConfigEntryBuilder entryBuilder = builder.entryBuilder();
Expand Down Expand Up @@ -204,7 +206,10 @@ enum DependencyDemoEnum {

testing.addEntry(entryBuilder.startTextDescription(
Component.translatable("text.cloth-config.testing.1",
Component.literal("ClothConfig").withStyle(s -> s.withBold(true).withHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_ITEM, new HoverEvent.ItemStackInfo(Util.make(new ItemStack(Items.PINK_WOOL), stack -> stack.setHoverName(Component.literal("(\u30FB\u2200\u30FB)")).enchant(Enchantments.BLOCK_EFFICIENCY, 10)))))),
Component.literal("ClothConfig").withStyle(s -> s.withBold(true).withHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_ITEM, new HoverEvent.ItemStackInfo(Util.make(new ItemStack(Items.PINK_WOOL), stack -> {
stack.set(DataComponents.CUSTOM_NAME, Component.literal("(\u30FB\u2200\u30FB)"));
stack.enchant(VanillaRegistries.createLookup().lookupOrThrow(Registries.ENCHANTMENT).getOrThrow(Enchantments.EFFICIENCY), 10);
}))))),
Component.translatable("text.cloth-config.testing.2").withStyle(s -> s.withColor(ChatFormatting.BLUE).withHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, Component.literal("https://shedaniel.gitbook.io/cloth-config/"))).withClickEvent(new ClickEvent(ClickEvent.Action.OPEN_URL, "https://shedaniel.gitbook.io/cloth-config/"))),
Component.translatable("text.cloth-config.testing.3").withStyle(s -> s.withColor(ChatFormatting.GREEN).withClickEvent(new ClickEvent(ClickEvent.Action.OPEN_FILE, Utils.getConfigFolder().getParent().resolve("options.txt").toString())))
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,12 @@
import net.fabricmc.api.Environment;
import net.minecraft.client.KeyMapping;
import net.minecraft.client.Minecraft;
import net.minecraft.core.registries.BuiltInRegistries;
import net.minecraft.network.chat.Component;
import net.minecraft.network.chat.TextColor;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.item.Item;
import net.minecraft.world.level.block.Block;

import java.util.List;
import java.util.function.Function;
Expand Down Expand Up @@ -155,4 +159,30 @@ default DropdownMenuBuilder<String> startStringDropdownMenu(Component fieldNameK
default DropdownMenuBuilder<String> startStringDropdownMenu(Component fieldNameKey, String value, Function<String, Component> toTextFunction) {
return startDropdownMenu(fieldNameKey, TopCellElementBuilder.of(value, s -> s, toTextFunction), new DefaultSelectionCellCreator<>());
}

<T> DropdownListBuilder<T> startDropdownList(Component fieldNameKey, List<T> value, Function<T, SelectionTopCellElement<T>> topCellCreator, SelectionCellCreator<T> cellCreator);

default DropdownListBuilder<ResourceLocation> startItemIdentifierList(Component fieldNameKey, List<ResourceLocation> value) {
DropdownListBuilder<ResourceLocation> entry = startDropdownList(fieldNameKey, value, element -> DropdownMenuBuilder.TopCellElementBuilder.ofItemIdentifier(BuiltInRegistries.ITEM.get(element)), DropdownMenuBuilder.CellCreatorBuilder.ofItemIdentifier());
entry.setSelections(BuiltInRegistries.ITEM.keySet());
return entry;
}

default DropdownListBuilder<ResourceLocation> startBlockIdentifierList(Component fieldNameKey, List<ResourceLocation> value) {
DropdownListBuilder<ResourceLocation> entry = startDropdownList(fieldNameKey, value, element -> DropdownMenuBuilder.TopCellElementBuilder.ofBlockIdentifier(BuiltInRegistries.BLOCK.get(element)), DropdownMenuBuilder.CellCreatorBuilder.ofBlockIdentifier());
entry.setSelections(BuiltInRegistries.BLOCK.keySet());
return entry;
}

default DropdownListBuilder<Item> startItemObjectList(Component fieldNameKey, List<Item> value) {
DropdownListBuilder<Item> entry = startDropdownList(fieldNameKey, value, element -> DropdownMenuBuilder.TopCellElementBuilder.ofItemObject(element), DropdownMenuBuilder.CellCreatorBuilder.ofItemObject());
entry.setSelections(BuiltInRegistries.ITEM);
return entry;
}

default DropdownListBuilder<Block> startBlockObjectList(Component fieldNameKey, List<Block> value) {
DropdownListBuilder<Block> entry = startDropdownList(fieldNameKey, value, element -> DropdownMenuBuilder.TopCellElementBuilder.ofBlockObject(element), DropdownMenuBuilder.CellCreatorBuilder.ofBlockObject());
entry.setSelections(BuiltInRegistries.BLOCK);
return entry;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,7 @@
public interface TabbedConfigScreen extends ConfigScreen {
void registerCategoryBackground(String text, ResourceLocation identifier);

void registerCategoryTransparency(String text, boolean transparent);

Component getSelectedCategory();
}
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
import java.util.function.Consumer;

public abstract class AbstractConfigScreen extends Screen implements ConfigScreen {
protected static final ResourceLocation CONFIG_TEX = new ResourceLocation("cloth-config2", "textures/gui/cloth_config.png");
protected static final ResourceLocation CONFIG_TEX = ResourceLocation.fromNamespaceAndPath("cloth-config2", "textures/gui/cloth_config.png");
private final ResourceLocation backgroundLocation;
protected boolean confirmSave;
protected final Screen parent;
Expand Down Expand Up @@ -137,7 +137,7 @@ public void setAlwaysShowTabs(boolean alwaysShowTabs) {
}

public boolean isTransparentBackground() {
return transparentBackground && Minecraft.getInstance().level != null;
return transparentBackground;
}

@ApiStatus.Internal
Expand Down Expand Up @@ -378,16 +378,14 @@ protected void overlayBackground(Matrix4f matrix, Rectangle rect, int red, int g
if (isTransparentBackground())
return;
Tesselator tesselator = Tesselator.getInstance();
BufferBuilder buffer = tesselator.getBuilder();
BufferBuilder buffer = tesselator.begin(VertexFormat.Mode.QUADS, DefaultVertexFormat.POSITION_TEX_COLOR);
RenderSystem.setShader(GameRenderer::getPositionTexColorShader);
RenderSystem.setShaderTexture(0, getBackgroundLocation());
RenderSystem.setShaderColor(1.0F, 1.0F, 1.0F, 1.0F);
buffer.begin(VertexFormat.Mode.QUADS, DefaultVertexFormat.POSITION_TEX_COLOR);
buffer.vertex(matrix, rect.getMinX(), rect.getMaxY(), 0.0F).uv(rect.getMinX() / 32.0F, rect.getMaxY() / 32.0F).color(red, green, blue, endAlpha).endVertex();
buffer.vertex(matrix, rect.getMaxX(), rect.getMaxY(), 0.0F).uv(rect.getMaxX() / 32.0F, rect.getMaxY() / 32.0F).color(red, green, blue, endAlpha).endVertex();
buffer.vertex(matrix, rect.getMaxX(), rect.getMinY(), 0.0F).uv(rect.getMaxX() / 32.0F, rect.getMinY() / 32.0F).color(red, green, blue, startAlpha).endVertex();
buffer.vertex(matrix, rect.getMinX(), rect.getMinY(), 0.0F).uv(rect.getMinX() / 32.0F, rect.getMinY() / 32.0F).color(red, green, blue, startAlpha).endVertex();
tesselator.end();
buffer.addVertex(matrix, rect.getMinX(), rect.getMaxY(), 0.0F).setUv(rect.getMinX() / 32.0F, rect.getMaxY() / 32.0F).setColor(red, green, blue, endAlpha);
buffer.addVertex(matrix, rect.getMaxX(), rect.getMaxY(), 0.0F).setUv(rect.getMaxX() / 32.0F, rect.getMaxY() / 32.0F).setColor(red, green, blue, endAlpha);
buffer.addVertex(matrix, rect.getMaxX(), rect.getMinY(), 0.0F).setUv(rect.getMaxX() / 32.0F, rect.getMinY() / 32.0F).setColor(red, green, blue, startAlpha);
buffer.addVertex(matrix, rect.getMinX(), rect.getMinY(), 0.0F).setUv(rect.getMinX() / 32.0F, rect.getMinY() / 32.0F).setColor(red, green, blue, startAlpha);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import java.util.Map;

public abstract class AbstractTabbedConfigScreen extends AbstractConfigScreen implements TabbedConfigScreen {
private final Map<String, Boolean> categoryTransparentBackground = Maps.newHashMap();
private final Map<String, ResourceLocation> categoryBackgroundLocation = Maps.newHashMap();

protected AbstractTabbedConfigScreen(Screen parent, Component title, ResourceLocation backgroundLocation) {
Expand All @@ -39,6 +40,19 @@ public final void registerCategoryBackground(String text, ResourceLocation ident
this.categoryBackgroundLocation.put(text, identifier);
}

@Override
public void registerCategoryTransparency(String text, boolean transparent) {
this.categoryTransparentBackground.put(text, transparent);
}

@Override
public boolean isTransparentBackground() {
Component selectedCategory = getSelectedCategory();
if (categoryTransparentBackground.containsKey(selectedCategory.getString()))
return categoryTransparentBackground.get(selectedCategory.getString());
return super.isTransparentBackground();
}

@Override
public ResourceLocation getBackgroundLocation() {
Component selectedCategory = getSelectedCategory();
Expand Down
Loading