Jump to content

[1.10.2][UNSOLVED and CLOSED] Forge blockstate varient system


Recommended Posts

Posted

on another post i saw this in a blockstate json:

  "forge_marker": 1,
  "defaults": {
    "transform": "forge:default-block"
  }

what is it and how can i use it to have 1 block with all sorts of varients that use diffrent json models and how can i place said varients within the code to a

World

Doing stuff n' things

Posted

I still do not understand.. the documation did not help sadly.....

 

How can i make it use diffrent json models

and set them in the world through code..

 

Is there an example of what im trying to do somewhere?

 

Doing stuff n' things

Posted

// Variant code from BlockPlanks
public static final PropertyEnum<BlockPlanks.EnumType> VARIANT = PropertyEnum.<BlockPlanks.EnumType>create("variant", BlockPlanks.EnumType.class);

 

JSON example from documentation please read the comments.

{
    "forge_marker": 1,
    "defaults": {
        "textures": {
            "texture": "blocks/planks_oak",
            "wall": "blocks/planks_oak"
        },
        "model": "pressure_plate_up",
        "uvlock": true
    },
    "variants": {
        // mossy is a boolean property.
        "mossy": {
            "true": {
                // if true it changes the pressure plate from oak planks to mossy cobble
                "textures": {
                    "texture": "blocks/cobblestone_mossy"
                }
            },
            "false": {
                // change nothing. The entry has to be here to be generated for internal usage by minecraft
            }
        },
        // pillarcount is a property that determines how many pillar submodels we have. Ranges from 0 to 2
        "pillarcount": {
            0: {
                // no pillar. Remember, has to be there.
            },
            1: {
                // if it is true, it will add the wall model and combine it with the pressure plate
                "submodel": "wall_n"
            },
            2: {
                "textures": {
                    "wall": "blocks/cobblestone"
                },
                "submodel": {
                    "pillar1": { "model": "wall_n" },
                    "pillar2": { "model": "wall_n", "y": 90 }
                }
            }
        }
    }
}

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect.

Forge and vanilla BlockState generator.

Posted

// Variant code from BlockPlanks
public static final PropertyEnum<BlockPlanks.EnumType> VARIANT = PropertyEnum.<BlockPlanks.EnumType>create("variant", BlockPlanks.EnumType.class);

 

JSON example from documentation please read the comments.

{
    "forge_marker": 1,
    "defaults": {
        "textures": {
            "texture": "blocks/planks_oak",
            "wall": "blocks/planks_oak"
        },
        "model": "pressure_plate_up",
        "uvlock": true
    },
    "variants": {
        // mossy is a boolean property.
        "mossy": {
            "true": {
                // if true it changes the pressure plate from oak planks to mossy cobble
                "textures": {
                    "texture": "blocks/cobblestone_mossy"
                }
            },
            "false": {
                // change nothing. The entry has to be here to be generated for internal usage by minecraft
            }
        },
        // pillarcount is a property that determines how many pillar submodels we have. Ranges from 0 to 2
        "pillarcount": {
            0: {
                // no pillar. Remember, has to be there.
            },
            1: {
                // if it is true, it will add the wall model and combine it with the pressure plate
                "submodel": "wall_n"
            },
            2: {
                "textures": {
                    "wall": "blocks/cobblestone"
                },
                "submodel": {
                    "pillar1": { "model": "wall_n" },
                    "pillar2": { "model": "wall_n", "y": 90 }
                }
            }
        }
    }
}

 

 

listen... i am.... what do you call it...  dumb?.. ye, that's what i am....

i still do not understand how i can use it... its so confusing....

 

i think i need to also do something with this:

 

