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

So basically, the mob is spawned in by onRightClick in the ItemMag.class, it is suppose to follow the player and be like directly behind the player and by its shoulder at all times but problem 1. Dont know how to set position for it, it usually stays up high, because I modeled it in the Ideal location so really its just a matter of keeping close behind the player. problem 2. the Mob wont follow the player at all, I think its the ItemMag.class error. problem 3. is onLeftClick doesnt despawn the mob, when it should. I want a player to only be able to spawn 1 of the entity. Here are  my classes.

ItemMag.class

package com.phantasyrealms.item;

import com.phantasyrealms.entity.EntityMag;
import com.phantasyrealms.lib.Strings;

import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.util.ChatComponentTranslation;
import net.minecraft.world.World;


public class ItemMag extends Item{

 EntityMag par1;

 public ItemStack onItemRightClick(ItemStack itemstack, World world, EntityPlayer player){
  if(par1 == null){
        par1 = new EntityMag(world);
        par1.setPosition(player.posX, player.posY+1,player.posZ-2);
        par1.func_152115_b(player.getUniqueID().toString());
        world.spawnEntityInWorld(par1);
        player.inventory.addItemStackToInventory(new ItemStack(PhantasyRealmsItems.mag));
        --itemstack.stackSize;
  }
  else{
  player.addChatComponentMessage(new ChatComponentTranslation ("Already Have one!"));
 }
  return null;
 }


  public ItemStack onItemLeftClick(ItemStack itemstack, World world, EntityPlayer player){
   par1.func_152115_b(player.getUniqueID().toString());
   world.removeEntity(par1);
   player.addChatComponentMessage(new ChatComponentTranslation ("RETURN!"));
   player.inventory.addItemStackToInventory(new ItemStack(PhantasyRealmsItems.mag));
   return null;
  }
}

 

EntityMag.class

package com.phantasyrealms.entity;

import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityAgeable;
import net.minecraft.entity.EntityLiving;
import net.minecraft.entity.EnumCreatureAttribute;
import net.minecraft.entity.SharedMonsterAttributes;
import net.minecraft.entity.ai.EntityAIAttackOnCollide;
import net.minecraft.entity.ai.EntityAIBeg;
import net.minecraft.entity.ai.EntityAIFollowOwner;
import net.minecraft.entity.ai.EntityAIHurtByTarget;
import net.minecraft.entity.ai.EntityAILeapAtTarget;
import net.minecraft.entity.ai.EntityAILookIdle;
import net.minecraft.entity.ai.EntityAIMate;
import net.minecraft.entity.ai.EntityAINearestAttackableTarget;
import net.minecraft.entity.ai.EntityAIOwnerHurtByTarget;
import net.minecraft.entity.ai.EntityAIOwnerHurtTarget;
import net.minecraft.entity.ai.EntityAISwimming;
import net.minecraft.entity.ai.EntityAITargetNonTamed;
import net.minecraft.entity.ai.EntityAIWander;
import net.minecraft.entity.ai.EntityAIWatchClosest;
import net.minecraft.entity.monster.IMob;
import net.minecraft.entity.passive.EntitySheep;
import net.minecraft.entity.passive.EntityTameable;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.util.DamageSource;
import net.minecraft.world.World;

public class EntityMag extends EntityTameable
{


public EntityMag(World world)
{
super(world);
this.getNavigator().setAvoidsWater(true);
this.tasks.addTask(1, new EntityAISwimming(this));
this.tasks.addTask(3, new EntityAILeapAtTarget(this, 0.4F));
this.tasks.addTask(4, new EntityAIAttackOnCollide(this, 1.0D, true));
this.tasks.addTask(5, new EntityAIFollowOwner(this, 1.0D, 10.0F, 2.0F));
this.tasks.addTask(7, new EntityAIWander(this, 1.0D));
this.tasks.addTask(9, new EntityAIWatchClosest(this, EntityPlayer.class, 8.0F));
this.tasks.addTask(9, new EntityAILookIdle(this));
this.targetTasks.addTask(1, new EntityAIOwnerHurtByTarget(this));
this.targetTasks.addTask(2, new EntityAIOwnerHurtTarget(this));
this.targetTasks.addTask(4, new EntityAITargetNonTamed(this, EntitySheep.class, 200, false));
this.setSize(0.9F, 0.9F);

}

protected void applyEntityAttributes(){
super.applyEntityAttributes();
this.getEntityAttribute(SharedMonsterAttributes.movementSpeed).setBaseValue(0.2);
this.getEntityAttribute(SharedMonsterAttributes.maxHealth).setBaseValue(20.0D);
}

public boolean attackEntityAsMob(Entity par1Entity)
{
int i = 5;
return par1Entity.attackEntityFrom(DamageSource.causeMobDamage(this), 5.0F);
}

protected boolean isAIEnabled()
{
return true;
}


public void onDeath(DamageSource par1DamageSource)
{
super.onDeath(par1DamageSource);

}

public EnumCreatureAttribute getCreatureAttribute()
{
return EnumCreatureAttribute.UNDEFINED;
}

public boolean interact(EntityPlayer par1EntityPlayer){
this.func_152115_b(par1EntityPlayer.getUniqueID().toString());
return true;
}

protected boolean canDespawn()
{
return false;
}

protected void dropFewItems(boolean par1, int par2)
{

}

public EntityAgeable createChild(EntityAgeable entityageable)
{
return null;
}
}

  • Author

You cant store data in your item class you need to use NBT for that.

How would I do this, I have never touched NBT methods and usage before.

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.