Jump to content

Render clouds (1.7.10)


Liahim

Recommended Posts

Hello everybody!

I'm trying to duplicate the standard cloud.

Is the following code (90% vanila):

private Minecraft mc = Minecraft.getMinecraft();
private TextureManager renderEngine;
private WorldClient theWorld;
private static final ResourceLocation locationCloudsPng = new ResourceLocation("mod:textures/environment/cloud.png");
    

@SideOnly(Side.CLIENT)
@SubscribeEvent
public void renderCloudEvent(RenderWorldLastEvent e) {

	layerCloudRender(e.partialTicks);
}

private void layerCloudRender(float partialTicks) {

	this.renderEngine = mc.getTextureManager();
	this.theWorld = mc.theWorld;

	float p_72718_1_ = partialTicks;
	IRenderHandler renderer = null;
        if ((renderer = theWorld.provider.getCloudRenderer()) != null)
        {
            renderer.render(p_72718_1_, theWorld, mc);
            return;
        }
        if (this.mc.theWorld.provider.isSurfaceWorld())
        {
                GL11.glDisable(GL11.GL_CULL_FACE);
                float f1 = (float)(this.mc.renderViewEntity.lastTickPosY + (this.mc.renderViewEntity.posY - this.mc.renderViewEntity.lastTickPosY) * (double)p_72718_1_);
                byte b0 = 32;
                int i = 256 / b0;
                Tessellator tessellator = Tessellator.instance;
                this.renderEngine.bindTexture(locationCloudsPng);
                GL11.glEnable(GL11.GL_BLEND);
                OpenGlHelper.glBlendFunc(770, 771, 1, 0);
                Vec3 vec3 = this.theWorld.getCloudColour(p_72718_1_);
                float f2 = (float)vec3.xCoord;
                float f3 = (float)vec3.yCoord;
                float f4 = (float)vec3.zCoord;
                float f5;

                if (this.mc.gameSettings.anaglyph)
                {
                    f5 = (f2 * 30.0F + f3 * 59.0F + f4 * 11.0F) / 100.0F;
                    float f6 = (f2 * 30.0F + f3 * 70.0F) / 100.0F;
                    float f7 = (f2 * 30.0F + f4 * 70.0F) / 100.0F;
                    f2 = f5;
                    f3 = f6;
                    f4 = f7;
                }

                f5 = 4.8828125E-4F;
                double d2 = (double)((float)50 + p_72718_1_);
                double d0 = this.mc.renderViewEntity.prevPosX + (this.mc.renderViewEntity.posX - this.mc.renderViewEntity.prevPosX) * (double)p_72718_1_ + d2 * 0.029999999329447746D;
                double d1 = this.mc.renderViewEntity.prevPosZ + (this.mc.renderViewEntity.posZ - this.mc.renderViewEntity.prevPosZ) * (double)p_72718_1_;
                int j = MathHelper.floor_double(d0 / 2048.0D);
                int k = MathHelper.floor_double(d1 / 2048.0D);
                d0 -= (double)(j * 2048);
                d1 -= (double)(k * 2048);
                float f8 = this.theWorld.provider.getCloudHeight() - f1 - 16.33F;
                float f9 = (float)(d0 * (double)f5);
                float f10 = (float)(d1 * (double)f5);
                tessellator.startDrawingQuads();
                tessellator.setColorRGBA_F(f2, f3, f4, 0.8F);

                for (int l = -b0 * i; l < b0 * i; l += b0)
                {
                    for (int i1 = -b0 * i; i1 < b0 * i; i1 += b0)
                    {
                        tessellator.addVertexWithUV((double)(l + 0), (double)f8, (double)(i1 + b0), (double)((float)(l + 0) * f5 + f9), (double)((float)(i1 + b0) * f5 + f10));
                        tessellator.addVertexWithUV((double)(l + b0), (double)f8, (double)(i1 + b0), (double)((float)(l + b0) * f5 + f9), (double)((float)(i1 + b0) * f5 + f10));
                        tessellator.addVertexWithUV((double)(l + b0), (double)f8, (double)(i1 + 0), (double)((float)(l + b0) * f5 + f9), (double)((float)(i1 + 0) * f5 + f10));
                        tessellator.addVertexWithUV((double)(l + 0), (double)f8, (double)(i1 + 0), (double)((float)(l + 0) * f5 + f9), (double)((float)(i1 + 0) * f5 + f10));
                    }
                }

                tessellator.draw();
                GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
                GL11.glDisable(GL11.GL_BLEND);
                GL11.glEnable(GL11.GL_CULL_FACE);
            }
}

 

However, my cloud do not disappear in the distance.

Moreover, translucent blocks in the foreground are not visible.

The picture shows the both problems:

KYWcYE7nGUI.jpg

 

How can I fix it?

Sorry, I don't speak English very well...

Link to comment
Share on other sites

You can't render it on RenderWorldLastEvent, because it is one of the farthest objects in the world, next to the sky. So you should render it on IRenderHandler and register it using WorldProvider#setCloudRenderer.

