Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

Posted

how would i make it so that when you use an item it changes one block to another, say stone to sand for example.

Use examples, i have aspergers.

Examples make sense to me.

    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!

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...

  • Author

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.

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...

Important Information

By using this site, you agree to our Terms of Use.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.