Jump to content

Recommended Posts

Posted (edited)

I have an entity and I want its head to have the texture of the player's head.

I wrote my layer class like this:

public class PlayerHeadLayer extends GeoLayerRenderer<PowerArmorEntity> {

    public PlayerHeadLayer(IGeoRenderer<PowerArmorEntity> entityRenderer) {
        super(entityRenderer);
    }

    @Override
    public void render(PoseStack matrixStackIn, MultiBufferSource bufferIn, int packedLightIn, PowerArmorEntity entity, float limbSwing, float limbSwingAmount, float partialTicks, float ageInTicks, float netHeadYaw, float headPitch) {
        if(!entity.isInvisible() && entity.isVehicle() && entity.getControllingPassenger() instanceof AbstractClientPlayer clientPlayer ) {
            var texture = clientPlayer.getSkinTextureLocation();
            int overlay = OverlayTexture.NO_OVERLAY;
            var cameo = RenderType.armorCutoutNoCull(texture);
            matrixStackIn.pushPose();
            matrixStackIn.scale(1.0f, 1.0f, 1.0f);
            matrixStackIn.translate(0.0d, 0.0d, 0.0d);
            this.getRenderer().render(
                    this.getEntityModel().getModel(POWER_ARMOR_MODEL_LOCATION),
                    entity,
                    partialTicks,
                    cameo,
                    matrixStackIn,
                    bufferIn,
                    bufferIn.getBuffer(cameo),
                    packedLightIn,
                    overlay,
                    1f, 1f, 1f, 1f);
            matrixStackIn.popPose();
        }
    }
}

But the player texture scale is too big

yqqtKHh.png

Texture of my entity:

3OHWrWV.png

Edited by Jetug
  • Jetug changed the title to How to scale texture?
Posted (edited)
  On 1/21/2023 at 2:39 PM, ChampionAsh5357 said:

Render the head and the rest of the model separately. Apply the player texture to the head and your texture to the rest of the model. Currently, the head texture is being applied to the entire model.

Expand  

I understood the logic, but I don't know how to implement it. I'm new to minecraft modding

Edited by Jetug
Posted
  On 1/21/2023 at 3:28 PM, Jetug said:

I understood the logic, but I don't know how to implement it.

Expand  

Look at how the LivingEntityRenderer sets the texture and repeat the process in your render method. You already have access to the entity model, so you should know how to render it. As how to separate it, either use two separate models or handle the rendering on the same model in two separate methods or implementations.

Posted (edited)
  On 1/22/2023 at 3:10 PM, ChampionAsh5357 said:

Look at how the LivingEntityRenderer sets the texture and repeat the process in your render method. You already have access to the entity model, so you should know how to render it. As how to separate it, either use two separate models or handle the rendering on the same model in two separate methods or implementations.

Expand  

I decided that it would be easier to do this with the resizing of the player texture and wrote this code while waiting for an answer:

@Override
public void render(PoseStack matrixStackIn, MultiBufferSource bufferIn, int packedLightIn, PowerArmorEntity entity, float limbSwing, float limbSwingAmount, float parti
    if(!entity.isInvisible() && entity.isVehicle() && entity.getControllingPassenger() instanceof AbstractClientPlayer clientPlayer ) {
        var texture = getHeadResourceLocation(clientPlayer, entity);
        if (texture == null) return;
        var cameo = RenderType.armorCutoutNoCull(texture);
        int overlay = OverlayTexture.NO_OVERLAY;
        matrixStackIn.pushPose();
        matrixStackIn.scale(1.0f, 1.0f, 1.0f);
        matrixStackIn.translate(0.0d, 0.0d, 0.0d);
        this.getRenderer().render(
                getEntityModel().getModel(POWER_ARMOR_MODEL_LOCATION),
                entity,
                partialTicks,
                cameo,
                matrixStackIn,
                bufferIn,
                bufferIn.getBuffer(cameo),
                packedLightIn,
                overlay,
                1f, 1f, 1f, 1f);
        matrixStackIn.popPose();
    }
}
                   
