Posted September 13, 20196 yr ... I mean multi block use an ID, use damage to distinguish. Who can give a example .java file with basic code to create and registry it and its ItemBlock? If you can show me how to give a TranslationKey, that's fantastic! Please help me... I've been trying for three days, I look ic2, te5 and even gtce, and I still can't understand how to meta-hack the block... my code: package com.github.nyasroryo.lanticaltech.common.block.buildmaterial; import com.github.nyasroryo.lanticaltech.common.block.BlockBase; import net.minecraft.block.Block; 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.ItemBlock; import net.minecraft.item.ItemStack; import net.minecraft.util.IStringSerializable; import net.minecraft.util.NonNullList; public class CeramicTile extends BlockBase { private static final String NAME = "CeramicTile"; public static final Block THIS_BLOCK = new CeramicTile(); public static final Item THIS_ITEMBLOCK = new ItemBlock(THIS_BLOCK).setRegistryName(NAME); public static final PropertyEnum<EnumColor> COLOR = PropertyEnum.create("color", EnumColor.class); public CeramicTile() { super(NAME); //set Hardness, resistance, sound etc. in other class setDefaultState(this.blockState.getBaseState().withProperty(COLOR, EnumColor.WHITE)); } @Override protected BlockStateContainer createBlockState() { return new BlockStateContainer(this, COLOR); } @Override public IBlockState getStateFromMeta(int metadata) { return this.getDefaultState().withProperty(COLOR, EnumColor.values()[metadata]); } @Override public int getMetaFromState(IBlockState state) { return state.getValue(COLOR).ordinal(); } @Override public int damageDropped(IBlockState state) { return getMetaFromState(state); } @Override public void getSubBlocks(CreativeTabs itemIn, NonNullList<ItemStack> items) { for (EnumDyeColor enumdyecolor : EnumDyeColor.values()) { items.add(new ItemStack(this, 1, enumdyecolor.getMetadata())); } } public static enum EnumColor implements IStringSerializable { WHITE("white"), BLACK("black"), RED("red"), BLUE("blue"), GREEN("green"), YELLOW("yellow"), ORANGE("orange"), GREY("grey"), PURPLE("purple"), CYAN("cyan"), PINK("pink"), MAGENTA("magenta"), BROWN("brown"), LIGHTBLUE("lightblue"), LIGHTGREY("lightgrey"), LIGHTGREEN("lightgreen"); private String name; private EnumColor(String color) { this.name = color; } @Override public String getName() { return this.name; } @Override public String toString() { return this.name; } } } Registry and error: ForgeRegistries.BLOCKS.register(CeramicTile.THIS_BLOCK); ForgeRegistries.ITEMS.register(CeramicTile.THIS_ITEMBLOCK); ModelLoader.setCustomModelResourceLocation(CeramicTile.THIS_ITEMBLOCK, 0, new ModelResourceLocation("CeramicTile","inventory")); ModelLoader.setCustomModelResourceLocation(CeramicTile.THIS_ITEMBLOCK, 1, new ModelResourceLocation("CeramicTile","inventory")); ModelLoader.setCustomModelResourceLocation(CeramicTile.THIS_ITEMBLOCK, 2, new ModelResourceLocation("CeramicTile","inventory")); Caused by: java.lang.NullPointerException at net.minecraft.block.state.BlockStateContainer.validateProperty(BlockStateContainer.java:103) at net.minecraft.block.state.BlockStateContainer.<init>(BlockStateContainer.java:77) at net.minecraft.block.state.BlockStateContainer.<init>(BlockStateContainer.java:62) at com.github.nyasroryo.lanticaltech.common.block.buildmaterial.CeramicTile.createBlockState(CeramicTile.java:32) at net.minecraft.block.Block.<init>(Block.java:313) at net.minecraft.block.Block.<init>(Block.java:322) at com.github.nyasroryo.lanticaltech.common.block.BlockBase.<init>(BlockBase.java:13) at com.github.nyasroryo.lanticaltech.common.block.buildmaterial.CeramicTile.<init>(CeramicTile.java:26) at com.github.nyasroryo.lanticaltech.common.block.buildmaterial.CeramicTile.<clinit>(CeramicTile.java:20) ... 51 more Edited September 13, 20196 yr by NyasRoryo
September 13, 20196 yr 41 minutes ago, NyasRoryo said: /*@Override protected BlockStateContainer createBlockState() { return new BlockStateContainer(this, COLOR); }*/ I don't know why you commented this out, because you need it. 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.
September 13, 20196 yr Author @Draco18s Sorry, I just commented it when I was debugging, but it throws NullPointerExpection after removing the comment. And how can I do now... Plz help me thx Edited September 13, 20196 yr by NyasRoryo
September 13, 20196 yr Somehow your property is null when it gets passed to the BlockStateContainer constructor. Also, you don't need BlockBase. There's already a "base" block class, its called Block. 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.
September 13, 20196 yr Author emm... 1 hour ago, Draco18s said: 当它传递给BlockStateContainer构造函数时,你的属性以某种方式为null。 此外,您不需要BlockBase。已经有一个“基础”块类,它叫做Block。 How a correct createBlockState like, plz show me thanks!!! and about BlockBase.class, I put hardness, resistance setter in it(because my mod's block's data is integrated in a class
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.