Skip to content

Commit

Permalink
添加部分内容
Browse files Browse the repository at this point in the history
- 添加油库里(替换史莱姆模型)
- 添加得分道具、命点等材质替换
  • Loading branch information
TartaricAcid committed Oct 20, 2023
1 parent b259b8b commit ef62d36
Show file tree
Hide file tree
Showing 18 changed files with 369 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import net.minecraft.client.renderer.blockentity.BlockEntityRenderers;
import net.minecraft.client.renderer.entity.EntityRenderers;
import net.minecraft.client.renderer.entity.ThrownItemRenderer;
import net.minecraft.world.entity.EntityType;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.client.event.EntityRenderersEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent;
Expand All @@ -36,6 +37,10 @@ public static void onEntityRenderers(EntityRenderersEvent.RegisterRenderers evt)
EntityRenderers.register(EntityExtinguishingAgent.TYPE, EntityExtinguishingAgentRenderer::new);
EntityRenderers.register(EntityBox.TYPE, EntityBoxRender::new);
EntityRenderers.register(EntityThrowPowerPoint.TYPE, ThrownItemRenderer::new);

EntityRenderers.register(EntityType.SLIME, EntityYukkuriSlimeRender::new);
EntityRenderers.register(EntityType.EXPERIENCE_ORB, ReplaceExperienceOrbRenderer::new);

BlockEntityRenderers.register(TileEntityAltar.TYPE, TileEntityAltarRenderer::new);
BlockEntityRenderers.register(TileEntityStatue.TYPE, TileEntityStatueRenderer::new);
BlockEntityRenderers.register(TileEntityGarageKit.TYPE, TileEntityGarageKitRenderer::new);
Expand All @@ -51,5 +56,6 @@ public static void onRegisterLayers(EntityRenderersEvent.RegisterLayerDefinition
event.registerLayerDefinition(MaidBackpackMiddleModel.LAYER, MaidBackpackMiddleModel::createBodyLayer);
event.registerLayerDefinition(MaidBackpackSmallModel.LAYER, MaidBackpackSmallModel::createBodyLayer);
event.registerLayerDefinition(StatueBaseModel.LAYER, StatueBaseModel::createBodyLayer);
event.registerLayerDefinition(EntityYukkuriModel.LAYER, EntityYukkuriModel::createBodyLayer);
}
}
Original file line number Diff line number Diff line change
@@ -1,27 +1,37 @@
package com.github.tartaricacid.touhoulittlemaid.client.init;

import com.github.tartaricacid.touhoulittlemaid.TouhouLittleMaid;
import com.github.tartaricacid.touhoulittlemaid.client.renderer.item.PerspectiveBakedModel;
import com.github.tartaricacid.touhoulittlemaid.client.renderer.item.ReplaceableBakedModel;
import com.github.tartaricacid.touhoulittlemaid.config.subconfig.VanillaConfig;
import com.github.tartaricacid.touhoulittlemaid.init.InitItems;
import com.google.common.collect.Lists;
import net.minecraft.client.resources.model.BakedModel;
import net.minecraft.client.resources.model.ModelResourceLocation;
import net.minecraft.core.registries.Registries;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.Items;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.client.event.ModelEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.registries.ForgeRegistries;
import net.minecraftforge.registries.RegisterEvent;
import org.apache.commons.lang3.tuple.Pair;
import org.apache.commons.lang3.tuple.Triple;

import java.util.List;
import java.util.Map;
import java.util.function.Supplier;

