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

1.21 port #94

Merged
merged 7 commits into from
Jun 18, 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 .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ 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 }}
Expand Down
80 changes: 78 additions & 2 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.6-SNAPSHOT" apply false
id "me.modmuss50.mod-publish-plugin" version "0.5.1"
}

architectury {
Expand Down Expand Up @@ -78,12 +79,87 @@ allprojects {
}

dependencies {
testImplementation 'org.junit.jupiter:junit-jupiter:5.9.2'
testImplementation 'org.junit.jupiter:junit-jupiter:5.11.0-M1'
}

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 forgeOptions = createOptions("forge")

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

curseforge("curseforgeFabric") {
from(curseForgeOptions, fabricOptions)
projectId = curseforge_id_fabric
requires('architectury-api')
requires('fabric-api')
optional('jei')
optional('roughly-enough-items')
}

curseforge("curseforgeNeoForge") {
from(curseForgeOptions, neoForgeOptions)
projectId = curseforge_id_forge
requires("architectury-api")
optional('jei')
optional('roughly-enough-items')
}

// curseforge("curseforgeForge") {
// from(curseForgeOptions, forgeOptions)
// projectId = curseforge_id_forge
// requires("architectury-api")
// optional('jei')
// optional('roughly-enough-items')
// }
}
32 changes: 3 additions & 29 deletions common/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,11 @@ dependencies {
exclude group: "dev.architectury"
}

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

// modCompileOnly "dev.emi:emi-xplat-intermediary:${emi_version}+${minecraft_version}:api"
modCompileOnly "dev.emi:emi-xplat-intermediary:${emi_version}+1.20.4:api"
modCompileOnly "dev.emi:emi-xplat-intermediary:${emi_version}+${minecraft_version}:api"
}

def ENV = System.getenv()

