Jump to content

Recommended Posts

Posted (edited)

So im trying to render some fluid inside my tank but it doesnt render anything idk why, please I need some help with this here is the code

package com.tigres810.testmod.tileentitys.renders;

import org.lwjgl.opengl.GL11;

import com.mojang.blaze3d.matrix.MatrixStack;
import com.mojang.blaze3d.vertex.IVertexBuilder;
import com.tigres810.testmod.tileentitys.TileFluidTankBlock;

import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.BufferBuilder;
import net.minecraft.client.renderer.IRenderTypeBuffer;
import net.minecraft.client.renderer.RenderType;
import net.minecraft.client.renderer.Tessellator;
import net.minecraft.client.renderer.texture.AtlasTexture;
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
import net.minecraft.client.renderer.tileentity.TileEntityRenderer;
import net.minecraft.client.renderer.tileentity.TileEntityRendererDispatcher;
import net.minecraft.client.renderer.vertex.DefaultVertexFormats;
import net.minecraft.fluid.Fluid;
import net.minecraft.inventory.container.PlayerContainer;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.math.vector.Matrix4f;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;
import net.minecraftforge.fluids.FluidAttributes;
import net.minecraftforge.fluids.FluidStack;

@OnlyIn(Dist.CLIENT)
public class RenderFluidTankBlock extends TileEntityRenderer<TileFluidTankBlock> {
	
	public static final float TANK_THICKNESS = 0.3f;
	public static final float TANK_HEIGHT = 0.2f;
	public static final float TANK_BOTTOM = 0.0f;

	public RenderFluidTankBlock(TileEntityRendererDispatcher rendererDispatcherIn) {
		super(rendererDispatcherIn);
	}
	
	private void add(IVertexBuilder renderer, MatrixStack stack, float x, float y, float z, float u, float v) {
        renderer.pos(stack.getLast().getMatrix(), x, y, z)
                .color(1.0f, 1.0f, 1.0f, 1.0f)
                .tex(u, v)
                .lightmap(0, 240)
                .normal(1, 0, 0)
                .endVertex();
    }

	@Override
	public void render(TileFluidTankBlock tileEntityIn, float partialTicks, MatrixStack matrixStackIn,
			IRenderTypeBuffer bufferIn, int combinedLightIn, int combinedOverlayIn) {
		if(tileEntityIn == null || tileEntityIn.isRemoved()) return;
		
		FluidStack fluid = tileEntityIn.getTank().getFluid();
		if (fluid == null) return;
		
		Fluid renderFluid = fluid.getFluid();
		if (renderFluid == null) return;
		
		FluidAttributes attributes = renderFluid.getAttributes();
        ResourceLocation fluidStill = attributes.getStillTexture(fluid);
        TextureAtlasSprite sprite = Minecraft.getInstance().getAtlasSpriteGetter(AtlasTexture.LOCATION_BLOCKS_TEXTURE).apply(fluidStill);
		
		IVertexBuilder builder = bufferIn.getBuffer(RenderType.getTranslucent());
		
		float scale = (1.0f - TANK_THICKNESS/2 - TANK_THICKNESS) * fluid.getAmount() / (tileEntityIn.getTank().getCapacity());
		
		matrixStackIn.push();
		matrixStackIn.translate(tileEntityIn.getPos().getX()+0.5, tileEntityIn.getPos().getY()+1.01/16.0, tileEntityIn.getPos().getZ()+0.5);
		matrixStackIn.scale(0.25f, 10.8f/16.0f, 0.25f);
		float u1 = sprite.getMinU();
        float v1 = sprite.getMinV();
        float u2 = sprite.getMaxU();
        float v2 = sprite.getMaxV();
        
        int color = renderFluid.getAttributes().getColor();
        
        float a = 1.0F;
        float r = (color >> 16 & 0xFF) / 255.0F;
        float g = (color >> 8 & 0xFF) / 255.0F;
        float b = (color & 0xFF) / 255.0F;
        
        add(builder, matrixStackIn, TANK_THICKNESS, scale + TANK_HEIGHT, TANK_THICKNESS, u1, v1);
		matrixStackIn.pop();
	}

}

I got no idea why is not working, also im trying to render one side to test if it works later ill add the rest of the faces.

Edited by tigres810
Posted

