Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

Posted

Hey everyone,

 

So I'm trying to implement a custom block model, however it displays in the hand, but is just an empty block when placed.

 

Here is the .json files:

 

- blockstate:

{
    "variants": {
        "normal": { "model": "ce:void_infuser" }
    }
}

- block model:

Spoiler

{
    "textures": {
        "0": "blocks/stonebrick_carved",
        "1": "blocks/planks_oak",
        "2": "blocks/coal_block",
        "3": "blocks/quartz_block_top"
    },
    "elements": [
        {
            "name": "bot",
            "from": [ 3.0, 0.0, 3.0 ], 
            "to": [ 13.0, 1.0, 13.0 ], 
            "faces": {
                "north": { "texture": "#0", "uv": [ 0.0, 0.0, 10.0, 1.0 ] },
                "east": { "texture": "#0", "uv": [ 0.0, 0.0, 10.0, 1.0 ] },
                "south": { "texture": "#0", "uv": [ 0.0, 0.0, 10.0, 1.0 ] },
                "west": { "texture": "#0", "uv": [ 0.0, 0.0, 10.0, 1.0 ] },
                "up": { "texture": "#0", "uv": [ 0.0, 0.0, 16.0, 16.0 ] },
                "down": { "texture": "#0", "uv": [ 0.0, 0.0, 16.0, 16.0 ] }
            }
        },
        {
            "name": "bot_top",
            "from": [ 4.0, 1.0, 4.0 ], 
            "to": [ 12.0, 2.0, 12.0 ], 
            "faces": {
                "north": { "texture": "#1", "uv": [ 0.0, 6.0, 16.0, 9.0 ] },
                "east": { "texture": "#1", "uv": [ 0.0, 6.0, 16.0, 9.0 ] },
                "south": { "texture": "#1", "uv": [ 0.0, 6.0, 16.0, 9.0 ] },
                "west": { "texture": "#1", "uv": [ 0.0, 6.0, 16.0, 9.0 ] },
                "up": { "texture": "#1", "uv": [ 0.0, 0.0, 16.0, 16.0 ] },
                "down": { "texture": "#-1", "uv": [ 0.0, 0.0, 8.0, 8.0 ] }
            }
        },
        {
            "name": "pillar_bot",
            "from": [ 6.0, 2.0, 6.0 ], 
            "to": [ 10.0, 7.0, 10.0 ], 
            "faces": {
                "north": { "texture": "#0", "uv": [ 0.0, 0.0, 16.0, 16.0 ] },
                "east": { "texture": "#0", "uv": [ 0.0, 0.0, 16.0, 16.0 ] },
                "south": { "texture": "#0", "uv": [ 0.0, 0.0, 16.0, 16.0 ] },
                "west": { "texture": "#0", "uv": [ 0.0, 0.0, 16.0, 16.0 ] },
                "up": { "texture": "#-1", "uv": [ 0.0, 0.0, 4.0, 4.0 ] },
                "down": { "texture": "#-1", "uv": [ 0.0, 0.0, 4.0, 4.0 ] }
            }
        },
        {
            "name": "top",
            "from": [ 4.0, 13.0, 4.0 ], 
            "to": [ 12.0, 14.0, 12.0 ], 
            "faces": {
                "north": { "texture": "#1", "uv": [ 0.0, 6.0, 16.0, 9.0 ] },
                "east": { "texture": "#1", "uv": [ 0.0, 6.0, 16.0, 9.0 ] },
                "south": { "texture": "#1", "uv": [ 0.0, 6.0, 16.0, 9.0 ] },
                "west": { "texture": "#1", "uv": [ 0.0, 6.0, 16.0, 9.0 ] },
                "up": { "texture": "#1", "uv": [ 0.0, 0.0, 16.0, 16.0 ] },
                "down": { "texture": "#-1", "uv": [ 0.0, 0.0, 8.0, 8.0 ] }
            }
        },
        {
            "name": "top_stand",
            "from": [ 2.0, 12.0, 2.0 ], 
            "to": [ 14.0, 13.0, 14.0 ], 
            "faces": {
                "north": { "texture": "#0", "uv": [ 0.0, 0.0, 12.0, 2.0 ] },
                "east": { "texture": "#0", "uv": [ 0.0, 0.0, 12.0, 2.0 ] },
                "south": { "texture": "#0", "uv": [ 0.0, 0.0, 12.0, 2.0 ] },
                "west": { "texture": "#0", "uv": [ 0.0, 0.0, 12.0, 2.0 ] },
                "up": { "texture": "#0", "uv": [ 0.0, 0.0, 16.0, 16.0 ] },
                "down": { "texture": "#0", "uv": [ 0.0, 0.0, 16.0, 16.0 ] }
            }
        },
        {
            "name": "infusion_platform",
            "from": [ 6.0, 14.0, 6.0 ], 
            "to": [ 10.0, 15.0, 10.0 ], 
            "faces": {
                "north": { "texture": "#2", "uv": [ 0.0, 0.0, 4.0, 1.0 ] },
                "east": { "texture": "#2", "uv": [ 0.0, 0.0, 4.0, 1.0 ] },
                "south": { "texture": "#2", "uv": [ 0.0, 0.0, 4.0, 1.0 ] },
                "west": { "texture": "#2", "uv": [ 0.0, 0.0, 4.0, 1.0 ] },
                "up": { "texture": "#2", "uv": [ 0.0, 0.0, 4.0, 4.0 ] },
                "down": { "texture": "#-1", "uv": [ 0.0, 0.0, 4.0, 4.0 ] }
            }
        },
        {
            "name": "pil_NW",
            "from": [ 5.0, 10.0, 5.0 ], 
            "to": [ 6.0, 16.0, 6.0 ], 
            "faces": {
                "north": { "texture": "#3", "uv": [ 1.0, 0.0, 4.0, 4.0 ] },
                "east": { "texture": "#3", "uv": [ 0.0, 0.0, 1.0, 6.0 ] },
                "south": { "texture": "#3", "uv": [ 0.0, 0.0, 1.0, 6.0 ] },
                "west": { "texture": "#3", "uv": [ 0.0, 0.0, 1.0, 6.0 ] },
                "up": { "texture": "#3", "uv": [ 0.0, 0.0, 1.0, 1.0 ] },
                "down": { "texture": "#3", "uv": [ 0.0, 0.0, 1.0, 1.0 ] }
            }
        },
        {
            "name": "pil_NE",
            "from": [ 10.0, 10.0, 5.0 ], 
            "to": [ 11.0, 16.0, 6.0 ], 
            "faces": {
                "north": { "texture": "#3", "uv": [ 0.0, 0.0, 1.0, 6.0 ] },
                "east": { "texture": "#3", "uv": [ 0.0, 0.0, 1.0, 6.0 ] },
                "south": { "texture": "#3", "uv": [ 0.0, 0.0, 1.0, 6.0 ] },
                "west": { "texture": "#3", "uv": [ 0.0, 0.0, 1.0, 6.0 ] },
                "up": { "texture": "#3", "uv": [ 0.0, 0.0, 1.0, 1.0 ] },
                "down": { "texture": "#3", "uv": [ 0.0, 0.0, 1.0, 1.0 ] }
            }
        },
        {
            "name": "pil_SW",
            "from": [ 5.0, 10.0, 10.0 ], 
            "to": [ 6.0, 16.0, 11.0 ], 
            "faces": {
                "north": { "texture": "#3", "uv": [ 0.0, 0.0, 1.0, 6.0 ] },
                "east": { "texture": "#3", "uv": [ 0.0, 0.0, 1.0, 6.0 ] },
                "south": { "texture": "#3", "uv": [ 0.0, 0.0, 1.0, 6.0 ] },
                "west": { "texture": "#3", "uv": [ 0.0, 0.0, 1.0, 6.0 ] },
                "up": { "texture": "#3", "uv": [ 0.0, 0.0, 1.0, 1.0 ] },
                "down": { "texture": "#3", "uv": [ 0.0, 0.0, 1.0, 1.0 ] }
            }
        },
        {
            "name": "pil_SE",
            "from": [ 10.0, 10.0, 10.0 ], 
            "to": [ 11.0, 16.0, 11.0 ], 
            "faces": {
                "north": { "texture": "#3", "uv": [ 0.0, 0.0, 1.0, 6.0 ] },
                "east": { "texture": "#3", "uv": [ 0.0, 0.0, 1.0, 6.0 ] },
                "south": { "texture": "#3", "uv": [ 0.0, 0.0, 1.0, 6.0 ] },
                "west": { "texture": "#3", "uv": [ 0.0, 0.0, 1.0, 6.0 ] },
                "up": { "texture": "#3", "uv": [ 0.0, 0.0, 1.0, 1.0 ] },
                "down": { "texture": "#3", "uv": [ 0.0, 0.0, 1.0, 1.0 ] }
            }
        },
        {
            "name": "pillar_top",
            "from": [ 6.0, 7.0, 6.0 ], 
            "to": [ 10.0, 12.0, 10.0 ], 
            "faces": {
                "north": { "texture": "#0", "uv": [ 0.0, 0.0, 16.0, 16.0 ] },
                "east": { "texture": "#0", "uv": [ 0.0, 0.0, 16.0, 16.0 ] },
                "south": { "texture": "#0", "uv": [ 0.0, 0.0, 16.0, 16.0 ] },
                "west": { "texture": "#0", "uv": [ 0.0, 0.0, 16.0, 16.0 ] },
                "up": { "texture": "#-1", "uv": [ 0.0, 0.0, 4.0, 4.0 ] },
                "down": { "texture": "#-1", "uv": [ 0.0, 0.0, 4.0, 4.0 ] }
            }
        }
    ]
}


 