@Mod.EventBusSubscriber(value = Dist.CLIENT, bus = Mod.EventBusSubscriber.Bus.MOD)
public final class InitSpecialItemRender {
private static final List<Pair<ModelResourceLocation, ModelResourceLocation>> PERSPECTIVE_MODEL_LIST = Lists.newArrayList();
private static final List<Triple<ModelResourceLocation, ModelResourceLocation, Supplier<Boolean>>> REPLACEABLE_MODEL_LIST = Lists.newArrayList();

private static final ResourceLocation LIFE_POINT = new ResourceLocation(TouhouLittleMaid.MOD_ID, "life_point");
private static final ResourceLocation POINT_ITEM = new ResourceLocation(TouhouLittleMaid.MOD_ID, "point_item");

@SubscribeEvent
public static void register(RegisterEvent event) {
Expand All @@ -30,6 +40,9 @@ public static void register(RegisterEvent event) {
addInHandModel(InitItems.EXTINGUISHER.get());
addInHandModel(InitItems.CAMERA.get());
addInHandModel(InitItems.MAID_BEACON.get());

addReplaceableModel(Items.TOTEM_OF_UNDYING, LIFE_POINT, () -> VanillaConfig.REPLACE_TOTEM_TEXTURE.get());
addReplaceableModel(Items.EXPERIENCE_BOTTLE, POINT_ITEM, () -> VanillaConfig.REPLACE_XP_BOTTLE_TEXTURE.get());
}
}

Expand All @@ -40,11 +53,17 @@ public static void onBakedModel(ModelEvent.BakingCompleted event) {
PerspectiveBakedModel model = new PerspectiveBakedModel(registry.get(pair.getLeft()), registry.get(pair.getRight()));
registry.put(pair.getLeft(), model);
}

for (Triple<ModelResourceLocation, ModelResourceLocation, Supplier<Boolean>> triple : REPLACEABLE_MODEL_LIST) {
ReplaceableBakedModel model = new ReplaceableBakedModel(registry.get(triple.getLeft()), registry.get(triple.getMiddle()), triple.getRight());
registry.put(triple.getLeft(), model);
}
}

@SubscribeEvent
public static void registerModels(ModelEvent.RegisterAdditional event) {
PERSPECTIVE_MODEL_LIST.forEach((pair) -> event.register(pair.getRight()));
REPLACEABLE_MODEL_LIST.forEach((triple) -> event.register(triple.getMiddle()));
}

public static void addInHandModel(Item item) {
Expand All @@ -55,4 +74,13 @@ public static void addInHandModel(Item item) {
PERSPECTIVE_MODEL_LIST.add(Pair.of(rawName, inHandName));
}
}

