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



×
×
  • Create New...

Important Information

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