Jump to content

Recommended Posts

Posted

I cannot get the Fog color to work; along with the density. I looked at other posts, tutorials, and GitHub Repository-s but still have no idea why this won't work.

@SubscribeEvent(priority = EventPriority.NORMAL, receiveCanceled = true)
public void onFogDensityEvent(EntityViewRenderEvent.FogDensity event) {
    event.setDensity(0.0001F);
    if (event.getEntity().isInsideOfMaterial(ModMaterials.MOLTEN_GLASS)) event.setDensity(1F);
}

@SubscribeEvent(priority = EventPriority.NORMAL, receiveCanceled = true)
public void onFogColorsEvent(EntityViewRenderEvent.FogColors event) {
    if (event.getEntity().isInsideOfMaterial(ModMaterials.MOLTEN_GLASS)) {
        event.setRed(COLOR_MOLTEN_GLASS.getRed());
        event.setGreen(COLOR_MOLTEN_GLASS.getGreen());
        event.setBlue(COLOR_MOLTEN_GLASS.getBlue());
    }
}
private static final Color COLOR_MOLTEN_GLASS = new Color(251, 143, 70);
Posted
41 minutes ago, DiamondMiner88 said:

I cannot get the Fog color to work; along with the density. I looked at other posts, tutorials, and GitHub Repository-s but still have no idea why this won't work.


@SubscribeEvent(priority = EventPriority.NORMAL, receiveCanceled = true)
public void onFogDensityEvent(EntityViewRenderEvent.FogDensity event) {
    event.setDensity(0.0001F);
    if (event.getEntity().isInsideOfMaterial(ModMaterials.MOLTEN_GLASS)) event.setDensity(1F);
}

@SubscribeEvent(priority = EventPriority.NORMAL, receiveCanceled = true)
public void onFogColorsEvent(EntityViewRenderEvent.FogColors event) {
    if (event.getEntity().isInsideOfMaterial(ModMaterials.MOLTEN_GLASS)) {
        event.setRed(COLOR_MOLTEN_GLASS.getRed());
        event.setGreen(COLOR_MOLTEN_GLASS.getGreen());
        event.setBlue(COLOR_MOLTEN_GLASS.getBlue());
    }
}

private static final Color COLOR_MOLTEN_GLASS = new Color(251, 143, 70);

Did you check if events are being called?

Posted

No, how do i do that?

I placed them in my ClientEventSubscriber

Spoiler

package tk.diamondbuildz.mod.character.client;

import com.google.common.base.Preconditions;
import net.minecraft.block.Block;
import net.minecraft.block.state.IBlockState;
import net.minecraft.client.renderer.block.model.ModelBakery;
import net.minecraft.client.renderer.block.model.ModelResourceLocation;
import net.minecraft.client.renderer.block.statemap.StateMapperBase;
import net.minecraft.item.Item;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.client.event.EntityViewRenderEvent;
import net.minecraftforge.client.event.ModelRegistryEvent;
import net.minecraftforge.client.model.ModelLoader;
import net.minecraftforge.fluids.IFluidBlock;
import net.minecraftforge.fml.common.Mod.EventBusSubscriber;
import net.minecraftforge.fml.common.eventhandler.EventPriority;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import net.minecraftforge.fml.common.registry.ForgeRegistries;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import tk.diamondbuildz.mod.character.reference.ModMaterials;

import javax.annotation.Nonnull;
import java.awt.*;

import static net.minecraftforge.fml.relauncher.Side.CLIENT;
import static tk.diamondbuildz.mod.character.reference.Reference.FLUID_MODEL_PATH;
import static tk.diamondbuildz.mod.character.reference.Reference.MOD_ID;

/**
 * Subscribe to events that should be handled on the PHYSICAL CLIENT in this class
 *
 * @author Diamond
 */
@EventBusSubscriber(modid = MOD_ID, value = CLIENT)
public final class ClientEventSubscriber {

