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

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

  • Author

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!

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.