Jump to content

Recommended Posts

Posted

Hi Guys,

 

I'm trying to create my own cauldron so that it will do 2 things differently than the vanilla cauldron.

 

1) Hold 16 levels of water instead of 4

2) Render the 16 levels of water

 

I have been able to accomplish this with ease, by testing my edits on the base class files, so I know for sure what stuff to change in my copy-and-pastes. My main problem is I don't quite understand how to make my own Custom Cauldron block override the RenderBlocks.java method that vanilla Cauldron uses.

 

Basically what happens is... I can place my Custom Cauldron, and it behaves as though it has 16 levels of water... but the actual rendering method being called is the vanilla Cauldron's, in RenderBlocks.java... so the water tile levels show up, behave the way vanilla's cauldron does.

 

I've created a RenderCustomCauldron class that I would like BlockCustomCauldron to use... but I must be overlooking something fairly simple... like registering something in the Registry or Proxies.

 

Or perhaps I'm not understanding how to override the method in RenderBlocks.java.

 

I would really appreciate any insights or help you can offer on this. Here's my code, if you don't mind taking a look at it:

 

ModRegistry:

 

package khufu.pack;
import net.minecraft.src.Block;
import net.minecraft.src.CreativeTabs;
import net.minecraftforge.common.Configuration;
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.Mod.PostInit;
import cpw.mods.fml.common.Mod.PreInit;
import cpw.mods.fml.common.SidedProxy;
import cpw.mods.fml.common.event.FMLInitializationEvent;
import cpw.mods.fml.common.event.FMLPostInitializationEvent;
import cpw.mods.fml.common.event.FMLPreInitializationEvent;
import cpw.mods.fml.common.network.NetworkMod;
import cpw.mods.fml.common.registry.GameRegistry;
import cpw.mods.fml.common.registry.LanguageRegistry;
@Mod(modid = "khufu", name = "Khufu", version = "1.0")
@NetworkMod(clientSideRequired = true, serverSideRequired = false)
public class ModRegistry {

@Instance("khufu")
public static ModRegistry instance;


@SidedProxy(clientSide = "khufu.pack.client.ClientProxy", serverSide = "khufu.pack.CommonProxy")
public static CommonProxy proxy;
public static Block khufucauldron;
public static int khufuCauldronID;
public static String configDir;

@PreInit
public void preInit(FMLPreInitializationEvent event) {
configDir = event.getModConfigurationDirectory().getAbsolutePath();
Configuration config = new Configuration(event.getSuggestedConfigurationFile());
config.load();
khufuCauldronID = config.get(config.CATEGORY_BLOCK,"Cauldron Block ID", 600).getInt(600);
config.save();
}
@Init
public void load(FMLInitializationEvent event) {

proxy.registerRenderInformation();
// proxy.registerRenderers();
// proxy.registerEntites();

khufucauldron = new BlockKhufuCauldron(khufuCauldronID).setBlockName("khufucauldron").setCreativeTab(CreativeTabs.tabBrewing);

GameRegistry.registerBlock(khufucauldron);

LanguageRegistry.addName(khufucauldron, "Khufu Cauldron");

}


@PostInit
public void postInit(FMLPostInitializationEvent event) {

}

}

 

 

 

CommonProxy:

 

package khufu.pack;

public class CommonProxy
{

public void registerRenderers () {
}
public void registerEntites() {
}

public void registerRenderInformation() {
}
}

 

 

 

BlockKhufuCauldron:

 

