Jump to content

1.12.2 modding assistance


set9753

Recommended Posts

10 hours ago, poopoodice said:

You can add on-hit effect here

image.png

Where does this code go? In the main file for the mod items? Or in some kind of new class for the modded item's effects? I should note, I've only recently started modding. I've only managed to spaghetti code the item into the game as is. (I used TechnoVision's youtube series to get started.) If it helps, I could share the source file? It's not like I'm worried about the idea being stolen

Link to comment
Share on other sites

13 hours ago, poopoodice said:

Vanilla ItemSword

Dont post source code that doesnt belong to you. Yes even the vanilla code.

 

2 hours ago, set9753 said:

Where does this code go?

The Items class file.

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect.

Forge and vanilla BlockState generator.

Link to comment
Share on other sites

17 minutes ago, set9753 said:

What code do I use, specifically, to add the effect to the attack?

Depends on the effect I guess.

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect.

Forge and vanilla BlockState generator.

Link to comment
Share on other sites

3 minutes ago, set9753 said:

Three, to be specific. Speed 1, Strength 1, and Fire Resistance 1. For 8 seconds.

So potion effects?
LivingEntityBase#addPotionEffect

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect.

Forge and vanilla BlockState generator.

Link to comment
Share on other sites

When I try to use that, I get an error reading "Syntax error on token "Invalid Character", delete this token.

The code looks like this, I know it's wrong, but I'm really stuck here.

 

 

public class ItemSword {
    
    PotionEffect effect;
    
    public boolean hitEntity(ItemStack stack, EntityLivingBase target, EntityLivingBase attacker, EntityLivingBase#addPotionEffect)
    {
        stack.damageItem(0, attacker);
        return true;
    }

}

Link to comment
Share on other sites

30 minutes ago, set9753 said:

I know it's wrong, but I'm really stuck here.

You need to learn Java. What you have there isnt a Forge error. You'd be able to fix it if you knew Java.

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect.

Forge and vanilla BlockState generator.

Link to comment
Share on other sites

You'll want to override hitEntity inside your sword class, and apply the potion effect inside the overridden method.

At the "target.addPotionEffect", you may want to give the effect to the attacker, rather than the target, I'm not sure.

 