item model:

{
   "parent": "ce:block/void_infuser"
}

 

Lastly, the block itself:

Spoiler

package com.unassigned.customenchants.blocks;

import com.unassigned.customenchants.CustomEnchants;
import com.unassigned.customenchants.blocks.base.BlockTEBase;
import com.unassigned.customenchants.blocks.tile.TileEntityVoidInfuser;
import com.unassigned.customenchants.blocks.tile.inventory.gui.GuiHandler;

import net.minecraft.block.material.Material;
import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.BlockRenderLayer;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.EnumHand;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;

public class BlockVoidInfuser extends BlockTEBase {

	public BlockVoidInfuser(String name, Material materialIn) {
		super(name, materialIn);
	}

	@Override
	public TileEntity createNewTileEntity(World worldIn, int meta) {
		return new TileEntityVoidInfuser();
	}
	
    @Override
    public boolean onBlockActivated(World world, BlockPos pos, IBlockState state, EntityPlayer player, EnumHand hand, EnumFacing par6, float par7, float par8, float par9){
        if(!world.isRemote){
            TileEntityVoidInfuser tile = (TileEntityVoidInfuser)world.getTileEntity(pos);
            if(tile != null){
                player.openGui(CustomEnchants.instance, GuiHandler.GuiTypes.VOID_INFUSER.ordinal(), world, pos.getX(), pos.getY(), pos.getZ());
            }
            return true;
        }
        return true;
    }
    
