-- item_addon.lua

local l = (context.bl and 1) or -1
local mat = context.matrices

--[[

PARTICLES
=====================================================================
addParticle(
particles, <- Always 'particles'
[space], <- true (Moves with the hand) / false (floats in the air)
[posX], <- X Position
[posY], <- Y Position
[posZ], <- Z Position
[dx], <- X Velocity
[dy], <- Y Velocity
[dz], <- Z Velocity
[Rotation3D_X], <- 3D rotation on X axis
[Rotation3D_Y], <- 3D rotation on Y axis
[rotation], <- 2D screen-space rotation
[?], <- Unknown parameter - effects unclear
[?], <- Unknown parameter - effects unclear
[?], <- Unknown parameter - effects unclear
[size], <- Size of particle
=====================================================================
]]


-- PARTICLES / EFFECTS
if (
        I:isOf(context.item, Items:get("minecraft:blaze_rod"))
    ) then
        particleManager:addParticle(context.particles, false, 0.11 * l, 0.20, 0.0375, 0, 0, 0, 0, 0, -23*l, 0, 0, 0, 2.85,
        Texture:of("minecraft", "textures/particle/glow_blaze_rod.png"),"ITEM", context.hand, "SPAWN", "ADDITIVE", 0, 111)
    end
-- TORCHS
if (
        I:isOf(context.item, Items:get("minecraft:torch"))
    ) then
        particleManager:addParticle(context.particles, false, 0.11 * l, 0.30, 0.09, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1.25,
        Texture:of("minecraft", "textures/particle/glow_torch.png"),"ITEM", context.hand, "SPAWN", "ADDITIVE", 0, 120)
    end

if (
        I:isOf(context.item, Items:get("minecraft:redstone_torch"))
    ) then
        particleManager:addParticle(context.particles, false, 0.11 * l, 0.30, 0.09, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1.25,
        Texture:of("minecraft", "textures/particle/glow_redstone_torch.png"),"ITEM", context.hand, "SPAWN", "ADDITIVE", 0, 120)
    end

if (
        I:isOf(context.item, Items:get("minecraft:soul_torch"))
    ) then
        particleManager:addParticle(context.particles, false, 0.11 * l, 0.30, 0.09, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1.25,
        Texture:of("minecraft", "textures/particle/glow_soul_torch.png"),"ITEM", context.hand, "SPAWN", "ADDITIVE", 0, 120)
    end

if (
        I:isOf(context.item, Items:get("minecraft:copper_torch"))
    ) then
        particleManager:addParticle(context.particles, false, 0.11 * l, 0.30, 0.09, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1.25,
        Texture:of("minecraft", "textures/particle/glow_copper_torch.png"),"ITEM", context.hand, "SPAWN", "ADDITIVE", 0, 120)
    end

-- NO RENDER AS BLOCK
local noRenderAsBlock = {
    "minecraft:snow",
    "minecraft:torch",
    "minecraft:redstone_torch",
    "minecraft:soul_torch",
    "minecraft:copper_torch",
    "minecraft:pointed_dripstone",
    "minecraft:moss_carpet",
    "minecraft:pale_moss_carpet",
    "minecraft:cake",
    "minecraft:end_rod"
}

for _, id in ipairs(noRenderAsBlock) do
    renderAsBlock:put(id, false)
end

--[[
TEMPLATE ITEMS
=====================================================================
if (
	I:isOf(context.item, Items:get("minecraft:ITEM1")) or
    I:isOf(context.item, Items:get("minecraft:ITEM2"))
    ....
) then
	M:moveX(mat, 0 * l)
    M:moveY(mat, 0)
	M:moveZ(mat, 0)

    M:rotateX(mat, 0)
	M:rotateY(mat, 0 * l)
	M:rotateZ(mat, 0 * l)

	M:scale(mat, 1, 1, 1)
end
=====================================================================
]]

-- ITEM POSITION
if (
	I:isOf(context.item, Items:get("minecraft:blaze_rod")) or
    I:isOf(context.item, Items:get("minecraft:breeze_rod"))
) then
	M:moveX(mat, 0.015 * l)
    M:moveY(mat, 0)
	M:moveZ(mat, 0)

    M:rotateX(mat, -8.5)
	M:rotateY(mat, 0 * l)
	M:rotateZ(mat, 0 * l)

	M:scale(mat, 1, 1, 1)
end

if (
	I:isOf(context.item, Items:get("minecraft:end_rod"))
) then
	M:moveX(mat, 0.027 * l)
    M:moveY(mat, -0.005)
	M:moveZ(mat, 0)

    M:rotateX(mat, -8.5)
	M:rotateY(mat, 0 * l)
	M:rotateZ(mat, 0 * l)

	M:scale(mat, 0.95, 0.95, 0.95)
end

if (
    I:isOf(context.item, Items:get("minecraft:torch")) or
    I:isOf(context.item, Items:get("minecraft:redstone_torch")) or
    I:isOf(context.item, Items:get("minecraft:soul_torch")) or
    I:isOf(context.item, Items:get("minecraft:copper_torch"))
) then
	M:moveX(mat, 0.015 * l)
    M:moveY(mat, 0.031)
	M:moveZ(mat, 0.015)

    M:rotateX(mat, -15)
	M:rotateY(mat, 0 * l)
	M:rotateZ(mat, 0 * l)

	M:scale(mat, 0.85, 0.85, 0.85)
end

if (
    I:isOf(context.item, Items:get("minecraft:snow"))
) then
	M:moveX(mat, 0 * l)
    M:moveY(mat, 0.0)
	M:moveZ(mat, 0.125)

    M:rotateX(mat, -56)
	M:rotateY(mat, 0 * l)
	M:rotateZ(mat, 0 * l)

	M:scale(mat, 1, 1, 1)
end

if (
    I:isOf(context.item, Items:get("minecraft:cake"))
) then
	M:moveX(mat, -0.06 * l)
    M:moveY(mat, -0.035)
	M:moveZ(mat, 0.2156)

    M:rotateX(mat, -90)
	M:rotateY(mat, 0 * l)
	M:rotateZ(mat, -17.5 * l)

	M:scale(mat, 1.11, 1.11, 1.11)
end

if (
    I:isOf(context.item, Items:get("minecraft:wind_charge"))
) then
	M:moveX(mat, 0.055 * l)
    M:moveY(mat, -0.005)
	M:moveZ(mat, 0.01)

    M:rotateX(mat, -60)
	M:rotateY(mat, 0 * l)
	M:rotateZ(mat, 0 * l)

	M:scale(mat, 1, 1, 1)
end