Search in sources :

Example 16 with HitBox

use of me.deecaad.weaponmechanics.weapon.projectile.HitBox in project MechanicsMain by WeaponMechanics.

the class WeaponMechanics method writeFiles.

void writeFiles() {
    // Create files
    if (!getDataFolder().exists() || getDataFolder().listFiles() == null || getDataFolder().listFiles().length == 0) {
        debug.info("Copying files from jar (This process may take up to 30 seconds during the first load!)");
        try {
            FileUtil.copyResourcesTo(getClassLoader().getResource("WeaponMechanics"), getDataFolder().toPath());
        } catch (IOException | URISyntaxException e) {
            e.printStackTrace();
        }
    }
    try {
    // TODO bad programmars comment out broken code
    // FileUtil.ensureDefaults(getClassLoader(), "WeaponMechanics/config.yml", new File(getDataFolder(), "config.yml"));
    } catch (YAMLException e) {
        debug.error("WeaponMechanics jar corruption... This is most likely caused by using /reload after building jar!");
    }
    // Fill config.yml mappings
    File configyml = new File(getDataFolder(), "config.yml");
    if (configyml.exists()) {
        List<IValidator> validators = new ArrayList<>();
        // No need for other validators here as this is only for config.yml
        validators.add(new HitBox());
        FileReader basicConfigurationReader = new FileReader(debug, null, validators);
        Configuration filledMap = basicConfigurationReader.fillOneFile(configyml);
        basicConfiguration = basicConfigurationReader.usePathToSerializersAndValidators(filledMap);
    } else {
        // Just creates empty map to prevent other issues
        basicConfiguration = new LinkedConfig();
        debug.log(LogLevel.WARN, "Could not locate config.yml?", "Make sure it exists in path " + getDataFolder() + "/config.yml");
    }
    // Ensure that the resource pack exists in the folder
    if (basicConfiguration.getBool("Resource_Pack_Download.Enabled")) {
        String link = basicConfiguration.getString("Resource_Pack_Download.Link");
        int connection = basicConfiguration.getInt("Resource_Pack_Download.Connection_Timeout");
        int read = basicConfiguration.getInt("Resource_Pack_Download.Read_Timeout");
        File pack = new File(getDataFolder(), "WeaponMechanicsResourcePack.zip");
        if (!pack.exists()) {
            FileUtil.downloadFile(pack, link, connection, read);
        }
    }
}
Also used : HitBox(me.deecaad.weaponmechanics.weapon.projectile.HitBox) Configuration(me.deecaad.core.file.Configuration) LinkedConfig(me.deecaad.core.file.LinkedConfig) ArrayList(java.util.ArrayList) YAMLException(org.yaml.snakeyaml.error.YAMLException) IOException(java.io.IOException) URISyntaxException(java.net.URISyntaxException) IValidator(me.deecaad.core.file.IValidator) FileReader(me.deecaad.core.file.FileReader) JarFile(java.util.jar.JarFile) File(java.io.File)

Example 17 with HitBox

use of me.deecaad.weaponmechanics.weapon.projectile.HitBox in project MechanicsMain by WeaponMechanics.

the class RayTraceCommand method execute.