    private static final Logger LOGGER = LogManager.getLogger();
    private static final String DEFAULT_VARIANT = "normal";

    private static final Color COLOR_MOLTEN_GLASS = new Color(251, 143, 70);

    /**
     * Cycle through all block and items already registered, if ModId of the entry matches to my ModId, calls
     * {@link ClientEventSubscriber#registerItemBlockModel(Block)}
     * or
     * {@link ClientEventSubscriber#registerItemModel(Item)}
     */
    @SubscribeEvent
    public static void onRegisterModelsEvent(@Nonnull final ModelRegistryEvent event) {
        ForgeRegistries.BLOCKS.getValuesCollection().stream()
                .filter(block -> block.getRegistryName().getNamespace().equals(MOD_ID))
                .forEach(ClientEventSubscriber::registerItemBlockModel);

        ForgeRegistries.ITEMS.getValuesCollection().stream()
                .filter(block -> block.getRegistryName().getNamespace().equals(MOD_ID))
                .forEach(ClientEventSubscriber::registerItemModel);

        LOGGER.debug("Registered models");
    }

    private static void registerItemModel(final Item item) {
        Preconditions.checkNotNull(item, "Item cannot be null!");
        final ResourceLocation registryName = item.getRegistryName();
        Preconditions.checkNotNull(registryName, "Item Registry Name cannot be null!");
        ModelLoader.setCustomModelResourceLocation(item, 0, new ModelResourceLocation(registryName, DEFAULT_VARIANT));
    }

    private static void registerItemBlockModel(final Block block) {
        Preconditions.checkNotNull(block, "Block cannot be null!");
        final ResourceLocation registryName = block.getRegistryName();
        Preconditions.checkNotNull(registryName, "Block Registry Name cannot be null!");
        if (block instanceof IFluidBlock) registerFluidModel((IFluidBlock) block);
        else
            ModelLoader.setCustomModelResourceLocation(Item.getItemFromBlock(block), 0, new ModelResourceLocation(registryName, DEFAULT_VARIANT));
    }

    private static void registerFluidModel(IFluidBlock fluidBlock) {
        Item item = Item.getItemFromBlock((Block) fluidBlock);
        ModelBakery.registerItemVariants(item);
        ModelResourceLocation modelResourceLocation = new ModelResourceLocation(FLUID_MODEL_PATH, fluidBlock.getFluid().getName());
        ModelLoader.setCustomMeshDefinition(item, stack -> modelResourceLocation);
        ModelLoader.setCustomStateMapper((Block) fluidBlock, new StateMapperBase() {
            @Override
            protected ModelResourceLocation getModelResourceLocation(@Nonnull IBlockState p_178132_1_) {
                return modelResourceLocation;
            }
        });
    }

    @SubscribeEvent(priority = EventPriority.NORMAL, receiveCanceled = true)
    public void onFogDensityEvent(EntityViewRenderEvent.FogDensity event) {
        event.setDensity(0.0001F);
        if (event.getEntity().isInsideOfMaterial(ModMaterials.MOLTEN_GLASS)) event.setDensity(1F);
    }

    @SubscribeEvent(priority = EventPriority.NORMAL, receiveCanceled = true)
    public void onFogColorsEvent(EntityViewRenderEvent.FogColors event) {
        if (event.getEntity().isInsideOfMaterial(ModMaterials.MOLTEN_GLASS)) {
            event.setRed(COLOR_MOLTEN_GLASS.getRed());
            event.setGreen(COLOR_MOLTEN_GLASS.getGreen());
            event.setBlue(COLOR_MOLTEN_GLASS.getBlue());
        }
    }
}

 

Posted
22 minutes ago, DiamondMiner88 said:

No, how do i do that?

I placed them in my ClientEventSubscriber

  Reveal hidden contents


package tk.diamondbuildz.mod.character.client;