Well, when you want to draw a rectangular form on paper you don't just place the pencil somewhere on the paper and hope for the rest of the shape to draw itself right? The same applies here, but luckily you just need to define only the four vertices of the shape, and rendering of the connections between them will be handled in the background.

Check out the port of the BetterEnd fabric mod (WIP): https://www.curseforge.com/minecraft/mc-mods/betterend-forge-port

Posted (edited)
  On 11/25/2020 at 7:43 PM, Beethoven92 said:

Well, when you want to draw a rectangular form on paper you don't just place the pencil somewhere on the paper and hope for the rest of the shape to draw itself right? The same applies here, but luckily you just need to define only the four vertices of the shape, and rendering of the connections between them will be handled in the background.

Expand  

Okay so I got it working somehow but when I place fluid inside it doesnt render only when I reenter world Image

Edited by tigres810
Posted

Mmmmm it seems you are doing some weird positioning with the matrix translation and vertex positions, which i can not really spot right now without messing with the values myself. Try to play a bit with the vertex positions and the values you put in the matrixStackIn.translate and see how they appear ingame, so you can have better idea what's wrong with them

Check out the port of the BetterEnd fabric mod (WIP): https://www.curseforge.com/minecraft/mc-mods/betterend-forge-port

  • 2 weeks later...
Posted
  On 11/26/2020 at 3:22 PM, Beethoven92 said:

Mmmmm it seems you are doing some weird positioning with the matrix translation and vertex positions, which i can not really spot right now without messing with the values myself. Try to play a bit with the vertex positions and the values you put in the matrixStackIn.translate and see how they appear ingame, so you can have better idea what's wrong with them

Expand  

I fixed the code by my own thanks for trying to help 👍

Posted
  On 12/8/2020 at 7:48 PM, Beethoven92 said:

I am glad you solved the issue by yourself. You may want to share your solution, so other people seeing this post in the future may find it helpful

Expand  

The code is really simple actually I draw each quad individually showed here: 

package com.tigres810.testmod.tileentitys.renders;

import com.mojang.blaze3d.matrix.MatrixStack;
import com.mojang.blaze3d.vertex.IVertexBuilder;
import com.tigres810.testmod.tileentitys.TileFluidTankBlock;

import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.IRenderTypeBuffer;
import net.minecraft.client.renderer.RenderType;
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
import net.minecraft.client.renderer.tileentity.TileEntityRenderer;
import net.minecraft.client.renderer.tileentity.TileEntityRendererDispatcher;
import net.minecraft.fluid.Fluid;
import net.minecraft.inventory.container.PlayerContainer;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.math.vector.Quaternion;
import net.minecraft.util.math.vector.Vector3f;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;
import net.minecraftforge.fluids.FluidAttributes;
import net.minecraftforge.fluids.FluidStack;

@OnlyIn(Dist.CLIENT)
public class RenderFluidTankBlock extends TileEntityRenderer<TileFluidTankBlock> {
	
	public static final float TANK_THICKNESS = 0.3f;
	public static final float TANK_HEIGHT = 0.2f;
	public static final float TANK_BOTTOM = 0.0f;

	public RenderFluidTankBlock(TileEntityRendererDispatcher rendererDispatcherIn) {
		super(rendererDispatcherIn);
	}
	
	private void add(IVertexBuilder renderer, MatrixStack stack, float x, float y, float z, float u, float v, float r, float g, float b, float a) {
        renderer.pos(stack.getLast().getMatrix(), x, y, z)
                .color(r, g, b, a)
                .tex(u, v)
                .lightmap(0, 240)
                .normal(1, 0, 0)
                .endVertex();
    }

