Jump to content

Recommended Posts

Posted

So I have a modeled block that is, as said above, 3x1x1 (3 blocks wide, 1 block high, and 1 block in depth) and it looks fine, but the hit-box only works for the center block. Through a bit of research I found out that I need to create two other blocks that 'spawn in' on either side when I place the main block, but I'm not sure how to go about this.

 

Any help would be greatly appreciated,

 

-Whyneb360

Posted

Could you please explain this in a bit more detail? I am somewhat new to modding, but very new to the more complicated aspects of block placement (which this query seems to be). I looked through the bed and door code, but I couldn't find anything that uses the 'onBlockPlacedinWorld' method

 

-Whyneb360

Posted

Hi

 

The bed and the door are both very good examples of this.

 

For bed, the most interesting parts are ItemBed and BlockBed.onNeighbourBlockChange.  The spawning takes place in ItemBed; ItemDoor shows a slightly different way of doing it.

 

The key thing is that you need to place the multiple blocks but also keep them in sync (eg if one is destroyed, the others need to be destroyed too)

 

-TGG

 

 

 

Posted

Okay, so my block spawns in with the second one attached (and gets destroyed as well), but how do I make it two different blocks? At the moment its the same block that spawns in, so I think it might have something to do with metadata in the case of the bed, so do I have to set up some metadata? All I want is for the model to only spawn on the first block, not the second

 

-Whyneb360

Posted

You're right metadata is the way to go about doing this. When the three blocks are placed you would need to set the metadata of the top on to 0, the metadata of the middle one to 1, and the metadata of the bottom block to 2. You can then use this metadata to determine which of the blocks is being broken so you can break the other two blocks. You would also use this information when you get the texture, returing a different IIcon depending on the side and metadata.

Don't make mods if you don't know Java.

Check out my website: http://shadowfacts.net

Developer of many mods

Posted

Sorry if this is an obvious question, but where and how would I set and use the metadata. Note that I am not just trying to texture the blocks differently, but I want one to have a model, and the others to not. I looked through the bed code, and found this: (warning, copy pasta ahead)

 

@SideOnly(Side.CLIENT)
    public IIcon getIcon(int p_149691_1_, int p_149691_2_)
    {
        if (p_149691_1_ == 0)
        {
            return Blocks.planks.getBlockTextureFromSide(p_149691_1_);
        }
        else
        {
            int k = getDirection(p_149691_2_);
            int l = Direction.bedDirection[k][p_149691_1_];
            int i1 = isBlockHeadOfBed(p_149691_2_) ? 1 : 0;
            return (i1 != 1 || l != 2) && (i1 != 0 || l != 3) ? (l != 5 && l != 4 ? this.field_149983_N[i1] : this.field_149982_M[i1]) : this.field_149980_b[i1];
        }
    }

    @SideOnly(Side.CLIENT)
    public void registerBlockIcons(IIconRegister p_149651_1_)
    {
        this.field_149983_N = new IIcon[] {p_149651_1_.registerIcon(this.getTextureName() + "_feet_top"), p_149651_1_.registerIcon(this.getTextureName() + "_head_top")};
        this.field_149980_b = new IIcon[] {p_149651_1_.registerIcon(this.getTextureName() + "_feet_end"), p_149651_1_.registerIcon(this.getTextureName() + "_head_end")};
        this.field_149982_M = new IIcon[] {p_149651_1_.registerIcon(this.getTextureName() + "_feet_side"), p_149651_1_.registerIcon(this.getTextureName() + "_head_side")};
    }

 

Which is how the textures are set, but I'm not sure how I'd change this to set a model for one, and an invisible texture for another (Just in the case of 2 blocks)

 

If needed, this is the code in my Workbench class, and my WorkbenchItem class (again, a bit of a copy pasta warning)

 

Workbench:

public class Workbench extends BlockContainer {

public static final int[][] thing = new int[][] {{0, 1}, { -1, 0}, {0, -1}, {1, 0}};
@SideOnly(Side.CLIENT)
private IIcon[] field_149980_b;
@SideOnly(Side.CLIENT)
private IIcon[] field_149982_M;
@SideOnly(Side.CLIENT)
private IIcon[] field_149983_N;
    
public Workbench(Material material) {
	super(material);

	this.setCreativeTab(DesconCreativeTabs.tabInterior);
	this.setHarvestLevel("axe", 1);
	this.setBlockBounds(0F, 0F, 0F, 1F, 1F, 1F);
	this.setHardness(3F);
	}

public int getRenderType() {
	return -1;
}

public boolean isOpaqueCube() {
	return false;
}

public boolean renderAsNormalBlock() {
	return false;
}

public TileEntity createNewTileEntity(World var1, int var2) {
	return new TileEntityWorkbench();
}

/*@SideOnly(Side.CLIENT)
public void registerBlockIcons(IIconRegister iconRegister) {
	this.blockIcon = iconRegister.registerIcon(Main.modID + ":" + this.getUnlocalizedName().substring(5));
} */

//Directional Bollocks

public void onBlockPlacedBy(World world, int x, int y, int z, EntityLivingBase player, ItemStack itemstack)
{
	int l = MathHelper.floor_double((double)(player.rotationYaw * 4.0F / 360.0F) + 0.5D) & 3;

	world.setBlockMetadataWithNotify(x, y, z, l, 3);

}


public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int q, float a, float b, float c) {
	if(!player.isSneaking()) {
		player.openGui(Main.instance, PropsGeneral.guiIDdesignersworkbench, world, x, y, z);
		return true;
	}else{
		return false;
	}
}

