Can someone please help me with the coding for this gun. I want to be able to adjust the strength of the shot and add delay to the gun. I would really appreciate it if someone could help me, here are my files.
It would be great if someone showed me what code I had to add or what part I had to edit in order to customize these features. For the shot delay I tried editing the getMaxItemUseDuration from return 72000 to 90000 and I trid other amounts but none of that worked.
mod_zombie
package net.minecraft.src;
import java.util.Map;
public class mod_zombie extends BaseMod
{
public static final Item Sniper = new ItemSniper(160).setItemName("Sniper");
public static final Item Sniperammo = new ItemSniperammo(161).setItemName("Sniperammo");
public void load()
{
Sniper.iconIndex = ModLoader.addOverride("/gui/items.png", "/zombies/sniper.png");
ModLoader.addName(Sniper, "Sniper Rifle");
ModLoader.addRecipe(new ItemStack(Sniper, 1), new Object [] {"#", Character.valueOf('#'), Block.dirt});
Sniperammo.iconIndex = ModLoader.addOverride("/gui/items.png", "/zombies/sniperammo.png");
ModLoader.addName(Sniperammo, "Sniper Bullets");
ModLoader.addRecipe(new ItemStack(Sniperammo, 64), new Object [] {"##", Character.valueOf('#'), Block.dirt});
}
public String getVersion()
{
return "1.3.1";
}
}
ItemSniper
package net.minecraft.src;
public class ItemSniper extends Item
{
public ItemSniper(int var1)
{
super(var1);
this.maxStackSize = 1;
}
public ItemStack onFoodEaten(ItemStack var1, World var2, EntityPlayer var3)
{
return var1;
}
/**
* How long it takes to use or consume an item
*/
public int getMaxItemUseDuration(ItemStack var1)
{
return 92000;
}
/**
* Called whenever this item is equipped and the right mouse button is pressed. Args: itemStack, world, entityPlayer
*/
public ItemStack onItemRightClick(ItemStack var1, World var2, EntityPlayer var3)
{
if (var3.inventory.hasItem(mod_zombie.Sniperammo.shiftedIndex))
{
EntitySniperammo var4 = new EntitySniperammo(var2, var3, 4.0F);
var4.arrowCritical = false;
var3.inventory.consumeInventoryItem(mod_zombie.Sniperammo.shiftedIndex);
var2.playSoundAtEntity(var3, "random.bow", 1.0F, 1.0F / (itemRand.nextFloat() * 0.4F + 1.2F));
var2.spawnEntityInWorld(var4);
}
return var1;
}
}
“Most good programmers do programming not because they expect to get paid or get adulation by the public, but because it is fun to program.”
- Linus Torvalds (Finnish American, software engineer and hacker, principal force behind the development of the Linux kernel)
For the gun delay I was thinking of putting an if then statement like if the timer is > then 0 it will not shoot and every time you shoot it sets the timers to a given number. Would anyone know how to code this?
For the gun delay I was thinking of putting an if then statement like if the timer is > then 0 it will not shoot and every time you shoot it sets the timers to a given number. Would anyone know how to code this?
Yeah, have your mod extend BaseMod (from ModLoader) Then, override a method called onTickInGame(float var 1, Minecraft var2).
Do your timer stuff in here, then return false.
Rollback Post to RevisionRollBack
“Most good programmers do programming not because they expect to get paid or get adulation by the public, but because it is fun to program.”
- Linus Torvalds (Finnish American, software engineer and hacker, principal force behind the development of the Linux kernel)
“Most good programmers do programming not because they expect to get paid or get adulation by the public, but because it is fun to program.”
- Linus Torvalds (Finnish American, software engineer and hacker, principal force behind the development of the Linux kernel)
ok so I couldn't get that to work so i made it like this
private int firingDelay;
public ItemSniper(int var1)
{
super(var1);
this.maxStackSize = 1;
this.setTabToDisplayOn(CreativeTabs.tabCombat);
firingDelay = 0;
}
public void onUpdate(ItemStack itemstack, World world, Entity entity, int i, boolean flag){
if(firingDelay > 0){
firingDelay--;
}
}
public ItemStack onItemRightClick(ItemStack var1, World var2, EntityPlayer var3)
{
if (var3.inventory.hasItem(mod_zombie.Sniperammo.shiftedIndex))
if(firingDelay <= 0)
{
EntitySniperammo var4 = new EntitySniperammo(var2, var3, 4.0F);
var4.arrowCritical = false;
var3.inventory.consumeInventoryItem(mod_zombie.Sniperammo.shiftedIndex);
var2.playSoundAtEntity(var3, "random.bow", 1.0F, 1.0F / (itemRand.nextFloat() * 0.4F + 1.2F));
var2.spawnEntityInWorld(var4);
firingDelay = 10; //Set this as you'd like
}
The only problem is that when i set the delay it lets me fire but once the 10 seconds are over it resets me back to the amount i had before I fired and only fires one bullet. How can i set it so that it doesn't let the gun shoot at all during the 10 seconds.
I can post a video if you want to see what happens.
I can post a video if you want to see what happens.
Yes, can you? I don't really get what you're saying.
Rollback Post to RevisionRollBack
“Most good programmers do programming not because they expect to get paid or get adulation by the public, but because it is fun to program.”
- Linus Torvalds (Finnish American, software engineer and hacker, principal force behind the development of the Linux kernel)
Ok sorry for the lag in the video but just watch the bullets and then how they go back to the original amount once the cow dies. I thought it was lag related at first but it only happens when the code is in.
Ok sorry for the lag in the video but just watch the bullets and then how they go back to the original amount once the cow dies. I thought it was lag related at first but it only happens when the code is in.
I don't know how to really solve this. My best guess would be to make a counter of how many bullets the gun fires. Then if the amount is reset, remove the amount of bullets that was fired from the player's inventory and reset the bullet counter.
Rollback Post to RevisionRollBack
“Most good programmers do programming not because they expect to get paid or get adulation by the public, but because it is fun to program.”
- Linus Torvalds (Finnish American, software engineer and hacker, principal force behind the development of the Linux kernel)
I don't know how to really solve this. My best guess would be to make a counter of how many bullets the gun fires. Then if the amount is reset, remove the amount of bullets that was fired from the player's inventory and reset the bullet counter.
Ya, can you post an example of the files? Maybe like a pistol or whatever I get how you did it, im not new to modding just could use an example to work with
hey u moind helping me out?,my mod is for vers 1.7.10 and i want to be able to make a gun that shoots firecharges in the players direction,can u give me the code for that?thx i really nned the help!
It would be great if someone showed me what code I had to add or what part I had to edit in order to customize these features. For the shot delay I tried editing the getMaxItemUseDuration from return 72000 to 90000 and I trid other amounts but none of that worked.
mod_zombie
ItemSniper
EntitySniperammo
- Linus Torvalds (Finnish American, software engineer and hacker, principal force behind the development of the Linux kernel)
Misread the site lol. I am not sure how to make this code shorter because I am not sure what is needed in order to add these features to my gun
* Sets the velocity to the args. Args: x, y, z
*/
public void setVelocity(double var1, double var3, double var5)
{
this.motionX = var1;
this.motionY = var3;
this.motionZ = var5;
Play around with that.
Yeah, have your mod extend BaseMod (from ModLoader) Then, override a method called onTickInGame(float var 1, Minecraft var2).
Do your timer stuff in here, then return false.
- Linus Torvalds (Finnish American, software engineer and hacker, principal force behind the development of the Linux kernel)
- Linus Torvalds (Finnish American, software engineer and hacker, principal force behind the development of the Linux kernel)
The only problem is that when i set the delay it lets me fire but once the 10 seconds are over it resets me back to the amount i had before I fired and only fires one bullet. How can i set it so that it doesn't let the gun shoot at all during the 10 seconds.
I can post a video if you want to see what happens.
Yes, can you? I don't really get what you're saying.
- Linus Torvalds (Finnish American, software engineer and hacker, principal force behind the development of the Linux kernel)
Ok sorry for the lag in the video but just watch the bullets and then how they go back to the original amount once the cow dies. I thought it was lag related at first but it only happens when the code is in.
I don't know how to really solve this. My best guess would be to make a counter of how many bullets the gun fires. Then if the amount is reset, remove the amount of bullets that was fired from the player's inventory and reset the bullet counter.
- Linus Torvalds (Finnish American, software engineer and hacker, principal force behind the development of the Linux kernel)
I didn't get it from a tutorial just took copied the bow and arrow files and took out what I didnt need if you want the files I made I can post them.
Ok thanks ill try and do that
hey u moind helping me out?,my mod is for vers 1.7.10 and i want to be able to make a gun that shoots firecharges in the players direction,can u give me the code for that?thx i really nned the help!
http://www.minecraftforum.net/forums/mapping-and-modding/minecraft-mods/2507269-stevenuniversecraft-mod