Skip to content

Conversation

@PeTcHeNkA
Copy link

Description

Adds proper fallback to default skins (Steve/Alex) when invalid texture ResourceLocations are provided for CustomNPCs, preventing invisible/transparent NPCs from appearing.

Problem

When an invalid texture path like customnpcs:textures/entity/test.png or an empty string "" is entered in the CustomNPC texture field, the NPC appears with a transparent texture instead of falling back to a default skin. While URL-based skins (skinType 2/3) already had fallback logic, local ResourceLocation textures (skinType 0) were missing validation and fallback handling.

The specific issue was in the else branch of skinType 0 handling, where new ResourceLocation(npc.display.texture) was created without checking if npc.display.texture was empty or invalid.

Changes

  • Added empty string check in skinType 0 else branch before creating ResourceLocation
  • Set textureLocation to fallBackSkin(npc) when texture is empty or invalid
  • Added null safety check at the end of getEntityTexture() to ensure fallback is returned if textureLocation is still null
  • Matches the same fallback pattern used in skinType 2/3 URL-based texture handling

Testing

  1. Create a CustomNPC
  2. Set texture to an empty string ""
  3. Verify the NPC displays with default Steve/Alex skin instead of being transparent
  4. Set texture to an invalid path (e.g., customnpcs:textures/entity/nonexistent.png)
  5. Verify the NPC still displays with default Steve/Alex skin

- Add empty string check in skinType 0 else branch
- Set textureLocation to fallBackSkin(npc) for invalid textures
- Add null safety check before returning textureLocation
- Prevents transparent NPCs when invalid paths like "customnpcs:textures/entity/test.png" or "teststring" are used
…ture

Previously, skinType==0 branch created a ResourceLocation directly without
checking if the resource actually exists. This was inconsistent with
adjustLocalTexture(), which probes the ResourceManager and falls back on
missing assets.

Now we call Minecraft.geMinecraft().getResourceManager().getResource(resLoc)
and catch IOException. On failure, we fall back to a valid texture via
fallBackSkin(npc), ensuring rendering always uses a valid path and avoiding
invalid ResourceLocation assignments.

This change aligns behavior across texture loading paths and prevents
rendering errors when NPC textures are missing.
@PeTcHeNkA
Copy link
Author

Before:

image image

After:

image image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant