Posted September 11, 20169 yr The tittle says it all, I get this NullPointerException and it's driving me crazy. In the method createBlockState it says that the setType is null, which I checked and for some reason it is null. I really don't know why this is not working... How I register my Block: BOA_0 = new AsphaltSet_BASE("boa_0", SetType.SET_0); Here's the code package tt.roadsmod.asphalt; import java.util.List; import java.util.Random; import javax.annotation.Nullable; import org.apache.commons.lang3.StringUtils; import org.lwjgl.input.Keyboard; import net.minecraft.block.Block; import net.minecraft.block.material.MapColor; import net.minecraft.block.material.Material; import net.minecraft.block.properties.IProperty; import net.minecraft.block.properties.PropertyBool; import net.minecraft.block.properties.PropertyEnum; import net.minecraft.block.properties.PropertyInteger; import net.minecraft.block.state.BlockStateContainer; import net.minecraft.block.state.IBlockState; import net.minecraft.creativetab.CreativeTabs; import net.minecraft.entity.Entity; import net.minecraft.entity.EntityLivingBase; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.util.BlockRenderLayer; import net.minecraft.util.EnumFacing; import net.minecraft.util.EnumHand; import net.minecraft.util.math.AxisAlignedBB; import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.RayTraceResult; import net.minecraft.world.IBlockAccess; import net.minecraft.world.World; import net.minecraftforge.fml.common.registry.GameRegistry; import net.minecraftforge.fml.relauncher.Side; import net.minecraftforge.fml.relauncher.SideOnly; import tt.roadsmod.asphalt.EnumAsphalt.Half; import tt.roadsmod.asphalt.EnumAsphalt.Set_0; import tt.roadsmod.client.RenderingRegistry; import tt.roadsmod.main.EnumAsphaltColor; import tt.roadsmod.main.EnumAsphaltType; import tt.roadsmod.main.IAsphaltBlockHelper; public class AsphaltSet_BASE extends Block implements IAsphaltBlockHelper { public static final PropertyEnum<Half> HALF = PropertyEnum.create("half", Half.class); public static final PropertyInteger META = PropertyInteger.create("meta", 0, 15); public static final PropertyBool OPEN = PropertyBool.create("open"); public static final PropertyInteger ORIENTATION_SD = PropertyInteger.create("orientation", 1, ; public static final PropertyInteger ORIENTATION_S = PropertyInteger.create("orientation", 1, 4); public static final PropertyInteger ORIENTATION_D = PropertyInteger.create("orientation", 1, 4); public static final PropertyEnum<Set_0> TYPE = PropertyEnum.create("type", Set_0.class); private String name; SetType setType = SetType.FULL; public AsphaltSet_BASE(String name, SetType setType) { super(Material.ROCK); this.name = name; this.setType = setType; register(); loadProperties(); } private void register() { GameRegistry.register(this.setRegistryName(name)); GameRegistry.register(new ItemAsphaltBlock(this, setType).setRegistryName(this.getRegistryName())); } /* PROPERTIES */ private void loadProperties() { setHardness(5.0F*getHeight()); setResistance(10.0F*getHeight()); RenderingRegistry.addToList(this, setType); switch (setType) { case FULL: this.setDefaultState(getDefaultState().withProperty(META, 0)); break; case SET_0: this.setDefaultState(getDefaultState().withProperty(TYPE, Set_0.ASPHALT).withProperty(OPEN, false)); break; case R28: this.setDefaultState(getDefaultState().withProperty(HALF, Half.FIRST).withProperty(ORIENTATION_SD, 0)); break; default: break; } } @Override public float getHeight() { if (StringUtils.contains(name, "coa")) { return 0.75F; } else if (StringUtils.contains(name, "soa")) { return 0.50F; } else if (StringUtils.contains(name, "hoa")) { return 0.25F; } else { return 1.0F; } } @Override public int getSet() { return Integer.valueOf(StringUtils.substringAfterLast(name, "_")); } @Override public EnumAsphaltColor getColor(IBlockState blockState) { return EnumAsphaltColor.getColorByString(setType == SetType.SET_0 ? blockState.getValue(TYPE).getName() : name); } @Override public EnumAsphaltType getType() { return EnumAsphaltType.getTypeByHeight(getHeight()); } @Override public MapColor getMapColor(IBlockState blockState) { return EnumAsphaltColor.getMapColor(getColor(blockState)); } public SetType getSetType() { return setType; } /* SOLID, OPAQUE, FULL CUBE */ @Override public boolean isOpaqueCube(IBlockState blockState) { if (setType == SetType.SET_0) { return (blockState.getValue(OPEN) == true || getHeight() != 1.0F || blockState.getValue(TYPE).getID() > 3) ? false : true; } else { return getHeight() == 1.0F; } } @Override public boolean isFullBlock(IBlockState blockState) { return isOpaqueCube(blockState); } @Override public BlockRenderLayer getBlockLayer() { if (setType == SetType.SET_0) { return BlockRenderLayer.CUTOUT; } else { return BlockRenderLayer.SOLID; } } @Override public boolean isSideSolid(IBlockState blockState, IBlockAccess blockAccess, BlockPos blockPos, EnumFacing facing) { if (getHeight() == 1.0F) { return true; } else { if (facing == EnumFacing.DOWN) { return true; } else { return false; } } } /* COLLISION AND BOUNDING BOXES */ @Override public void addCollisionBoxToList(IBlockState blockState, World world, BlockPos blockPos, AxisAlignedBB axisAlignedBB, List<AxisAlignedBB> list, @Nullable Entity entity) { if (setType == SetType.SET_0) { this.addCollisionBoxToList(blockPos, axisAlignedBB, list, new AxisAlignedBB(0.0, 0.0, 0.0, 1.0, 1.0*getHeight(), 0.0)); this.addCollisionBoxToList(blockPos, axisAlignedBB, list, new AxisAlignedBB(0.0, 0.0, 0.0, 0.0, 1.0*getHeight(), 1.0)); this.addCollisionBoxToList(blockPos, axisAlignedBB, list, new AxisAlignedBB(1.0, 0.0, 0.0, 1.0, 1.0*getHeight(), 1.0)); this.addCollisionBoxToList(blockPos, axisAlignedBB, list, new AxisAlignedBB(0.0, 0.0, 1.0, 1.0, 1.0*getHeight(), 1.0)); if (!(blockState.getValue(OPEN) == true)) { this.addCollisionBoxToList(blockPos, axisAlignedBB, list, new AxisAlignedBB(0.0, 0.0, 0.0, 1.0, 1.0*getHeight(), 1.0)); this.addCollisionBoxToList(blockPos, axisAlignedBB, list, new AxisAlignedBB(0.0, 0.0, 0.0, 1.0, 0, 1.0)); } } else { this.addCollisionBoxToList(blockPos, axisAlignedBB, list, new AxisAlignedBB(0.0, 0.0, 0.0, 1.0, 1.0*getHeight(), 1.0)); } } @Override public boolean isLadder(IBlockState blockState, IBlockAccess blockAccess, BlockPos blockPos, EntityLivingBase entityLivingBase) { if (setType == SetType.SET_0) { return ((blockState.getValue(TYPE).getID() > 3) && blockState.getValue(OPEN) == true) ? true : false; } else { return false; } } /* BLOCK STATE */ @Override protected BlockStateContainer createBlockState() { System.out.println("################################################"); System.out.println(setType); // THTA'S HOW I CHECKED IF IT'S NULL switch (setType) // THROWS THE EXCEPTION ON THIS LINE { case FULL: return new BlockStateContainer(this, new IProperty[] {META}); case SET_0: return new BlockStateContainer(this, new IProperty[] {TYPE, OPEN}); case R28: return new BlockStateContainer(this, new IProperty[] {HALF, ORIENTATION_SD}); default: return null; } } @Override public IBlockState getStateFromMeta(int meta) { switch (setType) { case FULL: getDefaultState().withProperty(META, meta); case SET_0: return getDefaultState().withProperty(TYPE, EnumAsphalt.Set_0.getTypeByID(meta%).withProperty(OPEN, meta < 8 ? false : true); case R28: return getDefaultState().withProperty(HALF, meta < 8 ? Half.FIRST : Half.SECOND).withProperty(ORIENTATION_SD, meta % 2); default: return null; } } @Override public int getMetaFromState(IBlockState blockState) { switch (setType) { case FULL: return blockState.getValue(META); case SET_0: return ((blockState.getValue(OPEN) == false ? 0 : + blockState.getValue(TYPE).getID()); case R28: return ((blockState.getValue(HALF) == Half.FIRST ? 0 : + blockState.getValue(ORIENTATION_SD)); default: return 0; } } /* DROP, PICK AND TAB */ @Override public Item getItemDropped(IBlockState blockState, Random random, int fortune) { return Item.getItemFromBlock(this); } @Override public int damageDropped(IBlockState blockState) { switch (setType) { case FULL: return blockState.getValue(META); case SET_0: return blockState.getValue(TYPE).getID(); case R28: return (blockState.getValue(HALF) == Half.FIRST ? 0 : ; default: return 0; } } @Override public ItemStack getPickBlock(IBlockState blockState, RayTraceResult rayTraceResult, World world, BlockPos blockPos, EntityPlayer entityPlayer) { return new ItemStack(getItemDropped(blockState, RANDOM, 0), 1, damageDropped(blockState)); } @SideOnly(Side.CLIENT) @Override public void getSubBlocks(Item item, CreativeTabs creativeTabs, List list) { switch (setType) { case FULL: for (int i = 0; i < 16; i++) { list.add(new ItemStack(item, 1, i)); } break; case SET_0: for (int i = 0; i < 8; i++) { list.add(new ItemStack(item, 1, i)); } break; case R28: list.add(new ItemStack(item, 1, 0)); list.add(new ItemStack(item, 1, ); break; } } /* SPECIAL FUNCTIONS */ @Override public boolean onBlockActivated(World world, BlockPos blockPos, IBlockState blockState, EntityPlayer entityPlayer, EnumHand hand, @Nullable ItemStack itemStack, EnumFacing side, float hitX, float hitY, float hitZ) { if (setType == SetType.SET_0) { if (Keyboard.isKeyDown(Keyboard.KEY_LCONTROL) && blockState.getValue(TYPE).getID() > 3) { if (!world.isRemote) { world.setBlockState(blockPos, getDefaultState().withProperty(TYPE, blockState.getValue(TYPE)).withProperty(OPEN, (blockState.getValue(OPEN) == true) ? false : true)); } return true; } } return false; } }
September 11, 20169 yr createBlockState is called in the constructor of Block therefore it is null. VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect. Forge and vanilla BlockState generator.
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.