Confirmedusers, editor
749
edits
Ninjanomnom (talk | contribs) m (Double checked information and updated version) |
(Replaced deprecated (1.9?) tick listener definition) Tags: Mobile edit Mobile web edit |
||
Line 1: | Line 1: | ||
__FORCETOC__ | __FORCETOC__ | ||
{{GameVersion|1. | {{GameVersion|1.16}} | ||
= Introduction = | = Introduction = | ||
Line 44: | Line 44: | ||
<syntaxhighlight lang="c#"> | <syntaxhighlight lang="c#"> | ||
public | public float timer; | ||
</syntaxhighlight> | </syntaxhighlight> | ||
Line 50: | Line 50: | ||
<syntaxhighlight lang="c#"> | <syntaxhighlight lang="c#"> | ||
public void | public void OnGameTick(float dt) | ||
{ | { | ||
Line 62: | Line 62: | ||
{ | { | ||
base.Initialize(api); | base.Initialize(api); | ||
RegisterGameTickListener( | RegisterGameTickListener(OnGameTick, 50); | ||
} | } | ||
</syntaxhighlight> | </syntaxhighlight> | ||
The timer itself should | The timer itself should increment by dt, the time difference in seconds between the current tick and the previous tick. It ticks about every 50ms or less often if the game is slow. So if the timer is greater than 3, it should replace the block: | ||
<syntaxhighlight lang="c#"> | <syntaxhighlight lang="c#"> | ||
public void | public void OnGameTick(float dt) | ||
{ | { | ||
timer+ | timer += dt; | ||
if(timer > | if(timer >= 3) | ||
{ | { | ||
Block block = Api.World.BlockAccessor.GetBlock(Pos); | Block block = Api.World.BlockAccessor.GetBlock(Pos); | ||
Line 97: | Line 97: | ||
{ | { | ||
base.ToTreeAttributes(tree); | base.ToTreeAttributes(tree); | ||
tree. | tree.SetFloat("timer", timer); | ||
} | } | ||
Line 103: | Line 103: | ||
{ | { | ||
base.FromTreeAttributes(tree, worldForResolving); | base.FromTreeAttributes(tree, worldForResolving); | ||
timer = tree. | timer = tree.GetFloat("timer"); | ||
} | } | ||