    @Override
    public boolean isFullCube(IBlockState state) {
    	return false;
    }
    
    @Override
    public boolean isOpaqueCube(IBlockState state) {
    	return false;
    }
    
    @Override
    public BlockRenderLayer getBlockLayer() {
    	return BlockRenderLayer.TRANSLUCENT;
    }

}

 

 

Thanks!

Edited by Lambda

Relatively new to modding.

Currently developing:

https://github.com/LambdaXV/DynamicGenerators

  • Author

 

Spoiler

 

For handling models, I use this class (which this block extends):

Spoiler


public abstract class BlockTEBase extends BlockContainer implements IModel {

	public BlockTEBase(String name, Material materialIn) {
		super(materialIn);
		
		setUnlocalizedName(name);
		setRegistryName(name);
		
		setCreativeTab(CustomEnchants.tabCustomEnchants);	
		
		ModBlocks.BLOCKS.add(this);
		ModItems.ITEMS.add(new ItemBlock(this).setRegistryName(this.getRegistryName()));
	}

	@Override
	public void registerModels() {
		CustomEnchants.proxy.registerItemRenderer(Item.getItemFromBlock(this), 0, "inventory");
	}
	
    private void dropInventory(World world, BlockPos position){
        if(!world.isRemote){
            TileEntity aTile = world.getTileEntity(position);
            if(aTile instanceof TileEntityContainerBase){
            	TileEntityContainerBase tile = (TileEntityContainerBase)aTile;
                if(tile.slots.getSlots() > 0){
                    for(int i = 0; i < tile.slots.getSlots(); i++){
                        this.dropSlotFromInventory(i, tile, world, position);
                    }
                }
            }
        }
    }
    
