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

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;
    }

}

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!

  • Author

How I can get the Wolf entity at the server?

btw. wolf.setOwner do not exist

aiSit is not visible

playTameEffect is not visible too

  • Author

But, Jacky said that Minecraft.getMinecraft() is clientside only. What should I do with this?

 

 

he also gave you the solution, its the if statement with the boolean that checks if the "game" is serversided

 

"if (!this.worldObj.isRemote)"

nah, mineraft.getMinecraft() is client only. You will have to send that information to the server using a packet.

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

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.