Search in sources :

Example 21 with HitBox

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

the class v1_12_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.e(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_12_R1.AxisAlignedBB) IBlockData(net.minecraft.server.v1_12_R1.IBlockData) HitBox(me.deecaad.weaponmechanics.weapon.projectile.HitBox) BlockPosition(net.minecraft.server.v1_12_R1.BlockPosition) Block(net.minecraft.server.v1_12_R1.Block) WorldServer(net.minecraft.server.v1_12_R1.WorldServer) CraftWorld(org.bukkit.craftbukkit.v1_12_R1.CraftWorld)

Example 22 with HitBox

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

the class v1_13_R2 method getHitBox.

@Override
public HitBox getHitBox(Block block) {
    if (block.isEmpty() || block.isLiquid() || block.isPassable())
        return null;
    BoundingBox boundingBox = block.getBoundingBox();
    HitBox hitBox = new HitBox(boundingBox.getMinX(), boundingBox.getMinY(), boundingBox.getMinZ(), boundingBox.getMaxX(), boundingBox.getMaxY(), boundingBox.getMaxZ());
    hitBox.setBlockHitBox(block);
    if (WeaponMechanics.getBasicConfigurations().getBool("Check_Accurate_Hitboxes", true)) {
        CraftBlock craftBlock = (CraftBlock) block;
        List<AxisAlignedBB> voxelShape = craftBlock.getNMS().getCollisionShape(craftBlock.getCraftWorld().getHandle(), craftBlock.getPosition()).d();
        if (voxelShape.size() > 1) {
            int x = block.getX();
            int y = block.getY();
            int z = block.getZ();
            for (AxisAlignedBB boxPart : voxelShape) {
                hitBox.addVoxelShapePart(new HitBox(x + boxPart.minX, y + boxPart.minY, z + boxPart.minZ, x + boxPart.maxX, y + boxPart.maxY, z + boxPart.maxZ));
            }
        }
    }
    return hitBox;
}
Also used : AxisAlignedBB(net.minecraft.server.v1_13_R2.AxisAlignedBB) HitBox(me.deecaad.weaponmechanics.weapon.projectile.HitBox) BoundingBox(org.bukkit.util.BoundingBox) CraftBlock(org.bukkit.craftbukkit.v1_13_R2.block.CraftBlock)

Example 23 with HitBox

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

the class v1_14_R1 method getHitBox.

@Override
public HitBox getHitBox(Block block) {
    if (block.isEmpty() || block.isLiquid() || block.isPassable())
        return null;
    BoundingBox boundingBox = block.getBoundingBox();
    HitBox hitBox = new HitBox(boundingBox.getMinX(), boundingBox.getMinY(), boundingBox.getMinZ(), boundingBox.getMaxX(), boundingBox.getMaxY(), boundingBox.getMaxZ());
    hitBox.setBlockHitBox(block);
    if (WeaponMechanics.getBasicConfigurations().getBool("Check_Accurate_Hitboxes", true)) {
        CraftBlock craftBlock = (CraftBlock) block;
        List<AxisAlignedBB> voxelShape = craftBlock.getNMS().getCollisionShape(craftBlock.getCraftWorld().getHandle(), craftBlock.getPosition()).d();
        if (voxelShape.size() > 1) {
            int x = block.getX();
            int y = block.getY();
            int z = block.getZ();
            for (AxisAlignedBB boxPart : voxelShape) {
                hitBox.addVoxelShapePart(new HitBox(x + boxPart.minX, y + boxPart.minY, z + boxPart.minZ, x + boxPart.maxX, y + boxPart.maxY, z + boxPart.maxZ));
            }
        }
    }
    return hitBox;
}
Also used : AxisAlignedBB(net.minecraft.server.v1_14_R1.AxisAlignedBB) HitBox(me.deecaad.weaponmechanics.weapon.projectile.HitBox) BoundingBox(org.bukkit.util.BoundingBox) CraftBlock(org.bukkit.craftbukkit.v1_14_R1.block.CraftBlock)

Example 24 with HitBox

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

the class v1_15_R1 method getHitBox.

@Override
public HitBox getHitBox(Block block) {
    if (block.isEmpty() || block.isLiquid() || block.isPassable())
        return null;
    BoundingBox boundingBox = block.getBoundingBox();
    HitBox hitBox = new HitBox(boundingBox.getMinX(), boundingBox.getMinY(), boundingBox.getMinZ(), boundingBox.getMaxX(), boundingBox.getMaxY(), boundingBox.getMaxZ());
    hitBox.setBlockHitBox(block);
    if (WeaponMechanics.getBasicConfigurations().getBool("Check_Accurate_Hitboxes", true)) {
        CraftBlock craftBlock = (CraftBlock) block;
        List<AxisAlignedBB> voxelShape = craftBlock.getNMS().getCollisionShape(craftBlock.getCraftWorld().getHandle(), craftBlock.getPosition()).d();
        if (voxelShape.size() > 1) {
            int x = block.getX();
            int y = block.getY();
            int z = block.getZ();
            for (AxisAlignedBB boxPart : voxelShape) {
                hitBox.addVoxelShapePart(new HitBox(x + boxPart.minX, y + boxPart.minY, z + boxPart.minZ, x + boxPart.maxX, y + boxPart.maxY, z + boxPart.maxZ));
            }
        }
    }
    return hitBox;
}
Also used : AxisAlignedBB(net.minecraft.server.v1_15_R1.AxisAlignedBB) HitBox(me.deecaad.weaponmechanics.weapon.projectile.HitBox) BoundingBox(org.bukkit.util.BoundingBox) CraftBlock(org.bukkit.craftbukkit.v1_15_R1.block.CraftBlock)

Example 25 with HitBox

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

the class IWeaponCompatibility method getHitBox.

/**
 * If entity is invulnerable or non alive this will always return null.
 * Otherwise this will always have non null value.
 *
 * @param entity the entity
 * @return the living entity's hit box
 */
default HitBox getHitBox(Entity entity) {
    if (entity.isInvulnerable() || !entity.getType().isAlive() || entity.isDead())
        return null;
    // This default should only be used after 1.13 R2
    BoundingBox boundingBox = entity.getBoundingBox();
    HitBox hitBox = new HitBox(boundingBox.getMinX(), boundingBox.getMinY(), boundingBox.getMinZ(), boundingBox.getMaxX(), boundingBox.getMaxY(), boundingBox.getMaxZ());
    hitBox.setLivingEntity((LivingEntity) entity);
    if (entity instanceof ComplexLivingEntity && WeaponMechanics.getBasicConfigurations().getBool("Check_Accurate_Hitboxes", true)) {
        for (ComplexEntityPart entityPart : ((ComplexLivingEntity) entity).getParts()) {
            BoundingBox boxPart = entityPart.getBoundingBox();
            hitBox.addVoxelShapePart(new HitBox(boxPart.getMinX(), boxPart.getMinY(), boxPart.getMinZ(), boxPart.getMaxX(), boxPart.getMaxY(), boxPart.getMaxZ()));
        }
    }
    return hitBox;
}
Also used : HitBox(me.deecaad.weaponmechanics.weapon.projectile.HitBox) ComplexEntityPart(org.bukkit.entity.ComplexEntityPart) BoundingBox(org.bukkit.util.BoundingBox) ComplexLivingEntity(org.bukkit.entity.ComplexLivingEntity)

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