Skip to content

Commit

Permalink
Merge pull request #25 from ix0rai/1.20.6
Browse files Browse the repository at this point in the history
port to 1.20.6
  • Loading branch information
ix0rai committed May 27, 2024
2 parents 329987a + 26fd63f commit 64a98c9
Show file tree
Hide file tree
Showing 74 changed files with 1,053 additions and 999 deletions.
13 changes: 9 additions & 4 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
plugins {
id "fabric-loom" version "1.5.+"
id "com.github.johnrengelman.shadow" version "7.1.2"
id "fabric-loom" version "1.6.+"
id "com.github.johnrengelman.shadow" version "7.1.+"
id "com.modrinth.minotaur" version "2.+"
}

Expand All @@ -12,6 +12,7 @@ repositories {
maven { url = "https://maven.gegy.dev/" }
maven { url = "https://maven.terraformersmc.com/releases/" }
maven { url = "https://maven.quiltmc.org/repository/release/" }
maven { url = "https://repo.sleeping.town/" }
}

configurations {
Expand All @@ -25,12 +26,16 @@ dependencies {
mappings("org.quiltmc:quilt-mappings:${project.minecraft_version}+build.${project.quilt_mappings}:intermediary-v2")
modImplementation("net.fabricmc:fabric-loader:${project.loader_version}")

include(modImplementation("dev.lambdaurora:spruceui:${project.spruceui_version}"))
modImplementation("com.terraformersmc:modmenu:${project.mod_menu_version}")
implementation("folk.sisby:kaleido-config:0.3.1+1.3.1")
include("folk.sisby:kaleido-config:0.3.1+1.3.1")

Set<String> apiModules = [
"fabric-networking-api-v1",
"fabric-resource-loader-v0"
"fabric-resource-loader-v0",
"fabric-screen-api-v1",
"fabric-key-binding-api-v1",
"fabric-lifecycle-events-v1",
]

apiModules.forEach {
Expand Down
15 changes: 7 additions & 8 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,16 @@ org.gradle.jvmargs=-Xmx1G

# minecraft, mappings and loader dependencies
# check these on https://modmuss50.me/fabric.html
minecraft_version=1.20.4
quilt_mappings=3
loader_version=0.15.7
minecraft_version=1.20.6
quilt_mappings=6
loader_version=0.15.11

# mod properties
mod_version=1.2.0+mc1.20.4
mod_version=1.3.0+mc1.20.6
maven_group=rainglow
archives_base_name=rainglow

# other dependencies
java_version=17
spruceui_version=5.0.3+1.20.4
mod_menu_version=9.0.0
fabric_api_version=0.96.4+1.20.4
java_version=21
mod_menu_version=10.0.0-beta.1
fabric_api_version=0.98.0+1.20.6
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,6 +1,6 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.3-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.7-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
Expand Down
17 changes: 9 additions & 8 deletions gradlew
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,8 @@ done
# This is normally unused
# shellcheck disable=SC2034
APP_BASE_NAME=${0##*/}
APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit
# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036)
APP_HOME=$( cd "${APP_HOME:-./}" > /dev/null && pwd -P ) || exit

# Use the maximum available, or set MAX_FD != -1 to use that value.
MAX_FD=maximum
Expand Down Expand Up @@ -144,15 +145,15 @@ if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then
case $MAX_FD in #(
max*)
# In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked.
# shellcheck disable=SC3045
# shellcheck disable=SC2039,SC3045
MAX_FD=$( ulimit -H -n ) ||
warn "Could not query maximum file descriptor limit"
esac
case $MAX_FD in #(
'' | soft) :;; #(
*)
# In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked.
# shellcheck disable=SC3045
# shellcheck disable=SC2039,SC3045
ulimit -n "$MAX_FD" ||
warn "Could not set maximum file descriptor limit to $MAX_FD"
esac
Expand Down Expand Up @@ -201,11 +202,11 @@ fi
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'

# Collect all arguments for the java command;
# * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of
# shell script including quotes and variable substitutions, so put them in
# double quotes to make sure that they get re-expanded; and
# * put everything else in single quotes, so that it's not re-expanded.
# Collect all arguments for the java command:
# * DEFAULT_JVM_OPTS, JAVA_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments,
# and any embedded shellness will be escaped.
# * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be
# treated as '${Hostname}' itself on the command line.

set -- \
"-Dorg.gradle.appname=$APP_BASE_NAME" \
Expand Down
20 changes: 10 additions & 10 deletions gradlew.bat
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,11 @@ set JAVA_EXE=java.exe
%JAVA_EXE% -version >NUL 2>&1
if %ERRORLEVEL% equ 0 goto execute

echo.
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
echo.
echo Please set the JAVA_HOME variable in your environment to match the
echo location of your Java installation.
echo. 1>&2
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 1>&2
echo. 1>&2
echo Please set the JAVA_HOME variable in your environment to match the 1>&2
echo location of your Java installation. 1>&2

goto fail

Expand All @@ -57,11 +57,11 @@ set JAVA_EXE=%JAVA_HOME%/bin/java.exe

if exist "%JAVA_EXE%" goto execute

echo.
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
echo.
echo Please set the JAVA_HOME variable in your environment to match the
echo location of your Java installation.
echo. 1>&2
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 1>&2
echo. 1>&2
echo Please set the JAVA_HOME variable in your environment to match the 1>&2
echo location of your Java installation. 1>&2

goto fail

Expand Down
154 changes: 31 additions & 123 deletions src/main/java/io/ix0rai/rainglow/Rainglow.java
Original file line number Diff line number Diff line change
@@ -1,133 +1,70 @@
package io.ix0rai.rainglow;

import com.google.gson.Gson;
import folk.sisby.kaleido.lib.quiltconfig.api.serializers.TomlSerializer;
import folk.sisby.kaleido.lib.quiltconfig.implementor_api.ConfigEnvironment;
import io.ix0rai.rainglow.config.RainglowConfig;
import io.ix0rai.rainglow.data.*;
import net.fabricmc.api.ModInitializer;
import net.fabricmc.fabric.api.networking.v1.PayloadTypeRegistry;
import net.fabricmc.fabric.api.networking.v1.ServerPlayConnectionEvents;
import net.fabricmc.fabric.api.resource.ResourceManagerHelper;
import net.fabricmc.loader.api.FabricLoader;
import net.minecraft.entity.data.DataTracker;
import net.minecraft.entity.data.TrackedData;
import net.minecraft.entity.data.TrackedDataHandlerRegistry;
import net.minecraft.entity.mob.SlimeEntity;
import net.minecraft.entity.passive.AllayEntity;
import net.minecraft.entity.passive.GlowSquidEntity;
import net.minecraft.item.Item;
import net.minecraft.resource.ResourceType;
import net.minecraft.text.Text;
import net.minecraft.util.Identifier;
import net.minecraft.util.random.RandomGenerator;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.*;
import java.util.ArrayList;
import java.util.List;

public class Rainglow implements ModInitializer {
public static final String MOD_ID = "rainglow";
public static final Logger LOGGER = LoggerFactory.getLogger(MOD_ID);
public static final RainglowConfig CONFIG = new RainglowConfig();
private static final String FORMAT = "toml";
private static final ConfigEnvironment ENVIRONMENT = new ConfigEnvironment(FabricLoader.getInstance().getConfigDir(), FORMAT, TomlSerializer.INSTANCE);
public static final RainglowConfig CONFIG = RainglowConfig.create(ENVIRONMENT, "", MOD_ID, RainglowConfig.class);
public static final Gson GSON = new Gson();

private static final List<RainglowColour> COLOURS = new ArrayList<>();
private static final Map<String, Identifier> GLOWSQUID_TEXTURES = new HashMap<>();
private static final Map<String, Identifier> ALLAY_TEXTURES = new HashMap<>();
private static final Map<String, Identifier> SLIME_TEXTURES = new HashMap<>();
private static TrackedData<String> glowSquidColour;
private static TrackedData<String> allayColour;
private static TrackedData<String> slimeColour;

public static final String CUSTOM_NBT_KEY = "Colour";
public static final Identifier SERVER_MODE_DATA_ID = id("server_mode_data");
public static final List<String> RAINGLOW_DATAPACKS = new ArrayList<>();

@Override
public void onInitialize() {
ResourceManagerHelper.get(ResourceType.SERVER_DATA).registerReloadListener((RainglowResourceReloader) () -> id("server_mode_data"));
ResourceManagerHelper.get(ResourceType.SERVER_DATA).registerReloadListener((RainglowResourceReloader) () -> SERVER_MODE_DATA_ID);

PayloadTypeRegistry.playS2C().register(RainglowNetworking.ConfigSyncPayload.PACKET_ID, RainglowNetworking.ConfigSyncPayload.PACKET_CODEC);
PayloadTypeRegistry.playS2C().register(RainglowNetworking.ModeSyncPayload.PACKET_ID, RainglowNetworking.ModeSyncPayload.PACKET_CODEC);

ServerPlayConnectionEvents.JOIN.register((handler, sender, server) -> {
if (CONFIG.isServerSyncEnabled()) {
// send modes to client
RainglowNetworking.sendModeData(handler.player);
// send modes to client
RainglowNetworking.syncModes(handler.player);

// send config to client
RainglowNetworking.syncConfig(handler.player);
}
// send config to client
RainglowNetworking.syncConfig(handler.player);
});
}

public static Identifier id(String id) {
return new Identifier(MOD_ID, id);
}

public static void setMode(RainglowMode mode) {
GLOWSQUID_TEXTURES.clear();
ALLAY_TEXTURES.clear();
SLIME_TEXTURES.clear();
COLOURS.clear();

List<RainglowColour> colours = mode.getColours();
if (colours.isEmpty()) {
LOGGER.info("No colours were present in the internal collection, adding blue so that the game doesn't crash");
colours.add(RainglowColour.BLUE);
}
colours.forEach(Rainglow::addColour);
}

public static void refreshColours() {
// we only ever need to refresh the colours of custom mode, all other sets of colours are immutable
if (CONFIG.getMode().getId().equals("custom")) {
setMode(RainglowMode.byId("custom"));
}
}

private static void addColour(RainglowColour colour) {
COLOURS.add(colour);

GLOWSQUID_TEXTURES.put(colour.getId(), colour.getTexture(RainglowEntity.GLOW_SQUID));
ALLAY_TEXTURES.put(colour.getId(), colour.getTexture(RainglowEntity.ALLAY));
SLIME_TEXTURES.put(colour.getId(), colour.getTexture(RainglowEntity.SLIME));

if (COLOURS.size() >= 100) {
throw new RuntimeException("Too many colours registered! Only up to 99 are allowed");
}
}

public static Identifier getTexture(RainglowEntity entityType, String colour) {
if (entityType == RainglowEntity.GLOW_SQUID) return GLOWSQUID_TEXTURES.get(colour);
else if (entityType == RainglowEntity.ALLAY) return ALLAY_TEXTURES.get(colour);
else return SLIME_TEXTURES.get(colour);
}

public static int getColourIndex(String colour) {
return COLOURS.indexOf(RainglowColour.get(colour));
}

public static RainglowColour.RGB getInkRgb(int index) {
return COLOURS.get(index).getInkRgb();
}

public static RainglowColour.RGB getPassiveParticleRGB(int index, RandomGenerator random) {
RainglowColour colour = COLOURS.get(index);
return random.nextBoolean() ? colour.getPassiveParticleRgb() : colour.getAltPassiveParticleRgb();
}

public static Item getItem(int index) {
return COLOURS.get(index).getItem();
}

public static String generateRandomColourId(RandomGenerator random) {
return COLOURS.get(random.nextInt(COLOURS.size())).getId();
}

public static Identifier getDefaultTexture(RainglowEntity entityType) {
if (entityType == RainglowEntity.SLIME) return RainglowColour.LIME.getTexture(entityType);
else return RainglowColour.BLUE.getTexture(entityType);
var colours = CONFIG.getMode().getColours();
return colours.get(random.nextInt(colours.size())).getId();
}

public static boolean colourUnloaded(String colour) {
return !COLOURS.contains(RainglowColour.get(colour));
public static boolean colourUnloaded(RainglowEntity entityType, String colour) {
var colours = CONFIG.getMode().getColours();
return !colours.contains(RainglowColour.get(colour)) && !colour.equals(entityType.getDefaultColour().getId());
}

public static String translatableTextKey(String key) {
if (key.split("\\.").length != 2) throw new IllegalArgumentException("key must be in format \"category.key\"");
if (key.split("\\.").length < 2) throw new IllegalArgumentException("key must be in format \"category.key\": " + key);
return MOD_ID + "." + key;
}

Expand All @@ -139,44 +76,15 @@ public static Text translatableText(String key) {
return Text.translatable(translatableTextKey(key));
}

public static TrackedData<String> getTrackedColourData(RainglowEntity entityType) {
// we cannot statically load the tracked data because then it gets registered too early
// it breaks the squids' other tracked data, their dark ticks after being hurt
// this is a workaround to make sure the data is registered at the right time
// we simply ensure it isn't loaded until it's needed, and that fixes the issue

if (entityType == RainglowEntity.GLOW_SQUID) {
if (glowSquidColour == null) {
glowSquidColour = DataTracker.registerData(GlowSquidEntity.class, TrackedDataHandlerRegistry.STRING);
}

return glowSquidColour;
} else if (entityType == RainglowEntity.ALLAY) {
if (allayColour == null) {
allayColour = DataTracker.registerData(AllayEntity.class, TrackedDataHandlerRegistry.STRING);
}

return allayColour;
} else if (entityType == RainglowEntity.SLIME) {
if (slimeColour == null) {
slimeColour = DataTracker.registerData(SlimeEntity.class, TrackedDataHandlerRegistry.STRING);
}

return slimeColour;
}

throw new RuntimeException("called getTrackedColourData on an unsupported entity type!");
}

public static String getColour(RainglowEntity entityType, DataTracker tracker, RandomGenerator random) {
public static RainglowColour getColour(RainglowEntity entityType, DataTracker tracker, RandomGenerator random) {
// generate random colour if the squid's colour isn't currently loaded
String colour = tracker.get(getTrackedColourData(entityType));
if (colourUnloaded(colour)) {
String colour = tracker.get(entityType.getTrackedData());
if (colourUnloaded(entityType, colour)) {
// Use last generated colour if not null else generate a new colour
tracker.set(getTrackedColourData(entityType), generateRandomColourId(random));
colour = tracker.get(getTrackedColourData(entityType));
tracker.set(entityType.getTrackedData(), generateRandomColourId(random));
colour = tracker.get(entityType.getTrackedData());
}

return colour;
return RainglowColour.get(colour);
}
}
Loading

0 comments on commit 64a98c9

Please sign in to comment.