Skip to content

Commit

Permalink
狐狸支持~
Browse files Browse the repository at this point in the history
  • Loading branch information
CSneko committed Dec 8, 2024
1 parent 17eb42d commit a012241
Show file tree
Hide file tree
Showing 19 changed files with 176 additions and 41 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,25 @@
import net.minecraft.world.level.ItemLike;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.CropBlock;
import net.minecraft.world.level.block.SoundType;
import net.minecraft.world.level.block.state.BlockBehaviour;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.material.MapColor;
import net.minecraft.world.level.material.PushReaction;
import net.minecraft.world.phys.shapes.CollisionContext;
import net.minecraft.world.phys.shapes.VoxelShape;
import org.cneko.toneko.common.mod.items.ToNekoItems;
import org.jetbrains.annotations.NotNull;

import java.util.function.Function;

public class CatnipBlock extends CropBlock {
private static final VoxelShape[] SHAPE_BY_AGE = new VoxelShape[]{Block.box(0.0, 0.0, 0.0, 16.0, 2.0, 16.0), Block.box(0.0, 0.0, 0.0, 16.0, 3.0, 16.0), Block.box(0.0, 0.0, 0.0, 16.0, 4.0, 16.0), Block.box(0.0, 0.0, 0.0, 16.0, 5.0, 16.0), Block.box(0.0, 0.0, 0.0, 16.0, 6.0, 16.0), Block.box(0.0, 0.0, 0.0, 16.0, 7.0, 16.0), Block.box(0.0, 0.0, 0.0, 16.0, 8.0, 16.0), Block.box(0.0, 0.0, 0.0, 16.0, 9.0, 16.0)};
public static final MapCodec<CatnipBlock> CODEC = simpleCodec(CatnipBlock::new);
public CatnipBlock(Properties properties) {
super(properties);
public static final MapCodec<CatnipBlock> CODEC = simpleCodec(properties1 -> new CatnipBlock());


public CatnipBlock() {
super(BlockBehaviour.Properties.of().mapColor(MapColor.PLANT).noCollission().randomTicks().instabreak().sound(SoundType.CROP).pushReaction(PushReaction.DESTROY));
}

public @NotNull MapCodec<CatnipBlock> codec() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,22 +1,7 @@
package org.cneko.toneko.common.mod.blocks;

import net.minecraft.core.Registry;
import net.minecraft.core.registries.BuiltInRegistries;
import net.minecraft.core.registries.Registries;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.CropBlock;
import net.minecraft.world.level.block.SoundType;
import net.minecraft.world.level.block.state.BlockBehaviour;
import net.minecraft.world.level.material.MapColor;
import net.minecraft.world.level.material.PushReaction;

import static org.cneko.toneko.common.Bootstrap.MODID;

public class ToNekoBlocks {
public static final Block CATNIP = Registry.register(BuiltInRegistries.BLOCK, ResourceLocation.fromNamespaceAndPath(MODID, "catnip"),
new CatnipBlock(BlockBehaviour.Properties.of().mapColor(MapColor.PLANT).noCollission().randomTicks().instabreak().sound(SoundType.CROP).pushReaction(PushReaction.DESTROY)));

public static void init() {
}
public static Block CATNIP;
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.ItemStack;
import org.cneko.toneko.common.api.TickTasks;
import org.cneko.toneko.common.mod.packets.MateWithCrystalNekoPayload;
import org.cneko.toneko.common.mod.packets.interactives.GiftItemPayload;
import org.cneko.toneko.common.mod.util.TickTaskQueue;
import org.cneko.toneko.common.mod.entities.CrystalNekoEntity;
Expand Down Expand Up @@ -118,12 +119,16 @@ public static Map<String,Button.Builder> getNekoButtonBuilders(InteractionScreen

builders.put("screen.toneko.neko_entity_interactive.button.breed",Button.builder(Component.translatable("screen.toneko.neko_entity_interactive.button.breed"),(btn)->{
Player player = Minecraft.getInstance().player;
TickTaskQueue messageQueue = new TickTaskQueue();
messageQueue.addTask(20, () -> player.sendSystemMessage(Component.translatable("message.toneko.crystal_neko.interactive.breed.0")));
messageQueue.addTask(50, () -> player.sendSystemMessage(Component.translatable("message.toneko.crystal_neko.interactive.breed.1")));
messageQueue.addTask(90, () -> player.sendSystemMessage(Component.translatable("message.toneko.crystal_neko.interactive.breed.2")));
messageQueue.addTask(120, () -> player.sendSystemMessage(Component.translatable("message.toneko.crystal_neko.interactive.breed.3")));
TickTasks.addClient(messageQueue);
if (player.getUUID().equals(CrystalNekoEntity.CRYSTAL_NEKO_UUID)){
ClientPlayNetworking.send(new MateWithCrystalNekoPayload(neko.getUUID().toString()));
}else {
TickTaskQueue messageQueue = new TickTaskQueue();
messageQueue.addTask(20, () -> player.sendSystemMessage(Component.translatable("message.toneko.crystal_neko.interactive.breed.0")));
messageQueue.addTask(50, () -> player.sendSystemMessage(Component.translatable("message.toneko.crystal_neko.interactive.breed.1")));
messageQueue.addTask(90, () -> player.sendSystemMessage(Component.translatable("message.toneko.crystal_neko.interactive.breed.2")));
messageQueue.addTask(120, () -> player.sendSystemMessage(Component.translatable("message.toneko.crystal_neko.interactive.breed.3")));
TickTasks.addClient(messageQueue);
}
}));

return builders;
Expand All @@ -148,7 +153,6 @@ public static Map<String, Button.Builder> getButtonBuilders(Screen screen, Cryst
neko.nya(Minecraft.getInstance().player);
}));


return builders;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,26 +11,30 @@
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.LevelAccessor;
import org.cneko.toneko.common.api.NekoQuery;
import org.cneko.toneko.common.mod.packets.interactives.CrystalNekoInteractivePayload;
import org.jetbrains.annotations.Nullable;

import java.util.UUID;

public class CrystalNekoEntity extends NekoEntity{
public static final String SKIN = "crystal_neko";
public static final String NAME = "Crystal_Neko";
public static final UUID CRYSTAL_NEKO_UUID = UUID.fromString("13309540-fcc1-4d54-884b-55433f1f431f");
private int nyaCount = 0;
public CrystalNekoEntity(EntityType<? extends NekoEntity> entityType, Level level) {
super(entityType, level);
this.setCustomName(Component.literal(NAME));
}

@Override
public @Nullable NekoEntity getBreedOffspring(ServerLevel level, INeko otherParent) {
return null;
public NekoEntity getBreedOffspring(ServerLevel level, INeko otherParent) {
return new CrystalNekoEntity(ToNekoEntities.CRYSTAL_NEKO, level);
}

@Override
public boolean canMate(INeko other) {
return false;
return other.getEntity().getUUID().equals(CRYSTAL_NEKO_UUID);
}

@Override
Expand All @@ -57,4 +61,9 @@ public void nya(Player player){
public static boolean checkCrystalNekoSpawnRules(EntityType<? extends net.minecraft.world.entity.Mob> entityType, LevelAccessor levelAccessor, MobSpawnType reason, BlockPos pos, RandomSource randomSource) {
return true;
}

@Override
public NekoQuery.Neko getNeko() {
return NekoQuery.getNeko(CRYSTAL_NEKO_UUID);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,8 @@ default boolean allowMateIfNotNeko(){
default boolean isNeko(){
return this.getNeko().isNeko();
}

default int getNekoAbility(){
return (int)((this.getNeko().getLevel()+1));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ public abstract class NekoEntity extends AgeableMob implements GeoEntity, INeko
public NekoEntity(EntityType<? extends NekoEntity> entityType, Level level) {
super(entityType, level);
if (!this.level().isClientSide()){
NekoQuery.Neko neko = NekoQuery.getNeko(this.getUUID());
NekoQuery.Neko neko = this.getNeko();
neko.setNeko(true);
randomize();
}
Expand All @@ -105,7 +105,7 @@ public NekoEntity(EntityType<? extends NekoEntity> entityType, Level level) {


public void randomize(){
NekoQuery.Neko neko = NekoQuery.getNeko(this.getUUID());
NekoQuery.Neko neko = this.getNeko();
// 设置名字(如果没有)
if (!this.hasCustomName()) {
this.setCustomName(Component.literal(NekoNameRegistry.getRandomName()));
Expand Down Expand Up @@ -225,7 +225,7 @@ public List<String> getMoeTags(){
String moeTagsString = this.entityData.get(MOE_TAGS_ID);
return moeTagsString.isEmpty() ? List.of() : List.of(moeTagsString.split(":"));
} else {
return NekoQuery.getNeko(this.getUUID()).getMoeTags();
return this.getNeko().getMoeTags();
}
}

Expand All @@ -246,7 +246,7 @@ public void setMoeTags(List<String> moeTags){
// 服务器需要更新猫娘数据,客户端不需要
if (!this.level().isClientSide){
// 同时更新猫娘数据
NekoQuery.getNeko(this.getUUID()).setMoeTags(moeTags);
this.getNeko().setMoeTags(moeTags);
}
// 更新数据
this.entityData.set(MOE_TAGS_ID, String.join(":", moeTags));
Expand Down Expand Up @@ -437,6 +437,9 @@ public void breed(ServerLevel level, INeko mate) {
if (mate instanceof ServerPlayer sp){
sp.connection.send(packet);
}
// 增加等级
this.getNeko().addLevel(0.1);
mate.getNeko().addLevel(0.1);
this.spawnChildFromBreeding(level, mate);
}
public void spawnChildFromBreeding(ServerLevel level, INeko mate) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@
import org.cneko.toneko.common.api.NekoQuery;
import org.cneko.toneko.common.api.Permissions;
import org.cneko.toneko.common.mod.api.EntityPoseManager;
import org.cneko.toneko.common.mod.entities.CrystalNekoEntity;
import org.cneko.toneko.common.mod.entities.INeko;
import org.cneko.toneko.common.mod.packets.MateWithCrystalNekoPayload;
import org.cneko.toneko.common.mod.packets.QuirkQueryPayload;
import org.cneko.toneko.common.mod.packets.interactives.*;
import org.cneko.toneko.common.mod.util.PermissionUtil;
Expand All @@ -36,6 +38,15 @@ public static void init(){
ServerPlayNetworking.registerGlobalReceiver(NekoPosePayload.ID, ToNekoNetworkEvents::onSetPose);
ServerPlayNetworking.registerGlobalReceiver(NekoMatePayload.ID, ToNekoNetworkEvents::onBreed);
ServerPlayNetworking.registerGlobalReceiver(ChatWithNekoPayload.ID, ToNekoNetworkEvents::onChatWithNeko);
ServerPlayNetworking.registerGlobalReceiver(MateWithCrystalNekoPayload.ID, ToNekoNetworkEvents::onMateWithCrystalNeko);
}

public static void onMateWithCrystalNeko(MateWithCrystalNekoPayload mateWithCrystalNekoPayload, ServerPlayNetworking.Context context) {
processNekoInteractive(context.player(), UUID.fromString(mateWithCrystalNekoPayload.uuid()), neko -> {
if (neko instanceof CrystalNekoEntity cneko){
cneko.tryMating((ServerLevel) neko.level(), context.player());
}
});
}

public static void onChatWithNeko(ChatWithNekoPayload payload, ServerPlayNetworking.Context context) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import net.minecraft.world.level.Level;
import net.minecraft.world.phys.AABB;
import org.cneko.toneko.common.mod.codecs.CountCodecs;
import org.cneko.toneko.common.mod.entities.INeko;
import org.cneko.toneko.common.mod.misc.ToNekoComponents;
import org.cneko.toneko.common.mod.misc.ToNekoAttributes;

Expand Down Expand Up @@ -41,8 +42,8 @@ public void inventoryTick(ItemStack stack, Level world, Entity entity, int slot,
entity.getX() + radius, entity.getY() + radius, entity.getZ() + radius);
List<Entity> entities = world.getEntities(entity, box);
for (Entity entity1 : entities) {
if (entity1 instanceof Cat) {
catCount++;
if (entity1 instanceof INeko) {
catCount+= ((INeko) entity1).getNekoAbility();
}
}
if (catCount==0) return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,9 @@ public boolean allowMateIfNotNeko() {
public boolean isNeko() {
return true;
}

@Override
public int getNekoAbility() {
return 1;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package org.cneko.toneko.common.mod.packets;

import net.minecraft.network.RegistryFriendlyByteBuf;
import net.minecraft.network.codec.ByteBufCodecs;
import net.minecraft.network.codec.StreamCodec;
import net.minecraft.network.protocol.common.custom.CustomPacketPayload;
import net.minecraft.resources.ResourceLocation;
import org.jetbrains.annotations.NotNull;

import static org.cneko.toneko.common.Bootstrap.MODID;

public record MateWithCrystalNekoPayload(String uuid) implements CustomPacketPayload {
public static final CustomPacketPayload.Type<MateWithCrystalNekoPayload> ID = new CustomPacketPayload.Type<>(ResourceLocation.fromNamespaceAndPath(MODID, "mate_with_crystal_neko"));
public static final StreamCodec<RegistryFriendlyByteBuf, MateWithCrystalNekoPayload> CODEC = StreamCodec.composite(
ByteBufCodecs.STRING_UTF8, MateWithCrystalNekoPayload::uuid,
MateWithCrystalNekoPayload::new
);

@Override
public @NotNull Type<? extends CustomPacketPayload> type() {
return ID;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,6 @@ public static void init(){
PayloadTypeRegistry.playC2S().register(NekoMatePayload.ID, NekoMatePayload.CODEC);
PayloadTypeRegistry.playS2C().register(CrystalNekoInteractivePayload.ID, CrystalNekoInteractivePayload.CODEC);
PayloadTypeRegistry.playC2S().register(ChatWithNekoPayload.ID, ChatWithNekoPayload.CODEC);
PayloadTypeRegistry.playC2S().register(MateWithCrystalNekoPayload.ID, MateWithCrystalNekoPayload.CODEC);
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions fabric/src/main/java/org/cneko/toneko/fabric/ToNeko.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import org.cneko.toneko.common.mod.util.PermissionUtil;
import org.cneko.toneko.common.util.LanguageUtil;
import org.cneko.toneko.fabric.entities.ToNekoEntities;
import org.cneko.toneko.fabric.items.ToNekoBlocks;
import org.cneko.toneko.fabric.items.ToNekoItems;
import org.cneko.toneko.common.mod.misc.ToNekoAttributes;

Expand All @@ -40,6 +41,7 @@ public void onInitialize() {
ToNekoArmorMaterials.init();
// 注册物品
ToNekoItems.init();
ToNekoBlocks.init();
// 注册状态
ToNekoEffects.init();
// 注册属性
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package org.cneko.toneko.fabric.items;

import net.minecraft.core.Registry;
import net.minecraft.core.registries.BuiltInRegistries;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.level.block.SoundType;
import net.minecraft.world.level.block.state.BlockBehaviour;
import net.minecraft.world.level.material.MapColor;
import net.minecraft.world.level.material.PushReaction;
import org.cneko.toneko.common.mod.blocks.CatnipBlock;

import static org.cneko.toneko.common.Bootstrap.MODID;

public class ToNekoBlocks {
public static void init(){
org.cneko.toneko.common.mod.blocks.ToNekoBlocks.CATNIP = Registry.register(BuiltInRegistries.BLOCK, ResourceLocation.fromNamespaceAndPath(MODID, "catnip"),
new CatnipBlock());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import org.cneko.toneko.common.util.ConfigUtil;
import org.cneko.toneko.common.util.LanguageUtil;
import org.cneko.toneko.neoforge.entities.ToNekoEntities;
import org.cneko.toneko.neoforge.items.ToNekoBlocks;
import org.cneko.toneko.neoforge.msic.ToNekoAttributes;
import org.cneko.toneko.neoforge.items.ToNekoArmorMaterials;
import org.cneko.toneko.neoforge.items.ToNekoItems;
Expand All @@ -35,13 +36,15 @@
@Mod(MODID)
public final class ToNekoNeoForge {
public static final DeferredRegister.Items ITEMS = DeferredRegister.createItems(MODID);
public static final DeferredRegister.Blocks BLOCKS = DeferredRegister.createBlocks(MODID);
public static final DeferredRegister.DataComponents DATA_COMPONENTS = DeferredRegister.createDataComponents(MODID);
public static final DeferredRegister<ArmorMaterial> ARMOR_MATERIALS = DeferredRegister.create(Registries.ARMOR_MATERIAL, MODID);
public static final DeferredRegister<CreativeModeTab> CREATIVE_MODE_TABS = DeferredRegister.create(Registries.CREATIVE_MODE_TAB, MODID);
public static final DeferredRegister<Attribute> ATTRIBUTES = DeferredRegister.create(Registries.ATTRIBUTE, MODID);
public static final DeferredRegister<EntityType<?>> ENTITY_TYPES = DeferredRegister.create(Registries.ENTITY_TYPE, MODID);
public ToNekoNeoForge(IEventBus bus, ModContainer container) {
ITEMS.register(bus);
BLOCKS.register(bus);
DATA_COMPONENTS.register(bus);
ARMOR_MATERIALS.register(bus);
ATTRIBUTES.register(bus);
Expand All @@ -50,6 +53,7 @@ public ToNekoNeoForge(IEventBus bus, ModContainer container) {
// 注册装备
ToNekoArmorMaterials.init();
ToNekoItems.init();
ToNekoBlocks.init();
//bus.addListener(ToNekoItems::buildContents);
//bus.addListener(ToNekoItems::registerEvent);
ToNekoAttributes.init();
Expand Down Expand Up @@ -77,6 +81,7 @@ public ToNekoNeoForge(IEventBus bus, ModContainer container) {
ModBootstrap.bootstrap();
ServerLifecycleEvents.SERVER_STARTED.register(server -> {
ModMeta.INSTANCE.setServer(server);
ToNekoItems.reg();
});
}

Expand Down
Loading

0 comments on commit a012241

Please sign in to comment.