@Override
public void execute(CommandSender sender, String[] args) {
    if (!(sender instanceof Player)) {
        sender.sendMessage(ChatColor.RED + "This command is only available for players.");
        return;
    }
    Player player = (Player) sender;
    boolean onlyHitPosition = args.length > 0 && Boolean.parseBoolean(args[0]);
    int distance = (args.length > 1) ? Integer.parseInt(args[1]) : 5;
    if (distance < 1) {
        sender.sendMessage(ChatColor.RED + "Distance was less than 1");
        return;
    }
    int time = (args.length > 2) ? Integer.parseInt(args[2]) : 200;
    sender.sendMessage(ChatColor.GREEN + "Showing hitboxes in distance " + distance + " for " + time + " ticks");
    IWeaponCompatibility weaponCompatibility = WeaponCompatibilityAPI.getWeaponCompatibility();
    new BukkitRunnable() {

        int ticker = 0;

        @Override
        public void run() {
            Location location = player.getEyeLocation();
            Vector direction = location.getDirection();
            BlockIterator blocks = new BlockIterator(player.getWorld(), location.toVector(), direction, 0.0, distance);
            while (blocks.hasNext()) {
                Block block = blocks.next();
                HitBox blockBox = weaponCompatibility.getHitBox(block);
                if (blockBox == null)
                    continue;
                RayTraceResult rayTraceResult = blockBox.rayTrace(location.toVector(), direction);
                if (rayTraceResult == null)
                    continue;
                if (onlyHitPosition) {
                    rayTraceResult.outlineOnlyHitPosition(player);
                } else {
                    blockBox.outlineAllBoxes(player);
                }
                player.sendMessage("Block: " + block.getType());
                break;
            }
            Collection<Entity> entities = player.getWorld().getNearbyEntities(location, distance, distance, distance);
            if (!entities.isEmpty()) {
                for (Entity entity : entities) {
                    if (!(entity instanceof LivingEntity) || entity.getEntityId() == player.getEntityId())
                        continue;
                    HitBox entityBox = weaponCompatibility.getHitBox(entity);
                    if (entityBox == null)
                        continue;
                    RayTraceResult rayTraceResult = entityBox.rayTrace(location.toVector(), direction);
                    if (rayTraceResult == null)
                        continue;
                    if (onlyHitPosition) {
                        rayTraceResult.outlineOnlyHitPosition(player);
                    } else {
                        entityBox.outlineAllBoxes(player);
                    }
                    player.sendMessage("Entity: " + entity.getType());
                    break;
                }
            }
            if (++ticker >= time) {
                cancel();
            }
        }
    }.runTaskTimer(WeaponMechanics.getPlugin(), 0, 0);
}
Also used : BlockIterator(org.bukkit.util.BlockIterator) Entity(org.bukkit.entity.Entity) LivingEntity(org.bukkit.entity.LivingEntity) Player(org.bukkit.entity.Player) HitBox(me.deecaad.weaponmechanics.weapon.projectile.HitBox) RayTraceResult(me.deecaad.weaponmechanics.weapon.projectile.weaponprojectile.RayTraceResult) BukkitRunnable(org.bukkit.scheduler.BukkitRunnable) IWeaponCompatibility(me.deecaad.weaponmechanics.compatibility.IWeaponCompatibility) LivingEntity(org.bukkit.entity.LivingEntity) Block(org.bukkit.block.Block) Collection(java.util.Collection) Vector(org.bukkit.util.Vector) Location(org.bukkit.Location)

Example 18 with HitBox

use of me.deecaad.weaponmechanics.weapon.projectile.HitBox in project MechanicsMain by WeaponMechanics.

the class v1_10_R1 method getHitBox.

@Override
public HitBox getHitBox(org.bukkit.entity.Entity entity) {
    if (entity.isInvulnerable() || !entity.getType().isAlive() || entity.isDead())
        return null;
    AxisAlignedBB aabb = ((CraftEntity) entity).getHandle().getBoundingBox();
    HitBox hitBox = new HitBox(aabb.a, aabb.b, aabb.c, aabb.d, aabb.e, aabb.f);
    hitBox.setLivingEntity((LivingEntity) entity);
    if (entity instanceof ComplexLivingEntity && WeaponMechanics.getBasicConfigurations().getBool("Check_Accurate_Hitboxes", true)) {
        for (ComplexEntityPart entityPart : ((ComplexLivingEntity) entity).getParts()) {
            AxisAlignedBB boxPart = ((CraftEntity) entityPart).getHandle().getBoundingBox();
            hitBox.addVoxelShapePart(new HitBox(boxPart.a, boxPart.b, boxPart.c, boxPart.d, boxPart.e, boxPart.f));
        }
    }
    return hitBox;
}
Also used : AxisAlignedBB(net.minecraft.server.v1_10_R1.AxisAlignedBB) HitBox(me.deecaad.weaponmechanics.weapon.projectile.HitBox) ComplexEntityPart(org.bukkit.entity.ComplexEntityPart) ComplexLivingEntity(org.bukkit.entity.ComplexLivingEntity)

Example 19 with HitBox

use of me.deecaad.weaponmechanics.weapon.projectile.HitBox in project MechanicsMain by WeaponMechanics.

the class v1_10_R1 method getHitBox.

