Skip to content

Commit

Permalink
Merge pull request #199 from NertzhulDEV/1.21
Browse files Browse the repository at this point in the history
Port to 1.21
  • Loading branch information
lucaargolo authored Aug 21, 2024
2 parents ed49f84 + f006869 commit 1e780ea
Show file tree
Hide file tree
Showing 26 changed files with 355 additions and 222 deletions.
44 changes: 30 additions & 14 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -1,22 +1,38 @@
name: Build

on: [push]
on: [ push, workflow_dispatch ]

jobs:
build:
strategy:
matrix:
java: [ 21 ]
os: [ ubuntu-latest ]
runs-on: ${{ matrix.os }}

runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v3
with:
fetch-depth: 0

container:
image: openjdk:17-jdk
options: --user root
- name: Validate Gradle wrapper
uses: gradle/wrapper-validation-action@v1

steps:
- uses: actions/[email protected]
- run: |
chmod +x ./gradlew
./gradlew build
- uses: actions/upload-artifact@v2
with:
name: build-artifacts
path: build/libs/
- name: Setup JDK ${{ matrix.java }}
uses: actions/setup-java@v3
with:
distribution: zulu
java-version: ${{ matrix.java }}

- name: Make Gradle wrapper executable
run: chmod +x ./gradlew

- name: Build
run: ./gradlew build --stacktrace --parallel

- name: Capture build artifacts
uses: actions/upload-artifact@v3
with:
name: Artifacts
path: build/libs/
47 changes: 31 additions & 16 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -1,24 +1,39 @@
name: Release

on: [workflow_dispatch]
on: [ workflow_dispatch ]

jobs:
release:
strategy:
matrix:
java: [ 21 ]
os: [ ubuntu-latest ]

runs-on: ubuntu-latest

container:
image: openjdk:17-jdk
options: --user root
runs-on: ${{ matrix.os }}

steps:
- uses: actions/[email protected]
- run: |
chmod +x ./gradlew
./gradlew build publish github curseforge modrinth --stacktrace
env:
CURSEFORGE_API_KEY: ${{ secrets.CURSEFORGE_API_KEY }}
GITHUB_TOKEN: ${{ secrets.GH_API_KEY }}
MODRINTH_TOKEN: ${{ secrets.MODRINTH_TOKEN }}
MAVEN_USERNAME: ${{ secrets.MAVEN_USERNAME }}
MAVEN_PASSWORD: ${{ secrets.MAVEN_PASSWORD }}
- name: Checkout repository
uses: actions/checkout@v3
with:
fetch-depth: 0

- name: Validate Gradle wrapper
uses: gradle/wrapper-validation-action@v1

- name: Setup JDK ${{ matrix.java }}
uses: actions/setup-java@v3
with:
distribution: zulu
java-version: ${{ matrix.java }}

- name: Make Gradle wrapper executable
run: chmod +x ./gradlew

- name: Build
run: ./gradlew build publish github curseforge modrinth --stacktrace
env:
CURSEFORGE_API_KEY: ${{ secrets.CURSEFORGE_API_KEY }}
GITHUB_TOKEN: ${{ secrets.GH_API_KEY }}
MODRINTH_TOKEN: ${{ secrets.MODRINTH_TOKEN }}
MAVEN_USERNAME: ${{ secrets.MAVEN_USERNAME }}
MAVEN_PASSWORD: ${{ secrets.MAVEN_PASSWORD }}
7 changes: 7 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -211,5 +211,12 @@ publishing {
}


}
}

idea {
module {
isDownloadSources = true
isDownloadJavadoc = true
}
}
14 changes: 7 additions & 7 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
org.gradle.jvmargs=-Xmx4G

# Gradle Plugins
loom_version=1.1-SNAPSHOT
loom_version=1.7-SNAPSHOT
grgit_version=5.0.0
cursegradle_version=1.4.0
modrinth_version=2.7.3
Expand All @@ -13,16 +13,16 @@ mod_version=2.3+1.20
maven_group=io.github.lucaargolo

# Fabric Properties
minecraft_version=1.20.1
yarn_mappings=1.20.1+build.10
loader_version=0.14.22
minecraft_version=1.21
yarn_mappings=1.21+build.9
loader_version=0.15.11

#Fabric api
fabric_version=0.86.1+1.20.1
fabric_version=0.100.7+1.21

#Libraries
modmenu_version=7.2.1
rei_version=12.0.645
modmenu_version=11.0.1
rei_version=16.0.729

