Jump to content

Recommended Posts

Posted

I understand the Json files, I understand how to make blocks, and now I want to know how to make metadata! I have no idea where to start so if you guys could help me out here I'd really appreciate it!

I am on my journey of making a remake of matmos, as explained here.

Posted

Show what you have tried.

If my post helped you, please press that "Thank You"-button to show your appreciation.

 

Also if you don't know Java, I would suggest you read the official tutorials by Oracle to get an idea of how to do this. Thanks, and good modding!

 

Also if you haven't, set up a Git repo for your mod not only for convinience but also to make it easier to help you.

Posted

Well, I'm not exactly sure where to start when I try... The only thing I have really tried is this:

 

blockstates/present.json

{
    "variants": {
        "type=white": { "model":"tutorial:block_properties_white" },
        "type=black": { "model":"tutorial:block_properties_black" }
    }
}

 

And that didn't really work out so I am not sure what to do... I just need some help starting and understanding what I need to do. I've looked up tutorials but they are all outdated so...

I am on my journey of making a remake of matmos, as explained here.

Posted

Show your block code.

If my post helped you, please press that "Thank You"-button to show your appreciation.

 

Also if you don't know Java, I would suggest you read the official tutorials by Oracle to get an idea of how to do this. Thanks, and good modding!

 

Also if you haven't, set up a Git repo for your mod not only for convinience but also to make it easier to help you.

Posted

I'll show you everything why not...

 

Blocks/present.java

 

package com.fire.christmastime.Blocks;

import com.fire.christmastime.Reference;

import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.creativetab.CreativeTabs;

public class present extends Block {

public present(Material materialIn, String name, CreativeTabs tab) {
	super(materialIn);
	this.setUnlocalizedName(name);
	this.setRegistryName(Reference.MOD_ID, name);
	this.setCreativeTab(tab);

	this.setLightOpacity(4);
	this.setHarvestLevel("axe", 0);
	this.setHardness(0.2F);
}

}

 

InitBlocks.java

package com.fire.christmastime.Init;

import com.fire.christmastime.Blocks.present;

import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.client.renderer.block.model.ModelResourceLocation;
import net.minecraft.item.Item;
import net.minecraft.item.ItemBlock;
import net.minecraftforge.client.model.ModelLoader;
import net.minecraftforge.fml.common.registry.GameRegistry;

public class InitBlocks {

public static Block present;

public static void Create(){
	present = new present(Material.WOOD, "present", InitCreativeTabs.christmas_time_tab);
	Register();
}

private static void Register(){
	RegisterBlock(present);
}

public static void Render(){
	RenderItem(Item.getItemFromBlock(present));
}

private static void RenderItem(Item item){
	ModelLoader.setCustomModelResourceLocation(item, 0, new ModelResourceLocation(item.getRegistryName(), "inventory"));
}

private static void RegisterBlock(Block block){
	GameRegistry.register(block);
	GameRegistry.register(new ItemBlock(block).setRegistryName(block.getRegistryName()));
}

}

 

MainRegistry.java

package com.fire.christmastime;

import org.apache.logging.log4j.Logger;

import com.fire.christmastime.Init.InitBlocks;
import com.fire.christmastime.Init.InitItems;
import com.fire.christmastime.Proxy.CommonProxy;

import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.common.Mod.EventHandler;
import net.minecraftforge.fml.common.Mod.Instance;
import net.minecraftforge.fml.common.SidedProxy;
import net.minecraftforge.fml.common.event.FMLInitializationEvent;
import net.minecraftforge.fml.common.event.FMLPostInitializationEvent;
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;

@Mod(modid = Reference.MOD_ID, name = Reference.NAME, version = Reference.VERSION)

public class MainRegistry {

@Instance(Reference.MOD_ID)
public static MainRegistry instance;

@SidedProxy(clientSide = Reference.CLIENT_PROXY, serverSide = Reference.SERVER_PROXY)
public static CommonProxy proxy;

public static Logger logger;

@EventHandler
public void PreInit(FMLPreInitializationEvent event){
	logger = event.getModLog();
	InitItems.Create();
	InitBlocks.Create();
	proxy.Render();
}

@EventHandler
public void Init(FMLInitializationEvent event){

}

@EventHandler
public void PostInit(FMLPostInitializationEvent event){

}

}

 

