Jump to content

[1.15/1.14] Portal Animation Overlay Alpha Problem


Slashking

Recommended Posts

Hey everyone, I'm currently trying to build a custom portal block and everything is working nicely so far, however I've run into a weird issue with the portal animation (the one that plays out when standing inside the portal):

Just like the vanilla game I call a function that renders the portal animation, I call it from a RenderGameOverlayEvent (which should be the correct event) and the timeInPortal value also is computed correctly (I checked to make sure, it changes as intended and is calculated the same way the vanilla portal calculates it). As far as I understand the code this value controls the alpha value of the texture, however it is always rendered with no transparency at all, even if I substitute timeInPortal with 0 and I'm not sure why. I'm assuming either the blend mode is wrong (which is unlikely, as I copied the code from the vanilla class) or I load my texture wrong/without alpha for some reason. Any pointers? (Yes, the block is set up to have translucency and as a block in the world it renders correctly, but not as an overlay texture for some reason)

Edit: Just tested with the vanilla portal texture, it also is rendered with no transparency

The render code (apart from grabbing a Minecraft Instance named mc this is exactly how vanilla does it aswell):

public static void renderPortalAnim(float timeInPortal, int scaledWidth, int scaledHeight)
    {
		if (timeInPortal < 1.0F) {
	         timeInPortal = timeInPortal * timeInPortal;
	         timeInPortal = timeInPortal * timeInPortal;
	         timeInPortal = timeInPortal * 0.8F + 0.2F;
	      }
		Minecraft mc = Minecraft.getInstance();
		
	      RenderSystem.disableAlphaTest();
	      RenderSystem.disableDepthTest();
	      RenderSystem.depthMask(false);
	      RenderSystem.defaultBlendFunc();
	      RenderSystem.color4f(1.0F, 1.0F, 1.0F, timeInPortal);
	      mc.getTextureManager().bindTexture(AtlasTexture.LOCATION_BLOCKS_TEXTURE);
	      TextureAtlasSprite textureatlassprite = mc.getBlockRendererDispatcher().getBlockModelShapes().getTexture(BlockInit.custom_portal.getDefaultState());
	      float f = textureatlassprite.getMinU();
	      float f1 = textureatlassprite.getMinV();
	      float f2 = textureatlassprite.getMaxU();
	      float f3 = textureatlassprite.getMaxV();
	      Tessellator tessellator = Tessellator.getInstance();
	      BufferBuilder bufferbuilder = tessellator.getBuffer();
	      bufferbuilder.begin(7, DefaultVertexFormats.POSITION_TEX);
	      bufferbuilder.func_225582_a_(0.0D, (double)scaledHeight, -90.0D).func_225583_a_(f, f3).endVertex();
	      bufferbuilder.func_225582_a_((double)scaledWidth, (double)scaledHeight, -90.0D).func_225583_a_(f2, f3).endVertex();
	      bufferbuilder.func_225582_a_((double)scaledWidth, 0.0D, -90.0D).func_225583_a_(f2, f1).endVertex();
	      bufferbuilder.func_225582_a_(0.0D, 0.0D, -90.0D).func_225583_a_(f, f1).endVertex();
	      tessellator.draw();
	      RenderSystem.depthMask(true);
	      RenderSystem.enableDepthTest();
	      RenderSystem.enableAlphaTest();
	      RenderSystem.color4f(1.0F, 1.0F, 1.0F, 1.0F);
    }

 

Edited by Slashking
Link to comment
Share on other sites

Alright I figured it out, for people having a similiar problem in the future: If you do stuff in the RenderGameOverlayEvent, make sure to only do it "once", aka check for the event's type and only run your render code for one event type, not all of them, otherwise transparency will not work as you render the same thing over and over again, multiple times in a single frame!

Link to comment
Share on other sites

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.