package khufu.pack;
import java.util.List;
import java.util.Random;
import net.minecraft.src.AxisAlignedBB;
import net.minecraft.src.BlockCauldron;
import net.minecraft.src.Entity;
import net.minecraft.src.EntityItem;
import net.minecraft.src.EntityPlayer;
import net.minecraft.src.EntityPlayerMP;
import net.minecraft.src.EnumArmorMaterial;
import net.minecraft.src.Item;
import net.minecraft.src.ItemArmor;
import net.minecraft.src.ItemStack;
import net.minecraft.src.World;
import cpw.mods.fml.common.Side;
import cpw.mods.fml.common.asm.SideOnly;
public class BlockKhufuCauldron extends BlockCauldron
{
public BlockKhufuCauldron(int par1)
{
//     super(par1, Material.iron); (Had to change this line because of extends BlockCauldron did not expect Material)
     super(par1);
     this.blockIndexInTexture = 154;
}


/**
     * From the specified side and block metadata retrieves the blocks texture. Args: side, metadata
     */
public int getBlockTextureFromSideAndMetadata(int par1, int par2)
{
     return par1 == 1 ? 138 : (par1 == 0 ? 155 : 154);
}


/**
     * if the specified block is in the given AABB, add its collision bounding box to the given list
     */
public void addCollidingBlockToList(World par1World, int par2, int par3, int par4, AxisAlignedBB par5AxisAlignedBB, List par6List, Entity par7Entity)
{
     this.setBlockBounds(0.0F, 0.0F, 0.0F, 1.0F, 0.3125F, 1.0F);
     super.addCollidingBlockToList(par1World, par2, par3, par4, par5AxisAlignedBB, par6List, par7Entity);
     float var8 = 0.125F;
     this.setBlockBounds(0.0F, 0.0F, 0.0F, var8, 1.0F, 1.0F);
     super.addCollidingBlockToList(par1World, par2, par3, par4, par5AxisAlignedBB, par6List, par7Entity);
     this.setBlockBounds(0.0F, 0.0F, 0.0F, 1.0F, 1.0F, var8);
     super.addCollidingBlockToList(par1World, par2, par3, par4, par5AxisAlignedBB, par6List, par7Entity);
     this.setBlockBounds(1.0F - var8, 0.0F, 0.0F, 1.0F, 1.0F, 1.0F);
     super.addCollidingBlockToList(par1World, par2, par3, par4, par5AxisAlignedBB, par6List, par7Entity);
     this.setBlockBounds(0.0F, 0.0F, 1.0F - var8, 1.0F, 1.0F, 1.0F);
     super.addCollidingBlockToList(par1World, par2, par3, par4, par5AxisAlignedBB, par6List, par7Entity);
     this.setBlockBoundsForItemRender();
}


/**
     * Sets the block's bounds for rendering it as an item
     */
public void setBlockBoundsForItemRender()
{
     this.setBlockBounds(0.0F, 0.0F, 0.0F, 1.0F, 1.0F, 1.0F);
}

/**
     * Is this block (a) opaque and (B) a full 1m cube? This determines whether or not to render the shared face of two
     * adjacent blocks and also whether the player can attach torches, redstone wire, etc to this block.
     */
public boolean isOpaqueCube()
{
     return false;
}


/**
     * The type of render function that is called for this block
     */
public int getRenderType()
{
     return 24;
}
    
/**
     * If this block doesn't render as an ordinary block it will return False (examples: signs, buttons, stairs, etc)
     */
public boolean renderAsNormalBlock()
{
     return false;
}


/**
     * Called upon block activation (right click on the block.)
     */
public boolean onBlockActivated(World par1World, int par2, int par3, int par4, EntityPlayer par5EntityPlayer, int par6, float par7, float par8, float par9)
{
     if (par1World.isRemote)
     {
         return true;
     }
     else
     {
         ItemStack var10 = par5EntityPlayer.inventory.getCurrentItem();
         if (var10 == null)
         {
             return true;
         }
         else
         {
             int var11 = par1World.getBlockMetadata(par2, par3, par4);
             if (var10.itemID == Item.bucketWater.shiftedIndex)
             {
//                 if (var11 < 3) (This line checks the Cauldron's metadata to see if it is less than the maximum (Cauldron not "full")... I changed the maximum to 15)
                 if (var11 < 15)
                 {
                     if (!par5EntityPlayer.capabilities.isCreativeMode)
                     {
                         par5EntityPlayer.inventory.setInventorySlotContents(par5EntityPlayer.inventory.currentItem, new ItemStack(Item.bucketEmpty));
                     }
//                     par1World.setBlockMetadataWithNotify(par2, par3, par4, 3); (Changed the Cauldron's maximum meta to 15 upon bucket of water filling it up.)
                     par1World.setBlockMetadataWithNotify(par2, par3, par4, 15);
                 }
                 return true;
             }
             else
             {
                 if (var10.itemID == Item.glassBottle.shiftedIndex)
                 {
                     if (var11 > 0)
                     {
                         ItemStack var12 = new ItemStack(Item.potion, 1, 0);
                         if (!par5EntityPlayer.inventory.addItemStackToInventory(var12))
                         {
                             par1World.spawnEntityInWorld(new EntityItem(par1World, (double)par2 + 0.5D, (double)par3 + 1.5D, (double)par4 + 0.5D, var12));
                         }
                         else if (par5EntityPlayer instanceof EntityPlayerMP)
                         {
                             ((EntityPlayerMP)par5EntityPlayer).sendContainerToPlayer(par5EntityPlayer.inventoryContainer);
                         }
                         --var10.stackSize;
                         if (var10.stackSize <= 0)
                         {
                             par5EntityPlayer.inventory.setInventorySlotContents(par5EntityPlayer.inventory.currentItem, (ItemStack)null);
                         }
                         par1World.setBlockMetadataWithNotify(par2, par3, par4, var11 - 1);
                     }
                 }
                 else if (var11 > 0 && var10.getItem() instanceof ItemArmor && ((ItemArmor)var10.getItem()).getArmorMaterial() == EnumArmorMaterial.CLOTH)
                 {
                     ItemArmor var13 = (ItemArmor)var10.getItem();
                     var13.removeColor(var10);
                     par1World.setBlockMetadataWithNotify(par2, par3, par4, var11 - 1);
                     return true;
                 }
                 return true;
             }
         }
     }
}
/**
     * currently only used by BlockCauldron to incrament meta-data during rain
     */
public void fillWithRain(World par1World, int par2, int par3, int par4)
{
     if (par1World.rand.nextInt(20) == 1)
     {
         int var5 = par1World.getBlockMetadata(par2, par3, par4);
//         if (var5 < 3) (If the cauldron is less than full.)
         if (var5 < 15)
         {
             par1World.setBlockMetadataWithNotify(par2, par3, par4, var5 + 1);
         }
     }
}
/**
     * Returns the ID of the items to drop on destruction.
     */
public int idDropped(int par1, Random par2Random, int par3)
{
     return Item.cauldron.shiftedIndex;
//     This should probably be changed to my new Khufu Cauldron when I get that far.
}
@SideOnly(Side.CLIENT)
/**
     * only called by clickMiddleMouseButton , and passed to inventory.setCurrentItem (along with isCreative)
     */
public int idPicked(World par1World, int par2, int par3, int par4)
{
     return Item.cauldron.shiftedIndex;
//     This should probably be changed to my new Khufu Cauldron when I get that far.
}
}

 

 

 