import com.google.common.base.Preconditions;
import net.minecraft.block.Block;
import net.minecraft.block.state.IBlockState;
import net.minecraft.client.renderer.block.model.ModelBakery;
import net.minecraft.client.renderer.block.model.ModelResourceLocation;
import net.minecraft.client.renderer.block.statemap.StateMapperBase;
import net.minecraft.item.Item;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.client.event.EntityViewRenderEvent;
import net.minecraftforge.client.event.ModelRegistryEvent;
import net.minecraftforge.client.model.ModelLoader;
import net.minecraftforge.fluids.IFluidBlock;
import net.minecraftforge.fml.common.Mod.EventBusSubscriber;
import net.minecraftforge.fml.common.eventhandler.EventPriority;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import net.minecraftforge.fml.common.registry.ForgeRegistries;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import tk.diamondbuildz.mod.character.reference.ModMaterials;

import javax.annotation.Nonnull;
import java.awt.*;

import static net.minecraftforge.fml.relauncher.Side.CLIENT;
import static tk.diamondbuildz.mod.character.reference.Reference.FLUID_MODEL_PATH;
import static tk.diamondbuildz.mod.character.reference.Reference.MOD_ID;

/**
 * Subscribe to events that should be handled on the PHYSICAL CLIENT in this class
 *
 * @author Diamond
 */
@EventBusSubscriber(modid = MOD_ID, value = CLIENT)
public final class ClientEventSubscriber {

    private static final Logger LOGGER = LogManager.getLogger();
    private static final String DEFAULT_VARIANT = "normal";

    private static final Color COLOR_MOLTEN_GLASS = new Color(251, 143, 70);

    /**
     * Cycle through all block and items already registered, if ModId of the entry matches to my ModId, calls
     * {@link ClientEventSubscriber#registerItemBlockModel(Block)}
     * or
     * {@link ClientEventSubscriber#registerItemModel(Item)}
     */
    @SubscribeEvent
    public static void onRegisterModelsEvent(@Nonnull final ModelRegistryEvent event) {
        ForgeRegistries.BLOCKS.getValuesCollection().stream()
                .filter(block -> block.getRegistryName().getNamespace().equals(MOD_ID))
                .forEach(ClientEventSubscriber::registerItemBlockModel);

        ForgeRegistries.ITEMS.getValuesCollection().stream()
                .filter(block -> block.getRegistryName().getNamespace().equals(MOD_ID))
                .forEach(ClientEventSubscriber::registerItemModel);

        LOGGER.debug("Registered models");
    }

    private static void registerItemModel(final Item item) {
        Preconditions.checkNotNull(item, "Item cannot be null!");
        final ResourceLocation registryName = item.getRegistryName();
        Preconditions.checkNotNull(registryName, "Item Registry Name cannot be null!");
        ModelLoader.setCustomModelResourceLocation(item, 0, new ModelResourceLocation(registryName, DEFAULT_VARIANT));
    }

    private static void registerItemBlockModel(final Block block) {
        Preconditions.checkNotNull(block, "Block cannot be null!");
        final ResourceLocation registryName = block.getRegistryName();
        Preconditions.checkNotNull(registryName, "Block Registry Name cannot be null!");
        if (block instanceof IFluidBlock) registerFluidModel((IFluidBlock) block);
        else
            ModelLoader.setCustomModelResourceLocation(Item.getItemFromBlock(block), 0, new ModelResourceLocation(registryName, DEFAULT_VARIANT));
    }

    private static void registerFluidModel(IFluidBlock fluidBlock) {
        Item item = Item.getItemFromBlock((Block) fluidBlock);
        ModelBakery.registerItemVariants(item);
        ModelResourceLocation modelResourceLocation = new ModelResourceLocation(FLUID_MODEL_PATH, fluidBlock.getFluid().getName());
        ModelLoader.setCustomMeshDefinition(item, stack -> modelResourceLocation);
        ModelLoader.setCustomStateMapper((Block) fluidBlock, new StateMapperBase() {
            @Override
            protected ModelResourceLocation getModelResourceLocation(@Nonnull IBlockState p_178132_1_) {
                return modelResourceLocation;
            }
        });
    }