	@Override
	public boolean hitEntity(ItemStack stack, EntityLivingBase target, EntityLivingBase attacker)
	{
		target.addPotionEffect(new PotionEffect(MobEffects.STRENGTH, 8 * 20, 0));
		stack.damageItem(1, attacker);
		return true;
	}

 

As for the illegal character...

Quote

public boolean hitEntity(ItemStack stack, EntityLivingBase target, EntityLivingBase attacker, EntityLivingBase#addPotionEffect)

What you were trying to do there was call a method inside the parameters taken in by hitEntity. The parameters are variables fed into hitEntity for it to do things with. When it's called, the stuff int the {} happens. When you hit an entity with your sword, hitEntity is called. The parameters are fed into the method, and the {} happens.

 

Also, EntityLivingBase#addPotionEffect means "the addPotionEffect within instances of EntityLivingBase", rather than

being an actual line of executable code. That's why I call it here on the target object, since target is an instance of EntityLivingBase.

Fancy 3D Graphing Calculator mod, with many different coordinate systems.

Lightweight 3D/2D position/vector transformations library, also with support for different coordinate systems.

Link to comment
Share on other sites

Thank you, so much for the explanations! I just have a few more questions to tie this together, if you don't mind...

 

I have the class ItemSword extending Item, and the item I want to use to boost on hit is made as an Item... Does the extension mean this will work?

If I wanted to add more than one potion effect, how would I go about that?

Link to comment
Share on other sites

Quote

I have the class ItemSword extending Item, and the item I want to use to boost on hit is made as an Item

So you have two items here, one is a miscellaneous sword, and the other is a sword/other with a hit effect?

You can get some extra sword-related methods and functionality by extending ItemSword (which in turn extends Item) instead of simply Item, but you can easily make the basic functionalities you're asking about in either, as hitEntity is a method for Items, not specifically ItemSwords. If you want some, but not all of the ItemSword features, you could just re-write some of it in your class.

In other words, the extensions are fine, but you may want more functionalities, which could be gotten from the ItemSword class. I'd suggest you take a look at its methods to get a better idea of what it can do.

 

Quote

If I wanted to add more than one potion effect, how would I go about that?

Quote

target.addPotionEffect(new PotionEffect(MobEffects.STRENGTH, 8 * 20, 0));

You can just add another of these. E.G: this inside the hitEntity method.

target.addPotionEffect(new PotionEffect(MobEffects.STRENGTH, 8 * 20, 0));
target.addPotionEffect(new PotionEffect(MobEffects.SPEED, 8 * 20, 0));

 

If you wanted a flexible, easily expandable set of potion effects, you could also do something like this.

Potion[] effectList = new Potion[]
{
		MobEffects.STRENGTH,
		MobEffects.SPEED
};

Iterating through the list in hitEntity.

	@Override
	public boolean hitEntity(ItemStack stack, EntityLivingBase target, EntityLivingBase attacker)
	{
		for (Potion current : effectList) { target.addPotionEffect(new PotionEffect(current, 8 * 20, 0)); }
		stack.damageItem(1, attacker);
		return true;
	}

Fancy 3D Graphing Calculator mod, with many different coordinate systems.

Lightweight 3D/2D position/vector transformations library, also with support for different coordinate systems.

Link to comment
Share on other sites

I should clarify, I've been spaghetti coding my way through this mod. And at one point thought I had to make a SwordItem to make the on hit effect work. I've since deleted the sword item, but kept the class and all. So I just made the SwordItem class extend the Item class. I only have the item, and assumed by extending Item via SwordItem's class I could achieve the effect I wanted (an item that could boost others by whacking them with it)

 

Would it be worth my time to just rewrite all the code into the Item class, and remove the Sworditem class? Or would it work the way I have it now? Everything seems to be turning out, I pretty much just want to know if the hitEntity effect will work out. (Once I finish this, the mod is done. I wont be adding onto it, so don't worry about my odd coding being a bother for later additions)

Link to comment
Share on other sites

If your class extends Item, and you override hitEntity and add the potion effect methods, then the potion effect methods should run when an entity is hit with the item.

 

If you want the extra sword functionalities that the base Item class doesn't have, you should extend ItemSword and do nothing different with hitEntity. If not, you can just keep it as a simple extension of Item.

Fancy 3D Graphing Calculator mod, with many different coordinate systems.

Lightweight 3D/2D position/vector transformations library, also with support for different coordinate systems.

Link to comment
Share on other sites

10 hours ago, set9753 said:

Where does this code go? In the main file for the mod items? Or in some kind of new class for the modded item's effects? I should note, I've only recently started modding. I've only managed to spaghetti code the item into the game as is. (I used TechnoVision's youtube series to get started.) If it helps, I could share the source file? It's not like I'm worried about the idea being stolen

you can override them once your iteminit extends ItemSword

Link to comment
Share on other sites

2 minutes ago, poopoodice said:

you can override them once your iteminit extends ItemSword

It doesn't have to extend ItemSword specifically, just Item.

Fancy 3D Graphing Calculator mod, with many different coordinate systems.

Lightweight 3D/2D position/vector transformations library, also with support for different coordinate systems.

Link to comment
Share on other sites

8 minutes ago, poopoodice said:

 without attack damage

True, though an even easier way of getting rid of attack damage would be to override onLeftClickEntity and return true after the potion effect methods.

	@Override
	public boolean onLeftClickEntity(ItemStack stack, EntityPlayer player, Entity entity)
	{
		if (entity instanceof EntityLivingBase) ((EntityLivingBase) entity).addPotionEffect(new PotionEffect(MobEffects.STRENGTH, 8 * 20, 0));
		return true;
	}

That doesn't deal any damage at all, not even fist damage. It doesn't apply knockback, though, so extending ItemSword would still be the way to go if they wanted that.

Come to think of it, would the attackDamage correspond to total damage dealt, or additional damage dealt? Meaning, would giving it a value of 0 result in 0 damage + fist damage, or 0 overall, negating the fist damage?

Fancy 3D Graphing Calculator mod, with many different coordinate systems.

Lightweight 3D/2D position/vector transformations library, also with support for different coordinate systems.

Link to comment
Share on other sites

21 minutes ago, SerpentDagger said:

True, though an even easier way of getting rid of attack damage would be to override onLeftClickEntity and return true after the potion effect methods.


	@Override
	public boolean onLeftClickEntity(ItemStack stack, EntityPlayer player, Entity entity)
	{
		if (entity instanceof EntityLivingBase) ((EntityLivingBase) entity).addPotionEffect(new PotionEffect(MobEffects.STRENGTH, 8 * 20, 0));
		return true;
	}

That doesn't deal any damage at all, not even fist damage. It doesn't apply knockback, though, so extending ItemSword would still be the way to go if they wanted that.

Come to think of it, would the attackDamage correspond to total damage dealt, or additional damage dealt? Meaning, would giving it a value of 0 result in 0 damage + fist damage, or 0 overall, negating the fist damage?

Good point. Now he/she can make a item that without everything but the attributes he wants such as potion effect while leftclick on an entity. Nice.

Link to comment
Share on other sites

3 hours ago, set9753 said:

I should clarify, I've been spaghetti coding my way through this mod. And at one point thought I had to make a SwordItem to make the on hit effect work. I've since deleted the sword item, but kept the class and all. So I just made the SwordItem class extend the Item class. I only have the item, and assumed by extending Item via SwordItem's class I could achieve the effect I wanted (an item that could boost others by whacking them with it)

 

Would it be worth my time to just rewrite all the code into the Item class, and remove the Sworditem class? Or would it work the way I have it now? Everything seems to be turning out, I pretty much just want to know if the hitEntity effect will work out. (Once I finish this, the mod is done. I wont be adding onto it, so don't worry about my odd coding being a bother for later additions)

SwordItem has a lot more sword-specific functions than an Item. Only extends sword when you need to actually use it to attack another entity like a vanilla sword. In your case extending Item should be sufficient.

 

@SerpentDagger Please note that posting copy-pastable code for others is discouraged, as others will not learn and might blindly copy the code.

Some tips:

Spoiler

Modder Support:

Spoiler

1. Do not follow tutorials on YouTube, especially TechnoVision (previously called Loremaster) and HarryTalks, due to their promotion of bad practice and usage of outdated code.

2. Always post your code.

3. Never copy and paste code. You won't learn anything from doing that.

4. 

Quote

Programming via Eclipse's hotfixes will get you nowhere

5. Learn to use your IDE, especially the debugger.

6.

Quote

The "picture that's worth 1000 words" only works if there's an obvious problem or a freehand red circle around it.

Support & Bug Reports:

Spoiler

1. Read the EAQ before asking for help. Remember to provide the appropriate log(s).

2. Versions below 1.11 are no longer supported due to their age. Update to a modern version of Minecraft to receive support.

 

 

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

    • Dalam dunia perjudian online yang berkembang pesat, mencari platform yang dapat memberikan kemenangan maksimal dan hasil terbaik adalah impian setiap penjudi. OLXTOTO, dengan bangga, mempersembahkan dirinya sebagai jawaban atas pencarian itu. Sebagai platform terbesar untuk kemenangan maksimal dan hasil optimal, OLXTOTO telah menciptakan gelombang besar di komunitas perjudian online. Satu dari banyak keunggulan yang dimiliki OLXTOTO adalah koleksi permainan yang luas dan beragam. Dari togel hingga slot online, dari live casino hingga permainan kartu klasik, OLXTOTO memiliki sesuatu untuk setiap pemain. Dibangun dengan teknologi terkini dan dikembangkan oleh para ahli industri, setiap permainan di platform ini dirancang untuk memberikan pengalaman yang tak tertandingi bagi para penjudi. Namun, keunggulan OLXTOTO tidak hanya terletak pada variasi permainan yang mereka tawarkan. Mereka juga menonjol karena komitmen mereka terhadap keamanan dan keadilan. Dengan sistem keamanan tingkat tinggi dan proses audit yang ketat, OLXTOTO memastikan bahwa setiap putaran permainan berjalan dengan adil dan transparan. Para pemain dapat merasa aman dan yakin bahwa pengalaman berjudi mereka di OLXTOTO tidak akan terganggu oleh masalah keamanan atau keadilan. Tak hanya itu, OLXTOTO juga terkenal karena layanan pelanggan yang luar biasa. Tim dukungan mereka selalu siap sedia untuk membantu para pemain dengan segala pertanyaan atau masalah yang mereka hadapi. Dengan respon cepat dan solusi yang efisien, OLXTOTO memastikan bahwa pengalaman berjudi para pemain tetap mulus dan menyenangkan. Dengan semua fitur dan keunggulan yang ditawarkannya, tidak mengherankan bahwa OLXTOTO telah menjadi pilihan utama bagi jutaan penjudi online di seluruh dunia. Jika Anda mencari platform yang dapat memberikan kemenangan maksimal dan hasil optimal, tidak perlu mencari lebih jauh dari OLXTOTO. Bergabunglah dengan OLXTOTO hari ini dan mulailah petualangan Anda menuju kemenangan besar dan hasil terbaik!
    • Selamat datang di OLXTOTO, situs slot gacor terpanas yang sedang booming di industri perjudian online. Jika Anda mencari pengalaman bermain yang luar biasa, maka OLXTOTO adalah tempat yang tepat untuk Anda. Dapatkan sensasi tidak biasa dengan variasi slot online terlengkap dan peluang memenangkan jackpot slot maxwin yang sering. Di sini, Anda akan merasakan keseruan yang luar biasa dalam bermain judi slot. DAFTAR OLXTOTO DISINI LOGIN OLXTOTO DISINI AKUN PRO OLXTOTO DISINI   Jackpot Slot Maxwin Sering Untuk Peluang Besar Di OLXTOTO, kami tidak hanya memberikan hadiah slot biasa, tapi juga memberikan kesempatan kepada pemain untuk memenangkan jackpot slot maxwin yang sering. Dengan demikian, Anda dapat meraih keberuntungan besar dan memenangkan ribuan rupiah sebagai hadiah jackpot slot maxwin kami. Jackpot slot maxwin merupakan peluang besar bagi para pemain judi slot untuk meraih keuntungan yang lebih besar. Dalam permainan kami, Anda tidak harus terpaku pada kemenangan biasa saja. Kami hadir dengan jackpot slot maxwin yang sering, sehingga Anda memiliki peluang yang lebih besar untuk meraih kemenangan besar dengan hadiah yang menggiurkan. Dalam permainan judi slot, pengalaman bermain bukan hanya tentang keseruan dan hiburan semata. Kami memahami bahwa para pemain juga menginginkan kesempatan untuk meraih keberuntungan besar. Oleh karena itu, OLXTOTO hadir dengan jackpot slot maxwin yang sering untuk memberikan peluang besar kepada para pemain kami. Peluang Besar Menang Jackpot Slot Maxwin Peluang menang jackpot slot maxwin di OLXTOTO sangatlah besar. Anda tidak perlu khawatir tentang batasan atau pembatasan dalam meraih jackpot tersebut. Kami ingin memberikan kesempatan kepada semua pemain kami untuk merasakan sensasi menang dalam jumlah yang luar biasa. Jackpot slot maxwin kami dibuka untuk semua pemain judi slot di OLXTOTO. Anda memiliki peluang yang sama dengan pemain lainnya untuk memenangkan hadiah jackpot yang besar. Kami percaya bahwa semua orang memiliki kesempatan untuk meraih keberuntungan besar, dan itulah mengapa kami menyediakan jackpot slot maxwin yang sering untuk memenuhi harapan dan keinginan Anda.   Kesimpulan OLXTOTO adalah situs slot gacor terbaik yang memberikan pengalaman bermain judi slot online yang tak terlupakan. Dengan variasi slot online terlengkap dan peluang memenangkan jackpot slot maxwin yang sering, OLXTOTO menjadi pilihan terbaik bagi para pemain yang mencari kesenangan dan kemenangan besar dalam perjudian online. Di samping itu, OLXTOTO juga menawarkan layanan pelanggan yang ramah dan responsif, siap membantu setiap pemain dalam mengatasi masalah teknis atau pertanyaan seputar perjudian online. Kami menjaga integritas game dan memberikan lingkungan bermain yang adil serta menjalankan kebijakan perlindungan pelanggan yang cermat. Bergabunglah dengan OLXTOTO sekarang dan nikmati pengalaman bermain slot online yang luar biasa. Jadilah bagian dari komunitas perjudian yang mengagumkan ini dan raih kesempatan untuk meraih kemenangan besar. Dapatkan akses mudah dan praktis ke situs OLXTOTO dan rasakan sensasi bermain judi slot yang tak terlupakan.  
    • OLXTOTO: Platform Maxwin dan Gacor Terbesar Sepanjang Masa Di dunia perjudian online yang begitu kompetitif, mencari platform yang dapat memberikan kemenangan maksimal (Maxwin) dan hasil terbaik (Gacor) adalah prioritas bagi para penjudi yang cerdas. Dalam upaya ini, OLXTOTO telah muncul sebagai pemain kunci yang mengubah lanskap perjudian online dengan menawarkan pengalaman tanpa tandingan.     Sejak diluncurkan, OLXTOTO telah menjadi sorotan industri perjudian online. Dikenal sebagai "Platform Maxwin dan Gacor Terbesar Sepanjang Masa", OLXTOTO telah menarik perhatian pemain dari seluruh dunia dengan reputasinya yang solid dan kinerja yang luar biasa. Salah satu fitur utama yang membedakan OLXTOTO dari pesaingnya adalah komitmen mereka untuk memberikan pengalaman berjudi yang unik dan memuaskan. Dengan koleksi game yang luas dan beragam, termasuk togel, slot online, live casino, dan banyak lagi, OLXTOTO menawarkan sesuatu untuk semua orang. Dibangun dengan teknologi terkini dan didukung oleh tim ahli yang berdedikasi, platform ini memastikan bahwa setiap pengalaman berjudi di OLXTOTO tidak hanya menghibur, tetapi juga menguntungkan. Namun, keunggulan OLXTOTO tidak hanya terletak pada permainan yang mereka tawarkan. Mereka juga terkenal karena keamanan dan keadilan yang mereka berikan kepada para pemain mereka. Dengan sistem keamanan tingkat tinggi dan audit rutin yang dilakukan oleh otoritas regulasi independen, para pemain dapat yakin bahwa setiap putaran permainan di OLXTOTO adalah adil dan transparan. Tidak hanya itu, OLXTOTO juga dikenal karena layanan pelanggan yang luar biasa. Dengan tim dukungan yang ramah dan responsif, para pemain dapat yakin bahwa setiap pertanyaan atau masalah mereka akan ditangani dengan cepat dan efisien. Dengan semua fitur dan keunggulan yang ditawarkannya, tidak mengherankan bahwa OLXTOTO telah menjadi platform pilihan bagi para penjudi online yang mencari kemenangan maksimal dan hasil terbaik. Jadi, jika Anda ingin bergabung dengan jutaan pemain yang telah merasakan keajaiban OLXTOTO, jangan ragu untuk mendaftar dan mulai bermain hari ini!  
    • OLXTOTO adalah bandar slot yang terkenal dan terpercaya di Indonesia. Mereka menawarkan berbagai jenis permainan slot yang menarik dan menghibur. Dengan tampilan yang menarik dan grafis yang berkualitas tinggi, pemain akan merasa seperti berada di kasino sungguhan. OLXTOTO juga menyediakan layanan pelanggan yang ramah dan responsif, siap membantu pemain dengan segala pertanyaan atau masalah yang mereka hadapi. Daftar =  https://surkale.me/Olxtotodotcom1
    • DAFTAR & LOGIN BIGO4D   Bigo4D adalah situs slot online yang populer dan menarik perhatian banyak pemain slot di Indonesia. Dengan berbagai game slot yang unik dan menarik, Bigo4D menjadi tempat yang ideal untuk pemula dan pahlawan slot yang berpengalaman. Dalam artikel ini, kami akan membahas tentang Bigo4D sebagai situs slot terbesar dan menarik yang saat ini banyak dijajaki oleh pemain slot online.
  • Topics

×
×
  • Create New...

Important Information

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