MaterialAPI - Create new items and blocks!

Discussion in 'Resources' started by Cybermaxke, Jan 19, 2013.

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

    Taurhuzz

    Will it be added in the future?
     
  2. Offline

    Cybermaxke

    Cjreek
    I will try to find the problem. ;)

    Taurhuzz
    Sure :)

    Cjreek
    Can you try a dev build of ProtocolLib?
    Download: here

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

    Cjreek

    Hi,

    I tried the dev-build but it didn't change anything :(
     
  4. Offline

    Cybermaxke

    I will send my latest version and maybe that will help to fix it.
    Download: here
     
  5. Offline

    Cjreek

    This doesn't work as well. It seems like my custom material changes into its base material if I change something with my stack. It seems to lose its custom material id.
     
  6. Offline

    Cybermaxke

    Trough the CustomItemStack?

    Comphenix
    We have a small problem with hiding the custom id and enchantments through ProtocolLib, sometimes they seem to be removed and also on dropping them. Do you have any idea how to fix it?

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

    Cjreek

    Ingame. If I right click a custom stack or add items to the stack or take some items from it than it doesn't work anymore.
     
  8. Offline

    Comphenix

    Removing the visible enchantment on dropped item is pretty straight forward - you need to intercept the item stack that is applied to the dropped item on the client side (through Packet40EntityMetadata). Look at how this is done in BlockPatcher:
    Code:java
    1. public void translateDroppedItemMetadata(PacketContainer packet, Player player, EventScheduler scheduler) {
    2. Entity entity = packet.getEntityModifier(player.getWorld()).read(0);
    3.  
    4. if (entity instanceof Item) {
    5. // Great. Get the item from the DataWatcher
    6. WrappedDataWatcher original = new WrappedDataWatcher(
    7. packet.getWatchableCollectionModifier().read(0)
    8. );
    9.  
    10. // Clone it
    11. WrappedDataWatcher watcher = original.deepClone();
    12.  
    13. // Allow mods to convert it and write back the result
    14. scheduler.computeItemConversion(new ItemStack[] { watcher.getItemStack(10) }, player, false);
    15. packet.getWatchableCollectionModifier().write(0, watcher.getWatchableObjects());
    16. }
    17. }

    You may also have to intercept Packet5EntityEquipment and clean up its ItemStack too.

    I haven't been able to reliably reproduce the other problem you're describing, but it looks like something really weird is going on. I would have to decompile MaterialAPI and start debugging, but the conversion process is a bit painful. It would have been much easier if you'd made it all available at the start. :)
     
  9. Offline

    Cybermaxke

    Comphenix
    I have the source on github: here

    First I want to get this problem fixed before adding new stuff.
    The ids and enchantments are pernamently removed when:
    - Dropping the item.
    - Right clicking in inventory.
    - And maybe other things...
     
  10. Offline

    rmh4209

    A couple questions/suggestions, as I'd love to use this.

    Is there any way we could get a Java 6 compatible version?

    Can you add an event to CustomMaterial for when en entity is hit while holding or wearing it?
     
  11. Offline

    DotChris

    Could you post the code to a fully made weapon like the phoenix sword? I keep getting the same error as CreeperShift and I can't help but feel I'm missing something, but I can't put my finger on it.
     
  12. Offline

    CreeperShift

    If you're getting the error without using a config file you're doing something wrong.

    I only get that error because I'm trying to access a value in another class, if I use fixed values it works fine.

    EDIT:

    Actually look at this, tested and works:

    Main Class:
    Code:
    package iPencil.Example.SuperSword;
     
    import me.cybermaxke.materialapi.inventory.CustomItemStack;
    import me.cybermaxke.materialapi.material.CustomMaterial;
    import me.cybermaxke.materialapi.recipe.CustomRecipeShaped;
    import me.cybermaxke.materialapi.recipe.RecipeData;
     
    import org.bukkit.Material;
    import org.bukkit.plugin.java.JavaPlugin;
     
    public class Sword extends JavaPlugin{
     
        public static CustomMaterial SuperSword;
       
       
        public void onDisable() {
              getLogger().info("SuperSword disabled!");
            }
       
       
        public void onEnable() {
              getLogger().info("SuperSword enabled!");
             
             
              SuperSword = new SuperSword("SuperSword", Material.DIAMOND_SWORD);
              CustomItemStack is1 = new CustomItemStack(SuperSword);
              CustomRecipeShaped r1 = new CustomRecipeShaped(is1);
             
             
              r1.setShape(
     
                        new CustomItemStack[] { null, new CustomItemStack(Material.DIAMOND), null },
     
                        new CustomItemStack[] { new CustomItemStack(Material.DIAMOND), new CustomItemStack(Material.DIAMOND_SWORD), new CustomItemStack(Material.DIAMOND) },
     
                        new CustomItemStack[] { null });
       
       
        RecipeData.registerRecipe(r1);
        }
    }
    
    and SuperSwords class:
    Code:
    package iPencil.Example.SuperSword;
    import me.cybermaxke.materialapi.material.CustomMaterial;
     
    import org.bukkit.Material;
    import org.bukkit.enchantments.Enchantment;
    import org.bukkit.entity.LivingEntity;
    import org.bukkit.entity.Player;
    import org.bukkit.potion.PotionEffect;
    import org.bukkit.potion.PotionEffectType;
     
    public class SuperSword extends CustomMaterial{
     
       
       
        public SuperSword(String id, Material material) {
            super(id, material);
           
            this.setDamage(1);
            this.setName("SuperSword");
            this.setLore("Mysterious weapon!", "Fire damage!");
            this.addEnchantment(Enchantment.KNOCKBACK, 1, false);
           
        }
     
        //Called when damaging a entity.
        @Override
        public void onHit(Player player, LivingEntity entity) {
       
            entity.setFireTicks(200);
            entity.addPotionEffect(new PotionEffect(PotionEffectType.SLOW, 200, 2));
        }
       
    }
    
     
  13. Offline

    Cybermaxke

    I think you also forgot 'depend: [MaterialAPI]' in your plugin.yml
    I also added it in the thread for future mistakes.

    I added my MaterialManager to the thread as example.
     
  14. Offline

    CreeperShift

    I see you you never understood what I was asking. It works fine with depend and without depend, I'm gonna show you what exactly my error is:

    (I removed everything to show you exactly what my problem is:)

    My Main Class, let's pretend "damage" is actually a value that gets loaded from a config, but for the sake of showing what I mean it's just a value right now:

    Code:
    public class Sword extends JavaPlugin{
     
        public int damage = 15;
     
        public static CustomMaterial SuperSword;
     
     
        public void onDisable() {
              getLogger().info("SuperSword disabled!");
            }
     
     
        public void onEnable() {
              getLogger().info("SuperSword enabled!");
           
           
              SuperSword = new SuperSword("SuperSword", Material.DIAMOND_SWORD);
              CustomItemStack is1 = new CustomItemStack(SuperSword);
              CustomRecipeShaped r1 = new CustomRecipeShaped(is1);
           
           
              r1.setShape(
     
                        new CustomItemStack[] { null, new CustomItemStack(Material.DIAMOND), null },
     
                        new CustomItemStack[] { new CustomItemStack(Material.DIAMOND), new CustomItemStack(Material.DIAMOND_SWORD), new CustomItemStack(Material.DIAMOND) },
     
                        new CustomItemStack[] { null });
     
     
        RecipeData.registerRecipe(r1);
        }
    }
    Now for my class "SuperSword" it looks like this:


    Code:
    public class SuperSword extends CustomMaterial{
     
        public Sword plugin;
     
        public SuperSword(String id, Material material) {
            super(id, material);
         
         
            this.setDamage(plugin.damage);
            this.setName("SuperSword");
            this.setLore("Mysterious weapon!", "Fire damage!");
            this.addEnchantment(Enchantment.KNOCKBACK, 1, false);
         
        }
     
        //Called when damaging a entity.
        @Override
        public void onHit(Player player, LivingEntity entity) {
     
            entity.setFireTicks(200);
            entity.addPotionEffect(new PotionEffect(PotionEffectType.SLOW, 200, 2));
        }
     
    }
    You see, the damage is supposed to be whatever "damage" is, it will be changeable via a config file. Now usually I would just put the plugin into the constructor, but in this case I will either have to change the constructor (and that breaks the plugin aswell) or find some other way. The problem is that it's loading a value from another class.

    The error I'm getting:

    Code:
    2013-01-24 19:06:23 [SEVERE] Error occurred while enabling SuperSword v0.1 (Is i
    t up to date?)
    java.lang.NullPointerException
            at iPencil.Example.SuperSword.SuperSword.<init>(Sword.java:58)
            at iPencil.Example.SuperSword.Sword.onEnable(Sword.java:32)
            at org.bukkit.plugin.java.JavaPlugin.setEnabled(JavaPlugin.java:217)
            at org.bukkit.plugin.java.JavaPluginLoader.enablePlugin(JavaPluginLoader
    .java:457)
            at org.bukkit.plugin.SimplePluginManager.enablePlugin(SimplePluginManage
    r.java:381)
            at org.bukkit.craftbukkit.v1_4_6.CraftServer.loadPlugin(CraftServer.java
    :282)
            at org.bukkit.craftbukkit.v1_4_6.CraftServer.enablePlugins(CraftServer.j
    ava:264)
            at net.minecraft.server.v1_4_6.MinecraftServer.j(MinecraftServer.java:32
    1)
            at net.minecraft.server.v1_4_6.MinecraftServer.e(MinecraftServer.java:30
    0)
            at net.minecraft.server.v1_4_6.MinecraftServer.a(MinecraftServer.java:25
    9)
            at net.minecraft.server.v1_4_6.DedicatedServer.init(DedicatedServer.java
    :149)
            at net.minecraft.server.v1_4_6.MinecraftServer.run(MinecraftServer.java:
    399)
            at net.minecraft.server.v1_4_6.ThreadServerApplication.run(SourceFile:84
    If it's still unclear, tell me and I will explain further. I'm really hoping to find a solution to this :)
     
  15. Offline

    Cybermaxke

    CreeperShift
    Adding a arg to the constructor is breaking it? That would be weird, but you are getting a null pointer because 'plugin' is still null.
     
  16. Offline

    CreeperShift

    Changing it to

    Code:
    public class SuperSword extends CustomMaterial{
     
        Sword plugin;
     
        public SuperSword(String id, Material material, Sword plugin) {
            super(id, material);
       
            this.plugin = plugin;
       
            this.setDamage(this.plugin.damage);
    Still throws the same Nullpointer :(

    The same code is used in one of my other plugins inside a listener class and works just fine. (the plugin name = plugin; stuff)
     
  17. Offline

    DotChris

    it was the plugin.yml -__- figures something simple.

    But, when I try to craft the recipe in the example of CreeperShift's code no item is created.
     
  18. Offline

    Cybermaxke

  19. Offline

    CreeperShift

    Are you sure you are crafting

    XYX
    YFY
    XXX

    X= air
    Y= diamond
    F = diamondsword

    ?


    Thanks! I just couldn't figure out how to change that constructor properly. :)
     
  20. Offline

    DotChris

    Positive that's what I did.
    I even tried changing it to a shapeless recipe with just diamond sword, nada.
     
  21. Offline

    bobacadodl

    Amazing. Will definitely be using this soon :)
     
  22. Offline

    TechTeller96

    Is there a way to make this support custom textures? :)
     
  23. Offline

    Cjreek

    TechTeller96 If you're using this for your own server I've got an idea for you:
    You could make a server texture pack and replace the disc textures with your custom textures.
    If discs are not important on your server than this should work.
     
  24. Offline

    CreeperShift

    Thats weird because I tested it multiple times and it worked just fine oO

    This might sound retarded but, are you sure you put the MaterialAPI plugin into your plugin folder? :p
     
  25. Offline

    DotChris

    Yes, the server even tells me that MaterialAPI is loaded.
     
  26. Offline

    Groxlord27

    Would I be able to create food, armor, or ranged weapons that behave like a bow using this API?
     
  27. Offline

    Cybermaxke

    Sure, food isn't added yet since there is no event and bow you should have to store the arrows because I didn't add that yet.
     
  28. Offline

    slasheh

    Hey I have some questions.

    Can you spawn in the custom items with /give or /i?

    Where you say the map texture what do you mean by that?
     
  29. Offline

    Cybermaxke

    You have to make the commands, for them u can also look to my MaterialManager.
    And for the maps is just drawing a image on them, without to much code adding yourself.
     
  30. Offline

    slasheh

    Oh ok thanks.
    I have another question, Is there a way to make the enchantments hook with TimTheEnchanter? So like if I would put Sharpness 10 on top of a diamond sword it would actually be a real Sharpness 10 because when I tried just putting Sharpness 10 on my custom sword it only did the base damage which is 7 but with Sharpness 10 on a regular diamond sword with TimTheEnchanter it kills me in 1 hit.

    Edit:
    Also I ran into a bug, so I was using a custom Shear and I was breaking a bunch of trees once my shear broke I pressed right clicked and it gave me it back all new and everything, after that I only used it for a little bit and right clicked again and it reset the item again. Hopefully there is a fix for this :/
     
Thread Status:
Not open for further replies.

Share This Page