Skip to content

Commit

Permalink
Update to 1.16
Browse files Browse the repository at this point in the history
Plus a little rewrite, don't worry about that
  • Loading branch information
Past Ennui committed Jun 11, 2020
1 parent e2b465d commit 9adee6a
Show file tree
Hide file tree
Showing 16 changed files with 212 additions and 53 deletions.
29 changes: 29 additions & 0 deletions .github/workflows/gradlepublish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# This workflow will build a package using Gradle and then publish it to GitHub packages when a release is created
# For more information see: https://github.com/actions/setup-java#publishing-using-gradle

name: Gradle Package

on: push

jobs:
build:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- name: Set up JDK 14
uses: actions/setup-java@v1
with:
java-version: 14
server-id: github # Value of the distributionManagement/repository/id field of the pom.xml
settings-path: ${{ github.workspace }} # location for the settings.xml file
- name: Build with Gradle
run: gradle build

# The USERNAME and PASSWORD need to correspond to the credentials environment variables used in
# the publishing section of your build.gradle
- name: Publish to GitHub Packages
run: gradle publish
env:
USERNAME: ${{ github.actor }}
PASSWORD: ${{ secrets.GITHUB_TOKEN }}
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ build/
out/
classes/

# eclipse

*.launch

# idea

.idea/
Expand All @@ -22,4 +26,4 @@ bin/

# fabric

run/
run/
16 changes: 13 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,17 @@
# Boring Backgrounds
<img src="./src/main/resources/assets/boringbackgrounds/icon.png" align="right" width="128px"/>