Reference.java

package com.fire.christmastime;

public class Reference {

public static final String MOD_ID = "christmastime";
public static final String NAME = "Christmas Time";
public static final String VERSION = "Release 1.0.0";

public static final String CLIENT_PROXY = "com.fire.christmastime.Proxy.ClientProxy";
public static final String SERVER_PROXY = "com.fire.christmastime.Proxy.ServerProxy";

}

 

And image of my layout

https://gyazo.com/b171f1acfeb7bdf3be97165db0f26039

 

https://gyazo.com/5988210592561ba7c06755894903c14d

 

ClientProxy.java

package com.fire.christmastime.Proxy;

import com.fire.christmastime.Init.InitBlocks;
import com.fire.christmastime.Init.InitItems;

public class ClientProxy implements CommonProxy {

@Override
public void Render() {
	InitItems.Render();
	InitBlocks.Render();
}

}

I am on my journey of making a remake of matmos, as explained here.

Posted

1) Classes start with upper case

2) You're not defining any extra states in your block.. go look at all the examples in vanilla minecraft it's straight forward.

I do Forge for free, however the servers to run it arn't free, so anything is appreciated.
Consider supporting the team on Patreon

Posted

Go look at any of the Minecraft blocks that have a directional facing or are colored (e.g. wool, carpets)

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

Can you please explain to me how these work? I'm trying by best to understand then so I can do it in the future eventually without having to look it up.

 

 

package net.minecraft.block;

import java.util.List;
import net.minecraft.block.material.MapColor;
import net.minecraft.block.material.Material;
import net.minecraft.block.properties.IProperty;
import net.minecraft.block.properties.PropertyEnum;
import net.minecraft.block.state.BlockStateContainer;
import net.minecraft.block.state.IBlockState;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.item.EnumDyeColor;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;

public class BlockCarpet extends Block
{
    public static final PropertyEnum<EnumDyeColor> COLOR = PropertyEnum.<EnumDyeColor>create("color", EnumDyeColor.class);
    protected static final AxisAlignedBB CARPET_AABB = new AxisAlignedBB(0.0D, 0.0D, 0.0D, 1.0D, 0.0625D, 1.0D);

    protected BlockCarpet()
    {
        super(Material.CARPET);
        this.setDefaultState(this.blockState.getBaseState().withProperty(COLOR, EnumDyeColor.WHITE));
        this.setTickRandomly(true);
        this.setCreativeTab(CreativeTabs.DECORATIONS);
    }

    public AxisAlignedBB getBoundingBox(IBlockState state, IBlockAccess source, BlockPos pos)
    {
        return CARPET_AABB;
    }

    /**
     * Get the MapColor for this Block and the given BlockState
     */
    public MapColor getMapColor(IBlockState state)
    {
        return ((EnumDyeColor)state.getValue(COLOR)).getMapColor();
    }

    /**
     * Used to determine ambient occlusion and culling when rebuilding chunks for render
     */
    public boolean isOpaqueCube(IBlockState state)
    {
        return false;
    }

    public boolean isFullCube(IBlockState state)
    {
        return false;
    }

    public boolean canPlaceBlockAt(World worldIn, BlockPos pos)
    {
        return super.canPlaceBlockAt(worldIn, pos) && this.canBlockStay(worldIn, pos);
    }

    /**
     * Called when a neighboring block was changed and marks that this state should perform any checks during a neighbor
     * change. Cases may include when redstone power is updated, cactus blocks popping off due to a neighboring solid
     * block, etc.
     */
    public void neighborChanged(IBlockState state, World worldIn, BlockPos pos, Block blockIn)
    {
        this.checkForDrop(worldIn, pos, state);
    }

    private boolean checkForDrop(World worldIn, BlockPos pos, IBlockState state)
    {
        if (!this.canBlockStay(worldIn, pos))
        {
            this.dropBlockAsItem(worldIn, pos, state, 0);
            worldIn.setBlockToAir(pos);
            return false;
        }
        else
        {
            return true;
        }
    }

    private boolean canBlockStay(World worldIn, BlockPos pos)
    {
        return !worldIn.isAirBlock(pos.down());
    }