test {
useJUnitPlatform()
}
Expand All @@ -43,31 +39,9 @@ artifacts {
publishing {
publications {
mavenCommon(MavenPublication) {
artifactId = rootProject.archivesBaseName
artifactId = "${rootProject.archives_base_name}"
version ftbPublishing.mavenVersion
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
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public FTBLibrary() {
}

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

private void serverStarted(MinecraftServer server) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
import java.util.OptionalLong;

public class ImageResourceConfig extends ResourceConfigValue<ResourceLocation> {
public static final ResourceLocation NONE = new ResourceLocation(FTBLibrary.MOD_ID, "none");
public static final ResourceLocation NONE = FTBLibrary.rl("none");

private boolean allowEmpty = true;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,10 @@ public boolean shouldAdd(String search) {
return true;
} else if (search.startsWith("@")) {
return RegistrarManager.getId(getStack().getFluid(), Registries.FLUID).getNamespace().contains(search.substring(1));
} else if (search.startsWith("#") && ResourceLocation.isValidResourceLocation(search.substring(1))) {
return getStack().getFluid().builtInRegistryHolder().is(TagKey.create(Registries.FLUID, new ResourceLocation(search.substring(1))));
} else if (search.startsWith("#")) {
return ResourceLocation.read(search.substring(1)).result()
.map(resloc -> getStack().getFluid().builtInRegistryHolder().is(TagKey.create(Registries.FLUID, resloc)))
.orElse(false);
} else {
return getStack().getName().getString().toLowerCase().contains(search);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,16 +127,15 @@ public Collection<? extends SelectableResource<ResourceLocation>> getAllResource
StringUtils.ignoreResourceLocationErrors = false;

textures.keySet().forEach(rl -> {
if (!ResourceLocation.isValidResourceLocation(rl.toString())) {
FTBLibrary.LOGGER.warn("Image " + rl + " has invalid path! Report this to author of '" + rl.getNamespace() + "'!");
} else if (isValidImage(rl)) {
images.add(rl);
}
ResourceLocation.read(rl.toString()).result().ifPresentOrElse(
images::add,
() -> FTBLibrary.LOGGER.warn("Image {} has invalid path! Report this to author of '{}'!", rl, rl.getNamespace())
);
});

cachedImages = images.stream().sorted().map(res -> {
// shorten <mod>:textures/A/B.png to <mod>:A/B
ResourceLocation res1 = new ResourceLocation(res.getNamespace(), res.getPath().substring(9, res.getPath().length() - 4));
ResourceLocation res1 = ResourceLocation.fromNamespaceAndPath(res.getNamespace(), res.getPath().substring(9, res.getPath().length() - 4));
TextureAtlasSprite sprite = Minecraft.getInstance().getModelManager().getAtlas(InventoryMenu.BLOCK_ATLAS).getSprite(res1);
SpriteContents contents = sprite.contents();
if (contents.name().equals(MissingTextureAtlasSprite.getLocation())) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,10 @@ public boolean shouldAdd(String search) {
return true;
} else if (search.startsWith("@")) {
return RegistrarManager.getId(getStack().getItem(), Registries.ITEM).getNamespace().contains(search.substring(1));
} else if (search.startsWith("#") && ResourceLocation.isValidResourceLocation(search.substring(1))) {
return getStack().is(TagKey.create(Registries.ITEM, new ResourceLocation(search.substring(1))));
} else if (search.startsWith("#")) {
return ResourceLocation.read(search.substring(1)).result()
.map(resloc -> getStack().is(TagKey.create(Registries.ITEM, resloc)))
.orElse(false);
} else {
return getStack().getHoverName().getString().toLowerCase().contains(search);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,16 +53,23 @@ public void draw(GuiGraphics graphics, int x, int y, int w, int h) {
var maxU = sprite.getU1();
var maxV = sprite.getV1();

RenderSystem.setShader(GameRenderer::getPositionColorTexShader);
RenderSystem.setShader(GameRenderer::getPositionTexColorShader);
RenderSystem.setShaderColor(1F, 1F, 1F, 1F);
RenderSystem.setShaderTexture(0, sprite.atlasLocation());
var buffer = Tesselator.getInstance().getBuilder();
buffer.begin(VertexFormat.Mode.QUADS, DefaultVertexFormat.POSITION_COLOR_TEX);
buffer.vertex(m, x, y, 0F).color(r, g, b, a).uv(minU, minV).endVertex();
buffer.vertex(m, x, y + h, 0F).color(r, g, b, a).uv(minU, maxV).endVertex();
buffer.vertex(m, x + w, y + h, 0F).color(r, g, b, a).uv(maxU, maxV).endVertex();
buffer.vertex(m, x + w, y, 0F).color(r, g, b, a).uv(maxU, minV).endVertex();
BufferUploader.drawWithShader(buffer.end());
var buffer = Tesselator.getInstance().begin(VertexFormat.Mode.QUADS, DefaultVertexFormat.POSITION_TEX_COLOR);
buffer.addVertex(m, x, y, 0F)
.setUv(minU, minV)
.setColor(r, g, b, a);
buffer.addVertex(m, x, y + h, 0F)
.setUv(minU, maxV)
.setColor(r, g, b, a);
buffer.addVertex(m, x + w, y + h, 0F)
.setUv(maxU, maxV)
.setColor(r, g, b, a);
buffer.addVertex(m, x + w, y, 0F)
.setUv(maxU, minV)
.setColor(r, g, b, a);
BufferUploader.drawWithShader(buffer.buildOrThrow());
}

@Override
Expand All @@ -79,7 +86,7 @@ public boolean hasPixelBuffer() {
@Nullable
public PixelBuffer createPixelBuffer() {
try {
return PixelBuffer.from(Minecraft.getInstance().getResourceManager().getResource(new ResourceLocation(id.getNamespace(), "textures/" + id.getPath() + ".png")).orElseThrow().open());
return PixelBuffer.from(Minecraft.getInstance().getResourceManager().getResource(ResourceLocation.fromNamespaceAndPath(id.getNamespace(), "textures/" + id.getPath() + ".png")).orElseThrow().open());
} catch (Exception ex) {
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.mojang.blaze3d.systems.RenderSystem;
import com.mojang.blaze3d.vertex.BufferUploader;
import com.mojang.blaze3d.vertex.DefaultVertexFormat;
import com.mojang.blaze3d.vertex.Tesselator;
import com.mojang.blaze3d.vertex.VertexFormat;
Expand Down Expand Up @@ -92,17 +93,15 @@ public void draw(GuiGraphics graphics, int x, int y, int w, int h) {

RenderSystem.setShader(GameRenderer::getPositionColorShader);
RenderSystem.setShaderColor(1F, 1F, 1F, 1F);
var tesselator = Tesselator.getInstance();
var buffer = tesselator.getBuilder();
buffer.begin(VertexFormat.Mode.QUADS, DefaultVertexFormat.POSITION_COLOR);
var buffer = Tesselator.getInstance().begin(VertexFormat.Mode.QUADS, DefaultVertexFormat.POSITION_COLOR);

GuiHelper.addRectToBuffer(graphics, buffer, x, y + 1, 1, h - 2, inverse ? cd : cb);
GuiHelper.addRectToBuffer(graphics, buffer, x + w - 1, y + 1, 1, h - 2, inverse ? cb : cd);
GuiHelper.addRectToBuffer(graphics, buffer, x + 1, y, w - 2, 1, inverse ? cd : cb);
GuiHelper.addRectToBuffer(graphics, buffer, x + 1, y + h - 1, w - 2, 1, inverse ? cb : cd);
GuiHelper.addRectToBuffer(graphics, buffer, x + 1, y + 1, w - 2, h - 2, c);

tesselator.end();
BufferUploader.drawWithShader(buffer.buildOrThrow());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import com.mojang.blaze3d.platform.GlStateManager.DestFactor;
import com.mojang.blaze3d.platform.GlStateManager.SourceFactor;
import com.mojang.blaze3d.systems.RenderSystem;
import com.mojang.blaze3d.vertex.BufferUploader;
import com.mojang.blaze3d.vertex.DefaultVertexFormat;
import com.mojang.blaze3d.vertex.Tesselator;
import com.mojang.blaze3d.vertex.VertexFormat;
Expand Down Expand Up @@ -375,11 +376,10 @@ public void draw(GuiGraphics graphics, int x, int y, int w, int h) {
RenderSystem.setShaderColor(1F, 1F, 1F, 1F);
RenderSystem.enableBlend();
RenderSystem.blendFuncSeparate(SourceFactor.SRC_ALPHA, DestFactor.ONE_MINUS_SRC_ALPHA, SourceFactor.ONE, DestFactor.ZERO);
var tesselator = Tesselator.getInstance();
var buffer = tesselator.getBuilder();
buffer.begin(VertexFormat.Mode.QUADS, DefaultVertexFormat.POSITION_COLOR);

var buffer = Tesselator.getInstance().begin(VertexFormat.Mode.QUADS, DefaultVertexFormat.POSITION_COLOR);
GuiHelper.addRectToBuffer(graphics, buffer, x, y, w, h, this);
tesselator.end();
BufferUploader.drawWithShader(buffer.buildOrThrow());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ private static Icon getIcon0(String id) {
}
}

return (id.endsWith(".png") || id.endsWith(".jpg")) ? new ImageIcon(new ResourceLocation(id)) : new AtlasSpriteIcon(new ResourceLocation(id));
return (id.endsWith(".png") || id.endsWith(".jpg")) ? new ImageIcon(ResourceLocation.parse(id)) : new AtlasSpriteIcon(ResourceLocation.parse(id));
}

private static boolean isNone(String id) {
Expand Down
26 changes: 17 additions & 9 deletions common/src/main/java/dev/ftb/mods/ftblibrary/icon/ImageIcon.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.google.common.base.Objects;
import com.mojang.blaze3d.systems.RenderSystem;
import com.mojang.blaze3d.vertex.BufferUploader;
import com.mojang.blaze3d.vertex.DefaultVertexFormat;
import com.mojang.blaze3d.vertex.Tesselator;
import com.mojang.blaze3d.vertex.VertexFormat;
Expand All @@ -18,7 +19,7 @@
import org.jetbrains.annotations.Nullable;

public class ImageIcon extends Icon implements IResourceIcon {
public static final ResourceLocation MISSING_IMAGE = new ResourceLocation(FTBLibrary.MOD_ID, "textures/gui/missing_image.png");
public static final ResourceLocation MISSING_IMAGE = FTBLibrary.rl("textures/gui/missing_image.png");

public final ResourceLocation texture;
public float minU, minV, maxU, maxV;
Expand Down Expand Up @@ -84,15 +85,22 @@ public void draw(GuiGraphics graphics, int x, int y, int w, int h) {

var m = graphics.pose().last().pose();
var tesselator = Tesselator.getInstance();
var buffer = tesselator.getBuilder();
RenderSystem.setShader(GameRenderer::getPositionColorTexShader);
RenderSystem.setShader(GameRenderer::getPositionTexColorShader);
RenderSystem.setShaderColor(1F, 1F, 1F, 1F);
buffer.begin(VertexFormat.Mode.QUADS, DefaultVertexFormat.POSITION_COLOR_TEX);
buffer.vertex(m, x, y + h, 0).color(r, g, b, a).uv((float) (x / tileSize), (float) ((y + h) / tileSize)).endVertex();
buffer.vertex(m, x + w, y + h, 0).color(r, g, b, a).uv((float) ((x + w) / tileSize), (float) ((y + h) / tileSize)).endVertex();
buffer.vertex(m, x + w, y, 0).color(r, g, b, a).uv((float) ((x + w) / tileSize), (float) (y / tileSize)).endVertex();
buffer.vertex(m, x, y, 0).color(r, g, b, a).uv((float) (x / tileSize), (float) (y / tileSize)).endVertex();
tesselator.end();
var buffer = tesselator.begin(VertexFormat.Mode.QUADS, DefaultVertexFormat.POSITION_TEX_COLOR);
buffer.addVertex(m, x, y + h, 0)
.setUv((float) (x / tileSize), (float) ((y + h) / tileSize))
.setColor(r, g, b, a);
buffer.addVertex(m, x + w, y + h, 0)
.setUv((float) ((x + w) / tileSize), (float) ((y + h) / tileSize))
.setColor(r, g, b, a);
buffer.addVertex(m, x + w, y, 0)
.setUv((float) ((x + w) / tileSize), (float) (y / tileSize))
.setColor(r, g, b, a);
buffer.addVertex(m, x, y, 0)
.setUv((float) (x / tileSize), (float) (y / tileSize))
.setColor(r, g, b, a);
BufferUploader.drawWithShader(buffer.buildOrThrow());
}
}

Expand Down
Loading
Loading