A mod that changes the boring dirt background with any texture that you specify in the config file. This mod depends on [Cotton](https://www.curseforge.com/minecraft/mc-mods/cotton).
# Boring Template

A mod that changes the boring dirt background with any texture that you specify in the config file. This mod bundles the [Fiber Config API](https://github.com/FabLabsMC/fiber) and does not require any other mods.

## Download

This mod is available for download on the following services:

- [CurseForge (recommended)](https://www.curseforge.com/minecraft/mc-mods/boring-backgrounds)
- [GitHub Releases (alternative)](https://github.com/joaoh1/BoringBackgrounds/releases)
- [GitHub Packages (indev releases, **use at your own risk**)](https://github.com/joaoh1/BoringBackgrounds/packages)

## License

This mod is licensed under the MIT license. You can freely include the mod on any modpack with no permission.
This mod is licensed under the MIT license. You can freely include the mod on any modpack with no permission. Use of this mod's code on other projects is allowed as long as credits are given.
41 changes: 30 additions & 11 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,26 +1,38 @@
plugins {
id 'fabric-loom' version '0.2.7-SNAPSHOT'
id 'fabric-loom' version '0.4-SNAPSHOT'
id 'maven-publish'
}

sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8

archivesBaseName = project.archives_base_name
version = project.mod_version

if (System.env.CI == "true") {
def branch
branch = System.env.GITHUB_REF
branch = branch.substring(branch.lastIndexOf("/")+1)

version = "${project.mod_version}.${branch}+${System.env.GITHUB_RUN_NUMBER}"
} else {
version = project.mod_version
}

group = project.maven_group

repositories {
maven { url = 'http://server.bbkr.space:8081/artifactory/libs-release' }
mavenCentral()
}

dependencies {
//to change the versions, see the gradle.properties file
minecraft "com.mojang:minecraft:${project.minecraft_version}"
mappings "net.fabricmc:yarn:${project.yarn_mappings}:v2"
modImplementation "net.fabricmc:fabric-loader:${project.loader_version}"

modImplementation "io.github.cottonmc.cotton:cotton-config:1.0.0-rc.7"

modImplementation "me.zeroeightsix:fiber:${project.fiber_version}"

include "me.zeroeightsix:fiber:${project.fiber_version}"
}

processResources {
Expand Down Expand Up @@ -57,6 +69,19 @@ jar {

// configure the maven publication
publishing {
repositories {
maven {
name = "GitHubPackages"
url = uri("https://maven.pkg.github.com/joaoh1/BoringBackgrounds")
credentials {
username = project.findProperty("gpr.user") ?: System.getenv("USERNAME")
password = project.findProperty("gpr.key") ?: System.getenv("PASSWORD")
}
}
// uncomment to publish to the local maven
// mavenLocal()
}

publications {
mavenJava(MavenPublication) {
// add all the jars that should be included when publishing to maven
Expand All @@ -68,10 +93,4 @@ publishing {
}
}
}

// select the repositories you want to publish to
repositories {
// uncomment to publish to the local maven
// mavenLocal()
}
}
15 changes: 9 additions & 6 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
# Done to increase the memory available to gradle.
org.gradle.jvmargs=-Xmx1G
org.gradle.jvmargs = -Xmx1G

# Fabric Properties, check these on http://modmuss50.me/fabric.html
minecraft_version=20w10a
yarn_mappings=20w10a+build.2
loader_version=0.7.8+build.186
minecraft_version = 1.16-pre3
yarn_mappings = 1.16-pre3+build.1
loader_version = 0.8.7+build.201

# Mod Properties
mod_version = 2.0.0
mod_version = 2.1.0-1.16.pre3
maven_group = io.github.joaoh1
archives_base_name = boringbackgrounds
archives_base_name = boringbackgrounds

# Dependencies
fiber_version = 0.22.1-2
Binary file modified gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-6.2.2-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-6.5-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
2 changes: 2 additions & 0 deletions gradlew
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ esac

CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar


# Determine the Java command to use to start the JVM.
if [ -n "$JAVA_HOME" ] ; then
if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
Expand Down Expand Up @@ -129,6 +130,7 @@ fi
if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then
APP_HOME=`cygpath --path --mixed "$APP_HOME"`
CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`

JAVACMD=`cygpath --unix "$JAVACMD"`

# We build the pattern for arguments to be converted via cygpath
Expand Down
1 change: 1 addition & 0 deletions gradlew.bat
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ set CMD_LINE_ARGS=%*

set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar


@rem Execute Gradle
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,22 @@

import java.util.Random;

import io.github.cottonmc.cotton.config.ConfigManager;
import io.github.joaoh1.boringbackgrounds.config.BoringBackgroundsConfig;
import net.fabricmc.api.ClientModInitializer;
import net.minecraft.util.Identifier;

public class BoringBackgroundsMod implements ClientModInitializer {
public static BoringBackgroundsConfig config;
public static Identifier backgroundTexture;
public static String[] textureIdentifierStrings;

public static void updateBackground() {
BoringBackgroundsConfig.loadJanksonConfig();
textureIdentifierStrings = BoringBackgroundsConfig.textureIdentifiers.getValue();
backgroundTexture = new Identifier(textureIdentifierStrings[new Random().nextInt(textureIdentifierStrings.length)]);
}

@Override
public void onInitializeClient() {
config = ConfigManager.loadConfig(BoringBackgroundsConfig.class);
// Pick the background texture with a randomly generated number, it will be used by the mixin
backgroundTexture = new Identifier(config.textureIds[new Random().nextInt(config.textureIds.length)]);
updateBackground();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
package io.github.joaoh1.boringbackgrounds.config;

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;

import io.github.fablabsmc.fablabs.api.fiber.v1.exception.FiberException;
import io.github.fablabsmc.fablabs.api.fiber.v1.schema.type.derived.ConfigTypes;
import io.github.fablabsmc.fablabs.api.fiber.v1.serialization.FiberSerialization;
import io.github.fablabsmc.fablabs.api.fiber.v1.serialization.JanksonValueSerializer;
import io.github.fablabsmc.fablabs.api.fiber.v1.tree.ConfigTree;
import io.github.fablabsmc.fablabs.api.fiber.v1.tree.PropertyMirror;

public class BoringBackgroundsConfig {
//Current config
private static final Path boringBackgroundsConfigPath = Paths.get("./config/boring_backgrounds.json5");
public static final PropertyMirror<String[]> textureIdentifiers = PropertyMirror.create(ConfigTypes.makeArray(ConfigTypes.STRING));
public static final PropertyMirror<Boolean> changeAfterNewScreen = PropertyMirror.create(ConfigTypes.BOOLEAN);

//TODO - Remove backward compatibility when 3.0.0 comes
//Backward compatibility with Boring Backgrounds 2.0.0/1.0.1
private static final Path legacyBoringBackgroundsConfigPath = Paths.get("./config/boringbackgrounds.json5");
public static final PropertyMirror<String[]> legacyTextureIdentifiers = PropertyMirror.create(ConfigTypes.makeArray(ConfigTypes.STRING));

public static final ConfigTree tree = ConfigTree.builder()
.beginValue("texture_identifiers", ConfigTypes.makeArray(ConfigTypes.STRING), new String[]{"minecraft:textures/gui/options_background.png"})
.withComment("The array of texture identifiers which will replace the dirt background, one will be picked once loaded.\nExample of a texture identifier: \"minecraft:textures/block/iron_block.png\"")
.finishValue(textureIdentifiers::mirror)
.beginValue("change_after_new_screen", ConfigTypes.BOOLEAN, false)
.withComment("If enabled, when a screen is opened, a new background will be chosen from the texture identifier array.")
.finishValue(changeAfterNewScreen::mirror)
.build();

public static final ConfigTree legacyTree = ConfigTree.builder()
.beginValue("textureIds", ConfigTypes.makeArray(ConfigTypes.STRING), new String[]{"minecraft:textures/gui/options_background.png"})
.withComment("The array of texture IDs which will replace the dirt background, one will be picked.")
.finishValue(legacyTextureIdentifiers::mirror)
.build();

private static JanksonValueSerializer serializer = new JanksonValueSerializer(false);

public static void loadJanksonConfig() {
if (Files.exists(legacyBoringBackgroundsConfigPath)) {
try {
FiberSerialization.deserialize(legacyTree, Files.newInputStream(legacyBoringBackgroundsConfigPath), serializer);
textureIdentifiers.setValue(legacyTextureIdentifiers.getValue());
Files.delete(legacyBoringBackgroundsConfigPath);
saveJanksonConfig();
} catch (IOException | FiberException e) {
e.printStackTrace();
}
} else if (Files.exists(boringBackgroundsConfigPath)) {
try {
FiberSerialization.deserialize(tree, Files.newInputStream(boringBackgroundsConfigPath), serializer);
} catch (IOException | FiberException e) {
e.printStackTrace();
}
} else {
saveJanksonConfig();
}
}

public static void saveJanksonConfig() {
try {
if (!Files.exists(Paths.get("./config/"))) {
Files.createDirectories(Paths.get("./config/"));
}
FiberSerialization.serialize(tree, Files.newOutputStream(boringBackgroundsConfigPath), serializer);
} catch (IOException e) {
e.printStackTrace();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package io.github.joaoh1.boringbackgrounds.mixin;

import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

import io.github.joaoh1.boringbackgrounds.BoringBackgroundsMod;
import io.github.joaoh1.boringbackgrounds.config.BoringBackgroundsConfig;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.gui.screen.Screen;

@Mixin(MinecraftClient.class)
public class MinecraftClientMixin {
@Inject(at = @At("HEAD"), method = "openScreen(Lnet/minecraft/client/gui/screen/Screen;)V")
public void changeBackgroundAfterOpenScreen(Screen screen, CallbackInfo info) {
if (BoringBackgroundsConfig.changeAfterNewScreen.getValue()) {
BoringBackgroundsMod.updateBackground();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,21 @@
@Mixin(TextureManager.class)
public class TextureManagerMixin {
@Inject(
at = @At(value = "INVOKE", target = "net/minecraft/client/texture/AbstractTexture.bindTexture()V"),
method = "bindTextureInner(Lnet/minecraft/util/Identifier;)V",
at = @At(value = "INVOKE", target = "net/minecraft/client/texture/TextureManager.registerTexture(Lnet/minecraft/util/Identifier;Lnet/minecraft/client/texture/AbstractTexture;)V"),
locals = LocalCapture.CAPTURE_FAILHARD,
cancellable = true
)
private void customBackgroundBindTextureInner(Identifier id, CallbackInfo info, AbstractTexture abstractTexture) {
// If the identifier is the same as the background texture, hijack it and change it to the chosen texture
if (id.equals(DrawableHelper.BACKGROUND_LOCATION)) {
if (id.equals(DrawableHelper.BACKGROUND_TEXTURE)) {
abstractTexture = new ResourceTexture(BoringBackgroundsMod.backgroundTexture);
this.registerTexture(id, (AbstractTexture)abstractTexture);
((AbstractTexture)abstractTexture).bindTexture();
info.cancel();
}
}

@Shadow private void registerTexture(Identifier id, AbstractTexture abstractTexture) {}
@Shadow
private void registerTexture(Identifier id, AbstractTexture abstractTexture) {}
}
19 changes: 10 additions & 9 deletions src/main/resources/boringbackgrounds.mixins.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
{
"required": true,
"package": "io.github.joaoh1.boringbackgrounds.mixin",
"compatibilityLevel": "JAVA_8",
"client": [
"TextureManagerMixin"
],
"injectors": {
"defaultRequire": 1
}
"required": true,
"package": "io.github.joaoh1.boringbackgrounds.mixin",
"compatibilityLevel": "JAVA_8",
"client": [
"MinecraftClientMixin",
"TextureManagerMixin"
],
"injectors": {
"defaultRequire": 1
}
}
Loading

0 comments on commit 9adee6a

Please sign in to comment.