Skip to content

Commit

Permalink
Also show ears and cape
Browse files Browse the repository at this point in the history
  • Loading branch information
Gaming32 committed Jul 22, 2024
1 parent f7d6275 commit aef1a0c
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,13 @@ public PlayerInfoScreen(Screen parentScreen, GameProfile profile) {
@Override
protected void init() {
assert minecraft != null;
final int top = height / 4 - 25;
final int bottom = height / 2 + 75;
addRenderableWidget(new WHPlayerSkinWidget(
width / 2 - 100, height / 2 - 150,
200, 225,
width / 2 - 100, top,
200, bottom - top,
() -> WorldHost.getInsecureSkin(profile),
() -> profile.getName().equals("deadmau5"),
minecraft.getEntityModels()
));
addRenderableWidget(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package io.github.gaming32.worldhost.gui.widget;

import com.mojang.blaze3d.platform.Lighting;
import com.mojang.blaze3d.vertex.VertexConsumer;
import com.mojang.math.Axis;
import io.github.gaming32.worldhost.WHPlayerSkin;
import io.github.gaming32.worldhost.versions.Components;
Expand All @@ -9,6 +10,7 @@
import net.minecraft.client.model.geom.EntityModelSet;
import net.minecraft.client.model.geom.ModelLayers;

import java.util.function.BooleanSupplier;
import java.util.function.Supplier;

import static io.github.gaming32.worldhost.gui.screen.WorldHostScreen.pose;
Expand All @@ -18,7 +20,9 @@
import net.minecraft.client.model.PlayerModel;
import net.minecraft.client.renderer.LightTexture;
import net.minecraft.client.renderer.MultiBufferSource;
import net.minecraft.client.renderer.RenderType;
import net.minecraft.client.renderer.texture.OverlayTexture;
import net.minecraft.client.sounds.SoundManager;
import net.minecraft.util.Mth;
//#else
//$$ import com.mojang.blaze3d.systems.RenderSystem;
Expand All @@ -36,18 +40,20 @@ public class WHPlayerSkinWidget extends AbstractWidget {
private static final float ROTATION_X_LIMIT = 50f;

private final Supplier<WHPlayerSkin> skin;
private final BooleanSupplier isDeadmau5;
private final PlayerModel<?> wideModel;
private final PlayerModel<?> slimModel;
private float rotationX = DEFAULT_ROTATION_X;
private float rotationY = DEFAULT_ROTATION_Y;

public WHPlayerSkinWidget(
int x, int y, int width, int height,
Supplier<WHPlayerSkin> skin,
Supplier<WHPlayerSkin> skin, BooleanSupplier isDeadmau5,
EntityModelSet models
) {
super(x, y, width, height, Components.empty());
this.skin = skin;
this.isDeadmau5 = isDeadmau5;

wideModel = new PlayerModel<>(models.bakeLayer(ModelLayers.PLAYER), false);
slimModel = new PlayerModel<>(models.bakeLayer(ModelLayers.PLAYER_SLIM), true);
Expand All @@ -61,6 +67,10 @@ protected void onDrag(double mouseX, double mouseY, double dragX, double dragY)
rotationY += (float)dragX * ROTATION_SENSITIVITY;
}

@Override
public void playDownSound(SoundManager handler) {
}

@Override
//#if MC >= 1.19.4
public void renderWidget(
Expand Down Expand Up @@ -103,6 +113,50 @@ private void renderModel(
final PlayerModel<?> model = skin.model() == WHPlayerSkin.Model.SLIM ? slimModel : wideModel;
final var renderType = model.renderType(skin.texture());
model.renderToBuffer(pose(context), bufferSource(context).getBuffer(renderType), LightTexture.FULL_BRIGHT, OverlayTexture.NO_OVERLAY);
if (isDeadmau5.getAsBoolean()) {
renderEars(context, model, skin);
}
if (skin.capeTexture() != null) {
renderCape(context, model, skin);
}
pose(context).popPose();
}

private void renderEars(
//#if MC < 1.20.0
//$$ PoseStack context,
//#else
GuiGraphics context,
//#endif
PlayerModel<?> model,
WHPlayerSkin skin
) {
final var consumer = bufferSource(context).getBuffer(RenderType.entitySolid(skin.texture()));
for (int ear = 0; ear < 2; ear++) {
pose(context).pushPose();
pose(context).translate(0.375f * (ear * 2 - 1), -0.375f, 0f);
final float scale = 1 + 1 / 3f;
pose(context).scale(scale, scale, scale);
model.renderEars(pose(context), consumer, LightTexture.FULL_BRIGHT, OverlayTexture.NO_OVERLAY);
pose(context).popPose();
}
}

private void renderCape(
//#if MC < 1.20.0
//$$ PoseStack context,
//#else
GuiGraphics context,
//#endif
PlayerModel<?> model,
WHPlayerSkin skin
) {
pose(context).pushPose();
pose(context).translate(0f, 0f, 0.125f);
pose(context).mulPose(Axis.XP.rotationDegrees(6f));
pose(context).mulPose(Axis.YP.rotationDegrees(180f));
final VertexConsumer consumer = bufferSource(context).getBuffer(RenderType.entitySolid(skin.capeTexture()));
model.renderCloak(pose(context), consumer, LightTexture.FULL_BRIGHT, OverlayTexture.NO_OVERLAY);
pose(context).popPose();
}

Expand Down

0 comments on commit aef1a0c

Please sign in to comment.