[1.8] Override Block - Did the update ruin it? {Can I be moved back?}

Discussion in 'Plugin Help/Development/Requests' started by Dudemister1999, Jan 26, 2015.

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

    Dudemister1999

    Hello! This issue has been bothering me for a long, long time. I'm attempting to override a block (In both Block.REGISTRY & Blocks.class), and it just isn't working. Here is my code:

    The Block (NewTNT):
    Show Spoiler

    Formatting gets awry when posted, here's the [Pastebin]


    The Registering code (It is firing, I checked):
    Show Spoiler

    Formatting gets awry when posted, here's the [Pastebin]



    The code is outputting this:
    Code:
    Blocks class:
    com.themcwar.block.NewTNT@1f01a0ff
    Block Registry:
    com.themcwar.block.NewTNT@1f01a0ff
    
    So it is in fact working. It just will not override the behavior.
     
    Last edited: Jan 26, 2015
  2. Offline

    _Filip

    It doesn't work because you're using allman style, use the proper java conventions then post it here and it may start working.
     
  3. Offline

    ColonelHedgehog

    There's nothing wrong with Allman style. In fact, as long as your style parses, you can use it. You could write almost everything on one line and it wouldn't affect the code's performance. CSS users actually do that to make the file faster to download/load.
     
  4. Offline

    mythbusterma

    @ColonelHedgehog

    He was joking. Nobody uses Allman style for Java because it's not how Java is written. He also didn't indent at all, which is another thing he was poking fun at.


    @Dudemister1999

    That looks like it's working to me...?
     
  5. Offline

    ColonelHedgehog

    That joke was so dry that it was confusing. I simply provided the water.

    *badum tss*

    I use Allman style for Java. I find it's easier to read and I'm used to it. However, indentations shouldn't vary from style to style. Not using them makes it hard to read.
     
  6. Offline

    _Filip

    @ColonelHedgehog
    I have a simple method to determine your skill in coding java.

    Code:
    int getSkill(Code code) {
        return code.usesAllmanStyle() ? 0 : code.getCodingSkill();
    }
    Edit:
    Here's the code rewritten to make it easier for someone like you to read.
    Code:
    int getSkill(Code code)
     {
        return code.usesAllmanStyle() ? 0 : code.getCodingSkill();
    }
     
    Skionz likes this.
  7. Offline

    ColonelHedgehog

    Am I supposed to be insulted? You took the most simple block of code imaginable to try to disprove the benefits of Allman. Very immature.

    It's a preference, not a method. I use Allman because that's what I like to use. However, it says nothing about my code skill. Does the writer of a book deserve to be ridiculed because he prefers to put periods outside of quotes rather than inside of them? No, that's a style and it's grammatically correct so long as he consistently uses this style with all sentence punctuation. In the same way, you shouldn't criticize people on their skill level based on whether or not they decide to place their {s on a new line or on the same line of an if, try/catch, method or class declaration.

    In the manner that a person's book can be judged by its actual contents and story, a person's skill level can, however, be determined by the contents of the code.

    Example. In a novel, this:

    Is equally as bad as:

    In a similar way,

    Code:
    public List<Toast> makeToast()
    {
        List<Toast> toastList = new ArrayList<>();
       Toast1 = new Toast();
       Toast2 = new Toast();
       Toast3 = new Toast();
       Toast4 = new Toast();
       Toast5 = new Toast();
    
        toastList.add(toast1);
        toastList.add(toast2);
        toastList.add(toast3);
        toastList.add(toast4);
        toastList.add(toast5);
    
    }
    
    ...Is equally as bad as:

    Code:
    public List<Toast> makeToast() {
        List<Toast> toastList = new ArrayList<>();
       Toast1 = new Toast();
       Toast2 = new Toast();
       Toast3 = new Toast();
       Toast4 = new Toast();
       Toast5 = new Toast();
    
        toastList.add(toast1);
        toastList.add(toast2);
        toastList.add(toast3);
        toastList.add(toast4);
        toastList.add(toast5);
    
    }
    
    And for your information, writing a fake method that uses other fake methods to convey an opinionated statement doesn't make it any more correct.
     
  8. Offline

    _Filip

    public k ok() {
    return thank you for your input, i greatly value your opinion;
    }
     
  9. Offline

    ColonelHedgehog

    Syntax error: could not resolve symbol "k." ;)
     
    Konato_K likes this.
  10. Offline

    Dudemister1999

    @ColonelHedgehog @_Filip
    Editing the post ruined the formatting, I apologize.

    @mythbusterma
    It is not. I could provide a .gif, if I knew how to create one. >.>

    {Edit 1}
    Oh dear, it appears the Bukkit forums hate me. The formatting gets ruined no matter what I do.

    Anyways, here's the code, formatted, in Pastebin:

    NewTNT: [Click]
    BlockManager: [Click]

    @_Filip

    And to be perfectly honest, I do not appreciate the sarcasm. I am sorry I do not conform to your specific methods of programming, but I happen to do things my way quite effectively. Yes, the format is a bit awry, but that is from editing my post three times. I will update it (To my specifications, I might add) now. Sorry for the inconvenience.

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

    mythbusterma

    @Dudemister1999

    Non-Java formatting aside, I don't see the issue. It looks like (based on the output above) that TNT now refers to the block you created instead.

    Is that not the case? Did I read something wrong?
     
  12. Offline

    Dudemister1999

    @mythbusterma
    It does, but the original TNT code still fires (It creates a PrimedTNT entity)
     
  13. Offline

    mythbusterma

    @Dudemister1999

    I'd recommend examining the source code of whatever you're using for a server, I'm assuming since you said 1.8 you mean Spigot?
     
  14. Offline

    Dudemister1999

    @mythbusterma No, Bukkit 1.8.

    The Jar's POM (In the META-INF)

    #Generated by Maven
    #Fri Nov 28 05:16:22 EST 2014
    version=1.8-R0.1-SNAPSHOT
    groupId=org.bukkit
    artifactId=bukkit

    EDIT: I know it's bukkit because it has Wolvereness' CraftBukkit code inside.
     
  15. Offline

    ColonelHedgehog

    Er, not really. Spigot forked "Bukkit" and updated it to 1.8. They also did the same to Craftbukkit, but they jumped through some hoops to avoid the DMCA
     
  16. Offline

    Dudemister1999

    @ColonelHedgehog That's interesting. I did not know that! I wonder if this jar is Spigot or Bukkit, then. Either way, the issue works in 1.7.10, but not in 1.8.
     
  17. Offline

    ColonelHedgehog

    Spigot rewrote many class files, yes. At any rate, I suggest you post this on their forums.
     
  18. Offline

    Duckdoom5

    For anyone still interested in this. I found a way to do it:


    Code:
    private void reg() {
      Block.REGISTRY.a(49, new MinecraftKey("obsidian"), new MeltingObsidianBlock());//Update block register
    
      setFinalStatic(Blocks.class, "OBSIDIAN", Block.REGISTRY.get(new MinecraftKey("obsidian"))); //Update block reference
    
      int i = Block.REGISTRY.b(Blocks.OBSIDIAN) << 4 | Blocks.OBSIDIAN.toLegacyData(Blocks.OBSIDIAN.getBlockData());
      Block.d.a(Blocks.OBSIDIAN.getBlockData(), i); //Update correct key
    
      invokeMethod(Item.class, "c", new Class[]{Block.class} , Blocks.OBSIDIAN); //Update item register
    }
    
    private void invokeMethod(Class clazz, String methodName, Class[] parameters, Object... args) {
      try {
          @SuppressWarnings ("unchecked")
          Method method = clazz.getDeclaredMethod(methodName, parameters);
          method.setAccessible(true);
          method.invoke(null, args);
      } catch (NoSuchMethodException | SecurityException | IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
          e.printStackTrace();
      }
    }
    
    private void setFinalStatic(Class clazz, String fieldName, Object newValue) {
      try {
          Field field = clazz.getDeclaredField(fieldName);
          field.setAccessible(true);
          Field modifiers = field.getClass().getDeclaredField("modifiers");
          modifiers.setAccessible(true);
          modifiers.setInt(field, field.getModifiers() & ~Modifier.FINAL);
          field.set(null, newValue);
      } catch (NoSuchFieldException | SecurityException | IllegalArgumentException | IllegalAccessException ex) {
          ex.printStackTrace(System.err);
      }
    }
    
    
     
    Last edited: Mar 17, 2015
    leimekiller likes this.
  19. Offline

    nverdier

    ColonelHedgehog likes this.
Thread Status:
Not open for further replies.

Share This Page