Jump to content

Item to ItemStack to Entity


TuxCraft

Recommended Posts

I'm making a mod with a spear in it and when you throw it you can go over and pick it back up. How would I make so that you pick up the exact same spear you threw with enchantments, and damage, and everything. I thought about using "this", but the spear pick up code is in the entity class so I can't do that. Is there any way to instead of "this" do "that"? Any way, what realistic way could I solve my problem, would packaging all the data I want the spear to keep into nbt data and sending it to the entity work?

Link to comment
Share on other sites

I'm making a mod with a spear in it and when you throw it you can go over and pick it back up. How would I make so that you pick up the exact same spear you threw with enchantments, and damage, and everything. I thought about using "this", but the spear pick up code is in the entity class so I can't do that. Is there any way to instead of "this" do "that"? Any way, what realistic way could I solve my problem, would packaging all the data I want the spear to keep into nbt data and sending it to the entity work?

Link to comment
Share on other sites

Yes, you could just put an ItemStack (the spear item with enchants and other things on it) into the entity. ItemStack can serialize itself into NBT ;).

mnn.getNativeLang() != English

If I helped you please click on the "thank you" button.

Link to comment
Share on other sites

Yes, you could just put an ItemStack (the spear item with enchants and other things on it) into the entity. ItemStack can serialize itself into NBT ;).

mnn.getNativeLang() != English

If I helped you please click on the "thank you" button.

Link to comment
Share on other sites

Hmm, well I've always had trouble with the difference between itemStack and item, so I don't necessarily know how to do that...

 

Minecraft code is a little funky.

 

Item classes are a singleton* instance (as is all Block classes).  An ItemStack is a class that allows the entire inventory system to function.  Every item in your inventory is a stack of items (even if the stack size is 1).  Essentially, it's a wrapper class that allows for instancing of the singleton class.  ItemStacks have enchantments, Items don't.

 

*It's actually not, but it's easier to think of it as if it is because it's only ever instanced once.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

Hmm, well I've always had trouble with the difference between itemStack and item, so I don't necessarily know how to do that...

 

Minecraft code is a little funky.

 

Item classes are a singleton* instance (as is all Block classes).  An ItemStack is a class that allows the entire inventory system to function.  Every item in your inventory is a stack of items (even if the stack size is 1).  Essentially, it's a wrapper class that allows for instancing of the singleton class.  ItemStacks have enchantments, Items don't.

 

*It's actually not, but it's easier to think of it as if it is because it's only ever instanced once.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

 

Minecraft code is a little funky.

 

Item classes are a singleton* instance (as is all Block classes).  An ItemStack is a class that allows the entire inventory system to function.  Every item in your inventory is a stack of items (even if the stack size is 1).  Essentially, it's a wrapper class that allows for instancing of the singleton class.  ItemStacks have enchantments, Items don't.

 

*It's actually not, but it's easier to think of it as if it is because it's only ever instanced once.

 

Ahh, thanks. Damage is also on the itemstack too right? Like when you use an inventory an you stack weapons they all have the same damage value. Also how would you set the spear as an itemstack and send it to the entity's pickup code?

Link to comment
Share on other sites

 

Minecraft code is a little funky.

 

Item classes are a singleton* instance (as is all Block classes).  An ItemStack is a class that allows the entire inventory system to function.  Every item in your inventory is a stack of items (even if the stack size is 1).  Essentially, it's a wrapper class that allows for instancing of the singleton class.  ItemStacks have enchantments, Items don't.

 

*It's actually not, but it's easier to think of it as if it is because it's only ever instanced once.

 

Ahh, thanks. Damage is also on the itemstack too right? Like when you use an inventory an you stack weapons they all have the same damage value. Also how would you set the spear as an itemstack and send it to the entity's pickup code?

Link to comment
Share on other sites

Ahh, thanks. Damage is also on the itemstack too right? Like when you use an inventory an you stack weapons they all have the same damage value. Also how would you set the spear as an itemstack and send it to the entity's pickup code?

 

Correct, damage is on the stack.

As for the pickup code, rather than telling the entity that it drops the base item class, tell it to drop a new ItemStack that has all the properties of what the original was, which you'd store as NBT data inside the entity.

 

