Skip to content

Commit

Permalink
[+] Particles.
Browse files Browse the repository at this point in the history
Signed-off-by: 秋雨落 <[email protected]>
  • Loading branch information
qyl27 committed Dec 29, 2024
1 parent 4c14f64 commit 3de45b0
Show file tree
Hide file tree
Showing 26 changed files with 257 additions and 166 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package cuteneko.catsplus.fabric.data.gen;

import cuteneko.catsplus.item.ModItems;
import cuteneko.catsplus.tag.ModItemTags;
import net.fabricmc.fabric.api.datagen.v1.FabricDataOutput;
import net.fabricmc.fabric.api.datagen.v1.provider.FabricTagProvider;
Expand All @@ -20,5 +21,9 @@ protected void addTags(HolderLookup.Provider provider) {
getOrCreateTagBuilder(ModItemTags.COOKED_FISHES)
.add(Items.COOKED_COD)
.add(Items.COOKED_SALMON);

getOrCreateTagBuilder(ModItemTags.CAT_INTERACTABLE)
.add(ModItems.CAT_BAG.get())
.add(ModItems.TOTEMEOW.get());
}
}
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
// 1.21.1 2024-12-29T17:32:40.4693369 Cats+/Language (en_us)
// 1.21.1 2024-12-29T21:45:19.613345 Cats+/Language (en_us)
4c954a23ddc8e4a06ac36b5dd90df1616bbb774f assets\catsplus\lang\en_us.json
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
// 1.21.1 2024-12-29T17:32:40.4708451 Cats+/Language (zh_cn)
// 1.21.1 2024-12-29T21:45:19.6143505 Cats+/Language (zh_cn)
48c49b72a471aa7dc799813b98f69a62d1c6a0dc assets\catsplus\lang\zh_cn.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
// 1.21.1 2024-12-29T17:32:40.4708451 Cats+/Tags for minecraft:block
// 1.21.1 2024-12-29T21:45:19.6143505 Cats+/Tags for minecraft:block
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
// 1.21.1 2024-12-29T17:32:40.4708451 Cats+/Tags for minecraft:item
// 1.21.1 2024-12-29T21:45:19.6143505 Cats+/Tags for minecraft:item
bc229f680fa773a41269c1569f5a700f669eb8e5 data\catsplus\tags\item\cooked_fishes.json
95b8ddf7fc19e46661b4d7924f76d5bab642dbfe data\catsplus\tags\item\cat_interactable.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// 1.21.1 2024-12-29T17:32:40.4698411 Cats+/Recipes
// 1.21.1 2024-12-29T21:45:19.6143505 Cats+/Recipes
42d7ddfe18f0e54b5b8899b35b51d6317bd6746b data\catsplus\recipe\cat_bag.json
1e24c90e0b77a584a20cae12e030f5721fe2de72 data\catsplus\recipe\totemeow.json
bc8eed3e40d27434c01dc0762c38ea6444076bb2 data\catsplus\advancement\recipes\tools\cat_bag.json
Expand Down
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
// 1.21.1 2024-12-29T17:32:40.4698411 Cats+/Model Definitions
// 1.21.1 2024-12-29T21:45:19.613345 Cats+/Model Definitions
882a1bd93aa3b1750ec3f9e2176a49e5561f45a9 assets\catsplus\models\item\totemeow.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"values": [
"catsplus:cat_bag",
"catsplus:totemeow"
]
}
15 changes: 15 additions & 0 deletions src/main/java/cuteneko/catsplus/bridge/ICatBridge.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package cuteneko.catsplus.bridge;

import net.minecraft.core.BlockPos;
import org.jetbrains.annotations.NotNull;

public interface ICatBridge {
boolean catsplus$isSoundPlaying();

@NotNull
BlockPos catsplus$getSoundSource();

void catsplus$startSound(@NotNull BlockPos pos);

void catsplus$stopSound();
}
56 changes: 8 additions & 48 deletions src/main/java/cuteneko/catsplus/data/entity/GeniusCat.java
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
package cuteneko.catsplus.data.entity;

