Slimefun / Slimefun4

Slimefun 4 - A unique Spigot/Paper plugin that looks and feels like a modpack. We've been giving you backpacks, jetpacks, reactors and much more since 2013.
GNU General Public License v3.0
973 stars 545 forks source link

attributes in items #655

Closed perengano99 closed 6 years ago

perengano99 commented 6 years ago

would you know if there is a way to put an attribute in

" new SlimefunItem (Categories.WEAPONS, SlimefunItems.PEDO_SWORD," PEDO_SWORD ", RecipeType.ENHANCED_CRAFTING_TABLE, new ItemStack [] {null, null, null, null, null, null, null, null, null}) .register (true); "

Hellcode48 commented 6 years ago

The only real way to do that is if the item is made without using Slimefun's CustomItem method, you can do something like: public static ItemStack getItem() { ItemStack item = new ItemStack(Material.STONE_SWORD); //enter metadata and attribute stuff here return item; }

then replace SlimefunItems.PEDO_SWORD with getItem()

perengano99 commented 6 years ago

You mean this?

public static ItemStack getItem() { ItemStack PEDO_SWORD = new ItemStack(Material.DIAMOND_SWORD); ItemMeta im3 = PEDO_SWORD.getItemMeta(); net.minecraft.server.v1_12_R1.ItemStack ia3nmsStack = CraftItemStack.asNMSCopy(PEDO_SWORD); NBTTagCompound ia3compound = ia3nmsStack.getTag(); if (ia3compound == null) { ia3compound = new NBTTagCompound(); ia3nmsStack.setTag(ia3compound); ia3compound = ia3nmsStack.getTag(); } NBTTagCompound ia3speed = new NBTTagCompound(); NBTTagList ia3 = new NBTTagList(); ia3speed.set("AttributeName", new NBTTagString("generic.movementSpeed")); ia3speed.set("Name", new NBTTagString("generic.movementSpeed")); ia3speed.set("Amount", new NBTTagDouble(0.1)); ia3speed.set("Operation", new NBTTagInt(0)); ia3speed.set("UUIDLeast", new NBTTagInt(894654)); ia3speed.set("UUIDMost", new NBTTagInt(2872)); ia3.add(ia3speed); im3.spigot().setUnbreakable(false); ia3compound.set("AttributeModifiers", ia3speed); ia3compound.set("AttributeModifiers", ia3); ia3nmsStack.setTag(ia3compound); return PEDO_SWORD; }

Hellcode48 commented 6 years ago

Im not 100% sure if the NBT is correct (never used it), but if it is, that is correct, I do suggest changing getItem() to maybe pedoSword or getPedoSword for your convenience (if you want to add more items like that). Also don't forget to set the item meta: PEDO_SWORD.setItemMeta(im3);