HELP - How to override public static final method?

Discussion in 'Plugin Development' started by F4BSE, Feb 4, 2013.

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

    F4BSE

    I want to override the method

    Code:
    public static final Block stone = (new BlockStone(1, 1)).setHardness(1.5F).setResistance(10.0F).setStepSound(soundStoneFootstep).setBlockName("stone");
    I want to make a new class like

    public class DaughterClass extends ParentClass
    {
    new method
    }

    but how can I override the "public static final" method??

    Thanks for help :)
     
  2. Offline

    evilmidget38

    F4BSE That's a field, and you should be able to replace it with reflection. Although, if you can't differentiate a field from a method something like reflection is probably not for you.
     
  3. Offline

    RealDope

    evilmidget38
    Bit off-topic here, but I've never really had an understanding of reflection, from the looks of this, it would allow you to change hardness, resistance, step sound, and block name of a block? Pretty sure I'm not following correctly since I was almost positive these things could only be changed via a client mod.
     
  4. Offline

    evilmidget38

    RealDope Some things can be changed via reflection, and some can't. Hardness, IIRC, you can change on the server side, but it will look a bit weird to the player and/or may not work. Resistance(I'm assuming you're referring to its strength against TNT) can be changed server side, as whether or not blocks break is calculated server side then sent to the client*. As for the name of the block, you could change it. It wouldn't show up differently on the client due to how item naming is handled and translations(The server doesn't send the client an item name unless it's been renamed.), but it would most likely screw stuff up on the server. As for step sound, I'm not sure, but, I believe that the individual player's step sound wouldn't change, but it would for the players around them. Once again, I'm not sure on that, it's merely speculation.

    The main benefit is custom behaviors. You could easily prevent cactus blocks from harming people by using this, or make more blocks harm people using this. You could make blocks light people on fire, or all sorts of interesting things. You could also easily change block drops.

    Using reflection and extending an NMS class is far more commonly done with entities(although, you often don't need reflection). An example of this for a plugin I'm working on is allowing minecarts to pass through each other. I'm simply overriding the method for when entities collide(collide(Entity), IIRC).


    * The way it's handled: Explosion effect(the particles) is sent to the client at the specified location. Then the server sends the client block break packets.
     
Thread Status:
Not open for further replies.

Share This Page