I. Stellarium for Minecraft: Configurable Universe for Minecraft! (WIP)

II. Stellar Sky, Better Star Rendering&Sky Utility mod, had separated from Stellarium.

Link to comment
Share on other sites

Yes, I tried it. But the glass blocks are still not visible.

But I've been thinking.

Water and colored glass using renderPass = 1 and they can see through each other.

How can I render a transparent plane (my clouds) using a renderPass = 1?

Sorry, I don't speak English very well...

Link to comment
Share on other sites

No, you can't use them. They are sorted correctly on rendering, thus have no problem.

What is the exact problem do you have with WorldProvider#setCloudRenderer?

That should not hide any transparent blocks

Show what you have tried with it in code.

I. Stellarium for Minecraft: Configurable Universe for Minecraft! (WIP)

II. Stellar Sky, Better Star Rendering&Sky Utility mod, had separated from Stellarium.

Link to comment
Share on other sites

My problem is that the horizon line is at a height of 160.

Duplicated clouds are located under your feet, at a height of about 140.

At this height clouds transparency settings are changed and the clouds become transparent. You can check it yourself.

Under such conditions, a translucent blocks are not visible.

This happens if the use WorldProvider#setCloudRenderer or RenderWorldLastEvent.

However, if you use DrawBlockHighlightEvent, for example, transparent blocks before clouds become visible, but they disappear behind the clouds.

 

My code:

@SideOnly(Side.CLIENT)
@SubscribeEvent
public void renderEvent(DrawBlockHighlightEvent e) {
World world = this.mc.thePlayer.worldObj;
if (world.isRemote && world.provider.dimensionId == CommonProxy.dimensionId) {
cloudRender(e.partialTicks, (WorldClient)world, this.mc);
}		
}

public static void cloudRender(float partialTicks, WorldClient world, Minecraft mc) {

float playerHeight = (float)(mc.renderViewEntity.lastTickPosY + (mc.renderViewEntity.posY - mc.renderViewEntity.lastTickPosY) * (double)partialTicks);
byte i = 4;
int r = mc.gameSettings.renderDistanceChunks * 16;
int e = r / i;
int d = r * 2;
Tessellator tessellator = Tessellator.instance;
Last Edit: Yesterday at 04:35:53 pm
mc.getTextureManager().bindTexture(locationCloudPng);
GL11.glEnable(GL11.GL_BLEND);
GL11.glAlphaFunc(GL11.GL_GREATER, 0.0F);
GL11.glEnable(GL11.GL_FOG);
OpenGlHelper.glBlendFunc(770, 771, 1, 0);
Vec3 vec3 = world.getCloudColour(partialTicks);
float f2 = (float)vec3.xCoord;
float f3 = (float)vec3.yCoord;
float f4 = (float)vec3.zCoord;
float colorOffset = 0.64F;

float height = 140;

tessellator.startDrawingQuads();
tessellator.setColorRGBA_F(f2 + colorOffset, f3 + colorOffset, f4 + colorOffset, 0.05F);

for (int x = -e * i; x < e * i; x += e)
{
for (int y = -e * i; y < e * i; y += e)
{
	tessellator.addVertexWithUV(x, height, y, (float)(r+y)/d, (float)(r-x)/d);
	tessellator.addVertexWithUV(x, height, y+e, (float)(r+y+e)/d, (float)(r-x)/d);
	tessellator.addVertexWithUV(x+e, height, y+e, (float)(r+y+e)/d, (float)(r-x-e)/d);
	tessellator.addVertexWithUV(x+e, height, y, (float)(r+y)/d, (float)(r-x-e)/d);
}
}	
            	
tessellator.draw();

GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
GL11.glDisable(GL11.GL_FOG);
GL11.glAlphaFunc(GL11.GL_GREATER, 0.1F);
GL11.glDisable(GL11.GL_BLEND);
}

Sorry, I don't speak English very well...

Link to comment
Share on other sites

Well, you didnt post the code you used with setCloudRenderer.

Also, you should try to understand vanilla cloud code before just copying it. GL state can be different on each methods.

 

What is your goal with this? If you are just simulating vanilla clouds.

I. Stellarium for Minecraft: Configurable Universe for Minecraft! (WIP)

II. Stellar Sky, Better Star Rendering&Sky Utility mod, had separated from Stellarium.

Link to comment
Share on other sites

You're right, my goal is not clouds. Sorry if I express myself is not clear.

I need to render a translucent plane under the player's feet.

The plane should be visible regardless of the clouds ON/OFF settings.

That's why I do not use the WorldProvider#setCloudRenderer.

Could you tell me about the GL states?

Maybe it will help me to implement its plans.

Sorry, I don't speak English very well...

Link to comment
Share on other sites

First, the cloud disappears when it is far enough from the player. (This phenomenon is caused by z-clipping)

So the closer its vertical position to the player, the further its visible edge goes.

 

The GL state related with this concept is Depth Test and Depth Mask.

Google is your friend: [lmgtfy]Depth Test and Depth Mask[/lmgtfy]

They might be disabled on RenderWorldLastEvent, test for it.

 

