How to add an item as a fuel?

Discussion in 'Plugin Development' started by boredherobrine13, Apr 24, 2015.

Thread Status:
Not open for further replies.
  1. Hi so I'm making a simple plugin that will add things as fuel in Minecraft. Note that it is not one with a config where you specify the item(s) you want to be a fuel. I just want to add certain items as fuels, for example: a bow. So my question is how in code would I specify the item I want to add, and then its burn time. I'm very new to plugin coding and need to know how to do this :) Any help is appreciated.
     
  2. Offline

    Koobaczech

    Hey bud. Here would be 2 ways to go about it that i just thought about. Say your bow consumes string to work
    1. In the plugin, compare the fuel item with the Material Type(Material.STRING), or the Type Id(287)
    2. When your action requires fuel, if the string is in your inventory etc etc, consume it in quantities(basically remove it piece by piece or all at once)
    3. Make a delayed task that triggers a STOP on the working item. This means that if the delayed task runs, you are out of fuel and whatever you are doing will stop working. In the delayed task make it set a boolean such as BowWork to FALSE
    4. However many string you consume as fuel at that time, multiply the delayed task by that amount
    So if your furnace/car/jetpack/bow/whatever requires a string as fuel, and you have a string in your inv, consume it, set a boolean to TRUE so your thing works, and delay a task by the string burn time*20L and that will give you stringburntime seconds of burn time. When the delayed task finally runs, the boolean will then be FALSE and you need more fuel

    Another way to go about it is make a rescheduling task, and every so often it takes an integer and if its not 0, it minuses it by 1. So when you consume a string, it will set that integer to like 100. And every second the rescheduling task will minus it by 1. SO you have 100 seconds of burn time. The good thing about this second way is that you can keep adding fuel. Form 1 only lets you add fuel once a run. Some people have told me not to spoon-feed, so il guide you through the thing with pseudocode if you require help! But heres way two run through
    1. Before firing, check if player inventory has Material.STRING or typeId 287
    2. If they do, consume 1 at a time, or the whole amount
    3. For how ever many consumed, add it to an integer named burntime. So burntime would be at 100 if 100 were consumed and each string adds a second of burn time
    4. Make a repeating task that minuses burntime by 1 every second if burntime is > 0
    5. If burntime > 0, fire le bow
    6. Find a way to cancel the task so its not eating your cpu
    7. Find a way to re start the task so your code works
    8. Read links below

    https://bukkit.org/threads/scheduled-delayed-tasks.98590/
    http://wiki.bukkit.org/Scheduler_Programming
     
    Last edited: Apr 24, 2015
  3. That might work but wouldn't that require a database of some sort? I'm extremely new to this and databases sound even more complicated.
     
  4. Offline

    nj2miami

    You were provided some great feedback and should have enough so that your next post shows some code of what you have tried.

    These forums are about helping so do not let anyone else tell you how you should respond. There are a few knuckleheads who feel like they control the flow of conversation here, but do not let them discourage you. :)
     
    Koobaczech likes this.
  5. Offline

    Koobaczech

    Thank you @nj2miami ! And no databases bud. A database would be needed to enhance the performance of working with large player/server/world/item/etc data, performance that exceeds pulling information from configuration yaml files. With databases, you can perform a query(filtered search) on data and get what you need, where as in a yaml you read through it all until you find what you need. None of that is happening here as far as i can see. Just variables and functions and checks and codeeee. If you would like to learn more on databases and how they can help you read up here! @boredherobrine13 https://www.mysql.com
     
  6. Man I just realized why this wasn't making sense. Sorry for the time waste. What you are describing sounds like a way to make a gun or projectile firing plugin correct? Like you hold a stick and left click in the direction you want to fire and it consumes something, for example clay? Am I correct? What I am looking for is a way to take something like a bow or a diamond block that ISNT usable as a furnace fuel and make a plugin so that I can use it as a furnace fuel. An example thats a little less confusing is put a diamond block into a furnace with iron ore above it, have the diamond block be consumed by the furnace, and then have the furnace output the iron ore in the top just like you were smelting it with say coal or wood, but using a diamond block or some other item/block instead. I should have phrased my question more clearly, sorry.

    Edit: Lol sorry if im not getting something here...noob alert.
     
  7. Offline

    Koobaczech

    Mm..Well if its a furnace you can try to mess with it. Bukkit allows you to change furnace states. I have no idea how to add other fuels to a furnace and this code is only for you to see you can dig deep into furnace states
    Code:
            Block blck=null; //Some block
            if(blck.getState() instanceof Furnace) {
                Furnace f = (Furnace)blck.getState(); //Get a Furnace
                f.getBurnTime(); //Get Furnace burn time
                f.setBurnTime(); //Change Furnace burn time
            }
    Heres some links i found
    https://bukkit.org/threads/adding-furance-fuels-solved.40715/
    https://bukkit.org/threads/adding-an-item-to-the-fuel-slot.280275/
     
    Last edited: Apr 24, 2015
  8. Hmmmm...Well earlier I was digging into that kind of stuff in the class files of bukkit. Time to go check out the documentation lol.

    Take a look here https://hub.spigotmc.org/javadocs/bukkit/ Look at the class "FurnaceRecipe" I think the answer may lie there if anywhere.
     
    Last edited by a moderator: Apr 24, 2015
  9. Offline

    Koobaczech

  10. so could I just put that in my onEnable and then have it clear recipes when it disables? I know thats how it is done when people add certain recipes to minecraft as well as making it so that you can cook rotten flesh into leather.
     
  11. Offline

    mythbusterma

    @Koobaczech

    That's just for modifying the inventory, that won't actually force the furnace to burn it. I believe that he's on the right track by adding furnace recipes.
     
    boredherobrine13 likes this.
  12. Offline

    Koobaczech

    I don't know boredhero, sorry! Id say play around with it. mythbusterma might know xD
     
  13. Well no rush...right now my PC can't open exe files. I accidently associated another program with them and now windows can't open them. Well the problem is I tried to re associate it with explorer, but guess what. Explorer is explorer.exe so windows can't open explorer.exe lololol

    Welp I'm back..finally fixed that. How would I go about adding a furnace recipe @mythbusterma ...my concern is that I will have to make a recipe for every smeltable item. Is that the case? Also how exactly would I format that.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 12, 2016
  14. Offline

    nj2miami

    OK, so I did some testing.
    OK, there is a big difference in creating furnace recipes and allowing for custom fuels.

    I am not 100% that this is the best way to accomplish the fuel issue, but I toyed around for about 20 minutes and came up with this method which seemed to work perfectly.

    1. Check the InventoryClickEvent - check if the click is in a FurnaceInventory
    2. Check if the player is clicking the fuel slot
    3. Check if the item in the Cursor is a "custom fuel" - I tested with Diamond Swords
    4. If it is a custom fuel, set the Fuel slot to a clone of the Cursor item then set the Cursor to Air (to empty what you are holding)

    This will now place your custom fuel in the slot (the GUI blocks any non-vanilla fuel). I am not sure if you can somehow add these fuel directly into MC, I did not find a method to do so.

    5. Now once the fuel is set you need to check the FurnaceBurnEvent (it will trigger when an item is added to the upper slot) and if the Fuel slot has a custom fuel, setBurnTime to whatever you want it to be based on your custom fuel. (setBurnTime is an INT in # of ticks, so you will want to multiply by 20 to get seconds of burn)

    6. Once your burn event has begun, set the Fuel slot to AIR.

    Create config file holding your custom types, burn times and even permissions to really add a level of customization to it. I basically wrote the plugin in under an hour and deployed on a 1.8.3 Spigot server with no errors.
     
  15. Hey guys thanks for all the advice and sorry for the super late bump. Ive been busy with school + ive decided to get to learn java better before I attempt this.
     
  16. Offline

    sistem21

    Anyone can send me an example of plugin?Pls...
     
  17. What exactly do you mean by "Example"
     
  18. The plugin already done.
     
  19. There Is no pre configured plugin for this already done that I know of? I know there were ones that allow you to configure things like this that are used for like minigames and stuff but I just want to make a pre configured plugin that will burn a list of things that are coded into it, non configurable.
     
  20. @sistem21 Are you a developer looking to create a similar plugin? Or are you a server admin looking to use this sort of plugin. If you are the former, the advice given here should be perfectly adequate in order for you to make your own plugin. If you are the latter, then please make a request in the "Plugin Requests" section.
     
  21. @AdamQpzm I am a server owner myself, but I wanted to take a shot at learning java and making a plugin. Sooo thats why theres so little activity here, because I'm basically in the middle of learning java lol.
     
  22. @boredherobrine13 In that case yeah, continue on with your Java learning before trying to understand plugins. In fact, I wouldn't really recommend looking at other plugins as a learning exercise - then stuff like bad practices happen :) I'd recommend following some tutorials then, when you've learned about Java and Bukkit, you can maybe try to make a plugin like this yourself as a challenge, it should be appropriate for a beginner :)
     
Thread Status:
Not open for further replies.

Share This Page