Jump to content

Recommended Posts

Posted (edited)

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

×   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



×
×
  • Create New...

Important Information

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