Skip to content

Commit

Permalink
添加示例方法
Browse files Browse the repository at this point in the history
  • Loading branch information
CSneko committed Nov 24, 2024
1 parent b1ca52c commit 1ec9958
Show file tree
Hide file tree
Showing 3 changed files with 98 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import org.ayamemc.ayame.Ayame;
import org.ayamemc.ayame.client.IAyameClientEvents;
import org.ayamemc.ayame.fabric.client.AyameClientEventsFabricImpl;
import org.ayamemc.ayame.fabric.client.event.ClientTickEvent;
import org.ayamemc.ayame.fabric.client.event.ModelReloadEventHandler;

/**
Expand All @@ -39,5 +40,6 @@ public void onInitialize() {
Ayame.init();
IAyameClientEvents.Instance.INSTANCE = new AyameClientEventsFabricImpl();
ResourceManagerHelper.get(PackType.CLIENT_RESOURCES).registerReloadListener(new ModelReloadEventHandler());
ClientTickEvent.init();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
/*
* Custom player model mod. Powered by GeckoLib.
* Copyright (C) 2024 CrystalNeko, HappyRespawnanchor, pertaz(Icon Designer)
*
* This file is part of Ayame.
*
* Ayame is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Ayame is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Ayame. If not, see <https://www.gnu.org/licenses/>.
*/

package org.ayamemc.ayame.fabric.client.event;

import com.mojang.math.Axis;
import net.fabricmc.fabric.api.client.rendering.v1.HudRenderCallback;
import net.minecraft.client.DeltaTracker;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiGraphics;
import net.minecraft.client.renderer.entity.EntityRenderDispatcher;
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.animal.Pig;

public class ClientTickEvent {
// TODO 这里是示例方法,请完善
public static void init(){
HudRenderCallback.EVENT.register(ClientTickEvent::renderEntityOnHud);
}


private static void renderEntityOnHud(GuiGraphics guiGraphics, DeltaTracker tickDelta) {
Minecraft client = Minecraft.getInstance();

if (client.level == null || client.player == null) return;

LivingEntity entity = new Pig(EntityType.PIG, client.level);

// 设置实体的起始位置
entity.setPos(client.player.getX(), client.player.getY(), client.player.getZ());

// 渲染逻辑
int x = client.getWindow().getGuiScaledWidth() - 50; // 右下角的X坐标
int y = client.getWindow().getGuiScaledHeight() - 50; // 右下角的Y坐标
renderEntityInGui(entity, x, y, 30); // 实体大小为30
}

private static void renderEntityInGui(LivingEntity entity, int x, int y, int size) {
Minecraft client = Minecraft.getInstance();
EntityRenderDispatcher dispatcher = client.getEntityRenderDispatcher();


com.mojang.blaze3d.vertex.PoseStack poseStack = new com.mojang.blaze3d.vertex.PoseStack();
poseStack.pushPose();
poseStack.translate(x, y, 1050.0);
poseStack.scale(size, size, size);
poseStack.mulPose(Axis.ZP.rotationDegrees(180.0F));

dispatcher.render(entity, 0.0, 0.0, 0.0, 0.0F, 1.0F, poseStack, client.renderBuffers().bufferSource(), 15728880);
poseStack.popPose();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,29 @@
package org.ayamemc.ayame.fabric.mixin.client.event;

import com.mojang.blaze3d.vertex.PoseStack;
import com.mojang.math.Axis;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiGraphics;
import net.minecraft.client.player.LocalPlayer;
import net.minecraft.client.renderer.ItemInHandRenderer;
import net.minecraft.client.renderer.MultiBufferSource;
import net.minecraft.client.renderer.entity.EntityRenderDispatcher;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.util.Mth;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.InteractionResult;
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.entity.HumanoidArm;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.animal.Pig;
import net.minecraft.world.item.ItemStack;
import org.ayamemc.ayame.client.api.PlayerModelAPI;
import org.ayamemc.ayame.fabric.client.api.event.RenderArmCallback;
import org.ayamemc.ayame.model.AyameModelCache;
import org.ayamemc.ayame.model.ModelType;
import org.joml.Vector3d;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
Expand Down Expand Up @@ -61,6 +74,7 @@ static ItemInHandRenderer.HandRenderSelection evaluateWhichHandsToRender(LocalPl

@Inject(method = "renderHandsWithItems", at = @At("HEAD"), cancellable = true)
private void renderHandsWithItems(float partialTicks, PoseStack poseStack, MultiBufferSource.BufferSource buffer, LocalPlayer playerEntity, int combinedLight, CallbackInfo ci) {
/*
float f = playerEntity.getAttackAnim(partialTicks);
InteractionHand interactionHand = playerEntity.swingingArm;
float pitch = Mth.lerp(partialTicks, playerEntity.xRotO, playerEntity.getXRot());
Expand Down Expand Up @@ -103,6 +117,17 @@ private void renderHandsWithItems(float partialTicks, PoseStack poseStack, Multi
if (result != InteractionResult.PASS) {
ci.cancel();
}
}
*/
ci.cancel();
}

@Inject(method = "renderHandsWithItems", at = @At("HEAD"),cancellable = true)
private void renderPlayerArm(float partialTicks, PoseStack poseStack, MultiBufferSource.BufferSource buffer, LocalPlayer playerEntity, int combinedLight, CallbackInfo ci) {
ci.cancel();
// ModelType model = AyameModelCache.getPlayerModel(playerEntity);
// ResourceLocation arm = model.getArm();

}


}

0 comments on commit 1ec9958

Please sign in to comment.