Jump to content

Recommended Posts

Posted (edited)

I am new to Minecraft modding, so I followed 2 tutorials on how to make custom blocks. 1 by Harry Talks, the other one by Loremaster. Both of the series use the same type of RegistryHandler's, but both series don't show how to use this way of registering slabs, stairs or walls. I found a post about custom slabs, but it does not use a RegistryHandler to register the slabs. Looking at it, I can understand what is going on. I just have a hard time converting that code to the other technique.

 

Therefor my question is, given the RegistryHandler, BlockSlabBase and BlockInit bellow, how do I go on about registering a new slab?

My code could be completely off to what it should be, but that's just because of the lack of tutorials.


 

Spoiler

 

BlockSlabBase


public class BlockSlabBase extends BlockSlab implements IHasModel {
	public BlockSlabBase(String name, Material material) {
		super(material);
		setUnlocalizedName(name);
		setRegistryName(name);
		setCreativeTab(CreativeTabs.BUILDING_BLOCKS);
		
		BlockInit.SLABS.add(this);
		ItemInit.ITEMS.add(new ItemBlock(this).setRegistryName(this.getRegistryName()));
	}
	
	@Override
	public void registerModels() {
		Main.proxy.registerItemRenderer(Item.getItemFromBlock(this), 0, "inventory");
	}

	@Override
	public String getUnlocalizedName(int meta) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public boolean isDouble() {
		// TODO Auto-generated method stub
		return false;
	}

	@Override
	public IProperty<?> getVariantProperty() {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public Comparable<?> getTypeForItem(ItemStack stack) {
		// TODO Auto-generated method stub
		return null;
	}
	
	public static class Double extends BlockSlabBase {

		public Double(String name, Material material) {
			super(name, material);
		}

		@Override
		public boolean isDouble() {
			return true;
		}

	}

	public static class Half extends BlockSlabBase {

		public Half(String name, Material material) {
			super(name, material);
		}

		@Override
		public boolean isDouble() {
			return false;
		}
	}
}

 

RegistryHandler


package com.floppygaming.sswm.util.handlers;

import com.floppygaming.sswm.init.BlockInit;
import com.floppygaming.sswm.init.ItemInit;
import com.floppygaming.sswm.util.IHasModel;

import net.minecraft.block.Block;
import net.minecraft.block.BlockSlab;
import net.minecraft.item.Item;
import net.minecraftforge.client.event.ModelRegistryEvent;
import net.minecraftforge.event.RegistryEvent;
import net.minecraftforge.fml.common.Mod.EventBusSubscriber;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;

@EventBusSubscriber
public class RegistryHandler {
	@SubscribeEvent
	public static void onItemRegister (RegistryEvent.Register<Item> event) {
		event.getRegistry().registerAll(ItemInit.ITEMS.toArray(new Item[0]));
	}
	
	@SubscribeEvent
	public static void onBlockRegister (RegistryEvent.Register<Block> event) {
		event.getRegistry().registerAll(BlockInit.BLOCKS.toArray(new Block[0]));
	}
	@SubscribeEvent
	public static void onModelRegister (ModelRegistryEvent event) {
		for (Item item : ItemInit.ITEMS) {
			if (item instanceof IHasModel) {
				((IHasModel)item).registerModels();
			}
		}
		
		for (Block block : BlockInit.BLOCKS) {
			if (block instanceof IHasModel) {
				((IHasModel)block).registerModels();
			}
		}
	}
}

 

BlockInit


package com.floppygaming.sswm.init;

import java.util.ArrayList;
import java.util.List;

import com.floppygaming.sswm.objects.blocks.BlockBase;
import com.floppygaming.sswm.objects.blocks.slabs.BlockSlabBase;

import net.minecraft.block.Block;
import net.minecraft.block.BlockSlab;
import net.minecraft.block.material.Material;

public class BlockInit {
	public static final List<BlockSlab> SLABS = new ArrayList<BlockSlab>();
	
	public static final BlockSlab ANDESITE_SLAB = new BlockSlabBase("andesite_slab", Material.ROCK);
}

 

 

 

 

Edited by FloppyGaming
Posted

I’m just gonna link this, read it, it’s all important. https://gist.github.com/Cadiboo/fbea89dc95ebbdc58d118f5350b7ba93

 

Slabs are a fairly complicated thing for a new Modder, as they involve 2 semi-seperate blocks and 1 custom itemblock. 

Heres my slab class (not how it’s abstract had has 2 subclasses, double & single) https://github.com/Cadiboo/Legendary-Winter/blob/master/src/main/java/geek/legendarywinter/blocks/BlockWinterstoneSlab.java

I create the blocks with

	registry.register(setupBlock(new BlockWinterstoneSlab.Half(), "winterstone_slab"));
	registry.register(setupBlock(new BlockWinterstoneSlab.Double(), "winterstone_double_slab"));
	

and the itemblock with

	final ItemSlab itemSlab = new ItemSlab(WINTERSTONE_SLAB_HALF, WINTERSTONE_SLAB_HALF, WINTERSTONE_SLAB_DOUBLE);
	final ResourceLocation name = WINTERSTONE_SLAB_HALF.getRegistryName();
	itemSlab.setRegistryName(name);
	registry.register(itemSlab);
	

I use a local variable and don’t chain setRegistryName because it returns an Item and not an ItemSlab, it’s not necessary though

About Me

Spoiler

My Discord - Cadiboo#8887

My WebsiteCadiboo.github.io

My ModsCadiboo.github.io/projects

My TutorialsCadiboo.github.io/tutorials

Versions below 1.14.4 are no longer supported on this forum. Use the latest version to receive support.

When asking support remember to include all relevant log files (logs are found in .minecraft/logs/), code if applicable and screenshots if possible.

Only download mods from trusted sites like CurseForge (minecraft.curseforge.com). A list of bad sites can be found here, with more information available at stopmodreposts.org

Edit your own signature at www.minecraftforge.net/forum/settings/signature/ (Make sure to check its compatibility with the Dark Theme)

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.