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

Hi there, I am trying to make a block with a custom model using the latest recommended build of Forge.

 

For some reason, the block in the player's hand is a grey grass-top texture, and when the block is placed, it is a bounding box with nothing inside it.

 

Any help would be appreciated.

 

BaseWaterdude.java

package com.waterdude.mod;

import net.minecraft.block.Block;
import net.minecraft.client.renderer.RenderBlocks;
import net.minecraft.client.renderer.tileentity.TileEntityRenderer;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.item.Item;
import net.minecraft.src.ModLoader;
import cpw.mods.fml.client.registry.RenderingRegistry;
import cpw.mods.fml.common.Mod;
import cpw.mods.fml.common.Mod.Init;
import cpw.mods.fml.common.Mod.Instance;
import cpw.mods.fml.common.event.FMLInitializationEvent;
import cpw.mods.fml.common.network.NetworkMod;
import cpw.mods.fml.common.network.NetworkRegistry;
import cpw.mods.fml.common.registry.GameRegistry;
import cpw.mods.fml.common.registry.LanguageRegistry;
import cpw.mods.fml.common.network.NetworkMod.SidedPacketHandler;
import cpw.mods.fml.common.SidedProxy;

import com.waterdude.mod.blocks.BlockArcaneFurnace;
import com.waterdude.mod.blocks.BlockMVBattery;
import com.waterdude.mod.blocks.BlockOre1;
import com.waterdude.mod.core.handlers.ClientPacketHandler;
import com.waterdude.mod.core.handlers.GuiHandler;
import com.waterdude.mod.core.handlers.ServerPacketHandler;
import com.waterdude.mod.core.CommonProxy;
import com.waterdude.mod.core.TileEntityArcaneFurnace;
import com.waterdude.mod.core.TileEntityMVBattery;
import com.waterdude.mod.core.IBlockRenderer;
import com.waterdude.mod.core.WorldGenMinableW;
import com.waterdude.mod.items.ItemEnergyDust;
import com.waterdude.mod.items.ItemFusedDust;
import com.waterdude.mod.items.ItemMVBattery;

@NetworkMod(clientSideRequired=true,serverSideRequired=false,

clientPacketHandlerSpec = @SidedPacketHandler(channels = {"TutorialGeneral" }, packetHandler = ClientPacketHandler.class), 
serverPacketHandlerSpec = @SidedPacketHandler(channels = {}, packetHandler = ServerPacketHandler.class)) 

@Mod(modid="ManaAndMagic",name="Mana and Magic",version="1.0.0") 

public class BaseWaterdude 
{ 

@Instance("ManaAndMagic")
public static BaseWaterdude instance = new BaseWaterdude();

@SidedProxy(clientSide = "com.waterdude.mod.core.ClientProxy", serverSide = "com.waterdude.mod.core.CommonProxy")
public static CommonProxy proxy;

public static Item itemFusedDust = new ItemFusedDust(17050).setIconIndex(0).setTextureFile("/ManaAndMagic/WaterdudeItems.png");
public static Item itemEnergyDust = new ItemEnergyDust(17051).setIconIndex(1).setTextureFile("/ManaAndMagic/WaterdudeItems.png");
//public static Item mvbItem = new ItemMVBattery(17052).setIconIndex(2).setTextureFile("/ManaAndMagic/WaterdudeItems.png");

public static Block blockOre1 = new BlockOre1(180);
public static Block afActive = new BlockArcaneFurnace(182, true).setHardness(3.5F).setStepSound(Block.soundStoneFootstep).setBlockName("afActive").setRequiresSelfNotify().setLightValue(0.875F);
public static Block afIdle = new BlockArcaneFurnace(181, false).setHardness(3.5F).setStepSound(Block.soundStoneFootstep).setBlockName("afIdle").setRequiresSelfNotify().setCreativeTab(CreativeTabs.tabMisc);

private GuiHandler guiHandler = new GuiHandler();

public static int mvbRenderID;
public static int mvbTexture;

public void renderInvBlock(RenderBlocks var1, Block var2, int var3, int var4)
{
	renderInvBlock(var1, var2, var3, var4);

	if (var2 == mvb)
	{
		TileEntityRenderer.instance.renderTileEntityAt(new TileEntityMVBattery(), 0.0D, 0.0D, 0.0D, 0.0F);
	}
}

@Init
public void Init(FMLInitializationEvent event)
{ 
	RenderingRegistry.registerBlockHandler(new IBlockRenderer());
     
    mvbRenderID = RenderingRegistry.getNextAvailableRenderId();

	NetworkRegistry.instance().registerGuiHandler(this, proxy); 
	GameRegistry.registerWorldGenerator(new WorldGenMinableW());

	NetworkRegistry.instance().registerGuiHandler(this, guiHandler);
	GameRegistry.registerTileEntity(TileEntityArcaneFurnace.class,"tileEntityArcaneFurnace");

	proxy.registerBlocks();
	proxy.addNames();
	proxy.addRecipes();
	proxy.registerRenderInformation();
}

public static Block mvb = new BlockMVBattery(183, mvbRenderID, TileEntityMVBattery.class).setHardness(4.5F).setStepSound(Block.soundMetalFootstep).setBlockName("mvb").setRequiresSelfNotify().setCreativeTab(CreativeTabs.tabMisc);

}

 

