Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

Posted

Hi.
I'm having trouble rendering my own head. If I place a head that has my skin texture and another one next to it (without texture - completely black) my skin is visible on the second one until the first head disappears from view. 
How to make the second head always be all black?

https://imgur.com/Bd2fNgP

https://imgur.com/m04kAWV

Code:

public class CustomSkullRenderer implements BlockEntityRenderer<CustomSkullBlockEntity> {
	
	SkullModelBase headModel;
	RenderType rendertype;
	DynamicTexture texture;
		
	private int[][] oldTextureMap;
	
	public CustomSkullRenderer(BlockEntityRendererProvider.Context context) {
		headModel = new SkullModel(context.bakeLayer(ClientSetup.HEAD));
		rendertype = null;		
		oldTextureMap = new int[16][32];
		
		texture = new DynamicTexture(64, 64, true);
	}
	
	@Override
	public void render(CustomSkullBlockEntity be, float p_112308_, PoseStack pose, MultiBufferSource buffer, int light, int p_112312_) {  
		try {
			updateImage(be);
			if(rendertype == null) {
				Minecraft.getInstance().getTextureManager().register(be.getLocation(), texture);
				rendertype = CustomRenderType.createSkullRenderType(be.getLocation());
			}
		} catch(Exception e) {
			e.printStackTrace();
		}
				
      BlockState blockstate = be.getBlockState();
      boolean flag = blockstate.getBlock() instanceof CustomSkullWall;
      Direction direction = flag ? blockstate.getValue(CustomSkullWall.FACING) : null;
      float f1 = 22.5F * (float)(flag ? (2 + direction.get2DDataValue()) * 4 : blockstate.getValue(CustomSkull.ROTATION));
      
      pose.pushPose();
      if(direction == null) {
      	pose.translate(0.5D, 0.0D, 0.5D);
      } else {
      	pose.translate((double)(0.5F - (float)direction.getStepX() * 0.25F), 0.25D, (double)(0.5F - (float)direction.getStepZ() * 0.25F));
      }

      pose.scale(-1.0F, -1.0F, 1.0F);
      VertexConsumer vertexconsumer = buffer.getBuffer(rendertype);
      headModel.setupAnim(0, f1, 0);
      headModel.renderToBuffer(pose, vertexconsumer, light, OverlayTexture.NO_OVERLAY, 1.0F, 1.0F, 1.0F, 1.0F);
      pose.popPose();
	}

	public void updateImage(CustomSkullBlockEntity be) {		
		boolean update = false;
		for(int y = 0; y < be.getTextureMap().length; y++) {
      	for(int x = 0; x < be.getTextureMap()[y].length; x++) {
      		if(oldTextureMap[y][x] != be.getTextureMap()[y][x]) {
      			setColorToImage(x, y, be.getTextureMap()[y][x]);
      			update = true;
      		}
      	}
      }

		if(update) {
			texture.upload();
		}
	}
	
	public void setColorToImage(int x, int y, int color) {						
		texture.getPixels().setPixelRGBA(x, y, color);
		oldTextureMap[y][x] = color;
	}
}
public static RenderType createSkullRenderType(ResourceLocation location) {
      RenderType.CompositeState rendertype$compositestate = RenderType.CompositeState.builder()
      		.setShaderState(RENDERTYPE_ENTITY_TRANSLUCENT_SHADER)
      		.setTextureState(new RenderStateShard.TextureStateShard(location, false, false))
      		.setTransparencyState(TRANSLUCENT_TRANSPARENCY)
      		.setCullState(NO_CULL)
      		.setLightmapState(LIGHTMAP)
      		.setOverlayState(OVERLAY)
      		.createCompositeState(true);
      return RenderType.create(Main.MODID + "_head", DefaultVertexFormat.NEW_ENTITY, VertexFormat.Mode.QUADS, 256, true, true, rendertype$compositestate);
}

 

Edited by grossik

  • grossik changed the title to [1.19] Custom head rendering problem

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...

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.