Jump to content
  • Home
  • Files
  • Docs
Topics
  • All Content

  • This Topic
  • This Forum

  • Advanced Search
  • Existing user? Sign In  

    Sign In



    • Not recommended on shared computers


    • Forgot your password?

  • Sign Up
  • All Activity
  • Home
  • Mod Developer Central
  • Modder Support
  • Having some issues with block transparency/opacity
Currently Supported: 1.16.X (Latest) and 1.15.X (LTS)
Sign in to follow this  
Followers 1
DonutPixel

Having some issues with block transparency/opacity

By DonutPixel, November 28, 2020 in Modder Support

  • Reply to this topic
  • Start new topic

Recommended Posts

DonutPixel    0

DonutPixel

DonutPixel    0

  • Tree Puncher
  • DonutPixel
  • Members
  • 0
  • 4 posts
Posted November 28, 2020

I'm a developer by trade but just recently picked up Java/Minecraft Modding, so I'm still relatively new to this.

 

I'm trying to replicate the Dark Glass block from the Extra Utilities mod. I have the block rendering in the game, however, when placed, all adjacent blocks are missing their textures and show a gap in the world. This can be fixed by adding

.notSolid()

to the properties of the block, but at that point, the block lets light through. My desired effect is to have a translucent block (think stained glass but darker) that you can see through, but that doesn't let light through. 

Here's my code for the Block's class:

public class DarkGlassBlock extends Block {
    public DarkGlassBlock() {
        super(Properties.create(Material.GLASS)
                .hardnessAndResistance(1.0f, 50.0f)
                .sound(SoundType.GLASS)
                .harvestLevel(1)
                .harvestTool(ToolType.PICKAXE));
    }
}

And code to set the Render Layer to Translucent (in my FMLClientSetupEvent method):

RenderTypeLookup.setRenderLayer(RegistryHandler.DARK_GLASS_BLOCK.get(), RenderType.getTranslucent());

I also attached a screenshot that better demonstrates the issue.

 

Thanks in advance!

Side note -- Does anybody know of any updated tutorials for mod development? A lot of resources that seem great appear to be outdated for 1.16 development. 

Screenshot 2020-11-27 210516.png

  • Quote

Share this post


Link to post
Share on other sites

ChampionAsh5357    158

ChampionAsh5357

ChampionAsh5357    158

  • Dragon Slayer
  • ChampionAsh5357
  • Members
  • 158
  • 995 posts
Posted November 28, 2020

You can override certain methods to disable light passthrough. Specifically, setting Block#propagatesSkylightDown to false will disable light passing through the block iirc.

4 hours ago, DonutPixel said:

Does anybody know of any updated tutorials for mod development? A lot of resources that seem great appear to be outdated for 1.16 development. 

None that I would recommend. You can still use old tutorials like those of McJty with a little bit of care, but most of them should still be relevant. You can read this to get a small rundown of some changes:

 

  • Like 1
  • Quote

Share this post


Link to post
Share on other sites

TheGreyGhost    818

TheGreyGhost

TheGreyGhost    818

  • Reality Controller
  • TheGreyGhost
  • Members
  • 818
  • 3280 posts
Posted November 28, 2020
9 hours ago, DonutPixel said:

I'm a developer by trade but just recently picked up Java/Minecraft Modding, so I'm still relatively new to this.

 

I'm trying to replicate the Dark Glass block from the Extra Utilities mod. I have the block rendering in the game, however, when placed, all adjacent blocks are missing their textures and show a gap in the world. This can be fixed by adding


.notSolid()

to the properties of the block, but at that point, the block lets light through. My desired effect is to have a translucent block (think stained glass but darker) that you can see through, but that doesn't let light through. 

 

 

Side note -- Does anybody know of any updated tutorials for mod development? A lot of resources that seem great appear to be outdated for 1.16 development. 

 

Howdy

 

That might be tricky depending on what you're trying to achieve; it will make blocks under your glass appear dark?

 