public static boolean isBlockWorkbench(int isBlock)
    {
        return (isBlock &  != 0;
    }

public static int getDirection(int direction)
    {
        return direction & 3;
    }

public void onNeighborBlockChange(World world, int x, int y, int z, Block block)
    {
        int l = world.getBlockMetadata(x, y, z);
        int i1 = getDirection(l);

        if (isBlockWorkbench(l))
        {
            if (world.getBlock(x - thing[i1][0], y, z - thing[i1][1]) != this)
            {
                world.setBlockToAir(x, y, z);
            }
        }
        else if (world.getBlock(x + thing[i1][0], y, z + thing[i1][1]) != this)
        {
            world.setBlockToAir(x, y, z);

            if (!world.isRemote)
            {
                this.dropBlockAsItem(world, x, y, z, l, 0);
            }
        }
    }

public Item getItemDropped(int p_149650_1_, Random p_149650_2_, int p_149650_3_)
    {
        
        return isBlockWorkbench(p_149650_1_) ? Item.getItemById(0) : DesconItems.workbench;
    }

@SideOnly(Side.CLIENT)
    public IIcon getIcon(int p_149691_1_, int p_149691_2_)
    {
        if (p_149691_1_ == 0)
        {
            return Blocks.planks.getBlockTextureFromSide(p_149691_1_);
        }
        else
        {
            int k = getDirection(p_149691_2_);
            int l = Direction.bedDirection[k][p_149691_1_];
            int i1 = isBlockWorkbench(p_149691_2_) ? 1 : 0;
            return (i1 != 1 || l != 2) && (i1 != 0 || l != 3) ? (l != 5 && l != 4 ? this.field_149983_N[i1] : this.field_149982_M[i1]) : this.field_149980_b[i1];
        }
    }

    @SideOnly(Side.CLIENT)
    public void registerBlockIcons(IIconRegister p_149651_1_)
    {
        this.field_149983_N = new IIcon[] {p_149651_1_.registerIcon(this.getTextureName() + "_feet_top"), p_149651_1_.registerIcon(this.getTextureName() + "_head_top")};
        this.field_149980_b = new IIcon[] {p_149651_1_.registerIcon(this.getTextureName() + "_feet_end"), p_149651_1_.registerIcon(this.getTextureName() + "_head_end")};
        this.field_149982_M = new IIcon[] {p_149651_1_.registerIcon(this.getTextureName() + "_feet_side"), p_149651_1_.registerIcon(this.getTextureName() + "_head_side")};
    }
} 

 

WorkbenchItem:

public class WorkbenchItem extends Item
{
    private static final String __OBFID = "CL_00001771";

    public WorkbenchItem()
    {
    }

    /**
     * Callback for item usage. If the item does something special on right clicking, he will have one of those. Return
     * True if something happen and false if it don't. This is for ITEMS, not BLOCKS
     */
    public boolean onItemUse(ItemStack itemstack, EntityPlayer player, World world, int x, int y, int z, int i, float x1, float y1, float z1)
    {
    	
        if (world.isRemote)
        {
            return true;
        }
        else if (i != 1)
        {
            return false;
        }
        else
        {
            ++y;
            Workbench workbench = (Workbench)PropsGeneral.designersworkbench;
            int i1 = MathHelper.floor_double((double)(player.rotationYaw * 4.0F / 360.0F) + 0.5D) & 3;
            byte b0 = 0;
            byte b1 = 0;

            if (i1 == 0)
            {
                b1 = 1;
            }

            if (i1 == 1)
            {
                b0 = -1;
            }

            if (i1 == 2)
            {
                b1 = -1;
            }

            if (i1 == 3)
            {
                b0 = 1;
            }

            if (player.canPlayerEdit(x, y, z, i, itemstack) && player.canPlayerEdit(x + b0, y, z + b1, i, itemstack))
            {
                if (world.isAirBlock(x, y, z) && world.isAirBlock(x + b0, y, z + b1) && World.doesBlockHaveSolidTopSurface(world, x, y - 1, z) && World.doesBlockHaveSolidTopSurface(world, x + b0, y - 1, z + b1))
                {
                    world.setBlock(x, y, z, workbench, i1, 3);

                    if (world.getBlock(x, y, z) == workbench)
                    {
                        world.setBlock(x + b0, y, z + b1, workbench, i1 + 8, 3);
                    }

                    --itemstack.stackSize;
                    return true;
                }
                else
                {
                    return false;
                }
            }
            else
            {
                return false;
            }
        }
    }
}

 

-Whyneb360

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.