Started by kevin timotius on Sun, 12/20/2015 - 05:05 Topic category: Advanced modding still have idea how to make aimed gun/ aiming gun? Jump to top Try this add to your gun code:[spoiler]public void onPlayerStoppedUsing(ItemStack par1ItemStack, World par2World, EntityPlayer par3EntityPlayer, int par4) { boolean var5 = par3EntityPlayer.capabilities.isCreativeMode || EnchantmentHelper.getEnchantmentLevel(Enchantment.infinity.effectId, par1ItemStack) > 0; if (var5 || par3EntityPlayer.inventory.hasItem(Items.arrow)) { int var6 = this.getMaxItemUseDuration(par1ItemStack) - par4; float var7 = (float)var6 / 20.0F; var7 = (var7 * var7 + var7 * 2.0F) / 3.0F; if ((double)var7 < 0.1D) { return; } if (var7 > 1.0F) { var7 = 1.0F; } EntityArrow var8 = new EntityArrow(par2World, par3EntityPlayer, var7 * 2.0F); if (var7 == 1.0F) { var8.setIsCritical(true); } int var9 = EnchantmentHelper.getEnchantmentLevel(Enchantment.power.effectId, par1ItemStack); if (var9 > 0) { var8.setDamage(var8.getDamage() + (double)var9 * 0.5D + 0.5D); } int var10 = EnchantmentHelper.getEnchantmentLevel(Enchantment.punch.effectId, par1ItemStack); if (var10 > 0) { var8.setKnockbackStrength(var10); } if (EnchantmentHelper.getEnchantmentLevel(Enchantment.flame.effectId, par1ItemStack) > 0) { var8.setFire(100); } par1ItemStack.damageItem(1, par3EntityPlayer); par2World.playSoundAtEntity(par3EntityPlayer, "random.bow", 1.0F, 1.0F / (itemRand.nextFloat() * 0.4F + 1.2F) + var7 * 0.5F); if (var5) { var8.canBePickedUp = 2; } else { par3EntityPlayer.inventory.consumeInventoryItem(Items.arrow); } if (!par2World.isRemote) { par2World.spawnEntityInWorld(var8); } } } public ItemStack onEaten(ItemStack par1ItemStack, World par2World, EntityPlayer par3EntityPlayer) { return par1ItemStack; } //How long it takes to use or consume an item public int getMaxItemUseDuration(ItemStack par1ItemStack) { return 72000; } //Returns the action that specifies what animation to play when the items is being used public EnumAction getItemUseAction(ItemStack par1ItemStack) { return EnumAction.bow; } //Called whenever this item is equipped and the right mouse button is pressed. Args: itemStack, world, entityPlayer public ItemStack onItemRightClick(ItemStack par1ItemStack, World par2World, EntityPlayer par3EntityPlayer) { if (par3EntityPlayer.capabilities.isCreativeMode || par3EntityPlayer.inventory.hasItem(Items.arrow)) { par3EntityPlayer.setItemInUse(par1ItemStack, this.getMaxItemUseDuration(par1ItemStack)); } return par1ItemStack; }[/spoiler] Jump to top Permalink Log in or register to post comments in a source code? where i must copy this code? Jump to top Permalink Log in or register to post comments can i add this to my tool code? Jump to top Permalink Log in or register to post comments this code was not working Jump to top Permalink Log in or register to post comments Can i see your code? Jump to top Permalink Log in or register to post comments can i add this to my item code? Jump to top Permalink Log in or register to post comments this my gun code: package mod.mcreator; import net.minecraftforge.fml.client.registry.*; import net.minecraftforge.fml.common.*; import net.minecraftforge.fml.common.asm.*; import net.minecraftforge.fml.common.asm.transformers.*; import net.minecraftforge.fml.common.discovery.*; import net.minecraftforge.fml.common.discovery.asm.*; import net.minecraftforge.fml.common.event.*; import net.minecraftforge.fml.common.functions.*; import net.minecraftforge.fml.common.network.*; import net.minecraftforge.fml.common.registry.*; import net.minecraftforge.fml.common.toposort.*; import net.minecraftforge.fml.common.versioning.*; import net.minecraftforge.fml.relauncher.*; import net.minecraftforge.fml.server.*; import net.minecraft.block.*; import net.minecraft.block.material.*; import net.minecraft.client.*; import net.minecraft.client.audio.*; import net.minecraft.client.entity.*; import net.minecraft.client.gui.*; import net.minecraft.client.gui.achievement.*; import net.minecraft.client.gui.inventory.*; import net.minecraft.client.model.*; import net.minecraft.client.multiplayer.*; import net.minecraft.client.particle.*; import net.minecraft.client.renderer.*; import net.minecraft.client.renderer.culling.*; import net.minecraft.client.renderer.entity.*; import net.minecraft.client.renderer.tileentity.*; import net.minecraft.client.settings.*; import net.minecraft.command.*; import net.minecraft.crash.*; import net.minecraft.creativetab.*; import net.minecraft.dispenser.*; import net.minecraft.enchantment.*; import net.minecraft.entity.*; import net.minecraft.entity.ai.*; import net.minecraft.entity.boss.*; import net.minecraft.entity.effect.*; import net.minecraft.entity.item.*; import net.minecraft.entity.monster.*; import net.minecraft.entity.passive.*; import net.minecraft.entity.player.*; import net.minecraft.entity.projectile.*; import net.minecraft.inventory.*; import net.minecraft.item.*; import net.minecraft.item.crafting.*; import net.minecraft.nbt.*; import net.minecraft.network.*; import net.minecraft.network.rcon.*; import net.minecraft.pathfinding.*; import net.minecraft.potion.*; import net.minecraft.profiler.*; import net.minecraft.server.*; import net.minecraft.server.dedicated.*; import net.minecraft.server.gui.*; import net.minecraft.server.integrated.*; import net.minecraft.server.management.*; import net.minecraft.stats.*; import net.minecraft.tileentity.*; import net.minecraft.util.*; import net.minecraft.village.*; import net.minecraft.world.*; import net.minecraft.world.biome.*; import net.minecraft.world.chunk.*; import net.minecraft.world.chunk.storage.*; import net.minecraft.world.demo.*; import net.minecraft.world.gen.*; import net.minecraft.world.gen.feature.*; import net.minecraft.world.gen.layer.*; import net.minecraft.world.gen.structure.*; import net.minecraft.world.storage.*; import net.minecraftforge.classloading.*; import net.minecraftforge.client.*; import net.minecraftforge.client.event.*; import net.minecraftforge.client.event.sound.*; import net.minecraftforge.common.*; import net.minecraftforge.event.*; import net.minecraftforge.event.entity.*; import net.minecraftforge.event.entity.item.*; import net.minecraftforge.event.entity.living.*; import net.minecraftforge.event.entity.minecart.*; import net.minecraftforge.event.entity.player.*; import net.minecraftforge.event.terraingen.*; import net.minecraftforge.event.world.*; import net.minecraftforge.oredict.*; import net.minecraftforge.transformers.*; import net.minecraft.init.*; import java.util.*; import net.minecraft.client.resources.model.*; public class mcreator_t { public mcreator_t(){} public static Item block; public static Object instance; public void load(FMLInitializationEvent event){ if(event.getSide() == Side.CLIENT) Minecraft.getMinecraft().getRenderItem().getItemModelMesher().register(block, 0, new ModelResourceLocation("TestEnvironmentMod:t", "inventory")); } public void registerRenderers(){} public void generateNether(World world, Random random, int chunkX, int chunkZ){} public void generateSurface(World world, Random random, int chunkX, int chunkZ){} public int addFuel(ItemStack fuel){ return 0; } public void serverLoad(FMLServerStartingEvent event){} public void preInit(FMLPreInitializationEvent event){} static{ block = (new ItemgGUN()); } static class ItemgGUN extends Item{ public ItemgGUN(){ super(); setMaxDamage(100); maxStackSize = 1; setFull3D(); setUnlocalizedName("t"); GameRegistry.registerItem(this, "t"); setCreativeTab(CreativeTabs.tabCombat); } public int getMaxItemUseDuration(ItemStack par1ItemStack) { return 72000; } public ItemStack onItemRightClick(ItemStack par1ItemStack, World par2World, final EntityPlayer par3EntityPlayer){ boolean flag = par3EntityPlayer.capabilities.isCreativeMode || EnchantmentHelper.getEnchantmentLevel(Enchantment.infinity.effectId, par1ItemStack) > 0; if (flag || par3EntityPlayer.inventory.hasItem(Items.arrow)) { float f = 1.0F; EntityArrow entityarrow = new EntityArrow(par2World, par3EntityPlayer, f * 2.0F) { public void onCollideWithPlayer(EntityPlayer entity){ super.onCollideWithPlayer(entity); int i = MathHelper.floor_double(this.getEntityBoundingBox().minX + 0.001D); int j = MathHelper.floor_double(this.getEntityBoundingBox().minY + 0.001D); int k = MathHelper.floor_double(this.getEntityBoundingBox().minZ + 0.001D); World world = this.worldObj; } public void onUpdate(){ super.onUpdate(); int i = MathHelper.floor_double(this.getEntityBoundingBox().minX + 0.001D); int j = MathHelper.floor_double(this.getEntityBoundingBox().minY + 0.001D); int k = MathHelper.floor_double(this.getEntityBoundingBox().minZ + 0.001D); World world = this.worldObj; Entity entity = (Entity)par3EntityPlayer; if (getBlock(this.worldObj, i, j, k) != Blocks.air || getBlock(this.worldObj, i, j-1, k) != Blocks.air || getBlock(this.worldObj, i, j+1, k) != Blocks.air || getBlock(this.worldObj, i+1, j, k) != Blocks.air || getBlock(this.worldObj, i-1, j, k) != Blocks.air || getBlock(this.worldObj, i, j, k+1) != Blocks.air || getBlock(this.worldObj, i, j, k-1) != Blocks.air){ this.kill(); } } }; entityarrow.setIsCritical(false); entityarrow.setDamage(5.0); entityarrow.setKnockbackStrength(5); if(false){ entityarrow.setFire(100); } par1ItemStack.damageItem(1, par3EntityPlayer); par2World.playSoundAtEntity(par3EntityPlayer, "random.bow", 1.0F, 1.0F / (itemRand.nextFloat() * 0.4F + 1.2F) + f * 0.5F); if (flag) { entityarrow.canBePickedUp = 2; } else { par3EntityPlayer.inventory.consumeInventoryItem(Items.arrow); } if (!par2World.isRemote) { par2World.spawnEntityInWorld(entityarrow); } World world = par2World; EntityPlayer entity = par3EntityPlayer; int i = (int)entity.posX; int j = (int)entity.posY; int k = (int)entity.posZ; } return par1ItemStack; } public Block getBlock(World par1World, int i, int j, int k){ return par1World.getBlockState(new BlockPos(i, j, k)).getBlock(); } /** * returns the action that specifies what animation to play when the items is being used */ public EnumAction getItemUseAction(ItemStack par1ItemStack) { return EnumAction.BOW; } public void onPlayerStoppedUsing(ItemStack par1ItemStack, World par2World, EntityPlayer par3EntityPlayer, int par4) { boolean var5 = par3EntityPlayer.capabilities.isCreativeMode || EnchantmentHelper.getEnchantmentLevel(Enchantment.infinity.effectId, par1ItemStack) > 0; if (var5 || par3EntityPlayer.inventory.hasItem(Items.arrow)) { int var6 = this.getMaxItemUseDuration(par1ItemStack) - par4; float var7 = (float)var6 / 20.0F; var7 = (var7 * var7 + var7 * 2.0F) / 3.0F; if ((double)var7 < 0.1D) { return; } if (var7 > 1.0F) { var7 = 1.0F; } EntityArrow var8 = new EntityArrow(par2World, par3EntityPlayer, var7 * 2.0F); if (var7 == 1.0F) { var8.setIsCritical(true); } int var9 = EnchantmentHelper.getEnchantmentLevel(Enchantment.power.effectId, par1ItemStack); if (var9 > 0) { var8.setDamage(var8.getDamage() + (double)var9 * 0.5D + 0.5D); } int var10 = EnchantmentHelper.getEnchantmentLevel(Enchantment.punch.effectId, par1ItemStack); if (var10 > 0) { var8.setKnockbackStrength(var10); } if (EnchantmentHelper.getEnchantmentLevel(Enchantment.flame.effectId, par1ItemStack) > 0) { var8.setFire(100); } par1ItemStack.damageItem(1, par3EntityPlayer); par2World.playSoundAtEntity(par3EntityPlayer, "random.bow", 1.0F, 1.0F / (itemRand.nextFloat() * 0.4F + 1.2F) + var7 * 0.5F); if (var5) { var8.canBePickedUp = 2; } else { par3EntityPlayer.inventory.consumeInventoryItem(Items.arrow); } if (!par2World.isRemote) { par2World.spawnEntityInWorld(var8); } } } public ItemStack onEaten(ItemStack par1ItemStack, World par2World, EntityPlayer par3EntityPlayer) { return par1ItemStack; } //How long it takes to use or consume an item public int getMaxItemUseDuration(ItemStack par1ItemStack) { return 72000; } //Returns the action that specifies what animation to play when the items is being used public EnumAction getItemUseAction(ItemStack par1ItemStack) { return EnumAction.bow; } //Called whenever this item is equipped and the right mouse button is pressed. Args: itemStack, world, entityPlayer public ItemStack onItemRightClick(ItemStack par1ItemStack, World par2World, EntityPlayer par3EntityPlayer) { if (par3EntityPlayer.capabilities.isCreativeMode || par3EntityPlayer.inventory.hasItem(Items.arrow)) { par3EntityPlayer.setItemInUse(par1ItemStack, this.getMaxItemUseDuration(par1ItemStack)); } return par1ItemStack; } }} Jump to top Permalink Log in or register to post comments I also add to my item code: package mod.mcreator; import net.minecraftforge.fml.client.registry.*; import net.minecraftforge.fml.common.*; import net.minecraftforge.fml.common.asm.*; import net.minecraftforge.fml.common.asm.transformers.*; import net.minecraftforge.fml.common.discovery.*; import net.minecraftforge.fml.common.discovery.asm.*; import net.minecraftforge.fml.common.event.*; import net.minecraftforge.fml.common.functions.*; import net.minecraftforge.fml.common.network.*; import net.minecraftforge.fml.common.registry.*; import net.minecraftforge.fml.common.toposort.*; import net.minecraftforge.fml.common.versioning.*; import net.minecraftforge.fml.relauncher.*; import net.minecraftforge.fml.server.*; import net.minecraft.block.*; import net.minecraft.block.material.*; import net.minecraft.client.*; import net.minecraft.client.audio.*; import net.minecraft.client.entity.*; import net.minecraft.client.gui.*; import net.minecraft.client.gui.achievement.*; import net.minecraft.client.gui.inventory.*; import net.minecraft.client.model.*; import net.minecraft.client.multiplayer.*; import net.minecraft.client.particle.*; import net.minecraft.client.renderer.*; import net.minecraft.client.renderer.culling.*; import net.minecraft.client.renderer.entity.*; import net.minecraft.client.renderer.tileentity.*; import net.minecraft.client.settings.*; import net.minecraft.command.*; import net.minecraft.crash.*; import net.minecraft.creativetab.*; import net.minecraft.dispenser.*; import net.minecraft.enchantment.*; import net.minecraft.entity.*; import net.minecraft.entity.ai.*; import net.minecraft.entity.boss.*; import net.minecraft.entity.effect.*; import net.minecraft.entity.item.*; import net.minecraft.entity.monster.*; import net.minecraft.entity.passive.*; import net.minecraft.entity.player.*; import net.minecraft.entity.projectile.*; import net.minecraft.inventory.*; import net.minecraft.item.*; import net.minecraft.item.crafting.*; import net.minecraft.nbt.*; import net.minecraft.network.*; import net.minecraft.network.rcon.*; import net.minecraft.pathfinding.*; import net.minecraft.potion.*; import net.minecraft.profiler.*; import net.minecraft.server.*; import net.minecraft.server.dedicated.*; import net.minecraft.server.gui.*; import net.minecraft.server.integrated.*; import net.minecraft.server.management.*; import net.minecraft.stats.*; import net.minecraft.tileentity.*; import net.minecraft.util.*; import net.minecraft.village.*; import net.minecraft.world.*; import net.minecraft.world.biome.*; import net.minecraft.world.chunk.*; import net.minecraft.world.chunk.storage.*; import net.minecraft.world.demo.*; import net.minecraft.world.gen.*; import net.minecraft.world.gen.feature.*; import net.minecraft.world.gen.layer.*; import net.minecraft.world.gen.structure.*; import net.minecraft.world.storage.*; import net.minecraftforge.classloading.*; import net.minecraftforge.client.*; import net.minecraftforge.client.event.*; import net.minecraftforge.client.event.sound.*; import net.minecraftforge.common.*; import net.minecraftforge.event.*; import net.minecraftforge.event.entity.*; import net.minecraftforge.event.entity.item.*; import net.minecraftforge.event.entity.living.*; import net.minecraftforge.event.entity.minecart.*; import net.minecraftforge.event.entity.player.*; import net.minecraftforge.event.terraingen.*; import net.minecraftforge.event.world.*; import net.minecraftforge.oredict.*; import net.minecraftforge.transformers.*; import net.minecraft.init.*; import java.util.*; import net.minecraftforge.common.util.*; import org.lwjgl.opengl.GL11; import net.minecraft.client.resources.model.*; @SuppressWarnings("unchecked") public class mcreator_revolverReload{ public mcreator_revolverReload(){} public static Item block;public static Object instance;public void load(FMLInitializationEvent event){ if(event.getSide() == Side.CLIENT) Minecraft.getMinecraft().getRenderItem().getItemModelMesher().register(block, 0, new ModelResourceLocation("TestEnvironmentMod:RevolverReload", "inventory")); GameRegistry.addRecipe(new ItemStack(block, 1), new Object[]{ "012", "X45", "XXX", Character.valueOf('0'), new ItemStack(mcreator_gunBarrel.block, 1), Character.valueOf('1'), new ItemStack(mcreator_revolverRound.block, 1), Character.valueOf('2'), new ItemStack(mcreator_gunLock.block, 1), Character.valueOf('4'), new ItemStack(mcreator_gear.block, 1), Character.valueOf('5'), new ItemStack(mcreator_gunStock.block, 1), });} public void generateNether(World world, Random random, int chunkX, int chunkZ){} public void generateSurface(World world, Random random, int chunkX, int chunkZ){} public int addFuel(ItemStack fuel){return 0;} public void serverLoad(FMLServerStartingEvent event){} public void preInit(FMLPreInitializationEvent event){} public void registerRenderers(){ } static{ block = (new ItemrevolverReload(448)); } static class ItemrevolverReload extends Item{ public ItemrevolverReload(int par1){ setMaxDamage(0); maxStackSize = 1; setUnlocalizedName("RevolverReload"); GameRegistry.registerItem(this, "RevolverReload"); setCreativeTab(CreativeTabs.tabCombat); } public int getItemEnchantability() { return 0; } public int getMaxItemUseDuration(ItemStack par1ItemStack) { return 0; } public float getStrVsBlock(ItemStack par1ItemStack, Block par2Block) { return 1.0F; } public ItemStack onItemRightClick(ItemStack itemstack, World world, EntityPlayer entity){ float var4 = 1.0F; int i = (int)(entity.prevPosX + (entity.posX - entity.prevPosX) * (double)var4); int j = (int)(entity.prevPosY + (entity.posY - entity.prevPosY) * (double)var4 + 1.62D); int k = (int)(entity.prevPosZ + (entity.posZ - entity.prevPosZ) * (double)var4); if(entity.inventory.hasItem(new ItemStack(mcreator_gunBullet.block).getItem())){ EntityArrow entityarrow = new EntityArrow(world, (EntityLivingBase)entity, 2 * 2.0F); entityarrow.setDamage(2*2.0F); entityarrow.setKnockbackStrength(1); world.playSoundAtEntity(entity, "random.bow", 1.0F, 1.0F / (0.5F * 0.4F + 1.2F) + 2 * 0.5F); if (!world.isRemote) world.spawnEntityInWorld(entityarrow); } if(entity.inventory.hasItem(new ItemStack(mcreator_gunBullet.block).getItem())){ if(entity instanceof EntityPlayer)((EntityPlayer)entity).inventory.consumeInventoryItem(mcreator_gunBullet.block); } if(true){ world.createExplosion((Entity)null, i, j, k, 0F, true); } return itemstack; } public void onPlayerStoppedUsing(ItemStack par1ItemStack, World par2World, EntityPlayer par3EntityPlayer, int par4) { boolean var5 = par3EntityPlayer.capabilities.isCreativeMode || EnchantmentHelper.getEnchantmentLevel(Enchantment.infinity.effectId, par1ItemStack) > 0; if (var5 || par3EntityPlayer.inventory.hasItem(mcreator_gunBullet.block)) { int var6 = this.getMaxItemUseDuration(par1ItemStack) - par4; float var7 = (float)var6 / 20.0F; var7 = (var7 * var7 + var7 * 2.0F) / 3.0F; if ((double)var7 < 0.1D) { return; } if (var7 > 1.0F) { var7 = 1.0F; } EntityArrow var8 = new EntityArrow(par2World, par3EntityPlayer, var7 * 2.0F); if (var7 == 1.0F) { var8.setIsCritical(true); } int var9 = EnchantmentHelper.getEnchantmentLevel(Enchantment.power.effectId, par1ItemStack); if (var9 > 0) { var8.setDamage(var8.getDamage() + (double)var9 * 0.5D + 0.5D); } int var10 = EnchantmentHelper.getEnchantmentLevel(Enchantment.punch.effectId, par1ItemStack); if (var10 > 0) { var8.setKnockbackStrength(var10); } if (EnchantmentHelper.getEnchantmentLevel(Enchantment.flame.effectId, par1ItemStack) > 0) { var8.setFire(100); } par1ItemStack.damageItem(1, par3EntityPlayer); par2World.playSoundAtEntity(par3EntityPlayer, "random.bow", 1.0F, 1.0F / (itemRand.nextFloat() * 0.4F + 1.2F) + var7 * 0.5F); if (var5) { var8.canBePickedUp = 2; } else { par3EntityPlayer.inventory.consumeInventoryItem(mcreator_gunBullet.block); } if (!par2World.isRemote) { par2World.spawnEntityInWorld(var8); } } } public ItemStack onEaten(ItemStack par1ItemStack, World par2World, EntityPlayer par3EntityPlayer) { return par1ItemStack; } //How long it takes to use or consume an item public int getMaxItemUseDuration(ItemStack par1ItemStack) { return 72000; } //Returns the action that specifies what animation to play when the items is being used public EnumAction getItemUseAction(ItemStack par1ItemStack) { return EnumAction.bow; } //Called whenever this item is equipped and the right mouse button is pressed. Args: itemStack, world, entityPlayer public ItemStack onItemRightClick(ItemStack par1ItemStack, World par2World, EntityPlayer par3EntityPlayer) { if (par3EntityPlayer.capabilities.isCreativeMode || par3EntityPlayer.inventory.hasItem(mcreator_gunBullet.block)) { par3EntityPlayer.setItemInUse(par1ItemStack, this.getMaxItemUseDuration(par1ItemStack)); } return par1ItemStack; } }} Jump to top Permalink Log in or register to post comments item and gun, still not working Jump to top Permalink Log in or register to post comments me to, I'm trying to make a Fortnite mod but I can't aim and the projectile is shooting for my head not the gun barrel. Jump to top Permalink Log in or register to post comments
Try this add to your gun code:[spoiler]public void onPlayerStoppedUsing(ItemStack par1ItemStack, World par2World, EntityPlayer par3EntityPlayer, int par4) { boolean var5 = par3EntityPlayer.capabilities.isCreativeMode || EnchantmentHelper.getEnchantmentLevel(Enchantment.infinity.effectId, par1ItemStack) > 0; if (var5 || par3EntityPlayer.inventory.hasItem(Items.arrow)) { int var6 = this.getMaxItemUseDuration(par1ItemStack) - par4; float var7 = (float)var6 / 20.0F; var7 = (var7 * var7 + var7 * 2.0F) / 3.0F; if ((double)var7 < 0.1D) { return; } if (var7 > 1.0F) { var7 = 1.0F; } EntityArrow var8 = new EntityArrow(par2World, par3EntityPlayer, var7 * 2.0F); if (var7 == 1.0F) { var8.setIsCritical(true); } int var9 = EnchantmentHelper.getEnchantmentLevel(Enchantment.power.effectId, par1ItemStack); if (var9 > 0) { var8.setDamage(var8.getDamage() + (double)var9 * 0.5D + 0.5D); } int var10 = EnchantmentHelper.getEnchantmentLevel(Enchantment.punch.effectId, par1ItemStack); if (var10 > 0) { var8.setKnockbackStrength(var10); } if (EnchantmentHelper.getEnchantmentLevel(Enchantment.flame.effectId, par1ItemStack) > 0) { var8.setFire(100); } par1ItemStack.damageItem(1, par3EntityPlayer); par2World.playSoundAtEntity(par3EntityPlayer, "random.bow", 1.0F, 1.0F / (itemRand.nextFloat() * 0.4F + 1.2F) + var7 * 0.5F); if (var5) { var8.canBePickedUp = 2; } else { par3EntityPlayer.inventory.consumeInventoryItem(Items.arrow); } if (!par2World.isRemote) { par2World.spawnEntityInWorld(var8); } } } public ItemStack onEaten(ItemStack par1ItemStack, World par2World, EntityPlayer par3EntityPlayer) { return par1ItemStack; } //How long it takes to use or consume an item public int getMaxItemUseDuration(ItemStack par1ItemStack) { return 72000; } //Returns the action that specifies what animation to play when the items is being used public EnumAction getItemUseAction(ItemStack par1ItemStack) { return EnumAction.bow; } //Called whenever this item is equipped and the right mouse button is pressed. Args: itemStack, world, entityPlayer public ItemStack onItemRightClick(ItemStack par1ItemStack, World par2World, EntityPlayer par3EntityPlayer) { if (par3EntityPlayer.capabilities.isCreativeMode || par3EntityPlayer.inventory.hasItem(Items.arrow)) { par3EntityPlayer.setItemInUse(par1ItemStack, this.getMaxItemUseDuration(par1ItemStack)); } return par1ItemStack; }[/spoiler] Jump to top Permalink Log in or register to post comments
in a source code? where i must copy this code? Jump to top Permalink Log in or register to post comments
this my gun code: package mod.mcreator; import net.minecraftforge.fml.client.registry.*; import net.minecraftforge.fml.common.*; import net.minecraftforge.fml.common.asm.*; import net.minecraftforge.fml.common.asm.transformers.*; import net.minecraftforge.fml.common.discovery.*; import net.minecraftforge.fml.common.discovery.asm.*; import net.minecraftforge.fml.common.event.*; import net.minecraftforge.fml.common.functions.*; import net.minecraftforge.fml.common.network.*; import net.minecraftforge.fml.common.registry.*; import net.minecraftforge.fml.common.toposort.*; import net.minecraftforge.fml.common.versioning.*; import net.minecraftforge.fml.relauncher.*; import net.minecraftforge.fml.server.*; import net.minecraft.block.*; import net.minecraft.block.material.*; import net.minecraft.client.*; import net.minecraft.client.audio.*; import net.minecraft.client.entity.*; import net.minecraft.client.gui.*; import net.minecraft.client.gui.achievement.*; import net.minecraft.client.gui.inventory.*; import net.minecraft.client.model.*; import net.minecraft.client.multiplayer.*; import net.minecraft.client.particle.*; import net.minecraft.client.renderer.*; import net.minecraft.client.renderer.culling.*; import net.minecraft.client.renderer.entity.*; import net.minecraft.client.renderer.tileentity.*; import net.minecraft.client.settings.*; import net.minecraft.command.*; import net.minecraft.crash.*; import net.minecraft.creativetab.*; import net.minecraft.dispenser.*; import net.minecraft.enchantment.*; import net.minecraft.entity.*; import net.minecraft.entity.ai.*; import net.minecraft.entity.boss.*; import net.minecraft.entity.effect.*; import net.minecraft.entity.item.*; import net.minecraft.entity.monster.*; import net.minecraft.entity.passive.*; import net.minecraft.entity.player.*; import net.minecraft.entity.projectile.*; import net.minecraft.inventory.*; import net.minecraft.item.*; import net.minecraft.item.crafting.*; import net.minecraft.nbt.*; import net.minecraft.network.*; import net.minecraft.network.rcon.*; import net.minecraft.pathfinding.*; import net.minecraft.potion.*; import net.minecraft.profiler.*; import net.minecraft.server.*; import net.minecraft.server.dedicated.*; import net.minecraft.server.gui.*; import net.minecraft.server.integrated.*; import net.minecraft.server.management.*; import net.minecraft.stats.*; import net.minecraft.tileentity.*; import net.minecraft.util.*; import net.minecraft.village.*; import net.minecraft.world.*; import net.minecraft.world.biome.*; import net.minecraft.world.chunk.*; import net.minecraft.world.chunk.storage.*; import net.minecraft.world.demo.*; import net.minecraft.world.gen.*; import net.minecraft.world.gen.feature.*; import net.minecraft.world.gen.layer.*; import net.minecraft.world.gen.structure.*; import net.minecraft.world.storage.*; import net.minecraftforge.classloading.*; import net.minecraftforge.client.*; import net.minecraftforge.client.event.*; import net.minecraftforge.client.event.sound.*; import net.minecraftforge.common.*; import net.minecraftforge.event.*; import net.minecraftforge.event.entity.*; import net.minecraftforge.event.entity.item.*; import net.minecraftforge.event.entity.living.*; import net.minecraftforge.event.entity.minecart.*; import net.minecraftforge.event.entity.player.*; import net.minecraftforge.event.terraingen.*; import net.minecraftforge.event.world.*; import net.minecraftforge.oredict.*; import net.minecraftforge.transformers.*; import net.minecraft.init.*; import java.util.*; import net.minecraft.client.resources.model.*; public class mcreator_t { public mcreator_t(){} public static Item block; public static Object instance; public void load(FMLInitializationEvent event){ if(event.getSide() == Side.CLIENT) Minecraft.getMinecraft().getRenderItem().getItemModelMesher().register(block, 0, new ModelResourceLocation("TestEnvironmentMod:t", "inventory")); } public void registerRenderers(){} public void generateNether(World world, Random random, int chunkX, int chunkZ){} public void generateSurface(World world, Random random, int chunkX, int chunkZ){} public int addFuel(ItemStack fuel){ return 0; } public void serverLoad(FMLServerStartingEvent event){} public void preInit(FMLPreInitializationEvent event){} static{ block = (new ItemgGUN()); } static class ItemgGUN extends Item{ public ItemgGUN(){ super(); setMaxDamage(100); maxStackSize = 1; setFull3D(); setUnlocalizedName("t"); GameRegistry.registerItem(this, "t"); setCreativeTab(CreativeTabs.tabCombat); } public int getMaxItemUseDuration(ItemStack par1ItemStack) { return 72000; } public ItemStack onItemRightClick(ItemStack par1ItemStack, World par2World, final EntityPlayer par3EntityPlayer){ boolean flag = par3EntityPlayer.capabilities.isCreativeMode || EnchantmentHelper.getEnchantmentLevel(Enchantment.infinity.effectId, par1ItemStack) > 0; if (flag || par3EntityPlayer.inventory.hasItem(Items.arrow)) { float f = 1.0F; EntityArrow entityarrow = new EntityArrow(par2World, par3EntityPlayer, f * 2.0F) { public void onCollideWithPlayer(EntityPlayer entity){ super.onCollideWithPlayer(entity); int i = MathHelper.floor_double(this.getEntityBoundingBox().minX + 0.001D); int j = MathHelper.floor_double(this.getEntityBoundingBox().minY + 0.001D); int k = MathHelper.floor_double(this.getEntityBoundingBox().minZ + 0.001D); World world = this.worldObj; } public void onUpdate(){ super.onUpdate(); int i = MathHelper.floor_double(this.getEntityBoundingBox().minX + 0.001D); int j = MathHelper.floor_double(this.getEntityBoundingBox().minY + 0.001D); int k = MathHelper.floor_double(this.getEntityBoundingBox().minZ + 0.001D); World world = this.worldObj; Entity entity = (Entity)par3EntityPlayer; if (getBlock(this.worldObj, i, j, k) != Blocks.air || getBlock(this.worldObj, i, j-1, k) != Blocks.air || getBlock(this.worldObj, i, j+1, k) != Blocks.air || getBlock(this.worldObj, i+1, j, k) != Blocks.air || getBlock(this.worldObj, i-1, j, k) != Blocks.air || getBlock(this.worldObj, i, j, k+1) != Blocks.air || getBlock(this.worldObj, i, j, k-1) != Blocks.air){ this.kill(); } } }; entityarrow.setIsCritical(false); entityarrow.setDamage(5.0); entityarrow.setKnockbackStrength(5); if(false){ entityarrow.setFire(100); } par1ItemStack.damageItem(1, par3EntityPlayer); par2World.playSoundAtEntity(par3EntityPlayer, "random.bow", 1.0F, 1.0F / (itemRand.nextFloat() * 0.4F + 1.2F) + f * 0.5F); if (flag) { entityarrow.canBePickedUp = 2; } else { par3EntityPlayer.inventory.consumeInventoryItem(Items.arrow); } if (!par2World.isRemote) { par2World.spawnEntityInWorld(entityarrow); } World world = par2World; EntityPlayer entity = par3EntityPlayer; int i = (int)entity.posX; int j = (int)entity.posY; int k = (int)entity.posZ; } return par1ItemStack; } public Block getBlock(World par1World, int i, int j, int k){ return par1World.getBlockState(new BlockPos(i, j, k)).getBlock(); } /** * returns the action that specifies what animation to play when the items is being used */ public EnumAction getItemUseAction(ItemStack par1ItemStack) { return EnumAction.BOW; } public void onPlayerStoppedUsing(ItemStack par1ItemStack, World par2World, EntityPlayer par3EntityPlayer, int par4) { boolean var5 = par3EntityPlayer.capabilities.isCreativeMode || EnchantmentHelper.getEnchantmentLevel(Enchantment.infinity.effectId, par1ItemStack) > 0; if (var5 || par3EntityPlayer.inventory.hasItem(Items.arrow)) { int var6 = this.getMaxItemUseDuration(par1ItemStack) - par4; float var7 = (float)var6 / 20.0F; var7 = (var7 * var7 + var7 * 2.0F) / 3.0F; if ((double)var7 < 0.1D) { return; } if (var7 > 1.0F) { var7 = 1.0F; } EntityArrow var8 = new EntityArrow(par2World, par3EntityPlayer, var7 * 2.0F); if (var7 == 1.0F) { var8.setIsCritical(true); } int var9 = EnchantmentHelper.getEnchantmentLevel(Enchantment.power.effectId, par1ItemStack); if (var9 > 0) { var8.setDamage(var8.getDamage() + (double)var9 * 0.5D + 0.5D); } int var10 = EnchantmentHelper.getEnchantmentLevel(Enchantment.punch.effectId, par1ItemStack); if (var10 > 0) { var8.setKnockbackStrength(var10); } if (EnchantmentHelper.getEnchantmentLevel(Enchantment.flame.effectId, par1ItemStack) > 0) { var8.setFire(100); } par1ItemStack.damageItem(1, par3EntityPlayer); par2World.playSoundAtEntity(par3EntityPlayer, "random.bow", 1.0F, 1.0F / (itemRand.nextFloat() * 0.4F + 1.2F) + var7 * 0.5F); if (var5) { var8.canBePickedUp = 2; } else { par3EntityPlayer.inventory.consumeInventoryItem(Items.arrow); } if (!par2World.isRemote) { par2World.spawnEntityInWorld(var8); } } } public ItemStack onEaten(ItemStack par1ItemStack, World par2World, EntityPlayer par3EntityPlayer) { return par1ItemStack; } //How long it takes to use or consume an item public int getMaxItemUseDuration(ItemStack par1ItemStack) { return 72000; } //Returns the action that specifies what animation to play when the items is being used public EnumAction getItemUseAction(ItemStack par1ItemStack) { return EnumAction.bow; } //Called whenever this item is equipped and the right mouse button is pressed. Args: itemStack, world, entityPlayer public ItemStack onItemRightClick(ItemStack par1ItemStack, World par2World, EntityPlayer par3EntityPlayer) { if (par3EntityPlayer.capabilities.isCreativeMode || par3EntityPlayer.inventory.hasItem(Items.arrow)) { par3EntityPlayer.setItemInUse(par1ItemStack, this.getMaxItemUseDuration(par1ItemStack)); } return par1ItemStack; } }} Jump to top Permalink Log in or register to post comments
I also add to my item code: package mod.mcreator; import net.minecraftforge.fml.client.registry.*; import net.minecraftforge.fml.common.*; import net.minecraftforge.fml.common.asm.*; import net.minecraftforge.fml.common.asm.transformers.*; import net.minecraftforge.fml.common.discovery.*; import net.minecraftforge.fml.common.discovery.asm.*; import net.minecraftforge.fml.common.event.*; import net.minecraftforge.fml.common.functions.*; import net.minecraftforge.fml.common.network.*; import net.minecraftforge.fml.common.registry.*; import net.minecraftforge.fml.common.toposort.*; import net.minecraftforge.fml.common.versioning.*; import net.minecraftforge.fml.relauncher.*; import net.minecraftforge.fml.server.*; import net.minecraft.block.*; import net.minecraft.block.material.*; import net.minecraft.client.*; import net.minecraft.client.audio.*; import net.minecraft.client.entity.*; import net.minecraft.client.gui.*; import net.minecraft.client.gui.achievement.*; import net.minecraft.client.gui.inventory.*; import net.minecraft.client.model.*; import net.minecraft.client.multiplayer.*; import net.minecraft.client.particle.*; import net.minecraft.client.renderer.*; import net.minecraft.client.renderer.culling.*; import net.minecraft.client.renderer.entity.*; import net.minecraft.client.renderer.tileentity.*; import net.minecraft.client.settings.*; import net.minecraft.command.*; import net.minecraft.crash.*; import net.minecraft.creativetab.*; import net.minecraft.dispenser.*; import net.minecraft.enchantment.*; import net.minecraft.entity.*; import net.minecraft.entity.ai.*; import net.minecraft.entity.boss.*; import net.minecraft.entity.effect.*; import net.minecraft.entity.item.*; import net.minecraft.entity.monster.*; import net.minecraft.entity.passive.*; import net.minecraft.entity.player.*; import net.minecraft.entity.projectile.*; import net.minecraft.inventory.*; import net.minecraft.item.*; import net.minecraft.item.crafting.*; import net.minecraft.nbt.*; import net.minecraft.network.*; import net.minecraft.network.rcon.*; import net.minecraft.pathfinding.*; import net.minecraft.potion.*; import net.minecraft.profiler.*; import net.minecraft.server.*; import net.minecraft.server.dedicated.*; import net.minecraft.server.gui.*; import net.minecraft.server.integrated.*; import net.minecraft.server.management.*; import net.minecraft.stats.*; import net.minecraft.tileentity.*; import net.minecraft.util.*; import net.minecraft.village.*; import net.minecraft.world.*; import net.minecraft.world.biome.*; import net.minecraft.world.chunk.*; import net.minecraft.world.chunk.storage.*; import net.minecraft.world.demo.*; import net.minecraft.world.gen.*; import net.minecraft.world.gen.feature.*; import net.minecraft.world.gen.layer.*; import net.minecraft.world.gen.structure.*; import net.minecraft.world.storage.*; import net.minecraftforge.classloading.*; import net.minecraftforge.client.*; import net.minecraftforge.client.event.*; import net.minecraftforge.client.event.sound.*; import net.minecraftforge.common.*; import net.minecraftforge.event.*; import net.minecraftforge.event.entity.*; import net.minecraftforge.event.entity.item.*; import net.minecraftforge.event.entity.living.*; import net.minecraftforge.event.entity.minecart.*; import net.minecraftforge.event.entity.player.*; import net.minecraftforge.event.terraingen.*; import net.minecraftforge.event.world.*; import net.minecraftforge.oredict.*; import net.minecraftforge.transformers.*; import net.minecraft.init.*; import java.util.*; import net.minecraftforge.common.util.*; import org.lwjgl.opengl.GL11; import net.minecraft.client.resources.model.*; @SuppressWarnings("unchecked") public class mcreator_revolverReload{ public mcreator_revolverReload(){} public static Item block;public static Object instance;public void load(FMLInitializationEvent event){ if(event.getSide() == Side.CLIENT) Minecraft.getMinecraft().getRenderItem().getItemModelMesher().register(block, 0, new ModelResourceLocation("TestEnvironmentMod:RevolverReload", "inventory")); GameRegistry.addRecipe(new ItemStack(block, 1), new Object[]{ "012", "X45", "XXX", Character.valueOf('0'), new ItemStack(mcreator_gunBarrel.block, 1), Character.valueOf('1'), new ItemStack(mcreator_revolverRound.block, 1), Character.valueOf('2'), new ItemStack(mcreator_gunLock.block, 1), Character.valueOf('4'), new ItemStack(mcreator_gear.block, 1), Character.valueOf('5'), new ItemStack(mcreator_gunStock.block, 1), });} public void generateNether(World world, Random random, int chunkX, int chunkZ){} public void generateSurface(World world, Random random, int chunkX, int chunkZ){} public int addFuel(ItemStack fuel){return 0;} public void serverLoad(FMLServerStartingEvent event){} public void preInit(FMLPreInitializationEvent event){} public void registerRenderers(){ } static{ block = (new ItemrevolverReload(448)); } static class ItemrevolverReload extends Item{ public ItemrevolverReload(int par1){ setMaxDamage(0); maxStackSize = 1; setUnlocalizedName("RevolverReload"); GameRegistry.registerItem(this, "RevolverReload"); setCreativeTab(CreativeTabs.tabCombat); } public int getItemEnchantability() { return 0; } public int getMaxItemUseDuration(ItemStack par1ItemStack) { return 0; } public float getStrVsBlock(ItemStack par1ItemStack, Block par2Block) { return 1.0F; } public ItemStack onItemRightClick(ItemStack itemstack, World world, EntityPlayer entity){ float var4 = 1.0F; int i = (int)(entity.prevPosX + (entity.posX - entity.prevPosX) * (double)var4); int j = (int)(entity.prevPosY + (entity.posY - entity.prevPosY) * (double)var4 + 1.62D); int k = (int)(entity.prevPosZ + (entity.posZ - entity.prevPosZ) * (double)var4); if(entity.inventory.hasItem(new ItemStack(mcreator_gunBullet.block).getItem())){ EntityArrow entityarrow = new EntityArrow(world, (EntityLivingBase)entity, 2 * 2.0F); entityarrow.setDamage(2*2.0F); entityarrow.setKnockbackStrength(1); world.playSoundAtEntity(entity, "random.bow", 1.0F, 1.0F / (0.5F * 0.4F + 1.2F) + 2 * 0.5F); if (!world.isRemote) world.spawnEntityInWorld(entityarrow); } if(entity.inventory.hasItem(new ItemStack(mcreator_gunBullet.block).getItem())){ if(entity instanceof EntityPlayer)((EntityPlayer)entity).inventory.consumeInventoryItem(mcreator_gunBullet.block); } if(true){ world.createExplosion((Entity)null, i, j, k, 0F, true); } return itemstack; } public void onPlayerStoppedUsing(ItemStack par1ItemStack, World par2World, EntityPlayer par3EntityPlayer, int par4) { boolean var5 = par3EntityPlayer.capabilities.isCreativeMode || EnchantmentHelper.getEnchantmentLevel(Enchantment.infinity.effectId, par1ItemStack) > 0; if (var5 || par3EntityPlayer.inventory.hasItem(mcreator_gunBullet.block)) { int var6 = this.getMaxItemUseDuration(par1ItemStack) - par4; float var7 = (float)var6 / 20.0F; var7 = (var7 * var7 + var7 * 2.0F) / 3.0F; if ((double)var7 < 0.1D) { return; } if (var7 > 1.0F) { var7 = 1.0F; } EntityArrow var8 = new EntityArrow(par2World, par3EntityPlayer, var7 * 2.0F); if (var7 == 1.0F) { var8.setIsCritical(true); } int var9 = EnchantmentHelper.getEnchantmentLevel(Enchantment.power.effectId, par1ItemStack); if (var9 > 0) { var8.setDamage(var8.getDamage() + (double)var9 * 0.5D + 0.5D); } int var10 = EnchantmentHelper.getEnchantmentLevel(Enchantment.punch.effectId, par1ItemStack); if (var10 > 0) { var8.setKnockbackStrength(var10); } if (EnchantmentHelper.getEnchantmentLevel(Enchantment.flame.effectId, par1ItemStack) > 0) { var8.setFire(100); } par1ItemStack.damageItem(1, par3EntityPlayer); par2World.playSoundAtEntity(par3EntityPlayer, "random.bow", 1.0F, 1.0F / (itemRand.nextFloat() * 0.4F + 1.2F) + var7 * 0.5F); if (var5) { var8.canBePickedUp = 2; } else { par3EntityPlayer.inventory.consumeInventoryItem(mcreator_gunBullet.block); } if (!par2World.isRemote) { par2World.spawnEntityInWorld(var8); } } } public ItemStack onEaten(ItemStack par1ItemStack, World par2World, EntityPlayer par3EntityPlayer) { return par1ItemStack; } //How long it takes to use or consume an item public int getMaxItemUseDuration(ItemStack par1ItemStack) { return 72000; } //Returns the action that specifies what animation to play when the items is being used public EnumAction getItemUseAction(ItemStack par1ItemStack) { return EnumAction.bow; } //Called whenever this item is equipped and the right mouse button is pressed. Args: itemStack, world, entityPlayer public ItemStack onItemRightClick(ItemStack par1ItemStack, World par2World, EntityPlayer par3EntityPlayer) { if (par3EntityPlayer.capabilities.isCreativeMode || par3EntityPlayer.inventory.hasItem(mcreator_gunBullet.block)) { par3EntityPlayer.setItemInUse(par1ItemStack, this.getMaxItemUseDuration(par1ItemStack)); } return par1ItemStack; } }} Jump to top Permalink Log in or register to post comments
me to, I'm trying to make a Fortnite mod but I can't aim and the projectile is shooting for my head not the gun barrel. Jump to top Permalink Log in or register to post comments
Try this add to your gun code:
[spoiler]
public void onPlayerStoppedUsing(ItemStack par1ItemStack, World par2World, EntityPlayer par3EntityPlayer, int par4) { boolean var5 = par3EntityPlayer.capabilities.isCreativeMode || EnchantmentHelper.getEnchantmentLevel(Enchantment.infinity.effectId, par1ItemStack) > 0; if (var5 || par3EntityPlayer.inventory.hasItem(Items.arrow)) { int var6 = this.getMaxItemUseDuration(par1ItemStack) - par4; float var7 = (float)var6 / 20.0F; var7 = (var7 * var7 + var7 * 2.0F) / 3.0F; if ((double)var7 < 0.1D) { return; } if (var7 > 1.0F) { var7 = 1.0F; } EntityArrow var8 = new EntityArrow(par2World, par3EntityPlayer, var7 * 2.0F); if (var7 == 1.0F) { var8.setIsCritical(true); } int var9 = EnchantmentHelper.getEnchantmentLevel(Enchantment.power.effectId, par1ItemStack); if (var9 > 0) { var8.setDamage(var8.getDamage() + (double)var9 * 0.5D + 0.5D); } int var10 = EnchantmentHelper.getEnchantmentLevel(Enchantment.punch.effectId, par1ItemStack); if (var10 > 0) { var8.setKnockbackStrength(var10); } if (EnchantmentHelper.getEnchantmentLevel(Enchantment.flame.effectId, par1ItemStack) > 0) { var8.setFire(100); } par1ItemStack.damageItem(1, par3EntityPlayer); par2World.playSoundAtEntity(par3EntityPlayer, "random.bow", 1.0F, 1.0F / (itemRand.nextFloat() * 0.4F + 1.2F) + var7 * 0.5F); if (var5) { var8.canBePickedUp = 2; } else { par3EntityPlayer.inventory.consumeInventoryItem(Items.arrow); } if (!par2World.isRemote) { par2World.spawnEntityInWorld(var8); } } } public ItemStack onEaten(ItemStack par1ItemStack, World par2World, EntityPlayer par3EntityPlayer) { return par1ItemStack; } //How long it takes to use or consume an item public int getMaxItemUseDuration(ItemStack par1ItemStack) { return 72000; } //Returns the action that specifies what animation to play when the items is being used public EnumAction getItemUseAction(ItemStack par1ItemStack) { return EnumAction.bow; } //Called whenever this item is equipped and the right mouse button is pressed. Args: itemStack, world, entityPlayer public ItemStack onItemRightClick(ItemStack par1ItemStack, World par2World, EntityPlayer par3EntityPlayer) { if (par3EntityPlayer.capabilities.isCreativeMode || par3EntityPlayer.inventory.hasItem(Items.arrow)) { par3EntityPlayer.setItemInUse(par1ItemStack, this.getMaxItemUseDuration(par1ItemStack)); } return par1ItemStack; }
[/spoiler]
in a source code? where i must copy this code?
can i add this to my tool code?
this code was not working
Can i see your code?
can i add this to my item code?
item and gun, still not working
me to, I'm trying to make a Fortnite mod but I can't aim and the projectile is shooting for my head not the gun barrel.