Confirmedusers, editor, Administrators
886
edits
No edit summary |
CreativeMD (talk | contribs) |
||
Line 94: | Line 94: | ||
</syntaxhighlight> | </syntaxhighlight> | ||
Although this code works already, some sound effects would be rather nice. | Although this code works already, some sound effects would be rather nice. We can implement it by adding a sound link field to our block, which can use to play the <code>game:tick</code> sound. | ||
<syntaxhighlight lang="c#"> | <syntaxhighlight lang="c#"> | ||
public AssetLocation tickSound = new AssetLocation("game", "tick"); | |||
</syntaxhighlight> | |||
This <code>tickSound</code> will played every time an entity bounces: | |||
<syntaxhighlight lang="c#"> | |||
world.PlaySoundAt(tickSound, entity.Pos.X, entity.Pos.Y, entity.Pos.Z); | |||
</syntaxhighlight> | </syntaxhighlight> | ||
Line 112: | Line 118: | ||
public class TrampolineMod : ModBase | public class TrampolineMod : ModBase | ||
{ | { | ||
public override void Start(ICoreAPI api) | public override void Start(ICoreAPI api) | ||
{ | { | ||
Line 121: | Line 128: | ||
public class TrampolineBlock : Block | public class TrampolineBlock : Block | ||
{ | { | ||
public override void | public AssetLocation tickSound = new AssetLocation("game", "tick"); | ||
public override void OnEntityCollide(IWorldAccessor world, Entity entity, BlockPos pos, BlockFacing facing, bool isImpact) | |||
{ | { | ||
if (isImpact && facing.Axis == EnumAxis.Y) | if (isImpact && facing.Axis == EnumAxis.Y) | ||
{ | { | ||
entity. | world.PlaySoundAt(tickSound, entity.Pos.X, entity.Pos.Y, entity.Pos.Z); | ||
entity.Pos.Motion.Y *= -0.8; | entity.Pos.Motion.Y *= -0.8; | ||
} | } |