Jump to content

[1.14.4] How to use a player's face as an item texture


BlockyPenguin

Recommended Posts

Hi! I'd like to know how to use a player's face as the texture for an item. I know this is possible due to player heads existing in-game. I have looked through the player head code, but I can't seem to understand it, as it calls methods from tile entities... how is that possible when it's an item? To be more specific, I'm not looking for a player head duplicate, just a 2D item that has the same texture as a player's face.

 

Thanks,

~BP

Today (22/10/20) I reached 100 posts!

I'm probably more excited than I should be for something so realistically minor...

Link to comment
Share on other sites

1 hour ago, Boy132 said:

Have you looked at SkullTileEntityRenderer?

And the player head calls methods from a tile entity because it's a block. (what have you have in your inventory is a BlockItem:P 

Ah, no, I saw SkullTileEntity, but not SkullTileEntityRenderer! I'll be sure to take a look.

By that last part, I'm guessing you mean that because it is a BlockItem, it can access the tile entity even though it hasn't been placed yet. Thanks!

P.S. How do you create inline code blocks in a post?

Today (22/10/20) I reached 100 posts!

I'm probably more excited than I should be for something so realistically minor...

Link to comment
Share on other sites

Just now, BlockyPenguin said:

Ah, no, I saw SkullTileEntity, but not SkullTileEntityRenderer! I'll be sure to take a look.

By that last part, I'm guessing you mean that because it is a BlockItem, it can access the tile entity even though it hasn't been placed yet. Thanks!

P.S. How do you create inline code blocks in a post?

image.png.3286a6d0cb030e7dce3b404f4af2baad.png :P 

  • Thanks 1
Link to comment
Share on other sites

30 minutes ago, Boy132 said:

image.png.3286a6d0cb030e7dce3b404f4af2baad.png :P 

Ah ok, thanks :P

 

Anyway, having now looked at SkullTileEntityRenderer, I'm not entirely sure what I need to keep. I'm new to modding in general and haven't dabbled at all in custom renderers, do you have any help or tips?

Thanks,

~BP

Today (22/10/20) I reached 100 posts!

I'm probably more excited than I should be for something so realistically minor...

Link to comment
Share on other sites

12 hours ago, BlockyPenguin said:

Having now looked at SkullTileEntityRenderer, I'm not entirely sure what I need to keep. I'm new to modding in general and haven't dabbled at all in custom renderers.

Okay, so, I've seemingly not done something right here... I can start MC and all perfectly fine, but when i /give myself the item, the game instanly crashes. no "Saving World" first or anything, just an instant crash. This is the crash report:
 

Spoiler

[10:06:14] [Server thread/INFO] [minecraft/MinecraftServer]: [Dev: Gave 1 [item.labkit.mini_player] to Dev]
[10:06:14] [Client thread/INFO] [minecraft/NewChatGui]: [CHAT] Gave 1 [item.labkit.mini_player] to Dev
FATAL ERROR in native method: Thread[Server thread,5,SERVER]: No context is current or a function that is not available in the current context was called. The JVM will abort execution.
    at org.lwjgl.opengl.GL11C.glBindTexture(Native Method)
    at org.lwjgl.opengl.GL11.glBindTexture(GL11.java:907)
    at com.mojang.blaze3d.platform.GlStateManager.bindTexture(GlStateManager.java:436)
    at net.minecraft.client.renderer.texture.ITextureObject.bindTexture(ITextureObject.java:22)
    at net.minecraft.client.renderer.texture.TextureManager.bindTexture(TextureManager.java:48)
    at com.blockypenguin.labkit.client.renderer.MiniPlayerRenderer.render(MiniPlayerRenderer.java:25)
    at com.blockypenguin.labkit.items.MiniPlayer.inventoryTick(MiniPlayer.java:22)
    at net.minecraft.item.ItemStack.inventoryTick(ItemStack.java:469)
    at net.minecraft.entity.player.PlayerInventory.tick(PlayerInventory.java:292)
    at net.minecraft.entity.player.PlayerEntity.livingTick(PlayerEntity.java:518)
    at net.minecraft.entity.LivingEntity.tick(LivingEntity.java:2187)
    at net.minecraft.entity.player.PlayerEntity.tick(PlayerEntity.java:235)
    at net.minecraft.entity.player.ServerPlayerEntity.playerTick(ServerPlayerEntity.java:381)
    at net.minecraft.network.play.ServerPlayNetHandler.tick(ServerPlayNetHandler.java:183)
    at net.minecraft.network.NetworkManager.tick(NetworkManager.java:245)
    at net.minecraft.network.NetworkSystem.tick(NetworkSystem.java:148)
    - locked <0x00000006de81c760> (a java.util.Collections$SynchronizedRandomAccessList)
    at net.minecraft.server.MinecraftServer.updateTimeLightAndEntities(MinecraftServer.java:882)
    at net.minecraft.server.MinecraftServer.tick(MinecraftServer.java:800)
    at net.minecraft.server.integrated.IntegratedServer.tick(IntegratedServer.java:118)
    at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:646)
    at java.lang.Thread.run(Thread.java:748)