public static enum EnumType implements IStringSerializable
    {
        OAK(0, "oak", MapColor.WOOD),
        SPRUCE(1, "spruce", MapColor.OBSIDIAN),
        BIRCH(2, "birch", MapColor.SAND),
        JUNGLE(3, "jungle", MapColor.DIRT),
        ACACIA(4, "acacia", MapColor.ADOBE),
        DARK_OAK(5, "dark_oak", "big_oak", MapColor.BROWN);

        private static final BlockPlanks.EnumType[] META_LOOKUP = new BlockPlanks.EnumType[values().length];
        private final int meta;
        private final String name;
        private final String unlocalizedName;
        /** The color that represents this entry on a map. */
        private final MapColor mapColor;

        private EnumType(int metaIn, String nameIn, MapColor mapColorIn)
        {
            this(metaIn, nameIn, nameIn, mapColorIn);
        }

        private EnumType(int metaIn, String nameIn, String unlocalizedNameIn, MapColor mapColorIn)
        {
            this.meta = metaIn;
            this.name = nameIn;
            this.unlocalizedName = unlocalizedNameIn;
            this.mapColor = mapColorIn;
        }

        public int getMetadata()
        {
            return this.meta;
        }

        /**
         * The color which represents this entry on a map.
         */
        public MapColor getMapColor()
        {
            return this.mapColor;
        }

        public String toString()
        {
            return this.name;
        }

        public static BlockPlanks.EnumType byMetadata(int meta)
        {
            if (meta < 0 || meta >= META_LOOKUP.length)
            {
                meta = 0;
            }

            return META_LOOKUP[meta];
        }

        public String getName()
        {
            return this.name;
        }

        public String getUnlocalizedName()
        {
            return this.unlocalizedName;
        }

        static
        {
            for (BlockPlanks.EnumType blockplanks$enumtype : values())
            {
                META_LOOKUP[blockplanks$enumtype.getMetadata()] = blockplanks$enumtype;
            }
        }
    }

 

 

im really really confused on how i can take this to my advantage...

Doing stuff n' things

Posted

Basically you use the new BlockState system

// Code from BlockPlanks
    @SideOnly(Side.CLIENT)
    // Adds all blockstates to creative tab(s)
    public void getSubBlocks(Item itemIn, CreativeTabs tab, List<ItemStack> list)
    {
        for (BlockPlanks.EnumType blockplanks$enumtype : BlockPlanks.EnumType.values())
        {
            list.add(new ItemStack(itemIn, 1, blockplanks$enumtype.getMetadata()));
        }
    }

    /**
     * Convert the given metadata into a BlockState for this Block
     */
    public IBlockState getStateFromMeta(int meta)
    {
        return this.getDefaultState().withProperty(VARIANT, BlockPlanks.EnumType.byMetadata(meta));
    }

    /**
     * Get the MapColor for this Block and the given BlockState
     */
    // Just changes the color that will be displayed on minmaps for example
    public MapColor getMapColor(IBlockState state)
    {
        return ((BlockPlanks.EnumType)state.getValue(VARIANT)).getMapColor();
    }

    /**
     * Convert the BlockState into the correct metadata value
     */
    public int getMetaFromState(IBlockState state)
    {
        return ((BlockPlanks.EnumType)state.getValue(VARIANT)).getMetadata();
    }
    
    // Does exactly what it says
    protected BlockStateContainer createBlockState()
    {
        return new BlockStateContainer(this, new IProperty[] {VARIANT});
    }

 

This allows you to add different models to the base model on different blockstates. I assume, but don't quote me, but you may also be able to change the base model. I(t will also allow you to change the texture(s). And a plus side is you do it in just one file, so you still only need 3 JSONs for one block (Yeah still kinda upset about that...).

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect.

Forge and vanilla BlockState generator.

Posted

Basically you use the new BlockState system

// Code from BlockPlanks
    @SideOnly(Side.CLIENT)
    // Adds all blockstates to creative tab(s)
    public void getSubBlocks(Item itemIn, CreativeTabs tab, List<ItemStack> list)
    {
        for (BlockPlanks.EnumType blockplanks$enumtype : BlockPlanks.EnumType.values())
        {
            list.add(new ItemStack(itemIn, 1, blockplanks$enumtype.getMetadata()));
        }
    }

    /**
     * Convert the given metadata into a BlockState for this Block
     */
    public IBlockState getStateFromMeta(int meta)
    {
        return this.getDefaultState().withProperty(VARIANT, BlockPlanks.EnumType.byMetadata(meta));
    }

    /**
     * Get the MapColor for this Block and the given BlockState
     */
    // Just changes the color that will be displayed on minmaps for example
    public MapColor getMapColor(IBlockState state)
    {
        return ((BlockPlanks.EnumType)state.getValue(VARIANT)).getMapColor();
    }

    /**
     * Convert the BlockState into the correct metadata value
     */
    public int getMetaFromState(IBlockState state)
    {
        return ((BlockPlanks.EnumType)state.getValue(VARIANT)).getMetadata();
    }
    
    // Does exactly what it says
    protected BlockStateContainer createBlockState()
    {
        return new BlockStateContainer(this, new IProperty[] {VARIANT});
    }

 

