Skip to content

Commit

Permalink
Merge pull request #61 from FTBTeam/1.21/dev
Browse files Browse the repository at this point in the history
feat: port to 1.21 & added mpp
  • Loading branch information
desht authored Jun 18, 2024
2 parents 44ed934 + 467bba9 commit 661eb68
Show file tree
Hide file tree
Showing 44 changed files with 451 additions and 381 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ jobs:
with:
curse-publish-task: ""
maven-snapshots: true
java-version: 21
secrets:
ftb-maven-token: ${{ secrets.FTB_MAVEN_TOKEN }}
saps-token: ${{ secrets.SAPS_TOKEN }}
saps-token: ${{ secrets.SAPS_TOKEN }}
5 changes: 3 additions & 2 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@ jobs:
!contains(github.event.head_commit.message, '[ciskip]')
uses: FTBTeam/mods-meta/.github/workflows/standard-release.yml@main
with:
curse-publish-task: curseforge
curse-publish-task: publishMods
java-version: 21
secrets:
ftb-maven-token: ${{ secrets.FTB_MAVEN_TOKEN }}
saps-token: ${{ secrets.SAPS_TOKEN }}
curse-token: ${{ secrets.CURSEFORGE_KEY }}
curse-token: ${{ secrets.CURSEFORGE_KEY }}
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,6 @@ logs
eclipse
run
.architectury-transformer/
**/extra-mods-*
**/extra-mods-*

.DS_Store
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# 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).

## [2100.0.0]

### Changed
* Ported to Minecraft 1.21. Support for Fabric and NeoForge.
* Forge support may be re-added if/when Architectury adds support for Forge
85 changes: 78 additions & 7 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
plugins {
id "architectury-plugin" version "3.4-SNAPSHOT"
id "dev.architectury.loom" version "1.2-SNAPSHOT" apply false
id "dev.architectury.loom" version "1.6-SNAPSHOT" apply false
id "me.modmuss50.mod-publish-plugin" version "0.5.1"
}

