Custom Entity Passenger/Vehicle issues

Discussion in 'Plugin Development' started by kennethbgoodin, Apr 27, 2014.

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

    kennethbgoodin

    I've got a CustomBat class that extends EntityBat, and can be spawned in the world, manipulated, etc. It works fine, I can override its movement (one of my original goals) without any problems, all that, except for one thing; I can't set anything as a passenger of it. When I try it with the player, it bugs and teleports the player to the origin, and with other entites, it creates a "ghost" entity that persists after I clear all entities, and will continue to stay there until I reload the server. The ghost entity can be hit once, but then becomes impossible to interact with.

    I've tried various things to get the passenger aspect of my entity working, but to no avail. I know there's something I'm doing wrong, because the regular bats can be used as a vehicle without any problems. If someone could point me in the right direction, that would be fantastic.

    Thanks.

    CustomBat:
    Code:
    package com.minigamepalooza.ss.entities;
     
    import net.minecraft.server.v1_7_R2.EntityBat;
    import net.minecraft.server.v1_7_R2.World;
     
    import org.bukkit.Location;
    import org.bukkit.craftbukkit.v1_7_R2.CraftWorld;
    import org.bukkit.craftbukkit.v1_7_R2.entity.CraftEntity;
    import org.bukkit.entity.Entity;
     
    public class CustomBat extends EntityBat {
     
    public CustomBat(World world) {
    super(world);
     
    }
     
    @Override
    public void move(double a, double b, double c) {}
     
    public void spawnCustomEntity(Location loc) {
    net.minecraft.server.v1_7_R2.World nmsWorld = ((CraftWorld) loc.getWorld()).getHandle();
    CustomBat bat = new CustomBat(nmsWorld);
    bat.setPosition(loc.getX(), loc.getY(), loc.getZ());
    nmsWorld.addEntity(bat);
    }
     
    public boolean setPassenger(Entity passenger) {
    if (passenger instanceof CraftEntity) {
    ((CraftEntity)passenger).getHandle().setPassengerOf(this);
    return true;
    }
    return false;
    }
     
     
    public boolean teleport(Location loc) {
    this.setLocation(loc.getX(), loc.getY(), loc.getZ(), loc.getYaw(), loc.getPitch());
    return false;
    }
     
    }
    
     
  2. I may not be an expert with custom entities, but why have the setPassenger feature when it extends EntityBat?
    Would you not just spawn the bat in, then use the BukkitAPI method of setting the passenger (with an entity) since EntityBat is an Entity.
     
    ImPhantom likes this.
  3. Offline

    kennethbgoodin

    You can't use the Bukkit method, because the Bukkit method is in the Bukkit Entity class, not the NMS Entity class: http://prntscr.com/3eekpg

    Bukkit and NMS classes don't extend each other. But it's irrelevant, because I am using the same code as the Bukkit method; the Bukkit method just makes a call to setPassengerOf(), which is what I've done.
     
  4. Offline

    TeeePeee

    kennethbgoodin
    Don't forget you can use Bukkit API calls by getting the Bukkit entity of the custom one. See the following.

    Code:java
    1. public boolean setPassengerSafely(net.minecraft.server.v1_7_R2.Entity passenger) {
    2. return getBukkitEntity().setPassenger(passenger.getBukkitEntity());
    3. }


    Bukkit should deal with it properly. If not, tag me and let me know.
     
    MrStrauss and Garris0n like this.
  5. Offline

    ZeusAllMighty11

    Watched the livestream of you coding this, and I decided to test out bats myself. I also have the same issue.

    Even just removing the bat's random flying causes them to become desynced with the server after a single action, for example hitting it. It will just fold it's wings and sit there, sometimes falls through the block it was hovering upon, and can't be killed naturally


    Might be a bug with bats
     
  6. Offline

    kennethbgoodin

    TeeePeee
    Nope, didn't work. I believe I've tried using Bukkit's setPassenger with getBukkitEntity() before. Same bugged sheep with the bat flying around (if its move method isn't overriden).
    Printing the bat's passenger to the console does return CraftSheep, so it is being set properly.

    ZeusAllMighty11 You were in the stream? That's awesome!
    Back to the topic; my bats don't seem to exhibit that behavior, they act like normal bats.

    Edit: Adding a 40 tick delay and then setting the sheep as the passenger of the bat makes it act very strangely; the sheep gets teleported to the origin.
     
  7. Offline

    kennethbgoodin

    It's been a few days, so I'm gonna bump this. I've tried the steps listed in this thread, and several others, and still not getting anywhere.

    TeeePeee
     
  8. Offline

    TeeePeee

    kennethbgoodin
    As ZeusAllMighty11 mentioned, it very well may be a bug with bats. They're not exactly creatures that tend to have living passengers and giving the bat custom movement may make it buggy. Make sure you have a call to the super move method, but other than that, I'm not sure what the problem could be.
     
  9. Offline

    kennethbgoodin

    TeeePeee The movement's not the issue, because it persists whether I override it or not (and I'm not doing anything when I override it, just overriding so the super doesn't run.

    Thanks for your help though, I'll look into other methods of accomplishing my goal.
     
Thread Status:
Not open for further replies.

Share This Page