ModelMVBattery.java

package com.waterdude.mod.core;

import net.minecraft.client.model.ModelBase;
import net.minecraft.client.model.ModelRenderer;
import net.minecraft.entity.Entity;

public class ModelMVBattery extends ModelBase
{
  //fields
    ModelRenderer Shape1;
    ModelRenderer Shape2;
    ModelRenderer Shape3;
    ModelRenderer Shape4;
    ModelRenderer Shape5;
  
  public ModelMVBattery()
  {
    textureWidth = 64;
    textureHeight = 32;
    
      Shape1 = new ModelRenderer(this, 19, 0);
      Shape1.addBox(0F, 0F, 0F, 6, 1, 6);
      Shape1.setRotationPoint(-3F, 23F, -3F);
      Shape1.setTextureSize(64, 32);
      Shape1.mirror = true;
      setRotation(Shape1, 0F, 0F, 0F);
      Shape2 = new ModelRenderer(this, 0, 5);
      Shape2.addBox(0F, 0F, 0F, 4, 3, 4);
      Shape2.setRotationPoint(-2F, 20F, -2F);
      Shape2.setTextureSize(64, 32);
      Shape2.mirror = true;
      setRotation(Shape2, 0F, 0F, 0F);
      Shape3 = new ModelRenderer(this, 19, ;
      Shape3.addBox(0F, 0F, 0F, 6, 1, 6);
      Shape3.setRotationPoint(-3F, 19F, -3F);
      Shape3.setTextureSize(64, 32);
      Shape3.mirror = true;
      setRotation(Shape3, 0F, 0F, 0F);
      Shape4 = new ModelRenderer(this, 0, 13);
      Shape4.addBox(0F, 0F, 0F, 4, 3, 4);
      Shape4.setRotationPoint(-2F, 16F, -2F);
      Shape4.setTextureSize(64, 32);
      Shape4.mirror = true;
      setRotation(Shape4, 0F, 0F, 0F);
      Shape5 = new ModelRenderer(this, 19, 16);
      Shape5.addBox(0F, 0F, 0F, 6, 1, 6);
      Shape5.setRotationPoint(-3F, 15F, -3F);
      Shape5.setTextureSize(64, 32);
      Shape5.mirror = true;
      setRotation(Shape5, 0F, 0F, 0F);
  }
  
  public void render(Entity entity, float f, float f1, float f2, float f3, float f4, float f5)
  {
    super.render(entity, f, f1, f2, f3, f4, f5);
    Shape1.render(f5);
    Shape2.render(f5);
    Shape3.render(f5);
    Shape4.render(f5);
    Shape5.render(f5);
  }
  public void renderModel(float f5)
  {
    Shape1.render(f5);
    Shape2.render(f5);
    Shape3.render(f5);
    Shape4.render(f5);
    Shape5.render(f5);
  }
  private void setRotation(ModelRenderer model, float x, float y, float z)
  {
    model.rotateAngleX = x;
    model.rotateAngleY = y;
    model.rotateAngleZ = z;
  }

}

 

BlockMVBattery.java

package com.waterdude.mod.blocks;

import java.util.List;
import java.util.Random;

import net.minecraft.block.BlockContainer;
import net.minecraft.block.material.Material;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.MathHelper;
import net.minecraft.world.World;

import com.waterdude.mod.BaseWaterdude;
import com.waterdude.mod.core.TileEntityMVBattery;

public class BlockMVBattery extends BlockContainer
{
public BlockMVBattery(int par1, int par2, Class class1)
{

	super(par1, par2, Material.rock);
	this.setCreativeTab(CreativeTabs.tabMisc);
	this.setRequiresSelfNotify();

}


/*public int idDropped()
{
	return BaseWaterdude.mvbItem.itemID;
}*/



public int quantityDropped(Random par1Random)
{
	return 1;
}