architectury {
Expand All @@ -16,10 +17,7 @@ subprojects {

dependencies {
minecraft "com.mojang:minecraft:${rootProject.minecraft_version}"
// The following line declares the mojmap mappings, you may use other mappings as well
mappings loom.officialMojangMappings()
// The following line declares the yarn mappings you may select this one as well.
// mappings "net.fabricmc:yarn:1.19.2+build.28:v2"
}
}

Expand All @@ -42,8 +40,18 @@ allprojects {
url "https://maven.architectury.dev/"
}

maven { url "https://maven.neoforged.net/" }

maven {
url "https://maven.saps.dev/minecraft"
url "https://maven.saps.dev/releases"
content {
includeGroup "dev.latvian.mods"
includeGroup "dev.ftb.mods"
}
}

maven {
url "https://maven.saps.dev/snapshots"
content {
includeGroup "dev.latvian.mods"
includeGroup "dev.ftb.mods"
Expand All @@ -68,12 +76,75 @@ allprojects {

tasks.withType(JavaCompile) {
options.encoding = "UTF-8"
options.release = 17
options.release = 21
}

java {
withSourcesJar()
}

publishing {
repositories {
if (ftbPublishing.ftbToken) {
maven {
url ftbPublishing.ftbURL
credentials {
username = ftbPublishing.ftbUser
password = ftbPublishing.ftbToken
}
}
}

if (ftbPublishing.sapsToken) {
maven {
url ftbPublishing.sapsURL
credentials {
username = ftbPublishing.sapsUser
password = ftbPublishing.sapsToken
}
}
}
}
}
}

task curseforgePublish
publishMods {
dryRun = providers.environmentVariable("CURSEFORGE_KEY").getOrNull() == null
changelog = providers.environmentVariable("CHANGELOG").getOrElse("No changelog provided")
version = "${mod_version}"

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

def createOptions = (String projectName) -> {
publishOptions {
file = project.provider { project(":$projectName").tasks.remapJar }.flatMap { it.archiveFile }
displayName = "[${projectName.toUpperCase()}][${minecraft_version}] ${readable_name} ${mod_version}"
modLoaders.add(projectName.toLowerCase())
}
}

def fabricOptions = createOptions("fabric")
def neoForgeOptions = createOptions("neoforge")

def curseForgeOptions = curseforgeOptions {
accessToken = providers.environmentVariable("CURSEFORGE_KEY")
minecraftVersions.add("${minecraft_version}")
}

curseforge("curseforgeFabric") {
from(curseForgeOptions, fabricOptions)
projectId = curseforge_id
requires("fabric-api")
requires("architectury-api")
requires('ftb-library-fabric')
}

curseforge("curseforgeNeoForge") {
from(curseForgeOptions, neoForgeOptions)
projectId = curseforge_id
requires("architectury-api")
requires('ftb-library-forge')
}
}
24 changes: 1 addition & 23 deletions common/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ dependencies {
// Do NOT use other classes from fabric loader
modImplementation "net.fabricmc:fabric-loader:${rootProject.fabric_loader_version}"
// Remove the next line if you don't want to depend on the API
modApi "dev.architectury:architectury:${rootProject.architectury_version}"
modApi "dev.architectury:architectury:${rootProject.architectury_api_version}"

modApi("dev.ftb.mods:ftb-library:${rootProject.ftb_library_version}") { transitive false }

Expand All @@ -27,26 +27,4 @@ publishing {
from components.java
}
}

repositories {
if (ftbPublishing.ftbToken) {
maven {
url ftbPublishing.ftbURL
credentials {
username = ftbPublishing.ftbUser
password = ftbPublishing.ftbToken
}
}
}

if (ftbPublishing.sapsToken) {
maven {
url ftbPublishing.sapsURL
credentials {
username = ftbPublishing.sapsUser
password = ftbPublishing.sapsToken
}
}
}
}
}
31 changes: 17 additions & 14 deletions common/src/main/java/dev/ftb/mods/ftbguides/FTBGuides.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,16 @@
import dev.architectury.utils.EnvExecutor;
import dev.ftb.mods.ftbguides.client.FTBGuidesClient;
import dev.ftb.mods.ftbguides.commands.OpenGuiCommand;
import dev.ftb.mods.ftbguides.commands.SetGuideCommand;
import dev.ftb.mods.ftbguides.docs.DocsLoader;
import dev.ftb.mods.ftbguides.net.FTBGuidesNet;
import dev.ftb.mods.ftbguides.registry.GuideBookData;
import dev.ftb.mods.ftbguides.registry.ModItems;
import net.minecraft.commands.CommandBuildContext;
import net.minecraft.commands.CommandSourceStack;
import net.minecraft.commands.Commands;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.network.chat.Component;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.server.packs.PackType;
import net.minecraft.world.InteractionHand;
Expand All @@ -27,15 +30,13 @@
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import java.util.HashMap;

public class FTBGuides {
public static final String MOD_ID = "ftbguides";
public static final String MOD_NAME = "FTB Guides";
public static final Logger LOGGER = LogManager.getLogger(MOD_NAME);

public static final CreativeModeTab ITEM_GROUP = CreativeTabRegistry.create(
new ResourceLocation(MOD_ID, MOD_ID), () -> new ItemStack(ModItems.BOOK.get())
);

public static void init() {
ReloadListenerRegistry.register(PackType.CLIENT_RESOURCES, new DocsLoader());

Expand All @@ -50,18 +51,21 @@ public static void init() {
}

public static ResourceLocation rl(String path) {
return new ResourceLocation(FTBGuides.MOD_ID, path);
return ResourceLocation.fromNamespaceAndPath(FTBGuides.MOD_ID, path);
}

private static CompoundEventResult<ItemStack> rightClickItem(Player player, InteractionHand interactionHand) {
if (player.level.isClientSide) {
if (player.level().isClientSide) {
ItemStack stack = player.getItemInHand(interactionHand);
if (stack.hasTag()) {
String target = stack.getTag().getString(MOD_ID + ":page");
if (!target.isEmpty()) {
FTBGuidesClient.openGui(target);
return CompoundEventResult.interruptTrue(stack);
GuideBookData data = stack.get(ModItems.GUIDE_DATA.get());
if (data != null) {
String target = data.guide();
if (target.isEmpty()) {
return CompoundEventResult.pass();
}

FTBGuidesClient.openGui(target);
return CompoundEventResult.interruptTrue(stack);
}
}
return CompoundEventResult.pass();
Expand All @@ -70,6 +74,7 @@ private static CompoundEventResult<ItemStack> rightClickItem(Player player, Inte
private static void registerCommands(CommandDispatcher<CommandSourceStack> dispatcher, CommandBuildContext buildContext, Commands.CommandSelection selection) {
dispatcher.register(Commands.literal(MOD_ID)
.then(OpenGuiCommand.register())
.then(SetGuideCommand.register())
);
}

Expand All @@ -78,9 +83,7 @@ public static ItemStack makeGuideBook(Item item, String page) {
}

public static ItemStack makeGuideBook(ItemStack stack, String page) {
CompoundTag tag = stack.hasTag() ? stack.getTag() : new CompoundTag();
tag.putString(MOD_ID + ":page", page);
stack.setTag(tag);
stack.set(ModItems.GUIDE_DATA.get(), new GuideBookData(page));
return stack;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@ public static void openGui(@Nullable String path) {
}

public static void displayError(Component error) {
Minecraft.getInstance().getToasts().addToast(new SystemToast(SystemToast.SystemToastIds.TUTORIAL_HINT, Component.translatable("ftbguides.gui.error"), error));
Minecraft.getInstance().getToasts().addToast(new SystemToast(SystemToast.SystemToastId.WORLD_BACKUP, Component.translatable("ftbguides.gui.error"), error));
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package dev.ftb.mods.ftbguides.client;

import dev.ftb.mods.ftbguides.FTBGuides;
import dev.ftb.mods.ftbguides.registry.GuideBookData;
import dev.ftb.mods.ftbguides.registry.ModItems;
import dev.ftb.mods.ftblibrary.icon.Color4I;
import net.minecraft.Util;
import net.minecraft.client.color.item.ItemColor;
Expand All @@ -26,8 +28,11 @@ public int getColor(ItemStack itemStack, int layer) {
}

private static String getBookNamespace(ItemStack itemStack) {
//noinspection DataFlowIssue
String s = itemStack.hasTag() ? itemStack.getTag().getString(FTBGuides.MOD_ID + ":page") : "";
return s.split(":")[0];
GuideBookData guideBookData = itemStack.get(ModItems.GUIDE_DATA.get());
if (guideBookData == null || guideBookData.guide().isEmpty()) {
return "";
}

return guideBookData.guide().split(":")[0];
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import dev.ftb.mods.ftblibrary.ui.GuiHelper;
import dev.ftb.mods.ftblibrary.ui.Theme;
import dev.ftb.mods.ftblibrary.ui.WidgetType;
import net.minecraft.client.gui.GuiGraphics;

public class FTBGuidesTheme extends Theme {
private final GuideScreen screen;
Expand All @@ -20,20 +21,20 @@ private GuideIndex.GuideTheme getGuideTheme() {
}

@Override
public void drawContextMenuBackground(PoseStack matrixStack, int x, int y, int w, int h) {
getGuideTheme().indexBgColor().draw(matrixStack, x, y, w, h);
GuiHelper.drawRectWithShade(matrixStack, x, y, w, h, getGuideTheme().guiColor(), 16);
public void drawContextMenuBackground(GuiGraphics guiGraphics, int x, int y, int w, int h) {
getGuideTheme().indexBgColor().draw(guiGraphics, x, y, w, h);
GuiHelper.drawRectWithShade(guiGraphics, x, y, w, h, getGuideTheme().guiColor(), 16);
}

@Override
public void drawScrollBarBackground(PoseStack matrixStack, int x, int y, int w, int h, WidgetType type) {
getGuideTheme().indexBgColor().draw(matrixStack, x, y, w, h);
GuiHelper.drawRectWithShade(matrixStack, x, y, w, h, getGuideTheme().guiColor(), -16);
public void drawScrollBarBackground(GuiGraphics guiGraphics, int x, int y, int w, int h, WidgetType type) {
getGuideTheme().indexBgColor().draw(guiGraphics, x, y, w, h);
GuiHelper.drawRectWithShade(guiGraphics, x, y, w, h, getGuideTheme().guiColor(), -16);
}

@Override
public void drawScrollBar(PoseStack matrixStack, int x, int y, int w, int h, WidgetType type, boolean vertical) {
getGuideTheme().guiColor().withAlpha(128).draw(matrixStack, x + 2, y + 1, w - 4, h - 2);
GuiHelper.drawRectWithShade(matrixStack, x + 2, y + 1, w - 4, h - 2, getGuideTheme().guiColor(), 16);
public void drawScrollBar(GuiGraphics guiGraphics, int x, int y, int w, int h, WidgetType type, boolean vertical) {
getGuideTheme().guiColor().withAlpha(128).draw(guiGraphics, x + 2, y + 1, w - 4, h - 2);
GuiHelper.drawRectWithShade(guiGraphics, x + 2, y + 1, w - 4, h - 2, getGuideTheme().guiColor(), 16);
}
}
Loading

0 comments on commit 661eb68

Please sign in to comment.