Jump to content

Recommended Posts

Posted (edited)

hi, im trying to create some subblocks. i wanted to use the same model and two different textures per type

the blocks are showing as purple and black instead of one sandstone and stone


Firstly this is my Blockstate JSON: file is called bs_sandstone
 

{
    "forge_marker": 1,
    "defaults": {
        "model": "myblocks:myblock",
        "uvlock": false
    },
    "variants": {
	"facing": {
  		"north": { "y": 180  },
	  	"south": { },
  	  	"east" : { "y" : 270 },
  	  	"west" : { "y" : 90 }
	},
	"inventory":    [{}],
	
	"type": {
  	    "sandstone"  : { "textures": { "0": "blocks/sandstone_top", "1": "blocks/sandstone_normal"} },
	    "stone"      : { "textures": { "0": "blocks/stone_slab_top", "1": "blocks/stone_slab_side"} }
	}
}

needs to have facing as i need it to be orientable

 

Next, this is my stone and sandstone model JSON,

as you can see below the model has 2 textures by default

Quote

        "0": "blocks/sandstone_top",
        "1": "blocks/sandstone_normal"

 

{    
    "parent": "block/block",
    "textures": {
        "0": "blocks/sandstone_top",
        "1": "blocks/sandstone_normal"
    },
    "display": {
        "gui": {
            "rotation": [ 30, 225, 0 ],
            "translation": [ 0, 0, 0],
            "scale":[ 0.625, 0.625, 0.625 ]
        },
        "ground": {
            "rotation": [ 0, 0, 0 ],
            "translation": [ 0, 3, 0],
            "scale":[ 0.25, 0.25, 0.25 ]
        },
        "fixed": {
            "rotation": [ 0, 0, 0 ],
            "translation": [ 0, 0, 0],
            "scale":[ 0.5, 0.5, 0.5 ]
        },
        "thirdperson_righthand": {
            "rotation": [ 75, 45, 0 ],
            "translation": [ 0, 2.5, 0],
            "scale": [ 0.375, 0.375, 0.375 ]
        },
        "firstperson_righthand": {
            "rotation": [ 0, 45, 0 ],
            "translation": [ 0, 0, 0 ],
            "scale": [ 0.40, 0.40, 0.40 ]
        },
        "firstperson_lefthand": {
            "rotation": [ 0, 225, 0 ],
            "translation": [ 0, 0, 0 ],
            "scale": [ 0.40, 0.40, 0.40 ]
        }
    },
    "elements": [
        {
            //blahh...
        }
    ]
}

 

Next is the item JSON, again all variants are the same except texture

{
	"parent": "myblocks/items/myblock",
	"textures": {
		"layer0": "blocks/sandstone_normal"
	}
}

 

This is my enum class for the block types:

public enum EnumBlockType implements IStringSerializable{
	STONE(0, "stone"),
	SANDSTONE(1,"sandstone"),
	SAND(2, "sand"),
	DIRT(3, "dirt");

	private final int id;
	private final String name;
	private static final EnumBlockType[] META_LOOKUP = new EnumBlockType[values().length];
	
	
	EnumBlockType(int id, String name) {
		this.id = id;
		this.name = name;
	}
	
	public static EnumBlockType byMetaData(int meta) {
		if(meta < 0 || meta >= META_LOOKUP.length) {
			meta = 0;
		}
		
		return META_LOOKUP[meta];
	}
	
	static {
		for(EnumBlockType type : values()) {
			META_LOOKUP[type.getId()] = type;
		}
	}
	
	@Override
	public String toString() {
		return getName();
	}

	public int getId() {
		return id;
	}

	@Override
	public String getName() {
		return name;
	}

}

 

This is my ModBlocks class where i create the block:

public class ModBlocks {

	public static BlockBase blockWithVariants = new MyCustomBlock("bs_sandstone", Material.ROCK,
			  2f, 0.75f, false,false,false,
			  BlockRenderLayer.SOLID, CreativeTabs.MATERIALS);
	
	public static List<Block> BLOCKS = new ArrayList<Block>();
	
    public static void register(RegistryEvent.Register<Block> event){
    	BLOCKS.add(blockWithVariants);
       
        for(Block block : BLOCKS){
            event.getRegistry().register(block);
        }
    }
   
    public static void registerItemBlocks(RegistryEvent.Register<Item> event) {
         for(Block block : BLOCKS){
                event.getRegistry().register(new ItemBlock(block)
                				   .setRegistryName(block.getRegistryName())
                				   .setMaxStackSize(64));
         } 
    }
   
    public static void registerModels() {
        blockWithVariants.registerItemModel(Item.getItemFromBlock(blockWithVariants));
    }
    

 

Finally, this is my MyCustomBlock class that each block uses:

public class MyCustomBlock extends BlockBase {

	public static final PropertyEnum<EnumBlockType> BLOCK_TYPE = PropertyEnum.<EnumBlockType>create("type", EnumBlockType.class);
	
	private static final AxisAlignedBB BOUNDING_BOX = new AxisAlignedBB(0f, 0f, 0f, 1f, 1f, 0.5f);

	boolean isFullBlock = false;
	boolean isFullCube = false;
	boolean isOpaqueCube = false;
	BlockRenderLayer blockLayer;
	
	
	
	public MyCustomBlock(String name, Material material, float hardness, float resistance, boolean isFullBlock, boolean isFullCube, boolean isOpaqueCube, BlockRenderLayer blockLayer, CreativeTabs tab) {
		super(material,name);
		
		this.isFullBlock = isFullBlock;
		this.isFullCube = isFullCube;
		this.isOpaqueCube = isOpaqueCube;
		this.blockLayer = blockLayer;
		setCreativeTab(tab);
		setUnlocalizedName(name);
		setHardness(hardness);
		setResistance(resistance);
		setDefaultState(this.blockState.getBaseState().withProperty(BlockHorizontal.FACING, EnumFacing.NORTH)
													  .withProperty(BLOCK_TYPE, EnumBlockType.SANDSTONE));
	}

	
    @Override
    public int damageDropped(IBlockState state){
    	EnumBlockType enumType = (EnumBlockType)state.getValue(BLOCK_TYPE);
        return enumType.getId();
    }
    
    
    @Override
    @SideOnly(Side.CLIENT)
    public void getSubBlocks(CreativeTabs tabs, NonNullList<ItemStack> list) {
    	EnumBlockType[] allTypes = EnumBlockType.values();
        for(EnumBlockType type : allTypes){
            list.add(new ItemStack(this, 1, type.getId()));
        }
    	super.getSubBlocks(tabs, list);
    }
    
	@Override
	public IBlockState getStateForPlacement(World world, BlockPos pos, EnumFacing facing, 
			float hitX, float hitY, float hitZ, int meta, EntityLivingBase placer) {
		// TODO getStateForPlacement is depreciated
		EnumBlockType type = EnumBlockType.byMetaData(meta);
		IBlockState state = super.getStateForPlacement(world,pos,facing,hitX,hitY,hitZ,meta,placer);
		return state.withProperty(BlockHorizontal.FACING, placer.getHorizontalFacing()).withProperty(BLOCK_TYPE, type);
	}
	
	@Override
	public int getMetaFromState(IBlockState state) {
		EnumBlockType type = (EnumBlockType)state.getValue(BLOCK_TYPE);
		return state.getValue(BlockHorizontal.FACING).getHorizontalIndex();
	}
	
	
	@Override
	public IBlockState getStateFromMeta(int meta) {
		EnumBlockType type = EnumBlockType.byMetaData(meta);
		return getDefaultState().withProperty(BlockHorizontal.FACING,EnumFacing.getHorizontal(meta));
	}
	
	@Override
	protected BlockStateContainer createBlockState() {
		//may not be like this...
		return new BlockStateContainer(this, new IProperty[] {BlockHorizontal.FACING, BLOCK_TYPE});
	}
	
	@Override
	public AxisAlignedBB getBoundingBox(IBlockState state, IBlockAccess source, BlockPos pos) {
		return BOUNDING_BOX;
	}

	@Override
	public void addCollisionBoxToList(IBlockState state, World world, BlockPos pos, 
									  AxisAlignedBB col, List<AxisAlignedBB> colList, Entity entity, boolean addColToList) {

		super.addCollisionBoxToList(pos,col,colList, BOUNDING_BOX);
	}
	
	@Override
	public boolean isFullCube(IBlockState state) {
		return isFullCube;
		//only for full cube blocks
	}	
	
	@Override
	public boolean isFullBlock(IBlockState state) {
		return isFullBlock;
		//only for full block blocks
	}

	@Override
	public boolean isOpaqueCube(IBlockState state) {
		return isOpaqueCube;
		//only for opaque blocks
	}
	
	@Override
	public BlockRenderLayer getBlockLayer() {
		return blockLayer;
		//change depending on type of block
	}
}

 

so the items are showing up in game, but just as the purple blocks and there seems to be more than i actually coded into the enum and the json (about 4)

Edited by syaak
Posted
9 hours ago, syaak said:

public static void registerModels() {
    blockWithVariants.registerItemModel(Item.getItemFromBlock(blockWithVariants));
}

 

Where does this go? Show this code.

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.