Jump to content

Recommended Posts

Posted

I make a Gun

 

This is Gun

 

 

package yorri.mods.mod_MicroUkr;

 

import net.minecraft.client.Minecraft;

import net.minecraft.entity.player.EntityPlayer;

import net.minecraft.item.Item;

import net.minecraft.item.ItemStack;

import net.minecraft.util.MovingObjectPosition;

import net.minecraft.world.World;

 

public class ItemPistol extends Item

{

private byte damage;

 

public ItemPistol(int i, byte dmg){

 

  super();

  maxStackSize = 1;

  this.damage = dmg;

  this.setMaxDamage(64);

  this.bFull3D=true;

  this.setCreativeTab(mod_MicroUkr.tabMicroUkr);

 

}

 

@Override

public ItemStack onItemRightClick(ItemStack par1ItemStack, World par2World, EntityPlayer par3EntityPlayer)

{

 

  if(par3EntityPlayer.inventory.hasItem(mod_MicroUkr.pistolclip))

  {

  par2World.playSoundAtEntity(par3EntityPlayer, "microukr:gunshot", 1, 1);

  par3EntityPlayer.inventory.consumeInventoryItem(mod_MicroUkr.pistolclip);

  par1ItemStack.damageItem(1, par3EntityPlayer);

 

 

  if(!par2World.isRemote)

{

  System.out.println( "from pistol onItemRightClick" );

      par2World.spawnEntityInWorld(new EntityBullet(par2World, par3EntityPlayer, (byte)5));

       

 

}

  }

 

 

  return par1ItemStack;

}

 

public int getMaxItemUseDuration(ItemStack par1ItemStack){

 

  return 10;

}

 

}

 

 

 

When I Right Click I create Bullet.

 

This is EntityBullet

 

 

package yorri.mods.mod_MicroUkr;

 

import net.minecraft.block.Block;

import net.minecraft.client.Minecraft;

import net.minecraft.entity.EntityLiving;

import net.minecraft.entity.player.EntityPlayer;

import net.minecraft.entity.projectile.EntityThrowable;

import net.minecraft.init.Blocks;

import net.minecraft.nbt.NBTTagCompound;

import net.minecraft.util.DamageSource;

import net.minecraft.util.MovingObjectPosition;

import net.minecraft.world.World;

 

public class EntityBullet  extends EntityThrowable

{

 

public byte damageValue;

public int xTile,yTile,zTile;

public MovingObjectPosition objectMouseOver;

 

public EntityBullet(World par1world, EntityPlayer par3EntityPlayer, byte damage)

{

  super(par1world);

  damageValue = damage;

  System.out.println( "constructor1" );

}

 

public EntityBullet(World par1world, EntityLiving par2EntityLiving, byte damage)

{

super(par1world, par2EntityLiving);

damageValue = damage;

}

 

public EntityBullet(World par1world, double par2, double par4, double par6, byte damage)

{

super(par1world, par2, par4, par6);

damageValue = damage;

}

 

@Override

public void onImpact(MovingObjectPosition par1MovingObjectPosition)

 

{

System.out.println( "on impact" );

}

 

@Override

protected void entityInit() {}

@Override

public void readEntityFromNBT(NBTTagCompound var1) {}

 

@Override

public void writeEntityToNBT(NBTTagCompound par1NBTTagCompound)

{}

}

 

 

In the console I see "from pistol onItemRightClick"  and  "constructor1" but I not see  "on impact"...

 

/sorry for my english/

Posted

May be I am wrong registering in main class?

 

 

pistol = new ItemPistol(getUniqueEntityId(),(byte)5).setUnlocalizedName("pistol").setTextureName(mod_MicroUkr.MODID + ":" + "pistol");

    GameRegistry.registerItem(pistol, pistol.getUnlocalizedName().substring(5));

   

    pistolclip = new ItemPistolClip(getUniqueEntityId()).setUnlocalizedName("pistolclip").setTextureName(mod_MicroUkr.MODID + ":" + "kula");

    GameRegistry.registerItem(pistolclip, pistolclip.getUnlocalizedName().substring(5));

   

   

    int i2=getUniqueEntityId();

    EntityRegistry.registerGlobalEntityID(EntityBullet.class, "bullet", i2);

    EntityRegistry.registerModEntity(EntityBullet.class, "bullet", i2, this, 64, 1, true);

       

    RenderingRegistry.registerEntityRenderingHandler(EntityBullet.class, new RenderSnowball(mod_MicroUkr.pistolclip));

 

 

 

Posted

Sorry. I detect my error. In the EntityBullet class in constructor. Must be

public EntityBullet(World par1world, EntityPlayer par3EntityPlayer)
{
	  super(par1world,[b]par3EntityPlayer[/b]);
}

I lost par3EntityPlayer.

(I created other similar item and entity and saw this error. I guess that the error is in my code. Sorry again for the trouble )

 

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.