Stopping boats from breaking by block damage

Discussion in 'Plugin Development' started by Purre, Feb 11, 2011.

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

    Purre

    Hi, I'm trying to stop a boat to be damaged by a block, is that possible? I've looked at the source files and it seems like the event just passes but no special damage is done just because it's a boat. There is no cancellation possible, and VehicleBlockCollisionEvent seems to be the only one called there that has to do with this. Is there anything I can do to stop the damage from beeing dealt?
     
  2. Offline

    Plague

    There is a plugin that deals with breaking boats, just learn from the code, PickBoat.
     
  3. Offline

    Purre

    Thanks :)
    That was not the thing I really was looking for, but by searching for the stick and wood dropping in the source file, I got around to use the variables which could determinate and stop the boat from breaking.
     
  4. Offline

    Plague

    Yes, that was actually what I was pushing you to do :D
     
  5. Offline

    XXLPaprika

    Could someone explain me how to do this?

    I'm not a coder or something so a jar would be nice! ;)
     
  6. Offline

    Purre

    I did it like this (Note that this will only stop boat to block breaking, not boat to entity):
    Code:
    import org.bukkit.event.vehicle.VehicleListener;
    import org.bukkit.event.vehicle.VehicleBlockCollisionEvent;
    import net.minecraft.server.EntityBoat;
    import org.bukkit.craftbukkit.entity.CraftBoat;
    import org.bukkit.entity.Boat;
    
    //<Some other code here>
    
        @Override
        public void onVehicleBlockCollision(VehicleBlockCollisionEvent event) {
            if (!(event.getVehicle() instanceof Boat)) return;
    
            CraftBoat cb = (CraftBoat) event.getVehicle();
            EntityBoat eb = (EntityBoat) cb.getHandle();
    
            double d5 = Math.sqrt(eb.motX * eb.motX + eb.motZ * eb.motZ);
    
            if (eb.B == true && d5 > 0.15D) { //Boat breaks!
                //Stop from breaking
                eb.motX = 0.00D;
                eb.motY = 0.00D;
            }
        }
    It works the way that the original breaking is made if eb.b == true and d5 > 0.15D, this is taken directly from the source code. We check if it will break (as this event is called before the actual breakage), if it will break we go on. To stop the breaking from happening we set motX and motZ (motion velocity) to 0. This is using classes from Craftbukkit, so make sure to add it as a dependency.
     
  7. Offline

    Nohup

    So are you saying EntityDamageByBlockEvent does not fire on this? Just curious since that would seem like the perfect place. That would fall under onEntityDamage and then have to be cast, but that would have been my first place to assume to catch this.
     
  8. Offline

    Purre

    Oh, it's using the old structure for EntityDamaged, it's a little outdated.. [​IMG]
     
Thread Status:
Not open for further replies.

Share This Page