A whole bunch of questions regarding vehicles

Discussion in 'Plugin Development' started by Butkicker12, Sep 5, 2011.

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

    Butkicker12

    Question 1: Is it possible to have powered rails be powered without detector rail or torch?
    Question 2: Can I make a command eg. /faster and it increases the minecrafts velocity in intervals
    Question 3: With the event VEHICLE_COLLISION_BLOCK and VEHICLE_COLLISION_ENTITY, how do I eject a player. I tried getPassenger.
     
  2. Offline

    bergerkiller

    1. Probably not, requires native code editing, which requires replacing blocks to custom types, which means custom Material ID list, which is not possible. :)

    2. Very hard but possible, if you handle all velocity changes somehow. If you meant Minecart there, replace the class and edit or handle onVehicleMove.

    3. entity.eject(); exists for vehicles I believe. :)
     
  3. Offline

    Shamebot

    Might even be not that hard. Replacing the block in the minecraft.server block array might do the job.
     
  4. Offline

    bergerkiller

    But will the client 'interpret' the new block ID being sent over? That is kinda the issue...

    With entities it will simply use instanceof and interprets it as being an EntityMinecart, but I am not sure about blocks in that matter... (or you send an existing ID over, but is this possible, since chunks of blocks are sent and not individual packages for each block)
     
  5. You won't need a new block ID since you don't create a new block. You would just override the redstone check thingy and pretend the rail would be powered. The server should do the rest for you.
    The client only needs to know that the rail is powered.

    Actually, powered rails have a data flag to show they are powered. So setting that without a block update should also be possible without any nasty native code replacements.
    You would just need to handle block updates ...
     
  6. Offline

    bergerkiller

    If it's so easy, then how can you replace the block? The server only stores the ID and a byte worth of data for each block, and optionally extra data (tileentities). You will need a different ID of some sort so the server won't react to it as a regular powered rail...so yeah. :)
     
  7. The idea that @Shamebot suggested was to replace the referenced block for powered rails in net.minecraft.server.Block with a custom modification.
    So everytime the server does something with a powered rail in your world, it will find your custom Block class instead of BlockRail in the field net.minecraft.server.Block.railPowered - -with its own treatment of powering.
     
  8. Offline

    bergerkiller

    Aaah yeah that makes sense, I did know things were stored there but I tend to overlook things now and then, thanks for clearing things up. :)
     
  9. Offline

    Shamebot

    Yes. BUT it turned out, that, unless the server is run with Java 1.2, we're not allowed to set static final fields (if that didn't change with 6 or 7).
    Edit:
    http://www.javaspecialists.eu/archive/Issue096.html
     
  10. Offline

    bergerkiller

    Yep they are final...but in the end everything is hackable. If required you could even inject custom code into memory, but that would probably be a liiiittlee too much work and a little dangerous too. :)
     
  11. Offline

    Shamebot

  12. Offline

    bergerkiller

    Now a way to replace actual class files and you could basically mod Bukkit. :)
     
  13. Offline

    Butkicker12

    Im starting to think this is a bit out of my experience. :/
     
  14. Actually, that whole final-hacking replacing thingy thing isn't even necessairy if you want your powered rail stuff pretty basic. Just set the data flag for the rail to turn it on:
    http://www.minecraftwiki.net/wiki/Data_values#Rails

    @Shamebot
    With the magic of reflect, everything seems possible :D
     
  15. Offline

    Shamebot

    I hope that works, when you set the redstonewire data it just goes out instantly.
     
  16. I guess bukkit's API is not enough for that (BLOCK_PHYSICS might do, I don't know), so you probably still need to hook CraftBukkit and net.minecraft.server classes.
     
  17. Offline

    Celeixen

    You realise minecart mania does all of what you just said, You could just looks at its source code. No forking.. rofl
     
  18. Offline

    bergerkiller

    There's a difference between entity replacement and block replacement. Yes, you can add modifiers to the minecart velocity to keep it running, but that's too easy. If you want ACTUAL block changes, in other words, see a lit powered rail, you will need some way to inject code into the block physics code. However, there is an onBlockPhysics event, so by cancelling it you may be able to prevent the rail from changing back. (?)

    It worked for portals, not sure about rails.
     
  19. Offline

    Butkicker12

    That would be stealing.
     
  20. Offline

    Celeixen

    I didnt mean copy it i just meant to see how they did it. Its not much better then someone else supplying you code here.
     
  21. Offline

    Butkicker12

    That makes sense. Ill go wade though all those class. Let then fun begin!
     
  22. Offline

    Butkicker12

    Back to this question again, I want to eject a player when there minecart colides with a block.
    I have this,

    public void
    onVehicleBlockCollision(VehicleBlockCollisionEvent event){ if(event.getBlock()instanceof
    Entity){
    Entity passenger = event.getVehicle().getPassenger();

    //Vehicle v = event.getVehicle();
    passenger.eject();
    }
    What am I doing wrong?
     
  23. Offline

    Celeixen

    Don't you want event.getblock().getType() == whatever block you want it to break on.
    Also try send the player a message just to mak sure it is getting the impact event.
     
  24. Offline

    Shamebot

     
  25. Offline

    Butkicker12

    What is that supposed to mean?
     
  26. Offline

    Taco

    A block is not an entity. A vehicle, however, is an entity.
     
  27. Offline

    Butkicker12

    That means I should change it to getEntity()
     
  28. Offline

    Taco

    You should check event.getVehicle() for the vehicle you want.

    Ex:

    if(event.getVehicle() instanceof Boat)
     
  29. Offline

    Butkicker12

    if(event.getVehicle( instanceof Boat)
    But if your dealing with minecarts its
    if(event.getVehicle( instanceof Minecart)
    Right?
     
  30. Offline

    Taco

    Correct.
     
    Butkicker12 likes this.
Thread Status:
Not open for further replies.

Share This Page