[Fixed/Close] Needing help with "performing physics"

Discussion in 'Plugin Development' started by feildmaster, Aug 8, 2011.

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

    feildmaster

    Alright, I have been discussing this with DinnerBone for a while, but I am going to look for a general discussion about this problem I am having:

    The problem is with QuantumConnectors, a player confronted it to me, that levers powered wireless-ly don't toggle Redstone Torches.
    [​IMG]

    Dinnerbone went and told me to "Perform Physics," so I call the following:
    Code:
    block.getState().update();
    Now, this lovely update "does" work. it just takes... oh... minutes (randomly between 20-200 seconds) to update.

    Want to discuss how I can make it faster? :)
     
  2. Offline

    Shay Williams

  3. Offline

    Shamebot

  4. Offline

    nisovin

    I flip switches like this (where block is the lever block):
    Code:
    net.minecraft.server.Block.LEVER.interact(((CraftWorld)block.getWorld()).getHandle(), block.getX(), block.getY(), block.getZ(), null);
    Unfortunately, I've never found a way to do this just using the Bukkit API.
     
  5. Offline

    feildmaster

    Yes, that would produce the same thing though. =P

    Guess I'll have to try that then... though that's a tad annoying.

    So, I tried "interact." It does indeed switch the lever, while updating physics correctly.

    The only thing is, it wont work for the plugin without extensive extra checks.
    Another thing:
    Code:
    net.minecraft.server.Block.LEVER.doPhysics(((CraftWorld)block.getWorld()).getHandle(), block.getX(), block.getY(), block.getZ(), (any int here));
    Doesn't seem to do much of anything either. :)

    @Dinnerbone : Want to join in on this public discussion? :)

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

    nisovin

    What kind of extensive checks are you talking about here? Also, you'd need to run doPhysics on the block the lever is attached to, not the lever itself.
     
  7. Offline

    feildmaster

    Extensive checks: I'd have to treat levers as a special case, as it would just "toggle" what the current output is. So if I tried "quantum" (sets to current power) with my plugin... it'd "toggle." or if i wanted it to "always turn off" it'd.. still "toggle". There's a lot of different circuits I'd have to check for.. :(


    Oh, I didn't think of that. Lets see what happens... :D
     
  8. Offline

    nisovin

    Actually, looks like you'd probably want to run applyPhysics() to the block, not doPhysics(). Here's the source of the interact function:
    https://github.com/Bukkit/mc-dev/blob/master/net/minecraft/server/BlockLever.java#L131
    It runs applyPhysics() for both the lever block itself and for the block it is attached to.
     
  9. Offline

    feildmaster

  10. Offline

    nisovin

    They are. It's on World, not Block.
     
  11. Offline

    feildmaster

    @nisovin : You try using it.
    block.getWorld().apply... Oh wait, it starts with "createExplosion()"
     
  12. Offline

    nisovin

    It's a CraftBukkit method, like the other one. Those are a bit harder to access.
    Code:
    ((net.minecraft.server.World)block.getWorld()).applyPhysics()
     
  13. Offline

    feildmaster

    ahh... Haven't I tried that already?

    Let me double check here...

    Edit: @nisovin : What should I use for the 4th int? "this.id"... Don't know what to use there.

    Oh this is rediculous. I got to the point where I was almost mimic-ing the interact code (which works):

    Code:
    net.minecraft.server.World w = ((net.minecraft.server.World)((CraftWorld)block.getWorld()).getHandle());
    Location l = block.getLocation();
    w.setData((int)l.getX(), (int)l.getY(), (int)l.getZ(), iData);
    w.b((int)l.getX(), (int)l.getY(), (int)l.getZ(), (int)l.getX(), (int)l.getY(), (int)l.getZ());
    w.applyPhysics((int)l.getX(), (int)l.getY(), (int)l.getZ(), 0);
    YET somehow this doesn't work.

    I'm going to assume it's the "0" I have under applyPhysics. But I don't know what ID to give it. What number is supposed to go there? No clue.

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

    nisovin

    I believe it's the block id. For a lever that would be 69.
     
  15. Offline

    feildmaster

    It's gotten faster, but it's not as instant as setting "interact."
     
  16. Offline

    nisovin

    You need to run applyPhysics() on both the lever block and the block the lever is attached to.
     
  17. Offline

    feildmaster

    ohh... geez. alright.
     
  18. Just drop the project and move to California :3
     
  19. Offline

    feildmaster

Thread Status:
Not open for further replies.

Share This Page