diff --git a/build.gradle b/build.gradle index a2a6dd1..0ef5933 100644 --- a/build.gradle +++ b/build.gradle @@ -1,4 +1,5 @@ plugins { + id 'java' 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 diff --git a/fabric/build.gradle b/fabric/build.gradle index c59a4c0..c016118 100644 --- a/fabric/build.gradle +++ b/fabric/build.gradle @@ -14,7 +14,7 @@ loom { vmArg "-Dfabric-api.datagen.output-dir=${file("../src/main/generated")}" vmArg '-Dfabric-api.datagen.modid=catsplus' - runDir 'build/datagen' + runDir 'run/datagen' } } } diff --git a/fabric/src/main/java/cuteneko/catsplus/fabric/CatsPlusDataImpl.java b/fabric/src/main/java/cuteneko/catsplus/fabric/CatsPlusDataImpl.java index e77c635..40e7865 100644 --- a/fabric/src/main/java/cuteneko/catsplus/fabric/CatsPlusDataImpl.java +++ b/fabric/src/main/java/cuteneko/catsplus/fabric/CatsPlusDataImpl.java @@ -1,18 +1,11 @@ package cuteneko.catsplus.fabric; -import cuteneko.catsplus.fabric.data.CatPlayerFabric; -import cuteneko.catsplus.fabric.data.GeniusCatFabric; -import cuteneko.catsplus.data.ICatPlayer; import cuteneko.catsplus.data.entity.GeniusCat; -import net.minecraft.entity.passive.CatEntity; -import net.minecraft.entity.player.PlayerEntity; +import cuteneko.catsplus.fabric.mixins.impl.ICatEntityMixin; +import net.minecraft.world.entity.animal.Cat; public class CatsPlusDataImpl { - public static ICatPlayer getCatPlayer(PlayerEntity player) { - return new CatPlayerFabric(player); - } - - public static GeniusCat getGeniusCat(CatEntity cat) { - return new GeniusCatFabric(cat); + public static GeniusCat getGeniusCat(Cat cat) { + return ((ICatEntityMixin) cat).catsplus$getGeniusCat(); } } diff --git a/fabric/src/main/java/cuteneko/catsplus/fabric/CatsPlusFabric.java b/fabric/src/main/java/cuteneko/catsplus/fabric/CatsPlusFabric.java index 79a60ec..1d10352 100644 --- a/fabric/src/main/java/cuteneko/catsplus/fabric/CatsPlusFabric.java +++ b/fabric/src/main/java/cuteneko/catsplus/fabric/CatsPlusFabric.java @@ -1,31 +1,11 @@ package cuteneko.catsplus.fabric; import cuteneko.catsplus.CatsPlus; -import cuteneko.catsplus.item.ModItems; -import net.fabricmc.api.ClientModInitializer; import net.fabricmc.api.ModInitializer; -import net.fabricmc.fabric.api.client.rendering.v1.ColorProviderRegistry; -import net.minecraft.item.DyeableItem; - -public class CatsPlusFabric implements ModInitializer, ClientModInitializer { - private final CatsPlus mod; - - public CatsPlusFabric() { - mod = new CatsPlus(); - } +public class CatsPlusFabric implements ModInitializer { @Override public void onInitialize() { - mod.init(); - } - - @Override - public void onInitializeClient() { - mod.initClient(); - - ColorProviderRegistry.ITEM.register( - (stack, tintIndex) -> tintIndex == 0 ? ((DyeableItem) stack.getItem()).getColor(stack) : -1, - ModItems.CAT_BAG.get() - ); + CatsPlus.init(); } } diff --git a/fabric/src/main/java/cuteneko/catsplus/fabric/client/CatsPlusFabricClient.java b/fabric/src/main/java/cuteneko/catsplus/fabric/client/CatsPlusFabricClient.java new file mode 100644 index 0000000..9543b1f --- /dev/null +++ b/fabric/src/main/java/cuteneko/catsplus/fabric/client/CatsPlusFabricClient.java @@ -0,0 +1,24 @@ +package cuteneko.catsplus.fabric.client; + +import cuteneko.catsplus.client.CatsPlusClient; +import cuteneko.catsplus.item.ModItems; +import net.fabricmc.api.ClientModInitializer; +import net.fabricmc.fabric.api.client.rendering.v1.ColorProviderRegistry; +import net.minecraft.core.component.DataComponents; + +public class CatsPlusFabricClient implements ClientModInitializer { + @Override + public void onInitializeClient() { + CatsPlusClient.initClient(); + + ColorProviderRegistry.ITEM.register((stack, tintIndex) -> { + if (tintIndex == 0) { + var color = stack.get(DataComponents.DYED_COLOR); + if (color != null) { + return color.rgb(); + } + } + return -1; + }, ModItems.CAT_BAG.get()); + } +} diff --git a/fabric/src/main/java/cuteneko/catsplus/fabric/data/CatPlayerFabric.java b/fabric/src/main/java/cuteneko/catsplus/fabric/data/CatPlayerFabric.java deleted file mode 100644 index 871eef6..0000000 --- a/fabric/src/main/java/cuteneko/catsplus/fabric/data/CatPlayerFabric.java +++ /dev/null @@ -1,35 +0,0 @@ -package cuteneko.catsplus.fabric.data; - -import cuteneko.catsplus.effect.ModEffects; -import cuteneko.catsplus.fabric.mixins.impl.IPlayerEntityMixin; -import cuteneko.catsplus.data.ICatPlayer; -import net.minecraft.entity.passive.CatEntity; -import net.minecraft.entity.player.PlayerEntity; - -public class CatPlayerFabric implements ICatPlayer { - private final PlayerEntity player; - - public CatPlayerFabric(PlayerEntity player) { - this.player = player; - } - - @Override - public CatEntity getCatEntity() { - return ((IPlayerEntityMixin) player).catsplus$getCatEntity(); - } - - @Override - public void setCatEntity(CatEntity cat) { - ((IPlayerEntityMixin) player).catsplus$setCatEntity(cat); - } - - @Override - public boolean isCat() { - return ((IPlayerEntityMixin) player).catsplus$isCat() || player.hasStatusEffect(ModEffects.CATTIFY.get()); - } - - @Override - public void setCat(boolean cat) { - ((IPlayerEntityMixin) player).catsplus$setCat(cat); - } -} diff --git a/fabric/src/main/java/cuteneko/catsplus/fabric/data/GeniusCatFabric.java b/fabric/src/main/java/cuteneko/catsplus/fabric/data/GeniusCatFabric.java deleted file mode 100644 index a50f068..0000000 --- a/fabric/src/main/java/cuteneko/catsplus/fabric/data/GeniusCatFabric.java +++ /dev/null @@ -1,59 +0,0 @@ -package cuteneko.catsplus.fabric.data; - -import cuteneko.catsplus.fabric.mixins.impl.ICatEntityMixin; -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; - -public class GeniusCatFabric implements GeniusCat { - private final CatEntity cat; - - public GeniusCatFabric(CatEntity cat) { - this.cat = cat; - } - - @Override - public boolean hasTotem() { - return ((ICatEntityMixin) cat).catsplus$hasTotem(); - } - - @Override - public void setTotem(boolean totem) { - ((ICatEntityMixin) cat).catsplus$setTotem(totem); - } - - @Override - public int getFavorability(PlayerEntity player) { - return ((ICatEntityMixin) cat).catsplus$getFavorability(player); - } - - @Override - public void setFavorability(int favorability, PlayerEntity player) { - ((ICatEntityMixin) cat).catsplus$setFavorability(favorability, player); - - if (getFavorability(player) <= 0) { - cat.tryAttack(player); - cat.getWorld().sendEntityStatus(cat, EntityStatuses.ADD_VILLAGER_ANGRY_PARTICLES); - - if (cat.isOwner(player)) { - cat.setOwnerUuid(null); - cat.setTamed(false); - cat.setSitting(false); - setLives(0); - cat.onTamedChanged(); - } - } - } - - @Override - public int getLives() { - return ((ICatEntityMixin) cat).catsplus$getLives(); - } - - @Override - public void setLives(int lives) { - ((ICatEntityMixin) cat).catsplus$setLives(lives); - } -} diff --git a/fabric/src/main/java/cuteneko/catsplus/fabric/data/gen/ModBlockTagProvider.java b/fabric/src/main/java/cuteneko/catsplus/fabric/data/gen/ModBlockTagProvider.java new file mode 100644 index 0000000..4beee84 --- /dev/null +++ b/fabric/src/main/java/cuteneko/catsplus/fabric/data/gen/ModBlockTagProvider.java @@ -0,0 +1,19 @@ +package cuteneko.catsplus.fabric.data.gen; + +import net.fabricmc.fabric.api.datagen.v1.FabricDataOutput; +import net.fabricmc.fabric.api.datagen.v1.provider.FabricTagProvider; +import net.minecraft.core.HolderLookup; + +import java.util.concurrent.CompletableFuture; + +public class ModBlockTagProvider extends FabricTagProvider.BlockTagProvider { + + public ModBlockTagProvider(FabricDataOutput output, CompletableFuture registriesFuture) { + super(output, registriesFuture); + } + + @Override + protected void addTags(HolderLookup.Provider provider) { + + } +} diff --git a/fabric/src/main/java/cuteneko/catsplus/fabric/data/gen/ModDataGen.java b/fabric/src/main/java/cuteneko/catsplus/fabric/data/gen/ModDataGen.java index ce79685..7f02cab 100644 --- a/fabric/src/main/java/cuteneko/catsplus/fabric/data/gen/ModDataGen.java +++ b/fabric/src/main/java/cuteneko/catsplus/fabric/data/gen/ModDataGen.java @@ -15,6 +15,8 @@ public void onInitializeDataGenerator(FabricDataGenerator generator) { pack.addProvider(ModItemModelProvider::new); pack.addProvider(ModRecipeProvider::new); - pack.addProvider(ModItemTagProvider::new); + + var blockTags = pack.addProvider(ModBlockTagProvider::new); + pack.addProvider((output, registry) -> new ModItemTagProvider(output, registry, blockTags)); } } diff --git a/fabric/src/main/java/cuteneko/catsplus/fabric/data/gen/ModItemModelProvider.java b/fabric/src/main/java/cuteneko/catsplus/fabric/data/gen/ModItemModelProvider.java index ed21e43..43ea4b6 100644 --- a/fabric/src/main/java/cuteneko/catsplus/fabric/data/gen/ModItemModelProvider.java +++ b/fabric/src/main/java/cuteneko/catsplus/fabric/data/gen/ModItemModelProvider.java @@ -3,22 +3,23 @@ import cuteneko.catsplus.item.ModItems; import net.fabricmc.fabric.api.datagen.v1.FabricDataOutput; import net.fabricmc.fabric.api.datagen.v1.provider.FabricModelProvider; -import net.minecraft.data.client.BlockStateModelGenerator; -import net.minecraft.data.client.ItemModelGenerator; -import net.minecraft.data.client.Models; +import net.minecraft.data.models.BlockModelGenerators; +import net.minecraft.data.models.ItemModelGenerators; +import net.minecraft.data.models.model.ModelTemplates; public class ModItemModelProvider extends FabricModelProvider { + public ModItemModelProvider(FabricDataOutput output) { super(output); } @Override - public void generateBlockStateModels(BlockStateModelGenerator generator) { + public void generateBlockStateModels(BlockModelGenerators generator) { } @Override - public void generateItemModels(ItemModelGenerator generator) { - generator.register(ModItems.TOTEMEOW.get(), Models.GENERATED); + public void generateItemModels(ItemModelGenerators generator) { + generator.generateFlatItem(ModItems.TOTEMEOW.get(), ModelTemplates.FLAT_ITEM); } } diff --git a/fabric/src/main/java/cuteneko/catsplus/fabric/data/gen/ModItemTagProvider.java b/fabric/src/main/java/cuteneko/catsplus/fabric/data/gen/ModItemTagProvider.java index a647a21..826cc72 100644 --- a/fabric/src/main/java/cuteneko/catsplus/fabric/data/gen/ModItemTagProvider.java +++ b/fabric/src/main/java/cuteneko/catsplus/fabric/data/gen/ModItemTagProvider.java @@ -3,18 +3,20 @@ import cuteneko.catsplus.tag.ModItemTags; import net.fabricmc.fabric.api.datagen.v1.FabricDataOutput; import net.fabricmc.fabric.api.datagen.v1.provider.FabricTagProvider; -import net.minecraft.item.Items; -import net.minecraft.registry.RegistryWrapper; +import net.minecraft.core.HolderLookup; +import net.minecraft.world.item.Items; +import org.jetbrains.annotations.Nullable; import java.util.concurrent.CompletableFuture; public class ModItemTagProvider extends FabricTagProvider.ItemTagProvider { - public ModItemTagProvider(FabricDataOutput output, CompletableFuture completableFuture) { - super(output, completableFuture); + + public ModItemTagProvider(FabricDataOutput output, CompletableFuture completableFuture, @Nullable BlockTagProvider blockTagProvider) { + super(output, completableFuture, blockTagProvider); } @Override - protected void configure(RegistryWrapper.WrapperLookup arg) { + protected void addTags(HolderLookup.Provider provider) { getOrCreateTagBuilder(ModItemTags.COOKED_FISHES) .add(Items.COOKED_COD) .add(Items.COOKED_SALMON); diff --git a/fabric/src/main/java/cuteneko/catsplus/fabric/data/gen/ModRecipeProvider.java b/fabric/src/main/java/cuteneko/catsplus/fabric/data/gen/ModRecipeProvider.java index 1447118..73294a3 100644 --- a/fabric/src/main/java/cuteneko/catsplus/fabric/data/gen/ModRecipeProvider.java +++ b/fabric/src/main/java/cuteneko/catsplus/fabric/data/gen/ModRecipeProvider.java @@ -3,42 +3,46 @@ import cuteneko.catsplus.item.ModItems; import net.fabricmc.fabric.api.datagen.v1.FabricDataOutput; import net.fabricmc.fabric.api.datagen.v1.provider.FabricRecipeProvider; -import net.minecraft.data.server.recipe.RecipeExporter; -import net.minecraft.data.server.recipe.ShapedRecipeJsonBuilder; -import net.minecraft.item.Items; -import net.minecraft.recipe.book.RecipeCategory; -import net.minecraft.registry.tag.ItemTags; -import net.minecraft.registry.tag.TagKey; +import net.minecraft.core.HolderLookup; +import net.minecraft.data.recipes.RecipeCategory; +import net.minecraft.data.recipes.RecipeOutput; +import net.minecraft.data.recipes.ShapedRecipeBuilder; +import net.minecraft.tags.ItemTags; +import net.minecraft.tags.TagKey; +import net.minecraft.world.item.Items; + +import java.util.concurrent.CompletableFuture; public class ModRecipeProvider extends FabricRecipeProvider { - public ModRecipeProvider(FabricDataOutput output) { - super(output); + + public ModRecipeProvider(FabricDataOutput output, CompletableFuture registriesFuture) { + super(output, registriesFuture); } - private static String hasTag(TagKey tag) { - return "has_tag_" + tag.id().getNamespace() + "_" + tag.id().getPath(); + private static String getHasName(TagKey tag) { + return "has_tag_" + tag.location().getNamespace() + "_" + tag.location().getPath(); } @Override - public void generate(RecipeExporter exporter) { - ShapedRecipeJsonBuilder.create(RecipeCategory.TOOLS, ModItems.CAT_BAG.get()) + public void buildRecipes(RecipeOutput output) { + ShapedRecipeBuilder.shaped(RecipeCategory.TOOLS, ModItems.CAT_BAG.get()) .pattern("LLL") .pattern("LGL") .pattern("LLL") - .input('L', Items.LEATHER) - .input('G', Items.GLASS_PANE) - .criterion(hasItem(Items.LEATHER), conditionsFromItem(Items.LEATHER)) - .criterion(hasItem(Items.GLASS_PANE), conditionsFromItem(Items.GLASS_PANE)) - .offerTo(exporter); + .define('L', Items.LEATHER) + .define('G', Items.GLASS_PANE) + .unlockedBy(getHasName(Items.LEATHER), has(Items.LEATHER)) + .unlockedBy(getHasName(Items.GLASS_PANE), has(Items.GLASS_PANE)) + .save(output); - ShapedRecipeJsonBuilder.create(RecipeCategory.TOOLS, ModItems.TOTEMEOW.get()) + ShapedRecipeBuilder.shaped(RecipeCategory.TOOLS, ModItems.TOTEMEOW.get()) .pattern("FFF") .pattern("FTF") .pattern("FFF") - .input('F', ItemTags.FISHES) - .input('T', Items.TOTEM_OF_UNDYING) - .criterion(hasTag(ItemTags.FISHES), conditionsFromTag(ItemTags.FISHES)) - .criterion(hasItem(Items.TOTEM_OF_UNDYING), conditionsFromItem(Items.TOTEM_OF_UNDYING)) - .offerTo(exporter); + .define('F', ItemTags.FISHES) + .define('T', Items.TOTEM_OF_UNDYING) + .unlockedBy(getHasName(ItemTags.FISHES), has(ItemTags.FISHES)) + .unlockedBy(getHasName(Items.TOTEM_OF_UNDYING), has(Items.TOTEM_OF_UNDYING)) + .save(output); } } diff --git a/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 index 8cf1570..51f5f13 100644 --- a/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 @@ -4,44 +4,47 @@ import cuteneko.catsplus.effect.ModEffects; import cuteneko.catsplus.item.ModItems; import cuteneko.catsplus.item.group.ModItemGroups; -import cuteneko.catsplus.utility.Constants; -import dev.architectury.registry.registries.DeferredSupplier; +import cuteneko.catsplus.utility.ModConstants; import net.fabricmc.fabric.api.datagen.v1.FabricDataOutput; import net.fabricmc.fabric.api.datagen.v1.provider.FabricLanguageProvider; +import net.minecraft.core.HolderLookup; + +import java.util.concurrent.CompletableFuture; public class ModLangProviderENUS extends FabricLanguageProvider { - public ModLangProviderENUS(FabricDataOutput dataOutput) { - super(dataOutput, "en_us"); + + public ModLangProviderENUS(FabricDataOutput dataOutput, CompletableFuture registries) { + super(dataOutput, "en_us", registries); } @Override - public void generateTranslations(TranslationBuilder builder) { + public void generateTranslations(HolderLookup.Provider provider, TranslationBuilder builder) { builder.add(ModItems.CAT_BAG.get(), "Cat Bag"); builder.add(ModItems.TOTEMEOW.get(), "Totemeow"); builder.add(ModItems.CAT_SPIRIT.get(), "Cat Spirit"); builder.add(ModItems.FANG_LUO.get(), "Doll of Fang_Luo"); - builder.add(Constants.MESSAGE_FANG_LUO_DESCRIPTION_1, "In memory of Fang_Luo, a girl who passed away because of cancer."); - builder.add(Constants.MESSAGE_FANG_LUO_DESCRIPTION_2, "Rest in peace, my friend."); + builder.add(ModConstants.MESSAGE_FANG_LUO_DESCRIPTION_1, "In memory of Fang_Luo, a girl who passed away because of cancer."); + builder.add(ModConstants.MESSAGE_FANG_LUO_DESCRIPTION_2, "Rest in peace, my friend."); builder.add(ModBlocks.CAT_RESURRECTION_STATION_BLOCK.get(), "Cat Resurrection Station"); builder.add(ModEffects.CATTIFY.get(), "Cattify"); - builder.add(Constants.MESSAGE_CATTIFY_POTION, "Potion of Cattify"); - builder.add(Constants.MESSAGE_CATTIFY_SPLASH_POTION, "Splash Potion of Cattify"); - builder.add(Constants.MESSAGE_CATTIFY_LINGERING_POTION, "Lingering Potion of Cattify"); - builder.add(Constants.MESSAGE_CATTIFY_POTION_ARROW, "Arrow of Cattify"); - - builder.add(((DeferredSupplier) ModItemGroups.CATS_PLUS).getKey(), "Cats+!"); - builder.add(Constants.MESSAGE_CAT_BAG_DESCRIPTION_NO_CAT, "Empty."); - builder.add(Constants.MESSAGE_CAT_BAG_DESCRIPTION_HAS_CAT, "Cat Inside!"); - builder.add(Constants.MESSAGE_CAT_BAG_DESCRIPTION_HAS_NAMED_CAT, "%1$s Inside!"); - - builder.add(Constants.MESSAGE_CAT_SPIRIT_NAME, "Spirit of %1$s"); - builder.add(Constants.MESSAGE_CAT_SPIRIT_DESCRIPTION_MESSAGE, ""); - builder.add(Constants.MESSAGE_CAT_SPIRIT_DESCRIPTION_TIME_LABEL, "Dead at: "); - builder.add(Constants.MESSAGE_CAT_SPIRIT_DESCRIPTION_TIME_PATTERN, "%2$s/%3$s/%1$s %4$s:%5$s:%6$s"); - builder.add(Constants.MESSAGE_CAT_SPIRIT_DESCRIPTION_TIME_LONG_TIME_AGO, "Long time ago"); - - builder.add(Constants.MESSAGE_CAT_DIED, "Your cat was died, here is its spirit."); + builder.add(ModConstants.MESSAGE_CATTIFY_POTION, "Potion of Cattify"); + builder.add(ModConstants.MESSAGE_CATTIFY_SPLASH_POTION, "Splash Potion of Cattify"); + builder.add(ModConstants.MESSAGE_CATTIFY_LINGERING_POTION, "Lingering Potion of Cattify"); + builder.add(ModConstants.MESSAGE_CATTIFY_POTION_ARROW, "Arrow of Cattify"); + + builder.add(ModItemGroups.CATS_PLUS.getKey(), "Cats+!"); + builder.add(ModConstants.MESSAGE_CAT_BAG_DESCRIPTION_NO_CAT, "Empty."); + builder.add(ModConstants.MESSAGE_CAT_BAG_DESCRIPTION_HAS_CAT, "Cat Inside!"); + builder.add(ModConstants.MESSAGE_CAT_BAG_DESCRIPTION_HAS_NAMED_CAT, "%1$s Inside!"); + + builder.add(ModConstants.MESSAGE_CAT_SPIRIT_NAME, "Spirit of %1$s"); + builder.add(ModConstants.MESSAGE_CAT_SPIRIT_DESCRIPTION_MESSAGE, ""); + builder.add(ModConstants.MESSAGE_CAT_SPIRIT_DESCRIPTION_TIME_LABEL, "Dead at: "); + builder.add(ModConstants.MESSAGE_CAT_SPIRIT_DESCRIPTION_TIME_PATTERN, "%2$s/%3$s/%1$s %4$s:%5$s:%6$s"); + builder.add(ModConstants.MESSAGE_CAT_SPIRIT_DESCRIPTION_TIME_LONG_TIME_AGO, "Long time ago"); + + builder.add(ModConstants.MESSAGE_CAT_DIED, "Your cat was died, its spirit back to its loved owner."); } } diff --git a/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 index 904c883..b7d904d 100644 --- a/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 @@ -4,45 +4,47 @@ import cuteneko.catsplus.effect.ModEffects; import cuteneko.catsplus.item.ModItems; import cuteneko.catsplus.item.group.ModItemGroups; -import cuteneko.catsplus.utility.Constants; -import dev.architectury.registry.registries.DeferredSupplier; +import cuteneko.catsplus.utility.ModConstants; import net.fabricmc.fabric.api.datagen.v1.FabricDataOutput; import net.fabricmc.fabric.api.datagen.v1.provider.FabricLanguageProvider; -import net.minecraft.item.ItemGroup; +import net.minecraft.core.HolderLookup; + +import java.util.concurrent.CompletableFuture; public class ModLangProviderZHCN extends FabricLanguageProvider { - public ModLangProviderZHCN(FabricDataOutput dataOutput) { - super(dataOutput, "zh_cn"); + + public ModLangProviderZHCN(FabricDataOutput dataOutput, CompletableFuture registries) { + super(dataOutput, "zh_cn", registries); } @Override - public void generateTranslations(TranslationBuilder builder) { + public void generateTranslations(HolderLookup.Provider provider, TranslationBuilder builder) { builder.add(ModItems.CAT_BAG.get(), "猫包"); builder.add(ModItems.TOTEMEOW.get(), "不死猫腾"); builder.add(ModItems.CAT_SPIRIT.get(), "猫魂"); builder.add(ModItems.FANG_LUO.get(), "坊洛玩偶"); - builder.add(Constants.MESSAGE_FANG_LUO_DESCRIPTION_1, "纪念因肿瘤离去的坊洛。"); - builder.add(Constants.MESSAGE_FANG_LUO_DESCRIPTION_2, "缅怀……"); + builder.add(ModConstants.MESSAGE_FANG_LUO_DESCRIPTION_1, "纪念因肿瘤离去的坊洛。"); + builder.add(ModConstants.MESSAGE_FANG_LUO_DESCRIPTION_2, "缅怀……"); builder.add(ModBlocks.CAT_RESURRECTION_STATION_BLOCK.get(), "猫咪复活台"); builder.add(ModEffects.CATTIFY.get(), "猫咪化"); - builder.add(Constants.MESSAGE_CATTIFY_POTION, "变猫药水"); - builder.add(Constants.MESSAGE_CATTIFY_SPLASH_POTION, "喷溅型变猫药水"); - builder.add(Constants.MESSAGE_CATTIFY_LINGERING_POTION, "滞留型变猫药水"); - builder.add(Constants.MESSAGE_CATTIFY_POTION_ARROW, "变猫药水箭"); - - builder.add(((DeferredSupplier) ModItemGroups.CATS_PLUS).getKey(), "Cats+!"); - builder.add(Constants.MESSAGE_CAT_BAG_DESCRIPTION_NO_CAT, "空的。"); - builder.add(Constants.MESSAGE_CAT_BAG_DESCRIPTION_HAS_CAT, "内含猫猫!"); - builder.add(Constants.MESSAGE_CAT_BAG_DESCRIPTION_HAS_NAMED_CAT, "%1$s 在里面!"); - - builder.add(Constants.MESSAGE_CAT_SPIRIT_NAME, "%1$s 的灵魂"); - builder.add(Constants.MESSAGE_CAT_SPIRIT_DESCRIPTION_MESSAGE, ""); - builder.add(Constants.MESSAGE_CAT_SPIRIT_DESCRIPTION_TIME_LABEL, "卒于:"); - builder.add(Constants.MESSAGE_CAT_SPIRIT_DESCRIPTION_TIME_PATTERN, "%1$s年%2$s月%3$s日 %4$s:%5$s:%6$s"); - builder.add(Constants.MESSAGE_CAT_SPIRIT_DESCRIPTION_TIME_LONG_TIME_AGO, "很久以前"); - - builder.add(Constants.MESSAGE_CAT_DIED, "你的猫猫死掉了,它的灵魂回到了你的身旁。"); + builder.add(ModConstants.MESSAGE_CATTIFY_POTION, "变猫药水"); + builder.add(ModConstants.MESSAGE_CATTIFY_SPLASH_POTION, "喷溅型变猫药水"); + builder.add(ModConstants.MESSAGE_CATTIFY_LINGERING_POTION, "滞留型变猫药水"); + builder.add(ModConstants.MESSAGE_CATTIFY_POTION_ARROW, "变猫药水箭"); + + builder.add(ModItemGroups.CATS_PLUS.getKey(), "Cats+!"); + builder.add(ModConstants.MESSAGE_CAT_BAG_DESCRIPTION_NO_CAT, "空的。"); + builder.add(ModConstants.MESSAGE_CAT_BAG_DESCRIPTION_HAS_CAT, "内含猫猫!"); + builder.add(ModConstants.MESSAGE_CAT_BAG_DESCRIPTION_HAS_NAMED_CAT, "%1$s 在里面!"); + + builder.add(ModConstants.MESSAGE_CAT_SPIRIT_NAME, "%1$s 的灵魂"); + builder.add(ModConstants.MESSAGE_CAT_SPIRIT_DESCRIPTION_MESSAGE, ""); + builder.add(ModConstants.MESSAGE_CAT_SPIRIT_DESCRIPTION_TIME_LABEL, "卒于:"); + builder.add(ModConstants.MESSAGE_CAT_SPIRIT_DESCRIPTION_TIME_PATTERN, "%1$s年%2$s月%3$s日 %4$s:%5$s:%6$s"); + builder.add(ModConstants.MESSAGE_CAT_SPIRIT_DESCRIPTION_TIME_LONG_TIME_AGO, "很久以前"); + + builder.add(ModConstants.MESSAGE_CAT_DIED, "你的猫猫死掉了,灵魂回到了主人的身边。"); } } diff --git a/fabric/src/main/java/cuteneko/catsplus/fabric/mixins/impl/ICatEntityMixin.java b/fabric/src/main/java/cuteneko/catsplus/fabric/mixins/impl/ICatEntityMixin.java index 292d885..443e4a4 100644 --- a/fabric/src/main/java/cuteneko/catsplus/fabric/mixins/impl/ICatEntityMixin.java +++ b/fabric/src/main/java/cuteneko/catsplus/fabric/mixins/impl/ICatEntityMixin.java @@ -1,15 +1,7 @@ package cuteneko.catsplus.fabric.mixins.impl; -import net.minecraft.entity.player.PlayerEntity; -import net.minecraft.util.math.BlockPos; +import cuteneko.catsplus.data.entity.GeniusCat; public interface ICatEntityMixin { - boolean catsplus$hasTotem(); - void catsplus$setTotem(boolean totem); - - int catsplus$getFavorability(PlayerEntity player); - void catsplus$setFavorability(int favorability, PlayerEntity player); - - int catsplus$getLives(); - void catsplus$setLives(int lives); + GeniusCat catsplus$getGeniusCat();; } diff --git a/fabric/src/main/java/cuteneko/catsplus/fabric/mixins/impl/IPlayerEntityMixin.java b/fabric/src/main/java/cuteneko/catsplus/fabric/mixins/impl/IPlayerEntityMixin.java deleted file mode 100644 index 2995f7c..0000000 --- a/fabric/src/main/java/cuteneko/catsplus/fabric/mixins/impl/IPlayerEntityMixin.java +++ /dev/null @@ -1,11 +0,0 @@ -package cuteneko.catsplus.fabric.mixins.impl; - -import net.minecraft.entity.passive.CatEntity; - -public interface IPlayerEntityMixin { - CatEntity catsplus$getCatEntity(); - void catsplus$setCatEntity(CatEntity cat); - - boolean catsplus$isCat(); - void catsplus$setCat(boolean cat); -} diff --git a/fabric/src/main/java/cuteneko/catsplus/fabric/mixins/mixin/CatEntityMixin.java b/fabric/src/main/java/cuteneko/catsplus/fabric/mixins/mixin/CatEntityMixin.java deleted file mode 100644 index b837801..0000000 --- a/fabric/src/main/java/cuteneko/catsplus/fabric/mixins/mixin/CatEntityMixin.java +++ /dev/null @@ -1,102 +0,0 @@ -package cuteneko.catsplus.fabric.mixins.mixin; - -import cuteneko.catsplus.fabric.mixins.impl.ICatEntityMixin; -import cuteneko.catsplus.utility.Constants; -import net.minecraft.entity.passive.CatEntity; -import net.minecraft.entity.player.PlayerEntity; -import net.minecraft.nbt.NbtCompound; -import net.minecraft.nbt.NbtElement; -import net.minecraft.nbt.NbtList; -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 java.util.HashMap; -import java.util.Map; -import java.util.UUID; - -@Mixin(CatEntity.class) -public abstract class CatEntityMixin implements ICatEntityMixin { - @Unique - private int catsplus$lives = 0; - @Unique - private boolean catsplus$hasTotem = false; - - @Unique - private final Map catsplus$favorability = new HashMap<>(); - - @Override - public boolean catsplus$hasTotem() { - return catsplus$hasTotem; - } - - @Override - public void catsplus$setTotem(boolean totem) { - catsplus$hasTotem = totem; - } - - @Override - public int catsplus$getFavorability(PlayerEntity player) { - if (!catsplus$favorability.containsKey(player.getUuid())) { - catsplus$favorability.put(player.getUuid(), 0); - } - - return catsplus$favorability.get(player.getUuid()); - } - - @Override - public void catsplus$setFavorability(int favorability, PlayerEntity player) { - catsplus$favorability.put(player.getUuid(), favorability); - } - - @Override - public int catsplus$getLives() { - return catsplus$lives; - } - - @Override - public void catsplus$setLives(int lives) { - catsplus$lives = lives; - } - - @Inject(method = "writeCustomDataToNbt", at = @At("HEAD")) - private void write(NbtCompound nbt, CallbackInfo ci) { - var tag = new NbtCompound(); - - tag.putInt(Constants.TAG_GENIUS_CAT_LIVES, catsplus$lives); - tag.putBoolean(Constants.TAG_GENIUS_CAT_TOTEM, catsplus$hasTotem); - - var favorability = new NbtList(); - for (var entry : catsplus$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); - - nbt.put(Constants.CAP_GENIUS_CAT.toString(), tag); - } - - @Inject(method = "readCustomDataFromNbt", at = @At("HEAD")) - private void read(NbtCompound nbt, CallbackInfo ci) { - var tag = nbt.getCompound(Constants.CAP_GENIUS_CAT.toString()); - - catsplus$lives = tag.getInt(Constants.TAG_GENIUS_CAT_LIVES); - catsplus$hasTotem = 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); - - catsplus$favorability.put(uuid, value); - } - } - } -} diff --git a/fabric/src/main/java/cuteneko/catsplus/fabric/mixins/mixin/CatMixin.java b/fabric/src/main/java/cuteneko/catsplus/fabric/mixins/mixin/CatMixin.java new file mode 100644 index 0000000..ee49fd6 --- /dev/null +++ b/fabric/src/main/java/cuteneko/catsplus/fabric/mixins/mixin/CatMixin.java @@ -0,0 +1,47 @@ +package cuteneko.catsplus.fabric.mixins.mixin; + +import cuteneko.catsplus.data.entity.GeniusCat; +import cuteneko.catsplus.fabric.mixins.impl.ICatEntityMixin; +import cuteneko.catsplus.utility.ModConstants; +import net.minecraft.nbt.CompoundTag; +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.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 CatMixin extends TamableAnimal implements ICatEntityMixin { + + @Unique + private GeniusCat catsplus$geniusCat; + + protected CatMixin(EntityType entityType, Level level) { + super(entityType, level); + } + + @Inject(method = "", at = @At("TAIL")) + private void catsplus$init(EntityType entityType, Level level, CallbackInfo ci) { + catsplus$geniusCat = new GeniusCat((Cat) (Object) this); + } + + @Inject(method = "addAdditionalSaveData", at = @At("HEAD")) + private void catsplus$addAdditionalSaveData(CompoundTag compound, CallbackInfo ci) { + compound.put(ModConstants.TAG_GENIUS_CAT, catsplus$geniusCat.serializeTag(level().registryAccess())); + } + + @Inject(method = "readAdditionalSaveData", at = @At("HEAD")) + private void read(CompoundTag compound, CallbackInfo ci) { + var tag = compound.getCompound(ModConstants.TAG_GENIUS_CAT); + catsplus$geniusCat.deserializeTag(tag, level().registryAccess()); + } + + @Unique + public GeniusCat getCatsplus$geniusCat() { + return catsplus$geniusCat; + } +} diff --git a/fabric/src/main/java/cuteneko/catsplus/fabric/mixins/mixin/PlayerEntityMixin.java b/fabric/src/main/java/cuteneko/catsplus/fabric/mixins/mixin/PlayerEntityMixin.java deleted file mode 100644 index 0246fd7..0000000 --- a/fabric/src/main/java/cuteneko/catsplus/fabric/mixins/mixin/PlayerEntityMixin.java +++ /dev/null @@ -1,102 +0,0 @@ -package cuteneko.catsplus.fabric.mixins.mixin; - -import cuteneko.catsplus.fabric.mixins.impl.IPlayerEntityMixin; -import cuteneko.catsplus.utility.Constants; -import net.minecraft.entity.EntityType; -import net.minecraft.entity.LivingEntity; -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.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; - -@Mixin(PlayerEntity.class) -public abstract class PlayerEntityMixin extends LivingEntity implements IPlayerEntityMixin { - @Unique - private CatEntity catsplus$catEntity = null; - - @Unique - private boolean catsplus$isCat = false; - - protected PlayerEntityMixin(EntityType entityType, World world) { - super(entityType, world); - } - - @Override - public CatEntity catsplus$getCatEntity() { - if (catsplus$catEntity == null) { - int variant = (int) (uuid.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); - }; - - catsplus$catEntity = EntityType.CAT.create(getWorld()); - - if (catsplus$catEntity != null) { - catsplus$catEntity.setVariant(Registries.CAT_VARIANT.get(key)); - } - - } - - return this.catsplus$catEntity; - } - - @Override - public void catsplus$setCatEntity(CatEntity cat) { - catsplus$catEntity = cat; - } - - @Override - public boolean catsplus$isCat() { - return catsplus$isCat; - } - - @Override - public void catsplus$setCat(boolean cat) { - catsplus$isCat = cat; - } - - @Inject(method = "writeCustomDataToNbt", at = @At("HEAD")) - private void write(NbtCompound nbt, CallbackInfo ci) { - var tag = new NbtCompound(); - - var catTag = new NbtCompound(); - catsplus$getCatEntity().saveNbt(catTag); - tag.put(Constants.TAG_CAT_PLAYER_INNER_CAT, catTag); - - tag.putBoolean(Constants.TAG_CAT_PLAYER_IS_CAT, catsplus$isCat); - - nbt.put(Constants.CAP_CAT_PLAYER.toString(), tag); - } - - @Inject(method = "readCustomDataFromNbt", at = @At("HEAD")) - private void read(NbtCompound nbt, CallbackInfo ci) { - var tag = nbt.getCompound(Constants.CAP_CAT_PLAYER.toString()); - - var catTag = tag.getCompound(Constants.TAG_CAT_PLAYER_INNER_CAT); - catsplus$getCatEntity().readNbt(catTag); - catsplus$isCat = tag.getBoolean(Constants.TAG_CAT_PLAYER_IS_CAT); - } -} diff --git a/fabric/src/main/resources/catsplus-fabric.mixins.json b/fabric/src/main/resources/catsplus-fabric.mixins.json index fc32d28..7f0e985 100644 --- a/fabric/src/main/resources/catsplus-fabric.mixins.json +++ b/fabric/src/main/resources/catsplus-fabric.mixins.json @@ -4,8 +4,7 @@ "package": "cuteneko.catsplus.fabric.mixins.mixin", "compatibilityLevel": "JAVA_17", "mixins": [ - "CatEntityMixin", - "PlayerEntityMixin" + "CatMixin" ], "client": [ ], diff --git a/fabric/src/main/resources/fabric.mod.json b/fabric/src/main/resources/fabric.mod.json index ac5e3a8..4c8c088 100644 --- a/fabric/src/main/resources/fabric.mod.json +++ b/fabric/src/main/resources/fabric.mod.json @@ -19,7 +19,7 @@ "environment": "*", "entrypoints": { "client": [ - "cuteneko.catsplus.fabric.CatsPlusFabric" + "cuteneko.catsplus.fabric.client.CatsPlusFabricClient" ], "main": [ "cuteneko.catsplus.fabric.CatsPlusFabric" @@ -33,9 +33,9 @@ "catsplus-fabric.mixins.json" ], "depends": { - "fabricloader": ">=${fabric_loader_version}", - "fabric": "*", - "minecraft": ">=${minecraft_version}", - "architectury": ">=${architectury_version}" + "minecraft": "${fabric_minecraft_version_range}", + "fabricloader": "${fabric_loader_version_range}", + "fabric": "${fabric_api_version_range}", + "architectury": "${fabric_architectury_version_range}" } } diff --git a/forge/src/main/java/cuteneko/catsplus/forge/CatsPlusDataImpl.java b/forge/src/main/java/cuteneko/catsplus/forge/CatsPlusDataImpl.java index e19dcb5..a14b2e8 100644 --- a/forge/src/main/java/cuteneko/catsplus/forge/CatsPlusDataImpl.java +++ b/forge/src/main/java/cuteneko/catsplus/forge/CatsPlusDataImpl.java @@ -1,8 +1,8 @@ -package cuteneko.catsplus.forge; +package cuteneko.catsplus.neoforge; import cuteneko.catsplus.data.ICatPlayer; import cuteneko.catsplus.data.IGeniusCat; -import cuteneko.catsplus.forge.capability.ModCapabilities; +import cuteneko.catsplus.neoforge.data.ModCapabilities; import net.minecraft.entity.passive.CatEntity; import net.minecraft.entity.player.PlayerEntity; diff --git a/forge/src/main/java/cuteneko/catsplus/forge/CatsPlusForge.java b/forge/src/main/java/cuteneko/catsplus/forge/CatsPlusForge.java index cc7970d..1ace4f4 100644 --- a/forge/src/main/java/cuteneko/catsplus/forge/CatsPlusForge.java +++ b/forge/src/main/java/cuteneko/catsplus/forge/CatsPlusForge.java @@ -1,4 +1,4 @@ -package cuteneko.catsplus.forge; +package cuteneko.catsplus.neoforge; import cuteneko.catsplus.CatsPlus; import dev.architectury.platform.forge.EventBuses; diff --git a/forge/src/main/java/cuteneko/catsplus/forge/capability/CatPlayerCapability.java b/forge/src/main/java/cuteneko/catsplus/forge/capability/CatPlayerCapability.java index 34a923e..59cfec3 100644 --- a/forge/src/main/java/cuteneko/catsplus/forge/capability/CatPlayerCapability.java +++ b/forge/src/main/java/cuteneko/catsplus/forge/capability/CatPlayerCapability.java @@ -1,4 +1,4 @@ -package cuteneko.catsplus.forge.capability; +package cuteneko.catsplus.neoforge.data; import cuteneko.catsplus.data.ICatPlayer; import cuteneko.catsplus.utility.Constants; diff --git a/forge/src/main/java/cuteneko/catsplus/forge/capability/GeniusCatCapability.java b/forge/src/main/java/cuteneko/catsplus/forge/capability/GeniusCatCapability.java index 6288163..3f0d99c 100644 --- a/forge/src/main/java/cuteneko/catsplus/forge/capability/GeniusCatCapability.java +++ b/forge/src/main/java/cuteneko/catsplus/forge/capability/GeniusCatCapability.java @@ -1,4 +1,4 @@ -package cuteneko.catsplus.forge.capability; +package cuteneko.catsplus.neoforge.data; import cuteneko.catsplus.data.IGeniusCat; import cuteneko.catsplus.utility.Constants; diff --git a/forge/src/main/java/cuteneko/catsplus/forge/capability/ModCapabilities.java b/forge/src/main/java/cuteneko/catsplus/forge/capability/ModCapabilities.java index 9f1286f..2edf4bf 100644 --- a/forge/src/main/java/cuteneko/catsplus/forge/capability/ModCapabilities.java +++ b/forge/src/main/java/cuteneko/catsplus/forge/capability/ModCapabilities.java @@ -1,10 +1,10 @@ -package cuteneko.catsplus.forge.capability; +package cuteneko.catsplus.neoforge.data; import cuteneko.catsplus.CatsPlus; import cuteneko.catsplus.data.ICatPlayer; import cuteneko.catsplus.data.IGeniusCat; -import cuteneko.catsplus.forge.capability.provider.CatPlayerProvider; -import cuteneko.catsplus.forge.capability.provider.GeniusCatProvider; +import cuteneko.catsplus.neoforge.data.provider.CatPlayerProvider; +import cuteneko.catsplus.neoforge.data.provider.GeniusCatProvider; import cuteneko.catsplus.utility.Constants; import net.minecraft.entity.Entity; import net.minecraft.entity.passive.CatEntity; diff --git a/forge/src/main/java/cuteneko/catsplus/forge/capability/provider/CatPlayerProvider.java b/forge/src/main/java/cuteneko/catsplus/forge/capability/provider/CatPlayerProvider.java index 576780d..72f55c8 100644 --- a/forge/src/main/java/cuteneko/catsplus/forge/capability/provider/CatPlayerProvider.java +++ b/forge/src/main/java/cuteneko/catsplus/forge/capability/provider/CatPlayerProvider.java @@ -1,8 +1,8 @@ -package cuteneko.catsplus.forge.capability.provider; +package cuteneko.catsplus.neoforge.data.provider; -import cuteneko.catsplus.forge.capability.CatPlayerCapability; -import cuteneko.catsplus.forge.capability.GeniusCatCapability; -import cuteneko.catsplus.forge.capability.ModCapabilities; +import cuteneko.catsplus.neoforge.data.CatPlayerCapability; +import cuteneko.catsplus.neoforge.data.GeniusCatCapability; +import cuteneko.catsplus.neoforge.data.ModCapabilities; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.nbt.NbtCompound; import net.minecraft.util.math.Direction; diff --git a/forge/src/main/java/cuteneko/catsplus/forge/capability/provider/GeniusCatProvider.java b/forge/src/main/java/cuteneko/catsplus/forge/capability/provider/GeniusCatProvider.java index 47a62b3..50ab6d4 100644 --- a/forge/src/main/java/cuteneko/catsplus/forge/capability/provider/GeniusCatProvider.java +++ b/forge/src/main/java/cuteneko/catsplus/forge/capability/provider/GeniusCatProvider.java @@ -1,7 +1,7 @@ -package cuteneko.catsplus.forge.capability.provider; +package cuteneko.catsplus.neoforge.data.provider; -import cuteneko.catsplus.forge.capability.GeniusCatCapability; -import cuteneko.catsplus.forge.capability.ModCapabilities; +import cuteneko.catsplus.neoforge.data.GeniusCatCapability; +import cuteneko.catsplus.neoforge.data.ModCapabilities; import net.minecraft.nbt.NbtCompound; import net.minecraft.util.math.Direction; import net.minecraftforge.common.capabilities.Capability; diff --git a/neoforge/src/main/java/cuteneko/catsplus/forge/CatsPlusDataImpl.java b/neoforge/src/main/java/cuteneko/catsplus/forge/CatsPlusDataImpl.java deleted file mode 100644 index d4c132a..0000000 --- a/neoforge/src/main/java/cuteneko/catsplus/forge/CatsPlusDataImpl.java +++ /dev/null @@ -1,17 +0,0 @@ -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 deleted file mode 100644 index cc7970d..0000000 --- a/neoforge/src/main/java/cuteneko/catsplus/forge/CatsPlusForge.java +++ /dev/null @@ -1,33 +0,0 @@ -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 deleted file mode 100644 index 34a923e..0000000 --- a/neoforge/src/main/java/cuteneko/catsplus/forge/capability/CatPlayerCapability.java +++ /dev/null @@ -1,88 +0,0 @@ -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 deleted file mode 100644 index 7dcf262..0000000 --- a/neoforge/src/main/java/cuteneko/catsplus/forge/capability/GeniusCatCapability.java +++ /dev/null @@ -1,92 +0,0 @@ -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 deleted file mode 100644 index a93da94..0000000 --- a/neoforge/src/main/java/cuteneko/catsplus/forge/capability/ModCapabilities.java +++ /dev/null @@ -1,59 +0,0 @@ -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 deleted file mode 100644 index 576780d..0000000 --- a/neoforge/src/main/java/cuteneko/catsplus/forge/capability/provider/CatPlayerProvider.java +++ /dev/null @@ -1,47 +0,0 @@ -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 deleted file mode 100644 index 47a62b3..0000000 --- a/neoforge/src/main/java/cuteneko/catsplus/forge/capability/provider/GeniusCatProvider.java +++ /dev/null @@ -1,38 +0,0 @@ -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/java/cuteneko/catsplus/neoforge/CatsPlusDataImpl.java b/neoforge/src/main/java/cuteneko/catsplus/neoforge/CatsPlusDataImpl.java new file mode 100644 index 0000000..bf1036a --- /dev/null +++ b/neoforge/src/main/java/cuteneko/catsplus/neoforge/CatsPlusDataImpl.java @@ -0,0 +1,11 @@ +package cuteneko.catsplus.neoforge; + +import cuteneko.catsplus.data.entity.GeniusCat; +import cuteneko.catsplus.neoforge.data.ModAttachment; +import net.minecraft.world.entity.animal.Cat; + +public class CatsPlusDataImpl { + public static GeniusCat getGeniusCat(Cat cat) { + return cat.getData(ModAttachment.GENIUS_CAT); + } +} diff --git a/neoforge/src/main/java/cuteneko/catsplus/neoforge/CatsPlusNeoForge.java b/neoforge/src/main/java/cuteneko/catsplus/neoforge/CatsPlusNeoForge.java new file mode 100644 index 0000000..df83c02 --- /dev/null +++ b/neoforge/src/main/java/cuteneko/catsplus/neoforge/CatsPlusNeoForge.java @@ -0,0 +1,21 @@ +package cuteneko.catsplus.neoforge; + +import cuteneko.catsplus.CatsPlus; +import cuteneko.catsplus.client.CatsPlusClient; +import net.neoforged.bus.api.IEventBus; +import net.neoforged.fml.common.Mod; +import net.neoforged.fml.event.lifecycle.FMLClientSetupEvent; + +@Mod(CatsPlus.MODID) +public class CatsPlusNeoForge { + + public CatsPlusNeoForge(IEventBus bus) { + CatsPlus.init(); + + bus.addListener(this::onClientSetup); + } + + public void onClientSetup(FMLClientSetupEvent event) { + event.enqueueWork(CatsPlusClient::initClient); + } +} diff --git a/neoforge/src/main/java/cuteneko/catsplus/neoforge/data/GeniusCatNeoForge.java b/neoforge/src/main/java/cuteneko/catsplus/neoforge/data/GeniusCatNeoForge.java new file mode 100644 index 0000000..1cf314b --- /dev/null +++ b/neoforge/src/main/java/cuteneko/catsplus/neoforge/data/GeniusCatNeoForge.java @@ -0,0 +1,24 @@ +package cuteneko.catsplus.neoforge.data; + +import cuteneko.catsplus.data.entity.GeniusCat; +import net.minecraft.core.HolderLookup; +import net.minecraft.nbt.CompoundTag; +import net.minecraft.world.entity.animal.Cat; +import net.neoforged.neoforge.common.util.INBTSerializable; +import org.jetbrains.annotations.NotNull; + +public class GeniusCatNeoForge extends GeniusCat implements INBTSerializable { + public GeniusCatNeoForge(Cat cat) { + super(cat); + } + + @Override + public @NotNull CompoundTag serializeNBT(HolderLookup.@NotNull Provider registries) { + return super.serializeTag(registries); + } + + @Override + public void deserializeNBT(HolderLookup.@NotNull Provider registries, @NotNull CompoundTag tag) { + super.deserializeTag(tag, registries); + } +} diff --git a/neoforge/src/main/java/cuteneko/catsplus/neoforge/data/ModAttachment.java b/neoforge/src/main/java/cuteneko/catsplus/neoforge/data/ModAttachment.java new file mode 100644 index 0000000..7cb43c1 --- /dev/null +++ b/neoforge/src/main/java/cuteneko/catsplus/neoforge/data/ModAttachment.java @@ -0,0 +1,19 @@ +package cuteneko.catsplus.neoforge.data; + +import cuteneko.catsplus.CatsPlus; +import net.minecraft.world.entity.animal.Cat; +import net.neoforged.fml.common.EventBusSubscriber; +import net.neoforged.neoforge.attachment.AttachmentType; +import net.neoforged.neoforge.registries.DeferredRegister; +import net.neoforged.neoforge.registries.NeoForgeRegistries; + +import java.util.function.Supplier; + +@EventBusSubscriber(modid = CatsPlus.MODID, bus = EventBusSubscriber.Bus.GAME) +public class ModAttachment { + private static final DeferredRegister> REGISTRY = DeferredRegister.create(NeoForgeRegistries.ATTACHMENT_TYPES, CatsPlus.MODID); + + public static final Supplier> GENIUS_CAT = REGISTRY.register("genius_cat", () -> AttachmentType + .serializable(holder -> holder instanceof Cat cat ? new GeniusCatNeoForge(cat) : null) + .build()); +} diff --git a/neoforge/src/main/resources/META-INF/mods.toml b/neoforge/src/main/resources/META-INF/mods.toml index ab3df94..1d83d4c 100644 --- a/neoforge/src/main/resources/META-INF/mods.toml +++ b/neoforge/src/main/resources/META-INF/mods.toml @@ -1,5 +1,5 @@ modLoader="javafml" -loaderVersion="[${forge_loader_version},)" +loaderVersion="${neoforge_loader_version_range}" license="MIT" issueTrackerURL="https://github.com/CuteNekoOwO/CatsPlus/issues" @@ -17,22 +17,22 @@ Make cats in Minecraft more fun! ''' [[dependencies.catsplus]] - modId="forge" + modId="neoforge" mandatory=true - versionRange="[${forge_version},)" + versionRange="${neoforge_version_range}" ordering="NONE" side="BOTH" [[dependencies.catsplus]] modId="minecraft" mandatory=true - versionRange="[${minecraft_version},)" + versionRange="${neoforge_minecraft_version_range}" ordering="NONE" side="BOTH" [[dependencies.catsplus]] modId="architectury" mandatory=true - versionRange="[${architectury_version},)" + versionRange="${neoforge_architectury_version_range}" ordering="NONE" side="BOTH" diff --git a/neoforge/src/main/resources/pack.mcmeta b/neoforge/src/main/resources/pack.mcmeta index ad66130..9517037 100644 --- a/neoforge/src/main/resources/pack.mcmeta +++ b/neoforge/src/main/resources/pack.mcmeta @@ -3,6 +3,6 @@ "description": { "text": "Cats+ resources" }, - "pack_format": 15 + "pack_format": 34 } } diff --git a/src/generated/resources/assets/catsplus/lang/en_us.json b/src/generated/resources/assets/catsplus/lang/en_us.json new file mode 100644 index 0000000..77e87ee --- /dev/null +++ b/src/generated/resources/assets/catsplus/lang/en_us.json @@ -0,0 +1,23 @@ +{ + "block.catsplus.cat_resurrection_station": "Cat Resurrection Station", + "effect.catsplus.cattify": "Cattify", + "item.catsplus.cat_bag": "Cat Bag", + "item.catsplus.cat_bag.desc.has_cat": "Cat Inside!", + "item.catsplus.cat_bag.desc.has_named_cat": "%1$s Inside!", + "item.catsplus.cat_bag.desc.no_cat": "Empty.", + "item.catsplus.cat_spirit": "Cat Spirit", + "item.catsplus.cat_spirit.desc.long_time_ago": "Long time ago", + "item.catsplus.cat_spirit.desc.message": "", + "item.catsplus.cat_spirit.desc.time_label": "Dead at: ", + "item.catsplus.cat_spirit.desc.time_pattern": "%2$s/%3$s/%1$s %4$s:%5$s:%6$s", + "item.catsplus.cat_spirit.with_name": "Spirit of %1$s", + "item.catsplus.fang_luo": "Doll of Fang_Luo", + "item.catsplus.fang_luo.desc.1": "In memory of Fang_Luo, a girl who passed away because of cancer.", + "item.catsplus.fang_luo.desc.2": "Rest in peace, my friend.", + "item.catsplus.totemeow": "Totemeow", + "item.minecraft.lingering_potion.effect.cattify": "Lingering Potion of Cattify", + "item.minecraft.potion.effect.cattify": "Potion of Cattify", + "item.minecraft.splash_potion.effect.cattify": "Splash Potion of Cattify", + "item.minecraft.tipped_arrow.effect.cattify": "Arrow of Cattify", + "itemGroup.catsplus.catsplus_group": "Cats+!" +} \ No newline at end of file diff --git a/src/generated/resources/assets/catsplus/lang/zh_cn.json b/src/generated/resources/assets/catsplus/lang/zh_cn.json new file mode 100644 index 0000000..07090a9 --- /dev/null +++ b/src/generated/resources/assets/catsplus/lang/zh_cn.json @@ -0,0 +1,23 @@ +{ + "block.catsplus.cat_resurrection_station": "猫咪复活台", + "effect.catsplus.cattify": "猫咪化", + "item.catsplus.cat_bag": "猫包", + "item.catsplus.cat_bag.desc.has_cat": "内含猫猫!", + "item.catsplus.cat_bag.desc.has_named_cat": "%1$s 在里面!", + "item.catsplus.cat_bag.desc.no_cat": "空的。", + "item.catsplus.cat_spirit": "猫魂", + "item.catsplus.cat_spirit.desc.long_time_ago": "很久以前", + "item.catsplus.cat_spirit.desc.message": "", + "item.catsplus.cat_spirit.desc.time_label": "卒于:", + "item.catsplus.cat_spirit.desc.time_pattern": "%1$s年%2$s月%3$s日 %4$s:%5$s:%6$s", + "item.catsplus.cat_spirit.with_name": "%1$s 的灵魂", + "item.catsplus.fang_luo": "坊洛玩偶", + "item.catsplus.fang_luo.desc.1": "纪念因肿瘤离去的坊洛。", + "item.catsplus.fang_luo.desc.2": "缅怀……", + "item.catsplus.totemeow": "不死猫腾", + "item.minecraft.lingering_potion.effect.cattify": "滞留型变猫药水", + "item.minecraft.potion.effect.cattify": "变猫药水", + "item.minecraft.splash_potion.effect.cattify": "喷溅型变猫药水", + "item.minecraft.tipped_arrow.effect.cattify": "变猫药水箭", + "itemGroup.catsplus.catsplus_group": "Cats+!" +} \ No newline at end of file diff --git a/src/generated/resources/assets/catsplus/models/item/totemeow.json b/src/generated/resources/assets/catsplus/models/item/totemeow.json new file mode 100644 index 0000000..fab43c3 --- /dev/null +++ b/src/generated/resources/assets/catsplus/models/item/totemeow.json @@ -0,0 +1,6 @@ +{ + "parent": "minecraft:item/generated", + "textures": { + "layer0": "catsplus:item/totemeow" + } +} \ No newline at end of file diff --git a/src/main/generated/data/catsplus/advancements/recipes/tools/cat_bag.json b/src/generated/resources/data/catsplus/advancements/recipes/tools/cat_bag.json similarity index 100% rename from src/main/generated/data/catsplus/advancements/recipes/tools/cat_bag.json rename to src/generated/resources/data/catsplus/advancements/recipes/tools/cat_bag.json diff --git a/src/main/generated/data/catsplus/advancements/recipes/tools/totemeow.json b/src/generated/resources/data/catsplus/advancements/recipes/tools/totemeow.json similarity index 100% rename from src/main/generated/data/catsplus/advancements/recipes/tools/totemeow.json rename to src/generated/resources/data/catsplus/advancements/recipes/tools/totemeow.json diff --git a/src/main/generated/data/catsplus/recipes/cat_bag.json b/src/generated/resources/data/catsplus/recipes/cat_bag.json similarity index 100% rename from src/main/generated/data/catsplus/recipes/cat_bag.json rename to src/generated/resources/data/catsplus/recipes/cat_bag.json diff --git a/src/main/generated/data/catsplus/recipes/totemeow.json b/src/generated/resources/data/catsplus/recipes/totemeow.json similarity index 100% rename from src/main/generated/data/catsplus/recipes/totemeow.json rename to src/generated/resources/data/catsplus/recipes/totemeow.json diff --git a/src/main/generated/data/catsplus/tags/items/cooked_fishes.json b/src/generated/resources/data/catsplus/tags/items/cooked_fishes.json similarity index 100% rename from src/main/generated/data/catsplus/tags/items/cooked_fishes.json rename to src/generated/resources/data/catsplus/tags/items/cooked_fishes.json diff --git a/src/main/generated/.cache/15e558425d03769b4c939a16ffd55f843ac56d0f b/src/main/generated/.cache/15e558425d03769b4c939a16ffd55f843ac56d0f index 61e416a..1755cdc 100644 --- a/src/main/generated/.cache/15e558425d03769b4c939a16ffd55f843ac56d0f +++ b/src/main/generated/.cache/15e558425d03769b4c939a16ffd55f843ac56d0f @@ -1,2 +1,2 @@ -// 1.20.4 2024-02-21T21:16:16.496054 Cats+/Language (en_us) -d6583927b847b4b2a3794090b7ac5fceccb13c82 assets\catsplus\lang\en_us.json +// 1.21.1 2024-12-19T20:49:40.2540232 Cats+/Language (en_us) +4c954a23ddc8e4a06ac36b5dd90df1616bbb774f assets\catsplus\lang\en_us.json diff --git a/src/main/generated/.cache/49e5c65ca1ab59f598f710846fb0f8d549021d95 b/src/main/generated/.cache/49e5c65ca1ab59f598f710846fb0f8d549021d95 index 9086c0d..f36ab33 100644 --- a/src/main/generated/.cache/49e5c65ca1ab59f598f710846fb0f8d549021d95 +++ b/src/main/generated/.cache/49e5c65ca1ab59f598f710846fb0f8d549021d95 @@ -1,2 +1,2 @@ -// 1.20.4 2024-02-21T21:16:16.4970528 Cats+/Language (zh_cn) -7931bcf23f857507e9bead0a1e1f3d793d6d5915 assets\catsplus\lang\zh_cn.json +// 1.21.1 2024-12-19T20:49:40.2555458 Cats+/Language (zh_cn) +48c49b72a471aa7dc799813b98f69a62d1c6a0dc assets\catsplus\lang\zh_cn.json diff --git a/src/main/generated/.cache/5e79d2cdbf486275146451d641b6d6e823f0432d b/src/main/generated/.cache/5e79d2cdbf486275146451d641b6d6e823f0432d new file mode 100644 index 0000000..65af1af --- /dev/null +++ b/src/main/generated/.cache/5e79d2cdbf486275146451d641b6d6e823f0432d @@ -0,0 +1 @@ +// 1.21.1 2024-12-19T20:49:40.2555458 Cats+/Tags for minecraft:block diff --git a/src/main/generated/.cache/aaa80d5935224bd236f347a63f6c896153bd61b8 b/src/main/generated/.cache/aaa80d5935224bd236f347a63f6c896153bd61b8 index ca11576..ea4976a 100644 --- a/src/main/generated/.cache/aaa80d5935224bd236f347a63f6c896153bd61b8 +++ b/src/main/generated/.cache/aaa80d5935224bd236f347a63f6c896153bd61b8 @@ -1,2 +1,2 @@ -// 1.20.4 2024-02-21T21:16:16.4970528 Cats+/Tags for minecraft:item -491c16568754e85de8983f2660885e26edfb506a data\catsplus\tags\items\cooked_fishes.json +// 1.21.1 2024-12-19T20:49:40.2565329 Cats+/Tags for minecraft:item +bc229f680fa773a41269c1569f5a700f669eb8e5 data\catsplus\tags\item\cooked_fishes.json diff --git a/src/main/generated/.cache/d5ee957bafb940ae78b04b56b65ec8b9002aa9dc b/src/main/generated/.cache/d5ee957bafb940ae78b04b56b65ec8b9002aa9dc index 0003043..635fd12 100644 --- a/src/main/generated/.cache/d5ee957bafb940ae78b04b56b65ec8b9002aa9dc +++ b/src/main/generated/.cache/d5ee957bafb940ae78b04b56b65ec8b9002aa9dc @@ -1,5 +1,5 @@ -// 1.20.4 2024-02-21T21:16:16.4970528 Cats+/Recipes -241ff3a315e1d01731c5b1b8f98108af0ab6656b data\catsplus\advancements\recipes\tools\cat_bag.json -10847e82ba25bc5c21abff40e303a1c023a77613 data\catsplus\recipes\totemeow.json -561f81e965a426c518aba9734d7fb823257b8eb5 data\catsplus\recipes\cat_bag.json -1e78d96156f59459b01f431a870f6a34699012fb data\catsplus\advancements\recipes\tools\totemeow.json +// 1.21.1 2024-12-19T20:49:40.2555458 Cats+/Recipes +1e24c90e0b77a584a20cae12e030f5721fe2de72 data\catsplus\recipe\totemeow.json +bc8eed3e40d27434c01dc0762c38ea6444076bb2 data\catsplus\advancement\recipes\tools\cat_bag.json +d9f24ab4cd89db43509b7cfd2f0719ddbb3d2b2d data\catsplus\advancement\recipes\tools\totemeow.json +42d7ddfe18f0e54b5b8899b35b51d6317bd6746b data\catsplus\recipe\cat_bag.json diff --git a/src/main/generated/.cache/dcf38aaf6b2f28016e34adbe561ad13afee480c8 b/src/main/generated/.cache/dcf38aaf6b2f28016e34adbe561ad13afee480c8 index d78662e..bbe0c1a 100644 --- a/src/main/generated/.cache/dcf38aaf6b2f28016e34adbe561ad13afee480c8 +++ b/src/main/generated/.cache/dcf38aaf6b2f28016e34adbe561ad13afee480c8 @@ -1,2 +1,2 @@ -// 1.20.4 2024-02-21T21:16:16.496054 Cats+/Model Definitions +// 1.21.1 2024-12-19T20:49:40.2545277 Cats+/Model Definitions 882a1bd93aa3b1750ec3f9e2176a49e5561f45a9 assets\catsplus\models\item\totemeow.json diff --git a/src/main/generated/assets/catsplus/lang/en_us.json b/src/main/generated/assets/catsplus/lang/en_us.json index 77e87ee..6fb598d 100644 --- a/src/main/generated/assets/catsplus/lang/en_us.json +++ b/src/main/generated/assets/catsplus/lang/en_us.json @@ -19,5 +19,6 @@ "item.minecraft.potion.effect.cattify": "Potion of Cattify", "item.minecraft.splash_potion.effect.cattify": "Splash Potion of Cattify", "item.minecraft.tipped_arrow.effect.cattify": "Arrow of Cattify", - "itemGroup.catsplus.catsplus_group": "Cats+!" + "itemGroup.catsplus.catsplus_group": "Cats+!", + "message.catsplus.cat_died": "Your cat was died, its spirit back to its loved owner." } \ No newline at end of file diff --git a/src/main/generated/assets/catsplus/lang/zh_cn.json b/src/main/generated/assets/catsplus/lang/zh_cn.json index 07090a9..772858f 100644 --- a/src/main/generated/assets/catsplus/lang/zh_cn.json +++ b/src/main/generated/assets/catsplus/lang/zh_cn.json @@ -19,5 +19,6 @@ "item.minecraft.potion.effect.cattify": "变猫药水", "item.minecraft.splash_potion.effect.cattify": "喷溅型变猫药水", "item.minecraft.tipped_arrow.effect.cattify": "变猫药水箭", - "itemGroup.catsplus.catsplus_group": "Cats+!" + "itemGroup.catsplus.catsplus_group": "Cats+!", + "message.catsplus.cat_died": "你的猫猫死掉了,灵魂回到了主人的身边。" } \ No newline at end of file diff --git a/src/main/generated/data/catsplus/advancement/recipes/tools/cat_bag.json b/src/main/generated/data/catsplus/advancement/recipes/tools/cat_bag.json new file mode 100644 index 0000000..2bf2f1f --- /dev/null +++ b/src/main/generated/data/catsplus/advancement/recipes/tools/cat_bag.json @@ -0,0 +1,43 @@ +{ + "parent": "minecraft:recipes/root", + "criteria": { + "has_glass_pane": { + "conditions": { + "items": [ + { + "items": "minecraft:glass_pane" + } + ] + }, + "trigger": "minecraft:inventory_changed" + }, + "has_leather": { + "conditions": { + "items": [ + { + "items": "minecraft:leather" + } + ] + }, + "trigger": "minecraft:inventory_changed" + }, + "has_the_recipe": { + "conditions": { + "recipe": "catsplus:cat_bag" + }, + "trigger": "minecraft:recipe_unlocked" + } + }, + "requirements": [ + [ + "has_the_recipe", + "has_leather", + "has_glass_pane" + ] + ], + "rewards": { + "recipes": [ + "catsplus:cat_bag" + ] + } +} \ No newline at end of file diff --git a/src/main/generated/data/catsplus/advancement/recipes/tools/totemeow.json b/src/main/generated/data/catsplus/advancement/recipes/tools/totemeow.json new file mode 100644 index 0000000..f895c88 --- /dev/null +++ b/src/main/generated/data/catsplus/advancement/recipes/tools/totemeow.json @@ -0,0 +1,43 @@ +{ + "parent": "minecraft:recipes/root", + "criteria": { + "has_tag_minecraft_fishes": { + "conditions": { + "items": [ + { + "items": "#minecraft:fishes" + } + ] + }, + "trigger": "minecraft:inventory_changed" + }, + "has_the_recipe": { + "conditions": { + "recipe": "catsplus:totemeow" + }, + "trigger": "minecraft:recipe_unlocked" + }, + "has_totem_of_undying": { + "conditions": { + "items": [ + { + "items": "minecraft:totem_of_undying" + } + ] + }, + "trigger": "minecraft:inventory_changed" + } + }, + "requirements": [ + [ + "has_the_recipe", + "has_tag_minecraft_fishes", + "has_totem_of_undying" + ] + ], + "rewards": { + "recipes": [ + "catsplus:totemeow" + ] + } +} \ No newline at end of file diff --git a/src/main/generated/data/catsplus/recipe/cat_bag.json b/src/main/generated/data/catsplus/recipe/cat_bag.json new file mode 100644 index 0000000..68825fc --- /dev/null +++ b/src/main/generated/data/catsplus/recipe/cat_bag.json @@ -0,0 +1,21 @@ +{ + "type": "minecraft:crafting_shaped", + "category": "equipment", + "key": { + "G": { + "item": "minecraft:glass_pane" + }, + "L": { + "item": "minecraft:leather" + } + }, + "pattern": [ + "LLL", + "LGL", + "LLL" + ], + "result": { + "count": 1, + "id": "catsplus:cat_bag" + } +} \ No newline at end of file diff --git a/src/main/generated/data/catsplus/recipe/totemeow.json b/src/main/generated/data/catsplus/recipe/totemeow.json new file mode 100644 index 0000000..77ab47e --- /dev/null +++ b/src/main/generated/data/catsplus/recipe/totemeow.json @@ -0,0 +1,21 @@ +{ + "type": "minecraft:crafting_shaped", + "category": "equipment", + "key": { + "F": { + "tag": "minecraft:fishes" + }, + "T": { + "item": "minecraft:totem_of_undying" + } + }, + "pattern": [ + "FFF", + "FTF", + "FFF" + ], + "result": { + "count": 1, + "id": "catsplus:totemeow" + } +} \ No newline at end of file diff --git a/src/main/generated/data/catsplus/tags/item/cooked_fishes.json b/src/main/generated/data/catsplus/tags/item/cooked_fishes.json new file mode 100644 index 0000000..4e459be --- /dev/null +++ b/src/main/generated/data/catsplus/tags/item/cooked_fishes.json @@ -0,0 +1,6 @@ +{ + "values": [ + "minecraft:cooked_cod", + "minecraft:cooked_salmon" + ] +} \ No newline at end of file diff --git a/src/main/java/cuteneko/catsplus/CatsPlusData.java b/src/main/java/cuteneko/catsplus/CatsPlusData.java index 2925fa8..c9873c5 100644 --- a/src/main/java/cuteneko/catsplus/CatsPlusData.java +++ b/src/main/java/cuteneko/catsplus/CatsPlusData.java @@ -1,7 +1,6 @@ package cuteneko.catsplus; import cuteneko.catsplus.data.entity.GeniusCat; -import cuteneko.catsplus.data.entity.MusicianCat; import dev.architectury.injectables.annotations.ExpectPlatform; import net.minecraft.world.entity.animal.Cat; @@ -10,9 +9,4 @@ public class CatsPlusData { public static GeniusCat getGeniusCat(Cat cat) { throw new AssertionError(); } - - @ExpectPlatform - public static MusicianCat getMusicianCat(Cat cat) { - throw new AssertionError(); - } } diff --git a/src/main/java/cuteneko/catsplus/bridge/IMusicianCat.java b/src/main/java/cuteneko/catsplus/bridge/IMusicianCat.java deleted file mode 100644 index 38e21cb..0000000 --- a/src/main/java/cuteneko/catsplus/bridge/IMusicianCat.java +++ /dev/null @@ -1,8 +0,0 @@ -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/data/ICompoundSerializable.java b/src/main/java/cuteneko/catsplus/data/ICompoundSerializable.java index 9dc9a5c..49f4305 100644 --- a/src/main/java/cuteneko/catsplus/data/ICompoundSerializable.java +++ b/src/main/java/cuteneko/catsplus/data/ICompoundSerializable.java @@ -5,7 +5,7 @@ import org.jetbrains.annotations.NotNull; public interface ICompoundSerializable { - @NotNull CompoundTag serializeNBT(HolderLookup.Provider registries); + @NotNull CompoundTag serializeTag(HolderLookup.Provider registries); - void deserializeNBT(@NotNull CompoundTag tag, HolderLookup.Provider registries); + void deserializeTag(@NotNull CompoundTag tag, HolderLookup.Provider registries); } diff --git a/src/main/java/cuteneko/catsplus/data/component/CatSpirit.java b/src/main/java/cuteneko/catsplus/data/component/CatSpirit.java new file mode 100644 index 0000000..e657c41 --- /dev/null +++ b/src/main/java/cuteneko/catsplus/data/component/CatSpirit.java @@ -0,0 +1,32 @@ +package cuteneko.catsplus.data.component; + +import com.mojang.serialization.Codec; +import com.mojang.serialization.codecs.RecordCodecBuilder; +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 java.time.OffsetDateTime; + +public record CatSpirit(OffsetDateTime time, Component reason) { + public static final Codec CODEC = RecordCodecBuilder.create(instance -> + instance.group( + Codec.STRING.fieldOf("time").forGetter(CatSpirit::getTime), + ComponentSerialization.CODEC.fieldOf("reason").forGetter(CatSpirit::reason) + ).apply(instance, CatSpirit::new)); + + public static final StreamCodec STREAM_CODEC = StreamCodec.composite( + ByteBufCodecs.STRING_UTF8, CatSpirit::getTime, + ComponentSerialization.STREAM_CODEC, CatSpirit::reason, + CatSpirit::new); + + public CatSpirit(String time, Component reason) { + this(OffsetDateTime.parse(time), reason); + } + + public String getTime() { + return time.toString(); + } +} diff --git a/src/main/java/cuteneko/catsplus/data/component/ModComponents.java b/src/main/java/cuteneko/catsplus/data/component/ModComponents.java index 5c7a61e..adca7a2 100644 --- a/src/main/java/cuteneko/catsplus/data/component/ModComponents.java +++ b/src/main/java/cuteneko/catsplus/data/component/ModComponents.java @@ -18,4 +18,10 @@ public static void register() { .persistent(CatContainer.CODEC) .networkSynchronized(CatContainer.STREAM_CODEC) .build()); + + public static final DeferredSupplier> CAT_SPIRIT = REGISTRY.register("cat_spirit", + () -> DataComponentType.builder() + .persistent(CatSpirit.CODEC) + .networkSynchronized(CatSpirit.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 index f07f165..70c0972 100644 --- a/src/main/java/cuteneko/catsplus/data/entity/GeniusCat.java +++ b/src/main/java/cuteneko/catsplus/data/entity/GeniusCat.java @@ -1,8 +1,15 @@ package cuteneko.catsplus.data.entity; import cuteneko.catsplus.data.ICompoundSerializable; +import cuteneko.catsplus.utility.ModConstants; +import cuteneko.catsplus.utility.TagHelper; +import net.minecraft.core.BlockPos; import net.minecraft.core.HolderLookup; import net.minecraft.nbt.CompoundTag; +import net.minecraft.network.syncher.EntityDataAccessor; +import net.minecraft.network.syncher.EntityDataSerializers; +import net.minecraft.network.syncher.SynchedEntityData; +import net.minecraft.world.entity.animal.Cat; import net.minecraft.world.entity.player.Player; import org.jetbrains.annotations.NotNull; @@ -11,16 +18,15 @@ import java.util.UUID; public class GeniusCat implements ICompoundSerializable { - private boolean undyingTotem = false; - public boolean hasTotem() { - return undyingTotem; - } + private final Cat cat; - public void setTotem(boolean totem) { - this.undyingTotem = totem; + public GeniusCat(Cat cat) { + this.cat = cat; } + // + // Cat's intimacies with player, [-100, 100] private final Map intimacies = new HashMap<>(); @@ -40,33 +46,91 @@ public void subIntimacyWith(Player player, int value) { setIntimacyWith(player, getIntimacyWith(player) - value); } + // + + // + + private boolean undyingTotem = false; + + public boolean hasTotem() { + return undyingTotem; + } + + public void setTotem(boolean totem) { + this.undyingTotem = totem; + } + + // + + // + + public static final EntityDataAccessor SOUND_PLAYING = SynchedEntityData.defineId(Cat.class, EntityDataSerializers.BOOLEAN); + + public static final EntityDataAccessor SOUND_SOURCE = SynchedEntityData.defineId(Cat.class, EntityDataSerializers.BLOCK_POS); + + public void setSoundPlaying(BlockPos source) { + if (source != null) { + cat.getEntityData().set(SOUND_PLAYING, true); + cat.getEntityData().set(SOUND_SOURCE, source); + } else { + cat.getEntityData().set(SOUND_PLAYING, false); + } + } + + public void setSoundStopped() { + cat.getEntityData().set(SOUND_PLAYING, false); + } + + public boolean isSoundPlaying() { + return cat.getEntityData().get(SOUND_PLAYING); + } + + public BlockPos getSoundSource() { + return cat.getEntityData().get(SOUND_SOURCE); + } + + // + @Override - public @NotNull CompoundTag serializeNBT(HolderLookup.Provider registries) { + public @NotNull CompoundTag serializeTag(HolderLookup.Provider registries) { var tag = new CompoundTag(); - tag.putBoolean("undyingTotem", hasTotem()); + tag.putBoolean(ModConstants.TAG_GENIUS_CAT_HAS_TOTEM, hasTotem()); var intimaciesTag = new CompoundTag(); for (var entry : this.intimacies.entrySet()) { intimaciesTag.putInt(entry.getKey().toString(), entry.getValue()); } - tag.put("intimacies", intimaciesTag); + tag.put(ModConstants.TAG_GENIUS_CAT_INTIMACIES, intimaciesTag); + + if (isSoundPlaying()) { + tag.put(ModConstants.TAG_GENIUS_CAT_SOUND_SOURCE, TagHelper.saveBlockPos(getSoundSource())); + } else { + tag.remove(ModConstants.TAG_GENIUS_CAT_SOUND_SOURCE); + } return tag; } @Override - public void deserializeNBT(@NotNull CompoundTag tag, HolderLookup.Provider registries) { - if (tag.contains("undyingTotem")) { - setTotem(tag.getBoolean("undyingTotem")); + public void deserializeTag(@NotNull CompoundTag tag, HolderLookup.Provider registries) { + if (tag.contains(ModConstants.TAG_GENIUS_CAT_HAS_TOTEM)) { + setTotem(tag.getBoolean(ModConstants.TAG_GENIUS_CAT_HAS_TOTEM)); } - if (tag.contains("intimacies")) { - var intimaciesTag = tag.getCompound("intimaciesTag"); + if (tag.contains(ModConstants.TAG_GENIUS_CAT_INTIMACIES)) { + var intimaciesTag = tag.getCompound(ModConstants.TAG_GENIUS_CAT_INTIMACIES); for (var e : intimaciesTag.getAllKeys()) { var uuid = UUID.fromString(e); var v = intimaciesTag.getInt(e); this.intimacies.put(uuid, v); } } + + if (tag.contains(ModConstants.TAG_GENIUS_CAT_SOUND_SOURCE)) { + var pos = TagHelper.loadBlockPos(tag.getCompound(ModConstants.TAG_GENIUS_CAT_SOUND_SOURCE)); + if (pos != null) { + setSoundPlaying(pos); + } + } } } diff --git a/src/main/java/cuteneko/catsplus/data/entity/MusicianCat.java b/src/main/java/cuteneko/catsplus/data/entity/MusicianCat.java deleted file mode 100644 index 9d8848a..0000000 --- a/src/main/java/cuteneko/catsplus/data/entity/MusicianCat.java +++ /dev/null @@ -1,34 +0,0 @@ -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/level/LevelWithCats.java b/src/main/java/cuteneko/catsplus/data/level/LevelWithCats.java index ad968d9..67589fd 100644 --- a/src/main/java/cuteneko/catsplus/data/level/LevelWithCats.java +++ b/src/main/java/cuteneko/catsplus/data/level/LevelWithCats.java @@ -1,6 +1,6 @@ package cuteneko.catsplus.data.level; -import cuteneko.catsplus.utility.Constants; +import cuteneko.catsplus.utility.ModConstants; import net.minecraft.core.HolderLookup; import net.minecraft.core.NonNullList; import net.minecraft.nbt.CompoundTag; @@ -23,7 +23,7 @@ public class LevelWithCats extends SavedData { 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"); + return level.getDataStorage().computeIfAbsent(FACTORY, ModConstants.LEVEL_WITH_CATS_FILE_NAME); } private final Map> catSpirits = new HashMap<>(); @@ -37,18 +37,18 @@ private NonNullList getCatSpirits(UUID uuid) { return catSpirits.get(uuid); } - public void addCatSpirit(Player player, ItemStack catSpirit) { - var list = getCatSpiritsByOwner(player); + public void addCatSpirit(UUID owner, ItemStack catSpirit) { + var list = getCatSpiritsByOwner(owner); list.add(catSpirit); setDirty(); } - public NonNullList getCatSpiritsByOwner(Player player) { - return getCatSpirits(player.getUUID()); + public NonNullList getCatSpiritsByOwner(UUID owner) { + return getCatSpirits(owner); } - public void removeCatSpiritsByOwner(Player player) { - catSpirits.remove(player.getUUID()); + public void removeCatSpiritsByOwner(UUID owner) { + catSpirits.remove(owner); setDirty(); } @@ -57,19 +57,15 @@ public void clearCatSpirits() { 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); + var spirits = tag.getList(ModConstants.TAG_SERVER_CAT_SPIRITS, Tag.TAG_COMPOUND); for (var spirit : spirits) { if (spirit instanceof CompoundTag compound) { - var uuid = compound.getUUID(Constants.TAG_UUID); + var uuid = compound.getUUID(ModConstants.TAG_UUID); var value = NonNullList.create(); - ContainerHelper.loadAllItems(compound.getCompound(Constants.TAG_VALUE), value, registries); + ContainerHelper.loadAllItems(compound.getCompound(ModConstants.TAG_VALUE), value, registries); data.catSpirits.put(uuid, value); } } @@ -82,10 +78,10 @@ public static LevelWithCats load(CompoundTag tag, HolderLookup.Provider registri 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)); + e.putUUID(ModConstants.TAG_UUID, entry.getKey()); + e.put(ModConstants.TAG_VALUE, ContainerHelper.saveAllItems(new CompoundTag(), entry.getValue(), registries)); } - tag.put(Constants.TAG_SERVER_CAT_SPIRITS, list); + tag.put(ModConstants.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 d94c712..24ae216 100644 --- a/src/main/java/cuteneko/catsplus/effect/CattifyEffect.java +++ b/src/main/java/cuteneko/catsplus/effect/CattifyEffect.java @@ -1,33 +1,38 @@ package cuteneko.catsplus.effect; +import cuteneko.catsplus.CatsPlus; +import net.minecraft.resources.ResourceLocation; import net.minecraft.world.effect.MobEffect; import net.minecraft.world.effect.MobEffectCategory; +import net.minecraft.world.effect.MobEffects; import net.minecraft.world.entity.LivingEntity; +import net.minecraft.world.entity.ai.attributes.AttributeModifier; +import net.minecraft.world.entity.ai.attributes.Attributes; import net.minecraft.world.entity.animal.Cat; public class CattifyEffect extends MobEffect { + private static final ResourceLocation attributeModifierId = CatsPlus.modLoc("effect.cattify"); + + // Todo: Can see invisible mobs + public CattifyEffect() { super(MobEffectCategory.NEUTRAL, 0xFF9CA8); + addAttributeModifier(Attributes.MAX_HEALTH, attributeModifierId, -0.5, AttributeModifier.Operation.ADD_MULTIPLIED_TOTAL); + addAttributeModifier(Attributes.ATTACK_DAMAGE, attributeModifierId, 0.5, AttributeModifier.Operation.ADD_VALUE); + addAttributeModifier(Attributes.SAFE_FALL_DISTANCE, attributeModifierId, 3, AttributeModifier.Operation.ADD_MULTIPLIED_TOTAL); + addAttributeModifier(Attributes.MOVEMENT_SPEED, attributeModifierId, 0.2, AttributeModifier.Operation.ADD_VALUE); } - // 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 + @Override + public boolean applyEffectTick(LivingEntity entity, int amplifier) { + if (entity instanceof Cat cat) { + return MobEffects.REGENERATION.value().applyEffectTick(entity, 0); + } + return super.applyEffectTick(entity, amplifier); + } -// @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)); -// } + @Override + public boolean shouldApplyEffectTickThisTick(int duration, int amplifier) { + return true; + } } diff --git a/src/main/java/cuteneko/catsplus/effect/ModEffects.java b/src/main/java/cuteneko/catsplus/effect/ModEffects.java index cb5e561..ba8cd02 100644 --- a/src/main/java/cuteneko/catsplus/effect/ModEffects.java +++ b/src/main/java/cuteneko/catsplus/effect/ModEffects.java @@ -3,6 +3,8 @@ import cuteneko.catsplus.CatsPlus; import dev.architectury.registry.registries.DeferredRegister; import dev.architectury.registry.registries.RegistrySupplier; +import net.minecraft.core.Holder; +import net.minecraft.core.registries.BuiltInRegistries; import net.minecraft.core.registries.Registries; import net.minecraft.world.effect.MobEffect; diff --git a/src/main/java/cuteneko/catsplus/effect/potion/ModPotions.java b/src/main/java/cuteneko/catsplus/effect/potion/ModPotions.java index 8c7da6e..af6f659 100644 --- a/src/main/java/cuteneko/catsplus/effect/potion/ModPotions.java +++ b/src/main/java/cuteneko/catsplus/effect/potion/ModPotions.java @@ -15,6 +15,6 @@ public static void register() { REGISTRY.register(); } - 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))); + public static final RegistrySupplier CATTIFY = REGISTRY.register("cattify", () -> new Potion(new MobEffectInstance(ModEffects.CATTIFY, 1800))); + public static final RegistrySupplier LONG_CATTIFY = REGISTRY.register("long_cattify", () -> new Potion("cattify", new MobEffectInstance(ModEffects.CATTIFY, 4800))); } diff --git a/src/main/java/cuteneko/catsplus/item/CatBagItem.java b/src/main/java/cuteneko/catsplus/item/CatBagItem.java index fcc9276..15ac84a 100644 --- a/src/main/java/cuteneko/catsplus/item/CatBagItem.java +++ b/src/main/java/cuteneko/catsplus/item/CatBagItem.java @@ -4,7 +4,8 @@ import cuteneko.catsplus.data.component.ModComponents; import cuteneko.catsplus.item.group.ModItemGroups; import cuteneko.catsplus.utility.ComponentHelper; -import cuteneko.catsplus.utility.Constants; +import cuteneko.catsplus.utility.ModConstants; +import cuteneko.catsplus.utility.ParticleHelper; import net.minecraft.ChatFormatting; import net.minecraft.core.component.DataComponents; import net.minecraft.network.chat.Component; @@ -39,14 +40,14 @@ public CatBagItem() { 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)); + tooltip.add(Component.translatable(ModConstants.MESSAGE_CAT_BAG_DESCRIPTION_NO_CAT).withStyle(ChatFormatting.DARK_GRAY)); return; } if (catContainer.hasCustomName()) { - tooltip.add(Component.translatable(Constants.MESSAGE_CAT_BAG_DESCRIPTION_HAS_NAMED_CAT, catContainer.customName().getString()).withStyle(ChatFormatting.BLUE)); + tooltip.add(Component.translatable(ModConstants.MESSAGE_CAT_BAG_DESCRIPTION_HAS_NAMED_CAT, catContainer.customName().getString()).withStyle(ChatFormatting.BLUE)); } else { - tooltip.add(Component.translatable(Constants.MESSAGE_CAT_BAG_DESCRIPTION_HAS_CAT).withStyle(ChatFormatting.BLUE)); + tooltip.add(Component.translatable(ModConstants.MESSAGE_CAT_BAG_DESCRIPTION_HAS_CAT).withStyle(ChatFormatting.BLUE)); } } @@ -79,7 +80,7 @@ public void appendHoverText(ItemStack stack, TooltipContext context, List tooltip, TooltipFlag tooltipFlag) { + + var catSpirit = ComponentHelper.getCatSpirit(stack); + if (catSpirit != null) { + tooltip.add(catSpirit.reason()); + var time = catSpirit.time(); + tooltip.add(Component.translatable(ModConstants.MESSAGE_CAT_SPIRIT_DESCRIPTION_TIME_LABEL) + .append(Component.translatable(ModConstants.MESSAGE_CAT_SPIRIT_DESCRIPTION_TIME_PATTERN, time.getYear(), time.getMonth().getValue(), time.getDayOfMonth(), time.getHour(), time.getMinute(), time.getSecond()))); + } + + + super.appendHoverText(stack, context, tooltip, tooltipFlag); + } } diff --git a/src/main/java/cuteneko/catsplus/item/FangLuoItem.java b/src/main/java/cuteneko/catsplus/item/FangLuoItem.java index e035853..c028488 100644 --- a/src/main/java/cuteneko/catsplus/item/FangLuoItem.java +++ b/src/main/java/cuteneko/catsplus/item/FangLuoItem.java @@ -1,6 +1,6 @@ package cuteneko.catsplus.item; -import cuteneko.catsplus.utility.Constants; +import cuteneko.catsplus.utility.ModConstants; import net.minecraft.ChatFormatting; import net.minecraft.network.chat.Component; import net.minecraft.world.item.Item; @@ -21,7 +21,7 @@ public FangLuoItem() { public void appendHoverText(ItemStack stack, TooltipContext context, List tooltip, TooltipFlag tooltipFlag) { super.appendHoverText(stack, context, tooltip, tooltipFlag); - 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)); + tooltip.add(Component.translatable(ModConstants.MESSAGE_FANG_LUO_DESCRIPTION_1).withStyle(ChatFormatting.GRAY)); + tooltip.add(Component.translatable(ModConstants.MESSAGE_FANG_LUO_DESCRIPTION_2).withStyle(ChatFormatting.GRAY)); } } diff --git a/src/main/java/cuteneko/catsplus/item/group/ModItemGroups.java b/src/main/java/cuteneko/catsplus/item/group/ModItemGroups.java index d230c07..d60d36b 100644 --- a/src/main/java/cuteneko/catsplus/item/group/ModItemGroups.java +++ b/src/main/java/cuteneko/catsplus/item/group/ModItemGroups.java @@ -2,7 +2,7 @@ import cuteneko.catsplus.CatsPlus; import cuteneko.catsplus.item.ModItems; -import cuteneko.catsplus.utility.Constants; +import cuteneko.catsplus.utility.ModConstants; import dev.architectury.registry.CreativeTabRegistry; import dev.architectury.registry.registries.DeferredRegister; import dev.architectury.registry.registries.RegistrySupplier; @@ -19,5 +19,5 @@ public static void register() { REGISTRY.register(); } - public static final RegistrySupplier CATS_PLUS = REGISTRY.register("catsplus_group", () -> CreativeTabRegistry.create(Component.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(ModConstants.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 b90474d..74f86b8 100644 --- a/src/main/java/cuteneko/catsplus/listener/CatSpiritListener.java +++ b/src/main/java/cuteneko/catsplus/listener/CatSpiritListener.java @@ -1,8 +1,7 @@ package cuteneko.catsplus.listener; -import cuteneko.catsplus.CatsPlusData; import cuteneko.catsplus.data.level.LevelWithCats; -import cuteneko.catsplus.utility.Constants; +import cuteneko.catsplus.utility.ModConstants; import dev.architectury.event.events.common.PlayerEvent; import net.minecraft.network.chat.Component; import net.minecraft.server.level.ServerPlayer; @@ -15,11 +14,11 @@ public CatSpiritListener() { private void onPlayerJoin(ServerPlayer player) { var level = player.serverLevel(); var data = LevelWithCats.getLevelWithCats(level); - var spirits = data.getCatSpiritsByOwner(player); + var spirits = data.getCatSpiritsByOwner(player.getUUID()); for (var spirit : spirits) { player.addItem(spirit); - player.sendSystemMessage(Component.translatable(Constants.MESSAGE_CAT_DIED)); + player.sendSystemMessage(Component.translatable(ModConstants.MESSAGE_CAT_DIED)); } - catServer.clearCatSpiritsByOwner(player); + data.removeCatSpiritsByOwner(player.getUUID()); } } diff --git a/src/main/java/cuteneko/catsplus/mixin/CatEntityMixin.java b/src/main/java/cuteneko/catsplus/mixin/CatEntityMixin.java deleted file mode 100644 index ea9a4c2..0000000 --- a/src/main/java/cuteneko/catsplus/mixin/CatEntityMixin.java +++ /dev/null @@ -1,82 +0,0 @@ -package cuteneko.catsplus.mixin; - -import cuteneko.catsplus.CatsPlusData; -import cuteneko.catsplus.item.ModItems; -import cuteneko.catsplus.utility.GeniusCatHelper; -import net.minecraft.entity.EntityType; -import net.minecraft.entity.passive.CatEntity; -import net.minecraft.entity.passive.TameableEntity; -import net.minecraft.entity.player.PlayerEntity; -import net.minecraft.item.ItemStack; -import net.minecraft.network.packet.s2c.play.EntityPassengersSetS2CPacket; -import net.minecraft.server.network.ServerPlayerEntity; -import net.minecraft.util.ActionResult; -import net.minecraft.util.Hand; -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; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; - -import java.util.Objects; - -@Mixin(CatEntity.class) -public abstract class CatEntityMixin extends TameableEntity { - protected CatEntityMixin(EntityType entityType, World world) { - super(entityType, world); - } - - @Inject(method = "isBreedingItem", at = @At("RETURN"), cancellable = true) - public void isBreedingItem(ItemStack stack, CallbackInfoReturnable cir) { - if (this.isTamed()) { - cir.setReturnValue(GeniusCatHelper.TAMED_CAT_FOODS.test(stack)); - } - } - - @Inject(method = "eat", at = @At("TAIL")) - protected void eat(PlayerEntity player, Hand hand, ItemStack stack, CallbackInfo ci) { - var geniusCat = CatsPlusData.getGeniusCat((CatEntity) (Object) this); - - if (this.isOwner(player)) { - geniusCat.addFavorability(Objects.requireNonNull(stack.getItem().getFoodComponent()).getHunger(), player); - } - } - - @Inject(method = "interactMob", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/passive/CatEntity;setSitting(Z)V"), cancellable = true) - public void invoke$InteractMobSetSitting(PlayerEntity player, Hand hand, CallbackInfoReturnable cir) { - var catPlayer = CatsPlusData.getCatPlayer(player); - var geniusCat = CatsPlusData.getGeniusCat((CatEntity) (Object) this); - - if (player.isSneaking() && !player.hasPassengers() && !catPlayer.isCat()) { - ((ServerPlayerEntity) player).networkHandler.sendPacket(new EntityPassengersSetS2CPacket(this)); - this.setSitting(false); - this.startRiding(player); - ((ServerPlayerEntity) player).networkHandler.sendPacket(new EntityPassengersSetS2CPacket(player)); - cir.setReturnValue(ActionResult.SUCCESS); - cir.cancel(); - return; - } else if (player.getFirstPassenger() == this) { // Not working since you can never click the cat on your head!! - ((ServerPlayerEntity) player).networkHandler.sendPacket(new EntityPassengersSetS2CPacket(this)); - this.stopRiding(); - ((ServerPlayerEntity) player).networkHandler.sendPacket(new EntityPassengersSetS2CPacket(player)); - cir.setReturnValue(ActionResult.SUCCESS); - return; - } - - ItemStack itemStack = player.getStackInHand(hand); - if (itemStack.isOf(ModItems.TOTEMEOW.get()) && !geniusCat.hasTotem()) { - itemStack.decrement(1); - geniusCat.setTotem(true); - player.setStackInHand(hand, itemStack); - cir.setReturnValue(ActionResult.SUCCESS); - cir.cancel(); - } - } - - @Inject(method = "interactMob", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/passive/CatEntity;setOwner(Lnet/minecraft/entity/player/PlayerEntity;)V")) - public void invokeInteractMobSetOwner(PlayerEntity player, Hand hand, CallbackInfoReturnable cir) { - var geniusCat = CatsPlusData.getGeniusCat((CatEntity) (Object) this); - geniusCat.setFavorability(50, player); - } -} diff --git a/src/main/java/cuteneko/catsplus/mixin/CatMixin.java b/src/main/java/cuteneko/catsplus/mixin/CatMixin.java new file mode 100644 index 0000000..cdf503c --- /dev/null +++ b/src/main/java/cuteneko/catsplus/mixin/CatMixin.java @@ -0,0 +1,82 @@ +package cuteneko.catsplus.mixin; + +import cuteneko.catsplus.CatsPlusData; +import cuteneko.catsplus.item.ModItems; +import cuteneko.catsplus.tag.ModItemTags; +import cuteneko.catsplus.utility.CattifyHelper; +import net.minecraft.core.component.DataComponents; +import net.minecraft.world.InteractionHand; +import net.minecraft.world.InteractionResult; +import net.minecraft.world.entity.EntityType; +import net.minecraft.world.entity.TamableAnimal; +import net.minecraft.world.entity.animal.Cat; +import net.minecraft.world.entity.player.Player; +import net.minecraft.world.item.ItemStack; +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; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; + +@Mixin(Cat.class) +public abstract class CatMixin extends TamableAnimal { + + protected CatMixin(EntityType entityType, Level level) { + super(entityType, level); + } + + @Inject(method = "isFood", at = @At("RETURN"), cancellable = true) + public void catsplus$isFood(ItemStack stack, CallbackInfoReturnable cir) { + if (this.isTame()) { + cir.setReturnValue(stack.is(ModItemTags.COOKED_FISHES)); + } + } + + @Inject(method = "usePlayerItem", at = @At("TAIL")) + protected void catsplus$eat(Player player, InteractionHand hand, ItemStack stack, CallbackInfo ci) { + var geniusCat = CatsPlusData.getGeniusCat((Cat) (Object) this); + + var intimacy = 1; + + var food = stack.get(DataComponents.FOOD); + if (food != null) { + intimacy *= food.nutrition(); + } + + if (this.isOwnedBy(player)) { + intimacy *= 2; + } + + geniusCat.addIntimacyWith(player, intimacy); + } + + @Inject(method = "mobInteract", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/animal/Cat;setOrderedToSit(Z)V"), cancellable = true) + public void catsplus$mobInteract(Player player, InteractionHand hand, CallbackInfoReturnable cir) { + var geniusCat = CatsPlusData.getGeniusCat((Cat) (Object) this); + + if (player.isShiftKeyDown() && !player.isVehicle() && !CattifyHelper.cattified(player)) { + // Todo +// ((ServerPlayer) player).connection.send(new ClientboundSetPassengersPacket(this)); + this.setOrderedToSit(false); + this.startRiding(player); +// ((ServerPlayer) player).connection.send(new ClientboundSetPassengersPacket(player)); + cir.setReturnValue(InteractionResult.SUCCESS); + cir.cancel(); + return; + } else if (player.getFirstPassenger() == this) { // Not working since you can never click the cat on your head!! +// ((ServerPlayer) player).connection.send(new ClientboundSetPassengersPacket(this)); + this.stopRiding(); +// ((ServerPlayer) player).connection.send(new ClientboundSetPassengersPacket(player)); + cir.setReturnValue(InteractionResult.SUCCESS); + return; + } + + ItemStack itemStack = player.getItemInHand(hand); + if (itemStack.is(ModItems.TOTEMEOW.get()) && !geniusCat.hasTotem()) { + itemStack.shrink(1); + geniusCat.setTotem(true); + cir.setReturnValue(InteractionResult.SUCCESS); + } + } +} diff --git a/src/main/java/cuteneko/catsplus/mixin/PlayerEntityMixin.java b/src/main/java/cuteneko/catsplus/mixin/PlayerEntityMixin.java deleted file mode 100644 index e0b4c67..0000000 --- a/src/main/java/cuteneko/catsplus/mixin/PlayerEntityMixin.java +++ /dev/null @@ -1,39 +0,0 @@ -package cuteneko.catsplus.mixin; - -import cuteneko.catsplus.CatsPlusData; -import net.minecraft.entity.EntityType; -import net.minecraft.entity.LivingEntity; -import net.minecraft.entity.passive.CatEntity; -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(PlayerEntity.class) -public abstract class PlayerEntityMixin extends LivingEntity { - 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 (getFirstPassenger() instanceof CatEntity - && (!isOnGround() || catPlayer.isCat())) { - var cat = getFirstPassenger(); - cat.stopRiding(); - - if (this.getWorld().isClient()) { - return; - } - - var vel = this.getVelocity(); - cat.addVelocity(vel.x * 5, vel.y, vel.z * 5); - } - } - - // Todo: qyl27: Right click tamed cat to increase favorability. -} diff --git a/src/main/java/cuteneko/catsplus/mixin/PlayerMixin.java b/src/main/java/cuteneko/catsplus/mixin/PlayerMixin.java new file mode 100644 index 0000000..bf22d1f --- /dev/null +++ b/src/main/java/cuteneko/catsplus/mixin/PlayerMixin.java @@ -0,0 +1,39 @@ +package cuteneko.catsplus.mixin; + +import cuteneko.catsplus.utility.CattifyHelper; +import net.minecraft.world.entity.EntityType; +import net.minecraft.world.entity.LivingEntity; +import net.minecraft.world.entity.animal.Cat; +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(Player.class) +public abstract class PlayerMixin extends LivingEntity { + + protected PlayerMixin(EntityType entityType, Level level) { + super(entityType, level); + } + + @Inject(method = "tick", at = @At("HEAD")) + public void tick(CallbackInfo ci) { + if (getFirstPassenger() instanceof Cat cat + && (!onGround() || CattifyHelper.cattified(this))) { + cat.stopRiding(); + + var level = this.level(); + + if (level.isClientSide()) { + return; + } + + var velocity = this.getDeltaMovement(); + cat.setDeltaMovement(velocity.x * 5, velocity.y, velocity.z * 5); + } + } + + // Todo: qyl27: Right click tamed cat to increase favorability. +} diff --git a/src/main/java/cuteneko/catsplus/mixin/TamableAnimalMixin.java b/src/main/java/cuteneko/catsplus/mixin/TamableAnimalMixin.java new file mode 100644 index 0000000..e11a154 --- /dev/null +++ b/src/main/java/cuteneko/catsplus/mixin/TamableAnimalMixin.java @@ -0,0 +1,21 @@ +package cuteneko.catsplus.mixin; + +import cuteneko.catsplus.CatsPlusData; +import net.minecraft.world.entity.TamableAnimal; +import net.minecraft.world.entity.animal.Cat; +import net.minecraft.world.entity.player.Player; +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(TamableAnimal.class) +public abstract class TamableAnimalMixin { + @Inject(method = "tame", at = @At(value = "TAIL")) + public void catsplus$tame(Player player, CallbackInfo ci) { + if ((Object) this instanceof Cat cat) { + var geniusCat = CatsPlusData.getGeniusCat(cat); + geniusCat.addIntimacyWith(player, 30); + } + } +} diff --git a/src/main/java/cuteneko/catsplus/mixin/cattify/CreeperEntityMixin.java b/src/main/java/cuteneko/catsplus/mixin/cattify/CreeperMixin.java similarity index 80% rename from src/main/java/cuteneko/catsplus/mixin/cattify/CreeperEntityMixin.java rename to src/main/java/cuteneko/catsplus/mixin/cattify/CreeperMixin.java index e4d4c6f..f4dd4b6 100644 --- a/src/main/java/cuteneko/catsplus/mixin/cattify/CreeperEntityMixin.java +++ b/src/main/java/cuteneko/catsplus/mixin/cattify/CreeperMixin.java @@ -13,13 +13,13 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; @Mixin(Creeper.class) -public abstract class CreeperEntityMixin extends Monster { - protected CreeperEntityMixin(EntityType entityType, Level level) { +public abstract class CreeperMixin extends Monster { + protected CreeperMixin(EntityType entityType, Level level) { super(entityType, level); } @Inject(method = "registerGoals", at = @At("TAIL")) - public void catsplus$afterRegisterGoals(CallbackInfo ci) { + public void catsplus$registerGoals(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 index 08cf2bd..59882ee 100644 --- a/src/main/java/cuteneko/catsplus/mixin/cattify/EntityMixin.java +++ b/src/main/java/cuteneko/catsplus/mixin/cattify/EntityMixin.java @@ -2,9 +2,11 @@ import cuteneko.catsplus.utility.CattifyHelper; import net.minecraft.world.entity.Entity; +import net.minecraft.world.entity.EntityType; import net.minecraft.world.entity.player.Player; 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; @@ -12,22 +14,42 @@ @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)); -// } -// } -// } + @Shadow public abstract boolean isShiftKeyDown(); + + @Inject(method = "getPassengerAttachmentPoint", at = @At("HEAD"), cancellable = true) + private void catsplus$getPassengerAttachmentPoint(CallbackInfoReturnable cir) { + if ((Object) this instanceof Player player) { + if (CattifyHelper.cattified(player)) { + var dimensions = EntityType.CAT.getDimensions(); + cir.setReturnValue(new Vector3f(0, dimensions.height() * 0.9F, 0)); + } + } + } + + @Inject(method = "getEyeHeight()F", at = @At("HEAD"), cancellable = true) + private void catsplus$getEyeHeight(CallbackInfoReturnable cir) { + if ((Object) this instanceof Player player) { + if (CattifyHelper.cattified(player)) { + cir.setReturnValue(EntityType.CAT.getDimensions().eyeHeight() + (isShiftKeyDown() ? -0.1F : 0)); + } + } + } + + @Inject(method = "getBbWidth", at = @At("RETURN"), cancellable = true) + private void catsplus$getBbWidth(CallbackInfoReturnable cir) { + if ((Object) this instanceof Player player) { + if (CattifyHelper.cattified(player)) { + cir.setReturnValue(EntityType.CAT.getDimensions().width()); + } + } + } + + @Inject(method = "getBbHeight", at = @At("RETURN"), cancellable = true) + private void catsplus$getBbHeight(CallbackInfoReturnable cir) { + if ((Object) this instanceof Player player) { + if (CattifyHelper.cattified(player)) { + cir.setReturnValue(EntityType.CAT.getDimensions().height() + (isShiftKeyDown() ? -0.2F : 0)); + } + } + } } diff --git a/src/main/java/cuteneko/catsplus/mixin/cattify/LivingEntityMixin.java b/src/main/java/cuteneko/catsplus/mixin/cattify/LivingEntityMixin.java index a9043ce..9267dfa 100644 --- a/src/main/java/cuteneko/catsplus/mixin/cattify/LivingEntityMixin.java +++ b/src/main/java/cuteneko/catsplus/mixin/cattify/LivingEntityMixin.java @@ -14,14 +14,14 @@ public abstract class LivingEntityMixin { @Inject(method = "getHurtSound", at = @At("RETURN"), cancellable = true) - private void playHurtSound(DamageSource damageSource, CallbackInfoReturnable cir) { + private void catsplus$getHurtSound(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) { + private void catsplus$getDeathSound(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/MobMixin.java similarity index 78% rename from src/main/java/cuteneko/catsplus/mixin/cattify/MobEntityMixin.java rename to src/main/java/cuteneko/catsplus/mixin/cattify/MobMixin.java index da29018..9bda610 100644 --- a/src/main/java/cuteneko/catsplus/mixin/cattify/MobEntityMixin.java +++ b/src/main/java/cuteneko/catsplus/mixin/cattify/MobMixin.java @@ -13,13 +13,13 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; @Mixin(Mob.class) -public abstract class MobEntityMixin extends LivingEntity { - protected MobEntityMixin(EntityType entityType, Level level) { +public abstract class MobMixin extends LivingEntity { + protected MobMixin(EntityType entityType, Level level) { super(entityType, level); } @Inject(method = "getAmbientSound", at = @At("RETURN"), cancellable = true) - private void afterGetAmbientSound(CallbackInfoReturnable cir) { + private void catsplus$getAmbientSound(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/PlayerRendererMixin.java similarity index 64% rename from src/main/java/cuteneko/catsplus/mixin/cattify/PlayerEntityRendererMixin.java rename to src/main/java/cuteneko/catsplus/mixin/cattify/PlayerRendererMixin.java index 9c65d86..6fd1d59 100644 --- a/src/main/java/cuteneko/catsplus/mixin/cattify/PlayerEntityRendererMixin.java +++ b/src/main/java/cuteneko/catsplus/mixin/cattify/PlayerRendererMixin.java @@ -3,11 +3,9 @@ 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; @@ -16,18 +14,13 @@ 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); - } +public abstract class PlayerRendererMixin { @Unique private CatPlayerRenderer catsplus$catPlayerRenderer; @Inject(method = "", at = @At("TAIL")) - private void catsplus$afterInit(EntityRendererProvider.Context context, boolean useSlimModel, CallbackInfo ci) { + private void catsplus$init(EntityRendererProvider.Context context, boolean useSlimModel, CallbackInfo ci) { catsplus$catPlayerRenderer = new CatPlayerRenderer(context); } @@ -36,7 +29,7 @@ public PlayerEntityRendererMixin(EntityRendererProvider.Context context, PlayerM at = @At(value = "HEAD"), cancellable = true ) - private void catsplus$beforeRender(AbstractClientPlayer entity, float entityYaw, float partialTicks, PoseStack poseStack, MultiBufferSource buffer, int packedLight, CallbackInfo ci) { + private void catsplus$render(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/AnimalMixin.java similarity index 74% rename from src/main/java/cuteneko/catsplus/mixin/dancing/AnimalEntityMixin.java rename to src/main/java/cuteneko/catsplus/mixin/dancing/AnimalMixin.java index 6043490..0433598 100644 --- a/src/main/java/cuteneko/catsplus/mixin/dancing/AnimalEntityMixin.java +++ b/src/main/java/cuteneko/catsplus/mixin/dancing/AnimalMixin.java @@ -1,7 +1,6 @@ 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; @@ -11,17 +10,18 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; @Mixin(Animal.class) -public abstract class AnimalEntityMixin { +public abstract class AnimalMixin { @Inject(method = "aiStep", at = @At("TAIL")) - private void afterTickMovement(CallbackInfo ci) { + private void catsplus$aiStep(CallbackInfo ci) { if ((Object) this instanceof Cat cat) { - var source = CatsPlusData.getMusicianCat(cat).getSoundSource(); + var geniusCat = CatsPlusData.getGeniusCat(cat); + var source = geniusCat.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); + geniusCat.setSoundStopped(); } } } diff --git a/src/main/java/cuteneko/catsplus/mixin/dancing/CatEntityMixin.java b/src/main/java/cuteneko/catsplus/mixin/dancing/CatEntityMixin.java deleted file mode 100644 index 8d33a38..0000000 --- a/src/main/java/cuteneko/catsplus/mixin/dancing/CatEntityMixin.java +++ /dev/null @@ -1,35 +0,0 @@ -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/mixin/dancing/CatEntityModelMixin.java b/src/main/java/cuteneko/catsplus/mixin/dancing/CatEntityModelMixin.java deleted file mode 100644 index 9e8b8b4..0000000 --- a/src/main/java/cuteneko/catsplus/mixin/dancing/CatEntityModelMixin.java +++ /dev/null @@ -1,31 +0,0 @@ -package cuteneko.catsplus.mixin.dancing; - -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; -import net.minecraft.entity.passive.CatEntity; -import net.minecraft.util.math.MathHelper; -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(CatEntityModel.class) -public abstract class CatEntityModelMixin - extends OcelotEntityModel { - public CatEntityModelMixin(ModelPart root) { - super(root); - } - - @Inject(method = "setAngles(Lnet/minecraft/entity/passive/CatEntity;FFFFF)V", at = @At("TAIL")) - public void setAngles(T cat, float f, float g, float h, float i, float j, CallbackInfo ci) { - // Random shake head to left or right. - var bias = cat.getUuid().getLeastSignificantBits() % 2 == 0 ? -1 : 1; - - if (((IMusicianCat) cat).catsplus$getSoundSource() != null) { - this.head.pitch = MathHelper.sin(cat.age * bias) * 0.3f; - this.head.yaw = MathHelper.cos(cat.age * bias) * -0.3f; - } - } -} diff --git a/src/main/java/cuteneko/catsplus/mixin/dancing/CatMixin.java b/src/main/java/cuteneko/catsplus/mixin/dancing/CatMixin.java new file mode 100644 index 0000000..4cb2fd2 --- /dev/null +++ b/src/main/java/cuteneko/catsplus/mixin/dancing/CatMixin.java @@ -0,0 +1,19 @@ +package cuteneko.catsplus.mixin.dancing; + +import cuteneko.catsplus.data.entity.GeniusCat; +import net.minecraft.core.BlockPos; +import net.minecraft.network.syncher.SynchedEntityData; +import net.minecraft.world.entity.animal.Cat; +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(Cat.class) +public abstract class CatMixin { + @Inject(method = "defineSynchedData", at = @At("TAIL")) + private void catsplus$defineSynchedData(SynchedEntityData.Builder builder, CallbackInfo ci) { + builder.define(GeniusCat.SOUND_PLAYING, false); + builder.define(GeniusCat.SOUND_SOURCE, BlockPos.ZERO); + } +} diff --git a/src/main/java/cuteneko/catsplus/mixin/dancing/CatModelMixin.java b/src/main/java/cuteneko/catsplus/mixin/dancing/CatModelMixin.java new file mode 100644 index 0000000..a08c92e --- /dev/null +++ b/src/main/java/cuteneko/catsplus/mixin/dancing/CatModelMixin.java @@ -0,0 +1,33 @@ +package cuteneko.catsplus.mixin.dancing; + +import cuteneko.catsplus.CatsPlusData; +import net.minecraft.client.model.CatModel; +import net.minecraft.client.model.OcelotModel; +import net.minecraft.client.model.geom.ModelPart; +import net.minecraft.util.Mth; +import net.minecraft.world.entity.animal.Cat; +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(CatModel.class) +public abstract class CatModelMixin + extends OcelotModel { + + public CatModelMixin(ModelPart root) { + super(root); + } + + @Inject(method = "setupAnim(Lnet/minecraft/world/entity/animal/Cat;FFFFF)V", at = @At("TAIL")) + public void catsplus$setupAnim(T cat, float f, float g, float h, float i, float j, CallbackInfo ci) { + // Random shake head to left or right. + var bias = cat.getUUID().getLeastSignificantBits() % 2 == 0 ? -1 : 1; + + var geniusCat = CatsPlusData.getGeniusCat(cat); + if (geniusCat.isSoundPlaying()) { + this.head.xRot = Mth.sin(cat.age * bias) * 0.3f; + this.head.yRot = Mth.cos(cat.age * bias) * -0.3f; + } + } +} diff --git a/src/main/java/cuteneko/catsplus/mixin/dancing/LivingEntityMixin.java b/src/main/java/cuteneko/catsplus/mixin/dancing/LivingEntityMixin.java index 1cebe06..20944b2 100644 --- a/src/main/java/cuteneko/catsplus/mixin/dancing/LivingEntityMixin.java +++ b/src/main/java/cuteneko/catsplus/mixin/dancing/LivingEntityMixin.java @@ -1,9 +1,9 @@ package cuteneko.catsplus.mixin.dancing; -import cuteneko.catsplus.bridge.IMusicianCat; -import net.minecraft.entity.LivingEntity; -import net.minecraft.entity.passive.CatEntity; -import net.minecraft.util.math.BlockPos; +import cuteneko.catsplus.CatsPlusData; +import net.minecraft.core.BlockPos; +import net.minecraft.world.entity.LivingEntity; +import net.minecraft.world.entity.animal.Cat; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; @@ -11,13 +11,15 @@ @Mixin(LivingEntity.class) public abstract class LivingEntityMixin { - @Inject(method = "setNearbySongPlaying", at = @At("TAIL")) - private void afterSetNearbySongPlaying(BlockPos songPosition, boolean playing, CallbackInfo ci) { - if ((Object) this instanceof CatEntity cat) { + @Inject(method = "setRecordPlayingNearby", at = @At("TAIL")) + private void catsplus$setRecordPlayingNearby(BlockPos jukebox, boolean playing, CallbackInfo ci) { + if ((Object) this instanceof Cat cat) { + var geniusCat = CatsPlusData.getGeniusCat(cat); + if (playing) { - ((IMusicianCat) cat).catsplus$setSoundSource(songPosition); + geniusCat.setSoundPlaying(jukebox); } else { - ((IMusicianCat) cat).catsplus$setSoundSource(null); + geniusCat.setSoundStopped(); } } } diff --git a/src/main/java/cuteneko/catsplus/mixin/favorability/CatRelaxOnOwnerGoalMixin.java b/src/main/java/cuteneko/catsplus/mixin/favorability/CatRelaxOnOwnerGoalMixin.java new file mode 100644 index 0000000..3ddaf45 --- /dev/null +++ b/src/main/java/cuteneko/catsplus/mixin/favorability/CatRelaxOnOwnerGoalMixin.java @@ -0,0 +1,30 @@ +package cuteneko.catsplus.mixin.favorability; + +import cuteneko.catsplus.CatsPlusData; +import cuteneko.catsplus.utility.ParticleHelper; +import net.minecraft.world.entity.EntityEvent; +import net.minecraft.world.entity.animal.Cat; +import net.minecraft.world.entity.player.Player; +import org.jetbrains.annotations.Nullable; +import org.spongepowered.asm.mixin.Final; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Shadow; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; + +@Mixin(targets = "net.minecraft.world.entity.animal.Cat$CatRelaxOnOwnerGoal") +public abstract class CatRelaxOnOwnerGoalMixin { + @Shadow @Final private Cat cat; + + @Shadow @Nullable private Player ownerPlayer; + + @Inject(method = "giveMorningGift", at = @At("HEAD")) + private void catsplus$giveMorningGift(CallbackInfo ci) { + var geniusCat = CatsPlusData.getGeniusCat(cat); + + geniusCat.addIntimacyWith(ownerPlayer, 5); + ParticleHelper.catHappy(cat); + // Todo: qyl27: Make a wish to the cat? The higher favorability, the better item will got. + } +} diff --git a/src/main/java/cuteneko/catsplus/mixin/favorability/CatSleepWithOwnerGoal.java b/src/main/java/cuteneko/catsplus/mixin/favorability/CatSleepWithOwnerGoal.java deleted file mode 100644 index c71e12e..0000000 --- a/src/main/java/cuteneko/catsplus/mixin/favorability/CatSleepWithOwnerGoal.java +++ /dev/null @@ -1,33 +0,0 @@ -package cuteneko.catsplus.mixin.favorability; - -import cuteneko.catsplus.CatsPlusData; -import net.minecraft.entity.EntityStatuses; -import net.minecraft.entity.passive.CatEntity; -import net.minecraft.entity.player.PlayerEntity; -import org.jetbrains.annotations.Nullable; -import org.spongepowered.asm.mixin.Final; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Shadow; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; - -@Mixin(targets = "net.minecraft.entity.passive.CatEntity$SleepWithOwnerGoal") -public abstract class CatSleepWithOwnerGoal { - @Shadow - @Final - private CatEntity cat; - - @Shadow private @Nullable PlayerEntity owner; - - @Inject(method = "dropMorningGifts", at = @At("HEAD"), cancellable = true) - private void afterDropMorningGifts(CallbackInfo ci) { - var geniusCat = CatsPlusData.getGeniusCat(cat); - - cat.getWorld().sendEntityStatus(cat, EntityStatuses.ADD_VILLAGER_HEART_PARTICLES); - // Todo: qyl27: Make a wish to the cat? The higher favorability, the better item will got. -// if (geniusCat.getFavorability(owner) < 50) { -// -// } - } -} diff --git a/src/main/java/cuteneko/catsplus/mixin/favorability/EntityMixin.java b/src/main/java/cuteneko/catsplus/mixin/favorability/EntityMixin.java index d738884..c253a45 100644 --- a/src/main/java/cuteneko/catsplus/mixin/favorability/EntityMixin.java +++ b/src/main/java/cuteneko/catsplus/mixin/favorability/EntityMixin.java @@ -1,10 +1,11 @@ package cuteneko.catsplus.mixin.favorability; import cuteneko.catsplus.CatsPlusData; -import net.minecraft.entity.Entity; -import net.minecraft.entity.damage.DamageSource; -import net.minecraft.entity.passive.CatEntity; -import net.minecraft.entity.player.PlayerEntity; +import cuteneko.catsplus.utility.ParticleHelper; +import net.minecraft.world.damagesource.DamageSource; +import net.minecraft.world.entity.Entity; +import net.minecraft.world.entity.animal.Cat; +import net.minecraft.world.entity.player.Player; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; @@ -12,17 +13,25 @@ @Mixin(Entity.class) public abstract class EntityMixin { - @Inject(method = "damage", at = @At("RETURN")) - private void afterDamage(DamageSource source, float amount, CallbackInfoReturnable cir) { - if ((Object) this instanceof CatEntity cat) { + @Inject(method = "hurt", at = @At("RETURN")) + private void catsplus$hurt(DamageSource source, float amount, CallbackInfoReturnable cir) { + if ((Object) this instanceof Cat cat) { if (cir.getReturnValue()) { - if (source.getSource() instanceof PlayerEntity player) { + if (source.getEntity() instanceof Player player) { var geniusCat = CatsPlusData.getGeniusCat(cat); - if (cat.isOwner(player)) { - geniusCat.subFavorability((int) amount * 5, player); + if (cat.isOwnedBy(player)) { + geniusCat.subIntimacyWith(player, (int) amount * 5); + + if (geniusCat.getIntimacyWith(player) < -100) { + ParticleHelper.catLeave(cat); + cat.setTame(false, true); + } else { + ParticleHelper.catAngry(cat); + } } else { - geniusCat.subFavorability((int) amount * 2, player); + geniusCat.subIntimacyWith(player, (int) amount * 2); + ParticleHelper.catAngry(cat); } } } diff --git a/src/main/java/cuteneko/catsplus/mixin/paper_model/BipedEntityModelMixin.java b/src/main/java/cuteneko/catsplus/mixin/paper_model/BipedEntityModelMixin.java deleted file mode 100644 index 05288b6..0000000 --- a/src/main/java/cuteneko/catsplus/mixin/paper_model/BipedEntityModelMixin.java +++ /dev/null @@ -1,60 +0,0 @@ -package cuteneko.catsplus.mixin.paper_model; - -import cuteneko.catsplus.item.ModItems; -import net.minecraft.client.model.ModelPart; -import net.minecraft.client.render.entity.model.BipedEntityModel; -import net.minecraft.entity.LivingEntity; -import org.spongepowered.asm.mixin.Final; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Shadow; -import org.spongepowered.asm.mixin.Unique; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; - -@Mixin(BipedEntityModel.class) -public abstract class BipedEntityModelMixin { - @Shadow - @Final - public ModelPart rightArm; - - @Shadow - @Final - public ModelPart leftArm; - - @Shadow - @Final - public ModelPart head; - - @Inject(method = "positionLeftArm", - at = @At(value = "INVOKE", - target = "Lnet/minecraft/client/render/entity/model/CrossbowPosing;hold(Lnet/minecraft/client/model/ModelPart;Lnet/minecraft/client/model/ModelPart;Lnet/minecraft/client/model/ModelPart;Z)V", - shift = At.Shift.AFTER), - cancellable = true) - private void catsplus$invokeLeftPosingHold(T entity, CallbackInfo ci) { - if (entity.getOffHandStack().isOf(ModItems.FANG_LUO.get())) { - catsplus$showHandheldPose(false); - ci.cancel(); - } - } - - @Inject(method = "positionRightArm", - at = @At(value = "INVOKE", - target = "Lnet/minecraft/client/render/entity/model/CrossbowPosing;hold(Lnet/minecraft/client/model/ModelPart;Lnet/minecraft/client/model/ModelPart;Lnet/minecraft/client/model/ModelPart;Z)V", - shift = At.Shift.AFTER), - cancellable = true) - private void catsplus$invokeRightPosingHold(T entity, CallbackInfo ci) { - if (entity.getMainHandStack().isOf(ModItems.FANG_LUO.get())) { - catsplus$showHandheldPose(true); - ci.cancel(); - } - } - - @Unique - private void catsplus$showHandheldPose(boolean rightArmed) { - rightArm.pitch = rightArmed ? -0.95f : -0.9f; - rightArm.yaw = (float) (-Math.PI / 8); - leftArm.pitch = rightArmed ? -0.9f : -0.95f; - leftArm.yaw = (float) (Math.PI / 8); - } -} diff --git a/src/main/java/cuteneko/catsplus/mixin/paper_model/HumanoidModelMixin.java b/src/main/java/cuteneko/catsplus/mixin/paper_model/HumanoidModelMixin.java new file mode 100644 index 0000000..ce83696 --- /dev/null +++ b/src/main/java/cuteneko/catsplus/mixin/paper_model/HumanoidModelMixin.java @@ -0,0 +1,60 @@ +package cuteneko.catsplus.mixin.paper_model; + +import cuteneko.catsplus.item.ModItems; +import net.minecraft.client.model.HumanoidModel; +import net.minecraft.client.model.geom.ModelPart; +import net.minecraft.world.entity.LivingEntity; +import org.spongepowered.asm.mixin.Final; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Shadow; +import org.spongepowered.asm.mixin.Unique; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; + +@Mixin(HumanoidModel.class) +public abstract class HumanoidModelMixin { + @Shadow + @Final + public ModelPart rightArm; + + @Shadow + @Final + public ModelPart leftArm; + + @Shadow + @Final + public ModelPart head; + + @Inject(method = "poseLeftArm", + at = @At(value = "INVOKE", + target = "Lnet/minecraft/client/model/AnimationUtils;animateCrossbowHold(Lnet/minecraft/client/model/geom/ModelPart;Lnet/minecraft/client/model/geom/ModelPart;Lnet/minecraft/client/model/geom/ModelPart;Z)V", + shift = At.Shift.AFTER), + cancellable = true) + private void catsplus$poseLeftArm(T entity, CallbackInfo ci) { + if (entity.getOffhandItem().is(ModItems.FANG_LUO.get())) { + catsplus$showHandheldPose(false); + ci.cancel(); + } + } + + @Inject(method = "poseRightArm", + at = @At(value = "INVOKE", + target = "Lnet/minecraft/client/model/AnimationUtils;animateCrossbowHold(Lnet/minecraft/client/model/geom/ModelPart;Lnet/minecraft/client/model/geom/ModelPart;Lnet/minecraft/client/model/geom/ModelPart;Z)V", + shift = At.Shift.AFTER), + cancellable = true) + private void catsplus$poseRightArm(T entity, CallbackInfo ci) { + if (entity.getOffhandItem().is(ModItems.FANG_LUO.get())) { + catsplus$showHandheldPose(true); + ci.cancel(); + } + } + + @Unique + private void catsplus$showHandheldPose(boolean rightArmed) { + rightArm.xRot = rightArmed ? -0.95f : -0.9f; + rightArm.yRot = (float) (-Math.PI / 8); + leftArm.xRot = rightArmed ? -0.9f : -0.95f; + leftArm.yRot = (float) (Math.PI / 8); + } +} diff --git a/src/main/java/cuteneko/catsplus/mixin/paper_model/PlayerEntityRendererMixin.java b/src/main/java/cuteneko/catsplus/mixin/paper_model/PlayerEntityRendererMixin.java deleted file mode 100644 index 5821014..0000000 --- a/src/main/java/cuteneko/catsplus/mixin/paper_model/PlayerEntityRendererMixin.java +++ /dev/null @@ -1,22 +0,0 @@ -package cuteneko.catsplus.mixin.paper_model; - -import cuteneko.catsplus.item.ModItems; -import net.minecraft.client.network.AbstractClientPlayerEntity; -import net.minecraft.client.render.entity.PlayerEntityRenderer; -import net.minecraft.client.render.entity.model.BipedEntityModel; -import net.minecraft.util.Hand; -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(PlayerEntityRenderer.class) -public abstract class PlayerEntityRendererMixin { - @Inject(method = "getArmPose", at = @At("TAIL"), cancellable = true) - private static void afterGetArmPose(AbstractClientPlayerEntity player, Hand hand, - CallbackInfoReturnable cir) { - if (player.getStackInHand(hand).isOf(ModItems.FANG_LUO.get())) { - cir.setReturnValue(BipedEntityModel.ArmPose.CROSSBOW_HOLD); - } - } -} diff --git a/src/main/java/cuteneko/catsplus/mixin/paper_model/PlayerHeldItemFeatureRendererMixin.java b/src/main/java/cuteneko/catsplus/mixin/paper_model/PlayerHeldItemFeatureRendererMixin.java deleted file mode 100644 index daae65b..0000000 --- a/src/main/java/cuteneko/catsplus/mixin/paper_model/PlayerHeldItemFeatureRendererMixin.java +++ /dev/null @@ -1,32 +0,0 @@ -package cuteneko.catsplus.mixin.paper_model; - -import cuteneko.catsplus.item.ModItems; -import net.minecraft.client.render.VertexConsumerProvider; -import net.minecraft.client.render.entity.feature.PlayerHeldItemFeatureRenderer; -import net.minecraft.client.render.entity.model.EntityModel; -import net.minecraft.client.render.entity.model.ModelWithArms; -import net.minecraft.client.render.entity.model.ModelWithHead; -import net.minecraft.client.render.model.json.ModelTransformationMode; -import net.minecraft.client.util.math.MatrixStack; -import net.minecraft.entity.LivingEntity; -import net.minecraft.entity.player.PlayerEntity; -import net.minecraft.item.ItemStack; -import net.minecraft.util.Arm; -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(PlayerHeldItemFeatureRenderer.class) -public abstract class PlayerHeldItemFeatureRendererMixin & ModelWithArms & ModelWithHead> { - @Inject(method = "renderItem", at = @At("HEAD"), cancellable = true) - private void catsplus$beforeRenderItem(LivingEntity entity, ItemStack stack, - ModelTransformationMode transformationMode, Arm arm, MatrixStack matrices, - VertexConsumerProvider vertexConsumers, int light, CallbackInfo ci) { - if (entity.getMainHandStack().isOf(ModItems.FANG_LUO.get()) || entity.getOffHandStack().isOf(ModItems.FANG_LUO.get())) { - if (!stack.isOf(ModItems.FANG_LUO.get())) { - ci.cancel(); - } - } - } -} diff --git a/src/main/java/cuteneko/catsplus/mixin/paper_model/PlayerItemInHandLayerMixin.java b/src/main/java/cuteneko/catsplus/mixin/paper_model/PlayerItemInHandLayerMixin.java new file mode 100644 index 0000000..7ae3e07 --- /dev/null +++ b/src/main/java/cuteneko/catsplus/mixin/paper_model/PlayerItemInHandLayerMixin.java @@ -0,0 +1,27 @@ +package cuteneko.catsplus.mixin.paper_model; + +import com.mojang.blaze3d.vertex.PoseStack; +import cuteneko.catsplus.item.ModItems; +import net.minecraft.client.renderer.MultiBufferSource; +import net.minecraft.client.renderer.entity.layers.PlayerItemInHandLayer; +import net.minecraft.world.entity.HumanoidArm; +import net.minecraft.world.entity.LivingEntity; +import net.minecraft.world.item.ItemDisplayContext; +import net.minecraft.world.item.ItemStack; +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(PlayerItemInHandLayer.class) +public abstract class PlayerItemInHandLayerMixin { + @Inject(method = "renderArmWithItem", at = @At("HEAD"), cancellable = true) + private void catsplus$renderArmWithItem(LivingEntity entity, ItemStack stack, ItemDisplayContext displayContext, HumanoidArm arm, PoseStack poseStack, MultiBufferSource buffer, int packedLight, CallbackInfo ci) { + if (entity.getMainHandItem().is(ModItems.FANG_LUO.get()) + || entity.getOffhandItem().is(ModItems.FANG_LUO.get())) { + if (!stack.is(ModItems.FANG_LUO.get())) { + ci.cancel(); + } + } + } +} diff --git a/src/main/java/cuteneko/catsplus/mixin/paper_model/PlayerRendererMixin.java b/src/main/java/cuteneko/catsplus/mixin/paper_model/PlayerRendererMixin.java new file mode 100644 index 0000000..c59ea02 --- /dev/null +++ b/src/main/java/cuteneko/catsplus/mixin/paper_model/PlayerRendererMixin.java @@ -0,0 +1,22 @@ +package cuteneko.catsplus.mixin.paper_model; + +import cuteneko.catsplus.item.ModItems; +import net.minecraft.client.model.HumanoidModel; +import net.minecraft.client.player.AbstractClientPlayer; +import net.minecraft.client.renderer.entity.player.PlayerRenderer; +import net.minecraft.world.InteractionHand; +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(PlayerRenderer.class) +public abstract class PlayerRendererMixin { + @Inject(method = "getArmPose", at = @At("TAIL"), cancellable = true) + private static void catsplus$getArmPose(AbstractClientPlayer player, InteractionHand hand, + CallbackInfoReturnable cir) { + if (player.getItemInHand(hand).is(ModItems.FANG_LUO.get())) { + cir.setReturnValue(HumanoidModel.ArmPose.CROSSBOW_HOLD); + } + } +} diff --git a/src/main/java/cuteneko/catsplus/mixin/totemeow/LivingEntityMixin.java b/src/main/java/cuteneko/catsplus/mixin/totemeow/LivingEntityMixin.java index 25aaf32..1f76e74 100644 --- a/src/main/java/cuteneko/catsplus/mixin/totemeow/LivingEntityMixin.java +++ b/src/main/java/cuteneko/catsplus/mixin/totemeow/LivingEntityMixin.java @@ -1,15 +1,15 @@ package cuteneko.catsplus.mixin.totemeow; import cuteneko.catsplus.CatsPlusData; -import net.minecraft.entity.Entity; -import net.minecraft.entity.EntityStatuses; -import net.minecraft.entity.EntityType; -import net.minecraft.entity.LivingEntity; -import net.minecraft.entity.damage.DamageSource; -import net.minecraft.entity.effect.StatusEffectInstance; -import net.minecraft.entity.effect.StatusEffects; -import net.minecraft.entity.passive.CatEntity; -import net.minecraft.world.World; +import net.minecraft.world.damagesource.DamageSource; +import net.minecraft.world.effect.MobEffectInstance; +import net.minecraft.world.effect.MobEffects; +import net.minecraft.world.entity.Entity; +import net.minecraft.world.entity.EntityEvent; +import net.minecraft.world.entity.EntityType; +import net.minecraft.world.entity.LivingEntity; +import net.minecraft.world.entity.animal.Cat; +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; @@ -17,22 +17,22 @@ @Mixin(LivingEntity.class) public abstract class LivingEntityMixin extends Entity { - public LivingEntityMixin(EntityType type, World world) { - super(type, world); + public LivingEntityMixin(EntityType entityType, Level level) { + super(entityType, level); } - @Inject(method = "tryUseTotem", at = @At("HEAD"), cancellable = true) - private void beforeTryUseTotem(DamageSource source, CallbackInfoReturnable cir) { - if ((Object) this instanceof CatEntity cat) { - var geniusCat = CatsPlusData.getGeniusCat((CatEntity) (Object) this); + @Inject(method = "checkTotemDeathProtection", at = @At("HEAD"), cancellable = true) + private void catsplus$checkTotemDeathProtection(DamageSource damageSource, CallbackInfoReturnable cir) { + if ((Object) this instanceof Cat cat) { + var geniusCat = CatsPlusData.getGeniusCat(cat); if (geniusCat.hasTotem()) { cat.setHealth(1.0f); - cat.clearStatusEffects(); - cat.addStatusEffect(new StatusEffectInstance(StatusEffects.REGENERATION, 900, 1)); - cat.addStatusEffect(new StatusEffectInstance(StatusEffects.ABSORPTION, 100, 1)); - cat.addStatusEffect(new StatusEffectInstance(StatusEffects.FIRE_RESISTANCE, 800, 0)); - cat.getWorld().sendEntityStatus(this, EntityStatuses.USE_TOTEM_OF_UNDYING); + cat.removeAllEffects(); + cat.addEffect(new MobEffectInstance(MobEffects.REGENERATION, 900, 1)); + cat.addEffect(new MobEffectInstance(MobEffects.ABSORPTION, 100, 1)); + cat.addEffect(new MobEffectInstance(MobEffects.FIRE_RESISTANCE, 800, 0)); + cat.level().broadcastEntityEvent(cat, EntityEvent.TALISMAN_ACTIVATE); geniusCat.setTotem(false); cir.setReturnValue(true); diff --git a/src/main/java/cuteneko/catsplus/mixin/totemeow/TamableAnimalMixin.java b/src/main/java/cuteneko/catsplus/mixin/totemeow/TamableAnimalMixin.java new file mode 100644 index 0000000..aab99f1 --- /dev/null +++ b/src/main/java/cuteneko/catsplus/mixin/totemeow/TamableAnimalMixin.java @@ -0,0 +1,63 @@ +package cuteneko.catsplus.mixin.totemeow; + +import cuteneko.catsplus.data.component.CatContainer; +import cuteneko.catsplus.data.component.CatSpirit; +import cuteneko.catsplus.data.level.LevelWithCats; +import cuteneko.catsplus.item.ModItems; +import cuteneko.catsplus.utility.ComponentHelper; +import cuteneko.catsplus.utility.ModConstants; +import net.minecraft.network.chat.Component; +import net.minecraft.server.level.ServerLevel; +import net.minecraft.server.level.ServerPlayer; +import net.minecraft.world.damagesource.DamageSource; +import net.minecraft.world.entity.EntityType; +import net.minecraft.world.entity.TamableAnimal; +import net.minecraft.world.entity.animal.Animal; +import net.minecraft.world.entity.animal.Cat; +import net.minecraft.world.item.ItemStack; +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; + +import java.time.OffsetDateTime; + +@Mixin(TamableAnimal.class) +public abstract class TamableAnimalMixin extends Animal { + + protected TamableAnimalMixin(EntityType entityType, Level level) { + super(entityType, level); + } + + @Inject(method = "die", at = @At("RETURN")) + private void catsplus$die(DamageSource damageSource, CallbackInfo ci) { + if ((Object) this instanceof Cat cat) { + if (cat.getOwnerUUID() == null) { + return; + } + + var level = cat.level(); + if (!(level instanceof ServerLevel serverLevel)) { + return; + } + + var stack = new ItemStack(ModItems.CAT_SPIRIT); + ComponentHelper.setCatContainer(stack, new CatContainer(cat)); + ComponentHelper.setCatSpirit(stack, new CatSpirit(OffsetDateTime.now(), getCombatTracker().getDeathMessage())); + + var owner = cat.getOwner(); + if (owner == null) { + var storage = LevelWithCats.getLevelWithCats(serverLevel); + // Todo: add it after Cat Resurrection Station. +// storage.addCatSpirit(cat.getOwnerUUID(), stack); + return; + } + + if (owner instanceof ServerPlayer player) { + player.addItem(stack); + player.sendSystemMessage(Component.translatable(ModConstants.MESSAGE_CAT_DIED)); + } + } + } +} diff --git a/src/main/java/cuteneko/catsplus/mixin/totemeow/TamableEntityMixin.java b/src/main/java/cuteneko/catsplus/mixin/totemeow/TamableEntityMixin.java deleted file mode 100644 index f8de35b..0000000 --- a/src/main/java/cuteneko/catsplus/mixin/totemeow/TamableEntityMixin.java +++ /dev/null @@ -1,69 +0,0 @@ -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; -import net.minecraft.entity.passive.AnimalEntity; -import net.minecraft.entity.passive.CatEntity; -import net.minecraft.entity.passive.TameableEntity; -import net.minecraft.entity.player.PlayerEntity; -import net.minecraft.item.ItemStack; -import net.minecraft.particle.ParticleTypes; -import net.minecraft.server.network.ServerPlayerEntity; -import net.minecraft.text.Text; -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; - -import java.time.OffsetDateTime; - -@Mixin(TameableEntity.class) -public abstract class TamableEntityMixin extends AnimalEntity { - protected TamableEntityMixin(EntityType entityType, World world) { - super(entityType, world); - } - - @Inject(method = "handleStatus", at = @At("HEAD"), cancellable = true) - private void beforeHandleStatus(byte status, CallbackInfo ci) { - if ((Object) this instanceof CatEntity) { - if (status == EntityStatuses.ADD_VILLAGER_ANGRY_PARTICLES) { - GeniusCatHelper.produceParticles(this, ParticleTypes.ANGRY_VILLAGER); - ci.cancel(); - } - } - } - - @Inject(method = "onDeath", at = @At("RETURN")) - private void afterDeath(DamageSource damageSource, CallbackInfo ci) { - if ((Object) this instanceof CatEntity cat) { - if (cat.getOwnerUuid() == null) { - return; - } - - var stack = new ItemStack(ModItems.CAT_SPIRIT); - var spirit = CatsPlusData.getCatSpirit(stack); - - spirit.setCat(cat); - spirit.setDeathTime(OffsetDateTime.now()); - spirit.setDeathMessage(getDamageTracker().getDeathMessage()); - - var owner = cat.getOwner(); - if (owner == null) { - CatsPlusData.getCatServer(cat.getServer()).addCatSpirit(cat.getOwnerUuid(), stack); - return; - } - - if (owner instanceof ServerPlayerEntity player) { - player.giveItemStack(stack); - player.sendMessage(Text.translatable(Constants.MESSAGE_CAT_DIED)); - } - } - } -} diff --git a/src/main/java/cuteneko/catsplus/tag/ModItemTags.java b/src/main/java/cuteneko/catsplus/tag/ModItemTags.java index bde2617..4f8f1a6 100644 --- a/src/main/java/cuteneko/catsplus/tag/ModItemTags.java +++ b/src/main/java/cuteneko/catsplus/tag/ModItemTags.java @@ -7,5 +7,5 @@ import net.minecraft.world.item.Item; public class ModItemTags { - public static final TagKey COOKED_FISHES = TagKey.of(Registries.ITEM, ResourceLocation.fromNamespaceAndPath(CatsPlus.MODID, "cooked_fishes")); + public static final TagKey COOKED_FISHES = TagKey.create(Registries.ITEM, ResourceLocation.fromNamespaceAndPath(CatsPlus.MODID, "cooked_fishes")); } diff --git a/src/main/java/cuteneko/catsplus/utility/CattifyHelper.java b/src/main/java/cuteneko/catsplus/utility/CattifyHelper.java index 78598bf..1ea578e 100644 --- a/src/main/java/cuteneko/catsplus/utility/CattifyHelper.java +++ b/src/main/java/cuteneko/catsplus/utility/CattifyHelper.java @@ -1,6 +1,9 @@ package cuteneko.catsplus.utility; import cuteneko.catsplus.effect.ModEffects; +import net.minecraft.core.Holder; +import net.minecraft.core.registries.BuiltInRegistries; +import net.minecraft.world.effect.MobEffect; import net.minecraft.world.entity.LivingEntity; import net.minecraft.world.entity.player.Player; @@ -9,7 +12,13 @@ public class CattifyHelper { public static final Predicate PREDICATE_CATTIFIED_PLAYER = entity -> entity instanceof Player && cattified(entity); +// private static Holder CATTIFY; + public static boolean cattified(LivingEntity entity) { +// if (CATTIFY == null) { +// CATTIFY = BuiltInRegistries.MOB_EFFECT.getHolder(ModEffects.CATTIFY.getId()).get(); +// } + 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 index 7cc43c3..d582099 100644 --- a/src/main/java/cuteneko/catsplus/utility/ComponentHelper.java +++ b/src/main/java/cuteneko/catsplus/utility/ComponentHelper.java @@ -1,6 +1,7 @@ package cuteneko.catsplus.utility; import cuteneko.catsplus.data.component.CatContainer; +import cuteneko.catsplus.data.component.CatSpirit; import cuteneko.catsplus.data.component.ModComponents; import net.minecraft.core.component.DataComponents; import net.minecraft.network.chat.Component; @@ -19,6 +20,18 @@ public static void removeCatContainer(ItemStack stack) { stack.remove(ModComponents.CAT_CONTAINER.get()); } + public static CatSpirit getCatSpirit(ItemStack stack) { + return stack.get(ModComponents.CAT_SPIRIT.get()); + } + + public static void setCatSpirit(ItemStack stack, CatSpirit catSpirit) { + stack.set(ModComponents.CAT_SPIRIT.get(), catSpirit); + } + + public static void removeCatSpirit(ItemStack stack) { + stack.remove(ModComponents.CAT_SPIRIT.get()); + } + public static Component getCustomName(ItemStack stack) { if (stack.has(DataComponents.CUSTOM_NAME)) { return stack.get(DataComponents.CUSTOM_NAME); diff --git a/src/main/java/cuteneko/catsplus/utility/GeniusCatHelper.java b/src/main/java/cuteneko/catsplus/utility/GeniusCatHelper.java deleted file mode 100644 index c8e0641..0000000 --- a/src/main/java/cuteneko/catsplus/utility/GeniusCatHelper.java +++ /dev/null @@ -1,21 +0,0 @@ -package cuteneko.catsplus.utility; - -import cuteneko.catsplus.tag.ModItemTags; -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.of(ModItemTags.COOKED_FISHES); - - 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.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/Constants.java b/src/main/java/cuteneko/catsplus/utility/ModConstants.java similarity index 65% rename from src/main/java/cuteneko/catsplus/utility/Constants.java rename to src/main/java/cuteneko/catsplus/utility/ModConstants.java index 9919d15..19d533b 100644 --- a/src/main/java/cuteneko/catsplus/utility/Constants.java +++ b/src/main/java/cuteneko/catsplus/utility/ModConstants.java @@ -3,35 +3,21 @@ import cuteneko.catsplus.CatsPlus; import net.minecraft.resources.ResourceLocation; -public class Constants { - public static final String TAG_CAT_CONTAINER = "Cat"; - - public static final String TAG_ENTITY_POS = "Pos"; - public static final String TAG_CUSTOM_NAME = "CustomName"; +public class ModConstants { public static final String TAG_X = "x"; public static final String TAG_Y = "y"; public static final String TAG_Z = "z"; public static final String TAG_UUID = "uuid"; public static final String TAG_VALUE = "value"; - public static final String TAG_DEATH_TIME = "deathAt"; - public static final String TAG_DEATH_MESSAGE = "deathMessage"; - - 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 ResourceLocation TAG_SERVER_HAS_CAT = CatsPlus.modLoc("cat_server_data"); + public static final String LEVEL_WITH_CATS_FILE_NAME = "cats_plus"; public static final String TAG_SERVER_CAT_SPIRITS = "catSpirits"; 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"; - public static final String TAG_GENIUS_CAT_FAVORABILITY = "favorability"; - public static final String TAG_GENIUS_CAT_DANCING = "dancing"; - public static final String TAG_GENIUS_CAT_DANCING_SOURCE = "source"; - public static final String TAG_GENIUS_CAT_DANCING_SOUND_PLAYING = "soundPlaying"; + public static final String TAG_GENIUS_CAT = CAP_GENIUS_CAT.toString(); + public static final String TAG_GENIUS_CAT_HAS_TOTEM = "hasUndyingTotem"; + public static final String TAG_GENIUS_CAT_INTIMACIES = "intimacies"; + public static final String TAG_GENIUS_CAT_SOUND_SOURCE = "soundSource"; public static final String MESSAGE_CATS_GROUP_TITLE = "itemGroup.catsplus.catsplus_group"; diff --git a/src/main/java/cuteneko/catsplus/utility/ParticleHelper.java b/src/main/java/cuteneko/catsplus/utility/ParticleHelper.java new file mode 100644 index 0000000..3230416 --- /dev/null +++ b/src/main/java/cuteneko/catsplus/utility/ParticleHelper.java @@ -0,0 +1,44 @@ +package cuteneko.catsplus.utility; + +import net.minecraft.core.particles.ParticleOptions; +import net.minecraft.core.particles.ParticleTypes; +import net.minecraft.world.entity.EntityEvent; +import net.minecraft.world.entity.LivingEntity; +import net.minecraft.world.entity.animal.Cat; + +public class ParticleHelper { + public static void catHappy(Cat cat) { + showHappy(cat); + } + + public static void catAngry(Cat cat) { + showAngry(cat); + } + + public static void catLeave(Cat cat) { + showFailed(cat); + } + + public static void showHappy(LivingEntity entity) { + produceParticles(entity, ParticleTypes.HEART); + } + + public static void showAngry(LivingEntity entity) { + produceParticles(entity, ParticleTypes.ANGRY_VILLAGER); + } + + public static void showFailed(LivingEntity entity) { + produceParticles(entity, ParticleTypes.SMOKE); + } + + private 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.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/TagHelper.java b/src/main/java/cuteneko/catsplus/utility/TagHelper.java index c538973..67f45da 100644 --- a/src/main/java/cuteneko/catsplus/utility/TagHelper.java +++ b/src/main/java/cuteneko/catsplus/utility/TagHelper.java @@ -7,20 +7,20 @@ 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()); - compound.putInt(Constants.TAG_Z, pos.getZ()); + compound.putInt(ModConstants.TAG_X, pos.getX()); + compound.putInt(ModConstants.TAG_Y, pos.getY()); + compound.putInt(ModConstants.TAG_Z, pos.getZ()); } return compound; } public static BlockPos loadBlockPos(CompoundTag compound) { - if (compound.contains(Constants.TAG_X) - && compound.contains(Constants.TAG_Y) - && compound.contains(Constants.TAG_Z)) { - var x = compound.getInt(Constants.TAG_X); - var y = compound.getInt(Constants.TAG_Y); - var z = compound.getInt(Constants.TAG_Z); + if (compound.contains(ModConstants.TAG_X) + && compound.contains(ModConstants.TAG_Y) + && compound.contains(ModConstants.TAG_Z)) { + var x = compound.getInt(ModConstants.TAG_X); + var y = compound.getInt(ModConstants.TAG_Y); + var z = compound.getInt(ModConstants.TAG_Z); return new BlockPos(x, y, z); } return null; diff --git a/src/main/resources/catsplus-common.mixins.json b/src/main/resources/catsplus-common.mixins.json index adc27d5..36ea0b9 100644 --- a/src/main/resources/catsplus-common.mixins.json +++ b/src/main/resources/catsplus-common.mixins.json @@ -1,31 +1,32 @@ { - "required": true, - "minVersion": "0.8", - "package": "cuteneko.catsplus.mixin", - "compatibilityLevel": "JAVA_17", - "mixins": [ - "CatEntityMixin", - "PlayerEntityMixin", - "cattify.CreeperEntityMixin", - "cattify.EntityMixin", - "cattify.LivingEntityMixin", - "cattify.MobEntityMixin", - "dancing.AnimalEntityMixin", - "dancing.CatEntityMixin", - "dancing.LivingEntityMixin", - "favorability.CatSleepWithOwnerGoal", - "favorability.EntityMixin", - "totemeow.LivingEntityMixin", - "totemeow.TamableEntityMixin" - ], - "client": [ - "cattify.PlayerEntityRendererMixin", - "dancing.CatEntityModelMixin", - "paper_model.BipedEntityModelMixin", - "paper_model.PlayerEntityRendererMixin", - "paper_model.PlayerHeldItemFeatureRendererMixin" - ], - "injectors": { - "defaultRequire": 1 - } + "required": true, + "minVersion": "0.8", + "package": "cuteneko.catsplus.mixin", + "compatibilityLevel": "JAVA_17", + "mixins": [ + "CatMixin", + "PlayerMixin", + "TamableAnimalMixin", + "cattify.CreeperMixin", + "cattify.EntityMixin", + "cattify.LivingEntityMixin", + "cattify.MobMixin", + "dancing.AnimalMixin", + "dancing.CatMixin", + "dancing.LivingEntityMixin", + "favorability.CatRelaxOnOwnerGoalMixin", + "favorability.EntityMixin", + "totemeow.LivingEntityMixin", + "totemeow.TamableAnimalMixin" + ], + "client": [ + "cattify.PlayerRendererMixin", + "dancing.CatModelMixin", + "paper_model.HumanoidModelMixin", + "paper_model.PlayerItemInHandLayerMixin", + "paper_model.PlayerRendererMixin" + ], + "injectors": { + "defaultRequire": 1 + } } diff --git a/src/main/resources/catsplus.accesswidener b/src/main/resources/catsplus.accesswidener index 2315d67..d7c95ed 100644 --- a/src/main/resources/catsplus.accesswidener +++ b/src/main/resources/catsplus.accesswidener @@ -1,10 +1,2 @@ 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 field net/minecraft/world/entity/AgeableMob age I