Posted April 27, 20205 yr 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...
April 27, 20205 yr 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)
April 27, 20205 yr Author 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) 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...
April 27, 20205 yr 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?
April 27, 20205 yr Author 30 minutes ago, Boy132 said: Ah ok, thanks 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...
April 28, 20205 yr Author 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 April 28, 20205 yr by BlockyPenguin Today (22/10/20) I reached 100 posts! I'm probably more excited than I should be for something so realistically minor...
April 28, 20205 yr Author bump? Today (22/10/20) I reached 100 posts! I'm probably more excited than I should be for something so realistically minor...
April 28, 20205 yr Author Sorry ? Today (22/10/20) I reached 100 posts! I'm probably more excited than I should be for something so realistically minor...
May 5, 20205 yr Author Bump Today (22/10/20) I reached 100 posts! I'm probably more excited than I should be for something so realistically minor...
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.