import cuteneko.catsplus.data.ICompoundSerializable;
import cuteneko.catsplus.bridge.ICatBridge;
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;
Expand All @@ -30,8 +28,13 @@ public GeniusCat(Cat cat) {
// Cat's intimacies with player, [-100, 100]
private final Map<UUID, Integer> intimacies = new HashMap<>();

public Integer getIntimacyWith(Player player) {
return intimacies.putIfAbsent(player.getUUID(), 0);
public int getIntimacyWith(Player player) {
var uuid = player.getUUID();
if (!intimacies.containsKey(uuid)) {
intimacies.put(uuid, 0);
}

return intimacies.get(uuid);
}

public void setIntimacyWith(Player player, int value) {
Expand Down Expand Up @@ -62,35 +65,6 @@ public void setTotem(boolean totem) {

// </editor-fold>

// <editor-fold desc="Dancing">

public static final EntityDataAccessor<Boolean> SOUND_PLAYING = SynchedEntityData.defineId(Cat.class, EntityDataSerializers.BOOLEAN);

public static final EntityDataAccessor<BlockPos> 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);
}

// </editor-fold>

@Override
public @NotNull CompoundTag serializeTag(HolderLookup.Provider registries) {
var tag = new CompoundTag();
Expand All @@ -101,13 +75,6 @@ public BlockPos getSoundSource() {
intimaciesTag.putInt(entry.getKey().toString(), entry.getValue());
}
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;
}

Expand All @@ -125,12 +92,5 @@ public void deserializeTag(@NotNull CompoundTag tag, HolderLookup.Provider regis
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);
}
}
}
}
13 changes: 6 additions & 7 deletions src/main/java/cuteneko/catsplus/item/CatBagItem.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,10 @@

