Skip to content

Commit

Permalink
Merge pull request #70 from tropicthedev/1.21
Browse files Browse the repository at this point in the history
Project Restructure and Preliminary Minecraft 1.21 Support
  • Loading branch information
KrisCris authored Oct 11, 2024
2 parents a26ef78 + 5cb71eb commit 987fac3
Show file tree
Hide file tree
Showing 32 changed files with 349 additions and 289 deletions.
9 changes: 9 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#
# https://help.github.com/articles/dealing-with-line-endings/
#
# Linux start script should use lf
/gradlew text eol=lf

# These are Windows script files and should use crlf
*.bat text eol=crlf

42 changes: 23 additions & 19 deletions .github/workflows/gradle.yml
Original file line number Diff line number Diff line change
@@ -1,33 +1,37 @@
# This workflow will build a Java project with Gradle
# For more information see: https://help.github.com/actions/language-and-framework-guides/building-and-testing-java-with-gradle

name: Java CI with Gradle

on:
push:
branches:
- latest
pull_request:
branches:
- latest
name: build
on: [push, pull_request]

jobs:
build:
strategy:
matrix:
java: [ 21, ]

runs-on: ubuntu-latest

runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v2
- name: Set up JDK 1.17
uses: actions/setup-java@v1
- name: Checkout repository
uses: actions/checkout@v4

- name: Validate gradle wrapper
uses: gradle/wrapper-validation-action@v2

- name: Setup jdk ${{ matrix.java }}
uses: actions/setup-java@v4
with:
java-version: 1.17
java-version: ${{ matrix.java }}
distribution: 'temurin'

- name: Grant execute permission for gradlew
run: chmod +x gradlew
run: chmod +x ./gradlew

- name: Build with Gradle
run: ./gradlew build
- uses: actions/upload-artifact@v2

- name: Upload artifacts
uses: actions/upload-artifact@v4
with:
name: AllStackable
name: AllStackable_Java${{ matrix.java }}
path: build/libs/AllStackable-*.*-*.*[^sourcedv].jar

7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,10 @@ bin/
# fabric

run/

# java

hs_err_*.log
replay_*.log
*.hprof
*.jfr
39 changes: 25 additions & 14 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
plugins {
id 'fabric-loom' version '1.6-SNAPSHOT'
id 'fabric-loom' version '1.7-SNAPSHOT'
id 'maven-publish'
}

sourceCompatibility = JavaVersion.VERSION_21
targetCompatibility = JavaVersion.VERSION_21

archivesBaseName = project.archives_base_name
version = "v${project.mod_version}-${project.minecraft_version}"
group = project.maven_group

base {
archivesName = project.archives_base_name
}