@Nullable
private ResourceLocation getHeadResourceLocation(AbstractClientPlayer clientPlayer, PowerArmorEntity entity) {
    var tag = clientPlayer.getUUID().toString();
    if (playerTextures.containsKey(tag)) {
        return playerTextures.get(tag);
    } else {
        var playerHead = getPlayerHead(clientPlayer);
        var entityTextureRL = entityRenderer.getTextureLocation(entity);
        var entityTexture = resourceToBufferedImage(entityTextureRL);
        if (playerHead == null || entityTexture == null) return null;
        playerHead = extendImage(playerHead, entityTexture.getWidth(), entityTexture.getHeight());
        var nativeImage = getNativeImage(playerHead);
        var dynamicTexture = new DynamicTexture(nativeImage);
        var finalTextureLocation = new ResourceLocation(Global.MOD_ID, tag);
        Minecraft.getInstance().getTextureManager().register(finalTextureLocation, dynamicTexture);
        playerTextures.put(tag, finalTextureLocation);
        return finalTextureLocation;
    }
}

And it actually worked, but Steve looks like he's turned into a vampire

XDbT0tH.png

I think the problem is in this method:

public static NativeImage getNativeImage(BufferedImage img) {
    NativeImage nativeImage = new NativeImage(img.getWidth(), img.getHeight(), true);
    for (int x = 0; x < img.getWidth(); x++) {
        for (int y = 0; y < img.getHeight(); y++) {
            var color = img.getRGB(x, y);
            nativeImage.setPixelRGBA(x, y, color);
        }
    }
    return nativeImage;
}

Full code: https://github.com/Jetug/PowerArmorMod/blob/1.18/src/main/java/com/jetug/power_armor_mod/client/render/layers/PlayerHeadLayer.java

Edited by Jetug
Posted
  On 1/22/2023 at 5:00 PM, Jetug said:

I decided that it would be easier to do this with the resizing of the player texture

Expand  

That's a lot harder. You literally just need two models or simply render the head part manually with the applied texture. And then you just need to create the rendertype with the texture twice. It's literally just what the LivingEntityRenderer is doing twice.

  On 1/22/2023 at 5:00 PM, Jetug said:

I think the problem is in this method:

Expand  

The pixel information is stored in BGRA format, so that makes sense.

  • Thanks 1
Posted
  On 1/22/2023 at 5:28 PM, ChampionAsh5357 said:

That's a lot harder. You literally just need two models or simply render the head part manually with the applied texture. And then you just need to create the rendertype with the texture twice. It's literally just what the LivingEntityRenderer is doing twice.

The pixel information is stored in BGRA format, so that makes sense.

Expand  

