Skip to content

Commit

Permalink
Add functions
Browse files Browse the repository at this point in the history
  • Loading branch information
zbx1425 committed Jan 4, 2025
1 parent d8461f9 commit b6e46a8
Show file tree
Hide file tree
Showing 12 changed files with 230 additions and 96 deletions.
92 changes: 84 additions & 8 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -56,19 +56,95 @@ tasks.withType(JavaCompile).configureEach {
it.options.release = 21
}

// Configure Maven publishing.



publishing {
publications {
mavenJava(MavenPublication) {
// Modified by TeaCon
register('release', MavenPublication) {
// noinspection GroovyAssignabilityCheck
from components.java
version = rootProject.mod_version
groupId = rootProject.maven_group
artifactId = "$mod_github_repo-$rootProject.minecraft_version"
pom {
name = mod_github_repo
url = "https://github.com/$mod_github_owner/$mod_github_repo"
licenses {
license {
name = mod_license
url = "https://github.com/$mod_github_owner/$mod_github_repo/blob/HEAD/LICENSE"
}
}
organization {
name = 'TeaConMC'
url = 'https://github.com/teaconmc'
}
developers {
for (mod_author in "$mod_authors".split(',')) {
developer { id = mod_author.trim(); name = mod_author.trim() }
}
}
issueManagement {
system = 'GitHub Issues'
url = "https://github.com/$mod_github_owner/$mod_github_repo/issues"
}
scm {
url = "https://github.com/$mod_github_owner/$mod_github_repo"
connection = "scm:git:git://github.com/$mod_github_owner/${mod_github_repo}.git"
developerConnection = "scm:git:[email protected]:$mod_github_owner/${mod_github_repo}.git"
}
}
}
}

// See https://docs.gradle.org/current/userguide/publishing_maven.html for information on how to set up publishing.
repositories {
// Add repositories to publish to here.
// Notice: This block does NOT have the same function as the block in the top level.
// The repositories here will be used for publishing your artifact, not for
// retrieving dependencies.
// Modified by TeaCon
maven {
name "teacon"
url "s3://maven/"
credentials(AwsCredentials) {
accessKey = System.env.ARCHIVE_ACCESS_KEY
secretKey = System.env.ARCHIVE_SECRET_KEY
}
}
}
}

// Added by TeaCon
tasks.withType(PublishToMavenRepository).configureEach {
if (repository && repository.name == "archive") {
it.onlyIf {
System.env.MAVEN_USERNAME && System.env.MAVEN_PASSWORD
}
}
}

abstract class TeaConDumpPathToGitHub extends DefaultTask {
@Input
abstract Property<String> getPublishName()
@InputFile
abstract RegularFileProperty getTargetFile()
@TaskAction
void dump() {
if (System.env.GITHUB_ACTIONS) {
File theFile = targetFile.getAsFile().get()

def outputFile = new File(System.env.GITHUB_OUTPUT)
// Use the env-specific line separator for maximally possible compatibility
def newLine = System.getProperty('line.separator')

// Write out new env variable for later usage
outputFile << newLine << "artifact_name=${theFile.getName()}"
outputFile << newLine << "artifact_publish_name=${publishName.get()}"
outputFile << newLine << "artifact_path=${theFile.absolutePath}"
}
}
}

// Added by TeaCon
tasks.register("githubActionOutput", TeaConDumpPathToGitHub) { task ->
task.onlyIf { System.env.GITHUB_ACTIONS }
task.getTargetFile().set(jar.archiveFile)
task.getPublishName().set("${jar.archiveBaseName.get()}-${version}.jar")
}
8 changes: 7 additions & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ org.gradle.jvmargs=-Xmx1G
loom.platform = neoforge

# Mod properties
mod_version = 1.0.0
mod_version = 0.1.0
maven_group = org.teacon
archives_name = gimmeman

Expand All @@ -13,3 +13,9 @@ minecraft_version = 1.21.1
# Dependencies
neoforge_version = 21.1.84
yarn_mappings_patch_version = 1.21+build.4

# Publishing
mod_license = MIT
mod_authors = Zbx1425
mod_github_owner = TeaConMC
mod_github_repo = GiveMeMan
33 changes: 0 additions & 33 deletions src/main/java/org/teacon/GiveMeMan.java

This file was deleted.

16 changes: 16 additions & 0 deletions src/main/java/org/teacon/gimmeman/GimmeMan.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package org.teacon.gimmeman;

import net.neoforged.fml.common.Mod;

import java.util.List;

@Mod(GimmeMan.MOD_ID)
public final class GimmeMan {
public static final String MOD_ID = "gimmeman";

public GimmeMan() {

}

public static final List<String> modsToRemoveAdvancements = List.of("l2backpack");
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package org.teacon.gimmeman.mixin;

import com.google.gson.JsonElement;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.server.ServerAdvancementManager;
import net.minecraft.server.packs.resources.ResourceManager;
import net.minecraft.util.profiling.ProfilerFiller;
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 org.teacon.gimmeman.GimmeMan;

import java.util.Map;

@Mixin(ServerAdvancementManager.class)
public class AdvancementManagerMixin {

@Inject(
method = "apply(Ljava/util/Map;Lnet/minecraft/server/packs/resources/ResourceManager;Lnet/minecraft/util/profiling/ProfilerFiller;)V",
at = @At("HEAD")
)
void preventAdvancementAddition(Map<ResourceLocation, JsonElement> map, ResourceManager resourceManager, ProfilerFiller profilerFiller, CallbackInfo ci) {
map.entrySet().removeIf((entry) -> GimmeMan.modsToRemoveAdvancements.contains(entry.getKey().getNamespace()));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package org.teacon.gimmeman.mixin;

import net.minecraft.advancements.AdvancementRewards;
import net.minecraft.commands.CacheableFunction;
import net.minecraft.resources.ResourceKey;
import net.minecraft.server.MinecraftServer;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.world.level.storage.loot.LootTable;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import org.teacon.gimmeman.GimmeMan;

import java.util.List;
import java.util.Optional;

@Mixin(AdvancementRewards.class)
public class AdvancementRewardsMixin {

@Shadow @Final private Optional<CacheableFunction> function;

@Shadow @Final private List<ResourceKey<LootTable>> loot;

@Inject(method = "grant", at = @At("HEAD"), cancellable = true)
private void cancelGrant(ServerPlayer arg, CallbackInfo ci) {
if (loot.stream().anyMatch(lootTableResourceKey -> lootTableResourceKey.location().getNamespace().equals(GimmeMan.MOD_ID)))
return;

MinecraftServer minecraftserver = arg.server;
this.function
.flatMap(argx -> argx.get(minecraftserver.getFunctions()))
.ifPresent(arg2 -> minecraftserver.getFunctions().execute(arg2, arg.createCommandSourceStack().withSuppressedOutput().withPermission(2)));

ci.cancel();
}
}
16 changes: 16 additions & 0 deletions src/main/java/org/teacon/gimmeman/mixin/DisplayInfoMixin.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package org.teacon.gimmeman.mixin;

import net.minecraft.advancements.DisplayInfo;
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.CallbackInfoReturnable;

@Mixin(DisplayInfo.class)
public class DisplayInfoMixin {

@Inject(method = "shouldAnnounceChat", at = @At("HEAD"), cancellable = true)
void shouldAnnounceChat(CallbackInfoReturnable<Boolean> cir) {
cir.setReturnValue(false);
}
}
23 changes: 0 additions & 23 deletions src/main/java/org/teacon/mixin/MixinClientAdvancements.java

This file was deleted.

28 changes: 0 additions & 28 deletions src/main/java/org/teacon/mixin/MixinPlayerAdvancements.java

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"criteria": {
"tick": {
"trigger": "minecraft:tick"
}
},
"rewards": {
"loot": [
"gimmeman:give_startup_items"
]
},
"display": {
"show_toast": false,
"announce_to_chat": false
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"type": "advancement_reward",
"pools": [
{
"rolls": 1,
"entries": [
{
"type": "item",
"name": "ae2:guide"
},
{
"type": "item",
"name": "scattered_shards:shard_tablet"
},
{
"type": "item",
"name": "worldcomment:comment_tool"
}
]
}
]
}
7 changes: 4 additions & 3 deletions src/main/resources/gimmeman.mixins.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
{
"required": true,
"package": "org.teacon.mixin",
"package": "org.teacon.gimmeman.mixin",
"compatibilityLevel": "JAVA_21",
"minVersion": "0.8",
"client": [
"MixinClientAdvancements"
],
"mixins": [
"MixinPlayerAdvancements"
"AdvancementManagerMixin",
"AdvancementRewardsMixin",
"DisplayInfoMixin"
],
"injectors": {
"defaultRequire": 1
Expand Down

0 comments on commit b6e46a8

Please sign in to comment.