Skip to content

Commit

Permalink
完成 1.18.2 的更新
Browse files Browse the repository at this point in the history
  • Loading branch information
TartaricAcid committed May 1, 2024
1 parent 2931471 commit f744023
Show file tree
Hide file tree
Showing 48 changed files with 623 additions and 310 deletions.
3 changes: 0 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -151,9 +151,6 @@ dependencies {
runtimeOnly fg.deobf("curse.maven:libipn-679177:${libipn_id}")
implementation fg.deobf("curse.maven:inventory-profiles-next-495267:${ipn_id}")

runtimeOnly fg.deobf("org.embeddedt:embeddium-1.18.2:${embeddedt_id}")
runtimeOnly fg.deobf("curse.maven:oculus-581495:${oculus_id}")

runtimeOnly fg.deobf("curse.maven:catalogue-459701:${catalogue_id}")

runtimeOnly fg.deobf("curse.maven:bookshelf-228525:${bookshelf_id}")
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
org.gradle.jvmargs=-Xmx4G
org.gradle.daemon=false
mod_version=1.1.8-hotfix2
mod_version=1.1.9
forge_version=1.18.2-40.2.0
jei_version=9.7.0.194
patchouli_version=1.18.2-67
Expand Down
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();
}
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;
}
}
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;
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.github.tartaricacid.touhoulittlemaid.api.event.client;

