Jump to content

[1.8] Connected textures in 1.8?


NoonShadow

Recommended Posts

Ok, so I have looked all over the place for a tutorial on connected textures.  I have gone and looked at the default fence code,but, that makes little to no sense at all.  I have a reasonable amount of experience with programming and have gotten my hands dirty in model files and other aspects of item and block rendering, but this just seems to elude me.  Anyone got some insight or tutorials that I could go read?  Am I missing something insanely simple?

2b || !2b

Link to comment
Share on other sites

Most blocks store the value of each of their properties in the metadata, which is saved with the world; but some blocks have properties whose values are only determined at runtime and aren't saved in the metadata.

 

The individual connection properties of

BlockFence

are an example of these unsaved properties: they're not stored in the metadata, they're only determined by calling

Block#getActualState

. This returns an

IBlockState

with each connection property set based on blocks adjacent to the fence at the specified position (

BlockFence#canConnectTo

).

 

Minecraft calls this method before choosing the model to render at each position (though it's also called in a few other places), allowing you to choose the model based on information only available at specific positions like neighbouring blocks or values from a

TileEntity

.

 

I don't have any examples of connected textures using this system, but I do have a few other blocks that use it:

  • BuildCraft-like pipes that connect to adjacent pipes:
    [url=https://github.com/Choonster/TestMod3/tree/dc884dbe20a1fa803ef4d7be2fd7d3babfda3d8d/src/main/java/com/choonster/testmod3/block/pipe]Block[/url]

    classes, blockstates file

  • Coloured rotatable blocks with values stored in a
    TileEntity

    :

    • Coloured Rotatable:
      [url=https://github.com/Choonster/TestMod3/blob/dc884dbe20a1fa803ef4d7be2fd7d3babfda3d8d/src/main/java/com/choonster/testmod3/block/BlockColoredRotatable.java]Block[/url]

      ,

      [url=https://github.com/Choonster/TestMod3/blob/dc884dbe20a1fa803ef4d7be2fd7d3babfda3d8d/src/main/java/com/choonster/testmod3/tileentity/TileEntityColoredRotatable.java]TileEntity[/url]

      , blockstates file

    • Coloured Multi Rotatable:
      [url=https://github.com/Choonster/TestMod3/blob/dc884dbe20a1fa803ef4d7be2fd7d3babfda3d8d/src/main/java/com/choonster/testmod3/block/BlockColoredMultiRotatable.java]Block[/url]

      ,

      [url=https://github.com/Choonster/TestMod3/blob/dc884dbe20a1fa803ef4d7be2fd7d3babfda3d8d/src/main/java/com/choonster/testmod3/tileentity/TileEntityColoredMultiRotatable.java]TileEntity[/url]

      , blockstates file

Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.

Link to comment
Share on other sites

The code that I looked at made sense for the pipe, but does it have to be that complex for a simple block?  I am not sure that I completely understand how connected textures on a block would work.  Would I have to make separate textures for each scenario and have it change models when a neighbor changes?  All of the code that I can find the implements connected textures is for 1.7.10, so I have no clue how they did it to begin with.

2b || !2b

Link to comment
Share on other sites

I had a look at Chisel's 1.7.10 CTM code and it's pretty complex. For each face, it checks for connections to all eight blocks surrounding the face and chooses the appropriate sub-icon from  to render in each quarter of the face.

 

It's probably possible in 1.8, but it will be tricky to implement using the standard blockstate/model system. You'll probably need a model composed of eight 8x8x8 cubes (a full block is 16x16x16) and a property for each corner of each face with seven possible values:

  • not connected
  • connected on side A, connected on side B
  • connected on side A and B, connected on side A and diagonal, connected on side B and diagonal
  • connected on side A, B and diagonal

 

The value of this property will determine which texture you use for the corner. The individual cubes only need to have their outside faces defined, the inside faces don't need to be rendered.

 

Forge's blockstates format will come in handy here.

 

Using a custom model class may make things easier, but I don't know much about the system.

Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.

Link to comment
Share on other sites

Connected textures are one of the things that had me banging my head on a wall for some time...

 

For a simple block you could check out this class of mine:

 

https://github.com/ZeroNoRyouki/TestMod18/blob/master/src/main/java/zero/mods/testmod18/common/blocks/OrnatedEmeraldBlock.java

 

width=180 height=135http://s18.postimg.org/ndkwmm2ed/IMG_3012.jpg[/img]

 

All the work is done, as stated by others before me, in getActualState. There is no actual state saved in the in-world blocks metadata

 

The isAdjacentBlockOfMyType method is just an helper function that check if and adjacent block is of the kind of the calling block

 

Please note that this is just a test mod I use to try stuff so the code is not, uhm, production-grade :D

 

The blockstate file is an ugly mess:

 

https://github.com/ZeroNoRyouki/TestMod18/blob/master/src/main/resources/assets/testmod18/blockstates/ornatedEmeraldBlock.json

 

I've tried to use the forge blockstate variant when I worked on some multiblocks code but I didn't find it usefull in this situation.

 

Hope this could be of help

 

Z

 

Link to comment
Share on other sites

Ok, so the code worked great, I successfully created a block that connects textures, however, I am not sure how to define the inventory model.  I have an item model, but, I do not know how to get it to use that for the inventory model.  Any ideas?  Thanks so much ZeroNo, this has been a great help.

2b || !2b

Link to comment
Share on other sites

Don't know if it's the best way, but it works for me.

 

(preInit)
GameRegistry.registerBlock(yourBlock, yourBlockItem.class, yourBlockName);

(init)
Item yourBlockItem = GameRegistry.findItem(yourModId, yourBlockName);
Minecraft.getMinecraft().getRenderItem().getItemModelMesher().modelMesher.register(yourBlockItem , 0, new ModelResourceLocation("yourModId:yourBlockName", "inventory"));

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

    • Hello! I'm currently having issues while building a jar file for my Minecraft 1.18.2 Forge mod. I've attached a link to imgur below that holds two screenshots of the errors. I'm using Jetbrains IntelliJ IDEA 2024.1 and Gradle 8.4. This is my repo: Mod Repo When I was modding, I needed to build the mod in order to test the mod, which didn't work, as the first screenshot gives. It throws errors for each classes in the forge registry class (or whatever the hell that mess is) and is just generally confusing. Now I have deleted everything in my project folder and re-pulled the repo from github, which now gives the errors in the second image where all forge classes are not imported somehow. When I try to build it now, it just repeats the same errors in the first image. https://imgur.com/a/DYwSKqJ Please I need help desparately
    • [main/WARN] [net.minecraft.server.Main/]: Failed to load datapacks, can't proceed with server load. You can either fix your datapacks or reset to vanilla with --safeMode 8400java.util.concurrent.ExecutionException: com.google.gson.JsonParseException: Error loading registry data: No key name in MapLike[{"elements":[{"element":{"element_type":"minecraft:legacy_single_pool_element","location":"duneons:towns/village_creeperforest/town_center_01","processors":{"processors":[]},"projection":"rigid"},"weight":1}],"fallback":"minecraft:empty","forge:registry_name":"duneons:towns/village_creeperforest/town_centers"}] 8401at java.util.concurrent.CompletableFuture.reportGet(CompletableFuture.java:396) ~[?:?] 8402at java.util.concurrent.CompletableFuture.get(CompletableFuture.java:2073) ~[?:?] 8403at net.minecraft.server.Main.main(Main.java:182) ~[server-1.19.2-20220805.130853-srg.jar%23243!/:?] 8404at jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:?] 8405at jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77) ~[?:?] 8406at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:?] 8407at java.lang.reflect.Method.invoke(Method.java:568) ~[?:?] 8408at net.minecraftforge.fml.loading.targets.CommonServerLaunchHandler.lambda$launchService$0(CommonServerLaunchHandler.java:29) ~[fmlloader-1.19.2-43.3.13.jar%2367!/:?] 8409at cpw.mods.modlauncher.LaunchServiceHandlerDecorator.launch(LaunchServiceHandlerDecorator.java:30) [modlauncher-10.0.8.jar%2354!/:?] 8410at cpw.mods.modlauncher.LaunchServiceHandler.launch(LaunchServiceHandler.java:53) [modlauncher-10.0.8.jar%2354!/:?] 8411at cpw.mods.modlauncher.LaunchServiceHandler.launch(LaunchServiceHandler.java:71) [modlauncher-10.0.8.jar%2354!/:?] 8412at cpw.mods.modlauncher.Launcher.run(Launcher.java:106) [modlauncher-10.0.8.jar%2354!/:?] 8413at cpw.mods.modlauncher.Launcher.main(Launcher.java:77) [modlauncher-10.0.8.jar%2354!/:?] 8414at cpw.mods.modlauncher.BootstrapLaunchConsumer.accept(BootstrapLaunchConsumer.java:26) [modlauncher-10.0.8.jar%2354!/:?] 8415at cpw.mods.modlauncher.BootstrapLaunchConsumer.accept(BootstrapLaunchConsumer.java:23) [modlauncher-10.0.8.jar%2354!/:?] 8416at cpw.mods.bootstraplauncher.BootstrapLauncher.main(BootstrapLauncher.java:141) [bootstraplauncher-1.1.2.jar:?] 8417Caused by: com.google.gson.JsonParseException: Error loading registry data: No key name in MapLike[{"elements":[{"element":{"element_type":"minecraft:legacy_single_pool_element","location":"duneons:towns/village_creeperforest/town_center_01","processors":{"processors":[]},"projection":"rigid"},"weight":1}],"fallback":"minecraft:empty","forge:registry_name":"duneons:towns/village_creeperforest/town_centers"}] 8418at net.minecraft.core.RegistryAccess.m_206152_(RegistryAccess.java:211) ~[server-1.19.2-20220805.130853-srg.jar%23243!/:?] 8419at java.util.Optional.ifPresent(Optional.java:178) ~[?:?] 8420at net.minecraft.core.RegistryAccess.m_206159_(RegistryAccess.java:210) ~[server-1.19.2-20220805.130853-srg.jar%23243!/:?] 8421at net.minecraft.core.RegistryAccess.m_206171_(RegistryAccess.java:203) ~[server-1.19.2-20220805.130853-srg.jar%23243!/:?] 8422at net.minecraft.resources.RegistryOps.m_206817_(RegistryOps.java:32) ~[server-1.19.2-20220805.130853-srg.jar%23243!/:?] 8423at net.minecraft.resources.RegistryOps.m_206813_(RegistryOps.java:25) ~[server-1.19.2-20220805.130853-srg.jar%23243!/:?] 8424at net.minecraft.server.Main.lambda$main$2(Main.java:160) ~[server-1.19.2-20220805.130853-srg.jar%23243!/:?] 8425at net.minecraft.server.WorldLoader.m_214362_(WorldLoader.java:24) ~[server-1.19.2-20220805.130853-srg.jar%23243!/:?] 8426at net.minecraft.server.WorldStem.m_214415_(WorldStem.java:18) ~[server-1.19.2-20220805.130853-srg.jar%23243!/:?] 8427at net.minecraft.server.Main.lambda$main$3(Main.java:158) ~[server-1.19.2-20220805.130853-srg.jar%23243!/:?] 8428at net.minecraft.Util.m_214652_(Util.java:775) ~[server-1.19.2-20220805.130853-srg.jar%23243!/:?] 8429at net.minecraft.Util.m_214679_(Util.java:770) ~[server-1.19.2-20220805.130853-srg.jar%23243!/:?] 8430at net.minecraft.server.Main.main(Main.java:157) ~[server-1.19.2-20220805.130853-srg.jar%23243!/:?] 8431... 13 more 8432  
    • Try using 1.20.6-50.0.5, it just fixed an issue related to enchanting: https://github.com/MinecraftForge/MinecraftForge/commit/0e829630da67c91d2b5a91ea4b65eb033f868e76
    • I have no idea - maybe switch to a pre-configured modpack and use it as working base Then add new mods one by one
  • Topics

×
×
  • Create New...

Important Information

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