It will probably help to dig through the vanilla code for notSolid and the vanilla calculations for light propagation, with any luck you will find a combination of properties that achieves what you want without messing up rendering effects like ambient occlusion or the rendering culling (the "see through portal" effect you discovered).

 

AbstractGlassBlock is a good place to start, glass already reduces the light passing through it by a certain amount (like water as well, from memory) so that may be a further clue.

 

Re tutorials-

You might find this tutorial project (working examples) useful; it's currently at 1.16.4

https://github.com/TheGreyGhost/MinecraftByExample

http://greyminecraftcoder.blogspot.com/2020/05/minecraft-by-example.html

 

-TGG

 

 

 

 

 

 

 

 

 

  • Like 1
  • Quote

Share this post


Link to post
Share on other sites

DonutPixel    0

DonutPixel

DonutPixel    0

  • Tree Puncher
  • DonutPixel
  • Members
  • 0
  • 4 posts
Posted November 28, 2020
8 hours ago, ChampionAsh5357 said:

You can override certain methods to disable light passthrough. Specifically, setting Block#propagatesSkylightDown to false will disable light passing through the block iirc.

None that I would recommend. You can still use old tutorials like those of McJty with a little bit of care, but most of them should still be relevant. You can read this to get a small rundown of some changes:

 

That guide is fantastic; thanks for the link!

2 hours ago, TheGreyGhost said:

Howdy

 

That might be tricky depending on what you're trying to achieve; it will make blocks under your glass appear dark?

 

It will probably help to dig through the vanilla code for notSolid and the vanilla calculations for light propagation, with any luck you will find a combination of properties that achieves what you want without messing up rendering effects like ambient occlusion or the rendering culling (the "see through portal" effect you discovered).

 

AbstractGlassBlock is a good place to start, glass already reduces the light passing through it by a certain amount (like water as well, from memory) so that may be a further clue.

 

Re tutorials-

You might find this tutorial project (working examples) useful; it's currently at 1.16.4

https://github.com/TheGreyGhost/MinecraftByExample

http://greyminecraftcoder.blogspot.com/2020/05/minecraft-by-example.html

 

-TGG 

 

 

 

 

 

 

 

 

 

I actually found your project a little earlier this morning; great stuff!

 

  • Quote

Share this post


Link to post
Share on other sites

DonutPixel    0

DonutPixel

DonutPixel    0

  • Tree Puncher
  • DonutPixel
  • Members
  • 0
  • 4 posts
Posted November 28, 2020 (edited)

If anyone was curious; I ended up actually finding source code for ExtraUtilities and found that the original developer was manually setting the opacity of the block to 255. That was done in 1.12.2, so the translation is a little different for 1.16.2. Anyways, I'd be mad if I came across this post as solved without an answer, so here's a detailed answer/explanation:

 

To make a block see-through, but not let light through, you must override the getOpacity method and make it return 255. This makes the block "opaque," while still allowing the player to see through.

 

To solve rendering culling issues, you must also override the isSideInvisible method, and make it return true only if the adjacentBlockState matches this block's state. 

 

In code, the following two overrides look like this:

@Override
public boolean isSideInvisible(BlockState state, BlockState adjacentBlockState, direction side) {
	// if the adjacentBlock is this block, side should be invisible. else, false
	return adjacentBlockState.isIn(this) ? true : false;
}

@Override
public int getOpacity(BlockState state, IBlockReader worldIn, BlockPos pos) {
	// NOTE: I'm not sure if this really has to be 255, or if there's a lower value at which this blocks all light.
	return 255;
}

Additionally, in the creation of the Block's properties, you should tack .notSolid() onto the list.

Edited November 28, 2020 by DonutPixel
  • Quote

Share this post


Link to post
Share on other sites

ChampionAsh5357    158

ChampionAsh5357

ChampionAsh5357    158

  • Dragon Slayer
  • ChampionAsh5357
  • Members
  • 158
  • 995 posts
Posted November 28, 2020
2 hours ago, DonutPixel said:

@OnlyIn(Dist.CLIENT)

Code Style 6. OnlyIn is used as a stripper to create the forge universal and server jars from one repository. Using it is more or less declaring that you didn't make sure your logic was only available to a certain physical side. In this case, it is completely unnecessary. 

  • Quote

Share this post


Link to post
Share on other sites

DonutPixel    0

DonutPixel

DonutPixel    0

  • Tree Puncher
  • DonutPixel
  • Members
  • 0
  • 4 posts
Posted November 28, 2020
5 minutes ago, ChampionAsh5357 said:

Code Style 6. OnlyIn is used as a stripper to create the forge universal and server jars from one repository. Using it is more or less declaring that you didn't make sure your logic was only available to a certain physical side. In this case, it is completely unnecessary. 

Thank you for the tip; I'll edit my code so as to not mislead other folks. 

  • Quote

Share this post


Link to post
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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  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.

    • Insert image from URL
×
  • Desktop
  • Tablet
  • Phone
Sign in to follow this  
Followers 1
Go To Topic Listing



  • Recently Browsing

    No registered users viewing this page.

  • Posts

    • Ironhead_
      Failure message: Missing License Information in file Mod File

      By Ironhead_ · Posted 16 minutes ago

      I'm playing on 1.14.4 and am only using the create mod, however I'm having to resort to adding JEI to see some recipes I'm stuck on. it doesn't let me use JEI without a licence
    • diesieben07
      (1.16.2) How do I use onPlayerTick?

      By diesieben07 · Posted 25 minutes ago

      This will immediately crash the game, there are not just server side entities. The fact that it doesn't mean your event handler is not even running. It is not running, because @EventBusSubscriber only works with static event handler methods.
    • diesieben07
      7 FPS with a GT 1030 + i5-4690 (1.16.3)

      By diesieben07 · Posted 27 minutes ago

      "Forge fix your terrible performance! this is horrible!" "Oh, I was using a mod that hugely increases render and world simulation load. sorry!"   Gotta love it how people jump to conclusions that with "just" 90 mods installed it must surely be Forge at fault.
    • XenoPyax
      I can't find any guide or wiki docs

      By XenoPyax · Posted 29 minutes ago

      Ah okay thanks
    • diesieben07
      [1.15.2] Change player name in Tab List (Player List)

      By diesieben07 · Posted 29 minutes ago

      No, it exists in 1.16.4 and also 1.15.2.   Make those Field fields static. You need to create the packet first and store it in a variable, so you can work with it. Don't immediately send it. You need to then get the list of AddPlayerData instances from the packet. For this you get the "players" field, using the reflection Field you have already. Then for those AddPlayerData instances you need to set their displayName field, again using reflection. You need to set it, because Minecraft never sends any custom display name to the client - even though it has the network infrastructure to do so (SPlayerListItemPacket). It always just sends null for the display name, even if a custom display name is set.
  • Topics

    • arkeN
      48
      Failure message: Missing License Information in file Mod File

      By arkeN
      Started October 11, 2020

    • e2rifia
      1
      (1.16.2) How do I use onPlayerTick?

      By e2rifia
      Started 40 minutes ago

    • PotatoEz1
      4
      7 FPS with a GT 1030 + i5-4690 (1.16.3)

      By PotatoEz1
      Started 2 hours ago

    • XenoPyax
      2
      I can't find any guide or wiki docs

      By XenoPyax
      Started 1 hour ago

    • Babatunde
      14
      [1.15.2] Change player name in Tab List (Player List)

      By Babatunde
      Started Thursday at 12:42 AM

  • Who's Online (See full list)

    • notesmee
    • FlashHUN
    • Ironhead_
    • XenoPyax
  • All Activity
  • Home
  • Mod Developer Central
  • Modder Support
  • Having some issues with block transparency/opacity
  • Theme

Copyright © 2019 ForgeDevelopment LLC · Ads by Longitude Ads LLC Powered by Invision Community