(Not having dealt with projectiles, I can't really comment more).

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

Ahh, thanks. Damage is also on the itemstack too right? Like when you use an inventory an you stack weapons they all have the same damage value. Also how would you set the spear as an itemstack and send it to the entity's pickup code?

 

Correct, damage is on the stack.

As for the pickup code, rather than telling the entity that it drops the base item class, tell it to drop a new ItemStack that has all the properties of what the original was, which you'd store as NBT data inside the entity.

 

(Not having dealt with projectiles, I can't really comment more).

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

So how would I have my code call the Item an itemstack?

 

When I do this...

public static ItemStack thisSpear = new ItemStack(this, 1);

It says this can't be used with a static modifier but adding the static modifier is the only way to get the entity to read it.

 

I'll look at the entityItem code, that might have some insight on my dilemma.

Link to comment
Share on other sites

So how would I have my code call the Item an itemstack?

 

When I do this...

public static ItemStack thisSpear = new ItemStack(this, 1);

It says this can't be used with a static modifier but adding the static modifier is the only way to get the entity to read it.

 

I'll look at the entityItem code, that might have some insight on my dilemma.

Link to comment
Share on other sites

Do you understand what the keyword static means?

you're title indicates some confusion to the this word which is closely related to the understanding of static. I would suggest that you take some time to read up on the topic of instances and static inn programming, you will benefit greatly from it! :)

 

I'm not saying it to be mean mate, it's just that what you said above here shows that you seem confused about the concepts and since it's vital for you to know them, I urge you to look them up when you have the time it will help you out greatly with developing your mod(s) :)

If you guys dont get it.. then well ya.. try harder...

Link to comment
Share on other sites

Do you understand what the keyword static means?

you're title indicates some confusion to the this word which is closely related to the understanding of static. I would suggest that you take some time to read up on the topic of instances and static inn programming, you will benefit greatly from it! :)

 

I'm not saying it to be mean mate, it's just that what you said above here shows that you seem confused about the concepts and since it's vital for you to know them, I urge you to look them up when you have the time it will help you out greatly with developing your mod(s) :)

If you guys dont get it.. then well ya.. try harder...

Link to comment
Share on other sites

Thanks Maze, that was a good tip.

 

I read the article oracle posted on instances and that does clear a lot up for me. I couldn't use "this" in another class because it wouldn't know what instance "this" was referring to.

 

So I tried putting this in the on release function...

 

EntitySpear.spearToDrop =  par3EntityPlayer.inventory.getCurrentItem();

 

And it works... kind of. It gives me back the exact spear I threw, damage, custom name, enchantment everything, but when I throw it again it just bounces off the entity I threw it at and does no damage. And when I try to attack with it it immediately deletes itself from my inventory.

Link to comment
Share on other sites

Thanks Maze, that was a good tip.

 

I read the article oracle posted on instances and that does clear a lot up for me. I couldn't use "this" in another class because it wouldn't know what instance "this" was referring to.

 

So I tried putting this in the on release function...

 

EntitySpear.spearToDrop =  par3EntityPlayer.inventory.getCurrentItem();

 

And it works... kind of. It gives me back the exact spear I threw, damage, custom name, enchantment everything, but when I throw it again it just bounces off the entity I threw it at and does no damage. And when I try to attack with it it immediately deletes itself from my inventory.

Link to comment
Share on other sites

I'm just guessing, but for me that sounds like a client/server sync issue.

You're client think's it has picked up the item, but the server is never told that it did.

Therefore the server is not aware of the item and when it's used the client says it hit and landed while the server is like "Spear? what spear? oh that thing, you never picked it up from where you left it the last time..?"

 

So you are on the right track I'd guess, but you need to start communicating with the server about what the client is doing :) Are you familiar with packets and packet handling?

http://www.minecraftforge.net/wiki/Packet_Handling

 

 

Thanks Maze, that was a good tip.

 

I read the article oracle posted on instances and that does clear a lot up for me. I couldn't use "this" in another class because it wouldn't know what instance "this" was referring to.

 

Yeey I made someone learn more Java  ;D

// Start pushing more java

If you want some quick intros to java check out thenewboston on google, or if you are inn for a more lengthy but very rewarding run check out CS106a - a free video lecture series on java from Stanford, which starts at the very basics and go as far as you want ;)

// End of java pushing.

 

Seriously if you want to learn more, it's great! It will make your mods better and not to mention it will make the creation of them so much easier when you know what you are doing <3

 

 

If you guys dont get it.. then well ya.. try harder...

Link to comment
Share on other sites

I'm just guessing, but for me that sounds like a client/server sync issue.

You're client think's it has picked up the item, but the server is never told that it did.

Therefore the server is not aware of the item and when it's used the client says it hit and landed while the server is like "Spear? what spear? oh that thing, you never picked it up from where you left it the last time..?"

 

So you are on the right track I'd guess, but you need to start communicating with the server about what the client is doing :) Are you familiar with packets and packet handling?

http://www.minecraftforge.net/wiki/Packet_Handling

 

 

Thanks Maze, that was a good tip.

 

I read the article oracle posted on instances and that does clear a lot up for me. I couldn't use "this" in another class because it wouldn't know what instance "this" was referring to.

 

Yeey I made someone learn more Java  ;D

// Start pushing more java

If you want some quick intros to java check out thenewboston on google, or if you are inn for a more lengthy but very rewarding run check out CS106a - a free video lecture series on java from Stanford, which starts at the very basics and go as far as you want ;)

// End of java pushing.

 

Seriously if you want to learn more, it's great! It will make your mods better and not to mention it will make the creation of them so much easier when you know what you are doing <3

 

 

If you guys dont get it.. then well ya.. try harder...

Link to comment
Share on other sites

Ok, I get the concept, but that's it  :D

 

Using the tutorial you linked to I was able to set up the random numbers being displayed when the player collides with the spear entity, and I noticed as I was messing around that if you put the addItemstack line in the spear entity's onCollide method try section it did the same thing as if it were just in the onCollide method.

 

