Skip to content

Commit

Permalink
Setup maven publishing, update NeoForge
Browse files Browse the repository at this point in the history
  • Loading branch information
Su5eD committed Jul 5, 2024
1 parent ed29d49 commit 0a0c14f
Show file tree
Hide file tree
Showing 11 changed files with 30 additions and 184 deletions.
53 changes: 5 additions & 48 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import net.fabricmc.loom.build.nesting.IncludedJarFactory
import net.fabricmc.loom.build.nesting.JarNester
import net.fabricmc.loom.util.Constants
import net.fabricmc.loom.util.GroovyXmlUtil
import org.apache.commons.codec.digest.DigestUtils
import org.eclipse.jgit.api.Git
import java.util.*
Expand Down Expand Up @@ -46,7 +45,6 @@ val upstreamVersion = version

ext["upstreamVersion"] = upstreamVersion

group = "org.sinytra"
version = "$upstreamVersion+$implementationVersion+$versionMc"
println("Version: $version")

Expand All @@ -60,6 +58,8 @@ allprojects {
apply(plugin = "java-library")
apply(plugin = "dev.architectury.loom")

group = "org.sinytra.forgified-fabric-api"

java {
toolchain.languageVersion.set(JavaLanguageVersion.of(21))
withSourcesJar()
Expand Down Expand Up @@ -125,7 +125,7 @@ allprojects {

dependencies {
// Include Forgified Fabric Loader
include("org.sinytra:fabric-loader:$versionForgifiedFabricLoader:full")
include("org.sinytra:forgified-fabric-loader:$versionForgifiedFabricLoader:full")
}

tasks {
Expand Down Expand Up @@ -153,10 +153,6 @@ allprojects {
apply(plugin = "ffapi.neo-entrypoint")
apply(plugin = "ffapi.package-info")

if (!META_PROJECTS.contains(name) && project != rootProject) {
// apply(plugin = "ffapi.neo-compat") TODO
}

allprojects.forEach { p ->
if (!META_PROJECTS.contains(p.name)) {
loom.mods.register(p.name) {
Expand All @@ -178,9 +174,7 @@ allprojects {
publishing {
publications {
register<MavenPublication>("mavenJava") {
pom {
// addPomMetadataInformation(project, pom) TODO
}
from(components["java"])
}
}
}
Expand All @@ -193,31 +187,12 @@ dependencies {
return@forEach
}

api(project(proj.path, "namedElements"))
include(api(project(proj.path, "namedElements"))!!)
"testmodImplementation"(proj.sourceSets.getByName("testmod").output)
}
}
}

publishing {
publications {
named<MavenPublication>("mavenJava") {
from(components["java"])

pom.withXml {
val depsNode = GroovyXmlUtil.getOrCreateNode(asNode(), "dependencies")
rootProject.configurations.include.get().dependencies.forEach {
val depNode = depsNode.appendNode("dependency")
depNode.appendNode("groupId", it.group)
depNode.appendNode("artifactId", it.name)
depNode.appendNode("version", it.version)
depNode.appendNode("scope", "compile")
}
}
}
}
}

val git: Git? = runCatching { Git.open(rootDir) }.getOrNull()

fun getSubprojectVersion(project: Project): String {
Expand Down Expand Up @@ -245,24 +220,6 @@ fun moduleDependencies(project: Project, depNames: List<String>) {
api(it)
}
}

// As we manually handle the maven artifacts, we need to also manually specify the deps.
project.publishing {
publications {
named<MavenPublication>("mavenJava") {
pom.withXml {
val depsNode = asNode().appendNode("dependencies")
deps.forEach {
val depNode = depsNode.appendNode("dependency")
depNode.appendNode("groupId", it.group)
depNode.appendNode("artifactId", it.name)
depNode.appendNode("version", it.version)
depNode.appendNode("scope", "compile")
}
}
}
}
}
}

fun testDependencies(project: Project, depNames: List<String>) {
Expand Down
101 changes: 0 additions & 101 deletions buildSrc/src/main/kotlin/ffapi.neo-compat.gradle.kts

This file was deleted.

13 changes: 2 additions & 11 deletions buildSrc/src/main/kotlin/ffapi.neo-setup.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -34,17 +34,10 @@ val testmod: SourceSet by sourceSets.creating {
}

dependencies {
// TODO Update gradle module metadata in FFLoader to avoid this
"compileOnly"("org.sinytra:fabric-loader:$versionForgifiedFabricLoader")
"runtimeOnly"("org.sinytra:fabric-loader:$versionForgifiedFabricLoader:full") {
isTransitive = false
}
"implementation"("org.sinytra:forgified-fabric-loader:$versionForgifiedFabricLoader")

"testmodImplementation"(mainSourceSet.output)
"testmodCompileOnly"("org.sinytra:fabric-loader:$versionForgifiedFabricLoader")
"testmodRuntimeOnly"("org.sinytra:fabric-loader:$versionForgifiedFabricLoader:full") {
isTransitive = false
}
"testmodImplementation"("org.sinytra:forgified-fabric-loader:$versionForgifiedFabricLoader")

if (project.name != "fabric-gametest-api-v1") {
"testmodImplementation"(project(":fabric-gametest-api-v1", "namedElements"))
Expand All @@ -68,8 +61,6 @@ loom.apply {
configureEach {
isIdeConfigGenerated = project.rootProject == project
property("mixin.debug", "true")
// FIXME Set this from fabric-api-base as ResourcePackProfileMixin fails otherwise
property("mixin.initialiserInjectionMode", "safe")
}

create("gametest") {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
import java.util.function.Predicate;

import com.mojang.datafixers.util.Pair;
import net.fabricmc.fabric.mixin.content.registry.HoeItemAccessor;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.item.HoeItem;
import net.minecraft.world.item.context.UseOnContext;
Expand All @@ -32,7 +31,7 @@
import net.minecraft.world.level.block.state.BlockState;
import net.neoforged.bus.api.SubscribeEvent;
import net.neoforged.fml.common.EventBusSubscriber;
import net.neoforged.neoforge.common.ToolActions;
import net.neoforged.neoforge.common.ItemAbilities;
import net.neoforged.neoforge.event.level.BlockEvent;

/**
Expand Down Expand Up @@ -93,7 +92,7 @@ public static void register(Block input, Predicate<UseOnContext> usagePredicate,

@SubscribeEvent
static void modify(BlockEvent.BlockToolModificationEvent event) {
if (event.getToolAction() == ToolActions.HOE_TILL && event.getHeldItemStack().canPerformAction(ToolActions.HOE_TILL)) {
if (event.getItemAbility() == ItemAbilities.HOE_TILL && event.getHeldItemStack().canPerformAction(ItemAbilities.HOE_TILL)) {
var modified = TILLABLES.get(event.getState().getBlock());
if (modified != null && modified.getFirst().test(event.getContext())) {
if (!event.isSimulated() && !event.getLevel().isClientSide()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@
import net.minecraft.world.entity.player.Player;
import net.neoforged.bus.api.SubscribeEvent;
import net.neoforged.fml.common.EventBusSubscriber;
import net.neoforged.neoforge.event.entity.living.LivingAttackEvent;
import net.neoforged.neoforge.event.entity.living.LivingConversionEvent;
import net.neoforged.neoforge.event.entity.living.LivingIncomingDamageEvent;
import net.neoforged.neoforge.event.entity.player.CanContinueSleepingEvent;
import net.neoforged.neoforge.event.entity.player.CanPlayerSleepEvent;
import net.neoforged.neoforge.event.entity.player.PlayerEvent;
Expand All @@ -36,7 +36,7 @@
public final class EntityEventHooks {

@SubscribeEvent
public static void onLivingAttack(LivingAttackEvent event) {
public static void onLivingAttack(LivingIncomingDamageEvent event) {
LivingEntity entity = event.getEntity();
if (!entity.level().isClientSide() && !ServerLivingEntityEvents.ALLOW_DAMAGE.invoker().allowDamage(entity, event.getSource(), event.getAmount())) {
event.setCanceled(true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,13 +74,6 @@ boolean beforeEntityKilled(LivingEntity livingEntity, DamageSource source, float
return isDeadOrDying() && ServerLivingEntityEvents.ALLOW_DEATH.invoker().allowDeath(livingEntity, source, amount);
}

@Inject(method = "hurt", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/LivingEntity;isSleeping()Z"), cancellable = true)
private void beforeDamage(DamageSource source, float amount, CallbackInfoReturnable<Boolean> cir) {
if (!ServerLivingEntityEvents.ALLOW_DAMAGE.invoker().allowDamage((LivingEntity) (Object) this, source, amount)) {
cir.setReturnValue(false);
}
}

@Inject(method = "startSleeping", at = @At("RETURN"))
private void onSleep(BlockPos pos, CallbackInfo info) {
EntitySleepEvents.START_SLEEPING.invoker().onStartSleeping((LivingEntity) (Object) this, pos);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
@Mixin(targets = "net/minecraft/server/commands/GameRuleCommand$1")
public abstract class GameRuleCommandVisitorMixin {
@Final
@Shadow
@Shadow(aliases = {"val$literalargumentbuilder"})
LiteralArgumentBuilder<CommandSourceStack> val$base;

@Inject(at = @At("HEAD"), method = "visit(Lnet/minecraft/world/level/GameRules$Key;Lnet/minecraft/world/level/GameRules$Type;)V", cancellable = true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,18 @@

package net.fabricmc.fabric.impl.itemgroup;

import java.util.HashMap;
import java.util.Map;

import org.jetbrains.annotations.Nullable;
import net.fabricmc.fabric.api.event.Event;
import net.fabricmc.fabric.api.event.EventFactory;
import net.fabricmc.fabric.api.itemgroup.v1.ItemGroupEvents;
import net.minecraft.resources.ResourceKey;
import net.minecraft.world.item.CreativeModeTab;
import org.jetbrains.annotations.Nullable;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

public class ItemGroupEventsImpl {
private static final Map<ResourceKey<CreativeModeTab>, Event<ItemGroupEvents.ModifyEntries>> ITEM_GROUP_EVENT_MAP = new HashMap<>();
private static final Map<ResourceKey<CreativeModeTab>, Event<ItemGroupEvents.ModifyEntries>> ITEM_GROUP_EVENT_MAP = new ConcurrentHashMap<>();

public static Event<ItemGroupEvents.ModifyEntries> getOrCreateModifyEntriesEvent(ResourceKey<CreativeModeTab> registryKey) {
return ITEM_GROUP_EVENT_MAP.computeIfAbsent(registryKey, (g -> createModifyEvent()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
public abstract class EntityRenderersMixin {
// synthetic lambda in reloadEntityRenderers
@SuppressWarnings({"unchecked", "rawtypes"})
@Redirect(method = "lambda$createEntityRenderers$26", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/renderer/entity/EntityRendererProvider;create(Lnet/minecraft/client/renderer/entity/EntityRendererProvider$Context;)Lnet/minecraft/client/renderer/entity/EntityRenderer;"))
@Redirect(method = {"lambda$createEntityRenderers$26", "lambda$createEntityRenderers$2"}, require = 1, at = @At(value = "INVOKE", target = "Lnet/minecraft/client/renderer/entity/EntityRendererProvider;create(Lnet/minecraft/client/renderer/entity/EntityRendererProvider$Context;)Lnet/minecraft/client/renderer/entity/EntityRenderer;"))
private static EntityRenderer<?> createEntityRenderer(EntityRendererProvider<?> entityRendererFactory, EntityRendererProvider.Context context, ImmutableMap.Builder builder, EntityRendererProvider.Context context2, EntityType<?> entityType) {
EntityRenderer<?> entityRenderer = entityRendererFactory.create(context);

Expand All @@ -48,7 +48,7 @@ private static EntityRenderer<?> createEntityRenderer(EntityRendererProvider<?>

// private static synthetic method_32175(Lcom/google/common/collect/ImmutableMap$Builder;Lnet/minecraft/class_5617$class_5618;Ljava/lang/String;Lnet/minecraft/class_5617;)V
@SuppressWarnings({"unchecked", "rawtypes"})
@Redirect(method = "lambda$createPlayerRenderers$27", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/renderer/entity/EntityRendererProvider;create(Lnet/minecraft/client/renderer/entity/EntityRendererProvider$Context;)Lnet/minecraft/client/renderer/entity/EntityRenderer;"))
@Redirect(method = {"lambda$createPlayerRenderers$27", "lambda$createPlayerRenderers$3"}, require = 1, at = @At(value = "INVOKE", target = "Lnet/minecraft/client/renderer/entity/EntityRendererProvider;create(Lnet/minecraft/client/renderer/entity/EntityRendererProvider$Context;)Lnet/minecraft/client/renderer/entity/EntityRenderer;"))
private static EntityRenderer<? extends Player> createPlayerEntityRenderer(EntityRendererProvider playerEntityRendererFactory, EntityRendererProvider.Context context) {
EntityRenderer<? extends Player> entityRenderer = playerEntityRendererFactory.create(context);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,17 @@

package net.fabricmc.fabric.mixin.resource.loader;

import java.util.List;
import java.util.Set;
import java.util.function.Predicate;

import net.minecraft.server.packs.PackSelectionConfig;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.Unique;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
import net.fabricmc.fabric.impl.resource.loader.FabricResourcePackProfile;
import net.fabricmc.fabric.impl.resource.loader.ResourcePackSourceTracker;
Expand All @@ -44,11 +47,16 @@ abstract class ResourcePackProfileMixin implements FabricResourcePackProfile {
@Unique
private static final Predicate<Set<String>> DEFAULT_PARENT_PREDICATE = parents -> true;
@Unique
private Predicate<Set<String>> parentsPredicate = DEFAULT_PARENT_PREDICATE;
private Predicate<Set<String>> parentsPredicate;

@Shadow
public abstract PackLocationInfo location();

@Inject(method = "<init>(Lnet/minecraft/server/packs/PackLocationInfo;Lnet/minecraft/server/packs/repository/Pack$ResourcesSupplier;Lnet/minecraft/server/packs/repository/Pack$Metadata;Lnet/minecraft/server/packs/PackSelectionConfig;Ljava/util/List;)V", at = @At("TAIL"))
private void onInit(PackLocationInfo arg, Pack.ResourcesSupplier arg2, Pack.Metadata arg3, PackSelectionConfig arg4, List<Pack> children, CallbackInfo ci) {
this.parentsPredicate = DEFAULT_PARENT_PREDICATE;
}

@Inject(method = "open", at = @At("RETURN"))
private void onCreateResourcePack(CallbackInfoReturnable<PackResources> info) {
ResourcePackSourceTracker.setSource(info.getReturnValue(), location().source());
Expand Down
Loading

0 comments on commit 0a0c14f

Please sign in to comment.