Jump to content

Recommended Posts

Posted

I have been trying to figure out how to have a block choose a random texture. I did some looking around and found that Botania's Elf Glass does what I have been trying to do. So, I tried what I saw and it does not seem to work.

 

{
  "forge_marker": 1,
  "defaults": {
    "model": "minecraft:cube_all",
    "transform": "forge:default-block"
  },
  "variants": {
    "normal": [
      { "textures": { "all": "botania:blocks/elfGlass0" } },
      { "textures": { "all": "botania:blocks/elfGlass1" } },
      { "textures": { "all": "botania:blocks/elfGlass2" } },
      { "textures": { "all": "botania:blocks/elfGlass3" } }
    ]
  }
}

 

{
  "forge_marker": 1,
  "defaults": {
    "model": "minecraft:cube_all",
    "transform": "forge:default-block"
  },
  "variants": {
    "type": {
      "biotic": [
        { "textures": { "all": "nex:blocks/netherrack_biotic0" } },
        { "textures": { "all": "nex:blocks/netherrack_biotic1" } },
        { "textures": { "all": "nex:blocks/netherrack_biotic2" } },
        { "textures": { "all": "nex:blocks/netherrack_biotic3" } }
      ],
      "burnt": {
        "textures": [
          { "textures": { "all": "nex:blocks/netherrack_burnt0" } },
          { "textures": { "all": "nex:blocks/netherrack_burnt1" } },
          { "textures": { "all": "nex:blocks/netherrack_burnt2" } },
          { "textures": { "all": "nex:blocks/netherrack_burnt3" } }
        ]
      },
      "frozen": {
        "textures": [
          { "textures": { "all": "nex:blocks/netherrack_frozen0" } },
          { "textures": { "all": "nex:blocks/netherrack_frozen1" } },
          { "textures": { "all": "nex:blocks/netherrack_frozen2" } },
          { "textures": { "all": "nex:blocks/netherrack_frozen3" } }
        ]
      }
    }
  }
}

Posted

I will logically approach this:

 

There is World.

In World there is 3D array of data.

Each data entry in said 3D array represents "what is on given x/y/z".

The data consists of:

* ID pointing at right Block (singleton) in registry.

* Metadata constructed by 4 bits (e.g: 0001, 1010, 0011, etc.)

4 bits gives you 16 permutations so you can save 16 (0-15) different variants for given x/y/z. If you need more - you need TileEntity.

 

Now - you are already taking up 2 of 4 bits by defining "biotic", "burnt", "frozen" - which are said block variants.

 

Now - think: Is it possible to randomly assign texture to x/y/z without saving it anywhere?

SPOILER ALERT: It's not.

So where would you save it? In metadata (as long as 4 bits is enough).

 

Now - since you still have 2 of 4 bits to spare you can use them to fit exactly 4 different texture variants.

xx00

xx01

xx10

xx11

(x - reserved for "biotic", "burnt", "frozen" and remaining 2 for textures)

 

How to randomly assign it? Place block with randomly picked metadata in x/y/z. You need it to be random when generating? Do the same, just during world generation.

1.7.10 is no longer supported by forge, you are on your own.

Posted

Actually, you can.

Pick a random texture based on xyz coordinates.

You'd have to reencode this as a non-saving property, but:

https://github.com/Draco18s/HarderStuff/blob/master/src/main/java/com/draco18s/hazards/block/BlockUnstableStone.java#L173-180

 

That code is for more than 4 textures, but I worked out a really good distribution so it is very hard to notice any repeating patterns.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Posted

...

 

It's entirely possible to set multiple models for a single variant in a blockstates file and have one selected at random every time the block is rendered; look at vanilla's grass blockstates file for an example.

 

Forge's blockstates format also supports this, I'm not sure why it's not working for the OP.

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.

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



×
×
  • Create New...

Important Information

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