diff --git a/build.gradle b/build.gradle index f657979..a2a6dd1 100644 --- a/build.gradle +++ b/build.gradle @@ -1,78 +1,101 @@ plugins { id 'architectury-plugin' version "${architect_plugin_version}" id 'dev.architectury.loom' version "${architectury_loom_version}" + id 'com.gradleup.shadow' version "${shadow_plugin_version}" apply false +} + +base { + archivesName = rootProject.archive_base_name } architectury { - minecraft = project.minecraft_version common(project.enabled_platforms.split(',')) } loom { + accessWidenerPath = file('src/main/resources/catsplus.accesswidener') + runConfigs.configureEach { ideConfigGenerated = true } } -sourceSets.main.resources.srcDir 'src/main/generated' +dependencies { + // In order to use the @Environment and @EnvironmentInterface annotations from fabric loader. + modImplementation "net.fabricmc:fabric-loader:${rootProject.fabric_loader_version}" + + modApi "dev.architectury:architectury:${rootProject.architectury_api_version}" +} + +sourceSets { + main { + resources { + srcDir file('src/generated/resources') + if (providers.gradleProperty('MOD_DEVELOPMENT').present) { + srcDir file('src/test/resources') + } + } + } +} allprojects { + apply plugin: 'java' + apply plugin: 'maven-publish' apply plugin: 'architectury-plugin' apply plugin: 'dev.architectury.loom' - apply plugin: 'maven-publish' group = 'cuteneko' - version = "${project.mod_version}+mc${project.minecraft_version}" + version = "${rootProject.mod_version}+mc${rootProject.minecraft_version}" architectury { - minecraft = project.minecraft_version + minecraft = rootProject.minecraft_version } loom { - accessWidenerPath = file('src/main/resources/catsplus.accesswidener') + silentMojangMappingsLicense() + + // Write your interface injections in architectury.common.json + interfaceInjection { + enableDependencyInterfaceInjection = true + } } repositories { - repositories { - maven { - name = 'Mod Menu' - url = 'https://maven.terraformersmc.com/releases' - } + maven { + name = 'ParchmentMC' + url = 'https://maven.parchmentmc.org' } - } - dependencies { - minecraft "com.mojang:minecraft:${project.minecraft_version}" - mappings "net.fabricmc:yarn:${project.yarn_mappings}:v2" + maven { + name = 'Mod Menu' + url = 'https://maven.terraformersmc.com/releases' + } - modImplementation "net.fabricmc:fabric-loader:${project.fabric_loader_version}" - modApi "dev.architectury:architectury:${project.architectury_version}" - } + maven { + name = 'NeoForged' + url = 'https://maven.neoforged.net/releases/' + } - configurations { - common - shadowCommon - compileClasspath.extendsFrom common - runtimeClasspath.extendsFrom common - developmentForge.extendsFrom common - developmentFabric.extendsFrom common - developmentNeoForge.extendsFrom common - developmentQuilt.extendsFrom common + maven { + name = 'Forge' + url = 'https://maven.minecraftforge.net/' + } } - def targetJavaVersion = 17 - tasks.withType(JavaCompile).configureEach { - it.options.encoding = 'UTF-8' - if (targetJavaVersion >= 10 || JavaVersion.current().isJava10Compatible()) { - it.options.release = targetJavaVersion + dependencies { + minecraft "com.mojang:minecraft:${rootProject.minecraft_version}" + mappings loom.layered() { + officialMojangMappings() + parchment("org.parchmentmc.data:parchment-${rootProject.parchment_minecraft_version}:${rootProject.parchment_version}@zip") } } + tasks.withType(JavaCompile) { + options.encoding = 'UTF-8' + options.release = 21 + } + java { - def javaVersion = JavaVersion.toVersion(targetJavaVersion) - if (JavaVersion.current() < javaVersion) { - toolchain.languageVersion = JavaLanguageVersion.of(targetJavaVersion) - } withSourcesJar() } @@ -83,17 +106,33 @@ allprojects { } processResources { - var resourcesToReplace = ['build.properties', 'META-INF/mods.toml', 'pack.mcmeta', 'fabric.mod.json'] + var resourcesToReplace = ['build.properties', + 'pack.mcmeta', + 'META-INF/mods.toml', + 'META-INF/neoforge.mods.toml', + 'fabric.mod.json'] var replaceTokens = [ - minecraft_version: minecraft_version, - mod_version: mod_version, - forge_loader_version: forge_loader_version, - forge_version: forge_version, - fabric_loader_version: fabric_loader_version, - fabric_api_version: fabric_api_version, - neoforge_version: neoforge_version, - architectury_version: architectury_version + mod_id : rootProject.mod_id, + mod_version : rootProject.mod_version, + + minecraft_version : rootProject.minecraft_version, + fabric_loader_version : rootProject.fabric_loader_version, + fabric_api_version : rootProject.fabric_api_version, + neoforge_loader_version : rootProject.neoforge_loader_version, + neoforge_version : rootProject.neoforge_version, + + architectury_api_version : rootProject.architectury_api_version, + + neoforge_minecraft_version_range : rootProject.neoforge_minecraft_version_range, + neoforge_loader_version_range : rootProject.neoforge_loader_version_range, + neoforge_version_range : rootProject.neoforge_version_range, + neoforge_architectury_version_range: rootProject.neoforge_architectury_version_range, + + fabric_minecraft_version_range : rootProject.fabric_minecraft_version_range, + fabric_loader_version_range : rootProject.fabric_loader_version_range, + fabric_api_version_range : rootProject.fabric_api_version_range, + fabric_architectury_version_range : rootProject.fabric_architectury_version_range ] inputs.properties replaceTokens @@ -111,7 +150,7 @@ allprojects { maven { name = 'YuluoMaven' - def ENV = System.getenv(); + def ENV = System.getenv() def releaseUrl = 'https://maven.yuluo.dev/repository/maven-releases/' def snapshotUrl = 'https://maven.yuluo.dev/repository/maven-snapshots/' @@ -123,5 +162,89 @@ allprojects { } } } + + publications { + maven(MavenPublication) { + from components.java + } + } + } +} + +subprojects { + apply plugin: 'com.gradleup.shadow' + + base { + archivesName = "$rootProject.archive_base_name-$project.name" + } + + loom { + accessWidenerPath = project(':').loom.accessWidenerPath + + runs { + client { + client() + + runDir 'run/client' + + // To support the Enhanced Class Redefinition in JBR. + vmArg '-XX:+IgnoreUnrecognizedVMOptions' + vmArg '-XX:+AllowEnhancedClassRedefinition' + + // https://openjdk.org/jeps/400 + property 'file.encoding', 'COMPAT' + } + + server { + server() + runDir 'run/server' + vmArg '-XX:+IgnoreUnrecognizedVMOptions' + vmArg '-XX:+AllowEnhancedClassRedefinition' + property 'file.encoding', 'COMPAT' + } + } + } + + configurations { + common { + canBeResolved = true + canBeConsumed = false + } + + compileClasspath.extendsFrom common + runtimeClasspath.extendsFrom common + developmentFabric.extendsFrom common + developmentNeoForge.extendsFrom common + developmentForge.extendsFrom common + + shadowBundle { + canBeResolved = true + canBeConsumed = false + } + } + + dependencies { + } + + shadowJar { + exclude 'architectury.common.json' + configurations = [project.configurations.shadowBundle] + archiveClassifier = 'dev-shadow' + } + + remapJar { + input.set shadowJar.archiveFile + } + + sourcesJar { + def commonSources = rootProject.sourcesJar + dependsOn commonSources + from commonSources.archiveFile.map { zipTree(it) } + } + + components.java { + withVariantsFromConfiguration(project.configurations.shadowRuntimeElements) { + skip() + } } } diff --git a/catsplus-fabric/build.gradle b/catsplus-fabric/build.gradle deleted file mode 100644 index 6e8ff35..0000000 --- a/catsplus-fabric/build.gradle +++ /dev/null @@ -1,73 +0,0 @@ -plugins { - id 'com.github.johnrengelman.shadow' version "${shadow_plugin_version}" - id 'me.shedaniel.unified-publishing' version "${unified_publishing_version}" -} - -architectury { - platformSetupLoomIde() - fabric() -} - -loom { - accessWidenerPath = project(':').loom.accessWidenerPath - - runs { - data { - inherit client - - name 'Data Generation' - - vmArg '-Dfabric-api.datagen' - vmArg "-Dfabric-api.datagen.output-dir=${file("../src/main/generated")}" - vmArg '-Dfabric-api.datagen.modid=catsplus' - - runDir 'build/datagen' - } - } -} - -dependencies { - modImplementation "net.fabricmc:fabric-loader:${project.fabric_loader_version}" - modApi "net.fabricmc.fabric-api:fabric-api:${project.fabric_api_version}" - modApi "dev.architectury:architectury-fabric:${project.architectury_version}" - - modRuntimeOnly "com.terraformersmc:modmenu:${project.mod_menu_version}" - - common(project(path: ':', configuration: 'namedElements')) { transitive = false } - shadowCommon(project(path: ':', configuration: 'transformProductionFabric')) { transitive = false } -} - -shadowJar { - exclude 'architectury.common.json' - - configurations = [project.configurations.shadowCommon] - archiveClassifier = 'dev-shadow' -} - -remapJar { - injectAccessWidener = true - input.set shadowJar.archiveFile - dependsOn shadowJar -} - -sourcesJar { - def commonSources = project(':').sourcesJar - dependsOn commonSources - from commonSources.archiveFile.map { zipTree(it) } -} - -components.java { - withVariantsFromConfiguration(project.configurations.shadowRuntimeElements) { - skip() - } -} - -publishing { - publications { - mavenFabric(MavenPublication) { - artifactId = project.name - version = "true".equalsIgnoreCase(System.getenv("MOD_RELEASE")) ? version : "${version}-SNAPSHOT" - from components.java - } - } -} diff --git a/catsplus-forge/build.gradle b/catsplus-forge/build.gradle deleted file mode 100644 index 8e0e790..0000000 --- a/catsplus-forge/build.gradle +++ /dev/null @@ -1,62 +0,0 @@ -plugins { - id 'com.github.johnrengelman.shadow' version "${shadow_plugin_version}" - id 'me.shedaniel.unified-publishing' version "${unified_publishing_version}" -} - -architectury { - platformSetupLoomIde() - forge() -} - -loom { - accessWidenerPath = project(':').loom.accessWidenerPath - - forge { - convertAccessWideners = true - extraAccessWideners.add loom.accessWidenerPath.get().asFile.name - } -} - -dependencies { - forge "net.minecraftforge:forge:${rootProject.minecraft_version}-${rootProject.forge_version}" - modApi "dev.architectury:architectury-forge:${project.architectury_version}" - - common(project(path: ':', configuration: 'namedElements')) { transitive = false } - shadowCommon(project(path: ':', configuration: 'transformProductionFabric')) { transitive = false } -} - -shadowJar { - exclude 'fabric.mod.json' - exclude 'architectury.common.json' - - configurations = [project.configurations.shadowCommon] - archiveClassifier = 'dev-shadow' -} - -remapJar { - injectAccessWidener = true - input.set shadowJar.archiveFile - dependsOn shadowJar -} - -sourcesJar { - def commonSources = project(':').sourcesJar - dependsOn commonSources - from commonSources.archiveFile.map { zipTree(it) } -} - -components.java { - withVariantsFromConfiguration(project.configurations.shadowRuntimeElements) { - skip() - } -} - -publishing { - publications { - mavenFabric(MavenPublication) { - artifactId = project.name - version = "true".equalsIgnoreCase(System.getenv("MOD_RELEASE")) ? version : "${version}-SNAPSHOT" - from components.java - } - } -} diff --git a/fabric/build.gradle b/fabric/build.gradle new file mode 100644 index 0000000..c59a4c0 --- /dev/null +++ b/fabric/build.gradle @@ -0,0 +1,35 @@ +architectury { + platformSetupLoomIde() + fabric() +} + +loom { + runs { + data { + inherit client + + name 'Data Generation' + + vmArg '-Dfabric-api.datagen' + vmArg "-Dfabric-api.datagen.output-dir=${file("../src/main/generated")}" + vmArg '-Dfabric-api.datagen.modid=catsplus' + + runDir 'build/datagen' + } + } +} + +dependencies { + modImplementation "net.fabricmc:fabric-loader:${rootProject.fabric_loader_version}" + modApi "net.fabricmc.fabric-api:fabric-api:${rootProject.fabric_api_version}" + + modApi "dev.architectury:architectury-fabric:${rootProject.architectury_api_version}" + modRuntimeOnly "com.terraformersmc:modmenu:${rootProject.fabric_mod_menu_version}" + + common(project(path: ':', configuration: 'namedElements')) { transitive false } + shadowBundle project(path: ':', configuration: 'transformProductionFabric') +} + +remapJar { + injectAccessWidener = true +} diff --git a/catsplus-fabric/src/main/java/cuteneko/catsplus/fabric/CatsPlusDataImpl.java b/fabric/src/main/java/cuteneko/catsplus/fabric/CatsPlusDataImpl.java similarity index 81% rename from catsplus-fabric/src/main/java/cuteneko/catsplus/fabric/CatsPlusDataImpl.java rename to fabric/src/main/java/cuteneko/catsplus/fabric/CatsPlusDataImpl.java index d3ad755..e77c635 100644 --- a/catsplus-fabric/src/main/java/cuteneko/catsplus/fabric/CatsPlusDataImpl.java +++ b/fabric/src/main/java/cuteneko/catsplus/fabric/CatsPlusDataImpl.java @@ -3,7 +3,7 @@ import cuteneko.catsplus.fabric.data.CatPlayerFabric; import cuteneko.catsplus.fabric.data.GeniusCatFabric; import cuteneko.catsplus.data.ICatPlayer; -import cuteneko.catsplus.data.IGeniusCat; +import cuteneko.catsplus.data.entity.GeniusCat; import net.minecraft.entity.passive.CatEntity; import net.minecraft.entity.player.PlayerEntity; @@ -12,7 +12,7 @@ public static ICatPlayer getCatPlayer(PlayerEntity player) { return new CatPlayerFabric(player); } - public static IGeniusCat getGeniusCat(CatEntity cat) { + public static GeniusCat getGeniusCat(CatEntity cat) { return new GeniusCatFabric(cat); } } diff --git a/catsplus-fabric/src/main/java/cuteneko/catsplus/fabric/CatsPlusFabric.java b/fabric/src/main/java/cuteneko/catsplus/fabric/CatsPlusFabric.java similarity index 100% rename from catsplus-fabric/src/main/java/cuteneko/catsplus/fabric/CatsPlusFabric.java rename to fabric/src/main/java/cuteneko/catsplus/fabric/CatsPlusFabric.java diff --git a/catsplus-fabric/src/main/java/cuteneko/catsplus/fabric/data/CatPlayerFabric.java b/fabric/src/main/java/cuteneko/catsplus/fabric/data/CatPlayerFabric.java similarity index 100% rename from catsplus-fabric/src/main/java/cuteneko/catsplus/fabric/data/CatPlayerFabric.java rename to fabric/src/main/java/cuteneko/catsplus/fabric/data/CatPlayerFabric.java diff --git a/catsplus-fabric/src/main/java/cuteneko/catsplus/fabric/data/GeniusCatFabric.java b/fabric/src/main/java/cuteneko/catsplus/fabric/data/GeniusCatFabric.java similarity index 88% rename from catsplus-fabric/src/main/java/cuteneko/catsplus/fabric/data/GeniusCatFabric.java rename to fabric/src/main/java/cuteneko/catsplus/fabric/data/GeniusCatFabric.java index f0a7f82..a50f068 100644 --- a/catsplus-fabric/src/main/java/cuteneko/catsplus/fabric/data/GeniusCatFabric.java +++ b/fabric/src/main/java/cuteneko/catsplus/fabric/data/GeniusCatFabric.java @@ -1,15 +1,13 @@ package cuteneko.catsplus.fabric.data; import cuteneko.catsplus.fabric.mixins.impl.ICatEntityMixin; -import cuteneko.catsplus.data.IGeniusCat; -import cuteneko.catsplus.mixins.bridge.dancing.IMusicianCat; +import cuteneko.catsplus.data.entity.GeniusCat; import net.minecraft.entity.EntityStatuses; import net.minecraft.entity.passive.CatEntity; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.util.math.BlockPos; -import org.jetbrains.annotations.Nullable; -public class GeniusCatFabric implements IGeniusCat { +public class GeniusCatFabric implements GeniusCat { private final CatEntity cat; public GeniusCatFabric(CatEntity cat) { diff --git a/catsplus-fabric/src/main/java/cuteneko/catsplus/fabric/data/gen/ModDataGen.java b/fabric/src/main/java/cuteneko/catsplus/fabric/data/gen/ModDataGen.java similarity index 100% rename from catsplus-fabric/src/main/java/cuteneko/catsplus/fabric/data/gen/ModDataGen.java rename to fabric/src/main/java/cuteneko/catsplus/fabric/data/gen/ModDataGen.java diff --git a/catsplus-fabric/src/main/java/cuteneko/catsplus/fabric/data/gen/ModItemModelProvider.java b/fabric/src/main/java/cuteneko/catsplus/fabric/data/gen/ModItemModelProvider.java similarity index 100% rename from catsplus-fabric/src/main/java/cuteneko/catsplus/fabric/data/gen/ModItemModelProvider.java rename to fabric/src/main/java/cuteneko/catsplus/fabric/data/gen/ModItemModelProvider.java diff --git a/catsplus-fabric/src/main/java/cuteneko/catsplus/fabric/data/gen/ModItemTagProvider.java b/fabric/src/main/java/cuteneko/catsplus/fabric/data/gen/ModItemTagProvider.java similarity index 100% rename from catsplus-fabric/src/main/java/cuteneko/catsplus/fabric/data/gen/ModItemTagProvider.java rename to fabric/src/main/java/cuteneko/catsplus/fabric/data/gen/ModItemTagProvider.java diff --git a/catsplus-fabric/src/main/java/cuteneko/catsplus/fabric/data/gen/ModRecipeProvider.java b/fabric/src/main/java/cuteneko/catsplus/fabric/data/gen/ModRecipeProvider.java similarity index 100% rename from catsplus-fabric/src/main/java/cuteneko/catsplus/fabric/data/gen/ModRecipeProvider.java rename to fabric/src/main/java/cuteneko/catsplus/fabric/data/gen/ModRecipeProvider.java diff --git a/catsplus-fabric/src/main/java/cuteneko/catsplus/fabric/data/gen/lang/ModLangProviderENUS.java b/fabric/src/main/java/cuteneko/catsplus/fabric/data/gen/lang/ModLangProviderENUS.java similarity index 98% rename from catsplus-fabric/src/main/java/cuteneko/catsplus/fabric/data/gen/lang/ModLangProviderENUS.java rename to fabric/src/main/java/cuteneko/catsplus/fabric/data/gen/lang/ModLangProviderENUS.java index ee98e3f..8cf1570 100644 --- a/catsplus-fabric/src/main/java/cuteneko/catsplus/fabric/data/gen/lang/ModLangProviderENUS.java +++ b/fabric/src/main/java/cuteneko/catsplus/fabric/data/gen/lang/ModLangProviderENUS.java @@ -8,7 +8,6 @@ import dev.architectury.registry.registries.DeferredSupplier; import net.fabricmc.fabric.api.datagen.v1.FabricDataOutput; import net.fabricmc.fabric.api.datagen.v1.provider.FabricLanguageProvider; -import net.minecraft.item.ItemGroup; public class ModLangProviderENUS extends FabricLanguageProvider { public ModLangProviderENUS(FabricDataOutput dataOutput) { diff --git a/catsplus-fabric/src/main/java/cuteneko/catsplus/fabric/data/gen/lang/ModLangProviderZHCN.java b/fabric/src/main/java/cuteneko/catsplus/fabric/data/gen/lang/ModLangProviderZHCN.java similarity index 100% rename from catsplus-fabric/src/main/java/cuteneko/catsplus/fabric/data/gen/lang/ModLangProviderZHCN.java rename to fabric/src/main/java/cuteneko/catsplus/fabric/data/gen/lang/ModLangProviderZHCN.java diff --git a/catsplus-fabric/src/main/java/cuteneko/catsplus/fabric/mixins/impl/ICatEntityMixin.java b/fabric/src/main/java/cuteneko/catsplus/fabric/mixins/impl/ICatEntityMixin.java similarity index 100% rename from catsplus-fabric/src/main/java/cuteneko/catsplus/fabric/mixins/impl/ICatEntityMixin.java rename to fabric/src/main/java/cuteneko/catsplus/fabric/mixins/impl/ICatEntityMixin.java diff --git a/catsplus-fabric/src/main/java/cuteneko/catsplus/fabric/mixins/impl/IPlayerEntityMixin.java b/fabric/src/main/java/cuteneko/catsplus/fabric/mixins/impl/IPlayerEntityMixin.java similarity index 100% rename from catsplus-fabric/src/main/java/cuteneko/catsplus/fabric/mixins/impl/IPlayerEntityMixin.java rename to fabric/src/main/java/cuteneko/catsplus/fabric/mixins/impl/IPlayerEntityMixin.java diff --git a/catsplus-fabric/src/main/java/cuteneko/catsplus/fabric/mixins/mixin/CatEntityMixin.java b/fabric/src/main/java/cuteneko/catsplus/fabric/mixins/mixin/CatEntityMixin.java similarity index 100% rename from catsplus-fabric/src/main/java/cuteneko/catsplus/fabric/mixins/mixin/CatEntityMixin.java rename to fabric/src/main/java/cuteneko/catsplus/fabric/mixins/mixin/CatEntityMixin.java diff --git a/catsplus-fabric/src/main/java/cuteneko/catsplus/fabric/mixins/mixin/PlayerEntityMixin.java b/fabric/src/main/java/cuteneko/catsplus/fabric/mixins/mixin/PlayerEntityMixin.java similarity index 100% rename from catsplus-fabric/src/main/java/cuteneko/catsplus/fabric/mixins/mixin/PlayerEntityMixin.java rename to fabric/src/main/java/cuteneko/catsplus/fabric/mixins/mixin/PlayerEntityMixin.java diff --git a/catsplus-fabric/src/main/resources/catsplus-fabric.mixins.json b/fabric/src/main/resources/catsplus-fabric.mixins.json similarity index 100% rename from catsplus-fabric/src/main/resources/catsplus-fabric.mixins.json rename to fabric/src/main/resources/catsplus-fabric.mixins.json diff --git a/catsplus-fabric/src/main/resources/fabric.mod.json b/fabric/src/main/resources/fabric.mod.json similarity index 100% rename from catsplus-fabric/src/main/resources/fabric.mod.json rename to fabric/src/main/resources/fabric.mod.json diff --git a/forge/build.gradle b/forge/build.gradle new file mode 100644 index 0000000..ae9bfa3 --- /dev/null +++ b/forge/build.gradle @@ -0,0 +1,19 @@ +architectury { + platformSetupLoomIde() + forge() +} + +loom { + forge { + convertAccessWideners = true + extraAccessWideners.add loom.accessWidenerPath.get().asFile.name + } +} + +dependencies { + forge "net.minecraftforge:forge:${rootProject.minecraft_version}-${rootProject.forge_version}" + modApi "dev.architectury:architectury-forge:${rootProject.architectury_api_version}" + + common(project(path: ':', configuration: 'namedElements')) { transitive false } + shadowBundle project(path: ':', configuration: 'transformProductionForge') +} diff --git a/catsplus-forge/gradle.properties b/forge/gradle.properties similarity index 100% rename from catsplus-forge/gradle.properties rename to forge/gradle.properties diff --git a/catsplus-forge/src/main/java/cuteneko/catsplus/forge/CatsPlusDataImpl.java b/forge/src/main/java/cuteneko/catsplus/forge/CatsPlusDataImpl.java similarity index 100% rename from catsplus-forge/src/main/java/cuteneko/catsplus/forge/CatsPlusDataImpl.java rename to forge/src/main/java/cuteneko/catsplus/forge/CatsPlusDataImpl.java diff --git a/catsplus-forge/src/main/java/cuteneko/catsplus/forge/CatsPlusForge.java b/forge/src/main/java/cuteneko/catsplus/forge/CatsPlusForge.java similarity index 100% rename from catsplus-forge/src/main/java/cuteneko/catsplus/forge/CatsPlusForge.java rename to forge/src/main/java/cuteneko/catsplus/forge/CatsPlusForge.java diff --git a/catsplus-forge/src/main/java/cuteneko/catsplus/forge/capability/CatPlayerCapability.java b/forge/src/main/java/cuteneko/catsplus/forge/capability/CatPlayerCapability.java similarity index 100% rename from catsplus-forge/src/main/java/cuteneko/catsplus/forge/capability/CatPlayerCapability.java rename to forge/src/main/java/cuteneko/catsplus/forge/capability/CatPlayerCapability.java diff --git a/catsplus-forge/src/main/java/cuteneko/catsplus/forge/capability/GeniusCatCapability.java b/forge/src/main/java/cuteneko/catsplus/forge/capability/GeniusCatCapability.java similarity index 100% rename from catsplus-forge/src/main/java/cuteneko/catsplus/forge/capability/GeniusCatCapability.java rename to forge/src/main/java/cuteneko/catsplus/forge/capability/GeniusCatCapability.java diff --git a/catsplus-forge/src/main/java/cuteneko/catsplus/forge/capability/ModCapabilities.java b/forge/src/main/java/cuteneko/catsplus/forge/capability/ModCapabilities.java similarity index 100% rename from catsplus-forge/src/main/java/cuteneko/catsplus/forge/capability/ModCapabilities.java rename to forge/src/main/java/cuteneko/catsplus/forge/capability/ModCapabilities.java diff --git a/catsplus-forge/src/main/java/cuteneko/catsplus/forge/capability/provider/CatPlayerProvider.java b/forge/src/main/java/cuteneko/catsplus/forge/capability/provider/CatPlayerProvider.java similarity index 100% rename from catsplus-forge/src/main/java/cuteneko/catsplus/forge/capability/provider/CatPlayerProvider.java rename to forge/src/main/java/cuteneko/catsplus/forge/capability/provider/CatPlayerProvider.java diff --git a/catsplus-forge/src/main/java/cuteneko/catsplus/forge/capability/provider/GeniusCatProvider.java b/forge/src/main/java/cuteneko/catsplus/forge/capability/provider/GeniusCatProvider.java similarity index 100% rename from catsplus-forge/src/main/java/cuteneko/catsplus/forge/capability/provider/GeniusCatProvider.java rename to forge/src/main/java/cuteneko/catsplus/forge/capability/provider/GeniusCatProvider.java diff --git a/catsplus-forge/src/main/resources/META-INF/mods.toml b/forge/src/main/resources/META-INF/mods.toml similarity index 100% rename from catsplus-forge/src/main/resources/META-INF/mods.toml rename to forge/src/main/resources/META-INF/mods.toml diff --git a/catsplus-forge/src/main/resources/pack.mcmeta b/forge/src/main/resources/pack.mcmeta similarity index 100% rename from catsplus-forge/src/main/resources/pack.mcmeta rename to forge/src/main/resources/pack.mcmeta diff --git a/gradle.properties b/gradle.properties index 4aa5e30..b854868 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,33 +1,46 @@ # Done to increase the memory available to gradle. org.gradle.jvmargs=-Xmx8G org.gradle.daemon=false +org.gradle.parallel=true architect_plugin_version=3.4-SNAPSHOT -architectury_loom_version=1.6-SNAPSHOT -shadow_plugin_version=8.1.1 +architectury_loom_version=1.9-SNAPSHOT +shadow_plugin_version=8.3.+ unified_publishing_version=0.1.+ -# Architectury -enabled_platforms=forge,fabric,neoforge,quilt - # Mod +enabled_platforms=forge,fabric,neoforge,quilt +archive_base_name=cats-plus +mod_id=catsplus mod_version=1.0.0 # Minecraft -minecraft_version=1.20.4 -yarn_mappings=1.20.4+build.3 - -# Forge -forge_loader_version=49 -forge_version=49.0.50 - -# Fabric -fabric_loader_version=0.15.7 -fabric_api_version=0.97.0+1.20.4 - -# NeoForge -neoforge_version=20.4.234 +minecraft_version=1.21.1 +parchment_minecraft_version=1.21.1 +parchment_version=2024.11.17 + +# Mod Loaders +fabric_loader_version=0.16.9 +fabric_api_version=0.110.0+1.21.1 +neoforge_loader_version=4 +neoforge_version=21.1.90 +forge_loader_version=52 +forge_version=52.0.28 # Dependencies -architectury_version=11.1.17 -mod_menu_version=9.2.0-beta.2 +architectury_api_version=13.0.8 +fabric_mod_menu_version=11.0.3 + +# Version range used in manifests +neoforge_minecraft_version_range=[1.21.1,) +neoforge_loader_version_range=[4,) +neoforge_version_range=[21.1,) +neoforge_architectury_version_range=[13,) +forge_minecraft_version_range=[1.21.1,) +forge_loader_version_range=[52,) +forge_version_range=[52,) +forge_architectury_version_range=[13,) +fabric_minecraft_version_range=>=1.21.1 +fabric_loader_version_range=>=0.16 +fabric_api_version_range=* +fabric_architectury_version_range=>=13 diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 17655d0..e48eca5 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,5 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-8.6-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.11-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/neoforge/build.gradle b/neoforge/build.gradle new file mode 100644 index 0000000..7b5c8da --- /dev/null +++ b/neoforge/build.gradle @@ -0,0 +1,17 @@ +architectury { + platformSetupLoomIde() + forge() +} + +dependencies { + neoForge "net.neoforged:neoforge:${rootProject.neoforge_version}" + + modApi "dev.architectury:architectury-neoforge:${rootProject.architectury_api_version}" + + common(project(path: ':', configuration: 'namedElements')) { transitive false } + shadowBundle project(path: ':', configuration: 'transformProductionNeoForge') +} + +remapJar { + atAccessWideners.add(loom.accessWidenerPath.get().asFile.name) +} diff --git a/neoforge/gradle.properties b/neoforge/gradle.properties new file mode 100644 index 0000000..7da18ea --- /dev/null +++ b/neoforge/gradle.properties @@ -0,0 +1 @@ +loom.platform=neoforge diff --git a/neoforge/src/main/java/cuteneko/catsplus/forge/CatsPlusDataImpl.java b/neoforge/src/main/java/cuteneko/catsplus/forge/CatsPlusDataImpl.java new file mode 100644 index 0000000..d4c132a --- /dev/null +++ b/neoforge/src/main/java/cuteneko/catsplus/forge/CatsPlusDataImpl.java @@ -0,0 +1,17 @@ +package cuteneko.catsplus.forge; + +import cuteneko.catsplus.data.ICatPlayer; +import cuteneko.catsplus.data.entity.GeniusCat; +import cuteneko.catsplus.forge.capability.ModCapabilities; +import net.minecraft.entity.passive.CatEntity; +import net.minecraft.entity.player.PlayerEntity; + +public class CatsPlusDataImpl { + public static ICatPlayer getCatPlayer(PlayerEntity player) { + return player.getCapability(ModCapabilities.CAT_PLAYER).orElseThrow(RuntimeException::new); + } + + public static GeniusCat getGeniusCat(CatEntity cat) { + return cat.getCapability(ModCapabilities.GENIUS_CAT).orElseThrow(RuntimeException::new); + } +} diff --git a/neoforge/src/main/java/cuteneko/catsplus/forge/CatsPlusForge.java b/neoforge/src/main/java/cuteneko/catsplus/forge/CatsPlusForge.java new file mode 100644 index 0000000..cc7970d --- /dev/null +++ b/neoforge/src/main/java/cuteneko/catsplus/forge/CatsPlusForge.java @@ -0,0 +1,33 @@ +package cuteneko.catsplus.forge; + +import cuteneko.catsplus.CatsPlus; +import dev.architectury.platform.forge.EventBuses; +import net.minecraftforge.common.capabilities.CapabilityManager; +import net.minecraftforge.fml.common.Mod; +import net.minecraftforge.fml.event.lifecycle.FMLClientSetupEvent; +import net.minecraftforge.fml.event.lifecycle.FMLCommonSetupEvent; +import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext; + +@Mod(CatsPlus.MODID) +public class CatsPlusForge { + private final CatsPlus mod; + + public CatsPlusForge() { + mod = new CatsPlus(); + + var bus = FMLJavaModLoadingContext.get().getModEventBus(); + + bus.addListener(this::onSetup); + bus.addListener(this::onClientSetup); + + EventBuses.registerModEventBus(CatsPlus.MODID, bus); + } + + public void onSetup(FMLCommonSetupEvent event) { + mod.init(); + } + + public void onClientSetup(FMLClientSetupEvent event) { + event.enqueueWork(mod::initClient); + } +} diff --git a/neoforge/src/main/java/cuteneko/catsplus/forge/capability/CatPlayerCapability.java b/neoforge/src/main/java/cuteneko/catsplus/forge/capability/CatPlayerCapability.java new file mode 100644 index 0000000..34a923e --- /dev/null +++ b/neoforge/src/main/java/cuteneko/catsplus/forge/capability/CatPlayerCapability.java @@ -0,0 +1,88 @@ +package cuteneko.catsplus.forge.capability; + +import cuteneko.catsplus.data.ICatPlayer; +import cuteneko.catsplus.utility.Constants; +import net.minecraft.entity.EntityType; +import net.minecraft.entity.passive.CatEntity; +import net.minecraft.entity.passive.CatVariant; +import net.minecraft.entity.player.PlayerEntity; +import net.minecraft.nbt.NbtCompound; +import net.minecraft.registry.Registries; +import net.minecraftforge.common.util.INBTSerializable; + +public class CatPlayerCapability implements ICatPlayer, INBTSerializable { + private CatEntity catEntity = null; + private boolean isCat = false; + + public CatPlayerCapability(PlayerEntity player) { + init(player); + } + + private void init(PlayerEntity player) { + int variant = (int) (player.getUuid().getLeastSignificantBits() % 11); + + if (variant < 0) { + variant += 11; + } + + var key = switch (variant) { + case 0 -> CatVariant.TABBY; + case 1 -> CatVariant.BLACK; + case 2 -> CatVariant.RED; + case 3 -> CatVariant.SIAMESE; + case 4 -> CatVariant.BRITISH_SHORTHAIR; + case 5 -> CatVariant.CALICO; + case 6 -> CatVariant.PERSIAN; + case 7 -> CatVariant.RAGDOLL; + case 8 -> CatVariant.WHITE; + case 9 -> CatVariant.JELLIE; + case 10 -> CatVariant.ALL_BLACK; + default -> throw new IllegalArgumentException("Invalid variant: " + variant); + }; + + catEntity = EntityType.CAT.create(player.getWorld()); + + if (catEntity != null) { + catEntity.setVariant(Registries.CAT_VARIANT.get(key)); + } + } + + @Override + public CatEntity getCatEntity() { + return catEntity; + } + + @Override + public void setCatEntity(CatEntity cat) { + this.catEntity = cat; + } + + @Override + public boolean isCat() { + return isCat; + } + + @Override + public void setCat(boolean cat) { + isCat = cat; + } + + @Override + public NbtCompound serializeNBT() { + var tag = new NbtCompound(); + + var catTag = new NbtCompound(); + getCatEntity().saveNbt(catTag); + tag.put(Constants.TAG_CAT_PLAYER_INNER_CAT, catTag); + + tag.putBoolean(Constants.TAG_CAT_PLAYER_IS_CAT, isCat); + return tag; + } + + @Override + public void deserializeNBT(NbtCompound tag) { + var catTag = tag.getCompound(Constants.TAG_CAT_PLAYER_INNER_CAT); + getCatEntity().readNbt(catTag); + isCat = tag.getBoolean(Constants.TAG_CAT_PLAYER_IS_CAT); + } +} diff --git a/neoforge/src/main/java/cuteneko/catsplus/forge/capability/GeniusCatCapability.java b/neoforge/src/main/java/cuteneko/catsplus/forge/capability/GeniusCatCapability.java new file mode 100644 index 0000000..7dcf262 --- /dev/null +++ b/neoforge/src/main/java/cuteneko/catsplus/forge/capability/GeniusCatCapability.java @@ -0,0 +1,92 @@ +package cuteneko.catsplus.forge.capability; + +import cuteneko.catsplus.data.entity.GeniusCat; +import cuteneko.catsplus.utility.Constants; +import net.minecraft.entity.player.PlayerEntity; +import net.minecraft.nbt.NbtCompound; +import net.minecraft.nbt.NbtElement; +import net.minecraft.nbt.NbtList; +import net.minecraftforge.common.util.INBTSerializable; + +import java.util.HashMap; +import java.util.Map; +import java.util.UUID; + +public class GeniusCatCapability implements GeniusCat, INBTSerializable { + + private int lives = 0; + private boolean totem = false; + + private final Map favorability = new HashMap<>(); + + @Override + public boolean hasTotem() { + return totem; + } + + @Override + public void setTotem(boolean totem) { + this.totem = totem; + } + + @Override + public int getFavorability(PlayerEntity player) { + if (!favorability.containsKey(player.getUuid())) { + favorability.put(player.getUuid(), 0); + } + + return favorability.get(player.getUuid()); + } + + @Override + public void setFavorability(int favorability, PlayerEntity player) { + this.favorability.put(player.getUuid(), favorability); + } + + @Override + public int getLives() { + return lives; + } + + @Override + public void setLives(int lives) { + this.lives = lives; + } + + @Override + public NbtCompound serializeNBT() { + var tag = new NbtCompound(); + + tag.putInt(Constants.TAG_GENIUS_CAT_LIVES, lives); + tag.putBoolean(Constants.TAG_GENIUS_CAT_TOTEM, totem); + + var favorability = new NbtList(); + for (var entry : this.favorability.entrySet()) { + var f = new NbtCompound(); + f.putUuid(Constants.TAG_UUID, entry.getKey()); + f.putInt(Constants.TAG_VALUE, entry.getValue()); + favorability.add(f); + } + tag.put(Constants.TAG_GENIUS_CAT_FAVORABILITY, favorability); + + return tag; + } + + @Override + public void deserializeNBT(NbtCompound tag) { + lives = tag.getInt(Constants.TAG_GENIUS_CAT_LIVES); + totem = tag.getBoolean(Constants.TAG_GENIUS_CAT_TOTEM); + + var favorability = tag.getList(Constants.TAG_GENIUS_CAT_FAVORABILITY, NbtElement.LIST_TYPE); + for (var entry : favorability) { + if (entry instanceof NbtCompound e + && e.contains(Constants.TAG_UUID) + && e.contains(Constants.TAG_VALUE)) { + var uuid = e.getUuid(Constants.TAG_UUID); + var value = e.getInt(Constants.TAG_VALUE); + + this.favorability.put(uuid, value); + } + } + } +} diff --git a/neoforge/src/main/java/cuteneko/catsplus/forge/capability/ModCapabilities.java b/neoforge/src/main/java/cuteneko/catsplus/forge/capability/ModCapabilities.java new file mode 100644 index 0000000..a93da94 --- /dev/null +++ b/neoforge/src/main/java/cuteneko/catsplus/forge/capability/ModCapabilities.java @@ -0,0 +1,59 @@ +package cuteneko.catsplus.forge.capability; + +import cuteneko.catsplus.CatsPlus; +import cuteneko.catsplus.data.ICatPlayer; +import cuteneko.catsplus.data.entity.GeniusCat; +import cuteneko.catsplus.forge.capability.provider.CatPlayerProvider; +import cuteneko.catsplus.forge.capability.provider.GeniusCatProvider; +import cuteneko.catsplus.utility.Constants; +import net.minecraft.entity.Entity; +import net.minecraft.entity.passive.CatEntity; +import net.minecraft.entity.player.PlayerEntity; +import net.minecraftforge.common.capabilities.Capability; +import net.minecraftforge.common.capabilities.CapabilityManager; +import net.minecraftforge.common.capabilities.CapabilityToken; +import net.minecraftforge.common.capabilities.RegisterCapabilitiesEvent; +import net.minecraftforge.event.AttachCapabilitiesEvent; +import net.minecraftforge.event.entity.player.PlayerEvent; +import net.minecraftforge.eventbus.api.SubscribeEvent; +import net.minecraftforge.fml.common.Mod; + +@Mod.EventBusSubscriber(modid = CatsPlus.MODID, bus = Mod.EventBusSubscriber.Bus.FORGE) +public class ModCapabilities { + public static Capability GENIUS_CAT = CapabilityManager.get(new CapabilityToken<>() {}); + public static Capability CAT_PLAYER = CapabilityManager.get(new CapabilityToken<>() {}); + + @SubscribeEvent + public void registerCaps(RegisterCapabilitiesEvent event) { + event.register(GeniusCat.class); + event.register(ICatPlayer.class); + } + + @SubscribeEvent + public void onAttachEntityCaps(AttachCapabilitiesEvent event) { + if (event.getObject() instanceof CatEntity) { + var provider = new GeniusCatProvider(); + event.addCapability(Constants.CAP_GENIUS_CAT, provider); + event.addListener(provider::invalidate); + } + + if (event.getObject() instanceof PlayerEntity player) { + var provider = new CatPlayerProvider(player); + event.addCapability(Constants.CAP_CAT_PLAYER, provider); + event.addListener(provider::invalidate); + } + } + + @SubscribeEvent + public void onPlayerClone(PlayerEvent.Clone event) { + if (!event.isWasDeath()) { + var original = event.getOriginal(); + var player = event.getEntity(); + player.getCapability(CAT_PLAYER) + .orElse(new CatPlayerCapability(player)) + .deserializeNBT(original.getCapability(CAT_PLAYER) + .orElse(new CatPlayerCapability(original)) + .serializeNBT()); + } + } +} diff --git a/neoforge/src/main/java/cuteneko/catsplus/forge/capability/provider/CatPlayerProvider.java b/neoforge/src/main/java/cuteneko/catsplus/forge/capability/provider/CatPlayerProvider.java new file mode 100644 index 0000000..576780d --- /dev/null +++ b/neoforge/src/main/java/cuteneko/catsplus/forge/capability/provider/CatPlayerProvider.java @@ -0,0 +1,47 @@ +package cuteneko.catsplus.forge.capability.provider; + +import cuteneko.catsplus.forge.capability.CatPlayerCapability; +import cuteneko.catsplus.forge.capability.GeniusCatCapability; +import cuteneko.catsplus.forge.capability.ModCapabilities; +import net.minecraft.entity.player.PlayerEntity; +import net.minecraft.nbt.NbtCompound; +import net.minecraft.util.math.Direction; +import net.minecraftforge.common.capabilities.Capability; +import net.minecraftforge.common.capabilities.ICapabilitySerializable; +import net.minecraftforge.common.util.LazyOptional; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +public class CatPlayerProvider implements ICapabilitySerializable { + private final PlayerEntity player; + + private final LazyOptional optional; + + public CatPlayerProvider(PlayerEntity player) { + this.player = player; + this.optional = LazyOptional.of(() -> new CatPlayerCapability(player)); + } + + public void invalidate() { + optional.invalidate(); + } + + @Override + public @NotNull LazyOptional getCapability(@NotNull Capability capability, @Nullable Direction arg) { + if (capability == ModCapabilities.CAT_PLAYER) { + return optional.cast(); + } + + return LazyOptional.empty(); + } + + @Override + public NbtCompound serializeNBT() { + return optional.orElse(new CatPlayerCapability(player)).serializeNBT(); + } + + @Override + public void deserializeNBT(NbtCompound nbt) { + optional.orElse(new CatPlayerCapability(player)).deserializeNBT(nbt); + } +} diff --git a/neoforge/src/main/java/cuteneko/catsplus/forge/capability/provider/GeniusCatProvider.java b/neoforge/src/main/java/cuteneko/catsplus/forge/capability/provider/GeniusCatProvider.java new file mode 100644 index 0000000..47a62b3 --- /dev/null +++ b/neoforge/src/main/java/cuteneko/catsplus/forge/capability/provider/GeniusCatProvider.java @@ -0,0 +1,38 @@ +package cuteneko.catsplus.forge.capability.provider; + +import cuteneko.catsplus.forge.capability.GeniusCatCapability; +import cuteneko.catsplus.forge.capability.ModCapabilities; +import net.minecraft.nbt.NbtCompound; +import net.minecraft.util.math.Direction; +import net.minecraftforge.common.capabilities.Capability; +import net.minecraftforge.common.capabilities.ICapabilitySerializable; +import net.minecraftforge.common.util.LazyOptional; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +public class GeniusCatProvider implements ICapabilitySerializable { + private final LazyOptional optional = LazyOptional.of(GeniusCatCapability::new); + + public void invalidate() { + optional.invalidate(); + } + + @Override + public @NotNull LazyOptional getCapability(@NotNull Capability capability, @Nullable Direction arg) { + if (capability == ModCapabilities.GENIUS_CAT) { + return optional.cast(); + } + + return LazyOptional.empty(); + } + + @Override + public NbtCompound serializeNBT() { + return optional.orElse(new GeniusCatCapability()).serializeNBT(); + } + + @Override + public void deserializeNBT(NbtCompound nbt) { + optional.orElse(new GeniusCatCapability()).deserializeNBT(nbt); + } +} diff --git a/neoforge/src/main/resources/META-INF/mods.toml b/neoforge/src/main/resources/META-INF/mods.toml new file mode 100644 index 0000000..ab3df94 --- /dev/null +++ b/neoforge/src/main/resources/META-INF/mods.toml @@ -0,0 +1,38 @@ +modLoader="javafml" +loaderVersion="[${forge_loader_version},)" +license="MIT" +issueTrackerURL="https://github.com/CuteNekoOwO/CatsPlus/issues" + +[[mods]] +modId="catsplus" +version="${mod_version}" +displayName="Cats+" +displayURL="https://github.com/CuteNekoOwO/CatsPlus" +#logoFile="" +credits="CuteNekoOwO" +authors="MeowBot233, YukieMiona and qyl27" +displayTest="MATCH_VERSION" +description=''' +Make cats in Minecraft more fun! +''' + +[[dependencies.catsplus]] + modId="forge" + mandatory=true + versionRange="[${forge_version},)" + ordering="NONE" + side="BOTH" + +[[dependencies.catsplus]] + modId="minecraft" + mandatory=true + versionRange="[${minecraft_version},)" + ordering="NONE" + side="BOTH" + +[[dependencies.catsplus]] + modId="architectury" + mandatory=true + versionRange="[${architectury_version},)" + ordering="NONE" + side="BOTH" diff --git a/neoforge/src/main/resources/pack.mcmeta b/neoforge/src/main/resources/pack.mcmeta new file mode 100644 index 0000000..ad66130 --- /dev/null +++ b/neoforge/src/main/resources/pack.mcmeta @@ -0,0 +1,8 @@ +{ + "pack": { + "description": { + "text": "Cats+ resources" + }, + "pack_format": 15 + } +} diff --git a/settings.gradle b/settings.gradle index a6fca64..7d79218 100644 --- a/settings.gradle +++ b/settings.gradle @@ -26,5 +26,6 @@ pluginManagement { rootProject.name = 'catsplus' -include ':catsplus-fabric' -include ':catsplus-forge' +include ':fabric' +include ':neoforge' +//include ':forge' diff --git a/src/main/java/cuteneko/catsplus/CatsPlus.java b/src/main/java/cuteneko/catsplus/CatsPlus.java index 8ea9ca3..3ac02bc 100644 --- a/src/main/java/cuteneko/catsplus/CatsPlus.java +++ b/src/main/java/cuteneko/catsplus/CatsPlus.java @@ -1,32 +1,19 @@ package cuteneko.catsplus; import cuteneko.catsplus.block.ModBlocks; +import cuteneko.catsplus.data.component.ModComponents; import cuteneko.catsplus.effect.ModEffects; import cuteneko.catsplus.effect.potion.ModPotions; import cuteneko.catsplus.item.ModItems; import cuteneko.catsplus.item.group.ModItemGroups; -import cuteneko.catsplus.listener.CatSpiritListener; import cuteneko.catsplus.listener.ModListeners; -import cuteneko.catsplus.utility.Constants; -import dev.architectury.registry.item.ItemPropertiesRegistry; -import net.minecraft.util.Identifier; - -import java.util.Objects; +import net.minecraft.resources.ResourceLocation; public class CatsPlus { public static final String MODID = "catsplus"; - private static CatsPlus INSTANCE; - - public CatsPlus() { - INSTANCE = this; - } - - public static CatsPlus getInstance() { - return INSTANCE; - } - - public void init() { + public static void init() { + ModComponents.register(); ModItemGroups.register(); ModBlocks.register(); ModItems.register(); @@ -35,30 +22,7 @@ public void init() { ModListeners.register(); } - public void initClient() { - ItemPropertiesRegistry.register(ModItems.CAT_BAG.get(), new Identifier(CatsPlus.MODID, "cat"), - (stack, clientLevel, livingEntity, i) -> { - if(!stack.hasNbt() - || stack.getNbt() == null - || !Objects.requireNonNull(stack.getNbt()).contains(Constants.TAG_CAT_CONTAINER)) { - return 0F; - } - - var nbt = stack.getNbt().getCompound(Constants.TAG_CAT_CONTAINER); - return switch (nbt.getString("variant")) { - case "minecraft:tabby" -> 0.05F; - case "minecraft:black" -> 0.1F; - case "minecraft:red" -> 0.15F; - case "minecraft:siamese" -> 0.2F; - case "minecraft:british_shorthair" -> 0.25F; - case "minecraft:calico" -> 0.3F; - case "minecraft:persian" -> 0.35F; - case "minecraft:ragdoll" -> 0.4F; - case "minecraft:white" -> 0.45F; - case "minecraft:jellie" -> 0.5F; - case "minecraft:all_black" -> 0.55F; - default -> 1F; - }; - }); + public static ResourceLocation modLoc(String path) { + return ResourceLocation.fromNamespaceAndPath(CatsPlus.MODID, path); } } diff --git a/src/main/java/cuteneko/catsplus/CatsPlusData.java b/src/main/java/cuteneko/catsplus/CatsPlusData.java index c778c98..2925fa8 100644 --- a/src/main/java/cuteneko/catsplus/CatsPlusData.java +++ b/src/main/java/cuteneko/catsplus/CatsPlusData.java @@ -1,49 +1,18 @@ package cuteneko.catsplus; -import cuteneko.catsplus.data.*; -import cuteneko.catsplus.data.impl.CatServer; -import cuteneko.catsplus.data.impl.CatSpirit; -import cuteneko.catsplus.item.ModItems; -import cuteneko.catsplus.data.impl.CatBag; -import cuteneko.catsplus.utility.Constants; +import cuteneko.catsplus.data.entity.GeniusCat; +import cuteneko.catsplus.data.entity.MusicianCat; import dev.architectury.injectables.annotations.ExpectPlatform; -import net.minecraft.entity.passive.CatEntity; -import net.minecraft.entity.player.PlayerEntity; -import net.minecraft.item.ItemStack; -import net.minecraft.server.MinecraftServer; -import net.minecraft.world.World; - -import java.util.Objects; +import net.minecraft.world.entity.animal.Cat; public class CatsPlusData { @ExpectPlatform - public static ICatPlayer getCatPlayer(PlayerEntity player) { - throw new UnsupportedOperationException(); + public static GeniusCat getGeniusCat(Cat cat) { + throw new AssertionError(); } @ExpectPlatform - public static IGeniusCat getGeniusCat(CatEntity cat) { - throw new UnsupportedOperationException(); - } - - public static ICatBag getCatBag(ItemStack bag) { - if (!bag.isOf(ModItems.CAT_BAG.get())) { - throw new IllegalArgumentException(); - } - - return new CatBag(bag); - } - - public static ICatSpirit getCatSpirit(ItemStack spirit) { - if (!spirit.isOf(ModItems.CAT_SPIRIT.get())) { - throw new IllegalArgumentException(); - } - - return new CatSpirit(spirit); - } - - public static ICatServer getCatServer(MinecraftServer server) { - return Objects.requireNonNull(server.getWorld(World.OVERWORLD)).getPersistentStateManager() - .getOrCreate(CatServer.TYPE, Constants.TAG_SERVER_HAS_CAT.toString()); + public static MusicianCat getMusicianCat(Cat cat) { + throw new AssertionError(); } } diff --git a/src/main/java/cuteneko/catsplus/block/CatResurrectionStationBlock.java b/src/main/java/cuteneko/catsplus/block/CatResurrectionStationBlock.java index 7984131..796db72 100644 --- a/src/main/java/cuteneko/catsplus/block/CatResurrectionStationBlock.java +++ b/src/main/java/cuteneko/catsplus/block/CatResurrectionStationBlock.java @@ -1,9 +1,9 @@ package cuteneko.catsplus.block; -import net.minecraft.block.Block; +import net.minecraft.world.level.block.Block; public class CatResurrectionStationBlock extends Block { - public CatResurrectionStationBlock(Settings settings) { + public CatResurrectionStationBlock(Properties settings) { super(settings); } } diff --git a/src/main/java/cuteneko/catsplus/block/ModBlocks.java b/src/main/java/cuteneko/catsplus/block/ModBlocks.java index f76d1a1..1247c88 100644 --- a/src/main/java/cuteneko/catsplus/block/ModBlocks.java +++ b/src/main/java/cuteneko/catsplus/block/ModBlocks.java @@ -1,24 +1,23 @@ package cuteneko.catsplus.block; import cuteneko.catsplus.CatsPlus; -import cuteneko.catsplus.item.group.ModItemGroups; import dev.architectury.registry.registries.DeferredRegister; import dev.architectury.registry.registries.RegistrySupplier; -import net.minecraft.block.AbstractBlock; -import net.minecraft.block.Block; -import net.minecraft.item.BlockItem; -import net.minecraft.item.Item; -import net.minecraft.registry.RegistryKeys; +import net.minecraft.core.registries.Registries; +import net.minecraft.world.item.BlockItem; +import net.minecraft.world.item.Item; +import net.minecraft.world.level.block.Block; +import net.minecraft.world.level.block.state.BlockBehaviour; public class ModBlocks { - public static final DeferredRegister BLOCKS = DeferredRegister.create(CatsPlus.MODID, RegistryKeys.BLOCK); - public static final DeferredRegister BLOCK_ITEMS = DeferredRegister.create(CatsPlus.MODID, RegistryKeys.ITEM); + public static final DeferredRegister BLOCKS = DeferredRegister.create(CatsPlus.MODID, Registries.BLOCK); + public static final DeferredRegister BLOCK_ITEMS = DeferredRegister.create(CatsPlus.MODID, Registries.ITEM); public static void register() { BLOCKS.register(); BLOCK_ITEMS.register(); } - public static final RegistrySupplier CAT_RESURRECTION_STATION_BLOCK = BLOCKS.register("cat_resurrection_station", () -> new CatResurrectionStationBlock(AbstractBlock.Settings.create().hardness(5f))); - public static final RegistrySupplier CAT_RESURRECTION_STATION = BLOCK_ITEMS.register("cat_resurrection_station", () -> new BlockItem(CAT_RESURRECTION_STATION_BLOCK.get(), new Item.Settings())); + public static final RegistrySupplier CAT_RESURRECTION_STATION_BLOCK = BLOCKS.register("cat_resurrection_station", () -> new CatResurrectionStationBlock(BlockBehaviour.Properties.of().destroyTime(5f))); + public static final RegistrySupplier CAT_RESURRECTION_STATION = BLOCK_ITEMS.register("cat_resurrection_station", () -> new BlockItem(CAT_RESURRECTION_STATION_BLOCK.get(), new Item.Properties())); } diff --git a/src/main/java/cuteneko/catsplus/bridge/IMusicianCat.java b/src/main/java/cuteneko/catsplus/bridge/IMusicianCat.java new file mode 100644 index 0000000..38e21cb --- /dev/null +++ b/src/main/java/cuteneko/catsplus/bridge/IMusicianCat.java @@ -0,0 +1,8 @@ +package cuteneko.catsplus.bridge; + +import net.minecraft.core.BlockPos; + +public interface IMusicianCat { + void catsplus$soundStarted(BlockPos pos); + void catsplus$soundStopped(); +} diff --git a/src/main/java/cuteneko/catsplus/client/CatPlayerClientHelper.java b/src/main/java/cuteneko/catsplus/client/CatPlayerClientHelper.java new file mode 100644 index 0000000..e1cb920 --- /dev/null +++ b/src/main/java/cuteneko/catsplus/client/CatPlayerClientHelper.java @@ -0,0 +1,5 @@ +package cuteneko.catsplus.client; + +public class CatPlayerClientHelper { + +} diff --git a/src/main/java/cuteneko/catsplus/client/CatsPlusClient.java b/src/main/java/cuteneko/catsplus/client/CatsPlusClient.java new file mode 100644 index 0000000..894d306 --- /dev/null +++ b/src/main/java/cuteneko/catsplus/client/CatsPlusClient.java @@ -0,0 +1,34 @@ +package cuteneko.catsplus.client; + +import cuteneko.catsplus.CatsPlus; +import cuteneko.catsplus.item.ModItems; +import cuteneko.catsplus.utility.ComponentHelper; +import dev.architectury.registry.item.ItemPropertiesRegistry; + +public class CatsPlusClient { + + public static void initClient() { + ItemPropertiesRegistry.register(ModItems.CAT_BAG.get(), CatsPlus.modLoc("cat"), + (stack, clientLevel, livingEntity, i) -> { + var catContainer = ComponentHelper.getCatContainer(stack); + if (catContainer == null) { + return 0; + } + + return switch (catContainer.variant()) { + case "minecraft:tabby" -> 0.05F; + case "minecraft:black" -> 0.1F; + case "minecraft:red" -> 0.15F; + case "minecraft:siamese" -> 0.2F; + case "minecraft:british_shorthair" -> 0.25F; + case "minecraft:calico" -> 0.3F; + case "minecraft:persian" -> 0.35F; + case "minecraft:ragdoll" -> 0.4F; + case "minecraft:white" -> 0.45F; + case "minecraft:jellie" -> 0.5F; + case "minecraft:all_black" -> 0.55F; + default -> 0F; + }; + }); + } +} diff --git a/src/main/java/cuteneko/catsplus/client/entity/CatPlayerRenderer.java b/src/main/java/cuteneko/catsplus/client/entity/CatPlayerRenderer.java new file mode 100644 index 0000000..e729fc1 --- /dev/null +++ b/src/main/java/cuteneko/catsplus/client/entity/CatPlayerRenderer.java @@ -0,0 +1,43 @@ +package cuteneko.catsplus.client.entity; + +import com.mojang.blaze3d.vertex.PoseStack; +import net.minecraft.client.model.OcelotModel; +import net.minecraft.client.model.geom.ModelLayers; +import net.minecraft.client.player.AbstractClientPlayer; +import net.minecraft.client.renderer.MultiBufferSource; +import net.minecraft.client.renderer.entity.EntityRendererProvider; +import net.minecraft.client.renderer.entity.LivingEntityRenderer; +import net.minecraft.core.registries.BuiltInRegistries; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.world.entity.animal.CatVariant; +import org.jetbrains.annotations.NotNull; + +import java.util.UUID; + +public class CatPlayerRenderer extends LivingEntityRenderer> { + public CatPlayerRenderer(EntityRendererProvider.Context context) { + super(context, new OcelotModel<>(context.bakeLayer(ModelLayers.CAT)), 0.4F); + } + + @Override + public @NotNull ResourceLocation getTextureLocation(AbstractClientPlayer entity) { + return getVariant(entity.getUUID()).texture(); + } + + private CatVariant getVariant(UUID uuid) { + return switch ((int) (uuid.getLeastSignificantBits() % 11)) { + case 0 -> BuiltInRegistries.CAT_VARIANT.get(CatVariant.TABBY); + case 1 -> BuiltInRegistries.CAT_VARIANT.get(CatVariant.BLACK); + case 2 -> BuiltInRegistries.CAT_VARIANT.get(CatVariant.RED); + case 3 -> BuiltInRegistries.CAT_VARIANT.get(CatVariant.SIAMESE); + case 4 -> BuiltInRegistries.CAT_VARIANT.get(CatVariant.BRITISH_SHORTHAIR); + case 5 -> BuiltInRegistries.CAT_VARIANT.get(CatVariant.CALICO); + case 6 -> BuiltInRegistries.CAT_VARIANT.get(CatVariant.PERSIAN); + case 7 -> BuiltInRegistries.CAT_VARIANT.get(CatVariant.RAGDOLL); + case 8 -> BuiltInRegistries.CAT_VARIANT.get(CatVariant.WHITE); + case 9 -> BuiltInRegistries.CAT_VARIANT.get(CatVariant.JELLIE); +// case 10 -> BuiltInRegistries.CAT_VARIANT.get(CatVariant.ALL_BLACK); + default -> BuiltInRegistries.CAT_VARIANT.get(CatVariant.ALL_BLACK); + }; + } +} diff --git a/src/main/java/cuteneko/catsplus/data/ICatBag.java b/src/main/java/cuteneko/catsplus/data/ICatBag.java deleted file mode 100644 index 7d46c08..0000000 --- a/src/main/java/cuteneko/catsplus/data/ICatBag.java +++ /dev/null @@ -1,6 +0,0 @@ -package cuteneko.catsplus.data; - -import cuteneko.catsplus.data.abstracted.ICatContainerItem; - -public interface ICatBag extends ICatContainerItem { -} diff --git a/src/main/java/cuteneko/catsplus/data/ICatPlayer.java b/src/main/java/cuteneko/catsplus/data/ICatPlayer.java deleted file mode 100644 index 6a5c840..0000000 --- a/src/main/java/cuteneko/catsplus/data/ICatPlayer.java +++ /dev/null @@ -1,11 +0,0 @@ -package cuteneko.catsplus.data; - -import net.minecraft.entity.passive.CatEntity; - -public interface ICatPlayer { - CatEntity getCatEntity(); - void setCatEntity(CatEntity cat); - - boolean isCat(); - void setCat(boolean cat); -} diff --git a/src/main/java/cuteneko/catsplus/data/ICatServer.java b/src/main/java/cuteneko/catsplus/data/ICatServer.java deleted file mode 100644 index c8ec77f..0000000 --- a/src/main/java/cuteneko/catsplus/data/ICatServer.java +++ /dev/null @@ -1,28 +0,0 @@ -package cuteneko.catsplus.data; - -import net.minecraft.entity.player.PlayerEntity; -import net.minecraft.item.ItemStack; -import net.minecraft.util.collection.DefaultedList; - -import java.util.Map; -import java.util.UUID; - -public interface ICatServer { - Map> getCatSpirits(); - - DefaultedList getCatSpiritsByOwner(UUID uuid); - - default DefaultedList getCatSpiritsByOwner(PlayerEntity player) { - return getCatSpiritsByOwner(player.getUuid()); - } - - void addCatSpirit(UUID uuid, ItemStack catSpirit); - - void clearCatSpirits(); - - void clearCatSpiritsByOwner(UUID uuid); - - default void clearCatSpiritsByOwner(PlayerEntity player) { - clearCatSpiritsByOwner(player.getUuid()); - } -} diff --git a/src/main/java/cuteneko/catsplus/data/ICatSpirit.java b/src/main/java/cuteneko/catsplus/data/ICatSpirit.java deleted file mode 100644 index bbbcf65..0000000 --- a/src/main/java/cuteneko/catsplus/data/ICatSpirit.java +++ /dev/null @@ -1,14 +0,0 @@ -package cuteneko.catsplus.data; - -import cuteneko.catsplus.data.abstracted.ICatContainerItem; -import net.minecraft.text.Text; - -import java.time.OffsetDateTime; - -public interface ICatSpirit extends ICatContainerItem { - OffsetDateTime getDeathTime(); - void setDeathTime(OffsetDateTime time); - - Text getDeathMessage(); - void setDeathMessage(Text message); -} diff --git a/src/main/java/cuteneko/catsplus/data/ICompoundSerializable.java b/src/main/java/cuteneko/catsplus/data/ICompoundSerializable.java new file mode 100644 index 0000000..9dc9a5c --- /dev/null +++ b/src/main/java/cuteneko/catsplus/data/ICompoundSerializable.java @@ -0,0 +1,11 @@ +package cuteneko.catsplus.data; + +import net.minecraft.core.HolderLookup; +import net.minecraft.nbt.CompoundTag; +import org.jetbrains.annotations.NotNull; + +public interface ICompoundSerializable { + @NotNull CompoundTag serializeNBT(HolderLookup.Provider registries); + + void deserializeNBT(@NotNull CompoundTag tag, HolderLookup.Provider registries); +} diff --git a/src/main/java/cuteneko/catsplus/data/IGeniusCat.java b/src/main/java/cuteneko/catsplus/data/IGeniusCat.java deleted file mode 100644 index d98ca93..0000000 --- a/src/main/java/cuteneko/catsplus/data/IGeniusCat.java +++ /dev/null @@ -1,27 +0,0 @@ -package cuteneko.catsplus.data; - -import net.minecraft.entity.player.PlayerEntity; -import net.minecraft.util.math.BlockPos; -import org.jetbrains.annotations.Nullable; - -public interface IGeniusCat { - boolean hasTotem(); - void setTotem(boolean totem); - - default boolean canRespawn() { - return hasTotem() || getLives() > 0; - } - - int getFavorability(PlayerEntity player); - void setFavorability(int favorability, PlayerEntity player); - - default void addFavorability(int value, PlayerEntity player) { - setFavorability(getFavorability(player) + value, player); - } - default void subFavorability(int value, PlayerEntity player) { - setFavorability(getFavorability(player) - value, player); - } - - int getLives(); // Todo: qyl27: Give it a purpose? - void setLives(int lives); -} diff --git a/src/main/java/cuteneko/catsplus/data/abstracted/ICatContainerItem.java b/src/main/java/cuteneko/catsplus/data/abstracted/ICatContainerItem.java deleted file mode 100644 index 6c23a94..0000000 --- a/src/main/java/cuteneko/catsplus/data/abstracted/ICatContainerItem.java +++ /dev/null @@ -1,15 +0,0 @@ -package cuteneko.catsplus.data.abstracted; - -import net.minecraft.entity.passive.CatEntity; -import net.minecraft.text.Text; -import net.minecraft.world.World; - -public interface ICatContainerItem { - boolean hasCat(); - CatEntity getCat(World world); - void setCat(CatEntity cat); - void clearCat(); - - boolean hasCustomCatName(); - Text getCustomCatName(); -} diff --git a/src/main/java/cuteneko/catsplus/data/component/CatContainer.java b/src/main/java/cuteneko/catsplus/data/component/CatContainer.java new file mode 100644 index 0000000..1931a78 --- /dev/null +++ b/src/main/java/cuteneko/catsplus/data/component/CatContainer.java @@ -0,0 +1,41 @@ +package cuteneko.catsplus.data.component; + +import com.mojang.serialization.Codec; +import com.mojang.serialization.codecs.RecordCodecBuilder; +import net.minecraft.nbt.CompoundTag; +import net.minecraft.network.RegistryFriendlyByteBuf; +import net.minecraft.network.chat.Component; +import net.minecraft.network.chat.ComponentSerialization; +import net.minecraft.network.codec.ByteBufCodecs; +import net.minecraft.network.codec.StreamCodec; +import net.minecraft.world.entity.EntityType; +import net.minecraft.world.entity.animal.Cat; +import net.minecraft.world.level.Level; + +public record CatContainer(CompoundTag data, String variant, boolean hasCustomName, Component customName) { + public static final Codec CODEC = RecordCodecBuilder.create(instance -> + instance.group( + CompoundTag.CODEC.fieldOf("cat").forGetter(CatContainer::data), + Codec.STRING.fieldOf("variant").forGetter(CatContainer::variant), + Codec.BOOL.fieldOf("hasCustomName").forGetter(CatContainer::hasCustomName), + ComponentSerialization.CODEC.fieldOf("customName").forGetter(CatContainer::customName) + ).apply(instance, CatContainer::new)); + + public static final StreamCodec STREAM_CODEC = StreamCodec.composite( + ByteBufCodecs.COMPOUND_TAG, CatContainer::data, + ByteBufCodecs.STRING_UTF8, CatContainer::variant, + ByteBufCodecs.BOOL, CatContainer::hasCustomName, + ComponentSerialization.STREAM_CODEC, CatContainer::customName, + CatContainer::new); + + public CatContainer(Cat cat) { + this(cat.saveWithoutId(new CompoundTag()), cat.getVariant().getRegisteredName(), cat.hasCustomName(), cat.hasCustomName() ? cat.getCustomName() : Component.empty()); + } + + public Cat createCat(Level level) { + var cat = EntityType.CAT.create(level); + assert cat != null; + cat.load(data); + return cat; + } +} diff --git a/src/main/java/cuteneko/catsplus/data/component/ModComponents.java b/src/main/java/cuteneko/catsplus/data/component/ModComponents.java new file mode 100644 index 0000000..5c7a61e --- /dev/null +++ b/src/main/java/cuteneko/catsplus/data/component/ModComponents.java @@ -0,0 +1,21 @@ +package cuteneko.catsplus.data.component; + +import cuteneko.catsplus.CatsPlus; +import dev.architectury.registry.registries.DeferredRegister; +import dev.architectury.registry.registries.DeferredSupplier; +import net.minecraft.core.component.DataComponentType; +import net.minecraft.core.registries.Registries; + +public class ModComponents { + private static final DeferredRegister> REGISTRY = DeferredRegister.create(CatsPlus.MODID, Registries.DATA_COMPONENT_TYPE); + + public static void register() { + REGISTRY.register(); + } + + public static final DeferredSupplier> CAT_CONTAINER = REGISTRY.register("cat_container", + () -> DataComponentType.builder() + .persistent(CatContainer.CODEC) + .networkSynchronized(CatContainer.STREAM_CODEC) + .build()); +} diff --git a/src/main/java/cuteneko/catsplus/data/entity/GeniusCat.java b/src/main/java/cuteneko/catsplus/data/entity/GeniusCat.java new file mode 100644 index 0000000..f07f165 --- /dev/null +++ b/src/main/java/cuteneko/catsplus/data/entity/GeniusCat.java @@ -0,0 +1,72 @@ +package cuteneko.catsplus.data.entity; + +import cuteneko.catsplus.data.ICompoundSerializable; +import net.minecraft.core.HolderLookup; +import net.minecraft.nbt.CompoundTag; +import net.minecraft.world.entity.player.Player; +import org.jetbrains.annotations.NotNull; + +import java.util.HashMap; +import java.util.Map; +import java.util.UUID; + +public class GeniusCat implements ICompoundSerializable { + private boolean undyingTotem = false; + + public boolean hasTotem() { + return undyingTotem; + } + + public void setTotem(boolean totem) { + this.undyingTotem = totem; + } + + // Cat's intimacies with player, [-100, 100] + private final Map intimacies = new HashMap<>(); + + public Integer getIntimacyWith(Player player) { + return intimacies.putIfAbsent(player.getUUID(), 0); + } + + public void setIntimacyWith(Player player, int value) { + intimacies.put(player.getUUID(), value); + } + + public void addIntimacyWith(Player player, int value) { + setIntimacyWith(player, getIntimacyWith(player) + value); + } + + public void subIntimacyWith(Player player, int value) { + setIntimacyWith(player, getIntimacyWith(player) - value); + } + + @Override + public @NotNull CompoundTag serializeNBT(HolderLookup.Provider registries) { + var tag = new CompoundTag(); + tag.putBoolean("undyingTotem", hasTotem()); + + var intimaciesTag = new CompoundTag(); + for (var entry : this.intimacies.entrySet()) { + intimaciesTag.putInt(entry.getKey().toString(), entry.getValue()); + } + tag.put("intimacies", intimaciesTag); + + return tag; + } + + @Override + public void deserializeNBT(@NotNull CompoundTag tag, HolderLookup.Provider registries) { + if (tag.contains("undyingTotem")) { + setTotem(tag.getBoolean("undyingTotem")); + } + + if (tag.contains("intimacies")) { + var intimaciesTag = tag.getCompound("intimaciesTag"); + for (var e : intimaciesTag.getAllKeys()) { + var uuid = UUID.fromString(e); + var v = intimaciesTag.getInt(e); + this.intimacies.put(uuid, v); + } + } + } +} diff --git a/src/main/java/cuteneko/catsplus/data/entity/MusicianCat.java b/src/main/java/cuteneko/catsplus/data/entity/MusicianCat.java new file mode 100644 index 0000000..9d8848a --- /dev/null +++ b/src/main/java/cuteneko/catsplus/data/entity/MusicianCat.java @@ -0,0 +1,34 @@ +package cuteneko.catsplus.data.entity; + +import cuteneko.catsplus.data.ICompoundSerializable; +import cuteneko.catsplus.utility.TagHelper; +import net.minecraft.core.BlockPos; +import net.minecraft.core.HolderLookup; +import net.minecraft.nbt.CompoundTag; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +public class MusicianCat implements ICompoundSerializable { + @Nullable + + + public void setSoundSource(@Nullable BlockPos pos) { + this.soundSource = pos; + } + + public @Nullable BlockPos getSoundSource() { + return soundSource; + } + + @Override + public @NotNull CompoundTag serializeNBT(HolderLookup.Provider registries) { + var tag = new CompoundTag(); + tag.put("soundSource", TagHelper.saveBlockPos(getSoundSource())); + return tag; + } + + @Override + public void deserializeNBT(@NotNull CompoundTag tag, HolderLookup.Provider registries) { + setSoundSource(TagHelper.loadBlockPos(tag)); + } +} diff --git a/src/main/java/cuteneko/catsplus/data/impl/CatBag.java b/src/main/java/cuteneko/catsplus/data/impl/CatBag.java deleted file mode 100644 index 245de28..0000000 --- a/src/main/java/cuteneko/catsplus/data/impl/CatBag.java +++ /dev/null @@ -1,12 +0,0 @@ -package cuteneko.catsplus.data.impl; - -import cuteneko.catsplus.data.ICatBag; -import cuteneko.catsplus.utility.Constants; -import net.minecraft.item.ItemStack; -import net.minecraft.text.Text; - -public class CatBag extends CatContainer implements ICatBag { - public CatBag(ItemStack stack) { - super(stack); - } -} diff --git a/src/main/java/cuteneko/catsplus/data/impl/CatContainer.java b/src/main/java/cuteneko/catsplus/data/impl/CatContainer.java deleted file mode 100644 index a027367..0000000 --- a/src/main/java/cuteneko/catsplus/data/impl/CatContainer.java +++ /dev/null @@ -1,82 +0,0 @@ -package cuteneko.catsplus.data.impl; - -import cuteneko.catsplus.data.abstracted.ICatContainerItem; -import cuteneko.catsplus.utility.Constants; -import net.minecraft.entity.EntityType; -import net.minecraft.entity.passive.CatEntity; -import net.minecraft.item.ItemStack; -import net.minecraft.nbt.NbtCompound; -import net.minecraft.text.Text; -import net.minecraft.world.World; - -public abstract class CatContainer implements ICatContainerItem { - protected ItemStack stack; - - public CatContainer(ItemStack stack) { - this.stack = stack; - } - - @Override - public boolean hasCat() { - var tag = stack.getNbt(); - if (tag != null) { - var compoundCat = tag.get(Constants.TAG_CAT_CONTAINER); - return compoundCat != null; - } - return false; - } - - @Override - public CatEntity getCat(World world) { - var tag = stack.getNbt(); - if (tag != null) { - var compoundCat = tag.getCompound(Constants.TAG_CAT_CONTAINER); - var optionalEntity = EntityType.getEntityFromNbt(compoundCat, world); - if (optionalEntity.isPresent() && optionalEntity.get() instanceof CatEntity cat) { - cat.readNbt(compoundCat); - return cat; - } - } - - return null; - } - - @Override - public void setCat(CatEntity cat) { - var compoundCat = new NbtCompound(); - cat.saveNbt(compoundCat); - var tag = stack.getOrCreateNbt(); - tag.put(Constants.TAG_CAT_CONTAINER, compoundCat); - stack.setNbt(tag); - } - - @Override - public void clearCat() { - var tag = stack.getOrCreateNbt(); - tag.remove(Constants.TAG_CAT_CONTAINER); - stack.setNbt(tag); - } - - @Override - public boolean hasCustomCatName() { - var tag = stack.getNbt(); - if (tag != null) { - var compoundCat = tag.getCompound(Constants.TAG_CAT_CONTAINER); - return compoundCat != null && compoundCat.contains(Constants.TAG_CUSTOM_NAME); - } - return false; - } - - @Override - public Text getCustomCatName() { - var tag = stack.getNbt(); - if (tag != null) { - var compoundCat = tag.getCompound(Constants.TAG_CAT_CONTAINER); - if (compoundCat != null) { - var name = compoundCat.getString(Constants.TAG_CUSTOM_NAME); - return Text.Serialization.fromJson(name); - } - } - return null; - } -} diff --git a/src/main/java/cuteneko/catsplus/data/impl/CatServer.java b/src/main/java/cuteneko/catsplus/data/impl/CatServer.java deleted file mode 100644 index 7e06d43..0000000 --- a/src/main/java/cuteneko/catsplus/data/impl/CatServer.java +++ /dev/null @@ -1,86 +0,0 @@ -package cuteneko.catsplus.data.impl; - -import com.google.common.collect.ImmutableMap; -import cuteneko.catsplus.data.ICatServer; -import cuteneko.catsplus.utility.Constants; -import net.minecraft.inventory.Inventories; -import net.minecraft.item.ItemStack; -import net.minecraft.nbt.NbtCompound; -import net.minecraft.nbt.NbtElement; -import net.minecraft.nbt.NbtList; -import net.minecraft.util.collection.DefaultedList; -import net.minecraft.world.PersistentState; - -import java.util.HashMap; -import java.util.Map; -import java.util.UUID; - -public class CatServer extends PersistentState implements ICatServer { - - // Todo: qyl27: DataFixerUpper. - public static final Type TYPE = new Type<>(CatServer::new, CatServer::loadFromNbt, null); - - private final Map> catSpirits = new HashMap<>(); - - @Override - public Map> getCatSpirits() { - return ImmutableMap.>builder().putAll(catSpirits).build(); - } - - @Override - public DefaultedList getCatSpiritsByOwner(UUID uuid) { - if (!catSpirits.containsKey(uuid)) { - catSpirits.put(uuid, DefaultedList.of()); - } - - return catSpirits.get(uuid); - } - - @Override - public void addCatSpirit(UUID uuid, ItemStack catSpirit) { - if (uuid == null) { - return; - } - - var list = getCatSpiritsByOwner(uuid); - list.add(catSpirit); - } - - @Override - public void clearCatSpirits() { - catSpirits.clear(); - } - - @Override - public void clearCatSpiritsByOwner(UUID uuid) { - getCatSpiritsByOwner(uuid).clear(); - } - - @Override - public NbtCompound writeNbt(NbtCompound nbt) { - var list = new NbtList(); - for (var entry : getCatSpirits().entrySet()) { - var e = new NbtCompound(); - e.putUuid(Constants.TAG_UUID, entry.getKey()); - e.put(Constants.TAG_VALUE, Inventories.writeNbt(new NbtCompound(), entry.getValue())); - } - nbt.put(Constants.TAG_SERVER_CAT_SPIRITS, list); - return nbt; - } - - public static CatServer loadFromNbt(NbtCompound nbt) { - var result = new CatServer(); - - var spirits = nbt.getList(Constants.TAG_SERVER_CAT_SPIRITS, NbtElement.COMPOUND_TYPE); - for (var spirit : spirits) { - if (spirit instanceof NbtCompound compound) { - var uuid = compound.getUuid(Constants.TAG_UUID); - var value = DefaultedList.of(); - Inventories.readNbt(compound.getCompound(Constants.TAG_VALUE), value); - result.catSpirits.put(uuid, value); - } - } - - return result; - } -} diff --git a/src/main/java/cuteneko/catsplus/data/impl/CatSpirit.java b/src/main/java/cuteneko/catsplus/data/impl/CatSpirit.java deleted file mode 100644 index 27eaedd..0000000 --- a/src/main/java/cuteneko/catsplus/data/impl/CatSpirit.java +++ /dev/null @@ -1,52 +0,0 @@ -package cuteneko.catsplus.data.impl; - -import cuteneko.catsplus.data.ICatSpirit; -import cuteneko.catsplus.utility.Constants; -import net.minecraft.item.ItemStack; -import net.minecraft.text.Text; - -import java.time.OffsetDateTime; - -public class CatSpirit extends CatContainer implements ICatSpirit { - public CatSpirit(ItemStack stack) { - super(stack); - } - - @Override - public OffsetDateTime getDeathTime() { - var tag = stack.getNbt(); - if (tag != null) { - var deathAt = tag.getString(Constants.TAG_DEATH_TIME); - if (!deathAt.isBlank()) { - return OffsetDateTime.parse(deathAt); - } - } - return null; - } - - @Override - public void setDeathTime(OffsetDateTime time) { - var tag = stack.getOrCreateNbt(); - tag.putString(Constants.TAG_DEATH_TIME, time.toString()); - stack.setNbt(tag); - } - - @Override - public Text getDeathMessage() { - var tag = stack.getNbt(); - if (tag != null) { - var deathMsg = tag.getString(Constants.TAG_DEATH_MESSAGE); - if (!deathMsg.isBlank()) { - return Text.Serialization.fromJson(deathMsg); - } - } - return Text.empty(); - } - - @Override - public void setDeathMessage(Text message) { - var tag = stack.getOrCreateNbt(); - tag.putString(Constants.TAG_DEATH_MESSAGE, Text.Serialization.toJsonString(message)); - stack.setNbt(tag); - } -} diff --git a/src/main/java/cuteneko/catsplus/data/level/LevelWithCats.java b/src/main/java/cuteneko/catsplus/data/level/LevelWithCats.java new file mode 100644 index 0000000..ad968d9 --- /dev/null +++ b/src/main/java/cuteneko/catsplus/data/level/LevelWithCats.java @@ -0,0 +1,91 @@ +package cuteneko.catsplus.data.level; + +import cuteneko.catsplus.utility.Constants; +import net.minecraft.core.HolderLookup; +import net.minecraft.core.NonNullList; +import net.minecraft.nbt.CompoundTag; +import net.minecraft.nbt.ListTag; +import net.minecraft.nbt.Tag; +import net.minecraft.server.level.ServerLevel; +import net.minecraft.world.ContainerHelper; +import net.minecraft.world.entity.player.Player; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.level.saveddata.SavedData; +import org.jetbrains.annotations.NotNull; + +import java.util.HashMap; +import java.util.Map; +import java.util.UUID; + +public class LevelWithCats extends SavedData { + + // Todo: qyl27: DataFixerUpper. + private static final Factory FACTORY = new Factory<>(LevelWithCats::new, LevelWithCats::load, null); + + public static LevelWithCats getLevelWithCats(ServerLevel level) { + return level.getDataStorage().get(FACTORY, "cats_plus"); + } + + private final Map> catSpirits = new HashMap<>(); + + private NonNullList getCatSpirits(UUID uuid) { + if (!catSpirits.containsKey(uuid)) { + catSpirits.put(uuid, NonNullList.create()); + setDirty(); + } + + return catSpirits.get(uuid); + } + + public void addCatSpirit(Player player, ItemStack catSpirit) { + var list = getCatSpiritsByOwner(player); + list.add(catSpirit); + setDirty(); + } + + public NonNullList getCatSpiritsByOwner(Player player) { + return getCatSpirits(player.getUUID()); + } + + public void removeCatSpiritsByOwner(Player player) { + catSpirits.remove(player.getUUID()); + setDirty(); + } + + public void clearCatSpirits() { + catSpirits.clear(); + setDirty(); + } + + public LevelWithCats create() { + return new LevelWithCats(); + } + + public static LevelWithCats load(CompoundTag tag, HolderLookup.Provider registries) { + LevelWithCats data = new LevelWithCats(); + + var spirits = tag.getList(Constants.TAG_SERVER_CAT_SPIRITS, Tag.TAG_COMPOUND); + for (var spirit : spirits) { + if (spirit instanceof CompoundTag compound) { + var uuid = compound.getUUID(Constants.TAG_UUID); + var value = NonNullList.create(); + ContainerHelper.loadAllItems(compound.getCompound(Constants.TAG_VALUE), value, registries); + data.catSpirits.put(uuid, value); + } + } + + return data; + } + + @Override + public @NotNull CompoundTag save(CompoundTag tag, HolderLookup.Provider registries) { + var list = new ListTag(); + for (var entry : catSpirits.entrySet()) { + var e = new CompoundTag(); + e.putUUID(Constants.TAG_UUID, entry.getKey()); + e.put(Constants.TAG_VALUE, ContainerHelper.saveAllItems(new CompoundTag(), entry.getValue(), registries)); + } + tag.put(Constants.TAG_SERVER_CAT_SPIRITS, list); + return tag; + } +} diff --git a/src/main/java/cuteneko/catsplus/effect/CattifyEffect.java b/src/main/java/cuteneko/catsplus/effect/CattifyEffect.java index 110d1a0..d94c712 100644 --- a/src/main/java/cuteneko/catsplus/effect/CattifyEffect.java +++ b/src/main/java/cuteneko/catsplus/effect/CattifyEffect.java @@ -1,32 +1,33 @@ package cuteneko.catsplus.effect; -import net.minecraft.entity.LivingEntity; -import net.minecraft.entity.effect.StatusEffect; -import net.minecraft.entity.effect.StatusEffectCategory; -import net.minecraft.entity.effect.StatusEffectInstance; -import net.minecraft.entity.effect.StatusEffects; -import net.minecraft.entity.passive.CatEntity; +import net.minecraft.world.effect.MobEffect; +import net.minecraft.world.effect.MobEffectCategory; +import net.minecraft.world.entity.LivingEntity; +import net.minecraft.world.entity.animal.Cat; -public class CattifyEffect extends StatusEffect { +public class CattifyEffect extends MobEffect { public CattifyEffect() { - super(StatusEffectCategory.NEUTRAL, 0xFF9CA8); + super(MobEffectCategory.NEUTRAL, 0xFF9CA8); } - @Override - public boolean canApplyUpdateEffect(int duration, int amplifier) { - return true; - } - - @Override - public void applyUpdateEffect(LivingEntity entity, int amplifier) { - if(!(entity instanceof CatEntity cat)) { - return; - } + // Todo: qyl27: use attribute to implement + // Max Health base value to 10 + // Attack damage base value to 2.5 + // Width 0.6 + // Height 0.7 + // No falling damage + // Can see invisible mobs - var effect = cat.getStatusEffect(this); - assert effect != null; - var duration = effect.getDuration(); - cat.removeStatusEffect(this); - cat.addStatusEffect(new StatusEffectInstance(StatusEffects.REGENERATION, duration, 0)); - } +// @Override +// public boolean applyEffectTick(LivingEntity entity, int amplifier) { +// if(!(entity instanceof Cat cat)) { +// return false; +// } +// +// var effect = cat.getStatusEffect(this); +// assert effect != null; +// var duration = effect.getDuration(); +// cat.removeStatusEffect(this); +// cat.addStatusEffect(new StatusEffectInstance(StatusEffects.REGENERATION, duration, 0)); +// } } diff --git a/src/main/java/cuteneko/catsplus/effect/ModEffects.java b/src/main/java/cuteneko/catsplus/effect/ModEffects.java index 7c6ea7b..cb5e561 100644 --- a/src/main/java/cuteneko/catsplus/effect/ModEffects.java +++ b/src/main/java/cuteneko/catsplus/effect/ModEffects.java @@ -3,15 +3,15 @@ import cuteneko.catsplus.CatsPlus; import dev.architectury.registry.registries.DeferredRegister; import dev.architectury.registry.registries.RegistrySupplier; -import net.minecraft.entity.effect.StatusEffect; -import net.minecraft.registry.RegistryKeys; +import net.minecraft.core.registries.Registries; +import net.minecraft.world.effect.MobEffect; public class ModEffects { - public static final DeferredRegister EFFECTS = DeferredRegister.create(CatsPlus.MODID, RegistryKeys.STATUS_EFFECT); + public static final DeferredRegister REGISTRY = DeferredRegister.create(CatsPlus.MODID, Registries.MOB_EFFECT); public static void register() { - EFFECTS.register(); + REGISTRY.register(); } - public static final RegistrySupplier CATTIFY = EFFECTS.register("cattify", CattifyEffect::new); + public static final RegistrySupplier CATTIFY = REGISTRY.register("cattify", CattifyEffect::new); } diff --git a/src/main/java/cuteneko/catsplus/effect/potion/ModPotions.java b/src/main/java/cuteneko/catsplus/effect/potion/ModPotions.java index 28de6ae..8c7da6e 100644 --- a/src/main/java/cuteneko/catsplus/effect/potion/ModPotions.java +++ b/src/main/java/cuteneko/catsplus/effect/potion/ModPotions.java @@ -4,17 +4,17 @@ import cuteneko.catsplus.effect.ModEffects; import dev.architectury.registry.registries.DeferredRegister; import dev.architectury.registry.registries.RegistrySupplier; -import net.minecraft.entity.effect.StatusEffectInstance; -import net.minecraft.potion.Potion; -import net.minecraft.registry.RegistryKeys; +import net.minecraft.core.registries.Registries; +import net.minecraft.world.effect.MobEffectInstance; +import net.minecraft.world.item.alchemy.Potion; public class ModPotions { - public static final DeferredRegister POTIONS = DeferredRegister.create(CatsPlus.MODID, RegistryKeys.POTION); + public static final DeferredRegister REGISTRY = DeferredRegister.create(CatsPlus.MODID, Registries.POTION); public static void register() { - POTIONS.register(); + REGISTRY.register(); } - public static final RegistrySupplier CATTIFY = POTIONS.register("cattify", () -> new Potion(new StatusEffectInstance(ModEffects.CATTIFY.get(), 1800))); - public static final RegistrySupplier LONG_CATTIFY = POTIONS.register("long_cattify", () -> new Potion("cattify", new StatusEffectInstance(ModEffects.CATTIFY.get(), 4800))); + public static final RegistrySupplier CATTIFY = REGISTRY.register("cattify", () -> new Potion(new MobEffectInstance(ModEffects.CATTIFY.get(), 1800))); + public static final RegistrySupplier LONG_CATTIFY = REGISTRY.register("long_cattify", () -> new Potion("cattify", new MobEffectInstance(ModEffects.CATTIFY.get(), 4800))); } diff --git a/src/main/java/cuteneko/catsplus/item/CatBagItem.java b/src/main/java/cuteneko/catsplus/item/CatBagItem.java index 1d5c162..fcc9276 100644 --- a/src/main/java/cuteneko/catsplus/item/CatBagItem.java +++ b/src/main/java/cuteneko/catsplus/item/CatBagItem.java @@ -1,114 +1,120 @@ package cuteneko.catsplus.item; -import cuteneko.catsplus.CatsPlusData; +import cuteneko.catsplus.data.component.CatContainer; +import cuteneko.catsplus.data.component.ModComponents; import cuteneko.catsplus.item.group.ModItemGroups; +import cuteneko.catsplus.utility.ComponentHelper; import cuteneko.catsplus.utility.Constants; -import net.minecraft.client.item.TooltipContext; -import net.minecraft.entity.EntityType; -import net.minecraft.entity.LivingEntity; -import net.minecraft.entity.SpawnReason; -import net.minecraft.entity.passive.CatEntity; -import net.minecraft.entity.player.PlayerEntity; -import net.minecraft.item.DyeableItem; -import net.minecraft.item.Item; -import net.minecraft.item.ItemStack; -import net.minecraft.item.ItemUsageContext; -import net.minecraft.nbt.NbtCompound; -import net.minecraft.nbt.NbtDouble; -import net.minecraft.nbt.NbtList; -import net.minecraft.server.world.ServerWorld; -import net.minecraft.text.Text; -import net.minecraft.util.ActionResult; -import net.minecraft.util.Formatting; -import net.minecraft.util.Hand; -import net.minecraft.util.math.BlockPos; -import net.minecraft.util.math.Direction; -import net.minecraft.util.math.Vec3d; -import net.minecraft.world.World; -import net.minecraft.world.event.GameEvent; -import org.jetbrains.annotations.Nullable; +import net.minecraft.ChatFormatting; +import net.minecraft.core.component.DataComponents; +import net.minecraft.network.chat.Component; +import net.minecraft.server.level.ServerLevel; +import net.minecraft.world.InteractionHand; +import net.minecraft.world.InteractionResult; +import net.minecraft.world.entity.LivingEntity; +import net.minecraft.world.entity.animal.Cat; +import net.minecraft.world.entity.player.Player; +import net.minecraft.world.item.Item; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.item.TooltipFlag; +import net.minecraft.world.item.component.DyedItemColor; +import net.minecraft.world.item.context.UseOnContext; +import net.minecraft.world.level.gameevent.GameEvent; +import org.jetbrains.annotations.NotNull; import java.util.List; -import java.util.Objects; -public class CatBagItem extends Item implements DyeableItem { +public class CatBagItem extends Item { public CatBagItem() { - super(new Item.Settings() - .fireproof() - .maxCount(1) + super(new Item.Properties() + .fireResistant() + .stacksTo(1) + .component(DataComponents.DYED_COLOR, new DyedItemColor(DyedItemColor.LEATHER_COLOR, false)) + .component(ModComponents.CAT_CONTAINER.get(), null) .arch$tab(ModItemGroups.CATS_PLUS)); } @Override - public void appendTooltip(ItemStack stack, @Nullable World world, List tooltip, TooltipContext context) { - if (!stack.hasNbt() || !Objects.requireNonNull(stack.getNbt()).contains(Constants.TAG_CAT_CONTAINER)) { - tooltip.add(Text.translatable(Constants.MESSAGE_CAT_BAG_DESCRIPTION_NO_CAT).formatted(Formatting.DARK_GRAY)); + public void appendHoverText(ItemStack stack, TooltipContext context, List tooltip, TooltipFlag tooltipFlag) { + var catContainer = ComponentHelper.getCatContainer(stack); + if (catContainer == null) { + tooltip.add(Component.translatable(Constants.MESSAGE_CAT_BAG_DESCRIPTION_NO_CAT).withStyle(ChatFormatting.DARK_GRAY)); return; } - var bag = CatsPlusData.getCatBag(stack); - if (bag.hasCustomCatName()) { - tooltip.add(Text.translatable(Constants.MESSAGE_CAT_BAG_DESCRIPTION_HAS_NAMED_CAT, bag.getCustomCatName().getString()).formatted(Formatting.BLUE)); + if (catContainer.hasCustomName()) { + tooltip.add(Component.translatable(Constants.MESSAGE_CAT_BAG_DESCRIPTION_HAS_NAMED_CAT, catContainer.customName().getString()).withStyle(ChatFormatting.BLUE)); } else { - tooltip.add(Text.translatable(Constants.MESSAGE_CAT_BAG_DESCRIPTION_HAS_CAT).formatted(Formatting.BLUE)); + tooltip.add(Component.translatable(Constants.MESSAGE_CAT_BAG_DESCRIPTION_HAS_CAT).withStyle(ChatFormatting.BLUE)); } } @Override - public ActionResult useOnBlock(ItemUsageContext context) { - var stack = context.getStack(); - - if (stack.hasCustomName()) { - var name = stack.getName().getString(); - if ("MeowBot233".equalsIgnoreCase(name) - || "Fang_Luo".equalsIgnoreCase(name) - || "坊洛".equalsIgnoreCase(name)) { - stack.removeCustomName(); - Objects.requireNonNull(context.getPlayer()).giveItemStack(new ItemStack(ModItems.FANG_LUO)); - return ActionResult.SUCCESS; + public @NotNull InteractionResult useOn(UseOnContext context) { + var stack = context.getItemInHand(); + var name = ComponentHelper.getCustomName(stack); + var player = context.getPlayer(); + if (player == null) { + return InteractionResult.PASS; + } + + if (name != null) { + var str = name.getString(); + if ("MeowBot233".equalsIgnoreCase(str) + || "Fang_Luo".equalsIgnoreCase(str) + || "坊洛".equalsIgnoreCase(str)) { + ComponentHelper.removeCustomName(stack); + player.addItem(new ItemStack(ModItems.FANG_LUO)); + return InteractionResult.SUCCESS; } } - var bag = CatsPlusData.getCatBag(stack); - if (!bag.hasCat()) { - return ActionResult.PASS; + var catContainer = ComponentHelper.getCatContainer(stack); + if (catContainer == null) { + return InteractionResult.PASS; } - Direction direction = context.getSide(); - var world = context.getWorld(); - var player = context.getPlayer(); - var pos = context.getBlockPos().offset(direction).toCenterPos(); + var direction = context.getClickedFace(); + var level = context.getLevel(); + var spawnPos = context.getClickedPos().relative(direction); + if (!level.isLoaded(spawnPos) || !level.getBlockState(spawnPos).isAir()) { + // Todo: Fail particle. + return InteractionResult.FAIL; + } - if (world instanceof ServerWorld) { - var cat = bag.getCat(world); - cat.setPosition(pos); - world.spawnEntity(cat); - world.emitGameEvent(player, GameEvent.ENTITY_PLACE, pos); + if (level instanceof ServerLevel) { + var cat = catContainer.createCat(level); + cat.setPos(spawnPos.getBottomCenter()); + cat.setOrderedToSit(true); + level.addFreshEntity(cat); + level.gameEvent(player, GameEvent.ENTITY_PLACE, spawnPos); } - bag.clearCat(); - Objects.requireNonNull(context.getPlayer()).setStackInHand(context.getHand(), stack); - return ActionResult.SUCCESS; + ComponentHelper.removeCatContainer(stack); + return InteractionResult.SUCCESS; } @Override - public ActionResult useOnEntity(ItemStack stack, PlayerEntity user, LivingEntity entity, Hand hand) { - if (entity instanceof CatEntity cat) { - var bag = CatsPlusData.getCatBag(stack); - if (!bag.hasCat()) { - if (cat.isOwner(user)) { - cat.setSitting(false); - bag.setCat(cat); - cat.discard(); - user.setStackInHand(hand, stack); - return ActionResult.SUCCESS; - } else { - return ActionResult.FAIL; - } + public @NotNull InteractionResult interactLivingEntity(ItemStack stack, Player player, LivingEntity entity, + InteractionHand usedHand) { + if (ComponentHelper.getCatContainer(stack) != null) { + return InteractionResult.PASS; + } + + if (entity instanceof Cat cat) { + if (!cat.isOwnedBy(player)) { + // Todo: Fail particle. + return InteractionResult.FAIL; } + + cat.setOrderedToSit(true); + var catContainer = new CatContainer(cat); + ComponentHelper.setCatContainer(stack, catContainer); + cat.discard(); + return InteractionResult.SUCCESS; } - return ActionResult.PASS; + return InteractionResult.PASS; } } diff --git a/src/main/java/cuteneko/catsplus/item/CatSpiritItem.java b/src/main/java/cuteneko/catsplus/item/CatSpiritItem.java index 99de6df..c2c5f62 100644 --- a/src/main/java/cuteneko/catsplus/item/CatSpiritItem.java +++ b/src/main/java/cuteneko/catsplus/item/CatSpiritItem.java @@ -2,30 +2,31 @@ import cuteneko.catsplus.CatsPlusData; import cuteneko.catsplus.item.group.ModItemGroups; +import cuteneko.catsplus.utility.ComponentHelper; import cuteneko.catsplus.utility.Constants; -import net.minecraft.item.Item; -import net.minecraft.item.ItemStack; -import net.minecraft.text.Text; -import net.minecraft.util.Rarity; +import net.minecraft.network.chat.Component; +import net.minecraft.world.item.Item; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.item.Rarity; +import org.jetbrains.annotations.NotNull; public class CatSpiritItem extends Item { public CatSpiritItem() { - super(new Item.Settings() - .maxCount(1) - .fireproof() + super(new Item.Properties() + .stacksTo(1) + .fireResistant() .rarity(Rarity.EPIC) .arch$tab(ModItemGroups.CATS_PLUS)); } @Override - public Text getName(ItemStack stack) { - var spirit = CatsPlusData.getCatSpirit(stack); - if (spirit.hasCat()) { - if (spirit.hasCustomCatName()) { - return Text.translatable(Constants.MESSAGE_CAT_SPIRIT_NAME, spirit.getCustomCatName().getString()); + public @NotNull Component getName(ItemStack stack) { + var catContainer = ComponentHelper.getCatContainer(stack); + if (catContainer != null) { + if (catContainer.hasCustomName()) { + return Component.translatable(Constants.MESSAGE_CAT_SPIRIT_NAME, catContainer.customName().getString()); } } - return super.getName(stack); } } diff --git a/src/main/java/cuteneko/catsplus/item/FangLuoItem.java b/src/main/java/cuteneko/catsplus/item/FangLuoItem.java index 2557182..e035853 100644 --- a/src/main/java/cuteneko/catsplus/item/FangLuoItem.java +++ b/src/main/java/cuteneko/catsplus/item/FangLuoItem.java @@ -1,30 +1,27 @@ package cuteneko.catsplus.item; import cuteneko.catsplus.utility.Constants; -import net.minecraft.client.item.TooltipContext; -import net.minecraft.item.Item; -import net.minecraft.item.ItemStack; -import net.minecraft.text.Text; -import net.minecraft.util.Formatting; -import net.minecraft.util.Rarity; -import net.minecraft.world.World; -import org.jetbrains.annotations.Nullable; +import net.minecraft.ChatFormatting; +import net.minecraft.network.chat.Component; +import net.minecraft.world.item.Item; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.item.Rarity; +import net.minecraft.world.item.TooltipFlag; import java.util.List; public class FangLuoItem extends Item { public FangLuoItem() { - super(new Item.Settings() - .maxCount(1) - .fireproof() - .rarity(Rarity.EPIC)); + super(new Item.Properties() + .fireResistant() + .rarity(Rarity.UNCOMMON)); } @Override - public void appendTooltip(ItemStack stack, @Nullable World world, List tooltip, TooltipContext context) { - super.appendTooltip(stack, world, tooltip, context); + public void appendHoverText(ItemStack stack, TooltipContext context, List tooltip, TooltipFlag tooltipFlag) { + super.appendHoverText(stack, context, tooltip, tooltipFlag); - tooltip.add(Text.translatable(Constants.MESSAGE_FANG_LUO_DESCRIPTION_1).formatted(Formatting.GRAY)); - tooltip.add(Text.translatable(Constants.MESSAGE_FANG_LUO_DESCRIPTION_2).formatted(Formatting.GRAY)); + tooltip.add(Component.translatable(Constants.MESSAGE_FANG_LUO_DESCRIPTION_1).withStyle(ChatFormatting.GRAY)); + tooltip.add(Component.translatable(Constants.MESSAGE_FANG_LUO_DESCRIPTION_2).withStyle(ChatFormatting.GRAY)); } } diff --git a/src/main/java/cuteneko/catsplus/item/ModItems.java b/src/main/java/cuteneko/catsplus/item/ModItems.java index 2820f1d..0a401e2 100644 --- a/src/main/java/cuteneko/catsplus/item/ModItems.java +++ b/src/main/java/cuteneko/catsplus/item/ModItems.java @@ -4,19 +4,19 @@ import cuteneko.catsplus.item.group.ModItemGroups; import dev.architectury.registry.registries.DeferredRegister; import dev.architectury.registry.registries.RegistrySupplier; -import net.minecraft.item.Item; -import net.minecraft.registry.RegistryKeys; -import net.minecraft.util.Rarity; +import net.minecraft.core.registries.Registries; +import net.minecraft.world.item.Item; +import net.minecraft.world.item.Rarity; public class ModItems { - public static final DeferredRegister ITEMS = DeferredRegister.create(CatsPlus.MODID, RegistryKeys.ITEM); + public static final DeferredRegister ITEMS = DeferredRegister.create(CatsPlus.MODID, Registries.ITEM); public static void register() { ITEMS.register(); } public static final RegistrySupplier CAT_BAG = ITEMS.register("cat_bag", CatBagItem::new); - public static final RegistrySupplier TOTEMEOW = ITEMS.register("totemeow", () -> new Item(new Item.Settings().maxCount(1).rarity(Rarity.UNCOMMON).arch$tab(ModItemGroups.CATS_PLUS))); + public static final RegistrySupplier TOTEMEOW = ITEMS.register("totemeow", () -> new Item(new Item.Properties().stacksTo(1).rarity(Rarity.UNCOMMON).arch$tab(ModItemGroups.CATS_PLUS))); public static final RegistrySupplier CAT_SPIRIT = ITEMS.register("cat_spirit", CatSpiritItem::new); public static final RegistrySupplier FANG_LUO = ITEMS.register("fang_luo", FangLuoItem::new); } diff --git a/src/main/java/cuteneko/catsplus/item/group/ModItemGroups.java b/src/main/java/cuteneko/catsplus/item/group/ModItemGroups.java index 66e9467..d230c07 100644 --- a/src/main/java/cuteneko/catsplus/item/group/ModItemGroups.java +++ b/src/main/java/cuteneko/catsplus/item/group/ModItemGroups.java @@ -6,18 +6,18 @@ import dev.architectury.registry.CreativeTabRegistry; import dev.architectury.registry.registries.DeferredRegister; import dev.architectury.registry.registries.RegistrySupplier; -import net.minecraft.item.ItemGroup; -import net.minecraft.item.ItemStack; -import net.minecraft.registry.RegistryKeys; -import net.minecraft.text.Text; +import net.minecraft.core.registries.Registries; +import net.minecraft.network.chat.Component; +import net.minecraft.world.item.CreativeModeTab; +import net.minecraft.world.item.ItemStack; public class ModItemGroups { - public static final DeferredRegister GROUPS = DeferredRegister.create(CatsPlus.MODID, RegistryKeys.ITEM_GROUP); + private static final DeferredRegister REGISTRY = DeferredRegister.create(CatsPlus.MODID, Registries.CREATIVE_MODE_TAB); public static void register() { - GROUPS.register(); + REGISTRY.register(); } - public static final RegistrySupplier CATS_PLUS = GROUPS.register("catsplus_group", () -> CreativeTabRegistry.create(Text.translatable(Constants.MESSAGE_CATS_GROUP_TITLE), () -> new ItemStack(ModItems.CAT_BAG))); + public static final RegistrySupplier CATS_PLUS = REGISTRY.register("catsplus_group", () -> CreativeTabRegistry.create(Component.translatable(Constants.MESSAGE_CATS_GROUP_TITLE), () -> new ItemStack(ModItems.CAT_BAG))); } diff --git a/src/main/java/cuteneko/catsplus/listener/CatSpiritListener.java b/src/main/java/cuteneko/catsplus/listener/CatSpiritListener.java index cc04a5a..b90474d 100644 --- a/src/main/java/cuteneko/catsplus/listener/CatSpiritListener.java +++ b/src/main/java/cuteneko/catsplus/listener/CatSpiritListener.java @@ -1,23 +1,24 @@ package cuteneko.catsplus.listener; import cuteneko.catsplus.CatsPlusData; +import cuteneko.catsplus.data.level.LevelWithCats; import cuteneko.catsplus.utility.Constants; import dev.architectury.event.events.common.PlayerEvent; -import net.minecraft.server.network.ServerPlayerEntity; -import net.minecraft.text.Text; +import net.minecraft.network.chat.Component; +import net.minecraft.server.level.ServerPlayer; public class CatSpiritListener { public CatSpiritListener() { -// TickEvent.PLAYER_POST.register(this::onPlayerTick); PlayerEvent.PLAYER_JOIN.register(this::onPlayerJoin); } - private void onPlayerJoin(ServerPlayerEntity player) { - var catServer = CatsPlusData.getCatServer(player.server); - var spirits = catServer.getCatSpiritsByOwner(player); + private void onPlayerJoin(ServerPlayer player) { + var level = player.serverLevel(); + var data = LevelWithCats.getLevelWithCats(level); + var spirits = data.getCatSpiritsByOwner(player); for (var spirit : spirits) { - player.giveItemStack(spirit); - player.sendMessage(Text.translatable(Constants.MESSAGE_CAT_DIED)); + player.addItem(spirit); + player.sendSystemMessage(Component.translatable(Constants.MESSAGE_CAT_DIED)); } catServer.clearCatSpiritsByOwner(player); } diff --git a/src/main/java/cuteneko/catsplus/mixins/mixin/CatEntityMixin.java b/src/main/java/cuteneko/catsplus/mixin/CatEntityMixin.java similarity index 98% rename from src/main/java/cuteneko/catsplus/mixins/mixin/CatEntityMixin.java rename to src/main/java/cuteneko/catsplus/mixin/CatEntityMixin.java index 46dad15..ea9a4c2 100644 --- a/src/main/java/cuteneko/catsplus/mixins/mixin/CatEntityMixin.java +++ b/src/main/java/cuteneko/catsplus/mixin/CatEntityMixin.java @@ -1,4 +1,4 @@ -package cuteneko.catsplus.mixins.mixin; +package cuteneko.catsplus.mixin; import cuteneko.catsplus.CatsPlusData; import cuteneko.catsplus.item.ModItems; diff --git a/src/main/java/cuteneko/catsplus/mixins/mixin/PlayerEntityMixin.java b/src/main/java/cuteneko/catsplus/mixin/PlayerEntityMixin.java similarity index 97% rename from src/main/java/cuteneko/catsplus/mixins/mixin/PlayerEntityMixin.java rename to src/main/java/cuteneko/catsplus/mixin/PlayerEntityMixin.java index 5cc6b96..e0b4c67 100644 --- a/src/main/java/cuteneko/catsplus/mixins/mixin/PlayerEntityMixin.java +++ b/src/main/java/cuteneko/catsplus/mixin/PlayerEntityMixin.java @@ -1,4 +1,4 @@ -package cuteneko.catsplus.mixins.mixin; +package cuteneko.catsplus.mixin; import cuteneko.catsplus.CatsPlusData; import net.minecraft.entity.EntityType; diff --git a/src/main/java/cuteneko/catsplus/mixin/cattify/CreeperEntityMixin.java b/src/main/java/cuteneko/catsplus/mixin/cattify/CreeperEntityMixin.java new file mode 100644 index 0000000..e4d4c6f --- /dev/null +++ b/src/main/java/cuteneko/catsplus/mixin/cattify/CreeperEntityMixin.java @@ -0,0 +1,26 @@ +package cuteneko.catsplus.mixin.cattify; + +import cuteneko.catsplus.utility.CattifyHelper; +import net.minecraft.world.entity.EntityType; +import net.minecraft.world.entity.ai.goal.AvoidEntityGoal; +import net.minecraft.world.entity.monster.Creeper; +import net.minecraft.world.entity.monster.Monster; +import net.minecraft.world.entity.player.Player; +import net.minecraft.world.level.Level; +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(Creeper.class) +public abstract class CreeperEntityMixin extends Monster { + protected CreeperEntityMixin(EntityType entityType, Level level) { + super(entityType, level); + } + + @Inject(method = "registerGoals", at = @At("TAIL")) + public void catsplus$afterRegisterGoals(CallbackInfo ci) { + this.goalSelector.addGoal(3, new AvoidEntityGoal<>(this, Player.class, + 6.0f, 1.0, 1.2, CattifyHelper.PREDICATE_CATTIFIED_PLAYER)); + } +} diff --git a/src/main/java/cuteneko/catsplus/mixin/cattify/EntityMixin.java b/src/main/java/cuteneko/catsplus/mixin/cattify/EntityMixin.java new file mode 100644 index 0000000..08cf2bd --- /dev/null +++ b/src/main/java/cuteneko/catsplus/mixin/cattify/EntityMixin.java @@ -0,0 +1,33 @@ +package cuteneko.catsplus.mixin.cattify; + +import cuteneko.catsplus.utility.CattifyHelper; +import net.minecraft.world.entity.Entity; +import net.minecraft.world.entity.player.Player; +import org.joml.Vector3f; +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(Entity.class) +public abstract class EntityMixin { + +// @Inject(method = "getPassengerAttachmentPoint", at = @At("HEAD"), cancellable = true) +// private void catsplus$beforeGetMountedHeightOffset(CallbackInfoReturnable cir) { +// if ((Object) this instanceof Player player) { +// if (CattifyHelper.cattified(player)) { +// var dimensions = player.getType().getDimensions(); +// cir.setReturnValue(new Vector3f(0, dimensions.height() * 0.9F, 0)); +// } +// } +// } +// +// @Inject(method = "getEyeHeight()F", at = @At("HEAD"), cancellable = true) +// private void catsplus$beforeGetStandingEyeHeight(CallbackInfoReturnable cir) { +// if ((Object) this instanceof Player player) { +// if (CattifyHelper.cattified(player)) { +// cir.setReturnValue(catPlayer.getCatEntity().getStandingEyeHeight() + (isSneaking() ? 0 : 0.2F)); +// } +// } +// } +} diff --git a/src/main/java/cuteneko/catsplus/mixin/cattify/LivingEntityMixin.java b/src/main/java/cuteneko/catsplus/mixin/cattify/LivingEntityMixin.java new file mode 100644 index 0000000..a9043ce --- /dev/null +++ b/src/main/java/cuteneko/catsplus/mixin/cattify/LivingEntityMixin.java @@ -0,0 +1,29 @@ +package cuteneko.catsplus.mixin.cattify; + +import cuteneko.catsplus.utility.CattifyHelper; +import net.minecraft.sounds.SoundEvent; +import net.minecraft.sounds.SoundEvents; +import net.minecraft.world.damagesource.DamageSource; +import net.minecraft.world.entity.LivingEntity; +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(LivingEntity.class) +public abstract class LivingEntityMixin { + + @Inject(method = "getHurtSound", at = @At("RETURN"), cancellable = true) + private void playHurtSound(DamageSource damageSource, CallbackInfoReturnable cir) { + if (CattifyHelper.cattified((LivingEntity) (Object) this)) { + cir.setReturnValue(SoundEvents.CAT_HURT); + } + } + + @Inject(method = "getDeathSound", at = @At("RETURN"), cancellable = true) + private void playDeathSound(CallbackInfoReturnable cir) { + if (CattifyHelper.cattified((LivingEntity) (Object) this)) { + cir.setReturnValue(SoundEvents.CAT_DEATH); + } + } +} diff --git a/src/main/java/cuteneko/catsplus/mixin/cattify/MobEntityMixin.java b/src/main/java/cuteneko/catsplus/mixin/cattify/MobEntityMixin.java new file mode 100644 index 0000000..da29018 --- /dev/null +++ b/src/main/java/cuteneko/catsplus/mixin/cattify/MobEntityMixin.java @@ -0,0 +1,27 @@ +package cuteneko.catsplus.mixin.cattify; + +import cuteneko.catsplus.utility.CattifyHelper; +import net.minecraft.sounds.SoundEvent; +import net.minecraft.sounds.SoundEvents; +import net.minecraft.world.entity.EntityType; +import net.minecraft.world.entity.LivingEntity; +import net.minecraft.world.entity.Mob; +import net.minecraft.world.level.Level; +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(Mob.class) +public abstract class MobEntityMixin extends LivingEntity { + protected MobEntityMixin(EntityType entityType, Level level) { + super(entityType, level); + } + + @Inject(method = "getAmbientSound", at = @At("RETURN"), cancellable = true) + private void afterGetAmbientSound(CallbackInfoReturnable cir) { + if (CattifyHelper.cattified(this)) { + cir.setReturnValue(SoundEvents.CAT_STRAY_AMBIENT); + } + } +} diff --git a/src/main/java/cuteneko/catsplus/mixin/cattify/PlayerEntityRendererMixin.java b/src/main/java/cuteneko/catsplus/mixin/cattify/PlayerEntityRendererMixin.java new file mode 100644 index 0000000..9c65d86 --- /dev/null +++ b/src/main/java/cuteneko/catsplus/mixin/cattify/PlayerEntityRendererMixin.java @@ -0,0 +1,45 @@ +package cuteneko.catsplus.mixin.cattify; + +import com.mojang.blaze3d.vertex.PoseStack; +import cuteneko.catsplus.client.entity.CatPlayerRenderer; +import cuteneko.catsplus.utility.CattifyHelper; +import net.minecraft.client.model.PlayerModel; +import net.minecraft.client.player.AbstractClientPlayer; +import net.minecraft.client.renderer.MultiBufferSource; +import net.minecraft.client.renderer.entity.EntityRendererProvider; +import net.minecraft.client.renderer.entity.LivingEntityRenderer; +import net.minecraft.client.renderer.entity.player.PlayerRenderer; +import org.spongepowered.asm.mixin.Mixin; +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; + +@Mixin(PlayerRenderer.class) +public abstract class PlayerEntityRendererMixin + extends LivingEntityRenderer> { + + public PlayerEntityRendererMixin(EntityRendererProvider.Context context, PlayerModel model, float shadowRadius) { + super(context, model, shadowRadius); + } + + @Unique + private CatPlayerRenderer catsplus$catPlayerRenderer; + + @Inject(method = "", at = @At("TAIL")) + private void catsplus$afterInit(EntityRendererProvider.Context context, boolean useSlimModel, CallbackInfo ci) { + catsplus$catPlayerRenderer = new CatPlayerRenderer(context); + } + + @Inject( + method = "render(Lnet/minecraft/client/player/AbstractClientPlayer;FFLcom/mojang/blaze3d/vertex/PoseStack;Lnet/minecraft/client/renderer/MultiBufferSource;I)V", + at = @At(value = "HEAD"), + cancellable = true + ) + private void catsplus$beforeRender(AbstractClientPlayer entity, float entityYaw, float partialTicks, PoseStack poseStack, MultiBufferSource buffer, int packedLight, CallbackInfo ci) { + if (CattifyHelper.cattified(entity)) { + catsplus$catPlayerRenderer.render(entity, entityYaw, partialTicks, poseStack, buffer, packedLight); + ci.cancel(); + } + } +} diff --git a/src/main/java/cuteneko/catsplus/mixin/dancing/AnimalEntityMixin.java b/src/main/java/cuteneko/catsplus/mixin/dancing/AnimalEntityMixin.java new file mode 100644 index 0000000..6043490 --- /dev/null +++ b/src/main/java/cuteneko/catsplus/mixin/dancing/AnimalEntityMixin.java @@ -0,0 +1,28 @@ +package cuteneko.catsplus.mixin.dancing; + +import cuteneko.catsplus.CatsPlusData; +import cuteneko.catsplus.bridge.IMusicianCat; +import net.minecraft.world.entity.animal.Animal; +import net.minecraft.world.entity.animal.Cat; +import net.minecraft.world.level.block.Blocks; +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(Animal.class) +public abstract class AnimalEntityMixin { + @Inject(method = "aiStep", at = @At("TAIL")) + private void afterTickMovement(CallbackInfo ci) { + if ((Object) this instanceof Cat cat) { + var source = CatsPlusData.getMusicianCat(cat).getSoundSource(); + + if (source == null + || !source.closerThan(cat.blockPosition(), 5) + || !cat.level().isLoaded(source) + || !cat.level().getBlockState(source).is(Blocks.JUKEBOX)) { + ((IMusicianCat) cat).catsplus$setSoundSource(null); + } + } + } +} diff --git a/src/main/java/cuteneko/catsplus/mixin/dancing/CatEntityMixin.java b/src/main/java/cuteneko/catsplus/mixin/dancing/CatEntityMixin.java new file mode 100644 index 0000000..8d33a38 --- /dev/null +++ b/src/main/java/cuteneko/catsplus/mixin/dancing/CatEntityMixin.java @@ -0,0 +1,35 @@ +package cuteneko.catsplus.mixin.dancing; + +import cuteneko.catsplus.bridge.IMusicianCat; +import net.minecraft.core.BlockPos; +import net.minecraft.network.syncher.EntityDataAccessor; +import net.minecraft.network.syncher.EntityDataSerializers; +import net.minecraft.network.syncher.SynchedEntityData; +import net.minecraft.world.entity.EntityType; +import net.minecraft.world.entity.TamableAnimal; +import net.minecraft.world.entity.animal.Cat; +import net.minecraft.world.level.Level; +import org.jetbrains.annotations.Nullable; +import org.spongepowered.asm.mixin.Mixin; +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; + +@Mixin(Cat.class) +public abstract class CatEntityMixin extends TamableAnimal implements IMusicianCat { + @Unique + private static final EntityDataAccessor CATSPLUS$SOUND_PLAYING = SynchedEntityData.defineId(Cat.class, EntityDataSerializers.BOOLEAN); + @Unique + private static final EntityDataAccessor CATSPLUS$SOUND_SOURCE = SynchedEntityData.defineId(Cat.class, EntityDataSerializers.BLOCK_POS); + + protected CatEntityMixin(EntityType entityType, Level level) { + super(entityType, level); + } + + @Inject(method = "defineSynchedData", at = @At("TAIL")) + private void catsplus$defineSynchedData(SynchedEntityData.Builder builder, CallbackInfo ci) { + builder.define(CATSPLUS$SOUND_PLAYING, false); + builder.define(CATSPLUS$SOUND_SOURCE, BlockPos.ZERO); + } +} diff --git a/src/main/java/cuteneko/catsplus/mixins/mixin/dancing/CatEntityModelMixin.java b/src/main/java/cuteneko/catsplus/mixin/dancing/CatEntityModelMixin.java similarity index 89% rename from src/main/java/cuteneko/catsplus/mixins/mixin/dancing/CatEntityModelMixin.java rename to src/main/java/cuteneko/catsplus/mixin/dancing/CatEntityModelMixin.java index a9e990d..9e8b8b4 100644 --- a/src/main/java/cuteneko/catsplus/mixins/mixin/dancing/CatEntityModelMixin.java +++ b/src/main/java/cuteneko/catsplus/mixin/dancing/CatEntityModelMixin.java @@ -1,7 +1,6 @@ -package cuteneko.catsplus.mixins.mixin.dancing; +package cuteneko.catsplus.mixin.dancing; -import cuteneko.catsplus.CatsPlusData; -import cuteneko.catsplus.mixins.bridge.dancing.IMusicianCat; +import cuteneko.catsplus.bridge.IMusicianCat; import net.minecraft.client.model.ModelPart; import net.minecraft.client.render.entity.model.CatEntityModel; import net.minecraft.client.render.entity.model.OcelotEntityModel; diff --git a/src/main/java/cuteneko/catsplus/mixins/mixin/dancing/LivingEntityMixin.java b/src/main/java/cuteneko/catsplus/mixin/dancing/LivingEntityMixin.java similarity index 88% rename from src/main/java/cuteneko/catsplus/mixins/mixin/dancing/LivingEntityMixin.java rename to src/main/java/cuteneko/catsplus/mixin/dancing/LivingEntityMixin.java index e795d1a..1cebe06 100644 --- a/src/main/java/cuteneko/catsplus/mixins/mixin/dancing/LivingEntityMixin.java +++ b/src/main/java/cuteneko/catsplus/mixin/dancing/LivingEntityMixin.java @@ -1,6 +1,6 @@ -package cuteneko.catsplus.mixins.mixin.dancing; +package cuteneko.catsplus.mixin.dancing; -import cuteneko.catsplus.mixins.bridge.dancing.IMusicianCat; +import cuteneko.catsplus.bridge.IMusicianCat; import net.minecraft.entity.LivingEntity; import net.minecraft.entity.passive.CatEntity; import net.minecraft.util.math.BlockPos; diff --git a/src/main/java/cuteneko/catsplus/mixins/mixin/favorability/CatSleepWithOwnerGoal.java b/src/main/java/cuteneko/catsplus/mixin/favorability/CatSleepWithOwnerGoal.java similarity index 95% rename from src/main/java/cuteneko/catsplus/mixins/mixin/favorability/CatSleepWithOwnerGoal.java rename to src/main/java/cuteneko/catsplus/mixin/favorability/CatSleepWithOwnerGoal.java index 5977c4c..c71e12e 100644 --- a/src/main/java/cuteneko/catsplus/mixins/mixin/favorability/CatSleepWithOwnerGoal.java +++ b/src/main/java/cuteneko/catsplus/mixin/favorability/CatSleepWithOwnerGoal.java @@ -1,4 +1,4 @@ -package cuteneko.catsplus.mixins.mixin.favorability; +package cuteneko.catsplus.mixin.favorability; import cuteneko.catsplus.CatsPlusData; import net.minecraft.entity.EntityStatuses; diff --git a/src/main/java/cuteneko/catsplus/mixins/mixin/favorability/EntityMixin.java b/src/main/java/cuteneko/catsplus/mixin/favorability/EntityMixin.java similarity index 95% rename from src/main/java/cuteneko/catsplus/mixins/mixin/favorability/EntityMixin.java rename to src/main/java/cuteneko/catsplus/mixin/favorability/EntityMixin.java index a5d756b..d738884 100644 --- a/src/main/java/cuteneko/catsplus/mixins/mixin/favorability/EntityMixin.java +++ b/src/main/java/cuteneko/catsplus/mixin/favorability/EntityMixin.java @@ -1,4 +1,4 @@ -package cuteneko.catsplus.mixins.mixin.favorability; +package cuteneko.catsplus.mixin.favorability; import cuteneko.catsplus.CatsPlusData; import net.minecraft.entity.Entity; diff --git a/src/main/java/cuteneko/catsplus/mixins/mixin/paper_model/BipedEntityModelMixin.java b/src/main/java/cuteneko/catsplus/mixin/paper_model/BipedEntityModelMixin.java similarity index 97% rename from src/main/java/cuteneko/catsplus/mixins/mixin/paper_model/BipedEntityModelMixin.java rename to src/main/java/cuteneko/catsplus/mixin/paper_model/BipedEntityModelMixin.java index d2e159d..05288b6 100644 --- a/src/main/java/cuteneko/catsplus/mixins/mixin/paper_model/BipedEntityModelMixin.java +++ b/src/main/java/cuteneko/catsplus/mixin/paper_model/BipedEntityModelMixin.java @@ -1,4 +1,4 @@ -package cuteneko.catsplus.mixins.mixin.paper_model; +package cuteneko.catsplus.mixin.paper_model; import cuteneko.catsplus.item.ModItems; import net.minecraft.client.model.ModelPart; diff --git a/src/main/java/cuteneko/catsplus/mixins/mixin/paper_model/PlayerEntityRendererMixin.java b/src/main/java/cuteneko/catsplus/mixin/paper_model/PlayerEntityRendererMixin.java similarity index 95% rename from src/main/java/cuteneko/catsplus/mixins/mixin/paper_model/PlayerEntityRendererMixin.java rename to src/main/java/cuteneko/catsplus/mixin/paper_model/PlayerEntityRendererMixin.java index d22857a..5821014 100644 --- a/src/main/java/cuteneko/catsplus/mixins/mixin/paper_model/PlayerEntityRendererMixin.java +++ b/src/main/java/cuteneko/catsplus/mixin/paper_model/PlayerEntityRendererMixin.java @@ -1,4 +1,4 @@ -package cuteneko.catsplus.mixins.mixin.paper_model; +package cuteneko.catsplus.mixin.paper_model; import cuteneko.catsplus.item.ModItems; import net.minecraft.client.network.AbstractClientPlayerEntity; diff --git a/src/main/java/cuteneko/catsplus/mixins/mixin/paper_model/PlayerHeldItemFeatureRendererMixin.java b/src/main/java/cuteneko/catsplus/mixin/paper_model/PlayerHeldItemFeatureRendererMixin.java similarity index 96% rename from src/main/java/cuteneko/catsplus/mixins/mixin/paper_model/PlayerHeldItemFeatureRendererMixin.java rename to src/main/java/cuteneko/catsplus/mixin/paper_model/PlayerHeldItemFeatureRendererMixin.java index 8ac0935..daae65b 100644 --- a/src/main/java/cuteneko/catsplus/mixins/mixin/paper_model/PlayerHeldItemFeatureRendererMixin.java +++ b/src/main/java/cuteneko/catsplus/mixin/paper_model/PlayerHeldItemFeatureRendererMixin.java @@ -1,4 +1,4 @@ -package cuteneko.catsplus.mixins.mixin.paper_model; +package cuteneko.catsplus.mixin.paper_model; import cuteneko.catsplus.item.ModItems; import net.minecraft.client.render.VertexConsumerProvider; diff --git a/src/main/java/cuteneko/catsplus/mixins/mixin/totemeow/LivingEntityMixin.java b/src/main/java/cuteneko/catsplus/mixin/totemeow/LivingEntityMixin.java similarity index 97% rename from src/main/java/cuteneko/catsplus/mixins/mixin/totemeow/LivingEntityMixin.java rename to src/main/java/cuteneko/catsplus/mixin/totemeow/LivingEntityMixin.java index 474861c..25aaf32 100644 --- a/src/main/java/cuteneko/catsplus/mixins/mixin/totemeow/LivingEntityMixin.java +++ b/src/main/java/cuteneko/catsplus/mixin/totemeow/LivingEntityMixin.java @@ -1,4 +1,4 @@ -package cuteneko.catsplus.mixins.mixin.totemeow; +package cuteneko.catsplus.mixin.totemeow; import cuteneko.catsplus.CatsPlusData; import net.minecraft.entity.Entity; diff --git a/src/main/java/cuteneko/catsplus/mixins/mixin/totemeow/TamableEntityMixin.java b/src/main/java/cuteneko/catsplus/mixin/totemeow/TamableEntityMixin.java similarity index 96% rename from src/main/java/cuteneko/catsplus/mixins/mixin/totemeow/TamableEntityMixin.java rename to src/main/java/cuteneko/catsplus/mixin/totemeow/TamableEntityMixin.java index 0a2666e..f8de35b 100644 --- a/src/main/java/cuteneko/catsplus/mixins/mixin/totemeow/TamableEntityMixin.java +++ b/src/main/java/cuteneko/catsplus/mixin/totemeow/TamableEntityMixin.java @@ -1,9 +1,10 @@ -package cuteneko.catsplus.mixins.mixin.totemeow; +package cuteneko.catsplus.mixin.totemeow; import cuteneko.catsplus.CatsPlusData; import cuteneko.catsplus.item.ModItems; import cuteneko.catsplus.utility.Constants; import cuteneko.catsplus.utility.GeniusCatHelper; +import net.minecraft.core.particles.ParticleTypes; import net.minecraft.entity.EntityStatuses; import net.minecraft.entity.EntityType; import net.minecraft.entity.damage.DamageSource; diff --git a/src/main/java/cuteneko/catsplus/mixins/bridge/dancing/IMusicianCat.java b/src/main/java/cuteneko/catsplus/mixins/bridge/dancing/IMusicianCat.java deleted file mode 100644 index 8849c55..0000000 --- a/src/main/java/cuteneko/catsplus/mixins/bridge/dancing/IMusicianCat.java +++ /dev/null @@ -1,11 +0,0 @@ -package cuteneko.catsplus.mixins.bridge.dancing; - -import net.minecraft.util.math.BlockPos; -import org.jetbrains.annotations.Nullable; - -public interface IMusicianCat { - void catsplus$setSoundSource(@Nullable BlockPos pos); - - @Nullable - BlockPos catsplus$getSoundSource(); -} diff --git a/src/main/java/cuteneko/catsplus/mixins/mixin/cattify/ActiveTargetGoalMixin.java b/src/main/java/cuteneko/catsplus/mixins/mixin/cattify/ActiveTargetGoalMixin.java deleted file mode 100644 index ce2d724..0000000 --- a/src/main/java/cuteneko/catsplus/mixins/mixin/cattify/ActiveTargetGoalMixin.java +++ /dev/null @@ -1,30 +0,0 @@ -package cuteneko.catsplus.mixins.mixin.cattify; - -import cuteneko.catsplus.utility.CatPlayerHelper; -import net.minecraft.entity.ai.TargetPredicate; -import net.minecraft.entity.ai.goal.ActiveTargetGoal; -import net.minecraft.entity.ai.goal.TrackTargetGoal; -import net.minecraft.entity.mob.HostileEntity; -import net.minecraft.entity.mob.MobEntity; -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; - -@Mixin(ActiveTargetGoal.class) -public abstract class ActiveTargetGoalMixin extends TrackTargetGoal { - @Shadow - public TargetPredicate targetPredicate; - - public ActiveTargetGoalMixin(MobEntity mob, boolean checkVisibility, boolean checkNavigable) { - super(mob, checkVisibility, checkNavigable); - } - - @Inject(method = "(Lnet/minecraft/entity/mob/MobEntity;Ljava/lang/Class;Z)V", at = @At("TAIL")) - private void targetGoal(MobEntity mob, Class targetClass, boolean checkVisibility, CallbackInfo ci) { - if (mob instanceof HostileEntity) { - this.targetPredicate.setPredicate(CatPlayerHelper.CATTIFY_PLAYER); - } - } -} diff --git a/src/main/java/cuteneko/catsplus/mixins/mixin/cattify/CreeperEntityMixin.java b/src/main/java/cuteneko/catsplus/mixins/mixin/cattify/CreeperEntityMixin.java deleted file mode 100644 index 3fe9027..0000000 --- a/src/main/java/cuteneko/catsplus/mixins/mixin/cattify/CreeperEntityMixin.java +++ /dev/null @@ -1,26 +0,0 @@ -package cuteneko.catsplus.mixins.mixin.cattify; - -import cuteneko.catsplus.utility.CatPlayerHelper; -import net.minecraft.entity.EntityType; -import net.minecraft.entity.ai.goal.FleeEntityGoal; -import net.minecraft.entity.mob.CreeperEntity; -import net.minecraft.entity.mob.HostileEntity; -import net.minecraft.entity.player.PlayerEntity; -import net.minecraft.world.World; -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(CreeperEntity.class) -public abstract class CreeperEntityMixin extends HostileEntity { - protected CreeperEntityMixin(EntityType entityType, World world) { - super(entityType, world); - } - - @Inject(method = "initGoals", at = @At("TAIL")) - public void initGoals(CallbackInfo ci) { - this.goalSelector.add(3, new FleeEntityGoal<>(this, PlayerEntity.class, - 6.0f, 1.0, 1.2, CatPlayerHelper.CATTIFY_PLAYER)); - } -} diff --git a/src/main/java/cuteneko/catsplus/mixins/mixin/cattify/EntityMixin.java b/src/main/java/cuteneko/catsplus/mixins/mixin/cattify/EntityMixin.java deleted file mode 100644 index e339a3f..0000000 --- a/src/main/java/cuteneko/catsplus/mixins/mixin/cattify/EntityMixin.java +++ /dev/null @@ -1,38 +0,0 @@ -package cuteneko.catsplus.mixins.mixin.cattify; - -import cuteneko.catsplus.CatsPlusData; -import net.minecraft.entity.Entity; -import net.minecraft.entity.player.PlayerEntity; -import org.joml.Vector3f; -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.CallbackInfoReturnable; - -@Mixin(Entity.class) -public abstract class EntityMixin { - @Shadow - public abstract boolean isSneaking(); - - @Inject(method = "getPassengerAttachmentPos", at = @At("HEAD"), cancellable = true) - private void beforeGetMountedHeightOffset(CallbackInfoReturnable cir) { - if ((Object) this instanceof PlayerEntity player) { - var catPlayer = CatsPlusData.getCatPlayer(player); - if (catPlayer.isCat()) { - var dimensions = player.getType().getDimensions(); - cir.setReturnValue(new Vector3f(0, dimensions.height * 0.9F, 0)); - } - } - } - - @Inject(method = "getStandingEyeHeight", at = @At("HEAD"), cancellable = true) - private void beforeGetStandingEyeHeight(CallbackInfoReturnable cir) { - if ((Object) this instanceof PlayerEntity player) { - var catPlayer = CatsPlusData.getCatPlayer(player); - if (catPlayer.isCat()) { - cir.setReturnValue(catPlayer.getCatEntity().getStandingEyeHeight() + (isSneaking() ? 0 : 0.2F)); - } - } - } -} diff --git a/src/main/java/cuteneko/catsplus/mixins/mixin/cattify/LivingEntityMixin.java b/src/main/java/cuteneko/catsplus/mixins/mixin/cattify/LivingEntityMixin.java deleted file mode 100644 index 1b63bac..0000000 --- a/src/main/java/cuteneko/catsplus/mixins/mixin/cattify/LivingEntityMixin.java +++ /dev/null @@ -1,33 +0,0 @@ -package cuteneko.catsplus.mixins.mixin.cattify; - -import cuteneko.catsplus.effect.ModEffects; -import net.minecraft.entity.LivingEntity; -import net.minecraft.entity.damage.DamageSource; -import net.minecraft.entity.effect.StatusEffect; -import net.minecraft.sound.SoundEvent; -import net.minecraft.sound.SoundEvents; -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.CallbackInfoReturnable; - -@Mixin(LivingEntity.class) -public abstract class LivingEntityMixin { - @Shadow - public abstract boolean hasStatusEffect(StatusEffect effect); - - @Inject(method = "getHurtSound", at = @At("RETURN"), cancellable = true) - private void playHurtSound(DamageSource source, CallbackInfoReturnable cir) { - if (hasStatusEffect(ModEffects.CATTIFY.get())) { - cir.setReturnValue(SoundEvents.ENTITY_CAT_HURT); - } - } - - @Inject(method = "getDeathSound", at = @At("RETURN"), cancellable = true) - private void playDeathSound(CallbackInfoReturnable cir) { - if (hasStatusEffect(ModEffects.CATTIFY.get())) { - cir.setReturnValue(SoundEvents.ENTITY_CAT_DEATH); - } - } -} diff --git a/src/main/java/cuteneko/catsplus/mixins/mixin/cattify/MobEntityMixin.java b/src/main/java/cuteneko/catsplus/mixins/mixin/cattify/MobEntityMixin.java deleted file mode 100644 index fce7496..0000000 --- a/src/main/java/cuteneko/catsplus/mixins/mixin/cattify/MobEntityMixin.java +++ /dev/null @@ -1,27 +0,0 @@ -package cuteneko.catsplus.mixins.mixin.cattify; - -import cuteneko.catsplus.effect.ModEffects; -import net.minecraft.entity.EntityType; -import net.minecraft.entity.LivingEntity; -import net.minecraft.entity.mob.MobEntity; -import net.minecraft.sound.SoundEvent; -import net.minecraft.sound.SoundEvents; -import net.minecraft.world.World; -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(MobEntity.class) -public abstract class MobEntityMixin extends LivingEntity { - protected MobEntityMixin(EntityType entityType, World world) { - super(entityType, world); - } - - @Inject(method = "getAmbientSound", at = @At("RETURN"), cancellable = true) - private void afterGetAmbientSound(CallbackInfoReturnable cir) { - if (this.hasStatusEffect(ModEffects.CATTIFY.get())) { - cir.setReturnValue(SoundEvents.ENTITY_CAT_STRAY_AMBIENT); - } - } -} diff --git a/src/main/java/cuteneko/catsplus/mixins/mixin/cattify/PlayerEntityMixin.java b/src/main/java/cuteneko/catsplus/mixins/mixin/cattify/PlayerEntityMixin.java deleted file mode 100644 index c8a4a9a..0000000 --- a/src/main/java/cuteneko/catsplus/mixins/mixin/cattify/PlayerEntityMixin.java +++ /dev/null @@ -1,64 +0,0 @@ -package cuteneko.catsplus.mixins.mixin.cattify; - -import cuteneko.catsplus.CatsPlusData; -import net.minecraft.entity.EntityDimensions; -import net.minecraft.entity.EntityPose; -import net.minecraft.entity.EntityType; -import net.minecraft.entity.LivingEntity; -import net.minecraft.entity.damage.DamageSource; -import net.minecraft.entity.player.PlayerEntity; -import net.minecraft.world.World; -import org.spongepowered.asm.mixin.Mixin; -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; - -@Mixin(PlayerEntity.class) -public abstract class PlayerEntityMixin extends LivingEntity { - @Unique - public EntityDimensions catsplus$playerDimensions; - - @Unique - public float catsplus$playerEyeHeight; - - protected PlayerEntityMixin(EntityType entityType, World world) { - super(entityType, world); - } - - @Inject(method = "tick", at = @At("HEAD")) - public void tick(CallbackInfo ci) { - var catPlayer = CatsPlusData.getCatPlayer((PlayerEntity) (Object) this); - - if (this.firstUpdate) { - this.catsplus$playerDimensions = this.dimensions; - this.catsplus$playerEyeHeight = this.standingEyeHeight; - } - - if (catPlayer.isCat()) { - var cat = catPlayer.getCatEntity(); - this.dimensions = cat.dimensions; - this.standingEyeHeight = this.getStandingEyeHeight(); - } else { - this.dimensions = this.catsplus$playerDimensions; - this.standingEyeHeight = this.catsplus$playerEyeHeight - (this.isSneaking() ? 0.25f : 0); - } - } - - @Inject(method = "getDimensions", at = @At("HEAD"), cancellable = true) - private void beforeGetDimensions(EntityPose pose, CallbackInfoReturnable cir) { - var catPlayer = CatsPlusData.getCatPlayer((PlayerEntity) (Object) this); - if (catPlayer.isCat()) { - cir.setReturnValue(catPlayer.getCatEntity().getDimensions(pose)); - } - } - - @Inject(method = "handleFallDamage", at = @At("HEAD"), cancellable = true) - private void handleFallDamage(float fallDistance, float damageMultiplier, DamageSource damageSource, CallbackInfoReturnable cir) { - var catPlayer = CatsPlusData.getCatPlayer((PlayerEntity) (Object) this); - if (catPlayer.isCat()) { - cir.setReturnValue(false); - } - } -} diff --git a/src/main/java/cuteneko/catsplus/mixins/mixin/cattify/PlayerEntityRendererMixin.java b/src/main/java/cuteneko/catsplus/mixins/mixin/cattify/PlayerEntityRendererMixin.java deleted file mode 100644 index 3544c5b..0000000 --- a/src/main/java/cuteneko/catsplus/mixins/mixin/cattify/PlayerEntityRendererMixin.java +++ /dev/null @@ -1,75 +0,0 @@ -package cuteneko.catsplus.mixins.mixin.cattify; - -import cuteneko.catsplus.CatsPlusData; -import net.minecraft.client.MinecraftClient; -import net.minecraft.client.network.AbstractClientPlayerEntity; -import net.minecraft.client.render.VertexConsumerProvider; -import net.minecraft.client.render.entity.EntityRenderer; -import net.minecraft.client.render.entity.EntityRendererFactory; -import net.minecraft.client.render.entity.LivingEntityRenderer; -import net.minecraft.client.render.entity.PlayerEntityRenderer; -import net.minecraft.client.render.entity.model.PlayerEntityModel; -import net.minecraft.client.util.math.MatrixStack; -import net.minecraft.entity.passive.CatEntity; -import org.spongepowered.asm.mixin.Mixin; -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; - -@Mixin(PlayerEntityRenderer.class) -public abstract class PlayerEntityRendererMixin - extends LivingEntityRenderer> { - - public PlayerEntityRendererMixin(EntityRendererFactory.Context ctx, PlayerEntityModel model, float shadowRadius) { - super(ctx, model, shadowRadius); - } - - @Unique - private EntityRenderer catsplus$renderer = null; - - @Unique - private EntityRenderer catsplus$getCatRenderer(CatEntity cat) { - if (catsplus$renderer == null) { - catsplus$renderer = MinecraftClient.getInstance().getEntityRenderDispatcher().getRenderer(cat); - } - - return catsplus$renderer; - } - - @Inject( - method = "render(Lnet/minecraft/client/network/AbstractClientPlayerEntity;FFLnet/minecraft/client/util/math/MatrixStack;Lnet/minecraft/client/render/VertexConsumerProvider;I)V", - at = @At(value = "INVOKE", target = "Lnet/minecraft/client/render/entity/LivingEntityRenderer;render(Lnet/minecraft/entity/LivingEntity;FFLnet/minecraft/client/util/math/MatrixStack;Lnet/minecraft/client/render/VertexConsumerProvider;I)V"), - cancellable = true - ) - private void onRender(AbstractClientPlayerEntity player, float f, float g, MatrixStack matrixStack, VertexConsumerProvider vertexConsumerProvider, int i, CallbackInfo ci) { - var catPlayer = CatsPlusData.getCatPlayer(player); - - if (catPlayer.isCat()) { - var cat = catPlayer.getCatEntity(); - cat.limbAnimator.updateLimbs(player.limbAnimator.getSpeed() * 0.4f, 1.0f); - cat.bodyYaw = player.bodyYaw; - cat.prevBodyYaw = player.prevBodyYaw; - cat.headYaw = player.headYaw; - cat.prevHeadYaw = player.prevHeadYaw; - cat.age = player.age; - cat.preferredHand = player.preferredHand; - cat.setOnGround(player.isOnGround()); - cat.setVelocity(player.getVelocity()); - cat.setPitch(player.getPitch()); - cat.prevPitch = player.prevPitch; - cat.setPos(player.getX(), player.getY(), player.getZ()); - cat.setSneaking(false); - cat.setSitting(player.isSneaking()); - cat.setInSittingPose(player.isInSneakingPose()); - cat.setSprinting(player.isSprinting()); - cat.setAttacking(player.isUsingItem()); - cat.setInSleepingPose(player.isSleeping()); - - var renderer = catsplus$getCatRenderer(cat); - renderer.render(cat, f, g, matrixStack, vertexConsumerProvider, i); - - ci.cancel(); - } - } -} diff --git a/src/main/java/cuteneko/catsplus/mixins/mixin/dancing/AnimalEntityMixin.java b/src/main/java/cuteneko/catsplus/mixins/mixin/dancing/AnimalEntityMixin.java deleted file mode 100644 index 1d3a68c..0000000 --- a/src/main/java/cuteneko/catsplus/mixins/mixin/dancing/AnimalEntityMixin.java +++ /dev/null @@ -1,26 +0,0 @@ -package cuteneko.catsplus.mixins.mixin.dancing; - -import cuteneko.catsplus.mixins.bridge.dancing.IMusicianCat; -import net.minecraft.block.Blocks; -import net.minecraft.entity.passive.AnimalEntity; -import net.minecraft.entity.passive.CatEntity; -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(AnimalEntity.class) -public abstract class AnimalEntityMixin { - @Inject(method = "tickMovement", at = @At("TAIL")) - private void afterTickMovement(CallbackInfo ci) { - if ((Object) this instanceof CatEntity cat) { - var source = ((IMusicianCat) cat).catsplus$getSoundSource(); - - if (source == null - || !source.isWithinDistance(cat.getPos(), 5) - || !cat.getWorld().getBlockState(source).isOf(Blocks.JUKEBOX)) { - ((IMusicianCat) cat).catsplus$setSoundSource(null); - } - } - } -} diff --git a/src/main/java/cuteneko/catsplus/mixins/mixin/dancing/CatEntityMixin.java b/src/main/java/cuteneko/catsplus/mixins/mixin/dancing/CatEntityMixin.java deleted file mode 100644 index 1f9eb32..0000000 --- a/src/main/java/cuteneko/catsplus/mixins/mixin/dancing/CatEntityMixin.java +++ /dev/null @@ -1,59 +0,0 @@ -package cuteneko.catsplus.mixins.mixin.dancing; - -import cuteneko.catsplus.CatsPlusData; -import cuteneko.catsplus.mixins.bridge.dancing.IMusicianCat; -import net.minecraft.entity.EntityData; -import net.minecraft.entity.EntityType; -import net.minecraft.entity.SpawnReason; -import net.minecraft.entity.data.DataTracker; -import net.minecraft.entity.data.TrackedData; -import net.minecraft.entity.data.TrackedDataHandlerRegistry; -import net.minecraft.entity.passive.CatEntity; -import net.minecraft.entity.passive.TameableEntity; -import net.minecraft.nbt.NbtCompound; -import net.minecraft.util.math.BlockPos; -import net.minecraft.world.LocalDifficulty; -import net.minecraft.world.ServerWorldAccess; -import net.minecraft.world.World; -import org.jetbrains.annotations.Nullable; -import org.spongepowered.asm.mixin.Mixin; -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; - -@Mixin(CatEntity.class) -public abstract class CatEntityMixin extends TameableEntity implements IMusicianCat { - @Unique - private static final TrackedData CATSPLUS$SOUND_PLAYING = DataTracker.registerData(CatEntity.class, TrackedDataHandlerRegistry.BOOLEAN); - @Unique - private static final TrackedData CATSPLUS$SOUND_SOURCE = DataTracker.registerData(CatEntity.class, TrackedDataHandlerRegistry.BLOCK_POS); - - protected CatEntityMixin(EntityType entityType, World world) { - super(entityType, world); - } - - @Inject(method = "initDataTracker", at = @At("TAIL")) - private void afterInitDataTracker(CallbackInfo ci) { - dataTracker.startTracking(CATSPLUS$SOUND_PLAYING, false); - dataTracker.startTracking(CATSPLUS$SOUND_SOURCE, BlockPos.ORIGIN); - } - - @Override - public @Nullable BlockPos catsplus$getSoundSource() { - if (dataTracker.get(CATSPLUS$SOUND_PLAYING)) { - return dataTracker.get(CATSPLUS$SOUND_SOURCE); - } else { - return null; - } - } - - @Override - public void catsplus$setSoundSource(@Nullable BlockPos pos) { - dataTracker.set(CATSPLUS$SOUND_PLAYING, pos != null); - - if (pos != null) { - dataTracker.set(CATSPLUS$SOUND_SOURCE, pos); - } - } -} diff --git a/src/main/java/cuteneko/catsplus/tag/ModItemTags.java b/src/main/java/cuteneko/catsplus/tag/ModItemTags.java index 7b050ad..bde2617 100644 --- a/src/main/java/cuteneko/catsplus/tag/ModItemTags.java +++ b/src/main/java/cuteneko/catsplus/tag/ModItemTags.java @@ -1,11 +1,11 @@ package cuteneko.catsplus.tag; import cuteneko.catsplus.CatsPlus; -import net.minecraft.item.Item; -import net.minecraft.registry.RegistryKeys; -import net.minecraft.registry.tag.TagKey; -import net.minecraft.util.Identifier; +import net.minecraft.core.registries.Registries; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.tags.TagKey; +import net.minecraft.world.item.Item; public class ModItemTags { - public static final TagKey COOKED_FISHES = TagKey.of(RegistryKeys.ITEM, new Identifier(CatsPlus.MODID, "cooked_fishes")); + public static final TagKey COOKED_FISHES = TagKey.of(Registries.ITEM, ResourceLocation.fromNamespaceAndPath(CatsPlus.MODID, "cooked_fishes")); } diff --git a/src/main/java/cuteneko/catsplus/utility/CatPlayerHelper.java b/src/main/java/cuteneko/catsplus/utility/CatPlayerHelper.java deleted file mode 100644 index cdf9afa..0000000 --- a/src/main/java/cuteneko/catsplus/utility/CatPlayerHelper.java +++ /dev/null @@ -1,17 +0,0 @@ -package cuteneko.catsplus.utility; - -import cuteneko.catsplus.CatsPlusData; -import net.minecraft.entity.LivingEntity; -import net.minecraft.entity.player.PlayerEntity; - -import java.util.function.Predicate; - -public class CatPlayerHelper { - public static final Predicate CATTIFY_PLAYER = entity -> { - if (entity instanceof PlayerEntity player) { - var catPlayer = CatsPlusData.getCatPlayer(player); - return catPlayer.isCat(); - } - return false; - }; -} diff --git a/src/main/java/cuteneko/catsplus/utility/CattifyHelper.java b/src/main/java/cuteneko/catsplus/utility/CattifyHelper.java new file mode 100644 index 0000000..78598bf --- /dev/null +++ b/src/main/java/cuteneko/catsplus/utility/CattifyHelper.java @@ -0,0 +1,15 @@ +package cuteneko.catsplus.utility; + +import cuteneko.catsplus.effect.ModEffects; +import net.minecraft.world.entity.LivingEntity; +import net.minecraft.world.entity.player.Player; + +import java.util.function.Predicate; + +public class CattifyHelper { + public static final Predicate PREDICATE_CATTIFIED_PLAYER = entity -> entity instanceof Player && cattified(entity); + + public static boolean cattified(LivingEntity entity) { + return entity.hasEffect(ModEffects.CATTIFY); + } +} diff --git a/src/main/java/cuteneko/catsplus/utility/ComponentHelper.java b/src/main/java/cuteneko/catsplus/utility/ComponentHelper.java new file mode 100644 index 0000000..7cc43c3 --- /dev/null +++ b/src/main/java/cuteneko/catsplus/utility/ComponentHelper.java @@ -0,0 +1,37 @@ +package cuteneko.catsplus.utility; + +import cuteneko.catsplus.data.component.CatContainer; +import cuteneko.catsplus.data.component.ModComponents; +import net.minecraft.core.component.DataComponents; +import net.minecraft.network.chat.Component; +import net.minecraft.world.item.ItemStack; + +public class ComponentHelper { + public static CatContainer getCatContainer(ItemStack stack) { + return stack.get(ModComponents.CAT_CONTAINER.get()); + } + + public static void setCatContainer(ItemStack stack, CatContainer catContainer) { + stack.set(ModComponents.CAT_CONTAINER.get(), catContainer); + } + + public static void removeCatContainer(ItemStack stack) { + stack.remove(ModComponents.CAT_CONTAINER.get()); + } + + public static Component getCustomName(ItemStack stack) { + if (stack.has(DataComponents.CUSTOM_NAME)) { + return stack.get(DataComponents.CUSTOM_NAME); + } + + return null; + } + + public static void setCustomName(ItemStack stack, Component name) { + stack.set(DataComponents.CUSTOM_NAME, name); + } + + public static void removeCustomName(ItemStack stack) { + stack.remove(DataComponents.CUSTOM_NAME); + } +} diff --git a/src/main/java/cuteneko/catsplus/utility/Constants.java b/src/main/java/cuteneko/catsplus/utility/Constants.java index b8a2628..9919d15 100644 --- a/src/main/java/cuteneko/catsplus/utility/Constants.java +++ b/src/main/java/cuteneko/catsplus/utility/Constants.java @@ -1,7 +1,7 @@ package cuteneko.catsplus.utility; import cuteneko.catsplus.CatsPlus; -import net.minecraft.util.Identifier; +import net.minecraft.resources.ResourceLocation; public class Constants { public static final String TAG_CAT_CONTAINER = "Cat"; @@ -17,14 +17,14 @@ public class Constants { public static final String TAG_DEATH_TIME = "deathAt"; public static final String TAG_DEATH_MESSAGE = "deathMessage"; - public static final Identifier CAP_CAT_PLAYER = new Identifier(CatsPlus.MODID, "cat_player_data"); + public static final ResourceLocation CAP_CAT_PLAYER = CatsPlus.modLoc("cat_player_data"); public static final String TAG_CAT_PLAYER_INNER_CAT = "innerCat"; public static final String TAG_CAT_PLAYER_IS_CAT = "isCat"; - public static final Identifier TAG_SERVER_HAS_CAT = new Identifier(CatsPlus.MODID, "cat_server_data"); + public static final ResourceLocation TAG_SERVER_HAS_CAT = CatsPlus.modLoc("cat_server_data"); public static final String TAG_SERVER_CAT_SPIRITS = "catSpirits"; - public static final Identifier CAP_GENIUS_CAT = new Identifier(CatsPlus.MODID, "genius_cat_data"); + public static final ResourceLocation CAP_GENIUS_CAT = CatsPlus.modLoc("genius_cat_data"); public static final String TAG_GENIUS_CAT_LIVES = "lives"; public static final String TAG_GENIUS_CAT_TOTEM = "totem"; public static final String TAG_GENIUS_CAT_CAN_RESPAWN = "respawn"; diff --git a/src/main/java/cuteneko/catsplus/utility/GeniusCatHelper.java b/src/main/java/cuteneko/catsplus/utility/GeniusCatHelper.java index 0b2fa3c..c8e0641 100644 --- a/src/main/java/cuteneko/catsplus/utility/GeniusCatHelper.java +++ b/src/main/java/cuteneko/catsplus/utility/GeniusCatHelper.java @@ -1,21 +1,21 @@ package cuteneko.catsplus.utility; import cuteneko.catsplus.tag.ModItemTags; -import net.minecraft.entity.LivingEntity; -import net.minecraft.particle.ParticleEffect; -import net.minecraft.recipe.Ingredient; +import net.minecraft.core.particles.ParticleOptions; +import net.minecraft.world.entity.LivingEntity; +import net.minecraft.world.item.crafting.Ingredient; public class GeniusCatHelper { - public static final Ingredient TAMED_CAT_FOODS = Ingredient.fromTag(ModItemTags.COOKED_FISHES); + public static final Ingredient TAMED_CAT_FOODS = Ingredient.of(ModItemTags.COOKED_FISHES); - public static void produceParticles(LivingEntity entity, ParticleEffect parameters) { + public static void produceParticles(LivingEntity entity, ParticleOptions parameters) { for (int i = 0; i < 5; ++i) { double d = entity.getRandom().nextGaussian() * 0.02; double e = entity.getRandom().nextGaussian() * 0.02; double f = entity.getRandom().nextGaussian() * 0.02; - entity.getEntityWorld().addParticle(parameters, - entity.getParticleX(1.0), entity.getRandomBodyY() + 1.0, - entity.getParticleZ(1.0), d, e, f); + entity.level().addParticle(parameters, + entity.getRandomX(1.0), entity.getRandomY() + 1.0, + entity.getRandomZ(1.0), d, e, f); } } } diff --git a/src/main/java/cuteneko/catsplus/utility/NBTHelper.java b/src/main/java/cuteneko/catsplus/utility/TagHelper.java similarity index 72% rename from src/main/java/cuteneko/catsplus/utility/NBTHelper.java rename to src/main/java/cuteneko/catsplus/utility/TagHelper.java index 50462e6..c538973 100644 --- a/src/main/java/cuteneko/catsplus/utility/NBTHelper.java +++ b/src/main/java/cuteneko/catsplus/utility/TagHelper.java @@ -1,10 +1,11 @@ package cuteneko.catsplus.utility; -import net.minecraft.nbt.NbtCompound; -import net.minecraft.util.math.BlockPos; +import net.minecraft.core.BlockPos; +import net.minecraft.nbt.CompoundTag; -public class NBTHelper { - public static NbtCompound putBlockPos(NbtCompound compound, BlockPos pos) { +public class TagHelper { + public static CompoundTag saveBlockPos(BlockPos pos) { + var compound = new CompoundTag(); if (pos != null) { compound.putInt(Constants.TAG_X, pos.getX()); compound.putInt(Constants.TAG_Y, pos.getY()); @@ -13,7 +14,7 @@ public static NbtCompound putBlockPos(NbtCompound compound, BlockPos pos) { return compound; } - public static BlockPos getBlockPos(NbtCompound compound) { + public static BlockPos loadBlockPos(CompoundTag compound) { if (compound.contains(Constants.TAG_X) && compound.contains(Constants.TAG_Y) && compound.contains(Constants.TAG_Z)) { diff --git a/src/main/resources/catsplus-common.mixins.json b/src/main/resources/catsplus-common.mixins.json index e766236..adc27d5 100644 --- a/src/main/resources/catsplus-common.mixins.json +++ b/src/main/resources/catsplus-common.mixins.json @@ -1,17 +1,15 @@ { "required": true, "minVersion": "0.8", - "package": "cuteneko.catsplus.mixins.mixin", + "package": "cuteneko.catsplus.mixin", "compatibilityLevel": "JAVA_17", "mixins": [ "CatEntityMixin", "PlayerEntityMixin", - "cattify.ActiveTargetGoalMixin", "cattify.CreeperEntityMixin", "cattify.EntityMixin", "cattify.LivingEntityMixin", "cattify.MobEntityMixin", - "cattify.PlayerEntityMixin", "dancing.AnimalEntityMixin", "dancing.CatEntityMixin", "dancing.LivingEntityMixin", diff --git a/src/main/resources/catsplus.accesswidener b/src/main/resources/catsplus.accesswidener index 5b3e5ca..2315d67 100644 --- a/src/main/resources/catsplus.accesswidener +++ b/src/main/resources/catsplus.accesswidener @@ -1,10 +1,10 @@ accessWidener v1 named -accessible method net/minecraft/entity/passive/CatEntity onTamedChanged ()V -extendable method net/minecraft/entity/LivingEntity tryUseTotem (Lnet/minecraft/entity/damage/DamageSource;)Z -extendable method net/minecraft/entity/Entity getStandingEyeHeight ()F -accessible method net/minecraft/entity/LivingEntity getEyeHeight (Lnet/minecraft/entity/EntityPose;Lnet/minecraft/entity/EntityDimensions;)F -extendable method net/minecraft/entity/LivingEntity getEyeHeight (Lnet/minecraft/entity/EntityPose;Lnet/minecraft/entity/EntityDimensions;)F -accessible field net/minecraft/entity/Entity standingEyeHeight F -accessible field net/minecraft/entity/Entity dimensions Lnet/minecraft/entity/EntityDimensions; -accessible field net/minecraft/entity/Entity boundingBox Lnet/minecraft/util/math/Box; -accessible field net/minecraft/entity/ai/goal/ActiveTargetGoal targetPredicate Lnet/minecraft/entity/ai/TargetPredicate; +#accessible method net/minecraft/entity/passive/CatEntity onTamedChanged ()V +#extendable method net/minecraft/entity/LivingEntity tryUseTotem (Lnet/minecraft/entity/damage/DamageSource;)Z +#extendable method net/minecraft/entity/Entity getStandingEyeHeight ()F +#accessible method net/minecraft/entity/LivingEntity getEyeHeight (Lnet/minecraft/entity/EntityPose;Lnet/minecraft/entity/EntityDimensions;)F +#extendable method net/minecraft/entity/LivingEntity getEyeHeight (Lnet/minecraft/entity/EntityPose;Lnet/minecraft/entity/EntityDimensions;)F +#accessible field net/minecraft/entity/Entity standingEyeHeight F +#accessible field net/minecraft/entity/Entity dimensions Lnet/minecraft/entity/EntityDimensions; +#accessible field net/minecraft/entity/Entity boundingBox Lnet/minecraft/util/math/Box; +#accessible field net/minecraft/entity/ai/goal/ActiveTargetGoal targetPredicate Lnet/minecraft/entity/ai/TargetPredicate;