Jump to content

[1.8] Custom leaves missing block texures


krikke93

Recommended Posts

Hello everyone,

 

I'm very new (3 days) to modding and I'm trying to make a custom tree. I've got the logs to work fine, I just need the leaves. However, I know very little about Properties and Metadata and find them very complicated to understand.

I got the inventory item texture to work, but the in-world block texture won't show up. Here's what I have so far:

 

Custom Leaves Class

 
package com.krikke93.expansion.blocks;

import java.util.List;
import java.util.Random;

import net.minecraft.block.BlockLeaves;
import net.minecraft.block.BlockPlanks.EnumType;
import net.minecraft.block.properties.IProperty;
import net.minecraft.block.state.BlockState;
import net.minecraft.block.state.IBlockState;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Blocks;
import net.minecraft.init.Items;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.BlockPos;
import net.minecraft.util.EnumWorldBlockLayer;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;

import com.krikke93.expansion.ExpansionMod;

public class ExtraLeavesBlock extends BlockLeaves {

public ExtraLeavesBlock(String name) {
	this.setDefaultState(this.blockState.getBaseState().withProperty(CHECK_DECAY, Boolean.valueOf(true)).withProperty(DECAYABLE, Boolean.valueOf(true)));
	setUnlocalizedName(name);
	setCreativeTab(ExpansionMod.tabBlocks);
}

public Item getItemDropped(IBlockState state, Random rand, int fortune) {
	//return Item.getItemFromBlock(TreeOresBlocks.Saplings1);
	return null;
}

protected void dropApple(World worldIn, BlockPos pos, IBlockState state, int chance) {
	if (worldIn.rand.nextInt(chance) == 0) {
		spawnAsEntity(worldIn, pos, new ItemStack(Items.apple, 1, 0));
	}
}

public IBlockState getStateFromMeta(int meta) {
	return this.getDefaultState().withProperty(DECAYABLE, Boolean.valueOf((meta & 4) == 0)).withProperty(CHECK_DECAY, Boolean.valueOf((meta &  > 0));
}

public int getMetaFromState(IBlockState state) {
	byte b0 = 0;
	int i = b0;

	if (!((Boolean) state.getValue(DECAYABLE)).booleanValue()) {
		i |= 4;
	}

	if (((Boolean) state.getValue(CHECK_DECAY)).booleanValue()) {
		i |= 8;
	}

	return i;
}

protected BlockState createBlockState() {
	return new BlockState(this, new IProperty[] { CHECK_DECAY, DECAYABLE });
}

@Override
public List<ItemStack> onSheared(ItemStack item, IBlockAccess world, BlockPos pos, int fortune) {
	IBlockState state = world.getBlockState(pos);
	return new java.util.ArrayList(java.util.Arrays.asList(new ItemStack(this, 1, 0)));
}

@Override
public EnumType getWoodType(int meta) {
	return null;
}

@Override
@SideOnly(Side.CLIENT)
public EnumWorldBlockLayer getBlockLayer() {
	return Blocks.leaves.getBlockLayer();
}

}

 

Registering Blocks

public static Block mahogany_leaves;
...
public void init() {
    mahogany_leaves = new ExtraLeavesBlock("mahogany_leaves");
}
...
public void register() {
    GameRegistry.registerBlock(mahogany_leaves, mahogany_leaves.getUnlocalizedName().substring(5));
}
...
public void registerRenders() {
    registerRender(mahogany_leaves);
}

 

blockstates/mahogany_leaves.json

{
    "variants": {
        "normal": { "model": "em:mahogany_leaves" }
    }
}

 

models/block/mahogany_leaves.json

{
    "parent": "block/cube_all",
    "textures": {
        "all": "em:blocks/mahogany_leaves"
    }
}

 

models/item/mahogany_leaves.json

{
    "parent": "em:block/mahogany_leaves",
    "display": {
        "thirdperson": {
            "rotation": [ 10, -45, 170 ],
            "translation": [ 0, 1.5, -2.75 ],
            "scale": [ 0.375, 0.375, 0.375 ]
        }
    }
}

 

My texture is in the right folder as it shows up in my inventory.

 

If anyone has any idea why it's not showing up, any help is welcome. I'm also sure there are better ways of creative a custom leaves class (with a VARIANT property for example). If you have a basic custom leaves class, I would gladly take a look at it to understand what's going on.

 

Also, they do act like leaves. They decay, drop apples etc. so the registering should be fine. Probably something to do with my json files but I can't seem to figure out what.

 

Thanks in advance,

Krikke

Link to comment
Share on other sites

Hi

 

Have a look in the console for an error which mentions your leaves.  You will probably find something that says it expects to find "decayable=true,check_decay=true" but couldn't.

 

->either add these to your blockstates file (four lines instead of just one)

or add a custom state mapper

http://www.minecraftforge.net/forum/index.php/topic,28997.msg149446.html#msg149446

 

-TGG

Link to comment
Share on other sites

Hi, and thanks for your reply.

 

I indeed managed to find the errors on the blockstates in my console.

I've tried changing my blockstate json into this:

{
    "variants": {
        "check_decay=true,decayable=true":  { "model": "em:mahogany_leaves" }
        "check_decay=false,decayable=true":  { "model": "em:mahogany_leaves" }
        "check_decay=true,decayable=false":  { "model": "em:mahogany_leaves" }
        "check_decay=false,decayable=false":  { "model": "em:mahogany_leaves" }
    }
}

 

but I'm not sure if this is the correct way to do it as I'm getting another error (and thus missing block textures):

java.lang.RuntimeException: Encountered an exception when loading model definition of 'em:mahogany_leaves#check_decay=false,decayable=true' from: 'em:blockstates/mahogany_leaves.json' in resourcepack: 'FMLFileResourcePack:Expansion Mod'

 

My apologies if I'm making a rookie mistake here, but how exactly do you add multiple properties to the blockstate json?

 

EDIT: Never mind, I noticed I didn't put commas at the end of my lines in the json file. It's working perfect now. Thanks a bunch!!

 

-Krikke

Link to comment
Share on other sites

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.