diff --git a/README.md b/README.md index c453466..b3c412b 100644 --- a/README.md +++ b/README.md @@ -1,9 +1,13 @@ -# Example Mod +# 自然之需:可抱起后代 +——三小时摸鱼作品 -## Setup +[English readme here](./README_en.md) -For setup instructions, please see the [Fabric Documentation page](https://docs.fabricmc.net/develop/getting-started/creating-a-project#setting-up) related to the IDE that you are using. +在使用 carryon 抱起生物的时候,默认是不能抱起敌对生物的——很合理,毕竟直觉上它们会反抗。 -## License +但是,自然之需有一个选项“敌对后代不攻击玩家”,这意味着它们大概不会反抗你抱起来了。 -This template is available under the CC0 license. Feel free to learn from it and incorporate it in your own projects. +因此,我们将此限制解除:如果是玩家产下的后代(无论谁生的,因为自然之需没有记录后代的母亲是哪个玩家),则无视敌对和体型限制,使其更符合直觉。 + +## todo +此 mod 没有读取自然之需的配置 `NeedsOfNature.getConfig().pregnancyFriendlyMobsIgnorePlayers()` 也没有新建一个配置,因为作为只有一个选项的 mod,关掉还不如直接卸了方便些。 \ No newline at end of file diff --git a/README_en.md b/README_en.md new file mode 100644 index 0000000..8c0e760 --- /dev/null +++ b/README_en.md @@ -0,0 +1,12 @@ +# Needs of Nature: Picking Up Offspring + +[中文文档](./README.md) + +By default, the `carryon` mod prevents players from picking up hostile creatures—which makes sense, as one would intuitively expect them to resist. + +However, the "Needs of Nature" mod includes an option called "Spawned hostiles ignore players," implying that such offspring likely wouldn't resist being picked up. + +Therefore, we have lifted this restriction: if the offspring was produced by a player (regardless of which specific player gave birth, as "Needs of Nature" does not track the mother's identity), the hostility and size constraints are ignored, making the behavior more intuitive. + +## TODO +This mod neither reads the "Needs of Nature" configuration setting `NeedsOfNature.getConfig().pregnancyFriendlyMobsIgnorePlayers()` nor introduces a new config option; since this mod has only a single function, simply uninstalling it is more convenient than toggling a setting off. \ No newline at end of file diff --git a/build.gradle b/build.gradle index d2326d7..7612d36 100644 --- a/build.gradle +++ b/build.gradle @@ -9,13 +9,18 @@ repositories { // Loom adds the essential maven repositories to download Minecraft and libraries from automatically. // See https://docs.gradle.org/current/userguide/declaring_repositories.html // for more information about repositories. + maven { + name = "Modrinth" + url = "https://api.modrinth.com/maven" + content { includeGroup "maven.modrinth" } + } } loom { splitEnvironmentSourceSets() mods { - "modid" { + "non-carryon" { sourceSet sourceSets.main sourceSet sourceSets.client } @@ -30,6 +35,12 @@ dependencies { // Fabric API. This is technically optional, but you probably want it anyway. modImplementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_api_version}" + + + + modImplementation files("lib/needsofnature-1.5.1+1.21.11.jar") +// modImplementation files("lib/carryon-fabric-1.21.11-2.9.2.jar") + modImplementation "maven.modrinth:carry-on:2.9.2" } processResources { diff --git a/lib/needsofnature-1.5.1+1.21.11.jar b/lib/needsofnature-1.5.1+1.21.11.jar new file mode 100644 index 0000000..ff4820b Binary files /dev/null and b/lib/needsofnature-1.5.1+1.21.11.jar differ diff --git a/settings.gradle b/settings.gradle index 11df772..a0f9673 100644 --- a/settings.gradle +++ b/settings.gradle @@ -10,4 +10,4 @@ pluginManagement { } // Should match your modid -rootProject.name = 'modid' +rootProject.name = 'non-carryon' diff --git a/src/client/java/com/example/client/ExampleModClient.java b/src/client/java/com/example/client/ExampleModClient.java deleted file mode 100644 index 98be303..0000000 --- a/src/client/java/com/example/client/ExampleModClient.java +++ /dev/null @@ -1,10 +0,0 @@ -package com.example.client; - -import net.fabricmc.api.ClientModInitializer; - -public class ExampleModClient implements ClientModInitializer { - @Override - public void onInitializeClient() { - // This entrypoint is suitable for setting up client-specific logic, such as rendering. - } -} \ No newline at end of file diff --git a/src/client/java/com/example/client/mixin/ExampleClientMixin.java b/src/client/java/com/example/client/mixin/ExampleClientMixin.java deleted file mode 100644 index 4869a33..0000000 --- a/src/client/java/com/example/client/mixin/ExampleClientMixin.java +++ /dev/null @@ -1,15 +0,0 @@ -package com.example.client.mixin; - -import net.minecraft.client.Minecraft; -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(Minecraft.class) -public class ExampleClientMixin { - @Inject(at = @At("HEAD"), method = "run") - private void init(CallbackInfo info) { - // This code is injected into the start of Minecraft.run()V - } -} \ No newline at end of file diff --git a/src/client/resources/modid.client.mixins.json b/src/client/resources/modid.client.mixins.json deleted file mode 100644 index 39112a4..0000000 --- a/src/client/resources/modid.client.mixins.json +++ /dev/null @@ -1,14 +0,0 @@ -{ - "required": true, - "package": "com.example.client.mixin", - "compatibilityLevel": "JAVA_21", - "client": [ - "ExampleClientMixin" - ], - "injectors": { - "defaultRequire": 1 - }, - "overwrites": { - "requireAnnotations": true - } -} \ No newline at end of file diff --git a/src/main/java/com/example/ExampleMod.java b/src/main/java/com/example/ExampleMod.java deleted file mode 100644 index cd26137..0000000 --- a/src/main/java/com/example/ExampleMod.java +++ /dev/null @@ -1,30 +0,0 @@ -package com.example; - -import net.fabricmc.api.ModInitializer; - -import net.minecraft.resources.Identifier; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -public class ExampleMod implements ModInitializer { - public static final String MOD_ID = "modid"; - - // This logger is used to write text to the console and the log file. - // It is considered best practice to use your mod id as the logger's name. - // That way, it's clear which mod wrote info, warnings, and errors. - public static final Logger LOGGER = LoggerFactory.getLogger(MOD_ID); - - @Override - public void onInitialize() { - // This code runs as soon as Minecraft is in a mod-load-ready state. - // However, some things (like resources) may still be uninitialized. - // Proceed with mild caution. - - LOGGER.info("Hello Fabric world!"); - } - - public static Identifier id(String path) { - return Identifier.fromNamespaceAndPath(MOD_ID, path); - } -} diff --git a/src/main/java/com/example/mixin/ExampleMixin.java b/src/main/java/com/example/mixin/ExampleMixin.java deleted file mode 100644 index 7a67d1f..0000000 --- a/src/main/java/com/example/mixin/ExampleMixin.java +++ /dev/null @@ -1,15 +0,0 @@ -package com.example.mixin; - -import net.minecraft.server.MinecraftServer; -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(MinecraftServer.class) -public class ExampleMixin { - @Inject(at = @At("HEAD"), method = "loadLevel") - private void init(CallbackInfo info) { - // This code is injected into the start of MinecraftServer.loadLevel()V - } -} \ No newline at end of file diff --git a/src/main/java/mystya/mixin/carryon.java b/src/main/java/mystya/mixin/carryon.java new file mode 100644 index 0000000..188ae23 --- /dev/null +++ b/src/main/java/mystya/mixin/carryon.java @@ -0,0 +1,61 @@ +package mystya.mixin; + +import com.llamalad7.mixinextras.sugar.Local; +import net.minecraft.world.entity.Entity; +import net.minecraft.world.entity.EntityType; +import net.minecraft.world.entity.MobCategory; +import net.minecraft.world.entity.player.Player; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Redirect; +import tschipp.carryon.common.carry.PickupHandler; +import org.spongepowered.asm.mixin.Mixin; +import tschipp.carryon.utils.SizeHelper; + +@Mixin(PickupHandler.class) + +public class carryon { + private static boolean hasTag(Entity e) { + return e.getTags().contains("non.pregnancy_friendly"); + } + + @Redirect( + method = "tryPickupEntity", + at = @At( + value = "INVOKE", + target = "Lnet/minecraft/world/entity/EntityType;getCategory()Lnet/minecraft/world/entity/MobCategory;" + ) + ) + private static MobCategory skipMonsterCheck(EntityType instance, @Local(argsOnly = true) Entity entity) { + MobCategory category = entity.getType().getCategory(); + if (category == MobCategory.MONSTER && hasTag(entity)) + return MobCategory.CREATURE; + return category; + } + + + @Redirect( + method = "tryPickupEntity", + at = @At( + value = "INVOKE", + target = "Ltschipp/carryon/utils/SizeHelper;getRelativeEntityHeight(Lnet/minecraft/world/entity/player/Player;Lnet/minecraft/world/entity/Entity;)F" + ) + ) + private static float skipHeightCheck(Player player, Entity entity) { + if (hasTag(entity)) return 0; + return SizeHelper.getRelativeEntityHeight(player, entity); + } + + + @Redirect( + method = "tryPickupEntity", + at = @At( + value = "INVOKE", + target = "Ltschipp/carryon/utils/SizeHelper;getRelativeEntityWidth(Lnet/minecraft/world/entity/player/Player;Lnet/minecraft/world/entity/Entity;)F" + ) + ) + private static float skipWidthCheck(Player player, Entity entity) { + if (hasTag(entity)) return 0; + return SizeHelper.getRelativeEntityWidth(player, entity); + } + +} \ No newline at end of file diff --git a/src/main/resources/assets/modid/icon.png b/src/main/resources/assets/modid/icon.png deleted file mode 100644 index 047b91f..0000000 Binary files a/src/main/resources/assets/modid/icon.png and /dev/null differ diff --git a/src/main/resources/assets/non-carryon/icon.png b/src/main/resources/assets/non-carryon/icon.png new file mode 100644 index 0000000..79158aa Binary files /dev/null and b/src/main/resources/assets/non-carryon/icon.png differ diff --git a/src/main/resources/assets/non-carryon/lang/en_us.json b/src/main/resources/assets/non-carryon/lang/en_us.json new file mode 100644 index 0000000..503601f --- /dev/null +++ b/src/main/resources/assets/non-carryon/lang/en_us.json @@ -0,0 +1,4 @@ +{ + "mystya.non-carryon.name": "non: allow carry on pickup hostile offspring", + "mystya.non-carryon.description": "skip carry on mob type check & size check for needs of nature pregnancy offspring" +} \ No newline at end of file diff --git a/src/main/resources/assets/non-carryon/lang/zh_cn.json b/src/main/resources/assets/non-carryon/lang/zh_cn.json new file mode 100644 index 0000000..27cbf5b --- /dev/null +++ b/src/main/resources/assets/non-carryon/lang/zh_cn.json @@ -0,0 +1,4 @@ +{ + "mystya.non-carryon.name": "自然之需:可抱起后代", + "mystya.non-carryon.description": "自然之需产下的后代可以被玩家 carryon 抱起,无论是敌对生物还是大体积生物。" +} \ No newline at end of file diff --git a/src/main/resources/fabric.mod.json b/src/main/resources/fabric.mod.json index 210cadb..8221f19 100644 --- a/src/main/resources/fabric.mod.json +++ b/src/main/resources/fabric.mod.json @@ -1,38 +1,32 @@ { "schemaVersion": 1, - "id": "modid", + "id": "non-carryon", "version": "${version}", - "name": "Example Mod", - "description": "This is an example description! Tell everyone what your mod is about!", + "name": "allow carry on pickup hostile offspring", + "description": "skip carry on mob type check & size check for needs of nature pregnancy offspring", + "modmenu": { + "nameTranslation": "mystya.non-carryon.name", + "descriptionTranslation": "mystya.non-carryon.description" + }, "authors": [ - "Me!" + "mystya" ], "contact": { - "homepage": "https://fabricmc.net/", - "sources": "https://github.com/FabricMC/fabric-example-mod" + "sources": "example.com" }, - "license": "CC0-1.0", - "icon": "assets/modid/icon.png", + "license": "CC BY-NC 4.0", + "icon": "assets/non-carryon/icon.png", "environment": "*", "entrypoints": { - "main": [ - "com.example.ExampleMod" - ], - "client": [ - "com.example.client.ExampleModClient" - ] }, "mixins": [ - "modid.mixins.json", - { - "config": "modid.client.mixins.json", - "environment": "client" - } + "non-carryon.mixins.json" ], "depends": { "fabricloader": ">=0.19.5", "minecraft": "~1.21.11", "java": ">=21", - "fabric-api": "*" + "carryon": ">=2.9.2", + "needsofnature": ">=1.5.1" } } \ No newline at end of file diff --git a/src/main/resources/modid.mixins.json b/src/main/resources/non-carryon.mixins.json similarity index 76% rename from src/main/resources/modid.mixins.json rename to src/main/resources/non-carryon.mixins.json index f48035e..ea67c2f 100644 --- a/src/main/resources/modid.mixins.json +++ b/src/main/resources/non-carryon.mixins.json @@ -1,9 +1,9 @@ { "required": true, - "package": "com.example.mixin", + "package": "mystya.mixin", "compatibilityLevel": "JAVA_21", "mixins": [ - "ExampleMixin" + "carryon" ], "injectors": { "defaultRequire": 1