I'm am working on a mod that has guns in it, and I have searched the web like crazy trying to find proper tutorials on creating guns, but nothing has worked so far. I tried this tutorial:
but it was out of date and I couldn't use the variable 'par3EntityPlayer.capabilities.depleteBuckets'
and I have tried de-compiling source code from SDKs gun mod, but there is just so much stuff that I can't really figure out myself.
What I want to make is a basic gun system. You craft the gun, you craft the ammo, the gun shoots, depletes one of the ammo itemstack, and creates a bullet entity/invisible bullet entity (idk which) that "shoots" forward and does damage to mobs and players.
I don't want to worry about recoil or anything because that just doesn't work in minecraft. If you can get a particle showing up near the gun item after I shoot that would be great too, but I don't really NEED it. Again, this is all for a bigger project and I need this working first.
Running Windows XP Home Service Pack 3 and Java SE 7u5 incase you might need that, though idk why.
I am using Minecraft 1.2.5 and Eclipse.
I also want to play a sound (which I have already) when I shoot and I don't want any fancy reload stuff.
Thanks in Advance,
Nighthawk
Hey Modders! If you need some example code for creating guns for your ModLoader mods then please look at the code I have posted below. (not the first code I post but the second code, it's more up-to-date)
Score! I figured out how to do it! The only problem is IDK how to make my pistol non-automatic lol. Any clue how to do this? I also want to know how to texture/color custom entities. This will be all, Nighthawk
Score! I figured out how to do it! The only problem is IDK how to make my pistol non-automatic lol. Any clue how to do this? I also want to know how to texture/color custom entities. This will be all, Nighthawk
sooo how do u make the guns/ammo? i curious to know myself
sooo how do u make the guns/ammo? i curious to know myself
This is my work in progress code. It passes in an extra parameter that determines its damage value. Currently the projectiles behave like a throwable snowball that packs a bit more punch lol.
package net.minecraft.src;
public class ItemGun extends Item{
private byte damage;
public ItemGun(int i, byte dmg){
super(i);
maxStackSize = 1;
damage = dmg;
}
public ItemStack onItemRightClick(ItemStack par1ItemStack, World par2World, EntityPlayer par3EntityPlayer){
if(par3EntityPlayer.inventory.hasItem(mod_zombieCraft.pistolclip.shiftedIndex)){
par3EntityPlayer.inventory.consumeInventoryItem(mod_zombieCraft.pistolclip.shiftedIndex);
if(!par2World.isRemote){
par2World.spawnEntityInWorld(new EntityBullet(par2World, par3EntityPlayer, (byte)5));
}
}
return par1ItemStack;
}
public int getMaxItemUseDuration(ItemStack par1ItemStack){
return 10;
}
}
package net.minecraft.src;
public class mod_zombieCraft extends BaseMod{
public static final Item pistolclip = new Item(386).setItemName("Pistol Clip");
public static final Item pistol = new ItemGun(387, (byte)5).setItemName("Gun");
public void load(){
pistolclip.iconIndex = ModLoader.addOverride("/gui/items.png", "/zombiecraft/Item/magnum.png");
pistol.iconIndex = ModLoader.addOverride("/gui/items.png", "/zombiecraft/Item/magnum.png");
ModLoader.addName(pistolclip, "Pistol Mag");
ModLoader.addName(pistol, "Magnum");
//I added some 'Cheat' recipies XD. Just so I don't have to get resources in survival to test lol
ModLoader.addRecipe(new ItemStack(Item.ingotIron, 64), new Object[]{
"##", Character.valueOf('#'), Block.dirt
});
ModLoader.addRecipe(new ItemStack(Item.gunpowder, 64), new Object[]{
" # ", "###", "###", Character.valueOf('#'), Block.dirt
});
ModLoader.addShapelessRecipe(new ItemStack(pistolclip, 10), new Object[]{
Item.gunpowder, Item.ingotIron
});
ModLoader.addRecipe(new ItemStack(pistol, 1), new Object[]{
"###", " #", " #", Character.valueOf('#'), Item.ingotIron
});
}
public String getVersion(){
return "1.2.5";
}
}
looks like you need some gunpowder , this mod looks good.
lol thanks I'm working on getting the bullets to shoot strait today. And I also got things working so that weapons like the pistol will have fire delay. All the recipes for the guns/ammo clips are temporary, as I plan to try making fully customizable weapons by mixing around the different parts, allowing for the creation of Pistols, UZIs, Machine Guns, Shotguns etc.
I also want to try adding an accuracy setting that will make the bullets shoot less accurately (entities spawning a little bit to the left or right depending on accuracy variable and random numbers) or more accurately. This will be good for making sniper rifles a bit more useful and machine guns less accurate etc.
I can help you with the custom bullet rendering texture thingy, basically you would have to make a RenderBullet class. Depending on what you want to make the bullet look like, you could go many ways. My suggestion is taking the RenderArrow code, changing the texture file to something smaller and changing the size of the bullet so that it looks like an arrow (in the way its rendered) but is much smaller + has a different texture.
EDIT: I noticed your ItemGun code makes it so that it removes a whole clip, but damages the gun giving it a max use of 10. Wouldn't it be better to damage the clip?
I can help you with the custom bullet rendering texture thingy, basically you would have to make a RenderBullet class. Depending on what you want to make the bullet look like, you could go many ways. My suggestion is taking the RenderArrow code, changing the texture file to something smaller and changing the size of the bullet so that it looks like an arrow (in the way its rendered) but is much smaller + has a different texture.
EDIT: I noticed your ItemGun code makes it so that it removes a whole clip, but damages the gun giving it a max use of 10. Wouldn't it be better to damage the clip?
EDIT2: NVM about the 10 uses thing, but it would make sense to either change it to consume bullets, or damage the clip.
lol sorry. You really should learn Java. Even after around a year of learning Java programming Minecraft was still very overwhelming and complicated to learn. Now that I'm better at Java, Minecraft code actually helps me get a better understand of how to make games (which is what I code java for in the first place )
Anyways you basically need to do this:
public ItemGun(int i, byte dmg){
super(i);
maxStackSize = 1;
damage = dmg;
setSize(1.0F, 1.0F);
}
except you replace 1.0 with the size of your bullet.
Also guys, my new and improved gun code. This adds functionality that decreases the durability of the gun by 1 each time you shoot. Then once you have only one durability left it wont do anything unless you have a clip, if you have a clip it will activate a reload timer and once that timer is over then it will deplete the clip and damage the item by a negative number, restoring the durability. I also got the bullets to shoot strait! I used the arrow code and also made it so that the arrow does not stay on the ground ;D
If anybody can get it so that the bullets don't bounce off each other like arrows that would help, but I'm not going to worry too much about it as it isn't a game changing bug. Just gives you a bad visual effect...
Item Creation that you do outside of your mod_modName
public static Item Magnum = new ItemGun(397, 5, 1, "Pistol", "zombiecraft.gun.pistol", 10).setItemName("Magnum");
[/spoiler]
ItemGun.java
[spoiler]
package net.minecraft.src;
public class ItemGun extends Item{
private double damage;
private final int shotdelay;
private int shotcounter;
private int bulletid;
private String bullettype;
private String sound;
private int maxammo;
private int reloadcounter;
private int reloadspeed;
/**
* Creates a new gun. Parameters: int ID, byte Damage, int Fire Delay, int Gun Type
*/
public ItemGun(int i, double dmg, int firedelay, String type, String soundtoset, int ammo){
super(i);
maxStackSize = 1;
maxammo = ammo;
setMaxDamage(maxammo + 1);
damage = dmg;
shotdelay = firedelay;
shotcounter = 0;
bulletid = 0;
sound = soundtoset;
reloadspeed = 4;
reloadcounter = 0;
if(type.equals("Machine Gun")){
bulletid = mod_zombieCraft.MGClip.shiftedIndex;
bullettype = "Normal";
}else if(type.equals("Shotgun")){
bulletid = mod_zombieCraft.ShotgunShell.shiftedIndex;
bullettype = "Shotgun";
}else if(type.equals("Pistol")){
bulletid = mod_zombieCraft.PistolClip.shiftedIndex;
bullettype = "Normal";
};
}
public ItemStack onItemRightClick(ItemStack par1ItemStack, World par2World, EntityPlayer par3EntityPlayer){
if(shotcounter == shotdelay){
if(par1ItemStack.getItemDamage() != maxammo){
par1ItemStack.damageItem(1, par3EntityPlayer);
if (!par2World.isRemote) {
par2World.spawnEntityInWorld(new EntityBullet(par2World, par3EntityPlayer, 3F, damage, bullettype));
par2World.playSoundAtEntity(par3EntityPlayer, sound, 0F, 2.5F);
}
}else if(par1ItemStack.getItemDamage() == maxammo && par3EntityPlayer.inventory.hasItem(bulletid)){
if(reloadcounter == reloadspeed){
par1ItemStack.damageItem(-maxammo, par3EntityPlayer);
par3EntityPlayer.inventory.consumeInventoryItem(bulletid);
par2World.playSoundAtEntity(par3EntityPlayer,"zombiecraft.gun.startreloading", 0F, 2.5F);
}else{
if(reloadcounter == 0){
par2World.playSoundAtEntity(par3EntityPlayer, "zombiecraft.gun.startreloading", 0F, 2.5F);
}
++reloadcounter;
}
}
shotcounter = 0;
}else{
++shotcounter;
}
return par1ItemStack;
}
public float getStrVsBlock(ItemStack par1ItemStack, Block par2Block){
return 0.5F;
}
public int getDamageVsEntity(Entity par1Entity){
return 4;
}
public boolean isFull3D(){
return true;
}
}
[/spoiler]
notice the method at the end that says 'isFull3D' and returns true? Well that is actually extremely helpful. This is basically what swords/picks/shovels do so that they show up in 3D and are a lot bigger (in 3rd person/multiplayer) If you make your gun textures barrel pointing at the top right (like SDKs gun mod) then you can usually get the guns handle around the area where your characters hand is, and it has a really cool effect even if he doesn't look like he's aiming when he shoots the gun XD
Have you gotten the sounds to effectively work, meaning when you test them, you can hear said sounds? If so, do you use eclipse, or run it from the mcp folder. If you run it out of eclipse, where do you put the sound files.
EDIT: For the bullets not behaving just like arrows, feel free to use this code. It basically causes the bullet to move very fast, with little/no accuracy change even at long distances. It would be possible to change that, but hard because of the way hit detection works with this entity, slower bullets for some reason don't properly register as hitting entities.
Have you gotten the sounds to effectively work, meaning when you test them, you can hear said sounds? If so, do you use eclipse, or run it from the mcp folder. If you run it out of eclipse, where do you put the sound files.
EDIT: For the bullets not behaving just like arrows, feel free to use this code. It basically causes the bullet to move very fast, with little/no accuracy change even at long distances. It would be possible to change that, but hard because of the way hit detection works with this entity, slower bullets for some reason don't properly register as hitting entities.
Thanks, I'll try using this code. My only problem with the code so far is that there must be something in notchs code involving velocity to increase damage, as my zombies need 60 health just to survive more than 2 shots with a pistol lol.
About the sound, I'm unsure, the last time I did a sound test it crashed.
I tried using it, can't say it worked exactly, I have no way of making a proper .ogg yet. XD--I tried converting .wavs to .oggs via the save-as menu, but paulscode starting giving me errors...
Thanks, I'll try using this code. My only problem with the code so far is that there must be something in notchs code involving velocity to increase damage, as my zombies need 60 health just to survive more than 2 shots with a pistol lol.
About the sound, I'm unsure, the last time I did a sound test it crashed.
I tried using it, can't say it worked exactly, I have no way of making a proper .ogg yet. XD--I tried converting .wavs to .oggs via the save-as menu, but paulscode starting giving me errors...
Oh yeah, for the entity thing, use this code to spawn in the entity (if using my entitybullet code)
The parameters damage and accuracy are ints, so add those parameters to the ItemGun constructor. Your ItemGun class should have 2 private ints (damage and accuracy) and the constructor should include the ints like this:
public class ItemGun extends Item implements ITextureProvider
{
private int damage;
private int accuracy;
private Item clip;
private int rateOfFire;
private int recoil;
private int reloadTime;
private int shootDelay;
public String type;
private String sound;
private static boolean mouseHeld;
private static boolean lastMouseHeld;
/**
*
* @param i the id of the gun
* @param l damage of bullte (in half hears)
* @param i1 accuracy of bullet (doesn't seem to be a factor, due to EntityBullet code
* @param item bullet (or might be changed to clip) that provides ammo
* @param rof rate of fire while the right mouse is being held down, doesn't do anything if rapid right click
* @param j recoil of gun
* @param k reload time of gun in ticks
* @param p time between shots
* @param type type of gun, can't seem to get this to do anything
* @param s sound the gun plays, again I can't seem to get this to do anything
*/
public ItemGun(int i, int l, int i1, Item item, int rof, int j, int k, int p, String s, String s1)
{
super(i);
maxStackSize = 1;
damage = l;
//TODO fix the accuracy not having affect
accuracy = i1;
clip = item;
rateOfFire = rof;
recoil = j;
reloadTime = k;
shootDelay = p;
type = s;
sound = s1;
}
Edit: that ITextureProvider is only if you are using forge.
The parameters damage and accuracy are ints, so add those parameters to the ItemGun constructor. Your ItemGun class should have 2 private ints (damage and accuracy) and the constructor should include the ints like this:
public class ItemGun extends Item implements ITextureProvider
{
private int damage;
private int accuracy;
private Item clip;
private int rateOfFire;
private int recoil;
private int reloadTime;
private int shootDelay;
public String type;
private String sound;
private static boolean mouseHeld;
private static boolean lastMouseHeld;
/**
*
* @param i the id of the gun
* @param l damage of bullte (in half hears)
* @param i1 accuracy of bullet (doesn't seem to be a factor, due to EntityBullet code
* @param item bullet (or might be changed to clip) that provides ammo
* @param rof rate of fire while the right mouse is being held down, doesn't do anything if rapid right click
* @param j recoil of gun
* @param k reload time of gun in ticks
* @param p time between shots
* @param type type of gun, can't seem to get this to do anything
* @param s sound the gun plays, again I can't seem to get this to do anything
*/
public ItemGun(int i, int l, int i1, Item item, int rof, int j, int k, int p, String s, String s1)
{
super(i);
maxStackSize = 1;
damage = l;
//TODO fix the accuracy not having affect
accuracy = i1;
clip = item;
rateOfFire = rof;
recoil = j;
reloadTime = k;
shootDelay = p;
type = s;
sound = s1;
}
Edit: that ITextureProvider is only if you are using forge.
public class ItemGun extends Item implements
{
private int damage;
private int accuracy;
private Item clip;
private int rateOfFire;
private int recoil;
private int reloadTime;
private int shootDelay;
public String type;
private String sound;
private static boolean mouseHeld;
private static boolean lastMouseHeld;
/**
*
* @param i the id of the gun
* @param l damage of bullte (in half hears)
* @param i1 accuracy of bullet (doesn't seem to be a factor, due to EntityBullet code
* @param item bullet (or might be changed to clip) that provides ammo
* @param rof rate of fire while the right mouse is being held down, doesn't do anything if rapid right click
* @param j recoil of gun
* @param k reload time of gun in ticks
* @param p time between shots
* @param type type of gun, can't seem to get this to do anything
* @param s sound the gun plays, again I can't seem to get this to do anything
*/
public ItemGun(int i, int l, int i1, Item item, int rof, int j, int k, int p, String s, String s1)
{
super(i);
maxStackSize = 1;
damage = l;
//TODO fix the accuracy not having affect
accuracy = i1;
clip = item;
rateOfFire = rof;
recoil = j;
reloadTime = k;
shootDelay = p;
type = s;
sound = s1;
}
Mod_*****:
package net.minecraft.src;
public class mod_***** extends BaseMod{
public static final Item pistolclip = new Item(386).setItemName("Pistol Clip");
public static final Item pistol = new ItemGun(387, (byte)5).setItemName("Gun");
public void load(){
pistolclip.iconIndex = ModLoader.addOverride("/gui/items.png", "/zombiecraft/Item/magnum.png");
pistol.iconIndex = ModLoader.addOverride("/gui/items.png", "/zombiecraft/Item/magnum.png");
ModLoader.addName(pistolclip, "Pistol Mag");
ModLoader.addName(pistol, "Magnum");
//I added some 'Cheat' recipies XD. Just so I don't have to get resources in survival to test lol
ModLoader.addRecipe(new ItemStack(Item.ingotIron, 64), new Object[]{
"##", Character.valueOf('#'), Block.dirt
});
ModLoader.addRecipe(new ItemStack(Item.gunpowder, 64), new Object[]{
" # ", "###", "###", Character.valueOf('#'), Block.dirt
});
ModLoader.addShapelessRecipe(new ItemStack(pistolclip, 10), new Object[]{
Item.gunpowder, Item.ingotIron
});
ModLoader.addRecipe(new ItemStack(pistol, 1), new Object[]{
"###", " #", " #", Character.valueOf('#'), Item.ingotIron
});
}
public String getVersion(){
return "1.2.5";
}
}
I will change somethings,like names rates of speed,but...
public ItemGun(int i, int l, int i1, Item item, int rof, int j, int k, int p, String s, String s1)
{
super(i);
maxStackSize = 1;
damage = l;
//This works in ModLoader?
accuracy = i1; //All this things will work Normaly?
clip = item;
rateOfFire = rof;
recoil = j;
reloadTime = k;
shootDelay = p;
type = s;
sound = s1;
}
This will work?:
super(i);
maxStackSize = 1;
damage = 5;
accuracy = 11; //This works?
clip = 7;
rateOfFire = 10;
recoil = 10;
reloadTime = 12;
shootDelay = 10;
type = s;
sound = s1
Thank you and
sorry for my bad inglish
The parameters damage and accuracy are ints, so add those parameters to the ItemGun constructor. Your ItemGun class should have 2 private ints (damage and accuracy) and the constructor should include the ints like this:
public class ItemGun extends Item implements
{
private int damage;
private int accuracy;
private Item clip;
private int rateOfFire;
private int recoil;
private int reloadTime;
private int shootDelay;
public String type;
private String sound;
private static boolean mouseHeld;
private static boolean lastMouseHeld;
/**
*
* @param i the id of the gun
* @param l damage of bullte (in half hears)
* @param i1 accuracy of bullet (doesn't seem to be a factor, due to EntityBullet code
* @param item bullet (or might be changed to clip) that provides ammo
* @param rof rate of fire while the right mouse is being held down, doesn't do anything if rapid right click
* @param j recoil of gun
* @param k reload time of gun in ticks
* @param p time between shots
* @param type type of gun, can't seem to get this to do anything
* @param s sound the gun plays, again I can't seem to get this to do anything
*/
public ItemGun(int i, int l, int i1, Item item, int rof, int j, int k, int p, String s, String s1)
{
super(i);
maxStackSize = 1;
damage = l;
//TODO fix the accuracy not having affect
accuracy = i1;
clip = item;
rateOfFire = rof;
recoil = j;
reloadTime = k;
shootDelay = p;
type = s;
sound = s1;
}
Edit: that ITextureProvider is only if you are using forge.
public class ItemGun extends Item implements
{
private int damage;
private int accuracy;
private Item clip;
private int rateOfFire;
private int recoil;
private int reloadTime;
private int shootDelay;
public String type;
private String sound;
private static boolean mouseHeld;
private static boolean lastMouseHeld;
/**
*
* @param i the id of the gun
* @param l damage of bullte (in half hears)
* @param i1 accuracy of bullet (doesn't seem to be a factor, due to EntityBullet code
* @param item bullet (or might be changed to clip) that provides ammo
* @param rof rate of fire while the right mouse is being held down, doesn't do anything if rapid right click
* @param j recoil of gun
* @param k reload time of gun in ticks
* @param p time between shots
* @param type type of gun, can't seem to get this to do anything
* @param s sound the gun plays, again I can't seem to get this to do anything
*/
public ItemGun(int i, int l, int i1, Item item, int rof, int j, int k, int p, String s, String s1)
{
super(i);
maxStackSize = 1;
damage = l;
//TODO fix the accuracy not having affect
accuracy = i1;
clip = item;
rateOfFire = rof;
recoil = j;
reloadTime = k;
shootDelay = p;
type = s;
sound = s1;
}
Mod_*****:
package net.minecraft.src;
public class mod_***** extends BaseMod{
public static final Item pistolclip = new Item(386).setItemName("Pistol Clip");
public static final Item pistol = new ItemGun(387, (byte)5).setItemName("Gun");
public void load(){
pistolclip.iconIndex = ModLoader.addOverride("/gui/items.png", "/zombiecraft/Item/magnum.png");
pistol.iconIndex = ModLoader.addOverride("/gui/items.png", "/zombiecraft/Item/magnum.png");
ModLoader.addName(pistolclip, "Pistol Mag");
ModLoader.addName(pistol, "Magnum");
//I added some 'Cheat' recipies XD. Just so I don't have to get resources in survival to test lol
ModLoader.addRecipe(new ItemStack(Item.ingotIron, 64), new Object[]{
"##", Character.valueOf('#'), Block.dirt
});
ModLoader.addRecipe(new ItemStack(Item.gunpowder, 64), new Object[]{
" # ", "###", "###", Character.valueOf('#'), Block.dirt
});
ModLoader.addShapelessRecipe(new ItemStack(pistolclip, 10), new Object[]{
Item.gunpowder, Item.ingotIron
});
ModLoader.addRecipe(new ItemStack(pistol, 1), new Object[]{
"###", " #", " #", Character.valueOf('#'), Item.ingotIron
});
}
public String getVersion(){
return "1.2.5";
}
}
I will change somethings,like names rates of speed,but...
public class ItemGun extends Item implements
{
private int damage;
private int accuracy;
private Item clip;
private int rateOfFire;
private int recoil;
private int reloadTime;
private int shootDelay;
public String type;
private String sound;
private static boolean mouseHeld;
private static boolean lastMouseHeld;
/**
*
* @param i the id of the gun
* @param l damage of bullte (in half hears)
* @param i1 accuracy of bullet (doesn't seem to be a factor, due to EntityBullet code
* @param item bullet (or might be changed to clip) that provides ammo
* @param rof rate of fire while the right mouse is being held down, doesn't do anything if rapid right click
* @param j recoil of gun
* @param k reload time of gun in ticks
* @param p time between shots
* @param type type of gun, can't seem to get this to do anything
* @param s sound the gun plays, again I can't seem to get this to do anything
*/
public ItemGun(int i, int l, int i1, Item item, int rof, int j, int k, int p, String s, String s1)
{
super(i);
maxStackSize = 1;
damage = l;
//This works in ModLoader?
accuracy = i1; //All this things will work Normaly?
clip = item;
rateOfFire = rof;
recoil = j;
reloadTime = k;
shootDelay = p;
type = s;
sound = s1;
}
This will work?: public class ItemGun extends Item implements
{
private int damage;
private int accuracy;
private Item clip;
private int rateOfFire;
private int recoil;
private int reloadTime;
private int shootDelay;
public String type;
private String sound;
private static boolean mouseHeld;
private static boolean lastMouseHeld;
/**
*
* @param i the id of the gun
* @param l damage of bullte (in half hears)
* @param i1 accuracy of bullet (doesn't seem to be a factor, due to EntityBullet code
* @param item bullet (or might be changed to clip) that provides ammo
* @param rof rate of fire while the right mouse is being held down, doesn't do anything if rapid right click
* @param j recoil of gun
* @param k reload time of gun in ticks
* @param p time between shots
* @param type type of gun, can't seem to get this to do anything
* @param s sound the gun plays, again I can't seem to get this to do anything
*/
super(i);
maxStackSize = 1;
damage = 5;
accuracy = 11; //This works?
clip = 7;
rateOfFire = 10;
recoil = 10;
reloadTime = 12;
shootDelay = 10;
type = s;
sound = s1
Thank you and
sorry for my bad inglish
I'm am working on a mod that has guns in it, and I have searched the web like crazy trying to find proper tutorials on creating guns, but nothing has worked so far. I tried this tutorial:
http://www.minecraft...5#entry13522705
but it was out of date and I couldn't use the variable 'par3EntityPlayer.capabilities.depleteBuckets'
and I have tried de-compiling source code from SDKs gun mod, but there is just so much stuff that I can't really figure out myself.
What I want to make is a basic gun system. You craft the gun, you craft the ammo, the gun shoots, depletes one of the ammo itemstack, and creates a bullet entity/invisible bullet entity (idk which) that "shoots" forward and does damage to mobs and players.
I don't want to worry about recoil or anything because that just doesn't work in minecraft. If you can get a particle showing up near the gun item after I shoot that would be great too, but I don't really NEED it. Again, this is all for a bigger project and I need this working first.
Running Windows XP Home Service Pack 3 and Java SE 7u5 incase you might need that, though idk why.
I am using Minecraft 1.2.5 and Eclipse.
I also want to play a sound (which I have already) when I shoot and I don't want any fancy reload stuff.
Thanks in Advance,
Nighthawk
Hey Modders! If you need some example code for creating guns for your ModLoader mods then please look at the code I have posted below. (not the first code I post but the second code, it's more up-to-date)
sooo how do u make the guns/ammo? i curious to know myself
for would be best, if you havent tried it already
edit: misread sorry
This is my work in progress code. It passes in an extra parameter that determines its damage value. Currently the projectiles behave like a throwable snowball that packs a bit more punch lol.
lol thanks I'm working on getting the bullets to shoot strait today. And I also got things working so that weapons like the pistol will have fire delay. All the recipes for the guns/ammo clips are temporary, as I plan to try making fully customizable weapons by mixing around the different parts, allowing for the creation of Pistols, UZIs, Machine Guns, Shotguns etc.
I also want to try adding an accuracy setting that will make the bullets shoot less accurately (entities spawning a little bit to the left or right depending on accuracy variable and random numbers) or more accurately. This will be good for making sniper rifles a bit more useful and machine guns less accurate etc.
Also do you know how to change the texture on the bullet when you shoot it? Right now when you shoot it its just a cube.
Yes I am aware of this. I am trying to find a new system so I can get custom textures/colors, and to get it to shoot strait.
If you call the method: setSize(float par1, float par2) inside you constructor you can change the size of the bullet.
EDIT: I noticed your ItemGun code makes it so that it removes a whole clip, but damages the gun giving it a max use of 10. Wouldn't it be better to damage the clip?
I'm new to Java so Im not sure what you mean.
lol sorry. You really should learn Java. Even after around a year of learning Java programming Minecraft was still very overwhelming and complicated to learn. Now that I'm better at Java, Minecraft code actually helps me get a better understand of how to make games (which is what I code java for in the first place )
Anyways you basically need to do this:
except you replace 1.0 with the size of your bullet.
Also guys, my new and improved gun code. This adds functionality that decreases the durability of the gun by 1 each time you shoot. Then once you have only one durability left it wont do anything unless you have a clip, if you have a clip it will activate a reload timer and once that timer is over then it will deplete the clip and damage the item by a negative number, restoring the durability. I also got the bullets to shoot strait! I used the arrow code and also made it so that the arrow does not stay on the ground ;D
If anybody can get it so that the bullets don't bounce off each other like arrows that would help, but I'm not going to worry too much about it as it isn't a game changing bug. Just gives you a bad visual effect...
Item Creation that you do outside of your mod_modName
[/spoiler]
ItemGun.java
[spoiler]
[/spoiler]
notice the method at the end that says 'isFull3D' and returns true? Well that is actually extremely helpful. This is basically what swords/picks/shovels do so that they show up in 3D and are a lot bigger (in 3rd person/multiplayer) If you make your gun textures barrel pointing at the top right (like SDKs gun mod) then you can usually get the guns handle around the area where your characters hand is, and it has a really cool effect even if he doesn't look like he's aiming when he shoots the gun XD
EntityBullet.java
[spoiler]
[/spoiler]
EDIT: For the bullets not behaving just like arrows, feel free to use this code. It basically causes the bullet to move very fast, with little/no accuracy change even at long distances. It would be possible to change that, but hard because of the way hit detection works with this entity, slower bullets for some reason don't properly register as hitting entities.
Thanks, I'll try using this code. My only problem with the code so far is that there must be something in notchs code involving velocity to increase damage, as my zombies need 60 health just to survive more than 2 shots with a pistol lol.
About the sound, I'm unsure, the last time I did a sound test it crashed.
Try audiomod or this: http://www.minecraftforum.net/topic/1058091-tutorial-how-to-use-custom-sounds-without-audiomod/
I tried using it, can't say it worked exactly, I have no way of making a proper .ogg yet. XD--I tried converting .wavs to .oggs via the save-as menu, but paulscode starting giving me errors...
Oh yeah, for the entity thing, use this code to spawn in the entity (if using my entitybullet code)
Edit: that ITextureProvider is only if you are using forge.
This work(In ModLoader)?:
EntityBullet:
ItemGun:
Mod_*****:
I will change somethings,like names rates of speed,but...
public ItemGun(int i, int l, int i1, Item item, int rof, int j, int k, int p, String s, String s1)
{
super(i);
maxStackSize = 1;
damage = l;
//This works in ModLoader?
accuracy = i1; //All this things will work Normaly?
clip = item;
rateOfFire = rof;
recoil = j;
reloadTime = k;
shootDelay = p;
type = s;
sound = s1;
}
This will work?:
super(i);
maxStackSize = 1;
damage = 5;
accuracy = 11; //This works?
clip = 7;
rateOfFire = 10;
recoil = 10;
reloadTime = 12;
shootDelay = 10;
type = s;
sound = s1
Thank you and
sorry for my bad inglish
This work(In ModLoader)?:
EntityBullet:
ItemGun:
Mod_*****:
I will change somethings,like names rates of speed,but...
public class ItemGun extends Item implements
{
private int damage;
private int accuracy;
private Item clip;
private int rateOfFire;
private int recoil;
private int reloadTime;
private int shootDelay;
public String type;
private String sound;
private static boolean mouseHeld;
private static boolean lastMouseHeld;
/**
*
* @param i the id of the gun
* @param l damage of bullte (in half hears)
* @param i1 accuracy of bullet (doesn't seem to be a factor, due to EntityBullet code
* @param item bullet (or might be changed to clip) that provides ammo
* @param rof rate of fire while the right mouse is being held down, doesn't do anything if rapid right click
* @param j recoil of gun
* @param k reload time of gun in ticks
* @param p time between shots
* @param type type of gun, can't seem to get this to do anything
* @param s sound the gun plays, again I can't seem to get this to do anything
*/
public ItemGun(int i, int l, int i1, Item item, int rof, int j, int k, int p, String s, String s1)
{
super(i);
maxStackSize = 1;
damage = l;
//This works in ModLoader?
accuracy = i1; //All this things will work Normaly?
clip = item;
rateOfFire = rof;
recoil = j;
reloadTime = k;
shootDelay = p;
type = s;
sound = s1;
}
This will work?:
public class ItemGun extends Item implements
{
private int damage;
private int accuracy;
private Item clip;
private int rateOfFire;
private int recoil;
private int reloadTime;
private int shootDelay;
public String type;
private String sound;
private static boolean mouseHeld;
private static boolean lastMouseHeld;
/**
*
* @param i the id of the gun
* @param l damage of bullte (in half hears)
* @param i1 accuracy of bullet (doesn't seem to be a factor, due to EntityBullet code
* @param item bullet (or might be changed to clip) that provides ammo
* @param rof rate of fire while the right mouse is being held down, doesn't do anything if rapid right click
* @param j recoil of gun
* @param k reload time of gun in ticks
* @param p time between shots
* @param type type of gun, can't seem to get this to do anything
* @param s sound the gun plays, again I can't seem to get this to do anything
*/
super(i);
maxStackSize = 1;
damage = 5;
accuracy = 11; //This works?
clip = 7;
rateOfFire = 10;
recoil = 10;
reloadTime = 12;
shootDelay = 10;
type = s;
sound = s1
Thank you and
sorry for my bad inglish
Anybody help with this.