Jump to content

Recommended Posts

Posted

    public boolean onItemUse(ItemStack par1ItemStack, EntityPlayer par2EntityPlayer, World par3World, int x, int y, int z, int par7, float par8, float par9, float par10)
    {
    	if (par3World.isRemote)
    	{
    		return true;
    	}else{
    	if(par3World.getBlockId(x, y, z) ==  Block.stone.blockID){
    		par3World.setBlock(x, y, z, Block.sand.blockID);
    	}
        return true;
    	}
    }

 

the first 'if' statement is so that the code is ran once. It's required

 

if you want to have it use the item then put this under par3World.setBlock

par1ItemStack.stackSize--;

Bumper Cars!

Posted

Just wanted to add some lines to the isRemote thing :)

world.isRemote - This is true if it's the client side reading the code. while it's false if it's the server.

                        Minecraft has a built inn server, even inn SSP, therefore you need to be aware of this fact even on SSP :)

 

This is at least very important to do when working with Entity's, so you don't spawn one on client side(ghost/fake entity which will only be visible to the client) and another one on the server.

 

If you guys dont get it.. then well ya.. try harder...

Posted

partly unrelated to the above but not too the title so eeh, how do i make this item onrightClick take one damage rather that deleting?

package ashtonsmod.common;

import net.minecraft.block.Block;
import net.minecraft.client.renderer.texture.IconRegister;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.EntityLiving;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.projectile.EntityPotion;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.potion.Potion;
import net.minecraft.potion.PotionEffect;
import net.minecraft.world.World;

public class BStick extends Item
{
    public BStick(int par1)
    {
        super(par1);
        this.maxStackSize = 64;
        this.setMaxDamage(32);
    }
    
    public boolean hitEntity(ItemStack par1ItemStack, EntityLiving par2EntityLiving, EntityLiving par3EntityLiving)
    {
  par1ItemStack.damageItem(1, par3EntityLiving);
  par2EntityLiving.setJumping(true);
  return true;
    }
    
    public ItemStack onItemRightClick(ItemStack par1ItemStack, World par2World, EntityPlayer par3EntityPlayer)
    {
        if (!par3EntityPlayer.capabilities.isCreativeMode)
        {
            --par1ItemStack.stackSize;
        }

        par2World.playSoundAtEntity(par3EntityPlayer, "random.bow", 0.5F, 0.4F / (itemRand.nextFloat() * 0.4F + 0.8F));

        if (!par2World.isRemote)
        {
            par2World.spawnEntityInWorld(new EntityPotion(par2World, par3EntityPlayer, 24));
            par2World.spawnEntityInWorld(new EntityPotion(par2World, par3EntityPlayer, 10));
        }
        return par1ItemStack ;
    }
    
    @Override
   	public void updateIcons(IconRegister par1IconRegister)
    {
        this.iconIndex = par1IconRegister.registerIcon("ashtonsmod:EvilStaff");
    }}

Use examples, i have aspergers.

Examples make sense to me.

Posted

If you check what methods you have access to on ItemStack objects you should find some for dealing damage to the item.

Just use them and then return the damaged item as the return value of the function :)

If you guys dont get it.. then well ya.. try harder...

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.