using getDurability to pass to a ShapedRecipe? and yml issues apparently

Discussion in 'Plugin Development' started by Vilicus, Jan 30, 2012.

Thread Status:
Not open for further replies.
  1. Offline

    Vilicus

    Let me start off by saying I'm new to programming in java, new to mods and all that junk. I've been wanting a way to clone an item, specifically a map. From what I understand, maps have a durability which determines which map you get. So what I want to do is make a recipe where it passes the durability over to 2 new maps. So far my untested, yet without errors code looks like this:
    Code:
    package us.nerdwood.Vilicus.CloneMap;
     
    import java.util.logging.Logger;
     
    import org.bukkit.Material;
    import org.bukkit.inventory.ItemStack;
    import org.bukkit.inventory.ShapedRecipe;
    import org.bukkit.plugin.PluginDescriptionFile;
    import org.bukkit.plugin.java.JavaPlugin;
     
    public class CloneMap extends JavaPlugin{
        public static CloneMap plugin;
        public final Logger logger = Logger.getLogger("Minecraft");
     
        public void onDisable() {
            PluginDescriptionFile pdffile = this.getDescription();
            this.logger.info(pdffile.getName() + " is now disabled.");
        }
        public void onEnable() {
            PluginDescriptionFile pdffile = this.getDescription();
            this.logger.info(pdffile.getName() + " version " + pdffile.getVersion() + " is enabled.");
            ShapedRecipe clonedMap = new ShapedRecipe(new ItemStack(Material.MAP, 2));
                clonedMap.shape("AAA", "ABA", "AAA");
                clonedMap.setIngredient('A', Material.PAPER);
                clonedMap.setIngredient('B', Material.MAP);
            getServer().addRecipe(clonedMap);
        }
    }
    Now I have no idea if the durability of the map placed in the ingredient automatically passes to the recipe itself but either way I cant seem to test it anyway. For whatever reason I cant run the jar on my server. Its erroring out when the server starts saying it cant find my plugins.yml file, which is a bunch of bull as I have created that and included in the export.

    Any help would be appreciated.

    I'm still needing help regarding both issues. Figuring out why I'm having issues with "plugin.yml" not being included when I'm export and figuring out a way to detect the durability of a map being used in a recipe for it to produce the same map with the same durability as a result.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 23, 2016
  2. Put the plugin.yml outside the src folder. It works for eclipse at least.

    Not sure on the other, as I haven't touched recipes before.
     
  3. Offline

    Vilicus

    ok, thanks for that, knowing to pull the plugin.yml out of src helped it startup. Managed to test it in-game and its creating 2 of a new map, and not 2 of the map I used in the recipe. :(
     
  4. Offline

    troed

    While I've been able to get this to work, it doesn't work nicely. Basically I can get a clone of the mapid I supply in the recipe if I shift-click the crafted result, but normal clicks result in new maps. I've been unable to find where in CraftBukkit the code that decides to allocate a new map even when an existing mapid is supplied to the recipe hides - but I'm quite confident that's how it works anyway.

    To be able to get a specific map by crafting, it seems likely an enhancement on Bukkit must be done. I'm going to write up such an enhancement request tomorrow, but it would help if someone who's done a lot of the map support got interested or at least if someone more successful than me in traversing CraftBukkit pointed out where it should be.

    Code:
    public CraftMapView createMap(World world) {
            ItemStack stack = new ItemStack(Item.MAP, 1, -1);
            WorldMap worldmap = Item.MAP.getSavedMap(stack, ((CraftWorld) world).getHandle());
            return worldmap.mapView;
        }
    My suggestion would be that:

    Code:
    ItemStack item = new ItemStack(Material.MAP, 1, Courier.MAPID);
    ShapelessRecipe recipe = new ShapelessRecipe(item);
    ... creates clones of the id supplied, and only if -1 is used instead (just as in CraftServer.createMap) a new one is allocated.

    (In your case you would need to supply the durability value of the map you want to clone to the recipe, and that's going to become quite tricky all in itself since you need to do that dynamically)

    ... and just now I thought of other plugins that might've run into the same issue, and sure thing, first one I found:

    http://dev.bukkit.org/server-mods/mapclone/

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 23, 2016
  5. Offline

    Tux2

    Lol, I'm surprised that you didn't find MapClone, which has been around ever since crafting maps was possible. ;)

    I haven't done that much research myself into the subject as I knew that shift clicking would give you map 0 and it bypassed whatever check the client/server did as far as map numbers. I'll do some research though and see what I can figure out and see if I can get a pull request accepted.
     
  6. Offline

    desht

  7. Offline

    troed

Thread Status:
Not open for further replies.

Share This Page