Skip to content

Commit

Permalink
fix: cosmetic preview doll not displaying at all.
Browse files Browse the repository at this point in the history
  • Loading branch information
AsoDesu committed Apr 23, 2024
1 parent 309c3b3 commit 812462d
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 35 deletions.
39 changes: 5 additions & 34 deletions src/main/java/net/asodev/islandutils/mixins/cosmetics/UIMixin.java
Original file line number Diff line number Diff line change
@@ -1,37 +1,25 @@
package net.asodev.islandutils.mixins.cosmetics;

import com.mojang.blaze3d.platform.Lighting;
import com.mojang.blaze3d.systems.RenderSystem;
import com.mojang.blaze3d.vertex.PoseStack;
import net.asodev.islandutils.mixins.accessors.WalkAnimStateAccessor;
import net.asodev.islandutils.modules.cosmetics.CosmeticUI;
import net.asodev.islandutils.options.IslandOptions;
import net.asodev.islandutils.options.categories.CosmeticsOptions;
import net.asodev.islandutils.state.MccIslandState;
import net.asodev.islandutils.modules.cosmetics.CosmeticState;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.Gui;
import net.minecraft.client.gui.GuiGraphics;
import net.minecraft.client.gui.screens.inventory.AbstractContainerScreen;
import net.minecraft.client.gui.screens.inventory.ContainerScreen;
import net.minecraft.client.gui.screens.inventory.InventoryScreen;
import net.minecraft.client.renderer.MultiBufferSource;
import net.minecraft.client.renderer.entity.EntityRenderDispatcher;
import net.minecraft.network.chat.Component;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.player.Inventory;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.inventory.ChestMenu;
import net.minecraft.world.inventory.Slot;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.Items;
import org.joml.Quaternionf;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

import java.util.UUID;

import static net.asodev.islandutils.modules.cosmetics.CosmeticState.applyColor;
import static net.asodev.islandutils.modules.cosmetics.CosmeticState.isCosmeticMenu;