    @SubscribeEvent(priority = EventPriority.NORMAL, receiveCanceled = true)
    public void onFogDensityEvent(EntityViewRenderEvent.FogDensity event) {
        event.setDensity(0.0001F);
        if (event.getEntity().isInsideOfMaterial(ModMaterials.MOLTEN_GLASS)) event.setDensity(1F);
    }

    @SubscribeEvent(priority = EventPriority.NORMAL, receiveCanceled = true)
    public void onFogColorsEvent(EntityViewRenderEvent.FogColors event) {
        if (event.getEntity().isInsideOfMaterial(ModMaterials.MOLTEN_GLASS)) {
            event.setRed(COLOR_MOLTEN_GLASS.getRed());
            event.setGreen(COLOR_MOLTEN_GLASS.getGreen());
            event.setBlue(COLOR_MOLTEN_GLASS.getBlue());
        }
    }
}

 

Well I am not an expert, but you can do that using debugger, orrr I always do that by simply putting

System.out.println("YAY It was called, so it's working!");

inside the method I wanna check.
I would suggest putting two checks - before if and after if - so you will get double result - check if your event is actually working (is it being called) and check if entity actually is inside that material, so you will be sure that your if works correctly.

Posted

Well, if you need to check, just do the getRed/Green/Blue method and see what it returns. And if you need to convert your RGB to a value between 0-1 range, it is as simple as dividing by 255.

Posted (edited)
48 minutes ago, Krevik said:

System.out.println("YAY It was called, so it's working!");

Tried that in both Events returned nothing in console, Im going to try LOGGER.debug instead.

 

Edited by DiamondMiner88
Posted

Hmmm.... could there be a problem with your events not being static? To be honest, not sure what the difference is between a static and non-static event is (I know the difference between static fields and methods). 

Posted
33 minutes ago, DiamondMiner88 said:

Tried that in both Events returned nothing in console, Im going to try LOGGER.debug instead.

 

so your events are not being called actually. Maybe try changing event methods to static?

Posted (edited)

Ok That fixed it. My other event subscriptions are static, didn't notice that. Now the problem is that the color is not working.

How it looks when I'm not in the fluid:

Spoiler

2019-05-07_12_58_29.png.04d8923d207e87330e0f9e8766775a81.png

When i am in the fluid:

Spoiler

2019-05-07_12_58_51.png.37b14ff2399f58b97670dde76e6a00b2.png2019-05-07_12_58_48.png.eb246394c0febd9274f08530efdac4ad.png

What i have done now:

Spoiler

@SubscribeEvent(priority = EventPriority.NORMAL, receiveCanceled = true)
public static void onFogDensityEvent(EntityViewRenderEvent.FogDensity event) {
    event.setDensity(0.0000000000000000000001F);
    if (event.getEntity().isInsideOfMaterial(ModMaterials.MOLTEN_GLASS)) {
        event.setDensity(1F);
    }
}

@SubscribeEvent(priority = EventPriority.NORMAL, receiveCanceled = true)
public static void onFogColorsEvent(EntityViewRenderEvent.FogColors event) {
    if (event.getEntity().isInsideOfMaterial(ModMaterials.MOLTEN_GLASS)) {
        event.setRed(COLOR_MOLTEN_GLASS.getRed() / 255);
        event.setGreen(COLOR_MOLTEN_GLASS.getGreen() / 255);
        event.setBlue(COLOR_MOLTEN_GLASS.getBlue() / 255);
    }
}

private static final Color COLOR_MOLTEN_GLASS = new Color(251, 143, 70);

 

 

Edited by DiamondMiner88
Posted