repositories {
// Add repositories to retrieve artifacts from in here.
// You should only use this when depending on other mods because
Expand All @@ -18,6 +18,18 @@ repositories {
// for more information about repositories.
}

loom {
splitEnvironmentSourceSets()

mods {
"allstackable" {
sourceSet sourceSets.main
sourceSet sourceSets.client
}
}

}

dependencies {
// To change the versions see the gradle.properties file
minecraft "com.mojang:minecraft:${project.minecraft_version}"
Expand All @@ -26,11 +38,7 @@ dependencies {

// Fabric API. This is technically optional, but you probably want it anyway.
modImplementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}"

// Uncomment the following line to enable the deprecated Fabric API modules.
// These are included in the Fabric API production distribution and allow you to update your mod to the latest modules at a later more convenient time.

// modImplementation "net.fabricmc.fabric-api:fabric-api-deprecated:${project.fabric_version}"

}

processResources {
Expand All @@ -42,27 +50,30 @@ processResources {
}

tasks.withType(JavaCompile).configureEach {
// Minecraft 1.18 (1.18-pre2) upwards uses Java 17.
it.options.release = 17
it.options.release = 21
}

java {
// Loom will automatically attach sourcesJar to a RemapSourcesJar task and to the "build" task
// if it is present.
// If you remove this line, sources will not be generated.
withSourcesJar()

sourceCompatibility = JavaVersion.VERSION_21
targetCompatibility = JavaVersion.VERSION_21
}

jar {
from("LICENSE") {
rename { "${it}_${project.archivesBaseName}"}
rename { "${it}_${project.base.archivesName.get()}"}
}
}

// configure the maven publication
publishing {
publications {
mavenJava(MavenPublication) {
create("mavenJava", MavenPublication) {
artifactId = project.archives_base_name
from components.java
}
}
Expand Down
20 changes: 11 additions & 9 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
# Done to increase the memory available to gradle.
org.gradle.jvmargs=-Xmx1G
org.gradle.jvmargs=-Xmx1G
org.gradle.parallel=true

#Fabric
minecraft_version=1.20.6
yarn_mappings=1.20.6+build.1
loader_version=0.15.11
fabric_version=0.98.0+1.20.6
# Fabric
loader_version=0.16.5
yarn_mappings=1.21+build.9
minecraft_version=1.21
fabric_version=0.102.0+1.21

# Mod Properties
mod_version = 2.1.0
maven_group = online.connlost.allstackable
archives_base_name = AllStackable
mod_version = 2.1.0
maven_group=online.connlost.allstackable
archives_base_name=AllStackable


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.7-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.8-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
Expand Down
2 changes: 1 addition & 1 deletion gradlew
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
# Darwin, MinGW, and NonStop.
#
# (3) This script is generated from the Groovy template
# https://github.com/gradle/gradle/blob/HEAD/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
# https://github.com/gradle/gradle/blob/HEAD/platforms/jvm/plugins-application/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
# within the Gradle project.
#
# You can find Gradle at https://github.com/gradle/gradle/.
Expand Down
2 changes: 1 addition & 1 deletion gradlew.bat
Original file line number Diff line number Diff line change
Expand Up @@ -89,4 +89,4 @@ exit /b %EXIT_CODE%
:mainEnd
if "%OS%"=="Windows_NT" endlocal

:omega
:omega
16 changes: 8 additions & 8 deletions settings.gradle
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
pluginManagement {
repositories {
maven {
name = 'Fabric'
url = 'https://maven.fabricmc.net/'
}
mavenCentral()
gradlePluginPortal()
}
repositories {
maven {
name = 'Fabric'
url = 'https://maven.fabricmc.net/'
}
mavenCentral()
gradlePluginPortal()
}
}
Original file line number Diff line number Diff line change
@@ -1,37 +1,35 @@
package online.connlost.allstackable.client;
package online.connlost.allstackable;

import net.fabricmc.api.ClientModInitializer;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.fabricmc.fabric.api.client.networking.v1.ClientPlayConnectionEvents;
import net.fabricmc.fabric.api.client.networking.v1.ClientPlayNetworking;
import net.fabricmc.fabric.api.networking.v1.PacketSender;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.network.ClientPlayNetworkHandler;
import net.minecraft.network.PacketByteBuf;

import java.util.ArrayList;
import java.util.LinkedHashMap;

import online.connlost.allstackable.AllStackableInit;
import online.connlost.allstackable.util.ByteArrayPayload;
import org.apache.commons.lang3.SerializationUtils;


public class AllStackableClientInit implements ClientModInitializer {

public class AllStackableClient implements ClientModInitializer {
@Override
@Environment(EnvType.CLIENT)
public void onInitializeClient() {
ClientPlayConnectionEvents.INIT.register((handler, client) ->{
ClientPlayConnectionEvents.INIT.register((handler, client) -> {
ClientPlayNetworking.registerReceiver(
AllStackableInit.SHARE_CONFIG_PACKET_ID,
(client1, handler1, buf, sender1) -> configHandler(handler1, sender1, client1, buf)
ByteArrayPayload.ID,
(packet, context) -> {
configHandler(packet.data());
}
);
});
}

private void configHandler(ClientPlayNetworkHandler handler, PacketSender sender, MinecraftClient client, PacketByteBuf buf){
ArrayList<LinkedHashMap<String, Integer>> configList = SerializationUtils.deserialize(buf.readByteArray());
// Updated configHandler method to match the new PlayPayloadHandler API
private void configHandler(byte[] configPayload) {
ArrayList<LinkedHashMap<String, Integer>> configList = SerializationUtils.deserialize(configPayload);
ConfigSync.syncConfig(configList);
}
}
Original file line number Diff line number Diff line change
@@ -1,36 +1,34 @@
package online.connlost.allstackable.client;
package online.connlost.allstackable;

import online.connlost.allstackable.server.config.ConfigManager;
import online.connlost.allstackable.util.ItemsHelper;
import online.connlost.allstackable.AllStackableInit;

import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.Map;

public class ConfigSync {
private static ItemsHelper itemsHelper = ItemsHelper.getItemsHelper();
private static final ItemsHelper itemsHelper = ItemsHelper.getItemsHelper();

/**
* Items' stacksize is directly modified, no config is held for that in the "client" side.
* In contrast, we do store rules in client side as some mixins in client side classes need it.
* @param configList
* @param configList the config list
*/
public static void syncConfig(ArrayList<LinkedHashMap<String, Integer>> configList){
AllStackableInit.LOGGER.info("[All Stackable] [Client] Sync config from server side!");
AllStackable.LOGGER.info("[All Stackable] [Client] Sync config from server side!");
itemsHelper.setCountByConfig(configList.get(0).entrySet(), false);
ConfigManager.getConfigManager().setRulesMap(configList.get(1));
AllStackableInit.LOGGER.info("[All Stackable] [Client] Sync rules:");
AllStackable.LOGGER.info("[All Stackable] [Client] Sync rules:");
for (Map.Entry<String, Integer> rule: configList.get(1).entrySet()){
String tag;
switch (rule.getValue()){
case 0: tag = "false";break;
case 1: tag = "true";break;
default: tag = rule.getValue().toString();
}
AllStackableInit.LOGGER.info("\t["+rule.getKey()+"] = "+tag);
String tag = switch (rule.getValue()) {
case 0 -> "false";
case 1 -> "true";
default -> rule.getValue().toString();
};
AllStackable.LOGGER.info("\t[{}] = {}", rule.getKey(), tag);
}
AllStackableInit.LOGGER.info("[All Stackable] [Client] Sync finished.");
AllStackable.LOGGER.info("[All Stackable] [Client] Sync finished.");
}

public static void resetConfig(){
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
package online.connlost.allstackable.mixin;

import online.connlost.allstackable.client.ConfigSync;
import online.connlost.allstackable.ConfigSync;
import net.minecraft.client.MinecraftClient;
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;

@Mixin(MinecraftClient.class)
public abstract class MixinMinecraftClientGame {
@Inject(method = "disconnect", at=@At("RETURN"))
public abstract class MixinMinecraftClient {
@Inject(method = "disconnect()V", at=@At("RETURN"))
private void resetMaxCount(CallbackInfo ci){
ConfigSync.resetConfig();
}
Expand Down
11 changes: 11 additions & 0 deletions src/client/resources/allstackable.client.mixins.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"required": true,
"package": "online.connlost.allstackable.mixin",
"compatibilityLevel": "JAVA_21",
"client": [
"MixinMinecraftClient"
],
"injectors": {
"defaultRequire": 1
}
}
Original file line number Diff line number Diff line change
@@ -1,28 +1,23 @@
package online.connlost.allstackable;

import net.fabricmc.fabric.api.networking.v1.PayloadTypeRegistry;
import online.connlost.allstackable.server.Server;
import online.connlost.allstackable.server.command.StackSizeCommand;
import online.connlost.allstackable.util.ByteArrayPayload;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import net.fabricmc.api.ModInitializer;
import net.minecraft.util.Identifier;
import net.fabricmc.fabric.api.event.lifecycle.v1.ServerLifecycleEvents;

public class AllStackableInit implements ModInitializer {
public static final Identifier SHARE_CONFIG_PACKET_ID = new Identifier("allstackable", "config");
public class AllStackable implements ModInitializer {
public static final Logger LOGGER = LogManager.getLogger();


@Override
public void onInitialize() {
PayloadTypeRegistry.playS2C().register(ByteArrayPayload.ID, ByteArrayPayload.CODEC);
LOGGER.info("[All Stackable] Start loading!");
StackSizeCommand.register();
LOGGER.info("[All Stackable] Command registered.");
ServerLifecycleEvents.SERVER_STARTED.register(server -> {
Server.onServerLoaded(server);
});

ServerLifecycleEvents.SERVER_STARTED.register(Server::onServerLoaded);
}


}
Loading

0 comments on commit 987fac3

Please sign in to comment.