    @Override
    public int getRenderType()
    {
        
        return BaseWaterdude.mvbRenderID;
    }


public boolean isOpaqueCube() 
{
	return false;
} 

public boolean renderAsNormalBlock() 
{
	return false;
} 

public TileEntity getBlockEntity() 
{
	return new TileEntityMVBattery();

}


public TileEntity createNewTileEntity(World var1)
{
	return new TileEntityMVBattery();

}


}

 

IBlockRenderer (got this from the wiki, not too sure on it)

package com.waterdude.mod.core;

import com.waterdude.mod.BaseWaterdude;

import net.minecraft.block.Block;
import net.minecraft.client.renderer.RenderBlocks;
import net.minecraft.client.renderer.tileentity.TileEntityRenderer;
import net.minecraft.world.IBlockAccess;
import cpw.mods.fml.client.registry.ISimpleBlockRenderingHandler;

public class IBlockRenderer implements ISimpleBlockRenderingHandler
{
    public void renderInventoryBlock(Block block, int metadata, int modelID, RenderBlocks renderer)
    {
	renderInventoryBlock(block, metadata, modelID, renderer);

	if (block == BaseWaterdude.mvb)
	{
		TileEntityRenderer.instance.renderTileEntityAt(new TileEntityMVBattery(), 0.0D, 0.0D, 0.0D, 0.0F);
	}
         
    }

    public boolean renderWorldBlock(IBlockAccess world, int x, int y, int z, Block block, int modelId, RenderBlocks renderer)
    {
         // Your renderring code
         return false;
    }

    public boolean shouldRender3DInInventory()
    {
         // This is where it asks if you want the renderInventory part called or not.
         return true; // Change to 'true' if you want the Inventory render to be called.
    }

    public int getRenderId()
    {
         // This is one place we need that renderId from earlier.
         return BaseWaterdude.mvbRenderID;
    }
}

 

TileEntityMVBattery.java

package com.waterdude.mod.core;

import net.minecraft.tileentity.TileEntity;

public class TileEntityMVBattery extends TileEntity
{
public TileEntityMVBattery()
{

} 
}

 

TileEntityMVBatteryRenderer.java

package com.waterdude.mod.core;

import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer;
import net.minecraft.tileentity.TileEntity;

import java.util.Random;

import org.lwjgl.opengl.GL11;

public class TileEntityMVBatteryRenderer extends TileEntitySpecialRenderer
{
private ModelMVBattery model;

public TileEntityMVBatteryRenderer()
{
	model = new ModelMVBattery();
}

public void renderAModelAt(TileEntityMVBattery tile, double d, double d1, double d2, float f)
{
	int i =0;

	if(tile.worldObj != null) 
	{
		i =(tile.worldObj.getBlockMetadata(tile.xCoord, tile.yCoord, tile.zCoord)); 
	}

	bindTextureByName("/ManaAndMagic/mvb.png");

	GL11.glPushMatrix(); 
	GL11.glTranslatef((float)d + 0.5F, (float)d1 + 1.5F, (float)d2 + 0.5F);
	GL11.glRotatef(0, 0.0F, 1.0F, 0.0F); 
	GL11.glScalef(1.0F, -1F, -1F); 
	model.renderModel(0.0625F); 
	GL11.glPopMatrix(); 
}



public void renderTileEntityAt(TileEntity tileentity, double d, double d1, double d2, float f)
{
	renderAModelAt((TileEntityMVBattery) tileentity, d, d1, d2, f);
}
}

 

If you need to see any other classes, just ask.

 

  • Author

UPDATE: Got the model to render in the world, but now I need to know how to render it in the player's hand.

Anybody have any idea how he fixed this? im stuck at the same point, and i just dont understand minecraft coding well enough yet to see the fix for the invisible block.

How is the item rendering not causing an infinite loop? You call the method within the method...within the method...within the method...etc.

 

Either way that's probably your problem so try commenting it out. (put '//' in front of it)

 

Unless there's a 'super' in front of that you removed for some reason but I don't think that works either.

I found this thread that might help shed some light on things: http://www.minecraftforge.net/forum/index.php/topic,3389.0.html

 

I'm not sure how good the solved code is nowadays, but some things I noticed:

 

-Since a Tile Entity is involved, it might be better to use a custom Tile Entity renderer, like they mention and write an example of later in the thread, rather than use the block rendering handlers.

-BlockVelvetTable.java, which extends BlockContainer, uses the getTextureFile() method we're more familiar with. Maybe BlockMVBattery.java should do the same, since it also extends BlockContainer?

IT WORKED!!!! sorry for all caps. thank you thank you thank you. I just had to add

ClientRegistry.bindTileEntitySpecialRenderer(TileEntitySuperCalc.class, new RenderSuperCalc());

to the client proxy. now how do I change to collision bounds so they just take up the area that the block is in.

I already got that to work but I can't get collision box to be correct. is there a way to make the block get the collision from model file?

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.