Jump to content

Recommended Posts

Posted

Hi ;)

What's wrong with this piece of code?

I just want to have a sword which behaves like a Bone, so you can tame a wolf with this sword using right click.

 

package xeno.mci.swords2;

import java.util.List;
import java.util.Random;

import scala.Int;
import net.minecraft.client.Minecraft;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLiving;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.boss.EntityWither;
import net.minecraft.entity.passive.EntityWolf;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Items;
import net.minecraft.item.ItemStack;
import net.minecraft.item.ItemSword;
import net.minecraft.pathfinding.PathEntity;
import net.minecraft.util.DamageSource;
import net.minecraft.util.MovingObjectPosition;
import net.minecraft.util.MovingObjectPosition.MovingObjectType;
import net.minecraft.world.World;
import xeno.mci.swords.mciSwords;

public class sWilczyMiecz extends ItemSword {

public sWilczyMiecz(ToolMaterial material) {

		super(material);

		//setMaxStackSize(1);
		this.setCreativeTab(mciSwords.ctab2);
		this.setUnlocalizedName("wilczymiecz");
		this.setTextureName("mciswords:2wilczymiecz");

}

public void addInformation(ItemStack par1ItemStack, EntityPlayer par2EntityPlayer, List par3List, boolean par4)
    {
	par3List.add("MCI #2 - Miecze");
    	par3List.add("Miejsce #3");
    	par3List.add("Autor: HeadPhoneKiller");

    }

@Override
    public boolean itemInteractionForEntity(ItemStack p1, EntityPlayer p2, EntityLivingBase p3)
    {
	return true;
    }

    public ItemStack onItemRightClick(ItemStack p1, World p2, EntityPlayer p3)
    {
    	
    	if(Minecraft.getMinecraft().objectMouseOver.entityHit != null){
    	    if(Minecraft.getMinecraft().objectMouseOver.entityHit instanceof EntityLiving){
    	    	EntityLiving ent = (EntityLiving) Minecraft.getMinecraft().objectMouseOver.entityHit;
    	    	//System.out.println("DEBUG1");
    	    	ItemStack bone = new ItemStack(Items.bone, 32);
    	    	p3.setCurrentItemOrArmor(0, bone);
    	    	p3.interactWith(ent);
    	    }
    	}
    	
        return p1;
    }

}

Posted

Minecraft.getminecraft() is client only

 

You have to get the Wolf entity at the server and then use something like this:

 

 

            if (!this.worldObj.isRemote)

            {

 

                    wolf.setTamed(true);

                    wolf.setPathToEntity((PathEntity)null);

                    wolf.setAttackTarget((EntityLivingBase)null);

                    wolf.aiSit.setSitting(true);

                    wolf.setHealth(20.0F);

                    wol.setOwner(par1EntityPlayer.getCommandSenderName());

                    wolf.playTameEffect(true);

                    wolf.worldObj.setEntityState(this, (byte)7);

 

            }

 

 

Here could be your advertisement!

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.