AL lib: (EE) alc_cleanup: 1 device not closed

 

My guess is I'm not rendering it properly. Here's my code:
MiniPlayer.java:
 

Spoiler

package com.blockypenguin.labkit.items;

import com.blockypenguin.labkit.client.renderer.MiniPlayerRenderer;

import net.minecraft.entity.Entity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.world.World;

public class MiniPlayer extends Item {

	public MiniPlayer() {
		super(new Item.Properties());
		setRegistryName("mini_player");
	}
	
	@Override
	public void inventoryTick(ItemStack stack, World world, Entity entity, int itemSlot, boolean isSelected) {
		if(entity instanceof PlayerEntity) {
			PlayerEntity player = (PlayerEntity) entity;
			MiniPlayerRenderer.render(player.getGameProfile());
		}else {
			MiniPlayerRenderer.render(null);
		}
		super.inventoryTick(stack, world, entity, itemSlot, isSelected);
	}
	
}

 

MiniPlayerRenderer.java:
 

Spoiler

package com.blockypenguin.labkit.client.renderer;

import java.util.Map;

import com.blockypenguin.labkit.client.renderer.model.TwoDimensionalFaceModel;
import com.mojang.authlib.GameProfile;
import com.mojang.authlib.minecraft.MinecraftProfileTexture;
import com.mojang.authlib.minecraft.MinecraftProfileTexture.Type;

import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.tileentity.ItemStackTileEntityRenderer;
import net.minecraft.client.resources.DefaultPlayerSkin;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;

@OnlyIn(Dist.CLIENT)
public class MiniPlayerRenderer extends ItemStackTileEntityRenderer {
	
	private static final TwoDimensionalFaceModel MODEL = new TwoDimensionalFaceModel();
   
   public static void render(GameProfile playerprofile) {
	   Minecraft minecraft = Minecraft.getInstance();
	   minecraft.getTextureManager().bindTexture(getSkin(playerprofile));
	   MODEL.render(0.0625F);
   }
   
   private static ResourceLocation getSkin(GameProfile profile) {
      ResourceLocation resourcelocation = DefaultPlayerSkin.getDefaultSkin(PlayerEntity.getUUID(profile));
      if (profile != null) {
         try {
        	 Minecraft minecraft = Minecraft.getInstance();
        	 Map<Type, MinecraftProfileTexture> map = minecraft.getSkinManager().loadSkinFromCache(profile);
        	 if (map.containsKey(Type.SKIN)) {
        		 resourcelocation = minecraft.getSkinManager().loadSkin(map.get(Type.SKIN), Type.SKIN);
        	 }
         }catch(Exception e) {
        	 try {
        		 resourcelocation = DefaultPlayerSkin.getDefaultSkin(PlayerEntity.getUUID(profile));
        	 }catch(Exception e1) {
        		 resourcelocation = DefaultPlayerSkin.getDefaultSkinLegacy();
        	 }
         }
      }
      return resourcelocation;
   }
}

 

TwoDimensionalFaceModel.java:
 

Spoiler

package com.blockypenguin.labkit.client.renderer.model;

import com.blockypenguin.labkit.LabKit;

import net.minecraft.client.renderer.entity.model.RendererModel;
import net.minecraft.client.renderer.model.Model;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;

@OnlyIn(Dist.CLIENT)
public class TwoDimensionalFaceModel extends Model {
   protected final RendererModel model;

   public TwoDimensionalFaceModel() {
      this(7, 8, 8, 8);
   }

   public TwoDimensionalFaceModel(int textureOffsetX, int textureOffsetY, int textureWidth, int textureHeight) {
      this.textureWidth = textureWidth;
      this.textureHeight = textureHeight;
      this.model = new RendererModel(this, textureOffsetX, textureOffsetY);
      this.model.addBox(-4.0F, -8.0F, -1.0F, 8, 8, 8, 0.0F);
      this.model.setRotationPoint(0.0F, 0.0F, 0.0F);
   }
   