#Publishing
curseforge_id=413523
Expand Down
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-7.3-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.8-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
80 changes: 41 additions & 39 deletions src/main/java/io/github/lucaargolo/seasons/FabricSeasons.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,23 @@
import com.google.gson.JsonParser;
import io.github.lucaargolo.seasons.commands.SeasonCommand;
import io.github.lucaargolo.seasons.mixed.BiomeMixed;
import io.github.lucaargolo.seasons.payload.ConfigSyncPacket;
import io.github.lucaargolo.seasons.payload.UpdateCropsPaycket;
import io.github.lucaargolo.seasons.resources.CropConfigs;
import io.github.lucaargolo.seasons.utils.*;
import io.github.lucaargolo.seasons.utils.GreenhouseCache;
import io.github.lucaargolo.seasons.utils.ModConfig;
import io.github.lucaargolo.seasons.utils.PlacedMeltablesState;
import io.github.lucaargolo.seasons.utils.ReplacedMeltablesState;
import io.github.lucaargolo.seasons.utils.Season;
import io.github.lucaargolo.seasons.utils.SeasonalFertilizable;
import it.unimi.dsi.fastutil.longs.LongArraySet;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.fabricmc.api.ModInitializer;
import net.fabricmc.fabric.api.command.v2.CommandRegistrationCallback;
import net.fabricmc.fabric.api.event.lifecycle.v1.ServerLifecycleEvents;
import net.fabricmc.fabric.api.event.lifecycle.v1.ServerTickEvents;
import net.fabricmc.fabric.api.networking.v1.PacketByteBufs;
import net.fabricmc.fabric.api.networking.v1.PayloadTypeRegistry;
import net.fabricmc.fabric.api.networking.v1.ServerPlayNetworking;
import net.fabricmc.fabric.api.resource.ResourceManagerHelper;
import net.fabricmc.loader.api.FabricLoader;
Expand All @@ -23,7 +30,6 @@
import net.minecraft.client.network.ClientPlayerEntity;
import net.minecraft.item.BlockItem;
import net.minecraft.item.Item;
import net.minecraft.network.PacketByteBuf;
import net.minecraft.registry.Registries;
import net.minecraft.registry.RegistryKey;
import net.minecraft.registry.RegistryKeys;
Expand Down Expand Up @@ -62,78 +68,74 @@ public class FabricSeasons implements ModInitializer {

public static HashMap<Item, Block> SEEDS_MAP = new HashMap<>();

public static Identifier ASK_FOR_CONFIG = new ModIdentifier("ask_for_config");
public static Identifier ANSWER_CONFIG = new ModIdentifier("anwer_config");

public static Identifier UPDATE_CROPS = new ModIdentifier("update_crops");


@Override
public void onInitialize() {

Path configPath = FabricLoader.getInstance().getConfigDir();
File configFile = new File(configPath + File.separator + "seasons.json");

LOGGER.info("["+MOD_NAME+"] Trying to read config file...");
LOGGER.info("[" + MOD_NAME + "] Trying to read config file...");
try {
if (configFile.createNewFile()) {
LOGGER.info("["+MOD_NAME+"] No config file found, creating a new one...");
LOGGER.info("[" + MOD_NAME + "] No config file found, creating a new one...");
String json = GSON.toJson(JsonParser.parseString(GSON.toJson(new ModConfig())));
try (PrintWriter out = new PrintWriter(configFile)) {
out.println(json);
}
CONFIG = new ModConfig();
LOGGER.info("["+MOD_NAME+"] Successfully created default config file.");
LOGGER.info("[" + MOD_NAME + "] Successfully created default config file.");
} else {
LOGGER.info("["+MOD_NAME+"] A config file was found, loading it..");
LOGGER.info("[" + MOD_NAME + "] A config file was found, loading it..");
CONFIG = GSON.fromJson(new String(Files.readAllBytes(configFile.toPath())), ModConfig.class);
if(CONFIG == null) {
throw new NullPointerException("["+MOD_NAME+"] The config file was empty.");
}else{
LOGGER.info("["+MOD_NAME+"] Successfully loaded config file.");
if (CONFIG == null) {
throw new NullPointerException("[" + MOD_NAME + "] The config file was empty.");
} else {
LOGGER.info("[" + MOD_NAME + "] Successfully loaded config file.");
}
}
}catch (Exception exception) {
LOGGER.error("["+MOD_NAME+"] There was an error creating/loading the config file!", exception);
} catch (Exception exception) {
LOGGER.error("[" + MOD_NAME + "] There was an error creating/loading the config file!", exception);
CONFIG = new ModConfig();
LOGGER.warn("["+MOD_NAME+"] Defaulting to original config.");
LOGGER.warn("[" + MOD_NAME + "] Defaulting to original config.");
}

CommandRegistrationCallback.EVENT.register((dispatcher, dedicated, ignored) -> SeasonCommand.register(dispatcher));

ServerLifecycleEvents.SERVER_STARTED.register(server -> {
SEEDS_MAP.clear();
Registries.ITEM.forEach(item -> {
if(item instanceof BlockItem) {
if (item instanceof BlockItem) {
Block block = ((BlockItem) item).getBlock();
if(block instanceof SeasonalFertilizable) {
if (block instanceof SeasonalFertilizable) {
FabricSeasons.SEEDS_MAP.put(item, ((BlockItem) item).getBlock());
}
}
});
});


PayloadTypeRegistry.playS2C().register(UpdateCropsPaycket.ID, UpdateCropsPaycket.CODEC);
ServerLifecycleEvents.SYNC_DATA_PACK_CONTENTS.register((player, joined) -> {
PacketByteBuf buf = PacketByteBufs.create();
CropConfigs.getDefaultCropConfig().toBuf(buf);
CropConfigs.toBuf(buf);
ServerPlayNetworking.send(player, UPDATE_CROPS, buf);
ServerPlayNetworking.send(player, UpdateCropsPaycket.fromConfig(CropConfigs.getDefaultCropConfig(), CropConfigs.getCropConfigMap()));
});

ServerTickEvents.END_SERVER_TICK.register(server -> {
GreenhouseCache.tick(server);
temporaryMeltableCache.clear();
});

ServerPlayNetworking.registerGlobalReceiver(ASK_FOR_CONFIG, (server, player, handler, buf, responseSender) -> {
PayloadTypeRegistry.playS2C().register(ConfigSyncPacket.ID, ConfigSyncPacket.CODEC);
PayloadTypeRegistry.playC2S().register(ConfigSyncPacket.ID, ConfigSyncPacket.CODEC);

ServerPlayNetworking.registerGlobalReceiver(ConfigSyncPacket.ID, (payload, context) -> {
String configJson = GSON.toJson(JsonParser.parseString(GSON.toJson(CONFIG)));
PacketByteBuf configBuf = PacketByteBufs.create();
configBuf.writeString(configJson);
ServerPlayNetworking.send(player, ANSWER_CONFIG, configBuf);
ServerPlayNetworking.send(context.player(), new ConfigSyncPacket(configJson));
});

ResourceManagerHelper.get(ResourceType.SERVER_DATA).registerReloadListener(new CropConfigs());
}

public static Identifier identifier(String path) {
return Identifier.of(MOD_ID, path);
}

public static void setMeltable(BlockPos blockPos) {
temporaryMeltableCache.add(blockPos.asLong());
Expand All @@ -144,11 +146,11 @@ public static boolean isMeltable(BlockPos blockPos) {
}

public static PlacedMeltablesState getPlacedMeltablesState(ServerWorld world) {
return world.getPersistentStateManager().getOrCreate(PlacedMeltablesState::createFromNbt, PlacedMeltablesState::new, "seasons_placed_meltables");
return world.getPersistentStateManager().getOrCreate(PlacedMeltablesState.getPersistentStateType(), "seasons_placed_meltables");
}

public static ReplacedMeltablesState getReplacedMeltablesState(ServerWorld world) {
return world.getPersistentStateManager().getOrCreate(ReplacedMeltablesState::createFromNbt, ReplacedMeltablesState::new, "seasons_replaced_meltables");
return world.getPersistentStateManager().getOrCreate(ReplacedMeltablesState.getPersistentStateType(), "seasons_replaced_meltables");
}

public static long getTimeToNextSeason(World world) {
Expand Down Expand Up @@ -337,8 +339,8 @@ else if (m == 12 && d > 20)
return season;
}

private static final TagKey<Biome> IGNORED_CATEGORIES_TAG = TagKey.of(RegistryKeys.BIOME, new Identifier(FabricSeasons.MOD_ID, "ignored"));
private static final TagKey<Biome> JUNGLE_LIKE_TAG = TagKey.of(RegistryKeys.BIOME, new Identifier(FabricSeasons.MOD_ID, "jungle_like"));
private static final TagKey<Biome> IGNORED_CATEGORIES_TAG = TagKey.of(RegistryKeys.BIOME, FabricSeasons.identifier("ignored"));
private static final TagKey<Biome> JUNGLE_LIKE_TAG = TagKey.of(RegistryKeys.BIOME, FabricSeasons.identifier("jungle_like"));

public static void injectBiomeTemperature(RegistryEntry<Biome> entry, World world) {
if(entry.isIn(IGNORED_CATEGORIES_TAG))
Expand Down
Loading

0 comments on commit 1e780ea

Please sign in to comment.