Posted August 6, 201411 yr 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; } }
August 6, 201411 yr 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!
August 6, 201411 yr 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
August 6, 201411 yr Author But, Jacky said that Minecraft.getMinecraft() is clientside only. What should I do with this?
August 6, 201411 yr he also gave you the solution, its the if statement with the boolean that checks if the "game" is serversided "if (!this.worldObj.isRemote)"
August 6, 201411 yr 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.