Do you put the addItemstack line in the packet handler file? When I tried putting that next to the system.out.print line it through a fit because it didn't like the EntityPlayer variable.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • ASIABET adalah pilihan terbaik bagi Anda yang mencari slot gacor hari ini dengan server Rusia dan jackpot menggiurkan. Berikut adalah beberapa alasan mengapa Anda harus memilih ASIABET: Slot Gacor Hari Ini Kami menyajikan koleksi slot gacor terbaik yang diperbarui setiap hari. Dengan fitur-fitur unggulan dan peluang kemenangan yang tinggi, Anda akan merasakan pengalaman bermain yang tak terlupakan setiap kali Anda memutar gulungan. Server Rusia yang Handal Kami menggunakan server Rusia yang handal dan stabil untuk memastikan kelancaran dan keadilan dalam setiap putaran permainan. Anda dapat bermain dengan nyaman tanpa khawatir tentang gangguan atau lag. Jackpot Menggiurkan Nikmati kesempatan untuk memenangkan jackpot menggiurkan yang dapat mengubah hidup Anda secara instan. Dengan hadiah-hadiah besar yang ditawarkan, setiap putaran permainan bisa menjadi peluang untuk meraih keberuntungan besar.
    • Sonic77 adalah pilihan tepat bagi Anda yang menginginkan pengalaman bermain slot yang unggul dengan akun pro Swiss terbaik. Berikut adalah beberapa alasan mengapa Anda harus memilih Sonic77: Slot Gacor Terbaik Kami menyajikan koleksi slot gacor terbaik dari provider terkemuka. Dengan fitur-fitur unggulan dan peluang kemenangan yang tinggi, Anda akan merasakan pengalaman bermain yang tak terlupakan. Akun Pro Swiss Berkualitas Kami menawarkan akun pro Swiss yang berkualitas dan terpercaya. Dengan akun ini, Anda dapat menikmati berbagai keuntungan eksklusif dan fasilitas premium yang tidak tersedia untuk akun reguler.
    • SV388 SITUS RESMI SABUNG AYAM 2024   Temukan situs resmi untuk sabung ayam terpercaya di tahun 2024 dengan SV388! Dengan layanan terbaik dan pengalaman bertaruh yang tak tertandingi, SV388 adalah tempat terbaik untuk pecinta sabung ayam. Daftar sekarang untuk mengakses arena sabung ayam yang menarik dan nikmati kesempatan besar untuk meraih kemenangan. Jelajahi sensasi taruhan yang tak terlupakan di tahun ini dengan SV388! [[jumpuri:❱❱❱❱❱ DAFTAR DI SINI ❰❰❰❰❰ > https://w303.pink/orochimaru]] [[jumpuri:❱❱❱❱❱ DAFTAR DI SINI ❰❰❰❰❰ > https://w303.pink/orochimaru]]   JURAGANSLOT88 SITUS JUDI SLOT ONLINE TERPERCAYA 2024 Jelajahi pengalaman judi slot online terpercaya di tahun 2024 dengan JuraganSlot88! Sebagai salah satu situs terkemuka, JuraganSlot88 menawarkan berbagai pilihan permainan slot yang menarik dengan layanan terbaik dan keamanan yang terjamin. Daftar sekarang untuk mengakses sensasi taruhan yang tak terlupakan dan raih kesempatan besar untuk meraih kemenangan di tahun ini dengan JuraganSlot88 [[jumpuri:❱❱❱❱❱ DAFTAR DI SINI ❰❰❰❰❰ > https://w303.pink/orochimaru]] [[jumpuri:❱❱❱❱❱ DAFTAR DI SINI ❰❰❰❰❰ > https://w303.pink/orochimaru]]
    • Slot Bank MEGA atau Daftar slot Bank MEGA bisa anda lakukan pada situs WINNING303 kapanpun dan dimanapun, Bermodalkan Hp saja anda bisa mengakses chat ke agen kami selama 24 jam full. keuntungan bergabung bersama kami di WINNING303 adalah anda akan mendapatkan bonus 100% khusus member baru yang bergabung dan deposit. Tidak perlu banyak, 5 ribu rupiah saja anda sudah bisa bermain bersama kami di WINNING303 . Tunggu apa lagi ? Segera Klik DAFTAR dan anda akan jadi Jutawan dalam semalam.
    • ladangtoto situs resmi ladangtoto situs terpercaya 2024   Temukan situs resmi dan terpercaya untuk tahun 2024 di LadangToto! Dengan layanan terbaik dan keamanan yang terjamin, LadangToto adalah pilihan utama untuk penggemar judi online. Daftar sekarang untuk mengakses berbagai jenis permainan taruhan, termasuk togel, kasino, dan banyak lagi. Jelajahi sensasi taruhan yang tak terlupakan dan raih kesempatan besar untuk meraih kemenangan di tahun ini dengan LadangToto!" [[jumpuri:❱❱❱❱❱ DAFTAR DI SINI ❰❰❰❰❰ > https://w303.pink/orochimaru]] [[jumpuri:❱❱❱❱❱ DAFTAR DI SINI ❰❰❰❰❰ > https://w303.pink/orochimaru]]
  • Topics

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.