Jump to content
Search In
  • More options...
Find results that contain...
Find results in...

Help Understanding Stringbuilder Append


Nathansmash9000
 Share

Recommended Posts

I was looking through some code about textures, and I found these lines: 

StringBuilder builder = new StringBuilder();
builder.append(" \"all\": \"" + BaseMod.MODID + ":blocks/" + texture + "\"");

The variable`texture` is  an image file.

What I understand is that the first line declares a StringBuilder (I'm not really sure what that is). Then, the second line applies textures to all sides of the block because of the `all` part. I need help understanding this, and how would I change the code so that the second line only applies textures to the front side?

Link to comment
Share on other sites

Applying textures is done through JSON files ever since Minecraft 1.8

 

Normally, for blocks with specific "front" sides, you want your block to dynamically rotate depending on it's relative position to the player (most commonly face the player when placed).
For that, you need to work with BlockState's. The vanilla furnace is a good example, and the BlockFurnace class should show you how to use PropertyDirection to alter the BlockState.

 

As for the textures, you can look at the furnace.json located in forgeSrc-<mc.version>-<forge.version>.jar/assets/minecraft/models/block. Use your IDE to find that file.

 

This model.JSON file has to exist inside src/main/resources/assets/modid/models/block, and if needed, a blockstate.JSON has to exist inside src/main/resources/assets/modid/blockstates

 

The JSON files have to be completely lowercase in 1.11, and their names have to be identical to your block's RegistryName.

Edited by Matryoshika

Also previously known as eAndPi.

"Pi, is there a station coming up where we can board your train of thought?" -Kronnn

Published Mods: Underworld

Handy links: Vic_'s Forge events Own WIP Tutorials.

Link to comment
Share on other sites

You're misunderstanding that code. A StringBuilder is a kind of mutable string object. All that line of code does is put together a string from those components - the result is (almost*) equivalent to just using the + operator on string literals directly.

 

(*StringBuilder tutorial)

 

Simple model code is usually controlled entirely in the json model files. If you want more help understanding or adapting the code that you found, we need (lots) more context to understand what it's doing.

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
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.

 Share



×
×
  • Create New...

Important Information

By using this site, you agree to our Privacy Policy.