import com.github.tartaricacid.touhoulittlemaid.api.entity.IMaid;
import com.github.tartaricacid.touhoulittlemaid.client.resource.models.MaidModels;
import com.github.tartaricacid.touhoulittlemaid.entity.passive.EntityMaid;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;
import net.minecraftforge.eventbus.api.Cancelable;
Expand All @@ -10,15 +10,15 @@
@Cancelable
@OnlyIn(Dist.CLIENT)
public class RenderMaidEvent extends Event {
private final EntityMaid maid;
private final IMaid maid;
private final MaidModels.ModelData modelData;

public RenderMaidEvent(EntityMaid maid, MaidModels.ModelData modelData) {
public RenderMaidEvent(IMaid maid, MaidModels.ModelData modelData) {
this.maid = maid;
this.modelData = modelData;
}

public EntityMaid getMaid() {
public IMaid getMaid() {
return maid;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
@OnlyIn(Dist.CLIENT)
@Mod.EventBusSubscriber(modid = TouhouLittleMaid.MOD_ID, value = Dist.CLIENT, bus = Mod.EventBusSubscriber.Bus.MOD)
public class InfoGetManager {
private static final String ROOT_URL = "http://tlm.cfpa.team:29434/";
private static final String ROOT_URL = "https://tlmdl.cfpa.team/";
private static final String INFO_JSON_URL = ROOT_URL + "info.json";
private static final String INFO_JSON_MD5_URL = ROOT_URL + "info.json.md5";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public final class SpecialMaidRenderEvent {

@SubscribeEvent(priority = EventPriority.HIGHEST)
public static void onRenderPlayerNamedMaid(RenderMaidEvent event) {
Component customName = event.getMaid().getCustomName();
Component customName = event.getMaid().asEntity().getCustomName();
if (customName == null) {
return;
}
Expand All @@ -46,7 +46,7 @@ public static void onRenderPlayerNamedMaid(RenderMaidEvent event) {

@SubscribeEvent(priority = EventPriority.NORMAL)
public static void onRenderEncryptNamedMaid(RenderMaidEvent event) {
Component customName = event.getMaid().getCustomName();
Component customName = event.getMaid().asEntity().getCustomName();
if (customName == null) {
return;
}
Expand All @@ -58,7 +58,7 @@ public static void onRenderEncryptNamedMaid(RenderMaidEvent event) {

@SubscribeEvent(priority = EventPriority.LOW)
public static void onRenderNormalNamedMaid(RenderMaidEvent event) {
Component customName = event.getMaid().getCustomName();
Component customName = event.getMaid().asEntity().getCustomName();
if (customName == null) {
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,17 @@
import com.github.tartaricacid.touhoulittlemaid.client.model.pojo.BedrockModelPOJO;
import com.github.tartaricacid.touhoulittlemaid.client.resource.CustomPackLoader;
import com.github.tartaricacid.touhoulittlemaid.client.resource.pojo.MaidModelInfo;
import com.github.tartaricacid.touhoulittlemaid.entity.passive.EntityMaid;
import net.minecraft.client.Minecraft;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.server.packs.resources.ResourceManager;
import net.minecraft.world.entity.Mob;

import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.nio.charset.StandardCharsets;

public class EasterEggModel extends BedrockModel<EntityMaid> {
public class EasterEggModel extends BedrockModel<Mob> {
private static final ResourceLocation MODEL = new ResourceLocation(TouhouLittleMaid.MOD_ID, "models/entity/easter_egg_model.json");
private static final ResourceLocation TEXTURE = new ResourceLocation(TouhouLittleMaid.MOD_ID, "textures/entity/easter_egg_model.png");
private static EasterEggModel INSTANCE;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,14 @@
import net.minecraft.client.Minecraft;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.server.packs.resources.ResourceManager;
import net.minecraft.world.entity.Mob;

import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.nio.charset.StandardCharsets;

public class PlayerMaidModel extends BedrockModel<EntityMaid> {
public class PlayerMaidModel extends BedrockModel<Mob> {
private static final ResourceLocation STEVE = new ResourceLocation(TouhouLittleMaid.MOD_ID, "models/entity/player_maid.json");
private static final ResourceLocation ALEX = new ResourceLocation(TouhouLittleMaid.MOD_ID, "models/entity/player_maid_slim.json");

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.github.tartaricacid.touhoulittlemaid.client.renderer.entity;

import com.github.tartaricacid.touhoulittlemaid.TouhouLittleMaid;
import com.github.tartaricacid.touhoulittlemaid.api.entity.IMaid;
import com.github.tartaricacid.touhoulittlemaid.api.event.client.RenderMaidEvent;
import com.github.tartaricacid.touhoulittlemaid.client.animation.script.GlWrapper;
import com.github.tartaricacid.touhoulittlemaid.client.model.bedrock.BedrockModel;
Expand All @@ -17,14 +18,15 @@
import net.minecraft.client.renderer.entity.EntityRendererProvider;
import net.minecraft.client.renderer.entity.MobRenderer;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.entity.Mob;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;
import net.minecraftforge.common.MinecraftForge;

import java.util.List;

@OnlyIn(Dist.CLIENT)
public class EntityMaidRenderer extends MobRenderer<EntityMaid, BedrockModel<EntityMaid>> {
public class EntityMaidRenderer extends MobRenderer<Mob, BedrockModel<Mob>> {
private static final ResourceLocation DEFAULT_TEXTURE = new ResourceLocation(TouhouLittleMaid.MOD_ID, "textures/entity/empty.png");
private static final String DEFAULT_MODEL_ID = "touhou_little_maid:hakurei_reimu";
private final GeckoEntityMaidRenderer geckoEntityMaidRenderer;
Expand All @@ -42,30 +44,36 @@ public EntityMaidRenderer(EntityRendererProvider.Context manager) {
}

@Override
public void render(EntityMaid entity, float entityYaw, float partialTicks, PoseStack poseStack, MultiBufferSource bufferIn, int packedLightIn) {
public void render(Mob entity, float entityYaw, float partialTicks, PoseStack poseStack, MultiBufferSource bufferIn, int packedLightIn) {
IMaid maid = IMaid.convert(entity);
if (maid == null) {
return;
}
// 读取默认模型,用于清除不存在模型的缓存残留
CustomPackLoader.MAID_MODELS.getModel(DEFAULT_MODEL_ID).ifPresent(model -> this.model = model);
CustomPackLoader.MAID_MODELS.getInfo(DEFAULT_MODEL_ID).ifPresent(info -> this.mainInfo = info);
CustomPackLoader.MAID_MODELS.getAnimation(DEFAULT_MODEL_ID).ifPresent(animations -> this.mainAnimations = animations);

MaidModels.ModelData eventModelData = new MaidModels.ModelData(model, mainInfo, mainAnimations);
if (MinecraftForge.EVENT_BUS.post(new RenderMaidEvent(entity, eventModelData))) {
BedrockModel<EntityMaid> bedrockModel = eventModelData.getModel();
if (MinecraftForge.EVENT_BUS.post(new RenderMaidEvent(maid, eventModelData))) {
BedrockModel<Mob> bedrockModel = eventModelData.getModel();
if (bedrockModel != null) {
this.model = bedrockModel;
}
this.mainInfo = eventModelData.getInfo();
this.mainAnimations = eventModelData.getAnimations();
} else {
// 通过模型 id 获取对应数据
CustomPackLoader.MAID_MODELS.getModel(entity.getModelId()).ifPresent(model -> this.model = model);
CustomPackLoader.MAID_MODELS.getInfo(entity.getModelId()).ifPresent(info -> this.mainInfo = info);
CustomPackLoader.MAID_MODELS.getAnimation(entity.getModelId()).ifPresent(animations -> this.mainAnimations = animations);
CustomPackLoader.MAID_MODELS.getModel(maid.getModelId()).ifPresent(model -> this.model = model);
CustomPackLoader.MAID_MODELS.getInfo(maid.getModelId()).ifPresent(info -> this.mainInfo = info);
CustomPackLoader.MAID_MODELS.getAnimation(maid.getModelId()).ifPresent(animations -> this.mainAnimations = animations);
}

// 渲染聊天气泡
if (InGameMaidConfig.INSTANCE.isShowChatBubble()) {
ChatBubbleRenderer.renderChatBubble(this, entity, poseStack, bufferIn, packedLightIn);
EntityMaid maidEntity = maid.asStrictMaid();
// 暂定只能女仆显示
if (maidEntity != null && InGameMaidConfig.INSTANCE.isShowChatBubble()) {
ChatBubbleRenderer.renderChatBubble(this, maidEntity, poseStack, bufferIn, packedLightIn);
}

// GeckoLib 接管渲染
Expand All @@ -83,13 +91,13 @@ public void render(EntityMaid entity, float entityYaw, float partialTicks, PoseS
}

@Override
protected void scale(EntityMaid maid, PoseStack poseStack, float partialTickTime) {
protected void scale(Mob maid, PoseStack poseStack, float partialTickTime) {
float scale = mainInfo.getRenderEntityScale();
poseStack.scale(scale, scale, scale);
}

@Override
public ResourceLocation getTextureLocation(EntityMaid maid) {
public ResourceLocation getTextureLocation(Mob maid) {
if (mainInfo == null) {
return DEFAULT_TEXTURE;
}
Expand Down
Loading

0 comments on commit f744023

Please sign in to comment.