-
Notifications
You must be signed in to change notification settings - Fork 72
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2931471
commit f744023
Showing
48 changed files
with
623 additions
and
310 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
82 changes: 82 additions & 0 deletions
82
src/main/java/com/github/tartaricacid/touhoulittlemaid/api/entity/IMaid.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
package com.github.tartaricacid.touhoulittlemaid.api.entity; | ||
|
||
import com.github.tartaricacid.touhoulittlemaid.api.backpack.IMaidBackpack; | ||
import com.github.tartaricacid.touhoulittlemaid.api.event.ConvertMaidEvent; | ||
import com.github.tartaricacid.touhoulittlemaid.entity.backpack.BackpackManager; | ||
import com.github.tartaricacid.touhoulittlemaid.entity.passive.EntityMaid; | ||
import net.minecraft.world.entity.Mob; | ||
import net.minecraft.world.item.ItemStack; | ||
import net.minecraftforge.common.MinecraftForge; | ||
import org.jetbrains.annotations.Nullable; | ||
|
||
/** | ||
* 女仆部分方法的接口化 | ||
* <p> | ||
* 目前仅用于渲染 | ||
*/ | ||
public interface IMaid { | ||
/** | ||
* 转换为接口,同时发送转换事件 | ||
* | ||
* @param mob 需要转换的实体对象 | ||
* @return 转换的 Maid 对象 | ||
*/ | ||
@Nullable | ||
static IMaid convert(Mob mob) { | ||
// 如果是继承了这个接口的,可以直接转换 | ||
if (mob instanceof IMaid maid) { | ||
return maid; | ||
} | ||
// 如果不是,那么发送事件进行检查 | ||
// 这样就可以兼容其他模组 | ||
var event = new ConvertMaidEvent(mob); | ||
MinecraftForge.EVENT_BUS.post(event); | ||
return event.getMaid(); | ||
} | ||
|
||
/** | ||
* 将 Mob 转换成 Maid 对象,转换不成功返回 Null | ||
*/ | ||
@Nullable | ||
static EntityMaid convertToMaid(Mob mob) { | ||
IMaid convert = convert(mob); | ||
if (convert == null) { | ||
return null; | ||
} | ||
return convert.asStrictMaid(); | ||
} | ||
|
||
/** | ||
* 获取背部显示物品 | ||
*/ | ||
default ItemStack getBackpackShowItem() { | ||
return ItemStack.EMPTY; | ||
} | ||
|
||
/** | ||
* 背包类型 | ||
*/ | ||
default IMaidBackpack getMaidBackpackType() { | ||
return BackpackManager.getEmptyBackpack(); | ||
} | ||
|
||
/** | ||
* 转换成女仆对象 | ||
* | ||
* @return 为 null 表示转换不了 | ||
*/ | ||
@Nullable | ||
default EntityMaid asStrictMaid() { | ||
return null; | ||
} | ||
|
||
/** | ||
* 获取模型 ID | ||
*/ | ||
String getModelId(); | ||
|
||
/** | ||
* 转成原实体对象 | ||
*/ | ||
Mob asEntity(); | ||
} |
33 changes: 33 additions & 0 deletions
33
src/main/java/com/github/tartaricacid/touhoulittlemaid/api/event/ConvertMaidEvent.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package com.github.tartaricacid.touhoulittlemaid.api.event; | ||
|
||
import com.github.tartaricacid.touhoulittlemaid.api.entity.IMaid; | ||
import net.minecraft.world.entity.Mob; | ||
import net.minecraftforge.eventbus.api.Event; | ||
import org.jetbrains.annotations.Nullable; | ||
|
||
/** | ||
* 其他模组作者可以捕获此事件 <br> | ||
* 调用 setMaid 方法,传入 IMaid 实例 <br> | ||
* 即可调用女仆渲染 | ||
*/ | ||
public class ConvertMaidEvent extends Event { | ||
private final Mob mob; | ||
private @Nullable IMaid maid; | ||
|
||
public ConvertMaidEvent(Mob mob) { | ||
this.mob = mob; | ||
} | ||
|
||
public Mob getEntity() { | ||
return mob; | ||
} | ||
|
||
public void setMaid(IMaid maid) { | ||
this.maid = maid; | ||
} | ||
|
||
@Nullable | ||
public IMaid getMaid() { | ||
return maid; | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
src/main/java/com/github/tartaricacid/touhoulittlemaid/api/event/MaidAfterEatEvent.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package com.github.tartaricacid.touhoulittlemaid.api.event; | ||
|
||
import com.github.tartaricacid.touhoulittlemaid.entity.passive.EntityMaid; | ||
import net.minecraft.world.item.ItemStack; | ||
import net.minecraftforge.eventbus.api.Event; | ||
|
||
public class MaidAfterEatEvent extends Event { | ||
private final EntityMaid maid; | ||
private final ItemStack foodAfterEat; | ||
|
||
public MaidAfterEatEvent(EntityMaid maid, ItemStack foodAfterEat) { | ||
this.maid = maid; | ||
this.foodAfterEat = foodAfterEat; | ||
} | ||
|
||
public EntityMaid getMaid() { | ||
return maid; | ||
} | ||
|
||
public ItemStack getFoodAfterEat() { | ||
return foodAfterEat; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.