Jump to content

[Forge 1.7.10] set block bounds problem for custom model


santabarbara_

Recommended Posts

I have a custom model of a coffin but I can't collide with it. It shows the boundaries when i hover over the block i place, but  can just walk straight through it. I'm poo garbage at java, help is required. So can anybody help?

 

Pictures:

 

50949020150827180707.png

28825320150827180659.png

 

BlockCoffin

 

 

 

package com.google.modwestern.common;

 

import java.util.List;

 

import com.google.modwestern.proxy.ClientProxy;

 

import cpw.mods.fml.relauncher.Side;

import cpw.mods.fml.relauncher.SideOnly;

import net.minecraft.block.Block;

import net.minecraft.block.material.Material;

import net.minecraft.client.renderer.texture.IIconRegister;

import net.minecraft.entity.Entity;

import net.minecraft.entity.EntityLivingBase;

import net.minecraft.entity.item.EntityItem;

import net.minecraft.entity.player.EntityPlayer;

import net.minecraft.init.Blocks;

import net.minecraft.inventory.IInventory;

import net.minecraft.item.ItemStack;

import net.minecraft.nbt.NBTTagCompound;

import net.minecraft.tileentity.TileEntity;

import net.minecraft.util.AxisAlignedBB;

import net.minecraft.util.ChatComponentText;

import net.minecraft.util.IIcon;

import net.minecraft.util.MathHelper;

import net.minecraft.world.IBlockAccess;

import net.minecraft.world.World;

 

public class BlockCoffin extends Block

{

private IIcon face, below;

private int[][] field_149981_a;

 

protected BlockCoffin(Material material)

{

super(material);

this.setBlockBounds(-1.0F, 0.0F, 0.0F, 1.0F, 1.0F, 1.0F);

}

 

 

 

public void registerBlockIcons(IIconRegister iiconRegister)

{

this.blockIcon = iiconRegister.registerIcon(ModWestern.MODID + ":side");

    this.below = iiconRegister.registerIcon(ModWestern.MODID + ":below");

    this.face = iiconRegister.registerIcon(ModWestern.MODID + ":face");

}

 

public void onBlockPlacedBy(World world, int x, int y, int z, EntityLivingBase living, ItemStack stack)

{

int direction = MathHelper.floor_double((double)(living.rotationYaw * 4.0F / 360.0F) + 2.5D) & 3;

System.out.println(direction);

    world.setBlockMetadataWithNotify(x, y, z, direction, 2);

   

   

}

 

 

private int getDirection(int l)

{

 

return 0;

}

 

 

 

private boolean isBlockHeadOfBed(int l)

{

 

return false;

}

 

 

 

@SideOnly(Side.CLIENT)

public IIcon getIcon(int side, int metadata)

    {

    if ((side == 3 && metadata == 0) || (side == 4 && metadata == 1) || (side == 2 && metadata ==2) || (side == 5 && metadata==3))

    {

    return this.face;

    }

    else if(side == 0)

    {

    return this.below;

    }

        return this.blockIcon;

    }

 

public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int side, float hitX, float hitY, float hitZ)

    {

        if(world.isRemote)

        {

            return true;

        }

        else

        {

            player.openGui(ModWestern.instance, 0, world, x, y, z);

            return true;

        }

    }

 

@Override

public boolean hasTileEntity(int metadata)

{

return true;

}

 

@Override

public TileEntity createTileEntity(World world, int metadata)

{

return new TileEntityCoffre();

}

 

 

 

 

public void breakBlock(World world, int x, int y, int z, Block block, int metadata)

    {

        TileEntity tileentity = world.getTileEntity(x, y, z);

 

        if(tileentity instanceof IInventory)

        {

            IInventory inv = (IInventory)tileentity;

            for(int i1 = 0; i1 < inv.getSizeInventory(); ++i1)

            {

                ItemStack itemstack = inv.getStackInSlot(i1);

 

                if(itemstack != null)

                {

                    float f = world.rand.nextFloat() * 0.8F + 0.1F;

                    float f1 = world.rand.nextFloat() * 0.8F + 0.1F;

                    EntityItem entityitem;

 

                    for(float f2 = world.rand.nextFloat() * 0.8F + 0.1F; itemstack.stackSize > 0; world.spawnEntityInWorld(entityitem))

                    {

                        int j1 = world.rand.nextInt(21) + 10;

 

                        if(j1 > itemstack.stackSize)

                        {

                            j1 = itemstack.stackSize;

                        }

 

                        itemstack.stackSize -= j1;

                        entityitem = new EntityItem(world, (double)((float)x + f), (double)((float)y + f1), (double)((float)z + f2), new ItemStack(itemstack.getItem(), j1, itemstack.getItemDamage()));

                        float f3 = 0.05F;

                        entityitem.motionX = (double)((float)world.rand.nextGaussian() * f3);

                        entityitem.motionY = (double)((float)world.rand.nextGaussian() * f3 + 0.2F);

                        entityitem.motionZ = (double)((float)world.rand.nextGaussian() * f3);

 

                        if(itemstack.hasTagCompound())

                        {

                            entityitem.getEntityItem().setTagCompound((NBTTagCompound)itemstack.getTagCompound().copy());

                        }

                    }

                }

            }

            world.func_147453_f(x, y, z, block);

        }

        super.breakBlock(world, x, y, z, block, metadata);

    }

 

public void onBlockPlacedBy1(World world, int x, int y, int z, EntityLivingBase living, ItemStack stack)

    {

        TileEntity tile = world.getTileEntity(x, y, z);

        if(tile instanceof TileEntityCoffre)

        {

            if(stack.hasDisplayName())

            {

                ((TileEntityCoffre)tile).setCustomName(stack.getDisplayName());

            }

        }

       

    }

 

public boolean renderAsNormalBlock()

{

return false;

}

 

public boolean isOpaqueCube()

{

return false;

}

 

@SideOnly(Side.CLIENT)

public int getRenderType()

{

return ClientProxy.renderInventoryTESRId;

}

}

 

 

 

Link to comment
Share on other sites

First off, you made your block bigger than a block.  That isn't the best of ideas.  Anything in vanilla for that, it is two blocks that form the overall bigger structure.  Look at chests, beds, ect.

 

 

Long time Bukkit & Forge Programmer

Happy to try and help

Link to comment
Share on other sites

Your code looks fairly clean for the 'java poo garbage' comment you made above.

 

When you set your block, it should look at the blocks around it to see if there is space to set a 2nd block (like the bed).  If so, it sets the 2nd block. ect ect

 

 

Actually, it is pretty complex if you are just starting out.  Make your block 1x1x1 and save the fancy stuff for later.

 

Long time Bukkit & Forge Programmer

Happy to try and help

Link to comment
Share on other sites

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.