public override void OnHeldAttackStart(ItemSlot slot, EntityAgent byEntity, BlockSelection blockSel, EntitySelection entitySel, ref EnumHandHandling handling) { if (blockSel == null) { return; } if (!(byEntity.World.BlockAccessor.GetBlock(blockSel.Position) is BlockAnvil)) { return; } BlockEntityAnvil bea = byEntity.World.BlockAccessor.GetBlockEntity(blockSel.Position) as BlockEntityAnvil; if (bea == null) { return; } IPlayer byPlayer = null; if (byEntity is EntityPlayer) { byPlayer = byEntity.World.PlayerByUid(((EntityPlayer)byEntity).PlayerUID); } if (byPlayer == null) { return; } bea.OnBeginUse(byPlayer, blockSel); byEntity.World.RegisterCallback((dt) => { if (byEntity.Controls.HandUse == EnumHandInteract.HeldItemAttack) { byPlayer.Entity.World.PlaySoundAt(new AssetLocation("sounds/effect/anvilhit"), byPlayer, byPlayer); } }, 464); handling = EnumHandHandling.PreventDefault; }
public override void OnHeldAttackStart(ItemSlot slot, EntityAgent byEntity, BlockSelection blockSel, EntitySelection entitySel, ref EnumHandHandling handling) { if (blockSel == null) { return; } IPlayer byPlayer = (byEntity as EntityPlayer)?.Player; if (byPlayer == null) { return; } BlockEntity be = byEntity.World.BlockAccessor.GetBlockEntity(blockSel.Position); if (be is BlockEntityAnvilPart beap) { handling = EnumHandHandling.PreventDefault; if (!beap.TestReadyToMerge()) { return; } byEntity.World.RegisterCallback((dt) => { if (byEntity.Controls.HandUse == EnumHandInteract.HeldItemAttack) { byPlayer.Entity.World.PlaySoundAt(new AssetLocation("sounds/effect/anvilmergehit"), byPlayer, byPlayer); } }, 464); return; } if (!(byEntity.World.BlockAccessor.GetBlock(blockSel.Position) is BlockAnvil)) { return; } BlockEntityAnvil bea = be as BlockEntityAnvil; if (bea == null) { return; } bea.OnBeginUse(byPlayer, blockSel); byEntity.World.RegisterCallback((dt) => { if (byEntity.Controls.HandUse == EnumHandInteract.HeldItemAttack) { byPlayer.Entity.World.PlaySoundAt(new AssetLocation("sounds/effect/anvilhit"), byPlayer, byPlayer); } }, 440); handling = EnumHandHandling.PreventDefault; }