Also, note that cloud is rendered twice, before world rendering and after world rendering.

You can simulate latter by RenderWorldLastEvent, but there is no event fired before world rendering.

So World#setCloudRenderer migh be the only possibility.

Look at EntityRenderer#renderWorldPass for more information.

I. Stellarium for Minecraft: Configurable Universe for Minecraft! (WIP)

II. Stellar Sky, Better Star Rendering&Sky Utility mod, had separated from Stellarium.

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



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • I have a problem, I am trying to put two different effects to two different armors but when I run it only the emerald armor effect works. This is the code public class ModArmorItem extends ArmorItem{ private static final Map<ArmorMaterial, MobEffectInstance> MATERIAL_TO_EFFECT_MAP = (new ImmutableMap.Builder<ArmorMaterial, MobEffectInstance>()) .put(ModArmorMaterials.EMERALD, new MobEffectInstance(MobEffects.HERO_OF_THE_VILLAGE,200, 1,false,false, true)) .put(ModArmorMaterials.OBSIDIAN, new MobEffectInstance(MobEffects.FIRE_RESISTANCE,200, 1,false,false, true)).build(); public ModArmorItem(ArmorMaterial pMaterial, Type pType, Properties pProperties) { super(pMaterial, pType, pProperties); } @Override public void onArmorTick(ItemStack stack, Level world, Player player){ if (!world.isClientSide()) { if (hasFullSuitOfArmorOn(player)) { evaluateArmorEffects(player); } } } private void evaluateArmorEffects(Player player) { for (Map.Entry<ArmorMaterial,MobEffectInstance> entry : MATERIAL_TO_EFFECT_MAP.entrySet()){ ArmorMaterial mapArmorMaterial = entry.getKey(); MobEffectInstance mapStatusEffect = entry.getValue(); if (hasCorrectArmorOn(mapArmorMaterial, player)) { addStatusEffectForMaterial(player, mapArmorMaterial, mapStatusEffect); } } } private void addStatusEffectForMaterial(Player player, ArmorMaterial mapArmorMaterial, MobEffectInstance mapStatusEffect) { boolean hasPlayerEffect = player.hasEffect(mapStatusEffect.getEffect()); if (hasCorrectArmorOn(mapArmorMaterial, player) && !hasPlayerEffect) { player.addEffect(new MobEffectInstance(mapStatusEffect)); } } private boolean hasCorrectArmorOn(ArmorMaterial material, Player player) { for (ItemStack armorStack : player.getInventory().armor){ if (!(armorStack.getItem() instanceof ArmorItem)) { return false; } } ArmorItem helmet = ((ArmorItem)player.getInventory().getArmor(3).getItem()); ArmorItem breastplace = ((ArmorItem)player.getInventory().getArmor(2).getItem()); ArmorItem leggins = ((ArmorItem)player.getInventory().getArmor(1).getItem()); ArmorItem boots = ((ArmorItem)player.getInventory().getArmor(0).getItem()); return helmet.getMaterial() == material && breastplace.getMaterial() == material && leggins.getMaterial() == material && boots.getMaterial() == material; } private boolean hasFullSuitOfArmorOn(Player player){ ItemStack helmet = player.getInventory().getArmor(3); ItemStack breastplace = player.getInventory().getArmor(2); ItemStack leggins = player.getInventory().getArmor(1); ItemStack boots = player.getInventory().getArmor(0); return !helmet.isEmpty() && !breastplace.isEmpty() && !leggins.isEmpty() && !boots.isEmpty(); } } Also when I place two effects on the same armor, the game crashes. Here is the crash file. The code is the same, only this part is different   private static final Map<ArmorMaterial, MobEffectInstance> MATERIAL_TO_EFFECT_MAP = (new ImmutableMap.Builder<ArmorMaterial, MobEffectInstance>()) .put(ModArmorMaterials.EMERALD, new MobEffectInstance(MobEffects.HERO_OF_THE_VILLAGE,200, 1,false,false, true)) .put(ModArmorMaterials.EMERALD, new MobEffectInstance(MobEffects.FIRE_RESISTANCE,200, 1,false,false, true)).build(); I hope you guys can help me. Thanks.
    • I removed all related embeddium and oculus mods, i just tested it by disconnecting and the error happened again. heres the report https://pastebin.com/1kcR5wAt   EDIT: i tried removing xaeros and also smoothboot thinking there may be an issue there, nothing, heres that report too. https://pastebin.com/zQS7i9rM
    • Hi, I need suggestions. I am a beginner in Minecraft Modding. I would like to apply custom effects to some armors, something like: more chance to drop seeds, change zombie awareness, drop more pieces of wood when chopping logs, and things like that. How would you recommend me to do it, is there any library that has something similar and which ones would you recommend me?.
    • "downloading minecraft server failed, invalid Checksum. try again, or manually place server.jar to skip download"    
    • You have to create an Entity class called PlayerPart and use multiple of them to make the different parts of the player. See EnderDragonPart.java source code. The green hitboxes of the dragon are all EnderDragonParts
  • Topics

×
×
  • Create New...

Important Information

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