public class CatBagItem extends Item {

public CatBagItem() {
super(new Item.Properties()
.fireResistant()
.stacksTo(1)
public CatBagItem(Properties properties) {
super(properties
.component(DataComponents.DYED_COLOR, new DyedItemColor(DyedItemColor.LEATHER_COLOR, false))
.component(ModComponents.CAT_CONTAINER.get(), null)
.sino$tab(ModItemGroups.CATS_PLUS));
.component(ModComponents.CAT_CONTAINER.get(), null));
}

@Override
Expand Down Expand Up @@ -93,6 +90,7 @@ public void appendHoverText(ItemStack stack, TooltipContext context, List<Compon
}

ComponentHelper.removeCatContainer(stack);
player.setItemInHand(context.getHand(), stack);
return InteractionResult.SUCCESS;
}

Expand All @@ -103,7 +101,7 @@ public void appendHoverText(ItemStack stack, TooltipContext context, List<Compon
return InteractionResult.PASS;
}

if (entity instanceof Cat cat) {
if (entity instanceof Cat cat && cat.isTame()) {
if (!cat.isOwnedBy(player)) {
ParticleHelper.showFailed(player);
return InteractionResult.FAIL;
Expand All @@ -112,6 +110,7 @@ public void appendHoverText(ItemStack stack, TooltipContext context, List<Compon
cat.setOrderedToSit(true);
var catContainer = new CatContainer(cat);
ComponentHelper.setCatContainer(stack, catContainer);
player.setItemInHand(usedHand, stack);
cat.discard();
return InteractionResult.SUCCESS;
}
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/cuteneko/catsplus/item/ModItems.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ public static void register() {
ITEMS.register();
}

public static final IRegRef<Item> CAT_BAG = ITEMS.register("cat_bag", CatBagItem::new);
public static final IRegRef<Item> TOTEMEOW = ITEMS.register("totemeow", () -> new Item(new Item.Properties().stacksTo(1).rarity(Rarity.UNCOMMON).sino$tab(ModItemGroups.CATS_PLUS)));
public static final IRegRef<Item> CAT_BAG = ITEMS.register("cat_bag", () -> new CatBagItem(new Item.Properties().fireResistant().stacksTo(1).sino$tab(ModItemGroups.CATS_PLUS)));
public static final IRegRef<Item> TOTEMEOW = ITEMS.register("totemeow", () -> new TotemeowItem(new Item.Properties().stacksTo(1).rarity(Rarity.UNCOMMON).sino$tab(ModItemGroups.CATS_PLUS)));
public static final IRegRef<Item> FANG_LUO = ITEMS.register("fang_luo", () -> new PaperDollItem(new Item.Properties().fireResistant().rarity(Rarity.UNCOMMON)));
public static final IRegRef<Item> CAT_SPIRIT = ITEMS.register("cat_spirit", CatSpiritItem::new);
public static final IRegRef<Item> FANG_LUO = ITEMS.register("fang_luo", PaperDollItem::new);
}
6 changes: 2 additions & 4 deletions src/main/java/cuteneko/catsplus/item/PaperDollItem.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,8 @@
import java.util.List;

public class PaperDollItem extends Item {
public PaperDollItem() {
super(new Item.Properties()
.fireResistant()
.rarity(Rarity.UNCOMMON));
public PaperDollItem(Properties properties) {
super(properties);
}

@Override
Expand Down
33 changes: 33 additions & 0 deletions src/main/java/cuteneko/catsplus/item/TotemeowItem.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package cuteneko.catsplus.item;

import cuteneko.catsplus.CatsPlusData;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.InteractionResult;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.animal.Cat;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack;
import org.jetbrains.annotations.NotNull;

public class TotemeowItem extends Item {
public TotemeowItem(Properties properties) {
super(properties);
}

@Override
public @NotNull InteractionResult interactLivingEntity(ItemStack stack, Player player, LivingEntity entity, InteractionHand hand) {
if (entity instanceof Cat cat) {
var geniusCat = CatsPlusData.getGeniusCat(cat);
if (geniusCat.hasTotem()) {
return InteractionResult.FAIL;
}

geniusCat.setTotem(true);
stack.shrink(1);
return InteractionResult.SUCCESS;
}

return super.interactLivingEntity(stack, player, entity, hand);
}
}
21 changes: 4 additions & 17 deletions src/main/java/cuteneko/catsplus/mixin/CatMixin.java
Original file line number Diff line number Diff line change
Expand Up @@ -57,34 +57,21 @@ protected CatMixin(EntityType<? extends TamableAnimal> entityType, Level level)

@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<InteractionResult> cir) {
if (!isTame()) {
return;
}

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));
} else if (player.getFirstPassenger() == 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);
var item = player.getItemInHand(hand);
if (item.is(ModItemTags.CAT_INTERACTABLE)) {
cir.setReturnValue(InteractionResult.PASS);
}
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package cuteneko.catsplus.mixin.client.musician;

import cuteneko.catsplus.bridge.ICatBridge;
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<T extends Cat>
extends OcelotModel<T> {

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 limbSwing, float limbSwingAmount, float ageInTicks, float netHeadYaw, float headPitch, CallbackInfo ci) {
// Random shake head to left or right.

var bridge = (ICatBridge) cat;
if (!bridge.catsplus$isSoundPlaying()) {
return;
}

var type = Math.floorMod(cat.getUUID().getLeastSignificantBits(), 4);

if (type == 0 || type == 1) {
var bias = type == 0 ? -0.8F : 0.8F;
this.head.xRot = Mth.sin(ageInTicks * bias) * 0.3f;
this.head.yRot = Mth.cos(ageInTicks * bias) * -0.3f;
} else if (type == 2 || type == 3) {
var bias = type == 2 ? -0.8F : 0.8F;
this.head.xRot = Mth.cos(ageInTicks * bias) * 0.3f;
this.head.yRot = Mth.sin(ageInTicks * bias) * -0.3f;
}
}
}
19 changes: 0 additions & 19 deletions src/main/java/cuteneko/catsplus/mixin/dancing/CatMixin.java

This file was deleted.

Loading

0 comments on commit 3de45b0

Please sign in to comment.