Making a ghast shoot a custom fireball

Discussion in 'Plugin Development' started by nuno1212sss, Mar 7, 2015.

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

    nuno1212sss

    How can I make a ghast shoot a custom fireball that I made, I am willing to use NMS and I tried to make a class, I came up with this:
    Code:
    public class CGhast extends EntityGhast {
    public CGhast(World w){
    super(w);
    }
    Entity target;
    int explosionPower = 1;
    int br = 0;
    protected void bq()
    {
    if ((!this.world.isStatic) && (this.world.difficulty == EnumDifficulty.PEACEFUL)) {
    die();
    }
    w();
    this.bo = this.bp;
    double d0 = this.i - this.locX;
    double d1 = this.bm - this.locY;
    double d2 = this.bn - this.locZ;
    double d3 = d0 * d0 + d1 * d1 + d2 * d2;
    if ((d3 < 1.0D) || (d3 > 3600.0D))
    {
    this.i = (this.locX + (this.random.nextFloat() * 2.0F - 1.0F) * 16.0F);
    this.bm = (this.locY + (this.random.nextFloat() * 2.0F - 1.0F) * 16.0F);
    this.bn = (this.locZ + (this.random.nextFloat() * 2.0F - 1.0F) * 16.0F);
    }
    if (this.h-- <= 0)
    {
    this.h += this.random.nextInt(5) + 2;
    d3 = MathHelper.sqrt(d3);
    if (a(this.i, this.bm, this.bn, d3))
    {
    this.motX += d0 / d3 * 0.1D;
    this.motY += d1 / d3 * 0.1D;
    this.motZ += d2 / d3 * 0.1D;
    }
    else{
    this.i = this.locX;
    this.bm = this.locY;
    this.bn = this.locZ;
    }
    }
    if ((this.target != null) && (this.target.dead))
    {
    EntityTargetEvent event = new EntityTargetEvent(getBukkitEntity(), null, EntityTargetEvent.TargetReason.TARGET_DIED);
    this.world.getServer().getPluginManager().callEvent(event);
    if (!event.isCancelled()) {
    if (event.getTarget() == null) {
    this.target = null;
    } else {
    this.target = ((CraftEntity)event.getTarget()).getHandle();
    }
    }
    }
    if ((this.target == null) || (this.br-- <= 0))
    {
    Entity target = this.world.findNearbyVulnerablePlayer(this, 100.0D);
    if (target != null)
    {
    EntityTargetEvent event = new EntityTargetEvent(getBukkitEntity(), target.getBukkitEntity(), EntityTargetEvent.TargetReason.CLOSEST_PLAYER);
    this.world.getServer().getPluginManager().callEvent(event);
    if (!event.isCancelled()) {
    if (event.getTarget() == null) {
    this.target = null;
    } else {
    this.target = ((CraftEntity)event.getTarget()).getHandle();
    }
    }
    }
    if (this.target != null) {
    this.br = 20;
    }
    }
    double d4 = 64.0D;
    if ((this.target != null) && (this.target.f(this) < d4 * d4))
    {
    double d5 = this.target.locX - this.locX;
    double d6 = this.target.boundingBox.b + this.target.length / 2.0F - (this.locY + this.length / 2.0F);
    double d7 = this.target.locZ - this.locZ;
    
    this.aM = (this.yaw = -(float)Math.atan2(d5, d7) * 180.0F / 3.1415927F);
    if (hasLineOfSight(this.target))
    {
    if (this.bp == 10) {
    this.world.a((EntityHuman)null, 1007, (int)this.locX, (int)this.locY, (int)this.locZ, 0);
    }
    this.bp += 1;
    if (this.bp == 20)
    {
    this.world.a((EntityHuman)null, 1008, (int)this.locX, (int)this.locY, (int)this.locZ, 0);
    //CHANGED HERE
    CFireball entitylargefireball = new CFireball(this.world);
    
    
    entitylargefireball.bukkitYield = (entitylargefireball.yield = this.explosionPower);
    double d8 = 4.0D;
    Vec3D vec3d = j(1.0F);
    
    entitylargefireball.locX = (this.locX + vec3d.a * d8);
    entitylargefireball.locY = (this.locY + this.length / 2.0F + 0.5D);
    entitylargefireball.locZ = (this.locZ + vec3d.c * d8);
    this.world.addEntity(entitylargefireball);
    this.bp = -40;
    }
    }
    else if (this.bp > 0)
    {
    this.bp -= 1;
    }
    }
    else{
    this.aM = (this.yaw = -(float)Math.atan2(this.motX, this.motZ) * 180.0F / 3.1415927F);
    if (this.bp > 0) {
    this.bp -= 1;
    }
    }
    if (!this.world.isStatic)
    {
    byte b0 = this.datawatcher.getByte(16);
    byte b1 = (byte)(this.bp > 10 ? 1 : 0);
    if (b0 != b1) {
    this.datawatcher.watch(16, Byte.valueOf(b1));
    }
    }
    }
    
    }
    
    But because NMS has some privates in between I got all sorts of errors.
    Any help would be apreciated.
     
  2. Offline

    mine-care

  3. Offline

    nuno1212sss

    @mine-care Hmm, how would I do that? Not sure on what kind of reflection you are talking about...

    @mine-care Nvm, I remembered, Will post a finished class when I'm done :D

    @mine-care Would something like this work? http://pastebin.com/QvTUshmK
    Note: I am getting an error on line 55, the method a() returns a NBTTagList, yet it is like that in the ghast class.

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

    Konato_K

    @nuno1212sss Isn't it possible to just replace the fireball with bukkit? I mean, no need to use NMS
     
  5. Offline

    Zombie_Striker

    Isn't is easier to just to set up an event that on a FireBall spawns, spawn the CustomFireball and just take the data and put it towards your custom fireball? You may need to add a variable to your CustomFireball to make sure its not a unbreakable loop, but that can be done by adding a datatag to it.
     
  6. Offline

    nuno1212sss

    @Zombie_Striker EntitySpawn isn't called when a ghast shoots a fireball :D
     
  7. Offline

    Konato_K

Thread Status:
Not open for further replies.

Share This Page