Posted October 12, 20169 yr I'm adding a gun item to my mod and it has a cool down. I have a system that works I'd say 20-10% of the time. When I fire the gun, it spawns a bullet and then instantly despawns it, but other times it works. code for gun: package mymod.items; import mymod.Main_1; import mymod.projectiles.MyEntityBlastProjectile; import mymod.projectiles.MyEntityBlastProjectile2; import mymod.projectiles.MyEntityBulletProjectile; import net.minecraft.client.renderer.texture.IconRegister; import net.minecraft.entity.Entity; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.projectile.EntityWitherSkull; import net.minecraft.item.EnumToolMaterial; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.item.ItemSword; import net.minecraft.potion.Potion; import net.minecraft.potion.PotionEffect; import net.minecraft.util.Vec3; import net.minecraft.world.World; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; public class MyPistolGunItem1 extends ItemSword { private String texturePath = "mymod:"; public int reload = 0; public MyPistolGunItem1(int ItemID, EnumToolMaterial material, String textureName) { super(ItemID, material); this.setUnlocalizedName(textureName); texturePath += textureName; canRepair = true; } @SideOnly(Side.CLIENT) public void registerIcons(IconRegister iconRegister) { this.itemIcon = iconRegister.registerIcon(texturePath); } //shoots fireball // public ItemStack onItemRightClick(ItemStack itemstack, World world, EntityPlayer entityplayer) { if (entityplayer.inventory.hasItem(Main_1.MyBulletItem_1.itemID) && reload == 0) { Vec3 look = entityplayer.getLookVec(); MyEntityBulletProjectile fireball2 = new MyEntityBulletProjectile(world, entityplayer, 1, 1, 1); fireball2.setPosition( entityplayer.posX + look.xCoord, entityplayer.posY + look.yCoord + 1, entityplayer.posZ + look.zCoord); fireball2.accelerationX = look.xCoord * 5.1; fireball2.accelerationY = look.yCoord * 5.1; fireball2.accelerationZ = look.zCoord * 5.1; world.spawnEntityInWorld(fireball2); entityplayer.inventory.consumeInventoryItem(Main_1.MyBulletItem_1.itemID); itemstack.damageItem(1, entityplayer); reload = 1; } else { return itemstack; } return itemstack; } @Override public void onUpdate (ItemStack stack, World world, Entity entity, int par4, boolean par5){ super.onUpdate(stack, world, entity, par4, par5); { EntityPlayer player = (EntityPlayer) entity; ItemStack equipped = player.getCurrentEquippedItem(); if (equipped == stack) { if (reload > 0 && reload < 21) { reload = reload + 1; } else if (reload == 21) { reload = 0; } else { } } } } }
October 12, 20169 yr registerIcons Update to 1.10.2, 1.7 is no longer supported here. Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable. If you think this is the case, JUST REPORT ME. Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice. Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked. DO NOT PM ME WITH PROBLEMS. No help will be given.
October 12, 20169 yr registerIcons Update to 1.10.2, 1.7 is no longer supported here. It's even worse: int ItemID Main_1.MyBulletItem_1.itemID Don't PM me with questions. They will be ignored! Make a thread on the appropriate board for support. 1.12 -> 1.13 primer by williewillus. 1.7.10 and older versions of Minecraft are no longer supported due to it's age! Update to the latest version for support. http://www.howoldisminecraft1710.today/
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.