   public void render(float scale) {
	   LabKit.LOGGER.info(scale);
	   this.model.render(scale);
   }
}

 

 

 

Where am I going wrong?

Thanks, ~BP

Edited by BlockyPenguin

Today (22/10/20) I reached 100 posts!

I'm probably more excited than I should be for something so realistically minor...

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • The mod I'm working on is in 1.19.2. The portal works correctly in Intellij but when I publish the jar, put it in the mods folder of the game it crashes with the following error whenever any entity collides with it: java.lang.IllegalAccessError: class com.github.warrentode.turtleblockacademy.blocks.TBAMiningPortalBlock tried to access protected field net.minecraft.world.entity.Entity.f_19819_ (com.github.warrentode.turtleblockacademy.blocks.TBAMiningPortalBlock is in module [email protected] of loader 'TRANSFORMER' @16c5b50a; net.minecraft.world.entity.Entity is in module [email protected] of loader 'TRANSFORMER' @16c5b50a)     at com.github.warrentode.turtleblockacademy.blocks.TBAMiningPortalBlock.m_7892_(TBAMiningPortalBlock.java:124) ~[turtleblockacademy-2024.2025-1.0.0.jar%23572!/:2024.2025-1.0.0] {re:classloading} The thing is, I have Entity.f_19819_ in my accessTransformer.cfg file in this line: public net.minecraft.world.entity.Entity f_19819_ # portalEntrancePos So what do I need to do to fix this error?
    • It will be about medeaival times
    • the mods are crashing and I'm not sure why so heres everything  crash log https://pastebin.com/RxLKbMNR  L2 Library (12library) has failed to load correctly java.lang.NoClassDefFoundError: org/antarcticgardens/newage/content/energiser/EnergiserBlock L2 Screen Tracker (12screentracker) has failed to load correctly java.lang.NoClassDefFoundError: Could not initialize class dev.xkmc.12library.base.L2Registrate Create: Interiors (interiors) has failed to load correctly java.lang.NoClassDefFoundError: Could not initialize class com.tterrag.registrate.AbstractRegistrate L2 Damage Tracker (12damagetracker) has failed to load correctly java.lang.NoClassDefFoundError: Could not initialize class dev.xkmc.l2library.base.L2Registrate Create Enchantment Industry (create_enchantment_industry) has failed to load correctly java.lang.NoClassDefFoundError: Could not initialize class com.simibubi.create.foundation.data.Createfiegistrate Create Crafts & Additions (createaddition) has failed to load correctly java.lang.NoClassDefFoundError: Could not initialize class com.simibubi.create.foundation.data.CreateRegistrate Create Slice & Dice (sliceanddice) has failed to load correctly java.lang.NoClassDefFoundError: Could not initialize class com.simibubi.create.foundation.data.CreateRegistrate L2 Tabs (12tabs) has failed to load correctly java.lang.NoClassDefFoundError: Could not initialize class dev.xkmc.l2library.base.L2Registrate Modular Golems (modulargolems) has failed to load correctly java.lang.NoClassDefFoundError: Could not initialize class dev.xkmc.l2library.base.L2Registrate Create: Steam 'n' FRails (railways) has failed to load correctly java.lang.NoClassDefFoundError : Could not initialize class com.simibubi.create.foundation.data.Createfregistrate Cuisine Delight (cuisinedelight) has failed to load correctly java.lang.NoClassDefFoundError: Could not initialize class dev.xkmc.12library.base.L2Registrate Create (create) has failed to load correctly java.lang.NoClassDefFoundError: Could not initialize class com.simibubi.create.Create Guardian Beam Defense (creategbd) has failed to load correctly java.lang.NoClassDefFoundError: Could not initialize class com.simibubi.create.foundation.data.CreateRegistrate L2 Item Selector (12itemselector) has failed to load correctly java.lang.NoClassDefFoundError: Could not initialize class dev.xkmc.l2library.base.L2Registrate
    • hey there, I have been using Forge for years without any problems, but for some time now I have been getting this error message when I click on “Installer” under the downloads. This happens on all versions. I have tried various things but have not gotten any results. If anyone has a solution, I would be very grateful!
    • I don't have mcreator installed.
  • Topics

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.