    private void dropSlotFromInventory(int i, TileEntityContainerBase tile, World world, BlockPos pos){
        ItemStack stack = tile.slots.getStackInSlot(i);
        if(ItemStackUtil.isValid(stack)){
            float dX = world.rand.nextFloat() * 0.5F + 0.1F;
            float dY = world.rand.nextFloat() * 0.5F + 0.1F;
            float dZ = world.rand.nextFloat() * 0.5F + 0.1F;
            EntityItem entityItem = new EntityItem(world, pos.getX()+dX, pos.getY()+dY, pos.getZ()+dZ, stack.copy());
            float factor = 0.025F;
            entityItem.motionX = world.rand.nextGaussian()*factor;
            entityItem.motionY = world.rand.nextGaussian()*factor+0.25F;
            entityItem.motionZ = world.rand.nextGaussian()*factor;
            world.spawnEntity(entityItem);
        }
    }

}

 

and IModel consisting of:


package com.unassigned.customenchants.util;

public interface IModel {

	public void registerModels();
}

 

and lastly,, the registry handler:


package com.unassigned.customenchants.util.handler;

import com.unassigned.customenchants.init.ModBlocks;
import com.unassigned.customenchants.init.ModItems;
import com.unassigned.customenchants.util.IModel;

import net.minecraft.block.Block;
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(modid="ce")
public class RegistryHandler {

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

 

 

Thanks

 

- EDIT:

After looking into my code more, I further realized that, as you mentioned, BlockContainer causes issues with my models, so i have removed the dependency and fixed the issue. Thanks for that.

 

 

 

EDIT 2:

Well after further testing, I find out that I cannot open/interact with my block, as if it doesnt have a TE. I have extended both but they dont seem to work.

here is the new base:

Spoiler

package com.unassigned.customenchants.blocks.base;

import com.unassigned.customenchants.CustomEnchants;
import com.unassigned.customenchants.blocks.tile.base.TileEntityContainerBase;
import com.unassigned.customenchants.init.ModBlocks;
import com.unassigned.customenchants.init.ModItems;
import com.unassigned.customenchants.util.IModel;
import com.unassigned.customenchants.util.ItemStackUtil;

import net.minecraft.block.Block;
import net.minecraft.block.BlockContainer;
import net.minecraft.block.material.Material;
import net.minecraft.entity.item.EntityItem;
import net.minecraft.item.Item;
import net.minecraft.item.ItemBlock;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;

public abstract class BlockTEBase extends Block implements IModel {

	public BlockTEBase(String name, Material materialIn) {
		super(materialIn);
		
		setUnlocalizedName(name);
		setRegistryName(name);
		
		setCreativeTab(CustomEnchants.tabCustomEnchants);	
		
		ModBlocks.BLOCKS.add(this);
		ModItems.ITEMS.add(new ItemBlock(this).setRegistryName(this.getRegistryName()));
		
	}

