The Meaning of Life, the Universe, and Everything.
Join Date:
4/24/2014
Posts:
108
Member Details
NOTE: I now have a new problem with textures, please look at latest post.
Fixed, but my client doesn't want to start anymore.
ORIGINAL POST:
Here's the thing:
I'm making a Minecraft Mod for 1.6.4, and I am trying to add in Blaze Swords which when right-clicked, spawn fireballs that shoot away from the player. I would also like help with adding enchantments on items so when they spawn, they already have the enchantment.
If it helps, here's my code for BlazeSword.java:
package eclipsis.mod.items;
import net.minecraft.item.EnumToolMaterial;
import net.minecraft.item.ItemSword;
public class BlazeSword extends ItemSword{
public BlazeSword(int par1, EnumToolMaterial par2EnumToolMaterial) {
super(2010, par2EnumToolMaterial);
}
}
I have the sword working fine, it does what it's supposed to, textures are ok, but I don't know how to do this stuff, and help would be much, much, MUCH appreciated.
Thanks in advance to anyone who will help.
NOTE: Also, if you think I should learn Basic Java before doing any of this, please link me to a place where I can learn the Basics of Java that are used by Minecraft. Thanks for your time.
For learning java, it can vary what's the best - I learnt most of it via books, but some learn best via video tutorials. Minecraft's "Basic" java is some moderately advanced OOP (packages, interfaces, etcetera), which any good java tutorial will cover early on.
If you want to get to advanced, which is what allows you to make AMAZING mods (EG. Forge, my current API project, or any real sort of API), you'd have to learn annotations, generics, and, if you use Java 8 (which not many do quite yet in the modding community, but when Minecraft hits java 7 (it had better), I'll be moving on to Java 8, if just for type/variable annotations), Lambda expressions, possibly more. But if this is a test mod, just ignore this paragraph.
Done that? Ok, good.
You can override the onItemRightClick method. Summoning the fireball will be the hard part, but you can look in the ghast code for fireball launching code. You are passed the player and the world object, which is everything needed for summoning fireballs.
Thanks for the help. The mod is in a sort-of Beta stage, where I'm really just testing to see what works best. However later on, I will make it a bit more advanced, having more content. The idea of the mod is "What Could Have Been" in Minecraft, adding more uses to stuff not normally used (Emerald, obsidian, blaze rods, etc.) Thanks for replying, and I guess I better start studying!
I think you have to add the enchantment to the ItemStack object via the method addEnchantment (at least in 1.7.2, I think it's the same in 1.6.4), which takes an Enchantment object and an int indicating the level. If you just want the effect, however, override hasEffect and make it return true. For example, in Forge, I assume you do it like this to enchant it on crafting:
GameRegistry.addRecipe(new ItemStack(ModItems.yourItem).addEnchantment(Enchantment.sharpness, 5), new Object[] {" X ", " X ", " Y ", new ItemStack(Items.stick), "Y", new ItemStack(Blocks.obsidian), "X"});
By the way, if possible, update to 1.7.2, it's the recommended version and Minecraft's code is cleaner. EDIT: Wait, this method existed? Why can't Forge just have some bleeding documentation?!
Thank you so much, guys! You are very nice to me, and are really helpful! You guys are definitely going in the credits of my mod
Rollback Post to RevisionRollBack
If you thought something was missing in Minecraft, think again.
MoreMine is coming soon for Minecraft 1.7.10
The Meaning of Life, the Universe, and Everything.
Join Date:
4/24/2014
Posts:
108
Member Details
Trying PD's original first method, it seems to be working, but the method addRecipe(ItemStack, Object...) in the type GameRegistry is not applicable for the arguments (Item, String, String, String, String, ItemStack). So I have to fix it by creating a method in 'GameRegistry', apparently, but I don't want to mess with the original source code. Maybe I'll just go with Xuluf's code.
Edit: Almost out of posts, so... I will talk through edits. But... I found this.
"void is an invalid type for the variable onCreated"Here is the BlazeSword coding once again:
package eclipsis.mod.items;
import net.minecraft.enchantment.Enchantment;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.EnumToolMaterial;
import net.minecraft.item.ItemStack;
import net.minecraft.item.ItemSword;
import net.minecraft.world.World;
public class BlazeSword extends ItemSword{
public BlazeSword(int par1, EnumToolMaterial par2EnumToolMaterial) {
super(2010, par2EnumToolMaterial);
public void onCreated(ItemStack par1ItemStack; World par2world; EntityPlayer par3Entityplayer;
par1ItemStack.addEnchantment(Enchantment.fireAspect, 2);
{
}
}
}
public void onCreated(ItemStack par1ItemStack; World par2World; EntityPlayer par3EntityPlayer;)
with:
public void onCreated(ItemStack par1ItemStack, World par2World, EntityPlayer par3EntityPlayer)
also move your code out of the constructor.. That is what's giving you the error..
so:
package eclipsis.mod.items;
import net.minecraft.enchantment.Enchantment;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.EnumToolMaterial;
import net.minecraft.item.ItemStack;
import net.minecraft.item.ItemSword;
import net.minecraft.world.World;
public class BlazeSword extends ItemSword{
public BlazeSword(int par1, EnumToolMaterial par2EnumToolMaterial) {
super(2010, par2EnumToolMaterial);
}
public void onCreated(ItemStack par1ItemStack; World par2world; EntityPlayer par3Entityplayer) {
par1ItemStack.addEnchantment(Enchantment.fireAspect, 2);
}
}
don't know if you already solved your initial problem or not, but shooting a fireball from your sword is done with this example code taken from the Snowball's code.[/indent]
public ItemStack onItemRightClick(ItemStack par1ItemStack, World par2World, EntityPlayer par3EntityPlayer)[/indent]
{
if (!par3EntityPlayer.capabilities.isCreativeMode)
{
--par1ItemStack.stackSize;
}
par2World.playSoundAtEntity(par3EntityPlayer, "random.bow", 0.5F, 0.4F / (itemRand.nextFloat() * 0.4F + 0.8F));
if (!par2World.isRemote)
{
par2World.spawnEntityInWorld(new EntitySnowball(par2World, par3EntityPlayer));
}
return par1ItemStack;
}
[/indent]
Edit: I didn't read your post correctly, ignore this.
Hey, thanks. I actually now can improve my code. You will also go into my credits.
EDIT: Wait, apparently when I replace Snowball with SmallFireball it doesn't work. I have the imports, but... What could be causing the problem? PM me for the code of the BlazeSword if you can help.
The Meaning of Life, the Universe, and Everything.
Join Date:
4/24/2014
Posts:
108
Member Details
Well, Xuluf, your code worked, but is there another on*insert something here* function? Like maybe, onItemSpawn or onItemGetFromCreativeTab? Because I really want it to be enchanted 100.00% of the time. The mod is still in Beta, so I guess the onCrafted is okay, but for the later stages I would like it to seem "professional", like Twilight Forest, if you've ever played that or seen a mod showcase on it.
Actually... here's kind of what I was talking about...
Well, Xuluf, your code worked, but is there another on*insert something here* function? Like maybe, onItemSpawn or onItemGetFromCreativeTab? Because I really want it to be enchanted 100.00% of the time. The mod is still in Beta, so I guess the onCrafted is okay, but for the later stages I would like it to seem "professional", like Twilight Forest, if you've ever played that or seen a mod showcase on it.
Actually... here's kind of what I was talking about...
public void onUpdate(ItemStack par1ItemStack, World par2World, EntityPlayer entityplayer, int par4, boolean par5)
{
par1ItemStack.addEnchantment(Enchantment.fireAspect, 2)
}
(I haven't tried this code yet)
Tried it, didn't work. But I didn't alter the code, btw. Maybe a kind of function like enchantment books; the enchantment is bound to it, just not random?
Rollback Post to RevisionRollBack
If you thought something was missing in Minecraft, think again.
MoreMine is coming soon for Minecraft 1.7.10
Wouldn't that just repeatedly add the enchantment? Personally, my code would go something like this, in the same method actually:
public void onUpdate(ItemStack itemStack, World world, Entity entity, int par4, boolean par5)
{
//Only add the enchant if it doesn't have an enchantment.
if (!itemStack.isItemEnchanted())
{
itemStack.addEnchantment(Enchantment.fireAspect, 2);
}
}
Another thing I want to say is I did the crafting code wrong, in retrospect. I didn't actually pay attention to the return type of addEnchantment XD. I shall provide (hopefully) fixed source code:
GameRegistry.addRecipe((ItemStack) (new ItemStack(ModItems.yourItem).addEnchantment(Enchantment.sharpness, 5)), new Object[] {" X ", " X ", " Y ", new ItemStack(Items.stick), "Y", new ItemStack(Blocks.obsidian), "X"});
Whoa thanks, but Xuluf kinda beat you to it. :/ However, I guess I still have something I can apply this to... Thanks.
Rollback Post to RevisionRollBack
If you thought something was missing in Minecraft, think again.
MoreMine is coming soon for Minecraft 1.7.10
A slick way to get your special item to always have an enchantment in the Creative Tab is to use the getSubItems method:
@SideOnly(Side.CLIENT)
public void getSubItems(int itemId, CreativeTabs tab, List list) {
ItemStack enchantedStack = new ItemStack(itemId, 1, 0);
// as far as I know, you can not add an enchantment directly from the constructor
// you must do it on a separate line, since the return type is 'void':
enchantedStack.addEnchantment(Enchantment.fireAspect, 2);
list.add(enchantedStack);
}
I'm not sure if that works for items without subtypes, but you could try it. Failing that, use the addInformation method to add a new enchantment to your item if unenchanted - keep in mind, both of these are CLIENT side only, for the purpose of making your item LOOK enchanted in the creative tab. The first method should also give you a real enchanted item when you take it out of the tab, but with addInformation I'm not so sure. Try it and see
P.S. In recipes, you don't need to have "new Object[] { .... }", just list the parameters and Java will do the rest.
A slick way to get your special item to always have an enchantment in the Creative Tab is to use the getSubItems method:
@SideOnly(Side.CLIENT)
public void getSubItems(int itemId, CreativeTabs tab, List list) {
ItemStack enchantedStack = new ItemStack(itemId, 1, 0);
// as far as I know, you can not add an enchantment directly from the constructor
// you must do it on a separate line, since the return type is 'void':
enchantedStack.addEnchantment(Enchantment.fireAspect, 2);
list.add(enchantedStack);
}
I'm not sure if that works for items without subtypes, but you could try it. Failing that, use the addInformation method to add a new enchantment to your item if unenchanted - keep in mind, both of these are CLIENT side only, for the purpose of making your item LOOK enchanted in the creative tab. The first method should also give you a real enchanted item when you take it out of the tab, but with addInformation I'm not so sure. Try it and see
P.S. In recipes, you don't need to have "new Object[] { .... }", just list the parameters and Java will do the rest.
Wow, thanks. This community is great Thanks for all the support. Will add you to the credits list too.
Rollback Post to RevisionRollBack
If you thought something was missing in Minecraft, think again.
MoreMine is coming soon for Minecraft 1.7.10
A slick way to get your special item to always have an enchantment in the Creative Tab is to use the getSubItems method:
@SideOnly(Side.CLIENT)
public void getSubItems(int itemId, CreativeTabs tab, List list) {
ItemStack enchantedStack = new ItemStack(itemId, 1, 0);
// as far as I know, you can not add an enchantment directly from the constructor
// you must do it on a separate line, since the return type is 'void':
enchantedStack.addEnchantment(Enchantment.fireAspect, 2);
list.add(enchantedStack);
}
I'm not sure if that works for items without subtypes, but you could try it. Failing that, use the addInformation method to add a new enchantment to your item if unenchanted - keep in mind, both of these are CLIENT side only, for the purpose of making your item LOOK enchanted in the creative tab. The first method should also give you a real enchanted item when you take it out of the tab, but with addInformation I'm not so sure. Try it and see
But thanks for the code used as a placeholder. BTW, the mod is now stable, expect a release soon. Just tools for Emerald, no Armor yet and no food, and no BlazeSword. Just want some Beta Testers, so... Would you try?
Rollback Post to RevisionRollBack
If you thought something was missing in Minecraft, think again.
MoreMine is coming soon for Minecraft 1.7.10
NOTE: I now have a new problem with textures, please look at latest post.Fixed, but my client doesn't want to start anymore.
ORIGINAL POST:
Here's the thing:
I'm making a Minecraft Mod for 1.6.4, and I am trying to add in Blaze Swords which when right-clicked, spawn fireballs that shoot away from the player. I would also like help with adding enchantments on items so when they spawn, they already have the enchantment.
If it helps, here's my code for BlazeSword.java:
I have the sword working fine, it does what it's supposed to, textures are ok, but I don't know how to do this stuff, and help would be much, much, MUCH appreciated.
Thanks in advance to anyone who will help.
NOTE: Also, if you think I should learn Basic Java before doing any of this, please link me to a place where I can learn the Basics of Java that are used by Minecraft. Thanks for your time.
If you thought something was missing in Minecraft, think again.
MoreMine is coming soon for Minecraft 1.7.10
If I helped you, hit that green arrow!
Thanks for the help. The mod is in a sort-of Beta stage, where I'm really just testing to see what works best. However later on, I will make it a bit more advanced, having more content. The idea of the mod is "What Could Have Been" in Minecraft, adding more uses to stuff not normally used (Emerald, obsidian, blaze rods, etc.) Thanks for replying, and I guess I better start studying!
If you thought something was missing in Minecraft, think again.
MoreMine is coming soon for Minecraft 1.7.10
If I helped you, hit that green arrow!
Something like this, but pre-enchanted:
https://www.dropbox....0j6n1m/ench.png
Thanks. Just a few tips, methods, maybe a line of code will help.
If you thought something was missing in Minecraft, think again.
MoreMine is coming soon for Minecraft 1.7.10
If I helped you, hit that green arrow!
but of course that would only make it enchanted when crafting it(not when taking it from creative or with commands?)
Art by me: MrPancakeWolfie@DeviantArt
Art by me: MrPancakeWolfie@DeviantArt
Thank you so much, guys! You are very nice to me, and are really helpful! You guys are definitely going in the credits of my mod
If you thought something was missing in Minecraft, think again.
MoreMine is coming soon for Minecraft 1.7.10
If I helped you, hit that green arrow!
https://www.dropbox....ctis9y7/Wat.png
Help...
EDIT: Am I missing any imports or anything? It doesn't look like it, but... Just need to be sure.
NEXT EDIT: I am offline, but please still post a solution. Thanks!!!
If you thought something was missing in Minecraft, think again.
MoreMine is coming soon for Minecraft 1.7.10
If I helped you, hit that green arrow!
As you are using Eclipse, just hold: and it should organize the imports.
And yes you are missing
Art by me: MrPancakeWolfie@DeviantArt
"void is an invalid type for the variable onCreation"
Here:
https://www.dropbox....o2cr8o/void.png
ANYONE Help?
If you thought something was missing in Minecraft, think again.
MoreMine is coming soon for Minecraft 1.7.10
If I helped you, hit that green arrow!
Edit: Almost out of posts, so... I will talk through edits. But... I found this.
"void is an invalid type for the variable onCreated"Here is the BlazeSword coding once again:
If you thought something was missing in Minecraft, think again.
MoreMine is coming soon for Minecraft 1.7.10
If I helped you, hit that green arrow!
first of all replace the
also move your code out of the constructor.. That is what's giving you the error..
so:
Art by me: MrPancakeWolfie@DeviantArt
Hey, thanks. I actually now can improve my code. You will also go into my credits.
EDIT: Wait, apparently when I replace Snowball with SmallFireball it doesn't work. I have the imports, but... What could be causing the problem? PM me for the code of the BlazeSword if you can help.
If you thought something was missing in Minecraft, think again.
MoreMine is coming soon for Minecraft 1.7.10
If I helped you, hit that green arrow!
Actually... here's kind of what I was talking about...
LINK
If you thought something was missing in Minecraft, think again.
MoreMine is coming soon for Minecraft 1.7.10
If I helped you, hit that green arrow!
Maybe you could use the onUpdate method?
(I haven't tried this code yet)
Art by me: MrPancakeWolfie@DeviantArt
Tried it, didn't work. But I didn't alter the code, btw. Maybe a kind of function like enchantment books; the enchantment is bound to it, just not random?
If you thought something was missing in Minecraft, think again.
MoreMine is coming soon for Minecraft 1.7.10
If I helped you, hit that green arrow!
Whoa thanks, but Xuluf kinda beat you to it. :/ However, I guess I still have something I can apply this to... Thanks.
If you thought something was missing in Minecraft, think again.
MoreMine is coming soon for Minecraft 1.7.10
If I helped you, hit that green arrow!
I'm not sure if that works for items without subtypes, but you could try it. Failing that, use the addInformation method to add a new enchantment to your item if unenchanted - keep in mind, both of these are CLIENT side only, for the purpose of making your item LOOK enchanted in the creative tab. The first method should also give you a real enchanted item when you take it out of the tab, but with addInformation I'm not so sure. Try it and see
P.S. In recipes, you don't need to have "new Object[] { .... }", just list the parameters and Java will do the rest.
Wow, thanks. This community is great Thanks for all the support. Will add you to the credits list too.
If you thought something was missing in Minecraft, think again.
MoreMine is coming soon for Minecraft 1.7.10
If I helped you, hit that green arrow!
I highly recommend this ^^
Art by me: MrPancakeWolfie@DeviantArt
But thanks for the code used as a placeholder. BTW, the mod is now stable, expect a release soon. Just tools for Emerald, no Armor yet and no food, and no BlazeSword. Just want some Beta Testers, so... Would you try?
If you thought something was missing in Minecraft, think again.
MoreMine is coming soon for Minecraft 1.7.10
If I helped you, hit that green arrow!