Posted May 7, 20196 yr comment_341445 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);
May 7, 20196 yr comment_341449 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?
May 7, 20196 yr Author comment_341450 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()); } } }
May 7, 20196 yr comment_341452 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.
May 7, 20196 yr comment_341460 FogColors likely expects the colour values to be within a [0-1] float range, not a [0-255]byte one
May 7, 20196 yr comment_341464 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.
May 7, 20196 yr Author comment_341465 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 May 7, 20196 yr by DiamondMiner88
May 7, 20196 yr comment_341466 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).
May 7, 20196 yr comment_341469 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?
May 7, 20196 yr comment_341470 Just now, Krevik said: Maybe try changing event methods to static? That is what I just said....
May 7, 20196 yr Author comment_341492 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 When i am in the fluid: Spoiler 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 May 7, 20196 yr by DiamondMiner88
May 7, 20196 yr Author comment_341502 Ok Fixed that. Didn't know they had a difference. When I'm in the liquid now this happens: The clouds and horizon is the color i want to be, but blocks appear to be the same color, no difference.
May 7, 20196 yr comment_341505 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.
May 7, 20196 yr Author comment_341513 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?
May 7, 20196 yr comment_341514 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
May 7, 20196 yr Author comment_341515 Assuming GlStateManager is a class, I can't find it. Doesen't show an option to import it. Im using IntelliJ Edited May 7, 20196 yr by DiamondMiner88
May 7, 20196 yr comment_341516 net.minecraft.client.renderer.GlStateManager. If you don't have this class then you are using 1.6 or lower. Or your setup is broken.
May 7, 20196 yr Author comment_341519 The font on this forum made me think that was a uppercase i not a lowercase L. Oops. Its GlStateManager.setFog(FogMode mode) Its it FogMode.EXP or FogMode.EXP2
May 7, 20196 yr comment_341520 Vanilla uses simple exponent for a lava fog I believe. It uses exp2 for water though. Play around with it to see which function suits you
May 7, 20196 yr Author comment_341538 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 Edited May 7, 20196 yr by DiamondMiner88
May 8, 20196 yr comment_341579 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 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);
May 8, 20196 yr comment_341615 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); }
May 8, 20196 yr comment_341616 56 minutes ago, DiamondMiner88 said: Nope, didn't do anything. Whow your code.
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.