    @SideOnly(Side.CLIENT)
    public boolean shouldSideBeRendered(IBlockState blockState, IBlockAccess blockAccess, BlockPos pos, EnumFacing side)
    {
        return side == EnumFacing.UP ? true : (blockAccess.getBlockState(pos.offset(side)).getBlock() == this ? true : super.shouldSideBeRendered(blockState, blockAccess, pos, side));
    }

    /**
     * Gets the metadata of the item this Block can drop. This method is called when the block gets destroyed. It
     * returns the metadata of the dropped item based on the old metadata of the block.
     */
    public int damageDropped(IBlockState state)
    {
        return ((EnumDyeColor)state.getValue(COLOR)).getMetadata();
    }

    /**
     * returns a list of blocks with the same ID, but different meta (eg: wood returns 4 blocks)
     */
    @SideOnly(Side.CLIENT)
    public void getSubBlocks(Item itemIn, CreativeTabs tab, List<ItemStack> list)
    {
        for (int i = 0; i < 16; ++i)
        {
            list.add(new ItemStack(itemIn, 1, i));
        }
    }

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

    /**
     * Convert the BlockState into the correct metadata value
     */
    public int getMetaFromState(IBlockState state)
    {
        return ((EnumDyeColor)state.getValue(COLOR)).getMetadata();
    }

    protected BlockStateContainer createBlockState()
    {
        return new BlockStateContainer(this, new IProperty[] {COLOR});
    }
}

I am on my journey of making a remake of matmos, as explained here.

Posted

Metadata.

 

And it really isn't that hard:

1) Override

BlockStateContainer

:

This is where you define what properties your block has

@Override
protected BlockStateContainer createBlockState() {
	//These properties can be whatever, here you can see a custom one and a Directional
	return new BlockStateContainer(this, new IProperty[] {Props.AXEL_ORIENTATION, BlockHorizontal.FACING});
}

2) Override

getStateFromMeta

and

getMetaFromState

:

This is how you tell your block to convert between States/Properties and metadata (you're still limited to 4 bits)

	@Override
public int getMetaFromState(IBlockState state) {
	int axel = state.getValue(Props.AXEL_ORIENTATION).getOrdinal()<<2;
	int face = state.getValue(BlockHorizontal.FACING).getIndex() - 2;
	//bitwise magic to not make UP and DOWN take up an extra bit
	//I actually get 'UP' back in the axel orientation property, because it would be mutually exclusive 
	//with the other values,and I don't need 'DOWN'
	if(face < 0) face = 0;
	return axel | face;
}

@Override
public IBlockState getStateFromMeta(int meta) {
	int face = (meta & 3) + 2; //reverse bitwise magic
	return this.getDefaultState().withProperty(Props.AXEL_ORIENTATION, Props.AxelOrientation.values()[meta>>2]).withProperty(BlockHorizontal.FACING, EnumFacing.VALUES[face]);
}

3) Create a variants file. Look how I even handle two different variants:

{
    "forge_marker": 1,
    "defaults": {
        "textures": {
            "particle": "blocks/log_oak"
        },
        "model": "harderores:axel",
        "uvlock": true
    },
    "variants": {
        "normal": [{

        }],
        "inventory": [{
            
        }],
        "axel_orientation": {
            "none": {
                
            },
            "gears": {
                "model": "harderores:frame"
            },
            "hub": {
                
            },
            "up": {
                "x": 270
            }
        },
        "facing": {
            "north": {
                "y": 0
            },
            "east": {
                "y": 90
            },
            "south": {
                "y": 180
            },
            "west": {
                "y": 270
            }
        }
    }
}

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

So when I do this, lets say I have a present names 'red_ribbon_present', do I name the texture red_ribbon_present#color=black, or what special thing do I need to do to name it?

I am on my journey of making a remake of matmos, as explained here.

Posted

No.

You need a json file in the blockstates folder that is named "red_ribbon_present.json" and it contains a variant named "color" with a valie of "black."

 

"variants": {
    "color": {
        "black: {
            "textures": { ... }
        }
    }
}

 

The "..." here is where you tell the game where to find the new texture to use.  You can name it whatever you want.

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.

Guest
This topic is now closed to further replies.

Announcements



×
×
  • Create New...

Important Information

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