Potion without glow effect?

Discussion in 'Plugin Development' started by Someone_Like_You, Mar 3, 2014.

Thread Status:
Not open for further replies.
  1. Is it possible to create colored water in bottle without the potion and the glow effect? (I know I can check for when player get effect)
    example : look at the right of the page. http://minecraft.gamepedia.com/Potions
     
  2. Offline

    Barinade

    Not sure on the glow, but you can deny the effect based on name or lore
     
  3. Offline

    RawCode

    remove NBT tags from item, it will remove effects and glow.
     
  4. Barinade Really love that cat xD and thanks!, RawCode I havent used NBT tags yet, is there anyway to do it with packets? if no, mind explain more about those NBT tags?
     
  5. Offline

    Barinade

    Get it's Minecraft ItemStack first
     
  6. Offline

    Barinade

    You can try setTag(null), not sure if that will work
     
  7. Offline

    RawCode

    just perform original research, NBT is very simple to use and understand, some questions about serialization and networking can be ignored at early stages (game will handle it on it's own)
     
  8. RawCode Barinade
    After editing the NBT data of the potion, how do I apply it to the itemstack and send it to the player?..
     
  9. Offline

    RawCode

    some questions about serialization and networking can be ignored at early stages (game will handle it on it's own)
     
  10. RawCode I still dont understand how to use NBT tags ... xD I have been look thru the forums, didnt learn anything tho... can you please explain me on those tags and how to use them? tutorial maybe?
     
  11. Offline

    Garris0n

  12. Offline

    NonameSL

    This glow enchantment code will help:
    Code:java
    1. import java.lang.reflect.Field;
    2.  
    3. import org.bukkit.enchantments.Enchantment;
    4. import org.bukkit.enchantments.EnchantmentTarget;
    5. import org.bukkit.enchantments.EnchantmentWrapper;
    6. import org.bukkit.inventory.ItemStack;
    7.  
    8. public class EnchantGlow extends EnchantmentWrapper
    9. {
    10.  
    11. private static Enchantment glow;
    12.  
    13. static String name;
    14. public EnchantGlow(int id)
    15. {
    16. super(id);
    17. }
    18.  
    19. @Override
    20. public boolean canEnchantItem(ItemStack item)
    21. {
    22. return true;
    23. }
    24.  
    25. @Override
    26. public boolean conflictsWith(Enchantment other)
    27. {
    28. return false;
    29. }
    30.  
    31. @Override
    32. public EnchantmentTarget getItemTarget()
    33. {
    34. return null;
    35. }
    36.  
    37. @Override
    38. public int getMaxLevel()
    39. {
    40. return 10;
    41. }
    42.  
    43. @Override
    44. public String getName()
    45. {
    46. return name;
    47. }
    48.  
    49. @Override
    50. public int getStartLevel()
    51. {
    52. return 1;
    53. }
    54.  
    55. public static Enchantment getGlow(String cname)
    56. {
    57. if ( glow != null )
    58. return glow;
    59.  
    60. try
    61. {
    62. Field f = Enchantment.class.getDeclaredField("acceptingNew");
    63. f.setAccessible(true);
    64. f.set(null , true);
    65. }
    66. catch (Exception e)
    67. {
    68. e.printStackTrace();
    69. }
    70. name=cname;
    71. glow = new EnchantGlow(255);
    72. Enchantment.registerEnchantment(glow);
    73. return glow;
    74. }
    75.  
    76. public static void addGlow(ItemStack item, String name)
    77. {
    78. Enchantment glow = getGlow(name);
    79.  
    80. item.addEnchantment(glow , 1);
    81. }
    82.  
    83. }

    This should do the work.
     
  13. NonameSL So the glow effect controlled by addGlow(ItemStack, String) and EnchantGold();?
    I still cant understand how to remove it, isnt there a way to do it with packets maybe?
     
  14. Offline

    RawCode

    that method is result of noobish approach to solve issues, IMHO such coding samples not allowed to ever show on bukkit forum. NonameSL

    Glow added by:

    Code:
    	CraftItemStack tz = (CraftItemStack) tt.getPlayer().getItemInHand();
    	if (tz == null)return;
    	net.minecraft.server.v1_7_R1.ItemStack handle = (net.minecraft.server.v1_7_R1.ItemStack) UnsafeImpl.getObject(tz, "handle");
    	handle.setTag(new NBTTagCompound());
    	NBTTagList ttz = new NBTTagList();
    	ttz.add(new NBTTagCompound());
    	handle.tag.set("ench", ttz);
    
    with this code with a bit of skill you can make snippet to remove glow, lore or anything else.
     
  15. RawCode Thanks, but I still cant understand, Il have to set the tag to null? heres ItemPotion class, where do you see the code for making it glow? is it even in that class? also, after Im setting the ItemStack nbt tag to X, can I just give it to players? or Il need like to "update" the ItemStack?
     
  16. Offline

    RawCode

    what about pressing control+c and control+v and pasting code i posted into your testing plugin (if you have none - bad news for you)?
     
  17. RawCode Dude, Im aint looking for spoon-feed, Im trying to learn... copy paste isnt learning, I would like to know WHY is that remove the glow effect (if it is) and some other questions about NMS itemstack

    EDIT: Whats that? UnsafeImpl
     
  18. Offline

    RawCode

    if you not looking for spoon feeding, ok, i will explain.

    1) Items rendered client side.
    2) Render class can be reached with some help from MCP and from other sources, just google it.
    also you can just decompile minecraft and seek by hardcoded string constants.

    3) Render class will render any item with enchantment glow if it have NBT tag "ench" of type 10.

    4) About NBT types, refer NBTBase class and all classes that extend it, there are 16 types total.

    5) Networking and storage park skipped, game will handle it on it's own, most classes that alter enviroment have buildin packet senders, feel free to read entire class-method chain self to discover them.

    6) UnsafeImpl is my own wrapper of reflections\unsafe that allow set\get fields ignoring memory barriers.
     
  19. RawCode Thanks, amazing! :) and if an item have NBTtag of "ench" 10 it would glow, so if I were to make it 0 instead of 10, its wont glow ? how can I set the number?
     
  20. Offline

    RawCode

    4) About NBT types, refer NBTBase class and all classes that extend it, there are 16 types total.
     
  21. RawCode You just repeated what you said before didnt ya?... Im asking how would I set the number to not be 10, also, can you post your UnsafeImpl class?
     
  22. Offline

    Garris0n

    You can use this to do that with a copy, what he's doing is using reflection to grab this, which you could use if you had to modify the original stack.

    To find all the nbt classes, go here and type in "nbt". You can access that 'File Finder' page by hitting the "t" key on a github repo.
     
  23. Offline

    RawCode

  24. Offline

    MisterPhiloe

    How would you get it so that if an itemstack is in a slot then remove the glow effect from it?

    somebody?

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

    RawCode

    care to read thread?
    i already posted code sample.
     
  26. Offline

    MisterPhiloe

    I meant when Itemstack is equal to Material.BLOCK
     
  27. Sorry for bumping it, but its kinda poinless to make new theard on same thing... My code have been working for while but now its not, I have no idea why tho... also I still got few questions:
    Garris0n RawCode
    Code:java
    1. @EventHandler
    2. public void onTest(PlayerInteractEvent e){
    3. if(e.getAction() == Action.RIGHT_CLICK_BLOCK && e.getClickedBlock() != null && e.getClickedBlock().getType()
    4. == Material.DIAMOND_BLOCK && e.getPlayer().getItemInHand() != null){
    5. Player p = e.getPlayer();
    6. CraftItemStack cis = (CraftItemStack) p.getItemInHand();
    7. try{
    8. Field hf = CraftItemStack.class.getDeclaredField("handle");
    9. hf.setAccessible(true);
    10. net.minecraft.server.v1_7_R1.ItemStack handle = (net.minecraft.server.v1_7_R1.ItemStack)hf.get(cis);
    11. handle.setTag(new NBTTagCompound()); //why adding new NBTTagCompund?
    12. NBTTagList ntl = new NBTTagList();
    13. NBTTagCompound ntc = new NBTTagCompound();
    14. ntc.setInt("ench", 0); //@RawCode said that if the "ench" tag != 10, then its wont glow, its still glow with protection enchantment level 0...
    15. ntl.add(ntc);
    16. handle.tag.set("ench", ntl); //what is this?
    17. }catch(Exception exc){
    18. exc.printStackTrace();
    19. }
    20. }
    21. }
     
  28. Offline

    RawCode

    3) Render class will render any item with enchantment glow if it have NBT tag "ench" of type 10.
    4) About NBT types, refer NBTBase class and all classes that extend it, there are 16 types total.

    since you at least did some code, i will spoonfeed you

    handle.setTag(null);
     
Thread Status:
Not open for further replies.

Share This Page