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

I am attempting to create a semi transparent model that will appear in a GUI. However, you can see behind the GUI with it and not behind in the GUI

spacer.png

    @SubscribeEvent
    public static void onTextureStitch(TextureStitchEvent.Pre event){
        if(event.getMap().getTextureLocation().equals(AtlasTexture.LOCATION_BLOCKS_TEXTURE)){
            event.addSprite(new ResourceLocation(MOD_ID, "planets/default"));
        }
    }
@Mod.EventBusSubscriber(modid=Main.MOD_ID, bus = Mod.EventBusSubscriber.Bus.MOD)
public class GUIBlockScreen extends ContainerScreen<GUIBlockContainer> {
    
  public GUIBlockScreen(GUIBlockContainer screenContainer, PlayerInventory inv, ITextComponent titleIn) {
        super(screenContainer, inv, titleIn);
    }

    @Override
    protected void drawGuiContainerBackgroundLayer(float partialTicks, int mouseX, int mouseY) {
        RenderSystem.color4f(1.0F, 1.0F, 1.0F, 1.0F);
        drawEntityOnScreen(this.width / 2, this.height / 2, (int) pow(30 - this.zoom / 3, 2 ));
    }

    public void drawOnScreen(int posX, int posY, int scale) {
        RenderSystem.pushMatrix();
      	// I have tried all of these but it dosn't seem to do anything
        // RenderSystem.enableBlend();
        // RenderSystem.enableTexture();
        // RenderSystem.enableDepthTest();
        // RenderSystem.disableCull();
        // RenderSystem.enableRescaleNormal();
        // RenderSystem.enableAlphaTest();
        // RenderSystem.defaultAlphaFunc();
        // RenderSystem.enableBlend();
        // RenderSystem.blendFunc(GlStateManager.SourceFactor.SRC_ALPHA, GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA);
        // RenderSystem.defaultBlendFunc();

        RenderSystem.translatef((float)posX, (float)posY, -1050.0F);
        RenderSystem.scalef(0.12F, 0.12F, 0.12F);

        MatrixStack matrixstack = new MatrixStack();

        IRenderTypeBuffer.Impl irendertypebuffer$impl = Minecraft.getInstance().getRenderTypeBuffers().getBufferSource();
      
      	IVertexBuilder vertexBuilder = irendertypebuffer$impl.getBuffer(RenderType.getTranslucent());

      	Material material = new Material(AtlasTexture.LOCATION_BLOCKS_TEXTURE, new ResourceLocation(Main.MOD_ID, 		"planets/defaulttransparency"));

		drawCube(new Vec3d(0.5, 0, 0), new Vec3d(0, 0.5, 0), new Vec3d(0, 0, 0.5), matrixstack, vertexBuilder, this.material, 0.3F);

        irendertypebuffer$impl.finish();

        RenderSystem.popMatrix();
    }
}
	private static void add(IVertexBuilder renderer, Matrix4f matrixPos, Vec3d A, Vec3d N, float u, float v, float opacity) {
        renderer.pos(matrixPos, (float) A.x, (float) A.y, (float) A.z)
                .color(1.0F, 1.0F, 1.0F, opacity)
                .tex(u, v)
                .lightmap(0, 240)
                .normal((float) N.x, (float) N.y, (float) N.z)
                .endVertex();
    }

    private static void square(IVertexBuilder renderer, Matrix4f matrixPos, Vec3d A, Vec3d B, Vec3d C, Material material, float opacity) {
        Vec3d N = A.crossProduct(B).normalize();
        float u = material.getSprite().getMinU();
        float U = material.getSprite().getMaxU();
        float v = material.getSprite().getMinV();
        float V = material.getSprite().getMaxV();
        add(renderer, matrixPos, C, N, u, v, opacity);
        add(renderer, matrixPos, A.add(C), N, U, v, opacity);
        add(renderer, matrixPos, A.add(B).add(C), N, U, V, opacity);
        add(renderer, matrixPos, B.add(C), N, u, V, opacity);
    }

    public static void drawCube(Vec3d A, Vec3d B, Vec3d C,
                                MatrixStack matrixstack, IVertexBuilder renderBuffer, Material material, float opacity) {
        // retrieves a position matrix
        Matrix4f matrixPos = matrixstack.getLast().getMatrix();

        // draws the 6 sides
        square(renderBuffer, matrixPos, A, B, Vec3d.ZERO, material, opacity);
        square(renderBuffer, matrixPos, B, A, C, material, opacity);

        square(renderBuffer, matrixPos, C, A, Vec3d.ZERO, material, opacity);
        square(renderBuffer, matrixPos, A, C, B, material, opacity);

        square(renderBuffer, matrixPos, B, C, Vec3d.ZERO, material, opacity);
        square(renderBuffer, matrixPos, C, B, A, material, opacity);
    }

 

Edited by garfield1002

  • Author

I found the solution. The error was not even in the code I put up, turns out the order in which the IVertexBuilder are created matters. (Create solid THEN translucent for good result)

IVertexBuilder

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.