	@Override
	public void registerModels() {
		CustomEnchants.proxy.registerItemRenderer(Item.getItemFromBlock(this), 0, "inventory");
	}
	
    private void dropInventory(World world, BlockPos position){
        if(!world.isRemote){
            TileEntity aTile = world.getTileEntity(position);
            if(aTile instanceof TileEntityContainerBase){
            	TileEntityContainerBase tile = (TileEntityContainerBase)aTile;
                if(tile.slots.getSlots() > 0){
                    for(int i = 0; i < tile.slots.getSlots(); i++){
                        this.dropSlotFromInventory(i, tile, world, position);
                    }
                }
            }
        }
    }
    
    private void dropSlotFromInventory(int i, TileEntityContainerBase tile, World world, BlockPos pos){
        ItemStack stack = tile.slots.getStackInSlot(i);
        if(ItemStackUtil.isValid(stack)){
            float dX = world.rand.nextFloat() * 0.5F + 0.1F;
            float dY = world.rand.nextFloat() * 0.5F + 0.1F;
            float dZ = world.rand.nextFloat() * 0.5F + 0.1F;
            EntityItem entityItem = new EntityItem(world, pos.getX()+dX, pos.getY()+dY, pos.getZ()+dZ, stack.copy());
            float factor = 0.025F;
            entityItem.motionX = world.rand.nextGaussian()*factor;
            entityItem.motionY = world.rand.nextGaussian()*factor+0.25F;
            entityItem.motionZ = world.rand.nextGaussian()*factor;
            world.spawnEntity(entityItem);
        }
    }
    
	@Override
	public boolean hasTileEntity() {
		return true;
	}
	

}

 

and here is the new block itself:

package com.unassigned.customenchants.blocks;

import com.unassigned.customenchants.CustomEnchants;
import com.unassigned.customenchants.blocks.base.BlockTEBase;
import com.unassigned.customenchants.blocks.tile.TileEntityVoidInfuser;
import com.unassigned.customenchants.blocks.tile.inventory.gui.GuiHandler;

import net.minecraft.block.material.Material;
import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.BlockRenderLayer;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.EnumHand;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;

public class BlockVoidInfuser extends BlockTEBase {

	public BlockVoidInfuser(String name, Material materialIn) {
		super(name, materialIn);
	}
	
	@Override
	public TileEntity createTileEntity(World world, IBlockState state) {
		return new TileEntityVoidInfuser();	
	}

    @Override
    public boolean onBlockActivated(World world, BlockPos pos, IBlockState state, EntityPlayer player, EnumHand hand, EnumFacing par6, float par7, float par8, float par9){
        if(!world.isRemote){
            TileEntityVoidInfuser tile = (TileEntityVoidInfuser)world.getTileEntity(pos);
            if(tile != null){
                player.openGui(CustomEnchants.instance, GuiHandler.GuiTypes.VOID_INFUSER.ordinal(), world, pos.getX(), pos.getY(), pos.getZ());
            }
            return true;
        }
        return true;
    }
    
    @Override
    public boolean isFullCube(IBlockState state) {
    	return false;
    }
    
    @Override
    public boolean isOpaqueCube(IBlockState state) {
    	return false;
    }
    
    @Override
    public BlockRenderLayer getBlockLayer() {
    	return BlockRenderLayer.CUTOUT;
    }



}

 

Edited by Lambda

Relatively new to modding.

Currently developing:

https://github.com/LambdaXV/DynamicGenerators

You're not overriding Block::hasTileEntitywhich is required for Minecraft to run Block::createTileEntity.

As stated in Problematic Code #4, you need to override both.

Also previously known as eAndPi.

"Pi, is there a station coming up where we can board your train of thought?" -Kronnn

Published Mods: Underworld

Handy links: Vic_'s Forge events Own WIP Tutorials.

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...

Important Information

By using this site, you agree to our Terms of Use.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.