Compare commits
No commits in common. "5406acc98722774d076f54c2bd53ca19a221acbe" and "73735995b75d48c8d5b43a69a46351dd0c19827d" have entirely different histories.
5406acc987
...
73735995b7
4 changed files with 60 additions and 81 deletions
|
@ -3,5 +3,4 @@ events.ENTITY_INIT:register(function ()
|
||||||
require("scripts.nameplate")
|
require("scripts.nameplate")
|
||||||
require("scripts.soggy")
|
require("scripts.soggy")
|
||||||
require("scripts.physics")
|
require("scripts.physics")
|
||||||
require("scripts.wheels.main")
|
|
||||||
end)
|
end)
|
||||||
|
|
|
@ -6,10 +6,66 @@ local g = require("scripts.libs.gradient")
|
||||||
|
|
||||||
---@param name string
|
---@param name string
|
||||||
---@param gradient Gradient
|
---@param gradient Gradient
|
||||||
|
---@param nameplates Nameplate | Nameplate[] where to use the animated name
|
||||||
|
---@param count number number of gradients to be present in the span
|
||||||
|
---@param phase_shift_rate number how fast to shift the gradient
|
||||||
|
---@returns fun():void # function to unregister
|
||||||
|
local function animate_gradient_name(name, gradient, nameplates, count, phase_shift_rate)
|
||||||
|
if type(nameplates) ~= "table" then
|
||||||
|
nameplates = {nameplates}
|
||||||
|
end
|
||||||
|
|
||||||
|
local string_width = client.getTextWidth(name) / count;
|
||||||
|
local string_width_chars = {};
|
||||||
|
for i = 1, #name do
|
||||||
|
string_width_chars[i] = client.getTextWidth(name:sub(i, i))
|
||||||
|
end
|
||||||
|
|
||||||
|
---@type ColoredText[]
|
||||||
|
local result = {}
|
||||||
|
|
||||||
|
local phase_shift = 0;
|
||||||
|
local function render()
|
||||||
|
if client.isPaused() then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
local acc = 0;
|
||||||
|
for i = 1, #name do
|
||||||
|
local offset = acc + string_width_chars[i];
|
||||||
|
local color = gradient:at((offset / string_width) + phase_shift);
|
||||||
|
acc = offset
|
||||||
|
|
||||||
|
result[i] = {
|
||||||
|
text = name:sub(i, i),
|
||||||
|
color = color:toHex(true, false)
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
|
phase_shift = phase_shift + phase_shift_rate
|
||||||
|
|
||||||
|
local json = toJson(result);
|
||||||
|
for _, nameplate in pairs(nameplates) do
|
||||||
|
nameplate:setText(json)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
events.render:register(render)
|
||||||
|
return function ()
|
||||||
|
events.render:remove(render)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
---@param name string
|
||||||
|
---@param gradient Gradient
|
||||||
|
---@param nameplates Nameplate | Nameplate[] where to use the static name
|
||||||
---@param count number number of gradients to be present in the span
|
---@param count number number of gradients to be present in the span
|
||||||
---@param phase_shift number shift of the gradient
|
---@param phase_shift number shift of the gradient
|
||||||
---@returns string
|
local function static_gradient_name(name, gradient, nameplates, count, phase_shift)
|
||||||
local function render_gradient_name(name, gradient, count, phase_shift)
|
if type(nameplates) ~= "table" then
|
||||||
|
nameplates = {nameplates}
|
||||||
|
end
|
||||||
|
|
||||||
local string_width = client.getTextWidth(name) / count;
|
local string_width = client.getTextWidth(name) / count;
|
||||||
local string_width_chars = {};
|
local string_width_chars = {};
|
||||||
for i = 1, #name do
|
for i = 1, #name do
|
||||||
|
@ -31,53 +87,9 @@ local function render_gradient_name(name, gradient, count, phase_shift)
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
return toJson(result)
|
local json = toJson(result);
|
||||||
end
|
|
||||||
|
|
||||||
---@param name string
|
|
||||||
---@param gradient Gradient
|
|
||||||
---@param nameplates Nameplate | Nameplate[] where to use the animated name
|
|
||||||
---@param count number number of gradients to be present in the span
|
|
||||||
---@param phase_shift_rate number how fast to shift the gradient
|
|
||||||
---@returns fun():void # function to unregister
|
|
||||||
local function animate_gradient_name(name, gradient, nameplates, count, phase_shift_rate)
|
|
||||||
if type(nameplates) ~= "table" then
|
|
||||||
nameplates = {nameplates}
|
|
||||||
end
|
|
||||||
|
|
||||||
local phase_shift = 0;
|
|
||||||
local function render()
|
|
||||||
if client.isPaused() then
|
|
||||||
return
|
|
||||||
end
|
|
||||||
|
|
||||||
phase_shift = phase_shift + phase_shift_rate
|
|
||||||
|
|
||||||
local result = render_gradient_name(name, gradient, count, phase_shift)
|
|
||||||
for _, nameplate in pairs(nameplates) do
|
for _, nameplate in pairs(nameplates) do
|
||||||
nameplate:setText(result)
|
nameplate:setText(json)
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
events.render:register(render)
|
|
||||||
return function ()
|
|
||||||
events.render:remove(render)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
---@param name string
|
|
||||||
---@param gradient Gradient
|
|
||||||
---@param nameplates Nameplate | Nameplate[] where to use the static name
|
|
||||||
---@param count number number of gradients to be present in the span
|
|
||||||
---@param phase_shift number shift of the gradient
|
|
||||||
local function static_gradient_name(name, gradient, nameplates, count, phase_shift)
|
|
||||||
if type(nameplates) ~= "table" then
|
|
||||||
nameplates = {nameplates}
|
|
||||||
end
|
|
||||||
|
|
||||||
local result = render_gradient_name(name, gradient, count, phase_shift);
|
|
||||||
for _, nameplate in pairs(nameplates) do
|
|
||||||
nameplate:setText(result)
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -1,18 +0,0 @@
|
||||||
local toggles = require("scripts.wheels.toggles")
|
|
||||||
|
|
||||||
local wheels = {
|
|
||||||
toggles
|
|
||||||
}
|
|
||||||
|
|
||||||
for i, v in pairs(wheels) do
|
|
||||||
if i == 1 then action_wheel:setPage(v) end
|
|
||||||
if #wheels ~= 1 then
|
|
||||||
v:newAction()
|
|
||||||
:title("to next page")
|
|
||||||
:item("minecraft:arrow")
|
|
||||||
:onLeftClick(function ()
|
|
||||||
local index = (i + 1) > #wheels and 1 or (i + 1)
|
|
||||||
action_wheel:setPage(wheels[index])
|
|
||||||
end)
|
|
||||||
end
|
|
||||||
end
|
|
|
@ -1,14 +0,0 @@
|
||||||
local toggles = action_wheel:newPage()
|
|
||||||
|
|
||||||
function pings.toggleArmor(state)
|
|
||||||
vanilla_model.ARMOR:setVisible(state)
|
|
||||||
end
|
|
||||||
|
|
||||||
local toggle_armor = toggles:newAction()
|
|
||||||
:setToggled(false)
|
|
||||||
:setOnToggle(pings.toggleArmor)
|
|
||||||
:title("toggle armor")
|
|
||||||
:item("red_wool")
|
|
||||||
:toggleItem("green_wool")
|
|
||||||
|
|
||||||
return toggles
|
|
Loading…
Add table
Add a link
Reference in a new issue