Jump to content

Recommended Posts

Posted

Good day once again,

I made a custom furnace recently, everything works fine except two things.

The first problem is that my machine won't rotate towards the player.

The second problem is that it doesn't change texture when active.

 

Here's the Block class for ya:

package elementum;

import java.util.Random;
import elementum.Elementum;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import net.minecraft.block.Block;
import net.minecraft.block.BlockContainer;
import net.minecraft.block.material.Material;
import net.minecraft.client.renderer.texture.IconRegister;
import net.minecraft.entity.EntityLiving;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.item.EntityItem;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.Container;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.Icon;
import net.minecraft.util.MathHelper;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;

public class BlockCellingMachine extends BlockContainer
{
    private Random inputFurnaceRand;
    private final boolean isActive;
    private static boolean keepInputFurnaceInventory = false;
    private static String textureName;
    
    @SideOnly(Side.CLIENT)
    private Icon topTexture;
    private Icon frontTexture;
    private Icon frontTextureActive;

    public BlockCellingMachine(int i, boolean flag)
    {
        super(i, Material.iron);
        inputFurnaceRand = new Random();
        isActive = flag;
        this.textureName = "cellingMachine";
    }

    @SideOnly(Side.CLIENT)
    public void registerIcons(IconRegister Icon)
    {
        this.blockIcon = Icon.registerIcon(Elementum.modid + ":" + textureName);
        this.frontTexture = Icon.registerIcon(Elementum.modid + ":" + textureName + "_front_off");
        this.frontTextureActive = Icon.registerIcon(Elementum.modid + ":" + textureName + "_front_on");
        this.topTexture = Icon.registerIcon(Elementum.modid + ":" + textureName + "_top");
    }

    @SideOnly(Side.CLIENT)
    public Icon getIcon(int side, int meta){
    	
    	if(side == 1){
    		return this.topTexture;
    	}
    	if(side == 3 && isActive){
    		return this.frontTextureActive;
    	}
    	else if(side == 3){
    		return this.frontTexture;
    	}
    	return this.blockIcon;
    }
    
    public void onBlockAdded(World par1World, int par2, int par3, int par4)
    {
        super.onBlockAdded(par1World, par2, par3, par4);
        this.setDefaultDirection(par1World, par2, par3, par4);
    }

    private void setDefaultDirection(World par1World, int par2, int par3, int par4)
    {
        if (!par1World.isRemote)
        {
            int l = par1World.getBlockId(par2, par3, par4 - 1);
            int i1 = par1World.getBlockId(par2, par3, par4 + 1);
            int j1 = par1World.getBlockId(par2 - 1, par3, par4);
            int k1 = par1World.getBlockId(par2 + 1, par3, par4);
            byte b0 = 3;

            if (Block.opaqueCubeLookup[l] && !Block.opaqueCubeLookup[i1])
            {
                b0 = 3;
            }

            if (Block.opaqueCubeLookup[i1] && !Block.opaqueCubeLookup[l])
            {
                b0 = 2;
            }

            if (Block.opaqueCubeLookup[j1] && !Block.opaqueCubeLookup[k1])
            {
                b0 = 5;
            }

            if (Block.opaqueCubeLookup[k1] && !Block.opaqueCubeLookup[j1])
            {
                b0 = 4;
            }

            par1World.setBlockMetadataWithNotify(par2, par3, par4, b0, 2);
        }
    }
    
    /*public void onBlockPlacedBy(World par1World, int par2, int par3, int par4, EntityLivingBase par5EntityLivingBase, ItemStack par6ItemStack)
    {
        int l = MathHelper.floor_double((double)(par5EntityLivingBase.rotationYaw * 4.0F / 360.0F) + 0.5D) & 3;

        if (l == 0)
        {
            par1World.setBlockMetadataWithNotify(par2, par3, par4, 2, 2);
        }

        if (l == 1)
        {
            par1World.setBlockMetadataWithNotify(par2, par3, par4, 5, 2);
        }

        if (l == 2)
        {
            par1World.setBlockMetadataWithNotify(par2, par3, par4, 3, 2);
        }

        if (l == 3)
        {
            par1World.setBlockMetadataWithNotify(par2, par3, par4, 4, 2);
        }
    }*/
        
    /**
     * 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 if (!par5EntityPlayer.isSneaking()) 
	{
		TileEntityCellingMachine var10 = (TileEntityCellingMachine) par1World.getBlockTileEntity(par2, par3, par4);
		if (var10 != null) 
		{
			par5EntityPlayer.openGui(Elementum.instance, 0, par1World, par2, par3, par4);
		}
		return true;
	} 
	else 
	{
		return false;
	}
    }
    
    /**
     * Update which block ID the furnace is using depending on whether or not it is burning
     */
    public static void updateFurnaceBlockState(boolean par0, World par1World, int par2, int par3, int par4)
    {
        int var5 = par1World.getBlockMetadata(par2, par3, par4);
        TileEntity var6 = par1World.getBlockTileEntity(par2, par3, par4);
        keepInputFurnaceInventory = true;

        if (par0)
        {
            par1World.setBlock(par2, par3, par4, Elementum.cellingMachineActive.blockID);
        }
        else
        {
            par1World.setBlock(par2, par3, par4, Elementum.cellingMachine.blockID);
        }

        keepInputFurnaceInventory = false;
        par1World.setBlockMetadataWithNotify(par2, par3, par4, var5, 2);

        if (var6 != null)
        {
            var6.validate();
            par1World.setBlockTileEntity(par2, par3, par4, var6);
        }
    }