@Override
public HitBox getHitBox(org.bukkit.block.Block block) {
    if (block.isEmpty() || block.isLiquid())
        return null;
    WorldServer worldServer = ((CraftWorld) block.getWorld()).getHandle();
    BlockPosition blockPosition = new BlockPosition(block.getX(), block.getY(), block.getZ());
    IBlockData blockData = worldServer.getType(blockPosition);
    Block nmsBlock = blockData.getBlock();
    // Passable block check -> false means passable (thats why !)
    if (!(blockData.d(worldServer, blockPosition) != Block.k && nmsBlock.a(blockData, false)))
        return null;
    AxisAlignedBB aabb = blockData.c(worldServer, blockPosition);
    // 1.12 -> e
    // 1.11 -> d
    // 1.9 - 1.10 -> c
    int x = blockPosition.getX(), y = blockPosition.getY(), z = blockPosition.getZ();
    HitBox hitBox = new HitBox(x + aabb.a, y + aabb.b, z + aabb.c, x + aabb.d, y + aabb.e, z + aabb.f);
    hitBox.setBlockHitBox(block);
    return hitBox;
}
Also used : AxisAlignedBB(net.minecraft.server.v1_10_R1.AxisAlignedBB) IBlockData(net.minecraft.server.v1_10_R1.IBlockData) HitBox(me.deecaad.weaponmechanics.weapon.projectile.HitBox) BlockPosition(net.minecraft.server.v1_10_R1.BlockPosition) Block(net.minecraft.server.v1_10_R1.Block) WorldServer(net.minecraft.server.v1_10_R1.WorldServer) CraftWorld(org.bukkit.craftbukkit.v1_10_R1.CraftWorld)

Example 20 with HitBox

use of me.deecaad.weaponmechanics.weapon.projectile.HitBox in project MechanicsMain by WeaponMechanics.

the class v1_11_R1 method getHitBox.

@Override
public HitBox getHitBox(org.bukkit.block.Block block) {
    if (block.isEmpty() || block.isLiquid())
        return null;
    WorldServer worldServer = ((CraftWorld) block.getWorld()).getHandle();
    BlockPosition blockPosition = new BlockPosition(block.getX(), block.getY(), block.getZ());
    IBlockData blockData = worldServer.getType(blockPosition);
    Block nmsBlock = blockData.getBlock();
    // Passable block check -> false means passable (thats why !)
    if (!(blockData.d(worldServer, blockPosition) != Block.k && nmsBlock.a(blockData, false)))
        return null;
    AxisAlignedBB aabb = blockData.d(worldServer, blockPosition);
    // 1.12 -> e
    // 1.11 -> d
    // 1.9 - 1.10 -> c
    int x = blockPosition.getX(), y = blockPosition.getY(), z = blockPosition.getZ();
    HitBox hitBox = new HitBox(x + aabb.a, y + aabb.b, z + aabb.c, x + aabb.d, y + aabb.e, z + aabb.f);
    hitBox.setBlockHitBox(block);
    return hitBox;
}
Also used : AxisAlignedBB(net.minecraft.server.v1_11_R1.AxisAlignedBB) IBlockData(net.minecraft.server.v1_11_R1.IBlockData) HitBox(me.deecaad.weaponmechanics.weapon.projectile.HitBox) BlockPosition(net.minecraft.server.v1_11_R1.BlockPosition) Block(net.minecraft.server.v1_11_R1.Block) WorldServer(net.minecraft.server.v1_11_R1.WorldServer) CraftWorld(org.bukkit.craftbukkit.v1_11_R1.CraftWorld)

Aggregations

HitBox (me.deecaad.weaponmechanics.weapon.projectile.HitBox)25 Vector (org.bukkit.util.Vector)7 Entity (org.bukkit.entity.Entity)6 BoundingBox (org.bukkit.util.BoundingBox)6 Block (org.bukkit.block.Block)5 ComplexEntityPart (org.bukkit.entity.ComplexEntityPart)5 ComplexLivingEntity (org.bukkit.entity.ComplexLivingEntity)5 LivingEntity (org.bukkit.entity.LivingEntity)5 ArrayList (java.util.ArrayList)4 IWeaponCompatibility (me.deecaad.weaponmechanics.compatibility.IWeaponCompatibility)4 Chunk (org.bukkit.Chunk)3 World (org.bukkit.World)3 BlockIterator (org.bukkit.util.BlockIterator)3 HashMap (java.util.HashMap)2 Ray (me.deecaad.weaponmechanics.weapon.explode.raytrace.Ray)2 TraceResult (me.deecaad.weaponmechanics.weapon.explode.raytrace.TraceResult)2 RayTraceResult (me.deecaad.weaponmechanics.weapon.projectile.weaponprojectile.RayTraceResult)2 AxisAlignedBB (net.minecraft.server.v1_10_R1.AxisAlignedBB)2 AxisAlignedBB (net.minecraft.server.v1_11_R1.AxisAlignedBB)2 AxisAlignedBB (net.minecraft.server.v1_12_R1.AxisAlignedBB)2