Posted March 12, 20169 yr 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....
March 12, 20169 yr 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)
March 12, 20169 yr Author 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....
March 12, 20169 yr 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.
March 12, 20169 yr Author 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....
March 12, 20169 yr 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
March 13, 20169 yr Author 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. 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....
March 13, 20169 yr 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.
March 13, 20169 yr Author 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....
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.