Jump to content

[Solved, m8]Modifying the functionality of torches


Toost

Recommended Posts

In my mod, I'm trying to make it so that torches are capable of setting other blocks on fire. I want to know if it's possible to do this without creating a new torch block that replaces old torches. I want to do this so that other mods that use torches in their recipes are compatible with this mod. Thanks!

DRAGONMANG: "I'm Dragonmang, m8. Here me roar."

HERO: "Oh no... not. Dragonmang."

DRAGONMANG: "Roar, m8."

HERO: "Ahhh......"

And so the brave knight and Dragonmang fought on the mountaintop for many moons....

Link to comment
Share on other sites

I am not sure if this would work, but basically my idea would be when a chunk loads check if it has torches, add every torch to a list (WorldSavedData + ITickable) and remove all torches in the chunk from the list when the chunk unloads.

In the update method of ur WorldSavedData you can check blocks around the torches and set em on fire if your conditions are met.

Of course you would also need to keep track of torches that get removed (was it the BreakEvent?)

 

EDIT:

Or you could create your custom blocks that looks like a torch, behaves like a torch and drops the normal vanilla torch when destroyed. Then make the block tick randomly. After that you only need to replace every placed vanilla torch with ur own (there is an event for torches getting placed but I dont think it fires for torches that get generated in the world e.g. villages)

Link to comment
Share on other sites

Alright, so I've taken your advice, and I think the solution is to create an event handler that checks when a player clicks. Then I could have it check if the player used a torch. After that, I can replace that torch block with my "toost torch"(The fake torch that can light things on fire). Then I just have to make it so that toost torches drop regular torches when broken.

I'm getting stuck on checking for the current item and replacing the regular torches. The rest of the solution should be easy enough, though.

This is the code for the event handler:

	@SubscribeEvent(priority = EventPriority.HIGH)
    public void onPlayerUseEvent(PlayerInteractEvent e) {
	ItemStack toostTorchStack = new ItemStack(ModBlocks.toost_torches);
	if(e.entityPlayer.getItemInUse() == toostTorchStack){
		System.out.println("Found Torch");

	}else{
		System.out.println("Found Item Use Event");

	}
    }

 

EDIT:

The console does output the bottom line whenever the player clicks, so the event handler is working. However, it doesn't differentiate whether or not the player is holding torches.

DRAGONMANG: "I'm Dragonmang, m8. Here me roar."

HERO: "Oh no... not. Dragonmang."

DRAGONMANG: "Roar, m8."

HERO: "Ahhh......"

And so the brave knight and Dragonmang fought on the mountaintop for many moons....

Link to comment
Share on other sites

Oh god, if you're going to make your own block, don't use the vanilla torch item.  That's dumb.

 

Just remove and replace the recipe.

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

I don't want to ruin compatibility...

DRAGONMANG: "I'm Dragonmang, m8. Here me roar."

HERO: "Oh no... not. Dragonmang."

DRAGONMANG: "Roar, m8."

HERO: "Ahhh......"

And so the brave knight and Dragonmang fought on the mountaintop for many moons....

Link to comment
Share on other sites

pretty sure there is a block placed event, you can check what they type of block is and if the block is vanilla torch, cancel event and place your torch instead. You could probably even have your torch extend the vanilla torch and the only code you would need would be however you choose to handle lighting things on fire. By extending vanilla torch, without overriding anything it should automatically look like a vanilla torch and drop vanilla torches.

Current Project: Armerger 

Planned mods: Light Drafter  | Ore Swords

Looking for help getting a mod off the ground? Coding  | Textures

Link to comment
Share on other sites

Nvm... I found a WAAAAYYyyyyy better way of handling torches. I've made it so that when the player tries to place a torch, they explode. A lot. Huge explode.  :D

That way they can still use torches in crafting if they need to, but they can't place them in the world.

 

Here's the event handler code if anybody's interested:

@SubscribeEvent(priority = EventPriority.HIGH)
    public void onPlayerUseEvent(PlayerInteractEvent e) {
	EntityPlayer player = e.entityPlayer;

	if(e.entityPlayer.getCurrentEquippedItem() != null){
		Item item = player.getCurrentEquippedItem().getItem();
		if(item == Item.getItemFromBlock(Blocks.torch)){
			e.world.newExplosion(null, player.posX, player.posY, player.posZ, 3f, true, true);
			e.setCanceled(true);

		}else{}
	}
    }

EDIT: Get rid of this line:

e.setCanceled(true);

Otherwise, when you right click, you will just get sent flying, but on left click you will actually explode.

I think this is because the swinging action isn't canceled, but the block placing action is, for some reason.

DRAGONMANG: "I'm Dragonmang, m8. Here me roar."

HERO: "Oh no... not. Dragonmang."

DRAGONMANG: "Roar, m8."

HERO: "Ahhh......"

And so the brave knight and Dragonmang fought on the mountaintop for many moons....

Link to comment
Share on other sites

Sure exploding torches.  Whatever you want.

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

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

    • 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   Slot Gacor untuk Sensasi Bermain Maksimal Olahraga cepat dan seru dengan slot gacor di OLXTOTO. Rasakan sensasi bermain maksimal dengan mesin slot yang memberikan kemenangan beruntun. Temukan keberuntungan Anda di antara berbagai pilihan slot gacor yang tersedia dan rasakan kegembiraan bermain judi slot yang tak terlupakan. Situs Slot Terpercaya dengan Pilihan Terlengkap OLXTOTO adalah situs slot terpercaya yang menawarkan pilihan terlengkap dalam perjudian online. Nikmati berbagai genre dan tema slot online yang menarik, dari slot klasik hingga slot video yang inovatif. Dipercaya oleh jutaan pemain, OLXTOTO memberikan pengalaman bermain yang aman dan terjamin.   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.  
    • LOGIN DAN DAFTAR DISINI SEKARANG !!!! Blacktogel adalah situs judi slot online yang menjadi pilihan banyak penggemar judi slot gacor di Indonesia. Dengan platform yang sangat user-friendly dan berbagai macam permainan slot yang tersedia, Blacktogel menjadi tempat yang tepat untuk penggemar judi slot online. Dalam artikel ini, kami akan membahas tentang Blacktogel dan keunggulan situs slot gacor online yang disediakan.  
    • Situs bandar slot online Gacor dengan bonus terbesar saat ini sedang menjadi sorotan para pemain judi online. Dengan persaingan yang semakin ketat dalam industri perjudian online, pemain mencari situs yang tidak hanya menawarkan permainan slot yang gacor (sering memberikan kemenangan), tetapi juga bonus terbesar yang bisa meningkatkan peluang menang. Daftar disini : https://gesit.io/googlegopek
    • Situs bandar slot online Gacor dengan bonus terbesar saat ini sedang menjadi sorotan para pemain judi online. Dengan persaingan yang semakin ketat dalam industri perjudian online, pemain mencari situs yang tidak hanya menawarkan permainan slot yang gacor (sering memberikan kemenangan), tetapi juga bonus terbesar yang bisa meningkatkan peluang menang. Daftar disini : https://gesit.io/googlegopek
    • Situs bandar slot online Gacor dengan bonus terbesar saat ini sedang menjadi sorotan para pemain judi online. Dengan persaingan yang semakin ketat dalam industri perjudian online, pemain mencari situs yang tidak hanya menawarkan permainan slot yang gacor (sering memberikan kemenangan), tetapi juga bonus terbesar yang bisa meningkatkan peluang menang. Daftar disini : https://gesit.io/googlegopek
  • Topics

×
×
  • Create New...

Important Information

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