RenderKhufuCauldron:

 


package khufu.pack.client;

import khufu.pack.BlockKhufuCauldron;
import net.minecraft.src.Block;
import net.minecraft.src.BlockAnvil;
import net.minecraft.src.BlockBeacon;
import net.minecraft.src.BlockBrewingStand;
import net.minecraft.src.BlockCocoa;
import net.minecraft.src.BlockDragonEgg;
import net.minecraft.src.BlockFence;
import net.minecraft.src.BlockFenceGate;
import net.minecraft.src.BlockFlowerPot;
import net.minecraft.src.BlockPane;
import net.minecraft.src.BlockRail;
import net.minecraft.src.BlockStairs;
import net.minecraft.src.BlockWall;
import net.minecraft.src.EntityRenderer;
import net.minecraft.src.FMLRenderAccessLibrary;
import net.minecraft.src.IBlockAccess;
import net.minecraft.src.RenderBlocks;
import net.minecraft.src.Tessellator;
import cpw.mods.fml.common.Side;
import cpw.mods.fml.common.asm.SideOnly;

@SideOnly(Side.CLIENT)
public class RenderKhufuCauldron extends RenderBlocks
{


@Override
/**
* Renders the block at the given coordinates using the block's rendering type
*/
public boolean renderBlockByRenderType(Block par1Block, int par2, int par3, int par4)
{
int var5 = par1Block.getRenderType();
par1Block.setBlockBoundsBasedOnState(this.blockAccess, par2, par3, par4);
this.func_83018_a(par1Block);
switch (var5)
{
case 0:
return this.renderStandardBlock(par1Block, par2, par3, par4);
case 31:
return this.renderBlockLog(par1Block, par2, par3, par4);
case 4:
return this.renderBlockFluids(par1Block, par2, par3, par4);
case 13:
return this.renderBlockCactus(par1Block, par2, par3, par4);
case 1:
return this.renderCrossedSquares(par1Block, par2, par3, par4);
case 19:
return this.renderBlockStem(par1Block, par2, par3, par4);
case 23:
return this.renderBlockLilyPad(par1Block, par2, par3, par4);
case 6:
return this.renderBlockCrops(par1Block, par2, par3, par4);
case 2:
return this.renderBlockTorch(par1Block, par2, par3, par4);
case 3:
return this.renderBlockFire(par1Block, par2, par3, par4);
case 5:
return this.renderBlockRedstoneWire(par1Block, par2, par3, par4);
case 8:
return this.renderBlockLadder(par1Block, par2, par3, par4);
case 7:
return this.renderBlockDoor(par1Block, par2, par3, par4);
case 9:
return this.renderBlockMinecartTrack((BlockRail)par1Block, par2, par3, par4);
case 10:
return this.renderBlockStairs((BlockStairs)par1Block, par2, par3, par4);
case 27:
return this.renderBlockDragonEgg((BlockDragonEgg)par1Block, par2, par3, par4);
case 11:
return this.renderBlockFence((BlockFence)par1Block, par2, par3, par4);
case 32:
return this.renderBlockWall((BlockWall)par1Block, par2, par3, par4);
case 12:
return this.renderBlockLever(par1Block, par2, par3, par4);
case 29:
return this.renderBlockTripWireSource(par1Block, par2, par3, par4);
case 30:
return this.renderBlockTripWire(par1Block, par2, par3, par4);
case 14:
return this.renderBlockBed(par1Block, par2, par3, par4);
case 15:
return this.renderBlockRepeater(par1Block, par2, par3, par4);
case 16:
return this.renderPistonBase(par1Block, par2, par3, par4, false);
case 17:
return this.renderPistonExtension(par1Block, par2, par3, par4, true);
case 18:
return this.renderBlockPane((BlockPane)par1Block, par2, par3, par4);
case 20:
return this.renderBlockVine(par1Block, par2, par3, par4);
case 21:
return this.renderBlockFenceGate((BlockFenceGate)par1Block, par2, par3, par4);
case 24:
return this.renderBlockCauldron((BlockKhufuCauldron)par1Block, par2, par3, par4);
case 33:
return this.renderBlockFlowerpot((BlockFlowerPot)par1Block, par2, par3, par4);
case 35:
return this.renderBlockAnvil((BlockAnvil)par1Block, par2, par3, par4);
case 25:
return this.renderBlockBrewingStand((BlockBrewingStand)par1Block, par2, par3, par4);
case 26:
return this.renderBlockEndPortalFrame(par1Block, par2, par3, par4);
case 28:
return this.renderBlockCocoa((BlockCocoa)par1Block, par2, par3, par4);
case 34:
return this.renderBlockBeacon((BlockBeacon)par1Block, par2, par3, par4);
default:
return FMLRenderAccessLibrary.renderWorldBlock(this, blockAccess, par2, par3, par4, par1Block, var5);
}
}




/**
* Render block cauldron
*/
public boolean renderBlockCauldron(BlockKhufuCauldron par1BlockCauldron, int par2, int par3, int par4)
{
this.renderStandardBlock(par1BlockCauldron, par2, par3, par4);
Tessellator var5 = Tessellator.instance;
var5.setBrightness(par1BlockCauldron.getMixedBrightnessForBlock(this.blockAccess, par2, par3, par4));
float var6 = 1.0F;
int var7 = par1BlockCauldron.colorMultiplier(this.blockAccess, par2, par3, par4);
float var8 = (float)(var7 >> 16 & 255) / 255.0F;
float var9 = (float)(var7 >> 8 & 255) / 255.0F;
float var10 = (float)(var7 & 255) / 255.0F;
float var12;

if (EntityRenderer.anaglyphEnable)
{
float var11 = (var8 * 30.0F + var9 * 59.0F + var10 * 11.0F) / 100.0F;
var12 = (var8 * 30.0F + var9 * 70.0F) / 100.0F;
float var13 = (var8 * 30.0F + var10 * 70.0F) / 100.0F;
var8 = var11;
var9 = var12;
var10 = var13;
}

var5.setColorOpaque_F(var6 * var8, var6 * var9, var6 * var10);
short var16 = 154;
var12 = 0.125F;
this.renderSouthFace(par1BlockCauldron, (double)((float)par2 - 1.0F + var12), (double)par3, (double)par4, var16);
this.renderNorthFace(par1BlockCauldron, (double)((float)par2 + 1.0F - var12), (double)par3, (double)par4, var16);
this.renderWestFace(par1BlockCauldron, (double)par2, (double)par3, (double)((float)par4 - 1.0F + var12), var16);
this.renderEastFace(par1BlockCauldron, (double)par2, (double)par3, (double)((float)par4 + 1.0F - var12), var16);
short var17 = 139;
this.renderTopFace(par1BlockCauldron, (double)par2, (double)((float)par3 - 1.0F + 0.25F), (double)par4, var17);
this.renderBottomFace(par1BlockCauldron, (double)par2, (double)((float)par3 + 1.0F - 0.75F), (double)par4, var17);
int var14 = this.blockAccess.getBlockMetadata(par2, par3, par4);

if (var14 > 0)
{
short var15 = 205;

// if (var14 > 3) (Maximizes the Cauldron's meta)
if (var14 > 15)
{
// var14 = 3;
var14 = 15;
}


// This line determines how high the Water Tile is rendered, and determines the increments it lowers as the Cauldron's meta data is incrementally decreased.
// this.renderTopFace(par1BlockCauldron, (double)par2, (double)((float)par3 - 1.0F + (6.0F + (float)var14 * 0.75F) / 16.0F), (double)par4, var15);
this.renderTopFace(par1BlockCauldron, (double)par2, (double)((float)par3 - 1.0F + (3.6875F + (float)var14 * 0.75F) / 16.0F), (double)par4, var15);


}

return true;
}
}

 

 

ClientProxy:


package khufu.pack.client;
import khufu.pack.CommonProxy;
public class ClientProxy extends CommonProxy {

@Override
public void registerRenderers() {

}

@Override
public void registerRenderInformation() {

}

@Override
public void registerEntites() {

}

}

 

Posted

In your Block Class don't return 24 for "getRenderType()" but "RenderKhufuCauldron.renderID"

Then add this to your RenderKhufuCauldron class:

 

public static final int renderID =  RenderingRegistry.getNextAvailableRenderId();

 

 

This will get a free renderID for the renderer and the "getRenderType()" in your Block Class will return it as the render for your 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.