From ee68a32509e5eaccd87d8bb517f157ae83e33d8d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=A7=8B=E9=9B=A8=E8=90=BD?= Date: Wed, 21 Feb 2024 21:10:34 +0800 Subject: [PATCH] Update doll. Fix bugs. Add cat spirit. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 秋雨落 --- .../catsplus/fabric/CatsPlusDataImpl.java | 18 ++++ .../catsplus/fabric/CatsPlusPlatformImpl.java | 18 ---- .../CatPlayerFabric.java} | 8 +- .../GeniusCatFabric.java} | 22 ++--- .../fabric/data/{ => gen}/ModDataGen.java | 6 +- .../data/{ => gen}/ModItemModelProvider.java | 2 +- .../data/{ => gen}/ModRecipeProvider.java | 2 +- .../{ => gen}/lang/ModLangProviderENUS.java | 23 +++-- .../{ => gen}/lang/ModLangProviderZHCN.java | 19 ++-- .../fabric/mixins/impl/ICatEntityMixin.java | 3 - .../fabric/mixins/mixin/CatEntityMixin.java | 14 --- .../src/main/resources/fabric.mod.json | 2 +- gradle.properties | 2 +- .../15e558425d03769b4c939a16ffd55f843ac56d0f | 4 +- .../49e5c65ca1ab59f598f710846fb0f8d549021d95 | 4 +- .../d5ee957bafb940ae78b04b56b65ec8b9002aa9dc | 2 +- .../dcf38aaf6b2f28016e34adbe561ad13afee480c8 | 2 +- .../generated/assets/catsplus/lang/en_us.json | 15 ++-- .../generated/assets/catsplus/lang/zh_cn.json | 11 ++- .../java/cuteneko/catsplus/CatsPlusData.java | 41 +++++++++ .../cuteneko/catsplus/CatsPlusPlatform.java | 19 ---- .../java/cuteneko/catsplus/data/ICatBag.java | 4 + .../catsplus/data/ICatContainerItem.java | 15 ++++ .../{platform => data}/ICatPlayer.java | 2 +- .../cuteneko/catsplus/data/ICatSpirit.java | 13 +++ .../{platform => data}/IGeniusCat.java | 5 +- .../cuteneko/catsplus/data/impl/CatBag.java | 12 +++ .../catsplus/data/impl/CatContainer.java | 82 +++++++++++++++++ .../catsplus/data/impl/CatSpirit.java | 52 +++++++++++ .../cuteneko/catsplus/item/CatBagItem.java | 87 ++++++------------- .../cuteneko/catsplus/item/CatSpiritItem.java | 16 ++++ .../catsplus/mixins/mixin/CatEntityMixin.java | 10 +-- .../mixins/mixin/PlayerEntityMixin.java | 4 +- .../mixins/mixin/cattify/EntityMixin.java | 6 +- .../mixin/cattify/PlayerEntityMixin.java | 8 +- .../cattify/PlayerEntityRendererMixin.java | 4 +- .../mixin/dancing/AnimalEntityMixin.java | 4 +- .../mixin/dancing/CatEntityModelMixin.java | 4 +- .../mixin/dancing/LivingEntityMixin.java | 4 +- .../mixin/favorability/EntityMixin.java | 4 +- .../mixin/totemeow/CatSleepWithOwnerGoal.java | 19 ++-- .../mixin/totemeow/LivingEntityMixin.java | 4 +- .../mixin/totemeow/TamableEntityMixin.java | 30 +++---- .../catsplus/utility/CatPlayerHelper.java | 4 +- .../cuteneko/catsplus/utility/Constants.java | 18 +++- 45 files changed, 424 insertions(+), 224 deletions(-) create mode 100644 catsplus-fabric/src/main/java/cuteneko/catsplus/fabric/CatsPlusDataImpl.java delete mode 100644 catsplus-fabric/src/main/java/cuteneko/catsplus/fabric/CatsPlusPlatformImpl.java rename catsplus-fabric/src/main/java/cuteneko/catsplus/fabric/{platform/CatPlayer.java => data/CatPlayerFabric.java} (81%) rename catsplus-fabric/src/main/java/cuteneko/catsplus/fabric/{platform/GeniusCat.java => data/GeniusCatFabric.java} (80%) rename catsplus-fabric/src/main/java/cuteneko/catsplus/fabric/data/{ => gen}/ModDataGen.java (75%) rename catsplus-fabric/src/main/java/cuteneko/catsplus/fabric/data/{ => gen}/ModItemModelProvider.java (94%) rename catsplus-fabric/src/main/java/cuteneko/catsplus/fabric/data/{ => gen}/ModRecipeProvider.java (97%) rename catsplus-fabric/src/main/java/cuteneko/catsplus/fabric/data/{ => gen}/lang/ModLangProviderENUS.java (57%) rename catsplus-fabric/src/main/java/cuteneko/catsplus/fabric/data/{ => gen}/lang/ModLangProviderZHCN.java (59%) create mode 100644 src/main/java/cuteneko/catsplus/CatsPlusData.java delete mode 100644 src/main/java/cuteneko/catsplus/CatsPlusPlatform.java create mode 100644 src/main/java/cuteneko/catsplus/data/ICatBag.java create mode 100644 src/main/java/cuteneko/catsplus/data/ICatContainerItem.java rename src/main/java/cuteneko/catsplus/{platform => data}/ICatPlayer.java (84%) create mode 100644 src/main/java/cuteneko/catsplus/data/ICatSpirit.java rename src/main/java/cuteneko/catsplus/{platform => data}/IGeniusCat.java (85%) create mode 100644 src/main/java/cuteneko/catsplus/data/impl/CatBag.java create mode 100644 src/main/java/cuteneko/catsplus/data/impl/CatContainer.java create mode 100644 src/main/java/cuteneko/catsplus/data/impl/CatSpirit.java diff --git a/catsplus-fabric/src/main/java/cuteneko/catsplus/fabric/CatsPlusDataImpl.java b/catsplus-fabric/src/main/java/cuteneko/catsplus/fabric/CatsPlusDataImpl.java new file mode 100644 index 0000000..d3ad755 --- /dev/null +++ b/catsplus-fabric/src/main/java/cuteneko/catsplus/fabric/CatsPlusDataImpl.java @@ -0,0 +1,18 @@ +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.IGeniusCat; +import net.minecraft.entity.passive.CatEntity; +import net.minecraft.entity.player.PlayerEntity; + +public class CatsPlusDataImpl { + public static ICatPlayer getCatPlayer(PlayerEntity player) { + return new CatPlayerFabric(player); + } + + public static IGeniusCat getGeniusCat(CatEntity cat) { + return new GeniusCatFabric(cat); + } +} diff --git a/catsplus-fabric/src/main/java/cuteneko/catsplus/fabric/CatsPlusPlatformImpl.java b/catsplus-fabric/src/main/java/cuteneko/catsplus/fabric/CatsPlusPlatformImpl.java deleted file mode 100644 index f350e07..0000000 --- a/catsplus-fabric/src/main/java/cuteneko/catsplus/fabric/CatsPlusPlatformImpl.java +++ /dev/null @@ -1,18 +0,0 @@ -package cuteneko.catsplus.fabric; - -import cuteneko.catsplus.fabric.platform.CatPlayer; -import cuteneko.catsplus.fabric.platform.GeniusCat; -import cuteneko.catsplus.platform.ICatPlayer; -import cuteneko.catsplus.platform.IGeniusCat; -import net.minecraft.entity.passive.CatEntity; -import net.minecraft.entity.player.PlayerEntity; - -public class CatsPlusPlatformImpl { - public static ICatPlayer getCatPlayer(PlayerEntity player) { - return new CatPlayer(player); - } - - public static IGeniusCat getGeniusCat(CatEntity cat) { - return new GeniusCat(cat); - } -} diff --git a/catsplus-fabric/src/main/java/cuteneko/catsplus/fabric/platform/CatPlayer.java b/catsplus-fabric/src/main/java/cuteneko/catsplus/fabric/data/CatPlayerFabric.java similarity index 81% rename from catsplus-fabric/src/main/java/cuteneko/catsplus/fabric/platform/CatPlayer.java rename to catsplus-fabric/src/main/java/cuteneko/catsplus/fabric/data/CatPlayerFabric.java index 0a5527e..871eef6 100644 --- a/catsplus-fabric/src/main/java/cuteneko/catsplus/fabric/platform/CatPlayer.java +++ b/catsplus-fabric/src/main/java/cuteneko/catsplus/fabric/data/CatPlayerFabric.java @@ -1,15 +1,15 @@ -package cuteneko.catsplus.fabric.platform; +package cuteneko.catsplus.fabric.data; import cuteneko.catsplus.effect.ModEffects; import cuteneko.catsplus.fabric.mixins.impl.IPlayerEntityMixin; -import cuteneko.catsplus.platform.ICatPlayer; +import cuteneko.catsplus.data.ICatPlayer; import net.minecraft.entity.passive.CatEntity; import net.minecraft.entity.player.PlayerEntity; -public class CatPlayer implements ICatPlayer { +public class CatPlayerFabric implements ICatPlayer { private final PlayerEntity player; - public CatPlayer(PlayerEntity player) { + public CatPlayerFabric(PlayerEntity player) { this.player = player; } diff --git a/catsplus-fabric/src/main/java/cuteneko/catsplus/fabric/platform/GeniusCat.java b/catsplus-fabric/src/main/java/cuteneko/catsplus/fabric/data/GeniusCatFabric.java similarity index 80% rename from catsplus-fabric/src/main/java/cuteneko/catsplus/fabric/platform/GeniusCat.java rename to catsplus-fabric/src/main/java/cuteneko/catsplus/fabric/data/GeniusCatFabric.java index c6b2780..e2f8b56 100644 --- a/catsplus-fabric/src/main/java/cuteneko/catsplus/fabric/platform/GeniusCat.java +++ b/catsplus-fabric/src/main/java/cuteneko/catsplus/fabric/data/GeniusCatFabric.java @@ -1,7 +1,7 @@ -package cuteneko.catsplus.fabric.platform; +package cuteneko.catsplus.fabric.data; import cuteneko.catsplus.fabric.mixins.impl.ICatEntityMixin; -import cuteneko.catsplus.platform.IGeniusCat; +import cuteneko.catsplus.data.IGeniusCat; import net.minecraft.advancement.criterion.Criteria; import net.minecraft.entity.EntityStatuses; import net.minecraft.entity.passive.CatEntity; @@ -9,10 +9,10 @@ import net.minecraft.server.network.ServerPlayerEntity; import net.minecraft.util.math.BlockPos; -public class GeniusCat implements IGeniusCat { +public class GeniusCatFabric implements IGeniusCat { private final CatEntity cat; - public GeniusCat(CatEntity cat) { + public GeniusCatFabric(CatEntity cat) { this.cat = cat; } @@ -28,12 +28,7 @@ public void setTotem(boolean totem) { @Override public boolean canRespawn() { - return ((ICatEntityMixin) cat).catsplus$canRespawn(); - } - - @Override - public void setCanRespawn(boolean canRespawn) { - ((ICatEntityMixin) cat).catsplus$setCanRespawn(canRespawn); + return hasTotem() || getLives() > 0; } @Override @@ -45,17 +40,14 @@ public int getFavorability(PlayerEntity player) { public void setFavorability(int favorability, PlayerEntity player) { ((ICatEntityMixin) cat).catsplus$setFavorability(favorability, player); - if(getFavorability(player) <= 0) { + if (cat.isOwner(player) && getFavorability(player) <= 0) { cat.tryAttack(player); cat.setOwnerUuid(null); cat.setTamed(false); cat.setSitting(false); - setCanRespawn(false); + setLives(0); cat.onTamedChanged(); cat.getWorld().sendEntityStatus(cat, EntityStatuses.ADD_VILLAGER_ANGRY_PARTICLES); - if (player instanceof ServerPlayerEntity) { - Criteria.TAME_ANIMAL.trigger((ServerPlayerEntity)player, cat); - } } } diff --git a/catsplus-fabric/src/main/java/cuteneko/catsplus/fabric/data/ModDataGen.java b/catsplus-fabric/src/main/java/cuteneko/catsplus/fabric/data/gen/ModDataGen.java similarity index 75% rename from catsplus-fabric/src/main/java/cuteneko/catsplus/fabric/data/ModDataGen.java rename to catsplus-fabric/src/main/java/cuteneko/catsplus/fabric/data/gen/ModDataGen.java index c0f41ac..aaec665 100644 --- a/catsplus-fabric/src/main/java/cuteneko/catsplus/fabric/data/ModDataGen.java +++ b/catsplus-fabric/src/main/java/cuteneko/catsplus/fabric/data/gen/ModDataGen.java @@ -1,7 +1,7 @@ -package cuteneko.catsplus.fabric.data; +package cuteneko.catsplus.fabric.data.gen; -import cuteneko.catsplus.fabric.data.lang.ModLangProviderENUS; -import cuteneko.catsplus.fabric.data.lang.ModLangProviderZHCN; +import cuteneko.catsplus.fabric.data.gen.lang.ModLangProviderENUS; +import cuteneko.catsplus.fabric.data.gen.lang.ModLangProviderZHCN; import net.fabricmc.fabric.api.datagen.v1.DataGeneratorEntrypoint; import net.fabricmc.fabric.api.datagen.v1.FabricDataGenerator; diff --git a/catsplus-fabric/src/main/java/cuteneko/catsplus/fabric/data/ModItemModelProvider.java b/catsplus-fabric/src/main/java/cuteneko/catsplus/fabric/data/gen/ModItemModelProvider.java similarity index 94% rename from catsplus-fabric/src/main/java/cuteneko/catsplus/fabric/data/ModItemModelProvider.java rename to catsplus-fabric/src/main/java/cuteneko/catsplus/fabric/data/gen/ModItemModelProvider.java index 581a59d..ed21e43 100644 --- a/catsplus-fabric/src/main/java/cuteneko/catsplus/fabric/data/ModItemModelProvider.java +++ b/catsplus-fabric/src/main/java/cuteneko/catsplus/fabric/data/gen/ModItemModelProvider.java @@ -1,4 +1,4 @@ -package cuteneko.catsplus.fabric.data; +package cuteneko.catsplus.fabric.data.gen; import cuteneko.catsplus.item.ModItems; import net.fabricmc.fabric.api.datagen.v1.FabricDataOutput; diff --git a/catsplus-fabric/src/main/java/cuteneko/catsplus/fabric/data/ModRecipeProvider.java b/catsplus-fabric/src/main/java/cuteneko/catsplus/fabric/data/gen/ModRecipeProvider.java similarity index 97% rename from catsplus-fabric/src/main/java/cuteneko/catsplus/fabric/data/ModRecipeProvider.java rename to catsplus-fabric/src/main/java/cuteneko/catsplus/fabric/data/gen/ModRecipeProvider.java index e7ff184..1447118 100644 --- a/catsplus-fabric/src/main/java/cuteneko/catsplus/fabric/data/ModRecipeProvider.java +++ b/catsplus-fabric/src/main/java/cuteneko/catsplus/fabric/data/gen/ModRecipeProvider.java @@ -1,4 +1,4 @@ -package cuteneko.catsplus.fabric.data; +package cuteneko.catsplus.fabric.data.gen; import cuteneko.catsplus.item.ModItems; import net.fabricmc.fabric.api.datagen.v1.FabricDataOutput; diff --git a/catsplus-fabric/src/main/java/cuteneko/catsplus/fabric/data/lang/ModLangProviderENUS.java b/catsplus-fabric/src/main/java/cuteneko/catsplus/fabric/data/gen/lang/ModLangProviderENUS.java similarity index 57% rename from catsplus-fabric/src/main/java/cuteneko/catsplus/fabric/data/lang/ModLangProviderENUS.java rename to catsplus-fabric/src/main/java/cuteneko/catsplus/fabric/data/gen/lang/ModLangProviderENUS.java index 12b0bb8..897dc22 100644 --- a/catsplus-fabric/src/main/java/cuteneko/catsplus/fabric/data/lang/ModLangProviderENUS.java +++ b/catsplus-fabric/src/main/java/cuteneko/catsplus/fabric/data/gen/lang/ModLangProviderENUS.java @@ -1,11 +1,14 @@ -package cuteneko.catsplus.fabric.data.lang; +package cuteneko.catsplus.fabric.data.gen.lang; import cuteneko.catsplus.block.ModBlocks; 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 net.fabricmc.fabric.api.datagen.v1.FabricDataOutput; import net.fabricmc.fabric.api.datagen.v1.provider.FabricLanguageProvider; +import net.minecraft.item.ItemGroup; public class ModLangProviderENUS extends FabricLanguageProvider { public ModLangProviderENUS(FabricDataOutput dataOutput) { @@ -18,8 +21,8 @@ public void generateTranslations(TranslationBuilder builder) { 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 was passed away because of cancer."); - builder.add(Constants.MESSAGE_FANG_LUO_DESCRIPTION_2, "Rest in peace."); + 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(ModBlocks.CAT_RESURRECTION_STATION_BLOCK.get(), "Cat Resurrection Station"); @@ -29,9 +32,15 @@ public void generateTranslations(TranslationBuilder builder) { builder.add(Constants.MESSAGE_CATTIFY_LINGERING_POTION, "Lingering Potion of Cattify"); builder.add(Constants.MESSAGE_CATTIFY_POTION_ARROW, "Arrow of Cattify"); - builder.add(Constants.MESSAGE_CATS_GROUP_TITLE, "Cats+!"); - builder.add(Constants.MESSAGE_CAT_BAG_NO_CAT, "Empty."); - builder.add(Constants.MESSAGE_CAT_BAG_HAS_CAT, "Cat Inside!"); - builder.add(Constants.MESSAGE_CAT_BAG_HAS_CAT_NAMED, "%1$s Inside!"); + 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"); } } diff --git a/catsplus-fabric/src/main/java/cuteneko/catsplus/fabric/data/lang/ModLangProviderZHCN.java b/catsplus-fabric/src/main/java/cuteneko/catsplus/fabric/data/gen/lang/ModLangProviderZHCN.java similarity index 59% rename from catsplus-fabric/src/main/java/cuteneko/catsplus/fabric/data/lang/ModLangProviderZHCN.java rename to catsplus-fabric/src/main/java/cuteneko/catsplus/fabric/data/gen/lang/ModLangProviderZHCN.java index c33e435..fcbaafa 100644 --- a/catsplus-fabric/src/main/java/cuteneko/catsplus/fabric/data/lang/ModLangProviderZHCN.java +++ b/catsplus-fabric/src/main/java/cuteneko/catsplus/fabric/data/gen/lang/ModLangProviderZHCN.java @@ -1,11 +1,14 @@ -package cuteneko.catsplus.fabric.data.lang; +package cuteneko.catsplus.fabric.data.gen.lang; import cuteneko.catsplus.block.ModBlocks; 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 net.fabricmc.fabric.api.datagen.v1.FabricDataOutput; import net.fabricmc.fabric.api.datagen.v1.provider.FabricLanguageProvider; +import net.minecraft.item.ItemGroup; public class ModLangProviderZHCN extends FabricLanguageProvider { public ModLangProviderZHCN(FabricDataOutput dataOutput) { @@ -29,9 +32,15 @@ public void generateTranslations(TranslationBuilder builder) { builder.add(Constants.MESSAGE_CATTIFY_LINGERING_POTION, "滞留型变猫药水"); builder.add(Constants.MESSAGE_CATTIFY_POTION_ARROW, "变猫药水箭"); - builder.add(Constants.MESSAGE_CATS_GROUP_TITLE, "Cats+!"); - builder.add(Constants.MESSAGE_CAT_BAG_NO_CAT, "空的。"); - builder.add(Constants.MESSAGE_CAT_BAG_HAS_CAT, "内含猫猫!"); - builder.add(Constants.MESSAGE_CAT_BAG_HAS_CAT_NAMED, "%1$s 在里面!"); + 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, "很久以前"); } } diff --git a/catsplus-fabric/src/main/java/cuteneko/catsplus/fabric/mixins/impl/ICatEntityMixin.java b/catsplus-fabric/src/main/java/cuteneko/catsplus/fabric/mixins/impl/ICatEntityMixin.java index a85cc69..0f2e6c1 100644 --- a/catsplus-fabric/src/main/java/cuteneko/catsplus/fabric/mixins/impl/ICatEntityMixin.java +++ b/catsplus-fabric/src/main/java/cuteneko/catsplus/fabric/mixins/impl/ICatEntityMixin.java @@ -13,9 +13,6 @@ public interface ICatEntityMixin { int catsplus$getLives(); void catsplus$setLives(int lives); - boolean catsplus$canRespawn(); - void catsplus$setCanRespawn(boolean canRespawn); - boolean catsplus$isSongPlaying(); void catsplus$setSongPlaying(boolean playing); BlockPos catsplus$getSongSource(); diff --git a/catsplus-fabric/src/main/java/cuteneko/catsplus/fabric/mixins/mixin/CatEntityMixin.java b/catsplus-fabric/src/main/java/cuteneko/catsplus/fabric/mixins/mixin/CatEntityMixin.java index 72ef973..d1e57a2 100644 --- a/catsplus-fabric/src/main/java/cuteneko/catsplus/fabric/mixins/mixin/CatEntityMixin.java +++ b/catsplus-fabric/src/main/java/cuteneko/catsplus/fabric/mixins/mixin/CatEntityMixin.java @@ -25,8 +25,6 @@ public abstract class CatEntityMixin implements ICatEntityMixin { private int catsplus$lives = 0; @Unique private boolean catsplus$hasTotem = false; - @Unique - private boolean catsplus$canRespawn = false; @Unique private boolean catsplus$songPlaying = false; @@ -70,16 +68,6 @@ public abstract class CatEntityMixin implements ICatEntityMixin { catsplus$lives = lives; } - @Override - public boolean catsplus$canRespawn() { - return catsplus$canRespawn; - } - - @Override - public void catsplus$setCanRespawn(boolean canRespawn) { - catsplus$canRespawn = canRespawn; - } - @Override public boolean catsplus$isSongPlaying() { return catsplus$songPlaying; @@ -106,7 +94,6 @@ private void write(NbtCompound nbt, CallbackInfo ci) { tag.putInt(Constants.TAG_GENIUS_CAT_LIVES, catsplus$lives); tag.putBoolean(Constants.TAG_GENIUS_CAT_TOTEM, catsplus$hasTotem); - tag.putBoolean(Constants.TAG_GENIUS_CAT_CAN_RESPAWN, catsplus$canRespawn); var dancing = new NbtCompound(); dancing.putBoolean(Constants.TAG_GENIUS_CAT_DANCING_SOUND_PLAYING, catsplus$songPlaying); @@ -131,7 +118,6 @@ private void read(NbtCompound nbt, CallbackInfo ci) { catsplus$lives = tag.getInt(Constants.TAG_GENIUS_CAT_LIVES); catsplus$hasTotem = tag.getBoolean(Constants.TAG_GENIUS_CAT_TOTEM); - catsplus$canRespawn = tag.getBoolean(Constants.TAG_GENIUS_CAT_CAN_RESPAWN); var dancing = tag.getCompound(Constants.TAG_GENIUS_CAT_DANCING); catsplus$songPlaying = dancing.getBoolean(Constants.TAG_GENIUS_CAT_DANCING_SOUND_PLAYING); diff --git a/catsplus-fabric/src/main/resources/fabric.mod.json b/catsplus-fabric/src/main/resources/fabric.mod.json index bd92b9c..ddf9697 100644 --- a/catsplus-fabric/src/main/resources/fabric.mod.json +++ b/catsplus-fabric/src/main/resources/fabric.mod.json @@ -25,7 +25,7 @@ "cuteneko.catsplus.fabric.CatsPlusFabric" ], "fabric-datagen": [ - "cuteneko.catsplus.fabric.data.ModDataGen" + "cuteneko.catsplus.fabric.data.gen.ModDataGen" ] }, "mixins": [ diff --git a/gradle.properties b/gradle.properties index c02e434..8c2a94d 100644 --- a/gradle.properties +++ b/gradle.properties @@ -8,7 +8,7 @@ shadow_plugin_version=8.1.1 unified_publishing_version=0.1.+ # Architectury -enabled_platforms=fabric,forge,neoforge +enabled_platforms=forge,fabric,neoforge,quilt # Mod mod_version=0.1.7 diff --git a/src/main/generated/.cache/15e558425d03769b4c939a16ffd55f843ac56d0f b/src/main/generated/.cache/15e558425d03769b4c939a16ffd55f843ac56d0f index 34b37d2..1dcdc21 100644 --- a/src/main/generated/.cache/15e558425d03769b4c939a16ffd55f843ac56d0f +++ b/src/main/generated/.cache/15e558425d03769b4c939a16ffd55f843ac56d0f @@ -1,2 +1,2 @@ -// 1.20.4 2024-02-21T08:45:46.2924207 Cats+/Language (en_us) -8e251fab5ce5c3f45ea9ac58c25f48ec8466f03f assets\catsplus\lang\en_us.json +// 1.20.4 2024-02-21T21:09:29.4662143 Cats+/Language (en_us) +d6583927b847b4b2a3794090b7ac5fceccb13c82 assets\catsplus\lang\en_us.json diff --git a/src/main/generated/.cache/49e5c65ca1ab59f598f710846fb0f8d549021d95 b/src/main/generated/.cache/49e5c65ca1ab59f598f710846fb0f8d549021d95 index 782b684..d719be1 100644 --- a/src/main/generated/.cache/49e5c65ca1ab59f598f710846fb0f8d549021d95 +++ b/src/main/generated/.cache/49e5c65ca1ab59f598f710846fb0f8d549021d95 @@ -1,2 +1,2 @@ -// 1.20.4 2024-02-21T08:45:46.2934204 Cats+/Language (zh_cn) -06df21f6ac57e8fe479a3cec1a60e08adbdf3cdb assets\catsplus\lang\zh_cn.json +// 1.20.4 2024-02-21T21:09:29.4682147 Cats+/Language (zh_cn) +7931bcf23f857507e9bead0a1e1f3d793d6d5915 assets\catsplus\lang\zh_cn.json diff --git a/src/main/generated/.cache/d5ee957bafb940ae78b04b56b65ec8b9002aa9dc b/src/main/generated/.cache/d5ee957bafb940ae78b04b56b65ec8b9002aa9dc index 1819f08..5cd23db 100644 --- a/src/main/generated/.cache/d5ee957bafb940ae78b04b56b65ec8b9002aa9dc +++ b/src/main/generated/.cache/d5ee957bafb940ae78b04b56b65ec8b9002aa9dc @@ -1,4 +1,4 @@ -// 1.20.4 2024-02-21T08:45:46.2934204 Cats+/Recipes +// 1.20.4 2024-02-21T21:09:29.4682147 Cats+/Recipes 241ff3a315e1d01731c5b1b8f98108af0ab6656b data\catsplus\advancements\recipes\tools\cat_bag.json 10847e82ba25bc5c21abff40e303a1c023a77613 data\catsplus\recipes\totemeow.json 561f81e965a426c518aba9734d7fb823257b8eb5 data\catsplus\recipes\cat_bag.json diff --git a/src/main/generated/.cache/dcf38aaf6b2f28016e34adbe561ad13afee480c8 b/src/main/generated/.cache/dcf38aaf6b2f28016e34adbe561ad13afee480c8 index 3abc723..01a4e71 100644 --- a/src/main/generated/.cache/dcf38aaf6b2f28016e34adbe561ad13afee480c8 +++ b/src/main/generated/.cache/dcf38aaf6b2f28016e34adbe561ad13afee480c8 @@ -1,2 +1,2 @@ -// 1.20.4 2024-02-21T08:45:46.2924207 Cats+/Model Definitions +// 1.20.4 2024-02-21T21:09:29.4682147 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 2306379..77e87ee 100644 --- a/src/main/generated/assets/catsplus/lang/en_us.json +++ b/src/main/generated/assets/catsplus/lang/en_us.json @@ -2,13 +2,18 @@ "block.catsplus.cat_resurrection_station": "Cat Resurrection Station", "effect.catsplus.cattify": "Cattify", "item.catsplus.cat_bag": "Cat Bag", - "item.catsplus.cat_bag.has_cat": "Cat Inside!", - "item.catsplus.cat_bag.has_cat_named": "%1$s Inside!", - "item.catsplus.cat_bag.no_cat": "Empty.", + "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 was passed away because of cancer.", - "item.catsplus.fang_luo.desc.2": "Rest in peace.", + "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", diff --git a/src/main/generated/assets/catsplus/lang/zh_cn.json b/src/main/generated/assets/catsplus/lang/zh_cn.json index 8949c8e..07090a9 100644 --- a/src/main/generated/assets/catsplus/lang/zh_cn.json +++ b/src/main/generated/assets/catsplus/lang/zh_cn.json @@ -2,10 +2,15 @@ "block.catsplus.cat_resurrection_station": "猫咪复活台", "effect.catsplus.cattify": "猫咪化", "item.catsplus.cat_bag": "猫包", - "item.catsplus.cat_bag.has_cat": "内含猫猫!", - "item.catsplus.cat_bag.has_cat_named": "%1$s 在里面!", - "item.catsplus.cat_bag.no_cat": "空的。", + "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": "缅怀……", diff --git a/src/main/java/cuteneko/catsplus/CatsPlusData.java b/src/main/java/cuteneko/catsplus/CatsPlusData.java new file mode 100644 index 0000000..ace8743 --- /dev/null +++ b/src/main/java/cuteneko/catsplus/CatsPlusData.java @@ -0,0 +1,41 @@ +package cuteneko.catsplus; + +import cuteneko.catsplus.data.ICatSpirit; +import cuteneko.catsplus.data.impl.CatSpirit; +import cuteneko.catsplus.item.ModItems; +import cuteneko.catsplus.data.ICatBag; +import cuteneko.catsplus.data.ICatPlayer; +import cuteneko.catsplus.data.IGeniusCat; +import cuteneko.catsplus.data.impl.CatBag; +import dev.architectury.injectables.annotations.ExpectPlatform; +import net.minecraft.entity.passive.CatEntity; +import net.minecraft.entity.player.PlayerEntity; +import net.minecraft.item.ItemStack; + +public class CatsPlusData { + @ExpectPlatform + public static ICatPlayer getCatPlayer(PlayerEntity player) { + throw new UnsupportedOperationException(); + } + + @ExpectPlatform + public static IGeniusCat getGeniusCat(CatEntity cat) { + throw new UnsupportedOperationException(); + } + + public static ICatBag getCatBag(ItemStack bag) { + if (!bag.isOf(ModItems.CAT_BAG.get())) { + throw new IllegalArgumentException(); + } + + return new CatBag(bag); + } + + public static ICatSpirit getCatSpirit(ItemStack spirit) { + if (!spirit.isOf(ModItems.CAT_SPIRIT.get())) { + throw new IllegalArgumentException(); + } + + return new CatSpirit(spirit); + } +} diff --git a/src/main/java/cuteneko/catsplus/CatsPlusPlatform.java b/src/main/java/cuteneko/catsplus/CatsPlusPlatform.java deleted file mode 100644 index ff1abe2..0000000 --- a/src/main/java/cuteneko/catsplus/CatsPlusPlatform.java +++ /dev/null @@ -1,19 +0,0 @@ -package cuteneko.catsplus; - -import cuteneko.catsplus.platform.ICatPlayer; -import cuteneko.catsplus.platform.IGeniusCat; -import dev.architectury.injectables.annotations.ExpectPlatform; -import net.minecraft.entity.passive.CatEntity; -import net.minecraft.entity.player.PlayerEntity; - -public class CatsPlusPlatform { - @ExpectPlatform - public static ICatPlayer getCatPlayer(PlayerEntity player) { - throw new UnsupportedOperationException(); - } - - @ExpectPlatform - public static IGeniusCat getGeniusCat(CatEntity cat) { - throw new UnsupportedOperationException(); - } -} diff --git a/src/main/java/cuteneko/catsplus/data/ICatBag.java b/src/main/java/cuteneko/catsplus/data/ICatBag.java new file mode 100644 index 0000000..fc27c12 --- /dev/null +++ b/src/main/java/cuteneko/catsplus/data/ICatBag.java @@ -0,0 +1,4 @@ +package cuteneko.catsplus.data; + +public interface ICatBag extends ICatContainerItem { +} diff --git a/src/main/java/cuteneko/catsplus/data/ICatContainerItem.java b/src/main/java/cuteneko/catsplus/data/ICatContainerItem.java new file mode 100644 index 0000000..b6b3e0a --- /dev/null +++ b/src/main/java/cuteneko/catsplus/data/ICatContainerItem.java @@ -0,0 +1,15 @@ +package cuteneko.catsplus.data; + +import net.minecraft.entity.passive.CatEntity; +import net.minecraft.text.Text; +import net.minecraft.world.World; + +public interface ICatContainerItem { + boolean hasCat(); + CatEntity getCat(World world); + void setCat(CatEntity cat); + void clearCat(); + + boolean hasCustomCatName(); + Text getCustomCatName(); +} diff --git a/src/main/java/cuteneko/catsplus/platform/ICatPlayer.java b/src/main/java/cuteneko/catsplus/data/ICatPlayer.java similarity index 84% rename from src/main/java/cuteneko/catsplus/platform/ICatPlayer.java rename to src/main/java/cuteneko/catsplus/data/ICatPlayer.java index 482aedb..6a5c840 100644 --- a/src/main/java/cuteneko/catsplus/platform/ICatPlayer.java +++ b/src/main/java/cuteneko/catsplus/data/ICatPlayer.java @@ -1,4 +1,4 @@ -package cuteneko.catsplus.platform; +package cuteneko.catsplus.data; import net.minecraft.entity.passive.CatEntity; diff --git a/src/main/java/cuteneko/catsplus/data/ICatSpirit.java b/src/main/java/cuteneko/catsplus/data/ICatSpirit.java new file mode 100644 index 0000000..6ecbd61 --- /dev/null +++ b/src/main/java/cuteneko/catsplus/data/ICatSpirit.java @@ -0,0 +1,13 @@ +package cuteneko.catsplus.data; + +import net.minecraft.text.Text; + +import java.time.OffsetDateTime; + +public interface ICatSpirit extends ICatContainerItem { + OffsetDateTime getDeathTime(); + void setDeathTime(OffsetDateTime time); + + Text getDeathMessage(); + void setDeathMessage(Text message); +} diff --git a/src/main/java/cuteneko/catsplus/platform/IGeniusCat.java b/src/main/java/cuteneko/catsplus/data/IGeniusCat.java similarity index 85% rename from src/main/java/cuteneko/catsplus/platform/IGeniusCat.java rename to src/main/java/cuteneko/catsplus/data/IGeniusCat.java index 45f1c45..260b659 100644 --- a/src/main/java/cuteneko/catsplus/platform/IGeniusCat.java +++ b/src/main/java/cuteneko/catsplus/data/IGeniusCat.java @@ -1,4 +1,4 @@ -package cuteneko.catsplus.platform; +package cuteneko.catsplus.data; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.util.math.BlockPos; @@ -8,14 +8,13 @@ public interface IGeniusCat { void setTotem(boolean totem); boolean canRespawn(); - void setCanRespawn(boolean canRespawn); int getFavorability(PlayerEntity player); void setFavorability(int favorability, PlayerEntity player); void addFavorability(int value, PlayerEntity player); void subFavorability(int value, PlayerEntity player); - int getLives(); + int getLives(); // Todo: qyl27: Give it a purpose? void setLives(int lives); boolean isSongPlaying(); diff --git a/src/main/java/cuteneko/catsplus/data/impl/CatBag.java b/src/main/java/cuteneko/catsplus/data/impl/CatBag.java new file mode 100644 index 0000000..245de28 --- /dev/null +++ b/src/main/java/cuteneko/catsplus/data/impl/CatBag.java @@ -0,0 +1,12 @@ +package cuteneko.catsplus.data.impl; + +import cuteneko.catsplus.data.ICatBag; +import cuteneko.catsplus.utility.Constants; +import net.minecraft.item.ItemStack; +import net.minecraft.text.Text; + +public class CatBag extends CatContainer implements ICatBag { + public CatBag(ItemStack stack) { + super(stack); + } +} diff --git a/src/main/java/cuteneko/catsplus/data/impl/CatContainer.java b/src/main/java/cuteneko/catsplus/data/impl/CatContainer.java new file mode 100644 index 0000000..b2b81a5 --- /dev/null +++ b/src/main/java/cuteneko/catsplus/data/impl/CatContainer.java @@ -0,0 +1,82 @@ +package cuteneko.catsplus.data.impl; + +import cuteneko.catsplus.data.ICatContainerItem; +import cuteneko.catsplus.utility.Constants; +import net.minecraft.entity.EntityType; +import net.minecraft.entity.passive.CatEntity; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NbtCompound; +import net.minecraft.text.Text; +import net.minecraft.world.World; + +public abstract class CatContainer implements ICatContainerItem { + protected ItemStack stack; + + public CatContainer(ItemStack stack) { + this.stack = stack; + } + + @Override + public boolean hasCat() { + var tag = stack.getNbt(); + if (tag != null) { + var compoundCat = tag.get(Constants.TAG_CAT_CONTAINER); + return compoundCat != null; + } + return false; + } + + @Override + public CatEntity getCat(World world) { + var tag = stack.getNbt(); + if (tag != null) { + var compoundCat = tag.getCompound(Constants.TAG_CAT_CONTAINER); + var optionalEntity = EntityType.getEntityFromNbt(compoundCat, world); + if (optionalEntity.isPresent() && optionalEntity.get() instanceof CatEntity cat) { + cat.readNbt(compoundCat); + return cat; + } + } + + return null; + } + + @Override + public void setCat(CatEntity cat) { + var compoundCat = new NbtCompound(); + cat.saveNbt(compoundCat); + var tag = stack.getOrCreateNbt(); + tag.put(Constants.TAG_CAT_CONTAINER, compoundCat); + stack.setNbt(tag); + } + + @Override + public void clearCat() { + var tag = stack.getOrCreateNbt(); + tag.remove(Constants.TAG_CAT_CONTAINER); + stack.setNbt(tag); + } + + @Override + public boolean hasCustomCatName() { + var tag = stack.getNbt(); + if (tag != null) { + var compoundCat = tag.getCompound(Constants.TAG_CAT_CONTAINER); + return compoundCat != null && compoundCat.contains(Constants.TAG_CUSTOM_NAME); + } + return false; + } + + @Override + public Text getCustomCatName() { + var tag = stack.getNbt(); + if (tag != null) { + var compoundCat = tag.getCompound(Constants.TAG_CAT_CONTAINER); + if (compoundCat != null) { + var name = compoundCat.getString(Constants.TAG_CUSTOM_NAME); + return Text.Serialization.fromJson(name); + } + } + return null; + } +} diff --git a/src/main/java/cuteneko/catsplus/data/impl/CatSpirit.java b/src/main/java/cuteneko/catsplus/data/impl/CatSpirit.java new file mode 100644 index 0000000..27eaedd --- /dev/null +++ b/src/main/java/cuteneko/catsplus/data/impl/CatSpirit.java @@ -0,0 +1,52 @@ +package cuteneko.catsplus.data.impl; + +import cuteneko.catsplus.data.ICatSpirit; +import cuteneko.catsplus.utility.Constants; +import net.minecraft.item.ItemStack; +import net.minecraft.text.Text; + +import java.time.OffsetDateTime; + +public class CatSpirit extends CatContainer implements ICatSpirit { + public CatSpirit(ItemStack stack) { + super(stack); + } + + @Override + public OffsetDateTime getDeathTime() { + var tag = stack.getNbt(); + if (tag != null) { + var deathAt = tag.getString(Constants.TAG_DEATH_TIME); + if (!deathAt.isBlank()) { + return OffsetDateTime.parse(deathAt); + } + } + return null; + } + + @Override + public void setDeathTime(OffsetDateTime time) { + var tag = stack.getOrCreateNbt(); + tag.putString(Constants.TAG_DEATH_TIME, time.toString()); + stack.setNbt(tag); + } + + @Override + public Text getDeathMessage() { + var tag = stack.getNbt(); + if (tag != null) { + var deathMsg = tag.getString(Constants.TAG_DEATH_MESSAGE); + if (!deathMsg.isBlank()) { + return Text.Serialization.fromJson(deathMsg); + } + } + return Text.empty(); + } + + @Override + public void setDeathMessage(Text message) { + var tag = stack.getOrCreateNbt(); + tag.putString(Constants.TAG_DEATH_MESSAGE, Text.Serialization.toJsonString(message)); + stack.setNbt(tag); + } +} diff --git a/src/main/java/cuteneko/catsplus/item/CatBagItem.java b/src/main/java/cuteneko/catsplus/item/CatBagItem.java index 23b4d02..e3d36c5 100644 --- a/src/main/java/cuteneko/catsplus/item/CatBagItem.java +++ b/src/main/java/cuteneko/catsplus/item/CatBagItem.java @@ -1,5 +1,6 @@ package cuteneko.catsplus.item; +import cuteneko.catsplus.CatsPlusData; import cuteneko.catsplus.item.group.ModItemGroups; import cuteneko.catsplus.utility.Constants; import net.minecraft.client.item.TooltipContext; @@ -22,6 +23,7 @@ import net.minecraft.util.Hand; import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.Direction; +import net.minecraft.util.math.Vec3d; import net.minecraft.world.World; import net.minecraft.world.event.GameEvent; import org.jetbrains.annotations.Nullable; @@ -40,31 +42,22 @@ public CatBagItem() { @Override public void appendTooltip(ItemStack stack, @Nullable World world, List tooltip, TooltipContext context) { - if (!stack.hasNbt() || !Objects.requireNonNull(stack.getNbt()).contains(Constants.TAG_CAT_BAG_CAT)) { - tooltip.add(Text.translatable(Constants.MESSAGE_CAT_BAG_NO_CAT).formatted(Formatting.DARK_GRAY)); + if (!stack.hasNbt() || !Objects.requireNonNull(stack.getNbt()).contains(Constants.TAG_CAT_CONTAINER)) { + tooltip.add(Text.translatable(Constants.MESSAGE_CAT_BAG_DESCRIPTION_NO_CAT).formatted(Formatting.DARK_GRAY)); return; } - var cat = stack.getNbt().getCompound(Constants.TAG_CAT_BAG_CAT); - if (cat.contains(Constants.TAG_CUSTOM_NAME)) { - var name = cat.getString(Constants.TAG_CUSTOM_NAME); - var component = Text.Serialization.fromJson(name); - - if (component != null) { - tooltip.add(Text.translatable(Constants.MESSAGE_CAT_BAG_HAS_CAT_NAMED, component.getString()).formatted(Formatting.BLUE)); - return; - } + var bag = CatsPlusData.getCatBag(stack); + if (bag.hasCustomCatName()) { + tooltip.add(Text.translatable(Constants.MESSAGE_CAT_BAG_DESCRIPTION_HAS_NAMED_CAT, bag.getCustomCatName().getString()).formatted(Formatting.BLUE)); + } else { + tooltip.add(Text.translatable(Constants.MESSAGE_CAT_BAG_DESCRIPTION_HAS_CAT).formatted(Formatting.BLUE)); } - - tooltip.add(Text.translatable(Constants.MESSAGE_CAT_BAG_HAS_CAT).formatted(Formatting.BLUE)); } @Override public ActionResult useOnBlock(ItemUsageContext context) { var stack = context.getStack(); - if (!stack.hasNbt()) { - return ActionResult.PASS; - } if (stack.hasCustomName()) { var name = stack.getName().getString(); @@ -77,68 +70,44 @@ public ActionResult useOnBlock(ItemUsageContext context) { } } - var nbt = stack.getNbt(); - if (!(nbt != null && nbt.contains(Constants.TAG_CAT_BAG_CAT))) { + var bag = CatsPlusData.getCatBag(stack); + if (!bag.hasCat()) { return ActionResult.PASS; } - var catNbt = nbt.getCompound(Constants.TAG_CAT_BAG_CAT); Direction direction = context.getSide(); var world = context.getWorld(); var player = context.getPlayer(); - var pos = context.getBlockPos().offset(direction); + var pos = context.getBlockPos().offset(direction).toCenterPos(); if (world instanceof ServerWorld) { - this.spawnEntity((ServerWorld) world, catNbt, pos); + var cat = bag.getCat(world); + cat.setPosition(pos); + world.spawnEntity(cat); world.emitGameEvent(player, GameEvent.ENTITY_PLACE, pos); } - nbt.remove(Constants.TAG_CAT_BAG_CAT); - stack.setNbt(nbt); + bag.clearCat(); Objects.requireNonNull(context.getPlayer()).setStackInHand(context.getHand(), stack); return ActionResult.SUCCESS; } @Override public ActionResult useOnEntity(ItemStack stack, PlayerEntity user, LivingEntity entity, Hand hand) { - if (!(entity instanceof CatEntity cat)) { - return ActionResult.PASS; - } - - if (stack.hasNbt()) { - assert stack.getNbt() != null; - if (stack.getNbt().contains(Constants.TAG_CAT_BAG_CAT)) { - return ActionResult.PASS; + if (entity instanceof CatEntity cat) { + var bag = CatsPlusData.getCatBag(stack); + if (!bag.hasCat()) { + if (cat.isOwner(user)) { + cat.setSitting(false); + bag.setCat(cat); + cat.discard(); + return ActionResult.SUCCESS; + } else { + return ActionResult.FAIL; + } } } - if (!cat.isOwner(user)) { - return ActionResult.FAIL; - } - - var nbt = stack.getOrCreateNbt(); - var catNbt = new NbtCompound(); - cat.setSitting(!cat.isSitting()); - cat.saveNbt(catNbt); - nbt.put(Constants.TAG_CAT_BAG_CAT, catNbt); - stack.setNbt(nbt); - user.setStackInHand(hand, stack); - cat.discard(); - return ActionResult.SUCCESS; - } - - private void spawnEntity(ServerWorld world, NbtCompound nbt, BlockPos pos) { - CatEntity cat = EntityType.CAT.spawn(world, nbt, null, pos, SpawnReason.EVENT, true, false); - assert cat != null; - assert nbt != null; - var x = NbtDouble.of(cat.getX()); - var y = NbtDouble.of(cat.getY()); - var z = NbtDouble.of(cat.getZ()); - var list = new NbtList(); - list.add(x); - list.add(y); - list.add(z); - nbt.put(Constants.TAG_ENTITY_POS, list); - cat.readNbt(nbt); + return ActionResult.PASS; } } diff --git a/src/main/java/cuteneko/catsplus/item/CatSpiritItem.java b/src/main/java/cuteneko/catsplus/item/CatSpiritItem.java index b40a774..e6a7b89 100644 --- a/src/main/java/cuteneko/catsplus/item/CatSpiritItem.java +++ b/src/main/java/cuteneko/catsplus/item/CatSpiritItem.java @@ -1,6 +1,10 @@ package cuteneko.catsplus.item; +import cuteneko.catsplus.CatsPlusData; +import cuteneko.catsplus.utility.Constants; import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +import net.minecraft.text.Text; import net.minecraft.util.Rarity; public class CatSpiritItem extends Item { @@ -10,4 +14,16 @@ public CatSpiritItem() { .fireproof() .rarity(Rarity.EPIC)); } + + @Override + public Text getName(ItemStack stack) { + var spirit = CatsPlusData.getCatSpirit(stack); + if (spirit.hasCat()) { + if (spirit.hasCustomCatName()) { + return Text.translatable(Constants.MESSAGE_CAT_SPIRIT_NAME, spirit.getCustomCatName().getString()); + } + } + + return super.getName(stack); + } } diff --git a/src/main/java/cuteneko/catsplus/mixins/mixin/CatEntityMixin.java b/src/main/java/cuteneko/catsplus/mixins/mixin/CatEntityMixin.java index 9a34b8d..46dad15 100644 --- a/src/main/java/cuteneko/catsplus/mixins/mixin/CatEntityMixin.java +++ b/src/main/java/cuteneko/catsplus/mixins/mixin/CatEntityMixin.java @@ -1,6 +1,6 @@ package cuteneko.catsplus.mixins.mixin; -import cuteneko.catsplus.CatsPlusPlatform; +import cuteneko.catsplus.CatsPlusData; import cuteneko.catsplus.item.ModItems; import cuteneko.catsplus.utility.GeniusCatHelper; import net.minecraft.entity.EntityType; @@ -36,7 +36,7 @@ public void isBreedingItem(ItemStack stack, CallbackInfoReturnable cir) @Inject(method = "eat", at = @At("TAIL")) protected void eat(PlayerEntity player, Hand hand, ItemStack stack, CallbackInfo ci) { - var geniusCat = CatsPlusPlatform.getGeniusCat((CatEntity) (Object) this); + var geniusCat = CatsPlusData.getGeniusCat((CatEntity) (Object) this); if (this.isOwner(player)) { geniusCat.addFavorability(Objects.requireNonNull(stack.getItem().getFoodComponent()).getHunger(), player); @@ -45,8 +45,8 @@ protected void eat(PlayerEntity player, Hand hand, ItemStack stack, CallbackInfo @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 = CatsPlusPlatform.getCatPlayer(player); - var geniusCat = CatsPlusPlatform.getGeniusCat((CatEntity) (Object) this); + 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)); @@ -76,7 +76,7 @@ protected void eat(PlayerEntity player, Hand hand, ItemStack stack, CallbackInfo @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 = CatsPlusPlatform.getGeniusCat((CatEntity) (Object) this); + var geniusCat = CatsPlusData.getGeniusCat((CatEntity) (Object) this); geniusCat.setFavorability(50, player); } } diff --git a/src/main/java/cuteneko/catsplus/mixins/mixin/PlayerEntityMixin.java b/src/main/java/cuteneko/catsplus/mixins/mixin/PlayerEntityMixin.java index a098083..f7170fb 100644 --- a/src/main/java/cuteneko/catsplus/mixins/mixin/PlayerEntityMixin.java +++ b/src/main/java/cuteneko/catsplus/mixins/mixin/PlayerEntityMixin.java @@ -1,6 +1,6 @@ package cuteneko.catsplus.mixins.mixin; -import cuteneko.catsplus.CatsPlusPlatform; +import cuteneko.catsplus.CatsPlusData; import net.minecraft.entity.EntityType; import net.minecraft.entity.LivingEntity; import net.minecraft.entity.passive.CatEntity; @@ -19,7 +19,7 @@ protected PlayerEntityMixin(EntityType entityType, World @Inject(method = "tick", at = @At("HEAD")) public void tick(CallbackInfo ci) { - var catPlayer = CatsPlusPlatform.getCatPlayer((PlayerEntity) (Object) this); + var catPlayer = CatsPlusData.getCatPlayer((PlayerEntity) (Object) this); if (getFirstPassenger() instanceof CatEntity && (!isOnGround() || catPlayer.isCat())) { diff --git a/src/main/java/cuteneko/catsplus/mixins/mixin/cattify/EntityMixin.java b/src/main/java/cuteneko/catsplus/mixins/mixin/cattify/EntityMixin.java index 7311146..e339a3f 100644 --- a/src/main/java/cuteneko/catsplus/mixins/mixin/cattify/EntityMixin.java +++ b/src/main/java/cuteneko/catsplus/mixins/mixin/cattify/EntityMixin.java @@ -1,6 +1,6 @@ package cuteneko.catsplus.mixins.mixin.cattify; -import cuteneko.catsplus.CatsPlusPlatform; +import cuteneko.catsplus.CatsPlusData; import net.minecraft.entity.Entity; import net.minecraft.entity.player.PlayerEntity; import org.joml.Vector3f; @@ -18,7 +18,7 @@ public abstract class EntityMixin { @Inject(method = "getPassengerAttachmentPos", at = @At("HEAD"), cancellable = true) private void beforeGetMountedHeightOffset(CallbackInfoReturnable cir) { if ((Object) this instanceof PlayerEntity player) { - var catPlayer = CatsPlusPlatform.getCatPlayer(player); + var catPlayer = CatsPlusData.getCatPlayer(player); if (catPlayer.isCat()) { var dimensions = player.getType().getDimensions(); cir.setReturnValue(new Vector3f(0, dimensions.height * 0.9F, 0)); @@ -29,7 +29,7 @@ private void beforeGetMountedHeightOffset(CallbackInfoReturnable cir) @Inject(method = "getStandingEyeHeight", at = @At("HEAD"), cancellable = true) private void beforeGetStandingEyeHeight(CallbackInfoReturnable cir) { if ((Object) this instanceof PlayerEntity player) { - var catPlayer = CatsPlusPlatform.getCatPlayer(player); + var catPlayer = CatsPlusData.getCatPlayer(player); if (catPlayer.isCat()) { cir.setReturnValue(catPlayer.getCatEntity().getStandingEyeHeight() + (isSneaking() ? 0 : 0.2F)); } diff --git a/src/main/java/cuteneko/catsplus/mixins/mixin/cattify/PlayerEntityMixin.java b/src/main/java/cuteneko/catsplus/mixins/mixin/cattify/PlayerEntityMixin.java index 024c498..c8a4a9a 100644 --- a/src/main/java/cuteneko/catsplus/mixins/mixin/cattify/PlayerEntityMixin.java +++ b/src/main/java/cuteneko/catsplus/mixins/mixin/cattify/PlayerEntityMixin.java @@ -1,6 +1,6 @@ package cuteneko.catsplus.mixins.mixin.cattify; -import cuteneko.catsplus.CatsPlusPlatform; +import cuteneko.catsplus.CatsPlusData; import net.minecraft.entity.EntityDimensions; import net.minecraft.entity.EntityPose; import net.minecraft.entity.EntityType; @@ -29,7 +29,7 @@ protected PlayerEntityMixin(EntityType entityType, World @Inject(method = "tick", at = @At("HEAD")) public void tick(CallbackInfo ci) { - var catPlayer = CatsPlusPlatform.getCatPlayer((PlayerEntity) (Object) this); + var catPlayer = CatsPlusData.getCatPlayer((PlayerEntity) (Object) this); if (this.firstUpdate) { this.catsplus$playerDimensions = this.dimensions; @@ -48,7 +48,7 @@ public void tick(CallbackInfo ci) { @Inject(method = "getDimensions", at = @At("HEAD"), cancellable = true) private void beforeGetDimensions(EntityPose pose, CallbackInfoReturnable cir) { - var catPlayer = CatsPlusPlatform.getCatPlayer((PlayerEntity) (Object) this); + var catPlayer = CatsPlusData.getCatPlayer((PlayerEntity) (Object) this); if (catPlayer.isCat()) { cir.setReturnValue(catPlayer.getCatEntity().getDimensions(pose)); } @@ -56,7 +56,7 @@ private void beforeGetDimensions(EntityPose pose, CallbackInfoReturnable cir) { - var catPlayer = CatsPlusPlatform.getCatPlayer((PlayerEntity) (Object) this); + var catPlayer = CatsPlusData.getCatPlayer((PlayerEntity) (Object) this); if (catPlayer.isCat()) { cir.setReturnValue(false); } diff --git a/src/main/java/cuteneko/catsplus/mixins/mixin/cattify/PlayerEntityRendererMixin.java b/src/main/java/cuteneko/catsplus/mixins/mixin/cattify/PlayerEntityRendererMixin.java index 1551d94..3544c5b 100644 --- a/src/main/java/cuteneko/catsplus/mixins/mixin/cattify/PlayerEntityRendererMixin.java +++ b/src/main/java/cuteneko/catsplus/mixins/mixin/cattify/PlayerEntityRendererMixin.java @@ -1,6 +1,6 @@ package cuteneko.catsplus.mixins.mixin.cattify; -import cuteneko.catsplus.CatsPlusPlatform; +import cuteneko.catsplus.CatsPlusData; import net.minecraft.client.MinecraftClient; import net.minecraft.client.network.AbstractClientPlayerEntity; import net.minecraft.client.render.VertexConsumerProvider; @@ -43,7 +43,7 @@ public PlayerEntityRendererMixin(EntityRendererFactory.Context ctx, PlayerEntity cancellable = true ) private void onRender(AbstractClientPlayerEntity player, float f, float g, MatrixStack matrixStack, VertexConsumerProvider vertexConsumerProvider, int i, CallbackInfo ci) { - var catPlayer = CatsPlusPlatform.getCatPlayer(player); + var catPlayer = CatsPlusData.getCatPlayer(player); if (catPlayer.isCat()) { var cat = catPlayer.getCatEntity(); diff --git a/src/main/java/cuteneko/catsplus/mixins/mixin/dancing/AnimalEntityMixin.java b/src/main/java/cuteneko/catsplus/mixins/mixin/dancing/AnimalEntityMixin.java index 0a3b9c8..f9abf9d 100644 --- a/src/main/java/cuteneko/catsplus/mixins/mixin/dancing/AnimalEntityMixin.java +++ b/src/main/java/cuteneko/catsplus/mixins/mixin/dancing/AnimalEntityMixin.java @@ -1,6 +1,6 @@ package cuteneko.catsplus.mixins.mixin.dancing; -import cuteneko.catsplus.CatsPlusPlatform; +import cuteneko.catsplus.CatsPlusData; import net.minecraft.block.Blocks; import net.minecraft.entity.passive.AnimalEntity; import net.minecraft.entity.passive.CatEntity; @@ -14,7 +14,7 @@ public abstract class AnimalEntityMixin { @Inject(method = "tickMovement", at = @At("TAIL")) private void afterTickMovement(CallbackInfo ci) { if ((Object) this instanceof CatEntity cat) { - var geniusCat = CatsPlusPlatform.getGeniusCat(cat); + var geniusCat = CatsPlusData.getGeniusCat(cat); if (geniusCat.getSongSource() == null || !geniusCat.getSongSource().isWithinDistance(cat.getPos(), 3.46) diff --git a/src/main/java/cuteneko/catsplus/mixins/mixin/dancing/CatEntityModelMixin.java b/src/main/java/cuteneko/catsplus/mixins/mixin/dancing/CatEntityModelMixin.java index d2f0c2c..aaee2cb 100644 --- a/src/main/java/cuteneko/catsplus/mixins/mixin/dancing/CatEntityModelMixin.java +++ b/src/main/java/cuteneko/catsplus/mixins/mixin/dancing/CatEntityModelMixin.java @@ -1,6 +1,6 @@ package cuteneko.catsplus.mixins.mixin.dancing; -import cuteneko.catsplus.CatsPlusPlatform; +import cuteneko.catsplus.CatsPlusData; import net.minecraft.client.model.ModelPart; import net.minecraft.client.render.entity.model.CatEntityModel; import net.minecraft.client.render.entity.model.OcelotEntityModel; @@ -20,7 +20,7 @@ public CatEntityModelMixin(ModelPart 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) { - var geniusCat = CatsPlusPlatform.getGeniusCat(cat); + var geniusCat = CatsPlusData.getGeniusCat(cat); if (geniusCat.isSongPlaying()) { this.head.pitch = MathHelper.sin(cat.age) * 0.3f; diff --git a/src/main/java/cuteneko/catsplus/mixins/mixin/dancing/LivingEntityMixin.java b/src/main/java/cuteneko/catsplus/mixins/mixin/dancing/LivingEntityMixin.java index e83dda8..6e31a6b 100644 --- a/src/main/java/cuteneko/catsplus/mixins/mixin/dancing/LivingEntityMixin.java +++ b/src/main/java/cuteneko/catsplus/mixins/mixin/dancing/LivingEntityMixin.java @@ -1,6 +1,6 @@ package cuteneko.catsplus.mixins.mixin.dancing; -import cuteneko.catsplus.CatsPlusPlatform; +import cuteneko.catsplus.CatsPlusData; import net.minecraft.entity.LivingEntity; import net.minecraft.entity.passive.CatEntity; import net.minecraft.util.math.BlockPos; @@ -14,7 +14,7 @@ public abstract class LivingEntityMixin { @Inject(method = "setNearbySongPlaying", at = @At("HEAD")) private void beforeSetNearbySongPlaying(BlockPos songPosition, boolean playing, CallbackInfo ci) { if ((Object) this instanceof CatEntity cat) { - var geniusCat = CatsPlusPlatform.getGeniusCat(cat); + var geniusCat = CatsPlusData.getGeniusCat(cat); geniusCat.songStartPlay(songPosition); } } diff --git a/src/main/java/cuteneko/catsplus/mixins/mixin/favorability/EntityMixin.java b/src/main/java/cuteneko/catsplus/mixins/mixin/favorability/EntityMixin.java index 4cdcb75..a5d756b 100644 --- a/src/main/java/cuteneko/catsplus/mixins/mixin/favorability/EntityMixin.java +++ b/src/main/java/cuteneko/catsplus/mixins/mixin/favorability/EntityMixin.java @@ -1,6 +1,6 @@ package cuteneko.catsplus.mixins.mixin.favorability; -import cuteneko.catsplus.CatsPlusPlatform; +import cuteneko.catsplus.CatsPlusData; import net.minecraft.entity.Entity; import net.minecraft.entity.damage.DamageSource; import net.minecraft.entity.passive.CatEntity; @@ -17,7 +17,7 @@ private void afterDamage(DamageSource source, float amount, CallbackInfoReturnab if ((Object) this instanceof CatEntity cat) { if (cir.getReturnValue()) { if (source.getSource() instanceof PlayerEntity player) { - var geniusCat = CatsPlusPlatform.getGeniusCat(cat); + var geniusCat = CatsPlusData.getGeniusCat(cat); if (cat.isOwner(player)) { geniusCat.subFavorability((int) amount * 5, player); diff --git a/src/main/java/cuteneko/catsplus/mixins/mixin/totemeow/CatSleepWithOwnerGoal.java b/src/main/java/cuteneko/catsplus/mixins/mixin/totemeow/CatSleepWithOwnerGoal.java index 29d882e..b405794 100644 --- a/src/main/java/cuteneko/catsplus/mixins/mixin/totemeow/CatSleepWithOwnerGoal.java +++ b/src/main/java/cuteneko/catsplus/mixins/mixin/totemeow/CatSleepWithOwnerGoal.java @@ -1,8 +1,10 @@ package cuteneko.catsplus.mixins.mixin.totemeow; -import cuteneko.catsplus.CatsPlusPlatform; +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; @@ -16,13 +18,16 @@ public abstract class CatSleepWithOwnerGoal { @Final private CatEntity cat; - @Inject(method = "dropMorningGifts", at = @At("TAIL")) + @Shadow private @Nullable PlayerEntity owner; + + @Inject(method = "dropMorningGifts", at = @At("HEAD"), cancellable = true) private void afterDropMorningGifts(CallbackInfo ci) { - var geniusCat = CatsPlusPlatform.getGeniusCat(cat); + var geniusCat = CatsPlusData.getGeniusCat(cat); - if (!geniusCat.canRespawn()) { - cat.getWorld().sendEntityStatus(cat, EntityStatuses.ADD_VILLAGER_HEART_PARTICLES); - geniusCat.setCanRespawn(true); - } + 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/mixins/mixin/totemeow/LivingEntityMixin.java b/src/main/java/cuteneko/catsplus/mixins/mixin/totemeow/LivingEntityMixin.java index dce6007..474861c 100644 --- a/src/main/java/cuteneko/catsplus/mixins/mixin/totemeow/LivingEntityMixin.java +++ b/src/main/java/cuteneko/catsplus/mixins/mixin/totemeow/LivingEntityMixin.java @@ -1,6 +1,6 @@ package cuteneko.catsplus.mixins.mixin.totemeow; -import cuteneko.catsplus.CatsPlusPlatform; +import cuteneko.catsplus.CatsPlusData; import net.minecraft.entity.Entity; import net.minecraft.entity.EntityStatuses; import net.minecraft.entity.EntityType; @@ -24,7 +24,7 @@ public LivingEntityMixin(EntityType type, World world) { @Inject(method = "tryUseTotem", at = @At("HEAD"), cancellable = true) private void beforeTryUseTotem(DamageSource source, CallbackInfoReturnable cir) { if ((Object) this instanceof CatEntity cat) { - var geniusCat = CatsPlusPlatform.getGeniusCat((CatEntity) (Object) this); + var geniusCat = CatsPlusData.getGeniusCat((CatEntity) (Object) this); if (geniusCat.hasTotem()) { cat.setHealth(1.0f); diff --git a/src/main/java/cuteneko/catsplus/mixins/mixin/totemeow/TamableEntityMixin.java b/src/main/java/cuteneko/catsplus/mixins/mixin/totemeow/TamableEntityMixin.java index 636940f..48d7e27 100644 --- a/src/main/java/cuteneko/catsplus/mixins/mixin/totemeow/TamableEntityMixin.java +++ b/src/main/java/cuteneko/catsplus/mixins/mixin/totemeow/TamableEntityMixin.java @@ -1,6 +1,6 @@ package cuteneko.catsplus.mixins.mixin.totemeow; -import cuteneko.catsplus.CatsPlusPlatform; +import cuteneko.catsplus.CatsPlusData; import cuteneko.catsplus.item.ModItems; import cuteneko.catsplus.utility.GeniusCatHelper; import net.minecraft.entity.EntityStatuses; @@ -9,8 +9,8 @@ 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.nbt.NbtCompound; import net.minecraft.particle.ParticleTypes; import net.minecraft.world.World; import org.spongepowered.asm.mixin.Mixin; @@ -18,6 +18,8 @@ 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) { @@ -34,23 +36,19 @@ private void beforeHandleStatus(byte status, CallbackInfo ci) { } } - @Inject(method = "onDeath", at = @At("HEAD")) - private void beforeDeath(DamageSource damageSource, CallbackInfo ci) { - // Todo: qyl27: More plan here. + @Inject(method = "onDeath", at = @At("RETURN")) + private void afterDeath(DamageSource damageSource, CallbackInfo ci) { if ((Object) this instanceof CatEntity cat) { - var geniusCat = CatsPlusPlatform.getGeniusCat(cat); + var owner = cat.getOwner(); + if (owner instanceof PlayerEntity player) { + var stack = new ItemStack(ModItems.CAT_SPIRIT); + var spirit = CatsPlusData.getCatSpirit(stack); - geniusCat.setLives(geniusCat.getLives() - 1); + spirit.setCat(cat); + spirit.setDeathTime(OffsetDateTime.now()); + spirit.setDeathMessage(this.getDamageTracker().getDeathMessage()); - if(geniusCat.canRespawn() && geniusCat.getLives() > 0) { - var stack = new ItemStack(ModItems.CAT_SPIRIT); - stack.setCount(1); - var nbt = stack.getOrCreateNbt(); - var catNbt = new NbtCompound(); - this.saveNbt(catNbt); - nbt.put("Cat", catNbt); - stack.setNbt(nbt); - this.dropStack(stack); + player.giveItemStack(stack); } } } diff --git a/src/main/java/cuteneko/catsplus/utility/CatPlayerHelper.java b/src/main/java/cuteneko/catsplus/utility/CatPlayerHelper.java index eb4942c..cdf9afa 100644 --- a/src/main/java/cuteneko/catsplus/utility/CatPlayerHelper.java +++ b/src/main/java/cuteneko/catsplus/utility/CatPlayerHelper.java @@ -1,6 +1,6 @@ package cuteneko.catsplus.utility; -import cuteneko.catsplus.CatsPlusPlatform; +import cuteneko.catsplus.CatsPlusData; import net.minecraft.entity.LivingEntity; import net.minecraft.entity.player.PlayerEntity; @@ -9,7 +9,7 @@ public class CatPlayerHelper { public static final Predicate CATTIFY_PLAYER = entity -> { if (entity instanceof PlayerEntity player) { - var catPlayer = CatsPlusPlatform.getCatPlayer(player); + var catPlayer = CatsPlusData.getCatPlayer(player); return catPlayer.isCat(); } return false; diff --git a/src/main/java/cuteneko/catsplus/utility/Constants.java b/src/main/java/cuteneko/catsplus/utility/Constants.java index 5177af0..62a152e 100644 --- a/src/main/java/cuteneko/catsplus/utility/Constants.java +++ b/src/main/java/cuteneko/catsplus/utility/Constants.java @@ -1,8 +1,9 @@ package cuteneko.catsplus.utility; public class Constants { + public static final String TAG_CAT_CONTAINER = "Cat"; + public static final String TAG_ENTITY_POS = "Pos"; - public static final String TAG_CAT_BAG_CAT = "Cat"; public static final String TAG_CUSTOM_NAME = "CustomName"; public static final String TAG_X = "x"; public static final String TAG_Y = "y"; @@ -10,6 +11,9 @@ public class Constants { 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 String TAG_CAT_PLAYER_DATA = "catsplus:cat_player_data"; public static final String TAG_CAT_PLAYER_INNER_CAT = "innerCat"; public static final String TAG_CAT_PLAYER_IS_CAT = "isCat"; @@ -24,11 +28,17 @@ public class Constants { public static final String TAG_GENIUS_CAT_DANCING_SOUND_PLAYING = "soundPlaying"; public static final String MESSAGE_CATS_GROUP_TITLE = "itemGroup.catsplus.catsplus_group"; - public static final String MESSAGE_CAT_BAG_NO_CAT = "item.catsplus.cat_bag.no_cat"; - public static final String MESSAGE_CAT_BAG_HAS_CAT = "item.catsplus.cat_bag.has_cat"; - public static final String MESSAGE_CAT_BAG_HAS_CAT_NAMED = "item.catsplus.cat_bag.has_cat_named"; + + public static final String MESSAGE_CAT_BAG_DESCRIPTION_NO_CAT = "item.catsplus.cat_bag.desc.no_cat"; + public static final String MESSAGE_CAT_BAG_DESCRIPTION_HAS_CAT = "item.catsplus.cat_bag.desc.has_cat"; + public static final String MESSAGE_CAT_BAG_DESCRIPTION_HAS_NAMED_CAT = "item.catsplus.cat_bag.desc.has_named_cat"; public static final String MESSAGE_FANG_LUO_DESCRIPTION_1 = "item.catsplus.fang_luo.desc.1"; public static final String MESSAGE_FANG_LUO_DESCRIPTION_2 = "item.catsplus.fang_luo.desc.2"; + public static final String MESSAGE_CAT_SPIRIT_NAME = "item.catsplus.cat_spirit.with_name"; + public static final String MESSAGE_CAT_SPIRIT_DESCRIPTION_MESSAGE = "item.catsplus.cat_spirit.desc.message"; + public static final String MESSAGE_CAT_SPIRIT_DESCRIPTION_TIME_LABEL = "item.catsplus.cat_spirit.desc.time_label"; + public static final String MESSAGE_CAT_SPIRIT_DESCRIPTION_TIME_PATTERN = "item.catsplus.cat_spirit.desc.time_pattern"; + public static final String MESSAGE_CAT_SPIRIT_DESCRIPTION_TIME_LONG_TIME_AGO = "item.catsplus.cat_spirit.desc.long_time_ago"; public static final String MESSAGE_CATTIFY_POTION = "item.minecraft.potion.effect.cattify"; public static final String MESSAGE_CATTIFY_SPLASH_POTION = "item.minecraft.splash_potion.effect.cattify";