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

feat: port to 1.21 #9

Merged
merged 1 commit into from
Jun 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import me.modmuss50.mpp.ReleaseType
plugins {
id "architectury-plugin" version "3.4-SNAPSHOT"
id "dev.architectury.loom" version "1.6-SNAPSHOT" apply false
id "me.modmuss50.mod-publish-plugin" version "0.4.5"
id "me.modmuss50.mod-publish-plugin" version "0.5.1"
}

architectury {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ public FTBFilterSystem() {
CommandRegistrationEvent.EVENT.register(FilterSystemCommands::registerCommands);

FilterRegistrationEvent.REGISTER.register(this::registerBuiltinFilters);
ModDataComponents.COMPONENT_TYPES.register();
ModItems.TABS.register();
ModItems.ITEMS.register();
ModDataComponents.COMPONENT_TYPES.register();

EnvExecutor.runInEnv(Env.CLIENT, () -> FTBFilterSystemClient.INSTANCE::init);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,16 @@
import net.minecraft.world.item.ItemStack;
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.NotNull;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.List;
import java.util.Objects;
import java.util.Optional;

public class FTBFilterSystemAPI {
private static final Logger LOGGER = LoggerFactory.getLogger(FTBFilterSystemAPI.class);

public static final String MOD_ID = "ftbfiltersystem";

private static API instance;
Expand Down Expand Up @@ -49,7 +53,7 @@ public static FTBFilterSystemClientAPI clientApi() {
* @return a new resource location
*/
public static ResourceLocation rl(String path) {
return new ResourceLocation(MOD_ID, path);
return ResourceLocation.fromNamespaceAndPath(MOD_ID, path);
}

/**
Expand All @@ -59,7 +63,17 @@ public static ResourceLocation rl(String path) {
* @return a resource location
*/
public static ResourceLocation modDefaultedRL(String str) {
return str.indexOf(':') > 0 ? new ResourceLocation(str) : new ResourceLocation(FTBFilterSystemAPI.MOD_ID, str);
if (str.indexOf(":") > 0) {
var result = ResourceLocation.tryParse(str);
if (result == null) {
LOGGER.warn("Invalid resource location: {}, falling back to ftbfiltersystem:", str);
return rl(str);
}

return result;
}

return rl(str);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ public void render(GuiGraphics guiGraphics, int pMouseX, int pMouseY, float pPar
guiGraphics.fill(scrollArea.getX() - 2, scrollArea.getY() - 2, scrollArea.getX() + scrollArea.getWidth(), scrollArea.getY() + scrollArea.getHeight(), 0xFF808080);
guiGraphics.fill(scrollArea.getX() - 1, scrollArea.getY() - 1, scrollArea.getX() + scrollArea.getWidth() - 1, scrollArea.getY() + scrollArea.getHeight() - 1, 0xFFA0A0A0);
// guiGraphics.blit(SCROLL_TEXTURE, sx, sy1 + (int) ((sy2 - sy1 - 17) * currentScroll), 232 + (needsScrollBars() ? 0 : 12), 0, 12, 15);
guiGraphics.blitSprite(new ResourceLocation("container/creative_inventory/scroller"), sx, sy1 + (int) ((sy2 - sy1 - 17) * currentScroll), 12, 15);
guiGraphics.blitSprite(ResourceLocation.withDefaultNamespace("container/creative_inventory/scroller"), sx, sy1 + (int) ((sy2 - sy1 - 17) * currentScroll), 12, 15);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,11 @@ public void render(GuiGraphics guiGraphics, int pMouseX, int pMouseY, float pPar

@Override
protected @Nullable ItemTagFilter makeNewFilter() {
ResourceLocation location;
if (itemTagList.getSelected() != null) {
return new ItemTagFilter(filter.getParent(), itemTagList.getSelected().tagKey);
} else if (itemTagList.children().isEmpty() && ResourceLocation.isValidResourceLocation(searchField.getValue())) {
return new ItemTagFilter(filter.getParent(), TagKey.create(Registries.ITEM, new ResourceLocation(searchField.getValue())));
} else if (itemTagList.children().isEmpty() && (location = ResourceLocation.tryParse(searchField.getValue())) != null) {
return new ItemTagFilter(filter.getParent(), TagKey.create(Registries.ITEM, location));
} else {
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public String getStringArg() {

public static ItemFilter fromString(SmartFilter.Compound parent, String str) {
try {
Item item = BuiltInRegistries.ITEM.getOrThrow(ResourceKey.create(Registries.ITEM, new ResourceLocation(str)));
Item item = BuiltInRegistries.ITEM.getOrThrow(ResourceKey.create(Registries.ITEM, ResourceLocation.tryParse(str)));
return new ItemFilter(parent, item);
} catch (IllegalArgumentException | IllegalStateException e) {
throw new FilterException(e.getMessage(), e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public String getStringArg() {

public static ItemTagFilter fromString(SmartFilter.Compound parent, String str) {
try {
return new ItemTagFilter(parent, TagKey.create(Registries.ITEM, new ResourceLocation(str)));
return new ItemTagFilter(parent, TagKey.create(Registries.ITEM, ResourceLocation.tryParse(str)));
} catch (ResourceLocationException e) {
throw new FilterException("invalid tag key " + str, e);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,33 +1,33 @@
package dev.ftb.mods.ftbfiltersystem.integration.jei;

import dev.ftb.mods.ftbfiltersystem.api.FTBFilterSystemAPI;
import dev.ftb.mods.ftbfiltersystem.client.gui.ComponentConfigScreen;
import dev.ftb.mods.ftbfiltersystem.client.gui.ItemConfigScreen;
import dev.ftb.mods.ftbfiltersystem.client.gui.ModConfigScreen;
import mezz.jei.api.IModPlugin;
import mezz.jei.api.JeiPlugin;
import mezz.jei.api.registration.IGuiHandlerRegistration;
import net.minecraft.resources.ResourceLocation;

@JeiPlugin
public class JEIIntegration implements IModPlugin {
private final ResourceLocation ID = FTBFilterSystemAPI.rl("default");

@Override
public ResourceLocation getPluginUid() {
return ID;
}

@Override
public void registerGuiHandlers(IGuiHandlerRegistration registration) {
registration.addGuiScreenHandler(ItemConfigScreen.class, new FFSScreenHandler<>());
registration.addGhostIngredientHandler(ItemConfigScreen.class, new FFSGhostHandler<>());

registration.addGuiScreenHandler(ComponentConfigScreen.class, new FFSScreenHandler<>());
// registration.addGhostIngredientHandler(NBTConfigScreen.class, new FFSGhostHandler<>(ItemStack::hasTag));
registration.addGhostIngredientHandler(ComponentConfigScreen.class, new FFSGhostHandler<>(s -> false));

registration.addGuiScreenHandler(ModConfigScreen.class, new FFSScreenHandler<>());
registration.addGhostIngredientHandler(ModConfigScreen.class, new FFSGhostHandler<>());
}
}
//package dev.ftb.mods.ftbfiltersystem.integration.jei;
//
//import dev.ftb.mods.ftbfiltersystem.api.FTBFilterSystemAPI;
//import dev.ftb.mods.ftbfiltersystem.client.gui.ComponentConfigScreen;
//import dev.ftb.mods.ftbfiltersystem.client.gui.ItemConfigScreen;
//import dev.ftb.mods.ftbfiltersystem.client.gui.ModConfigScreen;
//import mezz.jei.api.IModPlugin;
//import mezz.jei.api.JeiPlugin;
//import mezz.jei.api.registration.IGuiHandlerRegistration;
//import net.minecraft.resources.ResourceLocation;
//
//@JeiPlugin
//public class JEIIntegration implements IModPlugin {
// private final ResourceLocation ID = FTBFilterSystemAPI.rl("default");
//
// @Override
// public ResourceLocation getPluginUid() {
// return ID;
// }
//
// @Override
// public void registerGuiHandlers(IGuiHandlerRegistration registration) {
// registration.addGuiScreenHandler(ItemConfigScreen.class, new FFSScreenHandler<>());
// registration.addGhostIngredientHandler(ItemConfigScreen.class, new FFSGhostHandler<>());
//
// registration.addGuiScreenHandler(ComponentConfigScreen.class, new FFSScreenHandler<>());
//// registration.addGhostIngredientHandler(NBTConfigScreen.class, new FFSGhostHandler<>(ItemStack::hasTag));
// registration.addGhostIngredientHandler(ComponentConfigScreen.class, new FFSGhostHandler<>(s -> false));
//
// registration.addGuiScreenHandler(ModConfigScreen.class, new FFSScreenHandler<>());
// registration.addGhostIngredientHandler(ModConfigScreen.class, new FFSGhostHandler<>());
// }
//}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public class ModItems {
public static final DeferredRegister<CreativeModeTab> TABS = DeferredRegister.create(FTBFilterSystemAPI.MOD_ID, Registries.CREATIVE_MODE_TAB);
public static final RegistrySupplier<CreativeModeTab> CREATIVE_TAB = RegistrarManager.get(FTBFilterSystemAPI.MOD_ID)
.get(Registries.CREATIVE_MODE_TAB)
.register(new ResourceLocation(FTBFilterSystemAPI.MOD_ID, "default"), ModItems::buildDefaultTab);
.register(FTBFilterSystemAPI.rl("default"), ModItems::buildDefaultTab);

public static Item.Properties defaultProps() {
return new Item.Properties();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public static List<SmartFilter> parseFilterList(SmartFilter.Compound parent, Str
String type = str.substring(0, start).trim();
String arg = unescape(str.substring(start + 1, matchingParen).trim());

if (!ResourceLocation.isValidResourceLocation(type)) {
if (ResourceLocation.tryParse(type) == null) {
throw new FilterException("invalid filter ID: " + type);
}

Expand Down
2 changes: 1 addition & 1 deletion fabric/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ dependencies {
modApi "dev.architectury:architectury-fabric:${rootProject.architectury_version}"

// modCompileOnly("mezz.jei:jei-${rootProject.minecraft_version}-fabric-api:${rootProject.jei_version}")
modCompileOnly("mezz.jei:jei-1.20.4-fabric-api:${rootProject.jei_version}")
// modCompileOnly("mezz.jei:jei-1.20.4-fabric-api:${rootProject.jei_version}")

common(project(path: ":common", configuration: "namedElements")) { transitive false }
shadowCommon(project(path: ":common", configuration: "transformProductionFabric")) { transitive false }
Expand Down
2 changes: 1 addition & 1 deletion forge/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ dependencies {
// Remove the next line if you don't want to depend on the API
modApi "dev.architectury:architectury-forge:${rootProject.architectury_version}"

modCompileOnly("mezz.jei:jei-${rootProject.minecraft_version}-forge-api:${rootProject.jei_version}")
// modCompileOnly("mezz.jei:jei-${rootProject.minecraft_version}-forge-api:${rootProject.jei_version}")

common(project(path: ":common", configuration: "namedElements")) { transitive false }
shadowCommon(project(path: ":common", configuration: "transformProductionForge")) { transitive = false }
Expand Down
23 changes: 14 additions & 9 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -1,22 +1,27 @@
org.gradle.jvmargs=-Xmx2048M

minecraft_version=1.20.6
#enabled_platforms=fabric,forge,neoforge
enabled_platforms=fabric,neoforge

archives_base_name=ftb-filter-system
mod_version=2.1.0
readable_name=FTB Filter System
maven_group=dev.ftb.mods
curseforge_id=943925

architectury_version=12.1.3
# TODO: Should we move this over to the neo format of 21.0.0
mod_version=3.0.0

minecraft_version=1.21
architectury_version=13.0.1

fabric_loader_version=0.15.10
fabric_api_version=0.97.8+1.20.6
fabric_loader_version=0.15.11
fabric_api_version=0.100.1+1.21

forge_version=49.0.31
#forge_version=49.0.31

neoforge_version=20.6.100-beta
neoforge_loader_version=1
neoforge_version=21.0.10-beta
# https://maven.neoforged.net/#/releases/net/neoforged/fancymodloader/loader
neoforge_loader_version=4

jei_version=17.3.0.49

curseforge_id=943925
2 changes: 1 addition & 1 deletion neoforge/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ dependencies {
modApi "dev.architectury:architectury-neoforge:${rootProject.architectury_version}"

// modCompileOnly("mezz.jei:jei-${rootProject.minecraft_version}-forge-api:${rootProject.jei_version}")
modCompileOnly("mezz.jei:jei-1.20.4-forge-api:${rootProject.jei_version}")
// modCompileOnly("mezz.jei:jei-1.20.4-forge-api:${rootProject.jei_version}")

common(project(path: ":common", configuration: "namedElements")) { transitive false }
shadowCommon(project(path: ":common", configuration: "transformProductionNeoForge")) { transitive = false }
Expand Down
Loading