Confirmedusers, editor, Administrators
886
edits
CreativeMD (talk | contribs) No edit summary |
CreativeMD (talk | contribs) |
||
Line 27: | Line 27: | ||
== Adding particles == | == Adding particles == | ||
Now we need to implement the interact function. First of all we need to specify that the player can "use" this tool, therefore we need to | Now we need to implement the interact function. First of all we need to specify that the player can "use" this tool, therefore we need to set handling to <code>handled</code> ... | ||
<syntaxhighlight lang="c#"> | <syntaxhighlight lang="c#"> | ||
public override | public override void OnHeldInteractStart(ItemSlot slot, EntityAgent byEntity, BlockSelection blockSel, EntitySelection entitySel, bool firstEvent, ref EnumHandHandling handling) | ||
{ | { | ||
handling = EnumHandHandling.Handled; | |||
} | } | ||
</syntaxhighlight> | </syntaxhighlight> | ||
Line 39: | Line 39: | ||
<syntaxhighlight lang="c#"> | <syntaxhighlight lang="c#"> | ||
public override bool OnHeldInteractStep(float secondsUsed, | public override bool OnHeldInteractStep(float secondsUsed, ItemSlot slot, EntityAgent byEntity, BlockSelection blockSel, EntitySelection entitySel) | ||
{ | { | ||
if (byEntity.World is IClientWorldAccessor) | if (byEntity.World is IClientWorldAccessor) | ||
Line 46: | Line 46: | ||
tf.EnsureDefaultValues(); | tf.EnsureDefaultValues(); | ||
tf.Origin.Set(0, -1, 0); | |||
tf.Rotation.Z = Math.Min(30, secondsUsed * 40); | |||
byEntity.Controls.UsingHeldItemTransformAfter = tf; | |||
tf.Origin.Set(0, | |||
tf. | |||
byEntity.Controls. | |||
} | } | ||
return true; | |||
} | } | ||
</syntaxhighlight> | </syntaxhighlight> | ||
Line 112: | Line 107: | ||
<syntaxhighlight lang="c#"> | <syntaxhighlight lang="c#"> | ||
public override bool OnHeldInteractStep(float secondsUsed, | public override bool OnHeldInteractStep(float secondsUsed, ItemSlot slot, EntityAgent byEntity, BlockSelection blockSel, EntitySelection entitySel) | ||
{ | { | ||
if (byEntity.World is IClientWorldAccessor) | if (byEntity.World is IClientWorldAccessor) | ||
Line 119: | Line 114: | ||
tf.EnsureDefaultValues(); | tf.EnsureDefaultValues(); | ||
tf.Origin.Set(0, -1, 0); | |||
tf.Rotation.Z = Math.Min(30, secondsUsed * 40); | |||
byEntity.Controls.UsingHeldItemTransformAfter = tf; | |||
tf.Origin.Set(0, | |||
tf. | |||
byEntity.Controls. | |||
if (secondsUsed > 0.6) | if (secondsUsed > 0.6) | ||
{ | { | ||
Vec3d pos = | Vec3d pos = | ||
byEntity.Pos.XYZ.Add(0, byEntity.EyeHeight | byEntity.Pos.XYZ.Add(0, byEntity.EyeHeight, 0) | ||
.Ahead(1f, byEntity.Pos.Pitch, byEntity.Pos.Yaw) | .Ahead(1f, byEntity.Pos.Pitch, byEntity.Pos.Yaw) | ||
; | ; | ||
Line 139: | Line 128: | ||
particles.minVelocity = speedVec; | particles.minVelocity = speedVec; | ||
Random rand = new Random(); | Random rand = new Random(); | ||
particles.color = ColorUtil. | particles.color = ColorUtil.ToRgba(255, rand.Next(0, 255), rand.Next(0, 255), rand.Next(0, 255)); | ||
particles.minPos = pos.AddCopy(-0.05, -0.05, -0.05); | particles.minPos = pos.AddCopy(-0.05, -0.05, -0.05); | ||
particles.addPos.Set(0.1, 0.1, 0.1); | particles.addPos.Set(0.1, 0.1, 0.1); |