public static void addReplaceableModel(Item item, ResourceLocation replacedModel, Supplier<Boolean> isReplace) {
ResourceLocation res = ForgeRegistries.ITEMS.getKey(item);
if (res != null) {
ModelResourceLocation rawModelResourceLocation = new ModelResourceLocation(res, "inventory");
ModelResourceLocation replacedModelResourceLocation = new ModelResourceLocation(replacedModel, "inventory");
REPLACEABLE_MODEL_LIST.add(Triple.of(rawModelResourceLocation, replacedModelResourceLocation, isReplace));
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package com.github.tartaricacid.touhoulittlemaid.client.model;

import com.github.tartaricacid.touhoulittlemaid.TouhouLittleMaid;
import com.mojang.blaze3d.vertex.PoseStack;
import com.mojang.blaze3d.vertex.VertexConsumer;
import net.minecraft.client.model.EntityModel;
import net.minecraft.client.model.geom.ModelLayerLocation;
import net.minecraft.client.model.geom.ModelPart;
import net.minecraft.client.model.geom.PartPose;
import net.minecraft.client.model.geom.builders.*;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.entity.monster.Slime;

public class EntityYukkuriModel extends EntityModel<Slime> {
public static final ModelLayerLocation LAYER = new ModelLayerLocation(new ResourceLocation(TouhouLittleMaid.MOD_ID, "main"), "yukkuri");
private final ModelPart bone;

public EntityYukkuriModel(ModelPart root) {
this.bone = root.getChild("bone");
}

public static LayerDefinition createBodyLayer() {
MeshDefinition meshdefinition = new MeshDefinition();
PartDefinition partdefinition = meshdefinition.getRoot();
PartDefinition bone = partdefinition.addOrReplaceChild("bone", CubeListBuilder.create().texOffs(0, 18).addBox(-4.0F, -8.0F, -4.0F, 8.0F, 8.0F, 8.0F, new CubeDeformation(0.0F))
.texOffs(0, 0).addBox(-4.5F, -8.5F, -4.5F, 9.0F, 9.0F, 9.0F, new CubeDeformation(0.0F))
.texOffs(38, 0).mirror().addBox(3.0F, -3.75F, -5.0F, 2.0F, 4.0F, 2.0F, new CubeDeformation(-0.35F)).mirror(false)
.texOffs(38, 0).addBox(-5.0F, -3.75F, -5.0F, 2.0F, 4.0F, 2.0F, new CubeDeformation(-0.35F))
.texOffs(0, 0).addBox(-1.5F, -11.0F, -2.0F, 2.0F, 3.0F, 0.0F, new CubeDeformation(0.0F)), PartPose.offset(0.0F, 24.0F, 0.0F));
PartDefinition bone2 = bone.addOrReplaceChild("bone2", CubeListBuilder.create().texOffs(48, 14).addBox(-0.8195F, -2.0F, 0.1061F, 7.0F, 4.0F, 1.0F, new CubeDeformation(-0.2F)), PartPose.offsetAndRotation(0.0F, -6.5F, 4.0F, 0.0F, -0.1745F, -0.4363F));
PartDefinition bone3 = bone.addOrReplaceChild("bone3", CubeListBuilder.create().texOffs(48, 14).mirror().addBox(-6.1805F, -2.0F, 0.1061F, 7.0F, 4.0F, 1.0F, new CubeDeformation(-0.2F)).mirror(false), PartPose.offsetAndRotation(0.0F, -6.5F, 4.0F, 0.0F, 0.1745F, 0.4363F));
PartDefinition bone4 = bone.addOrReplaceChild("bone4", CubeListBuilder.create().texOffs(50, 20).addBox(-0.3195F, -2.0F, 0.1061F, 6.0F, 4.0F, 1.0F, new CubeDeformation(-0.3F)), PartPose.offsetAndRotation(0.0F, -6.5F, 4.0F, 0.0F, -0.1745F, 2.7053F));
PartDefinition bone5 = bone.addOrReplaceChild("bone5", CubeListBuilder.create().texOffs(50, 20).mirror().addBox(-5.6805F, -2.0F, 0.1061F, 6.0F, 4.0F, 1.0F, new CubeDeformation(-0.3F)).mirror(false), PartPose.offsetAndRotation(0.0F, -6.5F, 4.0F, 0.0F, 0.1745F, -2.7053F));
PartDefinition bone6 = bone.addOrReplaceChild("bone6", CubeListBuilder.create().texOffs(48, 0).addBox(0.1F, -3.5F, -3.3F, 2.0F, 7.0F, 6.0F, new CubeDeformation(0.0F)), PartPose.offsetAndRotation(3.0F, -3.0F, 1.0F, 0.0F, 0.0F, -0.2618F));
PartDefinition bone7 = bone.addOrReplaceChild("bone7", CubeListBuilder.create().texOffs(48, 0).mirror().addBox(-2.1F, -3.5F, -3.3F, 2.0F, 7.0F, 6.0F, new CubeDeformation(0.0F)).mirror(false), PartPose.offsetAndRotation(-3.0F, -3.0F, 1.0F, 0.0F, 0.0F, 0.2618F));
PartDefinition bone8 = bone.addOrReplaceChild("bone8", CubeListBuilder.create().texOffs(54, 35).addBox(-2.0F, -0.6042F, -1.0909F, 4.0F, 9.0F, 1.0F, new CubeDeformation(0.0F)), PartPose.offsetAndRotation(0.0F, -8.0F, 6.0F, 0.1745F, 0.0F, 0.0F));
return LayerDefinition.create(meshdefinition, 64, 64);
}

@Override
public void setupAnim(Slime slime, float limbSwing, float limbSwingAmount, float ageInTicks, float netHeadYaw, float headPitch) {
}

@Override
public void renderToBuffer(PoseStack poseStack, VertexConsumer vertexConsumer, int packedLight, int packedOverlay, float red, float green, float blue, float alpha) {
bone.render(poseStack, vertexConsumer, packedLight, packedOverlay, red, green, blue, alpha);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package com.github.tartaricacid.touhoulittlemaid.client.renderer.entity;

import com.github.tartaricacid.touhoulittlemaid.TouhouLittleMaid;
import com.github.tartaricacid.touhoulittlemaid.client.model.EntityYukkuriModel;
import com.github.tartaricacid.touhoulittlemaid.config.subconfig.VanillaConfig;
import com.mojang.blaze3d.vertex.PoseStack;
import net.minecraft.client.renderer.MultiBufferSource;
import net.minecraft.client.renderer.entity.EntityRendererProvider;
import net.minecraft.client.renderer.entity.MobRenderer;
import net.minecraft.client.renderer.entity.SlimeRenderer;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.util.Mth;
import net.minecraft.world.entity.monster.Slime;

public class EntityYukkuriSlimeRender extends MobRenderer<Slime, EntityYukkuriModel> {
private static final ResourceLocation TEXTURE = new ResourceLocation(TouhouLittleMaid.MOD_ID, "textures/entity/yukkuri.png");
private final SlimeRenderer vanillaRender;

public EntityYukkuriSlimeRender(EntityRendererProvider.Context context) {
super(context, new EntityYukkuriModel(context.bakeLayer(EntityYukkuriModel.LAYER)), 0.25F);
this.vanillaRender = new SlimeRenderer(context);
}

@Override
public void render(Slime slime, float yaw, float partialTicks, PoseStack poseStack, MultiBufferSource buffer, int packedLight) {
if (VanillaConfig.REPLACE_SLIME_MODEL.get()) {
renderYukkuri(slime, yaw, partialTicks, poseStack, buffer, packedLight);
} else {
vanillaRender.render(slime, yaw, partialTicks, poseStack, buffer, packedLight);
}
}

private void renderYukkuri(Slime slime, float yaw, float partialTicks, PoseStack poseStack, MultiBufferSource buffer, int packedLight) {
this.shadowRadius = 0.25F * (float) slime.getSize();
super.render(slime, yaw, partialTicks, poseStack, buffer, packedLight);
}

protected void scale(Slime slime, PoseStack poseStack, float partialTicks) {
poseStack.scale(0.999F, 0.999F, 0.999F);
poseStack.translate(0.0F, 0.001F, 0.0F);
float slimeSize = (float) slime.getSize();
float tmp = Mth.lerp(partialTicks, slime.oSquish, slime.squish) / (slimeSize * 0.5F + 1.0F);
float scale = 1.0F / (tmp + 1.0F);
poseStack.scale(scale * slimeSize, 1.0F / scale * slimeSize, scale * slimeSize);
}

public ResourceLocation getTextureLocation(Slime slime) {
return TEXTURE;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
package com.github.tartaricacid.touhoulittlemaid.client.renderer.entity;

import com.github.tartaricacid.touhoulittlemaid.TouhouLittleMaid;
import com.github.tartaricacid.touhoulittlemaid.config.subconfig.VanillaConfig;
import com.mojang.blaze3d.vertex.PoseStack;
import com.mojang.blaze3d.vertex.VertexConsumer;
import com.mojang.math.Axis;
import net.minecraft.client.renderer.MultiBufferSource;
import net.minecraft.client.renderer.RenderType;
import net.minecraft.client.renderer.entity.EntityRenderer;
import net.minecraft.client.renderer.entity.EntityRendererProvider;
import net.minecraft.client.renderer.entity.ExperienceOrbRenderer;
import net.minecraft.client.renderer.texture.OverlayTexture;
import net.minecraft.core.BlockPos;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.util.Mth;
import net.minecraft.world.entity.ExperienceOrb;
import org.joml.Matrix3f;
import org.joml.Matrix4f;

public class ReplaceExperienceOrbRenderer extends EntityRenderer<ExperienceOrb> {
private static final ResourceLocation POINT_ITEM_TEXTURE = new ResourceLocation(TouhouLittleMaid.MOD_ID, "textures/entity/point_item.png");
private static final RenderType RENDER_TYPE = RenderType.entityCutoutNoCull(POINT_ITEM_TEXTURE);
private final ExperienceOrbRenderer vanillaRender;

public ReplaceExperienceOrbRenderer(EntityRendererProvider.Context context) {
super(context);
this.shadowRadius = 0.15F;
this.shadowStrength = 0.75F;
this.vanillaRender = new ExperienceOrbRenderer(context);
}

protected int getBlockLightLevel(ExperienceOrb pEntity, BlockPos pPos) {
return Mth.clamp(super.getBlockLightLevel(pEntity, pPos) + 7, 0, 15);
}

@Override
public void render(ExperienceOrb orb, float pEntityYaw, float partialTicks, PoseStack poseStack, MultiBufferSource buffer, int packedLight) {
if (VanillaConfig.REPLACE_XP_TEXTURE.get()) {
renderPointItem(orb, pEntityYaw, partialTicks, poseStack, buffer, packedLight);
} else {
vanillaRender.render(orb, pEntityYaw, partialTicks, poseStack, buffer, packedLight);
}
}

private void renderPointItem(ExperienceOrb orb, float pEntityYaw, float partialTicks, PoseStack poseStack, MultiBufferSource buffer, int packedLight) {
poseStack.pushPose();
int icon = orb.getIcon();
float texU1 = (float) (icon % 4 * 16) / 64.0F;
float texU2 = (float) (icon % 4 * 16 + 16) / 64.0F;
float texV2 = (float) (icon / 4 * 16) / 64.0F;
float texV1 = (float) (icon / 4 * 16 + 16) / 64.0F;
poseStack.translate(0.0F, 0.1F, 0.0F);
poseStack.mulPose(this.entityRenderDispatcher.cameraOrientation());
poseStack.mulPose(Axis.YP.rotationDegrees(180.0F));
poseStack.scale(0.3F, 0.3F, 0.3F);
VertexConsumer consumer = buffer.getBuffer(RENDER_TYPE);
PoseStack.Pose lasted = poseStack.last();
Matrix4f pose = lasted.pose();
Matrix3f normal = lasted.normal();
vertex(consumer, pose, normal, -0.5F, -0.25F, 255, 255, 255, texU1, texV1, packedLight);
vertex(consumer, pose, normal, 0.5F, -0.25F, 255, 255, 255, texU2, texV1, packedLight);
vertex(consumer, pose, normal, 0.5F, 0.75F, 255, 255, 255, texU2, texV2, packedLight);
vertex(consumer, pose, normal, -0.5F, 0.75F, 255, 255, 255, texU1, texV2, packedLight);
poseStack.popPose();
super.render(orb, pEntityYaw, partialTicks, poseStack, buffer, packedLight);
}

private static void vertex(VertexConsumer pConsumer, Matrix4f pMatrix, Matrix3f pMatrixNormal, float pX, float pY, int pRed, int pGreen, int pBlue, float pTexU, float pTexV, int pPackedLight) {
pConsumer.vertex(pMatrix, pX, pY, 0.0F).color(pRed, pGreen, pBlue, 128).uv(pTexU, pTexV).overlayCoords(OverlayTexture.NO_OVERLAY).uv2(pPackedLight).normal(pMatrixNormal, 0.0F, 1.0F, 0.0F).endVertex();
}

public ResourceLocation getTextureLocation(ExperienceOrb pEntity) {
return POINT_ITEM_TEXTURE;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
package com.github.tartaricacid.touhoulittlemaid.client.renderer.item;

import com.mojang.blaze3d.vertex.PoseStack;
import net.minecraft.client.renderer.block.model.BakedQuad;
import net.minecraft.client.renderer.block.model.ItemOverrides;
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
import net.minecraft.client.resources.model.BakedModel;
import net.minecraft.core.Direction;
import net.minecraft.util.RandomSource;
import net.minecraft.world.item.ItemDisplayContext;
import net.minecraft.world.level.block.state.BlockState;
import org.jetbrains.annotations.Nullable;

import java.util.Collections;
import java.util.List;
import java.util.function.Supplier;

public class ReplaceableBakedModel implements BakedModel {
private final BakedModel rawBakedModel;
private final BakedModel replacedBakedModel;
private final Supplier<Boolean> isReplace;

public ReplaceableBakedModel(BakedModel rawBakedModel, BakedModel replacedBakedModel, Supplier<Boolean> isReplace) {
this.rawBakedModel = rawBakedModel;
this.replacedBakedModel = replacedBakedModel;
this.isReplace = isReplace;
}

@Override
public List<BakedQuad> getQuads(@Nullable BlockState pState, @Nullable Direction pDirection, RandomSource random) {
return Collections.emptyList();
}

@Override
public boolean useAmbientOcclusion() {
return rawBakedModel.useAmbientOcclusion();
}

@Override
public boolean isGui3d() {
return rawBakedModel.isGui3d();
}

@Override
public boolean usesBlockLight() {
return rawBakedModel.usesBlockLight();
}

@Override
public boolean isCustomRenderer() {
return false;
}

@Override
public TextureAtlasSprite getParticleIcon() {
return rawBakedModel.getParticleIcon();
}

@Override
public ItemOverrides getOverrides() {
return ItemOverrides.EMPTY;
}

@Override
public BakedModel applyTransform(ItemDisplayContext type, PoseStack mat, boolean applyLeftHandTransform) {
if (isReplace.get()) {
return this.replacedBakedModel.applyTransform(type, mat, applyLeftHandTransform);
} else {
return this.rawBakedModel.applyTransform(type, mat, applyLeftHandTransform);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
@ParametersAreNonnullByDefault
@MethodsReturnNonnullByDefault
package com.github.tartaricacid.touhoulittlemaid.client.renderer.item;

import net.minecraft.MethodsReturnNonnullByDefault;

import javax.annotation.ParametersAreNonnullByDefault;
Loading

0 comments on commit ef62d36

Please sign in to comment.