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

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/

Check the minecraft snowball src i think the correct method is inthere

I'm always happy to help others!

 

Java is not my main programming language but I have alot experience in PHP/HTML/JS/CSS3/C#/SQL

  • Author

Nothing...

I can not understand why does not work?

I see this

and made something like this. But it not work...

 

Try removing the @Override?

I'm always happy to help others!

 

Java is not my main programming language but I have alot experience in PHP/HTML/JS/CSS3/C#/SQL

  • Author

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

 

 

 

  • Author

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

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.