Skip to content

Commit

Permalink
Sync 1.21 (#582)
Browse files Browse the repository at this point in the history
* 修改图标功能

* cherry-pick

* cherry-pick 完成弓箭、弹幕、枪械的骑乘 AI 设计

* cherry-pick 修改本模组 API 注册时间,使其在配置文件之后加载,便于配置文件管控

* 修改背包物品掉落逻辑

* cherry-pick 添加部分 API

* replace forge with neoforge

---------

Co-authored-by: tartaric_acid <baka943@qq.com>
  • Loading branch information
AnonymeMeow and TartaricAcid authored Oct 4, 2024
1 parent 4bd2057 commit 51b3f1e
Show file tree
Hide file tree
Showing 30 changed files with 379 additions and 130 deletions.
Original file line number Diff line number Diff line change
@@ -1,19 +1,12 @@
package com.github.tartaricacid.touhoulittlemaid;

import com.github.tartaricacid.touhoulittlemaid.api.ILittleMaid;
import com.github.tartaricacid.touhoulittlemaid.block.multiblock.MultiBlockManager;
import com.github.tartaricacid.touhoulittlemaid.config.GeneralConfig;
import com.github.tartaricacid.touhoulittlemaid.config.ServerConfig;
import com.github.tartaricacid.touhoulittlemaid.entity.backpack.BackpackManager;
import com.github.tartaricacid.touhoulittlemaid.entity.chatbubble.ChatBubbleManger;
import com.github.tartaricacid.touhoulittlemaid.entity.task.TaskManager;
import com.github.tartaricacid.touhoulittlemaid.entity.task.meal.MaidMealManager;
import com.github.tartaricacid.touhoulittlemaid.init.*;
import com.github.tartaricacid.touhoulittlemaid.init.registry.CommandRegistry;
import com.github.tartaricacid.touhoulittlemaid.inventory.chest.ChestManager;
import com.github.tartaricacid.touhoulittlemaid.item.bauble.BaubleManager;
import com.github.tartaricacid.touhoulittlemaid.network.NetworkHandler;
import com.github.tartaricacid.touhoulittlemaid.util.AnnotatedInstanceUtil;
import com.google.common.collect.Lists;
import net.neoforged.bus.api.IEventBus;
import net.neoforged.fml.ModContainer;
Expand All @@ -35,7 +28,6 @@ public TouhouLittleMaid(IEventBus modEventBus, ModContainer modContainer) {
initRegister(modEventBus);
ChatBubbleManger.initDefaultChat();
registerConfiguration(modContainer);
modApiInit();
}

private static void initRegister(IEventBus eventBus) {
Expand All @@ -45,6 +37,7 @@ private static void initRegister(IEventBus eventBus) {
InitEntities.SENSOR_TYPES.register(eventBus);
InitEntities.SCHEDULES.register(eventBus);
InitEntities.DATA_SERIALIZERS.register(eventBus);
InitEntities.ACTIVITIES.register(eventBus);
InitBlocks.BLOCKS.register(eventBus);
InitBlocks.TILE_ENTITIES.register(eventBus);
InitItems.ITEMS.register(eventBus);
Expand All @@ -69,14 +62,4 @@ private static void registerConfiguration(ModContainer modContainer) {
modContainer.registerConfig(ModConfig.Type.COMMON, GeneralConfig.getConfigSpec());
modContainer.registerConfig(ModConfig.Type.SERVER, ServerConfig.init());
}

private static void modApiInit() {
EXTENSIONS = AnnotatedInstanceUtil.getModExtensions();
TaskManager.init();
BackpackManager.init();
BaubleManager.init();
MultiBlockManager.init();
ChestManager.init();
MaidMealManager.init();
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.github.tartaricacid.touhoulittlemaid.api;

import com.github.tartaricacid.touhoulittlemaid.block.multiblock.MultiBlockManager;
import com.github.tartaricacid.touhoulittlemaid.client.overlay.MaidTipsOverlay;
import com.github.tartaricacid.touhoulittlemaid.client.renderer.entity.EntityMaidRenderer;
import com.github.tartaricacid.touhoulittlemaid.client.renderer.entity.GeckoEntityMaidRenderer;
import com.github.tartaricacid.touhoulittlemaid.entity.backpack.BackpackManager;
Expand Down Expand Up @@ -62,6 +63,15 @@ default void addChestType(ChestManager manager) {
default void addMaidMeal(MaidMealManager manager) {
}

/**
* 添加女仆相关提示
* <p>
* 有些物品在指向女仆时,能够在屏幕上显示相关提示文本
*/
@OnlyIn(Dist.CLIENT)
default void addMaidTips(MaidTipsOverlay maidTipsOverlay) {
}

/**
* 添加默认模型风格的实体 layer 渲染
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.github.tartaricacid.touhoulittlemaid.api.backpack;

import com.github.tartaricacid.touhoulittlemaid.entity.backpack.BackpackManager;
import com.github.tartaricacid.touhoulittlemaid.entity.item.EntityTombstone;
import com.github.tartaricacid.touhoulittlemaid.entity.passive.EntityMaid;
import com.github.tartaricacid.touhoulittlemaid.item.BackpackLevel;
Expand Down Expand Up @@ -60,4 +61,11 @@ public IBackpackData getBackpackData(EntityMaid maid) {
protected final void dropAllItems(EntityMaid maid) {
ItemsUtil.dropEntityItems(maid, maid.getMaidInv(), BackpackLevel.EMPTY_CAPACITY);
}

protected final void dropRelativeItems(ItemStack stack, EntityMaid maid) {
BackpackManager.findBackpack(stack).ifPresentOrElse(backpack -> {
int startIndex = backpack.getAvailableMaxContainerIndex();
ItemsUtil.dropEntityItems(maid, maid.getMaidInv(), startIndex);
}, () -> this.dropAllItems(maid));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package com.github.tartaricacid.touhoulittlemaid.api.event;

import com.github.tartaricacid.touhoulittlemaid.entity.passive.EntityMaid;
import net.neoforged.bus.api.Event;
import snownee.jade.api.ITooltip;
import snownee.jade.api.config.IPluginConfig;

public class AddJadeInfoEvent extends Event {
private final EntityMaid maid;
private final ITooltip tooltip;
private final IPluginConfig pluginConfig;

public AddJadeInfoEvent(EntityMaid maid, ITooltip tooltip, IPluginConfig pluginConfig) {
this.maid = maid;
this.tooltip = tooltip;
this.pluginConfig = pluginConfig;
}

public EntityMaid getMaid() {
return maid;
}

public ITooltip getTooltip() {
return tooltip;
}

public IPluginConfig getPluginConfig() {
return pluginConfig;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package com.github.tartaricacid.touhoulittlemaid.api.event;

import com.github.tartaricacid.touhoulittlemaid.entity.passive.EntityMaid;
import mcjty.theoneprobe.api.IProbeHitEntityData;
import mcjty.theoneprobe.api.IProbeInfo;
import mcjty.theoneprobe.api.ProbeMode;
import net.neoforged.bus.api.Event;

public class AddTopInfoEvent extends Event {
private final EntityMaid maid;
private final ProbeMode probeMode;
private final IProbeInfo probeInfo;
private final IProbeHitEntityData hitEntityData;

public AddTopInfoEvent(EntityMaid maid, ProbeMode probeMode, IProbeInfo probeInfo, IProbeHitEntityData hitEntityData) {
this.maid = maid;
this.probeMode = probeMode;
this.probeInfo = probeInfo;
this.hitEntityData = hitEntityData;
}

public EntityMaid getMaid() {
return maid;
}

public ProbeMode getProbeMode() {
return probeMode;
}

public IProbeInfo getProbeInfo() {
return probeInfo;
}

public IProbeHitEntityData getHitEntityData() {
return hitEntityData;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,16 @@ public interface IMaidTask {
*/
List<Pair<Integer, BehaviorControl<? super EntityMaid>>> createBrainTasks(EntityMaid maid);

/**
* 骑乘、待命状态下执行的 AI,注意此时女仆不能移动,只能站桩执行相关 AI
*
* @param maid 女仆对象
* @return 如果什么都不做,请返回空集合
*/
default List<Pair<Integer, BehaviorControl<? super EntityMaid>>> createRideBrainTasks(EntityMaid maid) {
return Collections.emptyList();
}

/**
* 当前 Task 是否可使用
*
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package com.github.tartaricacid.touhoulittlemaid.client.overlay;

import com.github.tartaricacid.touhoulittlemaid.TouhouLittleMaid;
import com.github.tartaricacid.touhoulittlemaid.api.ILittleMaid;
import com.github.tartaricacid.touhoulittlemaid.entity.passive.EntityMaid;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Maps;
import net.minecraft.client.DeltaTracker;
import net.minecraft.client.Minecraft;
Expand All @@ -26,35 +28,44 @@

public class MaidTipsOverlay implements LayeredDraw.Layer {
private static final ResourceLocation ICON = ResourceLocation.fromNamespaceAndPath(TouhouLittleMaid.MOD_ID, "textures/gui/maid_tips_icon.png");
private static final Map<Item, MutableComponent> TIPS = Maps.newHashMap();

private static Map<Item, MutableComponent> TIPS = Maps.newHashMap();
private static Map<CheckCondition, MutableComponent> SPECIAL_TIPS = Maps.newHashMap();

public static void init() {
addTips("overlay.touhou_little_maid.compass.tips", Items.COMPASS);
addTips("overlay.touhou_little_maid.golden_apple.tips", Items.GOLDEN_APPLE, Items.ENCHANTED_GOLDEN_APPLE);
addTips("overlay.touhou_little_maid.potion.tips", Items.POTION);
addTips("overlay.touhou_little_maid.milk_bucket.tips", Items.MILK_BUCKET);
addTips("overlay.touhou_little_maid.script_book.tips", Items.WRITABLE_BOOK, Items.WRITTEN_BOOK);
addTips("overlay.touhou_little_maid.glass_bottle.tips", Items.GLASS_BOTTLE);
addTips("overlay.touhou_little_maid.name_tag.tips", Items.NAME_TAG);
addTips("overlay.touhou_little_maid.lead.tips", Items.LEAD);
addTips("overlay.touhou_little_maid.debug_stick.tips", Items.DEBUG_STICK);
addTips("overlay.touhou_little_maid.saddle.tips", Items.SADDLE);
}
MaidTipsOverlay overlay = new MaidTipsOverlay();

private static MutableComponent checkSpecialTips(ItemStack mainhandItem, EntityMaid maid, LocalPlayer player) {
if (!maid.isOwnedBy(player) && EntityMaid.getNtrItem().test(mainhandItem)) {
return Component.translatable("overlay.touhou_little_maid.ntr_item.tips");
}
if (maid.isOwnedBy(player) && maid.hasBackpack() && mainhandItem.is(Tags.Items.TOOLS_SHEAR)) {
return Component.translatable("overlay.touhou_little_maid.remove_backpack.tips");
overlay.addTips("overlay.touhou_little_maid.compass.tips", Items.COMPASS);
overlay.addTips("overlay.touhou_little_maid.golden_apple.tips", Items.GOLDEN_APPLE, Items.ENCHANTED_GOLDEN_APPLE);
overlay.addTips("overlay.touhou_little_maid.potion.tips", Items.POTION);
overlay.addTips("overlay.touhou_little_maid.milk_bucket.tips", Items.MILK_BUCKET);
overlay.addTips("overlay.touhou_little_maid.script_book.tips", Items.WRITABLE_BOOK, Items.WRITTEN_BOOK);
overlay.addTips("overlay.touhou_little_maid.glass_bottle.tips", Items.GLASS_BOTTLE);
overlay.addTips("overlay.touhou_little_maid.name_tag.tips", Items.NAME_TAG);
overlay.addTips("overlay.touhou_little_maid.lead.tips", Items.LEAD);
overlay.addTips("overlay.touhou_little_maid.debug_stick.tips", Items.DEBUG_STICK);
overlay.addTips("overlay.touhou_little_maid.saddle.tips", Items.SADDLE);

overlay.addSpecialTips("overlay.touhou_little_maid.ntr_item.tips", (item, maid, player) -> !maid.isOwnedBy(player) && EntityMaid.getNtrItem().test(item));
overlay.addSpecialTips("overlay.touhou_little_maid.remove_backpack.tips", (item, maid, player) -> maid.isOwnedBy(player) && maid.hasBackpack() && item.is(Tags.Items.TOOLS_SHEAR));

for (ILittleMaid littleMaid : TouhouLittleMaid.EXTENSIONS) {
littleMaid.addMaidTips(overlay);
}
return null;

TIPS = ImmutableMap.copyOf(TIPS);
SPECIAL_TIPS = ImmutableMap.copyOf(SPECIAL_TIPS);
}

private static void addTips(String key, Item... items) {
for (Item item : items) {
TIPS.put(item, Component.translatable(key));
private static MutableComponent checkSpecialTips(ItemStack mainhandItem, EntityMaid maid, LocalPlayer player) {
for (Map.Entry<CheckCondition, MutableComponent> entry : SPECIAL_TIPS.entrySet()) {
CheckCondition condition = entry.getKey();
MutableComponent text = entry.getValue();
if (condition.test(mainhandItem, maid, player)) {
return text;
}
}
return null;
}

@Override
Expand Down Expand Up @@ -102,4 +113,18 @@ public void render(@NotNull GuiGraphics guiGraphics, @NotNull DeltaTracker delta
}
}
}

public void addTips(String key, Item... items) {
for (Item item : items) {
TIPS.put(item, Component.translatable(key));
}
}

public void addSpecialTips(String key, CheckCondition condition) {
SPECIAL_TIPS.put(condition, Component.translatable(key));
}

public interface CheckCondition {
boolean test(ItemStack mainhandItem, EntityMaid maid, LocalPlayer player);
}
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
package com.github.tartaricacid.touhoulittlemaid.compat.jade.provider;

import com.github.tartaricacid.touhoulittlemaid.TouhouLittleMaid;
import com.github.tartaricacid.touhoulittlemaid.api.event.AddJadeInfoEvent;
import com.github.tartaricacid.touhoulittlemaid.api.task.IMaidTask;
import com.github.tartaricacid.touhoulittlemaid.entity.passive.EntityMaid;
import net.minecraft.ChatFormatting;
import net.minecraft.network.chat.Component;
import net.minecraft.network.chat.MutableComponent;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.entity.schedule.Activity;
import net.neoforged.neoforge.common.NeoForge;
import snownee.jade.api.EntityAccessor;
import snownee.jade.api.IEntityComponentProvider;
import snownee.jade.api.ITooltip;
Expand All @@ -25,6 +27,10 @@ public void appendTooltip(ITooltip iTooltip, EntityAccessor entityAccessor, IPlu
if (maid.isTame()) {
IMaidTask task = maid.getTask();
iTooltip.add(Component.translatable("top.touhou_little_maid.entity_maid.task").append(task.getName()));

// 添加于 Mode 之下,用于给 Mode 添加额外的信息
NeoForge.EVENT_BUS.post(new AddJadeInfoEvent(maid, iTooltip, iPluginConfig));

iTooltip.add(Component.translatable("top.touhou_little_maid.entity_maid.schedule").append(getActivityTransText(maid)));
iTooltip.add(Component.translatable("top.touhou_little_maid.entity_maid.favorability", maid.getFavorabilityManager().getLevel()));
iTooltip.add(Component.translatable("top.touhou_little_maid.entity_maid.nex_favorability_point", maid.getFavorabilityManager().nextLevelPoint()));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.github.tartaricacid.touhoulittlemaid.compat.top.provider;

import com.github.tartaricacid.touhoulittlemaid.TouhouLittleMaid;
import com.github.tartaricacid.touhoulittlemaid.api.event.AddTopInfoEvent;
import com.github.tartaricacid.touhoulittlemaid.api.task.IMaidTask;
import com.github.tartaricacid.touhoulittlemaid.entity.passive.EntityMaid;
import mcjty.theoneprobe.api.*;
Expand All @@ -12,6 +13,7 @@
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.entity.schedule.Activity;
import net.minecraft.world.level.Level;
import net.neoforged.neoforge.common.NeoForge;

public class MaidProvider implements IProbeInfoEntityProvider {
private static final String ID = (ResourceLocation.fromNamespaceAndPath(TouhouLittleMaid.MOD_ID, "maid")).toString();
Expand All @@ -24,6 +26,9 @@ public void addProbeEntityInfo(ProbeMode probeMode, IProbeInfo probeInfo, Player
MutableComponent taskTitle = Component.translatable("top.touhou_little_maid.entity_maid.task").append(task.getName());
probeInfo.horizontal(probeInfo.defaultLayoutStyle().alignment(ElementAlignment.ALIGN_CENTER)).text(taskTitle);

// 添加于 Mode 之下,用于给 Mode 添加额外的信息
NeoForge.EVENT_BUS.post(new AddTopInfoEvent(maid, probeMode, probeInfo, iProbeHitEntityData));

MutableComponent scheduleTitle = Component.translatable("top.touhou_little_maid.entity_maid.schedule").append(getActivityTransText(maid));
probeInfo.horizontal(probeInfo.defaultLayoutStyle().alignment(ElementAlignment.ALIGN_CENTER)).text(scheduleTitle);

Expand Down
Loading

0 comments on commit 51b3f1e

Please sign in to comment.