By default the fog density mode would be linear. You would need to change it to exponental using GlStateManager in your density hook. I also believe that the density for lava is 2, not 1.

Posted
1 hour ago, V0idWa1k3r said:

fog density mode would be linear

What does that mean?

1 hour ago, V0idWa1k3r said:

change it to exponental using GlStateManager in your density hook

How do i do that? Density Hook? Whats that?

Posted
7 minutes ago, DiamondMiner88 said:

Density Hook? Whats that?

 

2 hours ago, DiamondMiner88 said:

public static void onFogDensityEvent(EntityViewRenderEvent.FogDensity event) {

 

7 minutes ago, DiamondMiner88 said:

How do i do that?

 

1 hour ago, V0idWa1k3r said:

using GlStateManager

To be more specifically GlStateManager.fogMode

Posted (edited)

I have done this in my density hook but it appears to have done nothing

GlStateManager.setFog(GlStateManager.FogMode.EXP);

I haven't finished the flow texture so i just set it to be white, here's how it looks:

Spoiler

2019-05-07_16_42_31.png.6f3e6467d3bfa64a676ffaf6041cadac.png

 

Edited by DiamondMiner88
Posted
6 hours ago, DiamondMiner88 said:

I have done this in my density hook but it appears to have done nothing


GlStateManager.setFog(GlStateManager.FogMode.EXP);

I haven't finished the flow texture so i just set it to be white, here's how it looks:

  Hide contents

2019-05-07_16_42_31.png.6f3e6467d3bfa64a676ffaf6041cadac.png

 

Hmmm maybe you need to experiment with fogStart and fogEnd parameters? 

            GlStateManager.fogStart(fogStartFloat-for e.g. 4f);
            GlStateManager.fogEnd(fogEndFloat for e.g. 40f);

 

Posted

Try doing 

GlStateManager.setFogDensity(float);

Look at what Minecraft uses for water (in net.minecraft.client.renderer.EntityRenderer):

Spoiler

private void setupFog(int startCoords, float partialTicks)
    {
        Entity entity = this.mc.getRenderViewEntity();
        this.setupFogColor(false);
        GlStateManager.glNormal3f(0.0F, -1.0F, 0.0F);
        GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
        IBlockState iblockstate = ActiveRenderInfo.getBlockStateAtEntityViewpoint(this.mc.world, entity, partialTicks);
        float hook = net.minecraftforge.client.ForgeHooksClient.getFogDensity(this, entity, iblockstate, partialTicks, 0.1F);
        if (hook >= 0) GlStateManager.setFogDensity(hook);
        else
        if (entity instanceof EntityLivingBase && ((EntityLivingBase)entity).isPotionActive(MobEffects.BLINDNESS))
        {
            float f1 = 5.0F;
            int i = ((EntityLivingBase)entity).getActivePotionEffect(MobEffects.BLINDNESS).getDuration();

            if (i < 20)
            {
                f1 = 5.0F + (this.farPlaneDistance - 5.0F) * (1.0F - (float)i / 20.0F);
            }

            GlStateManager.setFog(GlStateManager.FogMode.LINEAR);

            if (startCoords == -1)
            {
                GlStateManager.setFogStart(0.0F);
                GlStateManager.setFogEnd(f1 * 0.8F);
            }
            else
            {
                GlStateManager.setFogStart(f1 * 0.25F);
                GlStateManager.setFogEnd(f1);
            }

            if (GLContext.getCapabilities().GL_NV_fog_distance)
            {
                GlStateManager.glFogi(34138, 34139);
            }
        }
        else if (this.cloudFog)
        {
            GlStateManager.setFog(GlStateManager.FogMode.EXP);
            GlStateManager.setFogDensity(0.1F);
        }
  		// Water starts here
        else if (iblockstate.getMaterial() == Material.WATER)
        {
            GlStateManager.setFog(GlStateManager.FogMode.EXP);

            if (entity instanceof EntityLivingBase)
            {
                if (((EntityLivingBase)entity).isPotionActive(MobEffects.WATER_BREATHING))
                {
                    GlStateManager.setFogDensity(0.01F);
                }
                else
                {
                    GlStateManager.setFogDensity(0.1F - (float)EnchantmentHelper.getRespirationModifier((EntityLivingBase)entity) * 0.03F);
                }
            }
            else
            {
                GlStateManager.setFogDensity(0.1F);
            }
        }
  		// and ends here
        else if (iblockstate.getMaterial() == Material.LAVA)
        {
            GlStateManager.setFog(GlStateManager.FogMode.EXP);
            GlStateManager.setFogDensity(2.0F);
        }
        else
        {
            float f = this.farPlaneDistance;
            GlStateManager.setFog(GlStateManager.FogMode.LINEAR);

            if (startCoords == -1)
            {
                GlStateManager.setFogStart(0.0F);
                GlStateManager.setFogEnd(f);
            }
            else
            {
                GlStateManager.setFogStart(f * 0.75F);
                GlStateManager.setFogEnd(f);
            }

            if (GLContext.getCapabilities().GL_NV_fog_distance)
            {
                GlStateManager.glFogi(34138, 34139);
            }

            if (this.mc.world.provider.doesXZShowFog((int)entity.posX, (int)entity.posZ) || this.mc.ingameGUI.getBossOverlay().shouldCreateFog())
            {
                GlStateManager.setFogStart(f * 0.05F);
                GlStateManager.setFogEnd(Math.min(f, 192.0F) * 0.5F);
            }
            net.minecraftforge.client.ForgeHooksClient.onFogRender(this, entity, iblockstate, partialTicks, startCoords, f);
        }

        GlStateManager.enableColorMaterial();
        GlStateManager.enableFog();
        GlStateManager.colorMaterial(1028, 4608);
    }

 

 

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

    • Hello all. I'm currently grappling with the updateShape method in a custom class extending Block.  My code currently looks like this: The conditionals in CheckState are there to switch blockstate properties, which is working fine, as it functions correctly every time in getStateForPlacement.  The problem I'm running into is that when I update a state, the blocks seem to call CheckState with the position of the block which was changed updated last.  If I build a wall I can see the same change propagate across. My question thus is this: is updateShape sending its return to the neighbouring block?  Is each block not independently executing the updateShape method, thus inserting its own current position?  The first statement appears to be true, and the second false (each block is not independently executing the method). I have tried to fix this by saving the block's own position to a variable myPos at inception, and then feeding this in as CheckState(myPos) but this causes a worse outcome, where all blocks take the update of the first modified block, rather than just their neighbour.  This raises more questions than it answers, obviously: how is a different instance's variable propagating here?  I also tried changing it so that CheckState did not take a BlockPos, but had myPos built into the body - same problem. I have previously looked at neighbourUpdate and onNeighbourUpdate, but could not find a way to get this to work at all.  One post on here about updatePostPlacement and other methods has proven itself long superceded.  All other sources on the net seem to be out of date. Many thanks in advance for any help you might offer me, it's been several days now of trying to get this work and several weeks of generally trying to get round this roadblock.  - Sandermall
    • sorry, I might be stupid, but how do I open it? because the only options I have are too X out, copy it, which doesn't work and send crash report, which doesn't show it to me, also, sorry for taking so long.
    • Can you reproduce this with version 55.0.21? A whole lot of plant placement issues were just fixed in this PR.
    • Necro'ing that thread to ask if you found a solution ? I'm encountering the same crash on loading the world. I created the world in Creative to test my MP, went into survival to test combat, died, crashed on respawn and since then crash on loading the world. Deactivating Oculus isn't fixing it either, and I don't have Optifine (Twilight forest is incompatible)
  • Topics

×
×
  • Create New...

Important Information

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