This allows you to add different models to the base model on different blockstates. I assume, but don't quote me, but you may also be able to change the base model. I(t will also allow you to change the texture(s). And a plus side is you do it in just one file, so you still only need 3 JSONs for one block (Yeah still kinda upset about that...).

 

so this is whats happening:

brain: cmon you fudging idiot you did way more complex things than a stupid blockstate for multiple blocks!

me: shut up you know im stupid because of you!

brain: why cant you understand the simplest of things!?

me: for me its not simple!

 

and it goes for ever and ever...

i'd really really like to know the forge blockstates and i think it will help me a butt ton...  but i find it too hard for me to understand... i think ill just register each of the blocks i need for this structure seperately.....

annd it is a symetric shape so i'd have to register 4 blocks for each one but i can do some work on it....

Doing stuff n' things

Posted

Here let me go into a little bit more of a in depth example once again using the BlockPlanks code, anyone that sees something wrong in this please correct me because I have not messed around with it I am only going on intuition and what I have seen.

 

The Enum in BlockPlanks

 

    public static enum EnumType implements IStringSerializable
    {
        OAK(0, "oak", MapColor.WOOD),
        SPRUCE(1, "spruce", MapColor.OBSIDIAN),
        BIRCH(2, "birch", MapColor.SAND),
        JUNGLE(3, "jungle", MapColor.DIRT),
        ACACIA(4, "acacia", MapColor.ADOBE),
        DARK_OAK(5, "dark_oak", "big_oak", MapColor.BROWN);

        private static final BlockPlanks.EnumType[] META_LOOKUP = new BlockPlanks.EnumType[values().length];
        private final int meta;
        private final String name;
        private final String unlocalizedName;
        /** The color that represents this entry on a map. */
        private final MapColor mapColor;

        private EnumType(int metaIn, String nameIn, MapColor mapColorIn)
        {
            this(metaIn, nameIn, nameIn, mapColorIn);
        }

        private EnumType(int metaIn, String nameIn, String unlocalizedNameIn, MapColor mapColorIn)
        {
            this.meta = metaIn;
            this.name = nameIn;
            this.unlocalizedName = unlocalizedNameIn;
            this.mapColor = mapColorIn;
        }

        public int getMetadata()
        {
            return this.meta;
        }

        /**
         * The color which represents this entry on a map.
         */
        public MapColor getMapColor()
        {
            return this.mapColor;
        }

        public String toString()
        {
            return this.name;
        }

        public static BlockPlanks.EnumType byMetadata(int meta)
        {
            if (meta < 0 || meta >= META_LOOKUP.length)
            {
                meta = 0;
            }

            return META_LOOKUP[meta];
        }

        public String getName()
        {
            return this.name;
        }

        public String getUnlocalizedName()
        {
            return this.unlocalizedName;
        }

        static
        {
            for (BlockPlanks.EnumType blockplanks$enumtype : values())
            {
                META_LOOKUP[blockplanks$enumtype.getMetadata()] = blockplanks$enumtype;
            }
        }
    }

 

Just holds all of the data, like the metadata, an unlocalized name, and the Color for the map.

 

Now if I were to guess the JSON would go something like

 

{
    "forge_marker": 1,
    "defaults": {
        "textures": {
            "texture": "blocks/planks_oak",
            "wall": "blocks/planks_oak"
        },
        "model": "oak_planks",
        "uvlock": true
    },
    "variants": {
        // mossy is a boolean property.
        "oak": {
			"model": "oak_planks"
                "textures": {
                    "texture": "blocks/planks_oak"
                }
            },
	"birch": {
			"model": "birch_planks"
			"textures": {
				"texture": "blocks/planks_birch"
			}
		},
		"jungle": {
			"model": "jungle_planks"
			"textures": {
				"texture": "blocks/planks_jungle"
			}
		},
		"acacia": {
			"model": "acacia_planks"
			"textures": {
				"texture": "blocks/planks_acacia"
			}
		},
		"dark_oak": {
			"model": "dark_oak_planks"
			"textures": {
				"texture": "blocks/planks_dark_oak"
			}
		}
        }
    }
}

 

Though I may be wrong I didn't test this as said above.

 

Also the specific property used

 