    /**
     * Returns the TileEntity used by this block.
     */
    public TileEntity getBlockEntity()
    {
        return new TileEntityCellingMachine();
    }
    
    public void onBlockPlacedBy(World par1World, int par2, int par3, int par4, EntityLivingBase par5EntityLivingBase, ItemStack par6ItemStack)
    {
        int l = MathHelper.floor_double((double)(par5EntityLivingBase.rotationYaw * 4.0F / 360.0F) + 0.5D) & 3;

        if (l == 0)
        {
            par1World.setBlockMetadataWithNotify(par2, par3, par4, 2, 2);
        }

        if (l == 1)
        {
            par1World.setBlockMetadataWithNotify(par2, par3, par4, 5, 2);
        }

        if (l == 2)
        {
            par1World.setBlockMetadataWithNotify(par2, par3, par4, 3, 2);
        }

        if (l == 3)
        {
            par1World.setBlockMetadataWithNotify(par2, par3, par4, 4, 2);
        }

        if (par6ItemStack.hasDisplayName())
        {
            ((TileEntityCellingMachine)par1World.getBlockTileEntity(par2, par3, par4)).setCustomName(par6ItemStack.getDisplayName());
        }
    }
    
    /**
     * Called whenever the block is removed.
     */
    public void breakBlock(World par1World, int par2, int par3, int par4, int par5, int par6)
    {
        if (!keepInputFurnaceInventory)
        {
            TileEntityCellingMachine var7 = (TileEntityCellingMachine)par1World.getBlockTileEntity(par2, par3, par4);

            if (var7 != null)
            {
                for (int var8 = 0; var8 < var7.getSizeInventory(); ++var8)
                {
                    ItemStack itemstack = var7.getStackInSlot(var8);

                    if (itemstack != null)
                    {
                        float f = this.inputFurnaceRand.nextFloat() * 0.8F + 0.1F;
                        float f1 = this.inputFurnaceRand.nextFloat() * 0.8F + 0.1F;
                        float f2 = this.inputFurnaceRand.nextFloat() * 0.8F + 0.1F;

                        while (itemstack.stackSize > 0)
                        {
                            int k1 = this.inputFurnaceRand.nextInt(21) + 10;

                            if (k1 > itemstack.stackSize)
                            {
                                k1 = itemstack.stackSize;
                            }

                            itemstack.stackSize -= k1;
                            EntityItem entityitem = new EntityItem(par1World, (double)((float)par2 + f), (double)((float)par3 + f1), (double)((float)par4 + f2), new ItemStack(itemstack.itemID, k1, itemstack.getItemDamage()));

                            if (itemstack.hasTagCompound())
                            {
                                entityitem.getEntityItem().setTagCompound((NBTTagCompound)itemstack.getTagCompound().copy());
                            }

                            float f3 = 0.05F;
                            entityitem.motionX = (double)((float)this.inputFurnaceRand.nextGaussian() * f3);
                            entityitem.motionY = (double)((float)this.inputFurnaceRand.nextGaussian() * f3 + 0.2F);
                            entityitem.motionZ = (double)((float)this.inputFurnaceRand.nextGaussian() * f3);
                            par1World.spawnEntityInWorld(entityitem);
                        }
                    }
                }

                par1World.func_96440_m(par2, par3, par4, par5);
            }
        }

        super.breakBlock(par1World, par2, par3, par4, par5, par6);
    }
    
    public boolean hasComparatorInputOverride() 
{
        return true;
    }

    public int getComparatorInputOverride(World par1World, int par2, int par3, int par4, int par5) 
{
        return Container.calcRedstoneFromInventory((IInventory)par1World.getBlockTileEntity(par2, par3, par4));
    }

@Override
public TileEntity createNewTileEntity(World world) 
{
	return new TileEntityCellingMachine();
}
}

Posted

1st, not rotating towards player???

2nd, don't do what minecraft does with furnaces. Instead make a variable for the tile entity weather the furnace is on or off. Based on that you can make a special renderer for the tile entity to change the furnace's texture.

"you seem to be THE best modder I've seen imo."

~spynathan

 

ლ(́◉◞౪◟◉‵ლ

Posted

Try changing the

side == 3

in your getIcon method to

side == meta

that should fix the rotating.

For the second one, the vanilla furnace uses 2 blocks, one with active and one with the idle texture. Try that way.

Don't PM me with questions. They will be ignored! Make a thread on the appropriate board for support.

 

1.12 -> 1.13 primer by williewillus.

 

1.7.10 and older versions of Minecraft are no longer supported due to it's age! Update to the latest version for support.

 

http://www.howoldisminecraft1710.today/

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.