Solved Projectiles with items/blocks

Discussion in 'Plugin Help/Development/Requests' started by benthomas7777, Apr 17, 2015.

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

    benthomas7777

    Hi, I am trying to make a plugin with different guns in, as I want to texture the bullets differently I wanted to use items/blocks that it fires and when they hit a player they disappear and cause damage. But also if they don't hit anything they disappear after traveling a short distance.

    The main problem is im not the best with java and this is the main area of the plugin I just have little clue what to do at the moment. I found some code that someone else wrote about something pretty close to what I'm trying. The post is: http://bukkit.org/threads/help-with-dropped-projectile-item.122284/

    But I would like to do it with an item like a hoe as a gun and any other type of item that fires out and harms other players. Im not sure if that over code will help, but I tried to see how it works, but came across a lot of errors. Please can someone give me help with that or some other code which will do what I want. Thank you in advance.

    My implementation of the code in forum (open)

    Code:
    package me.benthomas7777.clashmc.util;
    
    import java.util.List;
    
    import net.minecraft.server.v1_8_R2.AxisAlignedBB;
    import net.minecraft.server.v1_8_R2.EntityItem;
    import net.minecraft.server.v1_8_R2.EntityLiving;
    import net.minecraft.server.v1_8_R2.ItemStack;
    import net.minecraft.server.v1_8_R2.MathHelper;
    import net.minecraft.server.v1_8_R2.MovingObjectPosition;
    import net.minecraft.server.v1_8_R2.MovingObjectPosition.EnumMovingObjectType;
    import net.minecraft.server.v1_8_R2.Vec3D;
    import net.minecraft.server.v1_8_R2.World;
    
    import org.bukkit.Location;
    import org.bukkit.craftbukkit.v1_8_R2.CraftWorld;
    import org.bukkit.craftbukkit.v1_8_R2.entity.CraftPlayer;
    import org.bukkit.craftbukkit.v1_8_R2.inventory.CraftItemStack;
    import org.bukkit.entity.Entity;
    import org.bukkit.entity.Item;
    import org.bukkit.entity.LivingEntity;
    import org.bukkit.entity.Player;
    import org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason;
    import org.bukkit.potion.PotionEffect;
    import org.bukkit.potion.PotionEffectType;
    public class CustomItem extends EntityItem {
      
        private EntityLiving    shooter;
      
        public CustomItem(World world, double d0, double d1, double d2,
                ItemStack itemstack, EntityLiving entity) {
            super(world, d0, d1, d2, itemstack);
            shooter = entity;
        }
      
        public CustomItem(World world, EntityLiving entityliving, ItemStack item) {
            super(world);
            setItemStack(item);
            shooter = entityliving;
            this.a(0.25F, 0.25F);
            setPositionRotation(entityliving.locX,
                    entityliving.locY + entityliving.getHeadHeight(),
                    entityliving.locZ, entityliving.yaw, entityliving.pitch);
            locX -= (MathHelper.cos(yaw / 180.0F * 3.1415927F) * 0.16F);
            locY -= 0.10000000149011612D;
            locZ -= (MathHelper.sin(yaw / 180.0F * 3.1415927F) * 0.16F);
            setPosition(locX, locY, locZ);
            height = 0.0F;
            float f = 0.4F;
          
            motX = (-MathHelper.sin(yaw / 180.0F * 3.1415927F)
                    * MathHelper.cos(pitch / 180.0F * 3.1415927F) * f);
            motZ = (MathHelper.cos(yaw / 180.0F * 3.1415927F)
                    * MathHelper.cos(pitch / 180.0F * 3.1415927F) * f);
            motY = (-MathHelper.sin(pitch / 180.0F * 3.1415927F) * f);
            shoot(motX, motY, motZ, 1.5F, 1.0F);
        }
      
        @SuppressWarnings("rawtypes")
        @Override
        public void j_() {
            super.j_();
            Vec3D vec3d = world.getVec3DPool().create(locX, locY, locZ);
            Vec3D vec3d1 = world.getVec3DPool().create(locX + motX, locY + motY,
                    locZ + motZ);
            MovingObjectPosition movingobjectposition = world.a(vec3d, vec3d1);
          
            vec3d = world.getVec3DPool().create(locX, locY, locZ);
            vec3d1 = world.getVec3DPool().create(locX + motX, locY + motY,
                    locZ + motZ);
            if (movingobjectposition != null)
                vec3d1 = world.getVec3DPool().create(movingobjectposition.pos.c,
                        movingobjectposition.pos.d, movingobjectposition.pos.e);
          
            if (!world.isStatic) {
                Entity entity = null;
                List list = world.getEntities(this, boundingBox.a(motX, motY, motZ)
                        .grow(1.0D, 1.0D, 1.0D));
                double d0 = 0.0D;
                EntityLiving entityliving = shooter;
              
                for (int j = 0; j < list.size(); ++j) {
                    Entity entity1 = (Entity) list.get(j);
                  
                    if (entity1.L() && entity1 != entityliving) {
                        float f = 0.3F;
                        AxisAlignedBB axisalignedbb = entity1.boundingBox.grow(f,
                                f, f);
                        MovingObjectPosition movingobjectposition1 = axisalignedbb
                                .a(vec3d, vec3d1);
                      
                        if (movingobjectposition1 != null) {
                            double d1 = vec3d
                                    .distanceSquared(movingobjectposition1.pos);
                          
                            if (d1 < d0 || d0 == 0.0D) {
                                entity = entity1;
                                d0 = d1;
                            }
                        }
                    }
                }
              
                if (entity != null)
                    movingobjectposition = new MovingObjectPosition(entity);
            }
          
            LivingEntity living = null;
            if (movingobjectposition != null)
                if (movingobjectposition.type == EnumMovingObjectType.TILE) {
                }
                else if (movingobjectposition.entity != null
                        && movingobjectposition.entity instanceof EntityLiving)
                    living = (LivingEntity) movingobjectposition.entity
                            .getBukkitEntity();
            // HERE WRITE CODE ON ENTITY HIT---------------------------------------------------------------
            living.addPotionEffect(new PotionEffect(PotionEffectType.SLOW, 100, 1));
        }
      
        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() * 0.007499999832361937D * f1;
            d1 += random.nextGaussian() * 0.007499999832361937D * f1;
            d2 += random.nextGaussian() * 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.1415927410125732D);
            lastPitch = pitch = (float) (Math.atan2(d1, f3) * 180.0D / 3.1415927410125732D);
        }
      
        public static Item launch(Player player,
                org.bukkit.inventory.ItemStack item1) {
            Location location = player.getLocation();
            CustomItem item = new CustomItem(
                    ((CraftWorld) player.getWorld()).getHandle(),
                    ((CraftPlayer) player).getHandle(),
                    CraftItemStack.asNMSCopy(item1));
            ((CraftWorld) location.getWorld()).getHandle().addEntity(item,
                    SpawnReason.CUSTOM);
            return (Item) item.getBukkitEntity();
        }
      
    }
    

    Errors that eclipse shows (Don't know how to fix) (open)

    Code:
    Description    Resource    Path    Location    Type
    boundingBox cannot be resolved or is not a field    CustomItem.java    /Clashmc/src/me/benthomas7777/clashmc/util    line 88    Java Problem
    d cannot be resolved or is not a field    CustomItem.java    /Clashmc/src/me/benthomas7777/clashmc/util    line 74    Java Problem
    e cannot be resolved or is not a field    CustomItem.java    /Clashmc/src/me/benthomas7777/clashmc/util    line 74    Java Problem
    height cannot be resolved to a variable    CustomItem.java    /Clashmc/src/me/benthomas7777/clashmc/util    line 49    Java Problem
    isStatic cannot be resolved or is not a field    CustomItem.java    /Clashmc/src/me/benthomas7777/clashmc/util    line 76    Java Problem
    The constructor MovingObjectPosition(Entity) is undefined    CustomItem.java    /Clashmc/src/me/benthomas7777/clashmc/util    line 106    Java Problem
    The field Entity.boundingBox is not visible    CustomItem.java    /Clashmc/src/me/benthomas7777/clashmc/util    line 78    Java Problem
    The method a(Vec3D, AxisAlignedBB) in the type World is not applicable for the arguments (Vec3D, Vec3D)    CustomItem.java    /Clashmc/src/me/benthomas7777/clashmc/util    line 67    Java Problem
    The method getVec3DPool() is undefined for the type World    CustomItem.java    /Clashmc/src/me/benthomas7777/clashmc/util    line 64    Java Problem
    The method getVec3DPool() is undefined for the type World    CustomItem.java    /Clashmc/src/me/benthomas7777/clashmc/util    line 65    Java Problem
    The method getVec3DPool() is undefined for the type World    CustomItem.java    /Clashmc/src/me/benthomas7777/clashmc/util    line 69    Java Problem
    The method getVec3DPool() is undefined for the type World    CustomItem.java    /Clashmc/src/me/benthomas7777/clashmc/util    line 70    Java Problem
    The method getVec3DPool() is undefined for the type World    CustomItem.java    /Clashmc/src/me/benthomas7777/clashmc/util    line 73    Java Problem
    The method j_() is undefined for the type EntityItem    CustomItem.java    /Clashmc/src/me/benthomas7777/clashmc/util    line 63    Java Problem
    The method j_() of type CustomItem must override or implement a supertype method    CustomItem.java    /Clashmc/src/me/benthomas7777/clashmc/util    line 62    Java Problem
    The method L() is undefined for the type Entity    CustomItem.java    /Clashmc/src/me/benthomas7777/clashmc/util    line 86    Java Problem
    TILE cannot be resolved or is not a field    CustomItem.java    /Clashmc/src/me/benthomas7777/clashmc/util    line 111    Java Problem
    
     
  2. Offline

    pie_flavor

    @benthomas7777 Not sure how you can misinterpret the errors... they specifically state exactly what's going wrong.
     
Thread Status:
Not open for further replies.

Share This Page