Jump to content

Recommended Posts

Posted

Hello everyone!

 

I've got a problem with creating blocks in MC.

I've tried both options from the official Forge Docs and

also some other suggestions from other forums and

videos. I really don't know what's the error here.

Items work ingame, blocks don't.

 

I created a class called 'Blocks', which extends

net.minecraft.block.Block. Here's the code:

public class Blocks extends Block {
  public static final List<Block> blocks = new ArrayList<Block>();
  
  public Blocks(String name) {
    super(Properties.of(Material.STONE, MaterialColor.STONE).strength(60f, 120f).harvestTool(ToolType.PICKAXE).harvestLevel(2).sound(SoundType.METAL));
    setRegistryName(Info.MODID, name); // Info is basically another class with lots of info for the mod, such as credits, modid, version etc.
    blocks.add(this);
    
  }
  
}

 

In my 'Main' I have:

public class Main {
  public Main() {
      new Blocks("block_x");

  }

  @SubscribeEvent
  public void onBlocksRegistry(final RegistryEvent.Register<Block> blockRegE) {
      blockRegE.getRegistry().registerAll(Blocks.blocks.toArray(new Block[0]));

  }
  
}

 

Ingame no block is there. Also of course I have 'block_x' as .json files in

    assets.(MODID).blockstates,

    assets.(MODID).models.block,

    assets.(MODID).models.item

 

I've also got the texture in the assets.(MODID).textures folder.

 

Does anybody know why the block isn't registering?

Posted

First of all thank you for that fast reply.

 

In my 'Main' I do now have:

final DeferredRegister<Block> BLOCKS = DeferredRegister.create(ForgeRegistries.BLOCKS, Info.MODID);
BLOCKS.register("block_x", () -> new Block(Block.Properties.of(Material.STONE)));
BLOCKS.register(FMLJavaModLoadingContext.get().getModEventBus());

but still it doesn't work... Do I need to use 'TileEntityType'?

Posted

I would recommend doing the last line in your mod constructor

If you're already doing that, show your full class

This is my Forum Signature, I am currently attempting to transform it into a small guide for fixing easier issues using spoiler blocks to keep things tidy.

 

As the most common issue I feel I should put this outside the main bulk:

The only official source for Forge is https://files.minecraftforge.net, and the only site I trust for getting mods is CurseForge.

If you use any site other than these, please take a look at the StopModReposts project and install their browser extension, I would also advise running a virus scan.

 

For players asking for assistance with Forge please expand the spoiler below and read the appropriate section(s) in its/their entirety.

  Reveal hidden contents

 

Posted

Hello. I already have that in my Mod Constructor. Here is the full 'Main' class:

@Mod(Info.MODID)
public class Main {
	public Main() {
		final DeferredRegister<Block> BLOCKS = DeferredRegister.create(ForgeRegistries.BLOCKS, Info.MODID);
		BLOCKS.register("block_x", () -> new Block(Block.Properties.of(Material.STONE)));
		BLOCKS.register(FMLJavaModLoadingContext.get().getModEventBus());
	}
}

 

Posted

The issue is, that the block in not shown in the creative inventory in mc.

Also if I try to give it to me (/give ...), it won't work.

I've checked all the json files again, but I can't find any mistake.

 

Posted
  On 5/27/2021 at 9:24 AM, Amtsapparat said:

The issue is, that the block in not shown in the creative inventory in mc.

Also if I try to give it to me (/give ...), it won't work.

I've checked all the json files again, but I can't find any mistake.

Expand  

you need to create a item for the block

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.