AssertionError on world.getHandle().addEntity()

Discussion in 'Plugin Development' started by pkt, Jul 25, 2013.

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

    pkt

    I've made a couple custom entities before, but this is my first time doing a Projectile, and I get this weird error
    Code:
    2013-07-25 21:41:00 [SEVERE] Could not pass event PlayerInteractEvent to Plugin v1.0
    org.bukkit.event.EventException
        at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:427)
        at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.java:62)
        at org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.java:477)
        at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.java:462)
        at org.bukkit.craftbukkit.v1_6_R2.event.CraftEventFactory.callPlayerInteractEvent(CraftEventFactory.java:192)
        at org.bukkit.craftbukkit.v1_6_R2.event.CraftEventFactory.callPlayerInteractEvent(CraftEventFactory.java:162)
        at net.minecraft.server.v1_6_R2.PlayerConnection.a(PlayerConnection.java:610)
        at net.minecraft.server.v1_6_R2.Packet15Place.handle(SourceFile:58)
        at net.minecraft.server.v1_6_R2.NetworkManager.b(NetworkManager.java:296)
        at net.minecraft.server.v1_6_R2.PlayerConnection.e(PlayerConnection.java:118)
        at net.minecraft.server.v1_6_R2.ServerConnection.b(SourceFile:37)
        at net.minecraft.server.v1_6_R2.DedicatedServerConnection.b(SourceFile:30)
        at net.minecraft.server.v1_6_R2.MinecraftServer.t(MinecraftServer.java:590)
        at net.minecraft.server.v1_6_R2.DedicatedServer.t(DedicatedServer.java:226)
        at net.minecraft.server.v1_6_R2.MinecraftServer.s(MinecraftServer.java:486)
        at net.minecraft.server.v1_6_R2.MinecraftServer.run(MinecraftServer.java:419)
        at net.minecraft.server.v1_6_R2.ThreadServerApplication.run(SourceFile:582)
    Caused by: java.lang.AssertionError: class me.pkt77.plugin.entities.CustomSnowball
        at org.bukkit.craftbukkit.v1_6_R2.entity.CraftEntity.getEntity(CraftEntity.java:155)
        at net.minecraft.server.v1_6_R2.Entity.getBukkitEntity(Entity.java:1385)
        at net.minecraft.server.v1_6_R2.World.addEntity(World.java:926)
        at me.pkt77.minez.PlayerData.go(PlayerData.java:309)
        at me.pkt77.minez.PlayerData.interact(PlayerData.java:266)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
        at java.lang.reflect.Method.invoke(Unknown Source)
        at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:425)
        ... 16 more
    my code:
    Code:
            Location loc = player.getEyeLocation();
            Vector velocity = loc.getDirection();
            CraftWorld world = (CraftWorld) loc.getWorld();
            CustomSnowball snow = new CustomSnowball(world.getHandle());
            snow.setPositionRotation(loc.getX(), loc.getY(), loc.getZ(), loc.getPitch(), loc.getYaw());
            snow.shoot(velocity.getX(), velocity.getY(), velocity.getZ(), speed, spread);
            world.getHandle().addEntity(snow, SpawnReason.NATURAL); //error here
    Thats the same code I use for all my custom entities (except the shoot method for this projectile), so I don't see why this error is happening... :(

    CustomSnowball class:
    Code:
    public class CustomSnowball extends EntityProjectile {
     
        public CustomSnowball(World world) {
            super(world);
        }
     
        protected void a(MovingObjectPosition arg0) {
            for (int i = 0; i < 8; i++)
                this.world.addParticle("snowballpoof", this.locX, this.locY, this.locZ, 0.0D, 0.0D, 0.0D);
            if (!this.world.isStatic)
                die();
        }
     
        public void shoot(double d0, double d1, double d2, float f, float f1) {
            float f2 = MathHelper.sqrt(d0 * d0 + d1 * d1 + d2 * d2);
            d0 /= f2;
            d1 /= f2;
            d2 /= f2;
            d0 += random.nextGaussian() * (random.nextBoolean() ? -1 : 1) * 0.007499999832361937D * f1;
            d1 += random.nextGaussian() * (random.nextBoolean() ? -1 : 1) * 0.007499999832361937D * f1;
            d2 += random.nextGaussian() * (random.nextBoolean() ? -1 : 1) * 0.007499999832361937D * f1;
            d0 *= f;
            d1 *= f;
            d2 *= f;
            motX = d0;
            motY = d1;
            motZ = d2;
            float f3 = MathHelper.sqrt(d0 * d0 + d2 * d2);
            lastYaw = (yaw = (float) (Math.atan2(d0, d2) * 180.0D / 3.141592741012573D));
            lastPitch = (pitch = (float) (Math.atan2(d1, f3) * 180.0D / 3.141592741012573D));
        }
    }
     
  2. Offline

    Polaris29

    pkt What's in your CustomSnowball class? It could be because your CustomSnowball class doesn't somehow extend a net.minecraft.server entity
     
  3. Offline

    xTrollxDudex

    pkt
    That is way more complex than it needs to be if you just want to control a snowball
     
  4. Offline

    pkt

    what would you suggest then? I had to learn how to make custom entities myself, as the tutorials didn't work for me...

    added it above ^

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 3, 2016
  5. Offline

    xTrollxDudex

    pkt
    Javadocs. http://jd.bukkit.org/dev/apidocs/
    Also make sure to show Polaris29 your CustomSnowball class
    Otherwise
    PHP:
    Snowball sb = (Snowballplayer.getWorld().spawn(player.getEyeLocation(), Snowball.class);
    sb.setVelocity(player.getLocation().getDirection());
    That would shoot a snowball the direction the player is facing. To make it go faster add .multiply(int) after getDirection()
     
  6. Offline

    Polaris29

  7. Offline

    pkt

    Actually, velocity.multiply() is why I ended up making the custom snowball :/ , as it seems to make the projectile curve really fast about 3 seconds after its thrown... any suggestions?
     
  8. Offline

    xTrollxDudex

    pkt
    You can create your own vector. Or take what Polaris29 said, always be open for ideas/fixes
     
Thread Status:
Not open for further replies.

Share This Page