	@Override
	public void render(TileFluidTankBlock tileEntityIn, float partialTicks, MatrixStack matrixStackIn,
			IRenderTypeBuffer bufferIn, int combinedLightIn, int combinedOverlayIn) {
		if(tileEntityIn == null || tileEntityIn.isRemoved()) return;
		
		FluidStack fluid = tileEntityIn.getTank().getFluid();
		if (fluid == null) return;
		
		Fluid renderFluid = fluid.getFluid();
		if (renderFluid == null) return;
		
		FluidAttributes attributes = renderFluid.getAttributes();
        ResourceLocation fluidStill = attributes.getStillTexture(fluid);
        TextureAtlasSprite sprite = Minecraft.getInstance().getAtlasSpriteGetter(PlayerContainer.LOCATION_BLOCKS_TEXTURE).apply(fluidStill);
		
		IVertexBuilder builder = bufferIn.getBuffer(RenderType.getTranslucent());
		
		float scale = (1.0f - TANK_THICKNESS/2 - TANK_THICKNESS) * fluid.getAmount() / (tileEntityIn.getTank().getCapacity());
		
        Quaternion rotation = Vector3f.YP.rotationDegrees(0);
        
        int color = renderFluid.getAttributes().getColor();
        
        float a = 1.0F;
        float r = (color >> 16 & 0xFF) / 255.0F;
        float g = (color >> 8 & 0xFF) / 255.0F;
        float b = (color & 0xFF) / 255.0F;
		
		matrixStackIn.push();
        matrixStackIn.translate(.5, 0, .5);
        matrixStackIn.rotate(rotation);
        if(scale == 0.330f) { matrixStackIn.translate(0, -.1, 0); matrixStackIn.scale(.6f, scale + 0.110f, .6f);  } else if(scale == 0.440f) { matrixStackIn.translate(0, -.2, 0); matrixStackIn.scale(.6f, scale + 0.110f, .6f); } else if(scale == 0.550f) { matrixStackIn.translate(0, -.4, 0); matrixStackIn.scale(.6f, scale + 0.210f, .6f); } else { matrixStackIn.scale(.6f, scale, .6f); }
        matrixStackIn.translate(-.5, scale, -.5);
        
        // Top Face
        add(builder, matrixStackIn, 1 - .8f, 1, .8f, sprite.getMinU(), sprite.getMaxV(), r, g, b, a);
        add(builder, matrixStackIn, 0 + .8f, 1, .8f, sprite.getMaxU(), sprite.getMaxV(), r, g, b, a);
        add(builder, matrixStackIn, 0 + .8f, 1, .2f, sprite.getMaxU(), sprite.getMinV(), r, g, b, a);
        add(builder, matrixStackIn, 1 - .8f, 1, .2f, sprite.getMinU(), sprite.getMinV(), r, g, b, a);
        
        // Bottom Face of Top
        add(builder, matrixStackIn, 0 + .8f, 1, .8f, sprite.getMinU(), sprite.getMaxV(), r, g, b, a);
        add(builder, matrixStackIn, 1 - .8f, 1, .8f, sprite.getMaxU(), sprite.getMaxV(), r, g, b, a);
        add(builder, matrixStackIn, 1 - .8f, 1, .2f, sprite.getMaxU(), sprite.getMinV(), r, g, b, a);
        add(builder, matrixStackIn, 0 + .8f, 1, .2f, sprite.getMinU(), sprite.getMinV(), r, g, b, a);
        
        // Front Faces [NORTH - SOUTH]
        add(builder, matrixStackIn, 0 + .8f, 0 + 1, .8f, sprite.getMinU(), sprite.getMinV(), r, g, b, a);
        add(builder, matrixStackIn, 1 - .8f, 0 + 1, .8f, sprite.getMaxU(), sprite.getMinV(), r, g, b, a);
        add(builder, matrixStackIn, 1 - .8f, 1 - 1, .8f, sprite.getMaxU(), sprite.getMaxV(), r, g, b, a);
        add(builder, matrixStackIn, 0 + .8f, 1 - 1, .8f, sprite.getMinU(), sprite.getMaxV(), r, g, b, a);
        
        add(builder, matrixStackIn, 0 + .8f, 1 - 1, .2f, sprite.getMinU(), sprite.getMaxV(), r, g, b, a);
        add(builder, matrixStackIn, 1 - .8f, 1 - 1, .2f, sprite.getMaxU(), sprite.getMaxV(), r, g, b, a);
        add(builder, matrixStackIn, 1 - .8f, 0 + 1, .2f, sprite.getMaxU(), sprite.getMinV(), r, g, b, a);
        add(builder, matrixStackIn, 0 + .8f, 0 + 1, .2f, sprite.getMinU(), sprite.getMinV(), r, g, b, a);
        
        // Back Faces
        add(builder, matrixStackIn, 0 + .8f, 0 + 1, .2f, sprite.getMinU(), sprite.getMinV(), r, g, b, a);
        add(builder, matrixStackIn, 1 - .8f, 0 + 1, .2f, sprite.getMaxU(), sprite.getMinV(), r, g, b, a);
        add(builder, matrixStackIn, 1 - .8f, 1 - 1, .2f, sprite.getMaxU(), sprite.getMaxV(), r, g, b, a);
        add(builder, matrixStackIn, 0 + .8f, 1 - 1, .2f, sprite.getMinU(), sprite.getMaxV(), r, g, b, a);

        add(builder, matrixStackIn, 0 + .8f, 1 - 1, .8f, sprite.getMinU(), sprite.getMaxV(), r, g, b, a);
        add(builder, matrixStackIn, 1 - .8f, 1 - 1, .8f, sprite.getMaxU(), sprite.getMaxV(), r, g, b, a);
        add(builder, matrixStackIn, 1 - .8f, 0 + 1, .8f, sprite.getMaxU(), sprite.getMinV(), r, g, b, a);
        add(builder, matrixStackIn, 0 + .8f, 0 + 1, .8f, sprite.getMinU(), sprite.getMinV(), r, g, b, a);
        
        matrixStackIn.rotate(Vector3f.YP.rotationDegrees(90));
        matrixStackIn.translate(-1f, 0, 0);
        // Front Faces [EAST - WEST]
        add(builder, matrixStackIn, 0 + .8f, 0 + 1, .8f, sprite.getMinU(), sprite.getMinV(), r, g, b, a);
        add(builder, matrixStackIn, 1 - .8f, 0 + 1, .8f, sprite.getMaxU(), sprite.getMinV(), r, g, b, a);
        add(builder, matrixStackIn, 1 - .8f, 1 - 1, .8f, sprite.getMaxU(), sprite.getMaxV(), r, g, b, a);
        add(builder, matrixStackIn, 0 + .8f, 1 - 1, .8f, sprite.getMinU(), sprite.getMaxV(), r, g, b, a);

        add(builder, matrixStackIn, 0 + .8f, 1 - 1, .2f, sprite.getMinU(), sprite.getMaxV(), r, g, b, a);
        add(builder, matrixStackIn, 1 - .8f, 1 - 1, .2f, sprite.getMaxU(), sprite.getMaxV(), r, g, b, a);
        add(builder, matrixStackIn, 1 - .8f, 0 + 1, .2f, sprite.getMaxU(), sprite.getMinV(), r, g, b, a);
        add(builder, matrixStackIn, 0 + .8f, 0 + 1, .2f, sprite.getMinU(), sprite.getMinV(), r, g, b, a);
        
        // Back Faces
        add(builder, matrixStackIn, 0 + .8f, 0 + 1, .2f, sprite.getMinU(), sprite.getMinV(), r, g, b, a);
        add(builder, matrixStackIn, 1 - .8f, 0 + 1, .2f, sprite.getMaxU(), sprite.getMinV(), r, g, b, a);
        add(builder, matrixStackIn, 1 - .8f, 1 - 1, .2f, sprite.getMaxU(), sprite.getMaxV(), r, g, b, a);
        add(builder, matrixStackIn, 0 + .8f, 1 - 1, .2f, sprite.getMinU(), sprite.getMaxV(), r, g, b, a);

        add(builder, matrixStackIn, 0 + .8f, 1 - 1, .8f, sprite.getMinU(), sprite.getMaxV(), r, g, b, a);
        add(builder, matrixStackIn, 1 - .8f, 1 - 1, .8f, sprite.getMaxU(), sprite.getMaxV(), r, g, b, a);
        add(builder, matrixStackIn, 1 - .8f, 0 + 1, .8f, sprite.getMaxU(), sprite.getMinV(), r, g, b, a);
        add(builder, matrixStackIn, 0 + .8f, 0 + 1, .8f, sprite.getMinU(), sprite.getMinV(), r, g, b, a);
		matrixStackIn.pop();
	}

}

 

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



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • Add the crash-report or latest.log (logs-folder) with sites like https://mclo.gs/ and paste the link to it here  
    • Cracked Launchers are not supported
    • Hi, I have a problem in minecraft java (only in forge 1.20.1), When I start the game after a moment the game crashed with code 1 this only in forge 1.20.1 , I tried to reinstall java, Upgrade java to 17, update the drivers to the latest version, downgrade the drivers to the pervious version, deleting .minecraft and reinstall it , but none of these ways working.   here is the log:   [Launcher] Launching Minecraft... I'm hiding! mods after C:\Users\Windows\AppData\Roaming\.minecraft\mods\tl_skin_cape_forge_1.20_1.20.1-1.32.jar [InnerMinecraftServersImpl]  search changers of the servers read servers from servers.dat [] [InnerMinecraftServersImpl]  prepare inner servers save servers to servers.dat [Launcher] Game skin type: TLAUNCHER [Launcher] Starting Minecraft Forge 1.20.1... [Launcher] Launching in: C:\Users\Windows\AppData\Roaming\.minecraft Starting garbage collector: 96 / 227 MB Garbage collector completed: 60 / 214 MB [Launcher] Processing post-launch actions. Assist launch: true =============================================================================================== [05:29:03] [main/INFO]: ModLauncher running: args [--username, *********, --version, Forge 1.20.1, --gameDir, C:\Users\Windows\AppData\Roaming\.minecraft, --assetsDir, C:\Users\Windows\AppData\Roaming\.minecraft\assets, --assetIndex, 5, --uuid, *************************************, --accessToken, вќ„вќ„вќ„вќ„вќ„вќ„вќ„вќ„, --clientId, null, --xuid, null, --userType, mojang, --versionType, modified, --width, 925, --height, 530, --launchTarget, forgeclient, --fml.forgeVersion, 47.3.22, --fml.mcVersion, 1.20.1, --fml.forgeGroup, net.minecraftforge, --fml.mcpVersion, 20230612.114412] [05:29:04] [main/INFO]: ModLauncher 10.0.9+10.0.9+main.dcd20f30 starting: java version 17.0.12 by Oracle Corporation; OS Windows 10 arch amd64 version 10.0 [05:29:15] [main/INFO]: Loading ImmediateWindowProvider fmlearlywindow [05:29:24] [main/INFO]: Trying GL version 4.6 [05:29:60] [main/INFO]: Requested GL version 4.6 got version 4.6 [05:29:67] [main/INFO]: SpongePowered MIXIN Subsystem Version=0.8.5 Source=union:/C:/Users/Windows/AppData/Roaming/.minecraft/libraries/org/spongepowered/mixin/0.8.5/mixin-0.8.5.jar%23100!/ Service=ModLauncher Env=CLIENT FATAL ERROR in native method: Thread[pool-2-thread-1,5,main]: No context is current or a function that is not available in the current context was called. The JVM will abort execution.     at org.lwjgl.opengl.GL11C.nglGetString(org.lwjgl.opengl@3.3.1+7/Native Method)     at org.lwjgl.opengl.GL11C.glGetString(org.lwjgl.opengl@3.3.1+7/GL11C.java:978)     at net.minecraftforge.fml.earlydisplay.DisplayWindow.initRender(fmlearlydisplay@1.20.1-47.3.22/DisplayWindow.java:209)     at net.minecraftforge.fml.earlydisplay.DisplayWindow.lambda$start$5(fmlearlydisplay@1.20.1-47.3.22/DisplayWindow.java:292)     at net.minecraftforge.fml.earlydisplay.DisplayWindow$$Lambda$437/0x000001fab120a618.run(fmlearlydisplay@1.20.1-47.3.22/Unknown Source)     at java.util.concurrent.Executors$RunnableAdapter.call(java.base@17.0.12/Executors.java:539)     at java.util.concurrent.FutureTask.run(java.base@17.0.12/FutureTask.java:264)     at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(java.base@17.0.12/ScheduledThreadPoolExecutor.java:304)     at java.util.concurrent.ThreadPoolExecutor.runWorker(java.base@17.0.12/ThreadPoolExecutor.java:1136)     at java.util.concurrent.ThreadPoolExecutor$Worker.run(java.base@17.0.12/ThreadPoolExecutor.java:635)     at java.lang.Thread.run(java.base@17.0.12/Thread.java:842) Here I am! [VersionManager] Refreshing versions locally... [VersionManager] Versions has been refreshed (6 ms) [Launcher] Launcher exited. [Launcher] Minecraft closed with exit code: 1 flush now [Launcher] [Crash] Signature "Bad video drivers" matches! [Crash] Signature "Bad video drivers" matches! [Launcher] [Crash] Crash has been recognized! [Crash] Crash has been recognized! flush now
  • Topics

×
×
  • Create New...

Important Information

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