Expand All @@ -47,7 +35,8 @@ public void renderBg(GuiGraphics guiGraphics, float f, int i, int j, CallbackInf

CosmeticsOptions options = IslandOptions.getCosmetics();
if (!options.isShowPlayerPreview()) return;
if (options.isShowOnOnlyCosmeticMenus() && !CosmeticState.isCosmeticMenu(this.menu)) return;
boolean isCosmeticMenu = false;
if (options.isShowOnOnlyCosmeticMenus() && !(isCosmeticMenu = CosmeticState.isCosmeticMenu(this))) return;

checkInspect();

Expand All @@ -64,7 +53,7 @@ public void renderBg(GuiGraphics guiGraphics, float f, int i, int j, CallbackInf
if (CosmeticState.inspectingPlayer == null || CosmeticState.inspectingPlayer.getUUID() == Minecraft.getInstance().player.getUUID()) {
hatSlot = CosmeticState.hatSlot.getContents().getItem(this.menu);
accSlot = CosmeticState.accessorySlot.getContents().getItem(this.menu);
if (isCosmeticMenu(this.menu)) {
if (isCosmeticMenu) {
applyColor(hatSlot);
applyColor(accSlot);

Expand Down Expand Up @@ -93,7 +82,7 @@ public void renderBg(GuiGraphics guiGraphics, float f, int i, int j, CallbackInf
int x = (this.width - this.imageWidth) / 4;
int y = (this.height / 2) + size;

this.renderPlayerInInventory(
CosmeticUI.renderPlayerInInventory(
guiGraphics,
x, // x
y, // y
Expand Down Expand Up @@ -122,24 +111,6 @@ public void renderBg(GuiGraphics guiGraphics, float f, int i, int j, CallbackInf
guiGraphics.renderItem(this.minecraft.player, accSlot, itemPos, y+2, x + y * this.imageWidth);
}

// don't ask what this code does
// the answer is "it renders the player, it works, no touch."
private void renderPlayerInInventory(GuiGraphics guiGraphics, int x, int y, int size, LivingEntity livingEntity) {
float yRot = CosmeticState.yRot;
float xRot = (float)Math.atan(CosmeticState.xRot / 40.0f);;

InventoryScreen.renderEntityInInventoryFollowsMouse(
guiGraphics,
x, y,
x, y,
size,
0.0625f,
xRot,
yRot,
livingEntity
);
}

private void checkInspect() {
// TODO: Readd inspect menu support
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import net.asodev.islandutils.util.Utils;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.screens.inventory.AbstractContainerScreen;
import net.minecraft.core.component.DataComponents;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.network.chat.Component;
Expand Down Expand Up @@ -80,7 +81,10 @@ public static CosmeticType getType(ItemStack item) {
return null;
}

public static boolean isCosmeticMenu(ChestMenu menu) {
public static boolean isCosmeticMenu(AbstractContainerScreen<ChestMenu> screen) {
if (screen.getTitle().getString().contains("WARDROBE")) return true;

ChestMenu menu = screen.getMenu();
List<ItemStack> slots = new ArrayList<>(menu.slots.stream().map(Slot::getItem).toList());
slots.add(menu.getCarried());
for (ItemStack slot : slots){
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
package net.asodev.islandutils.modules.cosmetics;

import net.minecraft.client.gui.GuiGraphics;
import net.minecraft.client.gui.screens.inventory.InventoryScreen;
import net.minecraft.world.entity.LivingEntity;
import org.joml.Quaternionf;
import org.joml.Vector3f;

public class CosmeticUI {

public static void renderPlayerInInventory(GuiGraphics guiGraphics, int x, int y, int size, LivingEntity livingEntity) {
float yRot = CosmeticState.yRot;
float xRot = (float)Math.atan(CosmeticState.xRot / 40.0f);

// save rotations
float preYBodyRot = livingEntity.yBodyRot;
float preYRot = livingEntity.getYRot();
float preXrot = livingEntity.getXRot();
float preYHeadRot0 = livingEntity.yHeadRotO;
float preYHeadRot = livingEntity.yHeadRot;

// set rotations
livingEntity.yBodyRot = yRot;
livingEntity.setYRot(yRot);
livingEntity.yHeadRot = livingEntity.yBodyRot;
livingEntity.yHeadRotO = livingEntity.yBodyRot;
livingEntity.setXRot(xRot * -20f); // magic value - InventoryScreen#renderEntityInInventoryFollowsMouse [setXRot]

guiGraphics.pose().pushPose();
guiGraphics.pose().translate(0f, 0f, 105f); // translate to 105 on the z
float f = 0.0625F; // magic value - InventoryScreen#renderBg [renderEntityInInventoryFollowsMouse]
float livingEntityScale = livingEntity.getScale();

// here we make some quaternions and do some math with them
// idfk this is just what the inventory code does :sob:
// magic values - InventoryScreen#renderEntityInInventoryFollowsMouse
Quaternionf quaternionf = (new Quaternionf()).rotateZ(3.1415927F);
Quaternionf quaternionf2 = (new Quaternionf()).rotateX(xRot * 20.0F * 0.017453292F);
quaternionf.mul(quaternionf2);
Vector3f vector3f = new Vector3f(0.0F, livingEntity.getBbHeight() / 2.0F + f * livingEntityScale, 0.0F);
InventoryScreen.renderEntityInInventory(
guiGraphics,
x, y - size,
size / livingEntityScale,
vector3f,
quaternionf,
quaternionf2,
livingEntity
);
guiGraphics.pose().popPose();

// restore rotations
livingEntity.yBodyRot = preYBodyRot;
livingEntity.setYRot(preYRot);
livingEntity.setXRot(preXrot);
livingEntity.yHeadRotO = preYHeadRot0;
livingEntity.yHeadRot = preYHeadRot;
}

}

0 comments on commit 812462d

Please sign in to comment.