Jump to content

[1.12.2] How can I use subblock?


NyasRoryo

Recommended Posts

... 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 by NyasRoryo
Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

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.