Jump to content

Recommended Posts

Posted

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

Posted

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

  On 11/28/2020 at 2:18 AM, 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. 

Expand  

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
Posted
  On 11/28/2020 at 2:18 AM, 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. 

 

Expand  

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
Posted
  On 11/28/2020 at 6:25 AM, 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:

 

Expand  

That guide is fantastic; thanks for the link!

  On 11/28/2020 at 11:40 AM, 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 

 

 

 

 

 

 

 

 

 

Expand  

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

 

Posted (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 by DonutPixel
Posted
  On 11/28/2020 at 4:48 PM, 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. 

Expand  

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

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

    • Hi everyone, I'm currently developing a Forge 1.21 mod for Minecraft and I want to display a custom HUD overlay for a minigame. My goal: When the game starts, all players should see an item/block icon (from the base game, not a custom texture) plus its name/text in the HUD – similar to how the bossbar overlay works. The HUD should appear centered above the hotbar (or at a similar prominent spot), and update dynamically (icon and name change as the target item changes). What I've tried: I looked at many online tutorials and several GitHub repos (e.g. SeasonHUD, MiniHUD), but most of them use NeoForge or Forge versions <1.20 that provide the IGuiOverlay API (e.g. implements IGuiOverlay, RegisterGuiOverlaysEvent). In Forge 1.21, it seems that neither IGuiOverlay nor RegisterGuiOverlaysEvent exist anymore – at least, I can't import them and they are missing from the docs and code completion. I tried using RenderLevelStageEvent as a workaround but it is probably not intended for custom HUDs. I am not using NeoForge, and switching the project to NeoForge is currently not an option for me. I tried to look at the original minecraft source code to see how elements like hearts, hotbar etc are drawn on the screen but I am too new to Minecraft modding to understand. What I'm looking for: What is the correct way to add a custom HUD element (icon + text) in Forge 1.21, given that the previous overlay API is missing? Is there a new recommended event, callback, or method in Forge 1.21 for custom HUD overlays, or is everyone just using a workaround? Is there a minimal open-source example repo for Forge 1.21 that demonstrates a working HUD overlay without relying on NeoForge or deprecated Forge APIs? My ideal solution: Centered HUD element with an in-game item/block icon (from the base game's assets, e.g. a diamond or any ItemStack / Item) and its name as text, with a transparent background rectangle. It should be visible to the players when the mini game is running. Easy to update the item (e.g. static variable or other method), so it can change dynamically during the game. Any help, code snippets, or up-to-date references would be really appreciated! If this is simply not possible right now in Forge 1.21, it would also help to know that for sure. Thank you very much in advance!
    • The simple answer is there is not an easy way. You would need to know how to program in Java, as well as at least some familiarity with how Forge works so you could port the differences. You would also need the sourcecode for the original mod, and permission from the author to modify it, if they did not use some sort of open source license. So it's not impossible, but it would take some effort, but doing so would open up a whole new world of possibilities for you!
    • Does it still crash if you remove holdmyitems? Looks like that mod doesn't work on a server as far as I can tell from the error.  
    • Crashes the server when trying to start. Error code -1. Log  
  • Topics

  • Who's Online (See full list)

    • There are no registered users currently online
×
×
  • Create New...

Important Information

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