Maybe harder but i already did it :) Anyway thank you, I corrected the method and now it works

    public static NativeImage getNativeImage(BufferedImage img) {
        NativeImage nativeImage = new NativeImage(img.getWidth(), img.getHeight(), true);
        for (int x = 0; x < img.getWidth(); x++) {
            for (int y = 0; y < img.getHeight(); y++) {
                int clr = img.getRGB(x, y);
                int alpha = (clr & 0xff000000) >> 24;
                int red =   (clr & 0x00ff0000) >> 16;
                int green = (clr & 0x0000ff00) >> 8;
                int blue =   clr & 0x000000ff;

                int rgb = alpha;
                rgb = (rgb << 8) + blue;
                rgb = (rgb << 8) + green;
                rgb = (rgb << 8) + red;

                nativeImage.setPixelRGBA(x, y, rgb);
            }
        }
        return nativeImage;
    }

 

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

    • I am trying to make a custom item that converts to another custom item when eaten. The food properties includes "usingConvertsTo(ModItems.ITEM_NAME.get())", however since the item is not yet registered during the registration process, the get() method returns null. Is there any way to work around this?
    • Having problems with forge installation on headless arch linux, regardless of forge-server from yay or manual wget, Cant find class error and results in net/minecraft/world/waypoints/Waypoint$Icon.class   net/minecraft/world/waypoints/Waypoint.class   net/minecraft/world/waypoints/WaypointManager.class   net/minecraft/world/waypoints/WaypointStyleAsset.class   net/minecraft/world/waypoints/WaypointStyleAssets.class   net/minecraft/world/waypoints/WaypointTransmitter$BlockConnection.class   net/minecraft/world/waypoints/WaypointTransmitter$ChunkConnection.class   net/minecraft/world/waypoints/WaypointTransmitter$Connection.class   net/minecraft/world/waypoints/WaypointTransmitter$EntityAzimuthConnection.class   net/minecraft/world/waypoints/WaypointTransmitter$EntityBlockConnection.class   net/minecraft/world/waypoints/WaypointTransmitter$EntityChunkConnection.class   net/minecraft/world/waypoints/WaypointTransmitter.class   version.json   Processor failed, invalid outputs:     /srv/minecraft/./libraries/net/minecraft/server/1.21.6/server-1.21.6-official.jar       Expected: b1448d2c947e923ccd63224defc3b51e5a72a98d       Actual:   5f30bf411bd0d1208baca6b7be1584442f4f6579 There was an error during installation
    • This is my first time setting up a minecraft server, and I had wanted to add modding capabilities with forge but I keep getting errors while installing? I have tried installing several versions of forge but i have ended up getting unable to find class and checksum errors? Same thing when trying yay -S forge-server The only thing that works is installing the vanilla minecraft server from minecraft itself?   net/minecraft/util/parsing/packrat/Atom.class   net/minecraft/util/parsing/packrat/CachedParseState$CacheEntry.class   net/minecraft/util/parsing/packrat/CachedParseState$PositionCache.class   net/minecraft/util/parsing/packrat/CachedParseState$Silent.class   net/minecraft/util/parsing/packrat/CachedParseState$SimpleControl.class   net/minecraft/util/parsing/packrat/CachedParseState.class   net/minecraft/util/parsing/packrat/Control$1.class   net/minecraft/util/parsing/packrat/Control.class   net/minecraft/util/parsing/packrat/DelayedException.class   net/minecraft/util/parsing/packrat/Dictionary$Entry.class   net/minecraft/util/parsing/packrat/Dictionary$Reference.class   net/minecraft/util/parsing/packrat/Dictionary.class   net/minecraft/util/parsing/packrat/ErrorCollector$LongestOnly$MutableErrorEntry.class   net/minecraft/util/parsing/packrat/ErrorCollector$LongestOnly.class   net/minecraft/util/parsing/packrat/ErrorCollector$Nop.class   net/minecraft/util/parsing/packrat/ErrorCollector.class   net/minecraft/util/parsing/packrat/ErrorEntry.class   net/minecraft/util/parsing/packrat/NamedRule.class   net/minecraft/util/parsing/packrat/ParseState.class   net/minecraft/util/parsing/packrat/Rule$RuleAction.class   net/minecraft/util/parsing/packrat/Rule$SimpleRuleAction.class   net/minecraft/util/parsing/packrat/Rule$WrappedTerm.class Processor failed, invalid outputs:     /srv/minecraft/./libraries/net/minecraft/server/1.21.6/server-1.21.6-official.jar       Expected: b1448d2c947e923ccd63224defc3b51e5a72a98d       Actual:   5f30bf411bd0d1208baca6b7be1584442f4f6579 There was an error during installation  
    • Fight with others to gain more hearts.
    • I wanted to try out Immersive railroading mod + Miszko's train resource pack, but everytime i create a world. it just gives me saving world after the map icon shows 100% and then crashes..   latest.log here https://drive.google.com/file/d/14v1pGCoytqyDvVwPayfUkYolmxcZ7z6-/view?usp=sharing
  • Topics

×
×
  • Create New...

Important Information

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