// Uses an Enum you don't have to, but I makes the code look better in my opinion.
public static final PropertyEnum<BlockPlanks.EnumType> VARIANT = PropertyEnum.<BlockPlanks.EnumType>create("variant", BlockPlanks.EnumType.class);

 

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect.

Forge and vanilla BlockState generator.

Posted

Actually it would be:

 

},
    "variants": {
      "variant": {
        "oak": {
                "model": "oak_planks"
                "textures": {
                    "texture": "blocks/planks_oak"
                }
            },

 

The variant name (in this case "variant" because of the string passed to

PropertyEnum.<BlockPlanks.EnumType>create("variant", BlockPlanks.EnumType.class);

) creates a block, inside which you list all the variants associated with it.  Notice how "mossy" had a top-level block that contained both "true" and "false."

 

Of course, you should give your variant a better than than "variant" such as "wood_type."

 

I've got a two-property example here:

https://github.com/Draco18s/ReasonableRealism/blob/master/src/main/resources/assets/harderores/blockstates/axel.json

 

Though my enums are set up differently.

https://github.com/Draco18s/ReasonableRealism/blob/master/src/main/java/com/draco18s/hardlib/blockproperties/Props.java#L70

 

IMetaLookup being a custom interface to supply cleaner meta->enum and enum->meta conversions (there is no need for a

META_LOOKUP

array: Enum.values() already exists, as well as Enum#ordinal()

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

Actually it would be:

 

},
    "variants": {
      "variant": {
        "oak": {
			"model": "oak_planks"
                "textures": {
                    "texture": "blocks/planks_oak"
                }
            },

 

The variant name (in this case "variant" because of the string passed to

PropertyEnum.<BlockPlanks.EnumType>create("variant", BlockPlanks.EnumType.class);

) creates a block, inside which you list all the variants associated with it.  Notice how "mossy" had a top-level block that contained both "true" and "false."

 

Of course, you should give your variant a better than than "variant" such as "wood_type."

im not working now.. just got this in my email.. i plan to work on the mod later today... how can i place said variants within code? i have them in a structure that im doing for my mod and i only need them to be placed within code.. no play player placement...

Doing stuff n' things

Posted

You need to create the variant:

public static final PropertyEnum<BlockPlanks.EnumType> VARIANT = PropertyEnum.<BlockPlanks.EnumType>create("variant", BlockPlanks.EnumType.class);

 

Register it by overriding

protected BlockStateContainer createBlockState()

 

And finally translate between the states and meta by overriding

public IBlockState getStateFromMeta(int meta)

and

public int getMetaFromState(IBlockState state)

 

Do note that you're still limited to 16 possible values for metadata.  Blockstates aren't magic.

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

Actually it would be:

 

},
    "variants": {
      "variant": {
        "oak": {
                "model": "oak_planks"
                "textures": {
                    "texture": "blocks/planks_oak"
                }
            },

 

The variant name (in this case "variant" because of the string passed to

PropertyEnum.<BlockPlanks.EnumType>create("variant", BlockPlanks.EnumType.class);

) creates a block, inside which you list all the variants associated with it.  Notice how "mossy" had a top-level block that contained both "true" and "false."

 

Of course, you should give your variant a better than than "variant" such as "wood_type."

 

I've got a two-property example here:

https://github.com/Draco18s/ReasonableRealism/blob/master/src/main/resources/assets/harderores/blockstates/axel.json

 

Though my enums are set up differently.

https://github.com/Draco18s/ReasonableRealism/blob/master/src/main/java/com/draco18s/hardlib/blockproperties/Props.java#L70

 

IMetaLookup being a custom interface to supply cleaner meta->enum and enum->meta conversions (there is no need for a

META_LOOKUP

array: Enum.values() already exists, as well as Enum#ordinal()

Thanks i new i was missing something, glad it was something as simple as that as i was just stat8ng my hypothesis.

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect.

Forge and vanilla BlockState generator.

Posted

Do note that you're still limited to 16 possible values for metadata.  Blockstates aren't magic.

waaait really!?  awww man that ruined so much of my plans!  man this is really confusing stuff...

i think il just register blocks for each type and then, how can i use the orientable blocks? like a furnace for example... i want 1 block to have 4 possible directions and to be able to place them within code...

Doing stuff n' things

Posted

waaait really!?  awww man that ruined so much of my plans!  man this is really confusing stuff...

i think il just register blocks for each type and then, how can i use the orientable blocks? like a furnace for example... i want 1 block to have 4 possible directions and to be able to place them within code...

Just look at BlockFurnace try to wrap you mind around that, then have your models parent be block/orientable

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect.

Forge and vanilla BlockState generator.

Posted

waaait really!?  awww man that ruined so much of my plans!  man this is really confusing stuff...

i think il just register blocks for each type and then, how can i use the orientable blocks? like a furnace for example... i want 1 block to have 4 possible directions and to be able to place them within code...

Just look at BlockFurnace try to wrap you mind around that, then have your models parent be block/orientable

 

These blocks wont be containers.. Is there anything to do with

BlockDirectional

instead?

Doing stuff n' things

Posted

Do note that you're still limited to 16 possible values for metadata.  Blockstates aren't magic.

waaait really!?  awww man that ruined so much of my plans!  man this is really confusing stuff...

i think il just register blocks for each type and then, how can i use the orientable blocks? like a furnace for example... i want 1 block to have 4 possible directions and to be able to place them within code...

 

You can have more than 16 possible states, they just can't be stored in metadata.  It's either taken from the world or taken from the tile entity (using

getActualState()

)

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.

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

    • Reach Out To Rapid Digital: What sapp Info: +1 41 4 80 7 14 85 Email INFO: rap iddi gita lrecov ery @ exe cs. com Hello, my name is Jayson, and I’m 35 years old from the United Kingdom. My family and I recently endured an incredibly challenging experience that I wouldn’t wish on anyone. We became victims of a cryptocurrency investment fraud scheme that saw us lose a staggering $807,000 in USDT and Bitcoins. The fraudsters had created a convincing facade, and we were lured into investing, only to discover later that the platform was a complete scam. We were left devastated, not just financially, but emotionally, as we had trusted these people and believed in the legitimacy of the investment. After the initial shock wore off, we desperately searched for ways to recover the lost funds. It seemed like an impossible task, and we felt as though there was no hope. That’s when, by sheer luck, we stumbled across a post about Rapid Digital Recovery, a cryptocurrency and funds recovery organization with a proven track record in cybersecurity and fraud recovery. We decided to reach out to them, and from the first interaction, we were impressed with their professionalism and transparency. They explained the recovery process in detail and reassured us that they had the skills and expertise to track down the perpetrators and recover our funds. This gave us a renewed sense of hope, something we hadn’t felt in months. What truly stood out during our experience with Rapid Digital Recovery was their dedication to the recovery process. The team went above and beyond, using sophisticated tracking tools and cyber forensics to gather critical information. Within a matter of weeks, they had successfully located the funds and traced the scam back to the fraudsters responsible. They worked with the authorities to ensure the criminals were held accountable for their actions. To our relief, the team at Rapid Digital Recovery was able to recover every single penny we had lost. The funds were returned in full, and the sense of closure we felt was invaluable. We couldn’t have imagined such a positive outcome in the early stages of our recovery journey, and we are deeply grateful for the work they did. If you ever find yourself in a similar situation, I highly recommend contacting Rapid Digital Recovery. Their expertise, transparency, and dedication to their clients make them the go-to choice for anyone seeking to recover lost cryptocurrency or funds. They truly gave us back our financial future.  
    • This is my first time modding anything, so maybe just skill issue. I'm using Forge 54.0.12 and Temurin 21.0.5+11-LTS I wanted to create a custom keybind and to check whether it works I'd like to send a chat message. I tried using Minecraft.getInstance().player.sendSystemMessage(Component.literal("test")); but IntelliJ couldnt resolve sendSystemMessage(...). Since I saw people using it in earlier versions, I tried the same thing with 1.20.6(- 50.1.0), where it works fine, now I can't figure out if this is intentional and whether there are other options for sending chat messages. On that note, is there more documentation than https://docs.minecraftforge.net/en/1.21.x/? It seems very incomplete compared to something like the Oracle Java docs
    • Hi, i'm having this error and I wanna fix it. we try: -Reload drivers -Eliminate .minecraft -Eliminate Java -Restart launcher -Verify if minecraft is using gpu -Mods  in .minecraft is empty -Install the latest and recomended version of forge idk what i have to do, help me pls. the lastest log is: https://mclo.gs/WAMao8x  
    • Read the FAQ, Rule #2. (https://forums.minecraftforge.net/topic/125488-rules-and-frequently-asked-questions-faq/)  
  • Topics

  • Who's Online (See full list)

×
×
  • Create New...

Important Information

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