Jump to content

Having some issues with block transparency/opacity


DonutPixel

Recommended Posts

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

Link to comment
Share on other sites

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
Link to comment
Share on other sites

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
Link to comment
Share on other sites

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!

 

Link to comment
Share on other sites

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
Link to comment
Share on other sites

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. 

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

    • Minecraft Version: 1.8-1.20.X Forge Version: All (Tested on 49.0.27, 11.14.4.1577 and some others) Steps to Reproduce: Setup a server with IPV6 only Setup a docker container with forge Try to connect to the Forge Server Description of issue: Hello, I am reaching out to seek your expertise within this forum to clarify a technical situation I am encountering, suspecting a potential issue related to Forge in a Docker environment, specifically in an IPv6 context. Initial Configuration: Debian 12 server, configured exclusively for IPv6, with Docker installed. Using the Docker image ghcr.io/pterodactyl/yolks:java_17, launching a Minecraft Vanilla server version 1.20.4 proceeds without any issues. Problem: The issue arises when deploying a Minecraft Forge server version 1.20.4 with the same Docker image (ghcr.io/pterodactyl/yolks:java_17), where connecting to the server becomes impossible. Notably, this issue does not occur when launching outside of Docker, where the server functions as expected. Hypothesis: This situation leads me to question the interaction between Forge and Docker, particularly in an IPv6-only configuration, despite several resolution attempts (testing with different versions of Forge, adjusting container network configurations (0.0.0.0, ::/0, and the server's ipv6), trials with various network settings, and modifications of Java options). Further testing was conducted with and without the use of the Pterodactyl game panel, unsuccessfully. The parameter -Djava.net.preferIPv4Stack=false also did not provide a solution. I tried to do the same things on multiple Minecraft server (include vanilla,spigot,fabric,sponge) and this work fine. The problem only happend with Forge. This issue seem to happend on all forge versions.   I appreciate your time and assistance in advance.
    • The game crashed whilst exception ticking world Error: java.lang.NullPointerException: Cannot invoke "net.minecraft.resources.ResourceLocation.equals(Object)" because "this.lootTableId" is null Error given is above. I was already playing for around 15 minutes and wasn't doing anything specific or even breaking anything when the crashed happened. This is update 1.19.2 forge: 43.2.23 Mod list: ESSENTIAL Mod (by SparkUniverse_) Traveler's Titles (Forge) (by YUNGNICKYOUNG) Resourceful Config (by ThatGravyBoat) Dynamic Lights (by atomicstrykergrumpy) TenzinLib (by CommodoreThrawn) Nature's Compass (by Chaosyr) Library Ferret - Forge (by jtl_elisa) Cold Sweat (by Mikul) Simple Voice Chat (by henkelmax) Waystones (by BlayTheNinth) Carry On (by Tschipp) [Let's Do] Meadow (by satisfy) Creeper Overhaul (by joosh_7889) AutoRegLib (by Vazkii) Moonlight Lib (by MehVahdJukaar) AppleSkin (by squeek502) Xaero's World Map (by xaero96) Rotten Creatures (by fusionstudiomc) YUNG's API (Forge) (by YUNGNICKYOUNG) Village Artifacts (by Lothrazar) Right Click, Get Crops (by TeamCoFH) Supplementaries (by MehVahdJukaar) Automatic Tool Swap (by MelanX) Better Third Person (by Socolio) Supplementaries Squared (by plantspookable) Traveler's Backpack (by Tiviacz1337) Caelus API (Forge/NeoForge) (by TheIllusiveC4) Creatures and Beasts (by joosh_7889) Architectury API (Fabric/Forge/NeoForge) (by shedaniel) Quark Oddities (by Vazkii) Origins (Forge) (by EdwinMindcraft) Villager Names (by Serilum) GeckoLib (by Gecko) Realistic Bees (by Serilum) Illuminations Forge 🔥 (by dimadencep) Serene Seasons (by TheAdubbz) Critters and Companions (by joosh_7889) [Let's Do] Bakery (by satisfy) Falling Leaves (Forge) (by Cheaterpaul) Jade 🔍 (by Snownee) Collective (by Serilum) TerraBlender (Forge) (by TheAdubbz) [Let's Do] API (by Cristelknight) Towns and Towers (by Biban_Auriu) More Villagers (by SameDifferent) Biomes O' Plenty (by Forstride) Goblin Traders (by MrCrayfish) Corpse (by henkelmax) Tree Harvester (by Serilum) Balm (Forge Edition) (by BlayTheNinth) Mouse Tweaks (by YaLTeR) Sound Physics Remastered (by henkelmax) Xaero's Minimap (by xaero96) Just Enough Items (JEI) (by mezz) Terralith (by Starmute) Quark (by Vazkii) [Let's Do] Vinery (by satisfy) [Let's Do] Candlelight (by satisfy) Repurposed Structures (Neoforge/Forge) (by telepathicgrunt) Dusty Decorations (by flint_mischiff) Immersive Armors [Fabric/Forge] (by Conczin) Serene Seasons Fix (by Or_OS) Shutup Experimental Settings! (by Corgi_Taco) Skin Layers 3D (Fabric/Forge) (by tr7zw)
    • Make sure Java is running via Nvidia GPU https://windowsreport.com/minecraft-not-using-gpu/  
    • Also make a test with other Custom Launchers like AT Launcher, MultiMC or Technic Launcher
    • Embeddium and valkyrienskies are not working together - remove one of these mods With removing Embeddium, also remove Oculus, TexTrue's Embeddium Options and Embeddium Extras Or use Rubidium instead
  • Topics

×
×
  • Create New...

Important Information

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