Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

Posted

I've been working on getting a block with multiple blockstates that act as different blocks (similar to how in Thermal Expansion, all the ores are on the same id but with different meta values). I've encountered a bunch of problems, most of which I fixed on my own. However, I'm having a problem where although all 8 'variants' of my block appear in the creative menu, taking one and trying to place it always places the variant with meta:0. For reference, I am running MinecraftForge v12.18.0.2005

 

I've been trying to figure it out for about 2 hours now, and my google-fu is failing me. Chances are it is probably a really silly mistake. I'm fairly certain that it is a problem with my BlockGemOre class because everything seems to be rendering correctly from my json files. Can you tell me what I should do?

 

BlockOre (Abstract class that is the parent class of BlockGemOre, so I can easily make changes to all my ore classes in the future)

package com.gmail.sharpcastle33.civilization.blocks.ores;

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

public abstract class BlockOre extends Block {

public BlockOre(String unlocalized_name) {
	super(Material.IRON);
	this.setCreativeTab(CreativeTabs.BUILDING_BLOCKS);
	this.setHardness(3.0f);
	this.setResistance(15.0f);
	this.setUnlocalizedName(unlocalized_name);

}

}

 

BlockGemOre

package com.gmail.sharpcastle33.civilization.blocks.ores;


import java.util.List;

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.entity.EntityLivingBase;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.util.IStringSerializable;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;

public class BlockGemOre extends BlockOre implements IMetaBlockName{
public enum EnumType implements IStringSerializable {
	    
	/*"diamond", "ruby",  "emerald", "sapphire", "amber", "onyx",
	"moonstone", "amethyst"
};
//clear, red, green, blue, yellow, black, white, purple*/

		DIAMOND(0, "diamond"),
	    RUBY(1, "ruby"),
	    EMERALD(2, "emerald"),
	    SAPPHIRE(3, "sapphire"),
	    AMBER(4, "amber"),
	    ONYX(5, "onyx"),
	    MOONSTONE(6, "moonstone"),
	    AMETHYST(7, "amethyst");

	    private int ID;
	    private String name;
	    
	    private EnumType(int ID, String name) {
	        this.ID = ID;
	        this.name = name;
	    }
	    
	    @Override
	    public String getName() {
	        return name;
	    }

	    public int getID() {
	        return ID;
	    }
	    
	    @Override
	    public String toString() {
	        return getName();
	    }

}
//http://bedrockminer.jimdo.com/modding-tutorials/basic-modding-1-8/blockstates-and-metadata/
//http://www.minecraftforge.net/wiki/Metadata_Based_Subblocks
public BlockGemOre(String s) {
	super(s);
	this.setCreativeTab(CreativeTabs.BUILDING_BLOCKS);
	this.setHardness(2.5f);
	this.setResistance(12.5f);
	this.setDefaultState(this.blockState.getBaseState().withProperty(TYPE, EnumType.DIAMOND));
}

public static final PropertyEnum TYPE = PropertyEnum.create("type", BlockGemOre.EnumType.class);

@Override
protected BlockStateContainer createBlockState() {
    return new BlockStateContainer(this, new IProperty[] { TYPE });
}

@Override
public IBlockState getStateFromMeta(int meta) {
   //switch(getDefaultState().withProperty(TYPE, value))
	EnumType t = EnumType.AMETHYST;

	switch(meta){
		case 0: t = EnumType.DIAMOND;
		break;
		case 1: t = EnumType.RUBY;
		break;
		case 2: t = EnumType.EMERALD;
		break;
		case 3: t = EnumType.SAPPHIRE;
		break;
		case 4: t = EnumType.AMBER;
		break;
		case 5: t = EnumType.ONYX;
		break;
		case 6: t = EnumType.MOONSTONE;
		break;
		case 7: t = EnumType.AMETHYST;
		break;
		default: t = EnumType.DIAMOND;
		break;
	}
	  return getDefaultState().withProperty(TYPE, t);
}

@Override
public int getMetaFromState(IBlockState state) {
    EnumType type = (EnumType) state.getValue(TYPE);
    return type.getID();
}

@Override
public int damageDropped(IBlockState state) {
    return getMetaFromState(state);
}

@Override
@SideOnly(Side.CLIENT)
public void getSubBlocks(Item itemIn, CreativeTabs tab, List list) {
    list.add(new ItemStack(itemIn, 1, 0)); //Meta 0
    list.add(new ItemStack(itemIn, 1, 1)); //Meta 1
    list.add(new ItemStack(itemIn, 1, 2));
    list.add(new ItemStack(itemIn, 1, 3));
    list.add(new ItemStack(itemIn, 1, 4));
    list.add(new ItemStack(itemIn, 1, 5));
    list.add(new ItemStack(itemIn, 1, 6));
    list.add(new ItemStack(itemIn, 1, 7));
}

@Override
public String getSpecialName(ItemStack stack) {
	EnumType t = null;
	switch(stack.getItemDamage()){
	case 0: t = EnumType.DIAMOND;
	break;
	case 1: t = EnumType.RUBY;
	break;
	case 2: t = EnumType.EMERALD;
	break;
	case 3: t = EnumType.SAPPHIRE;
	break;
	case 4: t = EnumType.AMBER;
	break;
	case 5: t = EnumType.ONYX;
	break;
	case 6: t = EnumType.MOONSTONE;
	break;
	case 7: t = EnumType.AMETHYST;
	break;
	default: t = EnumType.DIAMOND;
	break;
 }
	return t.getName();
}













}

 

ItemBlockGemOre

package com.gmail.sharpcastle33.civilization.blocks.ores;

import com.gmail.sharpcastle33.civilization.blocks.ores.BlockGemOre.EnumType;

import net.minecraft.block.Block;
import net.minecraft.item.ItemBlock;
import net.minecraft.item.ItemStack;

public class ItemBlockGemOre extends ItemBlock{
/*private final static String[] subNames = {
		"diamond", "ruby",  "emerald", "sapphire", "amber", "onyx",
		"moonstone", "amethyst"
	};
//clear, red, green, blue, yellow, black, white, purple


public ItemBlockGemOre(Block b){
	super(b);
}

public int getMetadata (int damageValue) {
	return damageValue;
}

public String getUnlocalizedName(ItemStack itemstack) {
	return getUnlocalizedName() + "." + subNames[itemstack.getItemDamage()];
}
*/
public ItemBlockGemOre(Block block) {
        super(block);
        if (!(block instanceof IMetaBlockName)) {
            throw new IllegalArgumentException(String.format("The given Block %s is not an instance of ISpecialBlockName!", block.getUnlocalizedName()));
        }
        this.setMaxDamage(0);
        this.setHasSubtypes(true);
    }

}

 

Also, another thing that I think might be a problem is that all variants of my block have the same unlocalized name, 'tile.block_gem_ore.name" Am I missing something that I'm supposed to do so that they can have separate names based on their metadata?

 

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...

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.