package com.acethewildfire.acesbs.entity.custom;

import com.acethewildfire.acesbs.entity.ModEntities;
import com.acethewildfire.acesbs.item.ModItems;
import net.minecraft.block.AbstractFireBlock;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityType;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.entity.projectile.PersistentProjectileEntity;
import net.minecraft.item.ItemStack;
import net.minecraft.util.hit.BlockHitResult;
import net.minecraft.util.hit.EntityHitResult;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;

public class CombustibleLemonEntity extends PersistentProjectileEntity {
    private float rotation;
//    public Vector2f groundedOffset;

    public CombustibleLemonEntity(EntityType<? extends PersistentProjectileEntity> entityType, World world) {
        super(entityType, world);
    }

    public CombustibleLemonEntity(World world, PlayerEntity player) {
        super(ModEntities.C_LEMON, player, world, new ItemStack(ModItems.COMBUSTIBLE_LEMON), null);
    }

    @Override
    protected ItemStack getDefaultItemStack() {
        return new ItemStack(ModItems.COMBUSTIBLE_LEMON);
    }

    public float getRenderingRotation() {
        rotation += 0.5f;
        if(rotation >= 360) {
            rotation = 0;
        }
        return rotation;
    }

    public boolean isGrounded() {
        return inGround;
    }

    @Override
    protected void onEntityHit(EntityHitResult entityHitResult) {
        super.onEntityHit(entityHitResult);
        Entity entity = entityHitResult.getEntity();
//        entity.damage(this.getDamageSources().thrown(this, this.getOwner()), 4);
        entity.setOnFireFor(20);

        if (!this.getWorld().isClient()) {
            this.getWorld().sendEntityStatus(this, (byte)3);
            this.discard();
        }
    }

    @Override
    protected void onBlockHit(BlockHitResult result) {
        super.onBlockHit(result);

        BlockPos blockPos = result.getBlockPos().offset(result.getSide());
        if (this.getWorld().isAir(blockPos)) {
            this.getWorld().setBlockState(blockPos, AbstractFireBlock.getState(this.getWorld(), blockPos));
        }

        this.discard();

//        if(result.getSide() == Direction.SOUTH) {
//            groundedOffset = new Vector2f(215f,180f);
//        }
//        if(result.getSide() == Direction.NORTH) {
//            groundedOffset = new Vector2f(215f, 0f);
//        }
//        if(result.getSide() == Direction.EAST) {
//            groundedOffset = new Vector2f(215f,-90f);
//        }
//        if(result.getSide() == Direction.WEST) {
//            groundedOffset = new Vector2f(215f,90f);
//        }
//
//        if(result.getSide() == Direction.DOWN) {
//            groundedOffset = new Vector2f(115f,180f);
//        }
//        if(result.getSide() == Direction.UP) {
//            groundedOffset = new Vector2f(285f,180f);
//        }
    }
}
