Cancel "breakage" of Rails on Piston Retract

Discussion in 'Plugin Development' started by Don Redhorse, Jan 8, 2012.

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

    Don Redhorse

    Hi,

    it's getting late and I can't figure it out..

    I want to keep the rails connected to blocks on piston retract.

    @md_5 already said to use onBlockPhysics

    I already tried that before but it didn't work.

    So does anybody have an idea how to make it work?

    Either by cancelling the event or by a workaround.

    I already tried cancelling the itemspawn and putting the rails back in place but there is a race condition and that doesn't work..

    @bergerkiller any idea?
     
  2. Offline

    bergerkiller

    I also have an old thread hanging around requesting for a method to retract/extend a piston, but no replies were ever made. I then worked around with a lot of packets and block data changing, all to no avail. The internal physics event quickly takes over control and resets it again.

    In your case, maybe a scheduled task would work? Right before it retracts, you calculate the expected location for the rail and change that block to that rail, all one/0 ticks delayed.
     
  3. Offline

    Don Redhorse

    hmm... what I can do is block the physics which move the track down (later on perhaps even right or left).

    So I could than switch that block to air and also switch the block on top of the piston block to rail again (which is air in that case).

    that would be a major "hack" though.

    Cancelling the "breakage" would be by far better.

    So question is is there such an event? Or where is he hiding..

    oh and bedankt @bergerkiller
     
  4. Offline

    Chiller

  5. I tested using rails and sticky pistons to move rails sideways, they work ok but they only break when you place the piston up-right and rails on top of that block and retract the piston... it makes sense the rails pop off because the rails aren't beeing drawn back along with the block, you need to cancel the physics event and re-place the rails.

    That unless you're doing something else...
     
  6. Offline

    Don Redhorse

    I already tried of of that... hmm..

    Code:
    if (event.getType() == Type.BLOCK_PHYSICS && checkIfRail(event.getBlock())){
                    event.setCancelled(true);
                    rarpLogger.debug("cancelling blockphysics");
                }
    this will keep the tracks but they will hover in air aka not be pulled down .. :-(

    yeah I think I will need to do that... so when you pull them sideways the keep on the blocks?

    good to know so I don't have to code for that.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 23, 2016
  7. Yes, moving rails sideways work amazingly well as long as the block they're moved on is a valid placeable one (not air, signs, plants, etc).

    Hmm, you could also allow rails to be placed directly on pistons, that way I *think* you can move them up/down just fine, never tried it tough... however, there's always the thing with slope connected rails, those could also pop.
     
  8. Offline

    Don Redhorse

    well that is the next point.. I guess I will cancel, set to air, set to rail, and than I only have to implement one minor think I'm done...

    just wondered if there was a nicer way... off to create "bug" for it..

    aaarrrggghhhhhh.... ok... I cancel the blockPhysics event and than I get a nice line of rails in the air... I kill the rails, and put the rails back in one block lower...

    with the effect that the rails don't stick on the floor.. only every second one... looks like there is an issue with other physics events when I replace the rails.

    so perhaps this would work if I set the rails back with a timer, but how do I do that.

    @bergerkiller do you have an idea?

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

    bergerkiller

    @Don Redhorse note that, whenever you a block changes, it performs physics in all directions (north/east/south/west/up/down). So, you also need to cancel any physics on blocks attached to the rail.
     
  10. Offline

    Don Redhorse

    hmm... can do that... so I get 6 events per block... so I need to get a HashMap<Location, Hashmap<Material, Integer>> to store the Location, the Material (rail, detector etc) and the number 6 and than deduct those events..
    or I use 2 HashMaps with Location,Material and Location,Integer... any better idea? stupid noob programers :-/ (<= me)

    argh wait. so I have to cancel physics at x +1, x -1, y +1 , y -1, z +1 and z -1 plus my x,y,z or?

    but I only need to cancel those if they are triggered because of my x,y,z block, so I can not blankly cancel them.
    arrgh...

    ok, to late for me atm... and I can't get my head around it atm.. I would really appreciate some help..

    so is the above correct?

    any Idea who I can figure out the events I need to cancel?

    what doesn't work atm is placing the rails on the pistons again...

    btw; the above mentioned code is only done after comparing the location where the rail is

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

    bergerkiller

    @Don Redhorse I got a very simple alternative for you. Simply suppress block physics right before the piston event and allow them again afterwards. (not sure when this afterwards is, because it suppresses physics on the entire world)

    Code:
    ((CraftWorld) event.getWorld()).getHandle().suppressPhysics = true;
     
  12. Offline

    Don Redhorse

    well I don't know the piston event, or do you mean when I get the triggered event?

    I could try that... well I released the module without the full feature set :-(

    and I wanted to make the RedSeaEffekt really cool :-(
     
  13. Offline

    Don Redhorse

    ok... still need help with this... I pushed the plugin out without the piston effekt, but I really would like to implement it.

    does anybody has an idea?

    Otherwise I will try to log all physics events and will try to block them one by one to see what it is

    I will also try @bergerkiller idea but I doubt this will work.. and I will try the idea of a sync thread to place the rails but stil...
     
  14. Offline

    xGhOsTkiLLeRx

    Don Redhorse
    Sorry for pushing this thread, but could you solve this problem?
    I need a solution, too...
     
  15. Offline

    Don Redhorse

    nope... you need it for blocksonglass ? I hoped you had it fixed.

    I couldn't get my had around it, it is too high for me atm.. I dropped the idea.. to look at it again later.

    I also created a leaky issue for it but the team said they wouldn't change how minecraft works... what I wanted was a way to cancel the rail detachment
     
  16. Offline

    xGhOsTkiLLeRx

    I could use it in BlocksOnGlass, primarily I need it for my server ;)
    Sad you have no solution, maybe I'll look into it. (Or directly modify the minecraft code...)
     
  17. Offline

    Don Redhorse

    well I wanted it for my Redstone And Rail Protection... I already put one block of air on top of the rails if configured... with pistons working (retract as push works)... it would have been totally cool..

    pistons + block + rail 3 blocks beneath water level.... triggered... save drive through a sea or similar..

    sigh... pistons are crappy supported atm... just figured out that there isn't even a real api for them, you can't extend or retract them via code for example.
     
Thread Status:
Not open for further replies.

Share This Page